1 !*------------------------------------------------------------------------------
4 !* Forecast Systems Laboratory
10 !* ADVANCED COMPUTING BRANCH
11 !* SMS/NNT Version: 2.0.0
13 !* This software and its documentation are in the public domain and
14 !* are furnished "as is". The United States government, its
15 !* instrumentalities, officers, employees, and agents make no
16 !* warranty, express or implied, as to the usefulness of the software
17 !* and documentation for any purpose. They assume no
18 !* responsibility (1) for the use of the software and documentation;
19 !* or (2) to provide technical support to users.
21 !* Permission to use, copy, modify, and distribute this software is
22 !* hereby granted, provided that this disclaimer notice appears in
23 !* all copies. All modifications to this software must be clearly
24 !* documented, and are solely the responsibility of the agent making
25 !* the modification. If significant modifications or enhancements
26 !* are made to this software, the SMS Development team
27 !* (sms-info@fsl.noaa.gov) should be notified.
29 !*----------------------------------------------------------------------------
32 ! Author: Jacques Middlecoff jacquesm@fsl.noaa.gov
33 !* Date: October 6, 2000
35 !*----------------------------------------------------------------------------
38 use ext_ncdpar_support_routines
40 include 'wrf_status_codes.h'
42 integer ,intent(in) :: DataHandle
43 character*(*) ,intent(in) :: Element
44 character*(*) ,intent(in) :: Var
48 integer ,intent(out) :: Status
49 type(wrf_data_handle) ,pointer :: DH
52 character (VarNameLen) :: VarName
58 Status = WRF_WARN_ZERO_LENGTH_GET
60 'Warning ZERO LENGTH GET in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
61 call wrf_debug ( WARN , msg)
65 call GetDH(DataHandle,DH,Status)
66 if(Status /= WRF_NO_ERR) then
68 'Warning Status = ',Status,' in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
69 call wrf_debug ( WARN , msg)
72 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
73 Status = WRF_WARN_FILE_NOT_OPENED
75 'Warning FILE NOT OPENED in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
76 call wrf_debug ( WARN , msg)
77 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
78 Status = WRF_WARN_DRYRUN_READ
80 'Warning DRYRUN READ in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
81 call wrf_debug ( WARN , msg)
82 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
83 Status = WRF_WARN_READ_WONLY_FILE
85 'Warning READ WONLY FILE in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
86 call wrf_debug ( WARN , msg)
87 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
89 if(DH%VarNames(NVar) == VarName) then
91 elseif(NVar == DH%NumVars) then
92 Status = WRF_WARN_VAR_NF
94 'Warning VARIABLE NOT FOUND in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
95 call wrf_debug ( WARN , msg)
99 stat = NF_INQ_ATT(DH%NCID,DH%VarIDs(NVar),trim(Element),XType,XLen)
100 call netcdf_err(stat,Status)
101 if(Status /= WRF_NO_ERR) then
103 'NetCDF error in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__,' Element ',Element
104 call wrf_debug ( WARN , msg)
106 if ( NF_TYPE == NF_DOUBLE .OR. NF_TYPE == NF_FLOAT ) then
107 if( .NOT. ( XType==NF_FLOAT .OR. XType==NF_DOUBLE) ) then
108 Status = WRF_WARN_TYPE_MISMATCH
110 'Warning TYPE MISMATCH in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
111 call wrf_debug ( WARN , msg)
115 if(XType /= NF_TYPE) then
116 Status = WRF_WARN_TYPE_MISMATCH
118 'Warning TYPE MISMATCH in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
119 call wrf_debug ( WARN , msg)
124 allocate(Buffer(XLen), STAT=stat)
126 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
128 'Fatal ALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
129 call wrf_debug ( FATAL , msg)
132 stat = NF_ROUTINE(DH%NCID,DH%VarIDs(NVar),trim(Element), Buffer )
134 if(XLen > len(Data)) then
135 Status = WRF_WARN_CHARSTR_GT_LENDATA
137 'Warning LEN CHAR STRING > LEN DATA in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
138 call wrf_debug ( WARN , msg)
141 stat = NF_ROUTINE(DH%NCID,DH%VarIDs(NVar),trim(Element), Data )
143 call netcdf_err(stat,Status)
144 if(Status /= WRF_NO_ERR) then
146 'NetCDF error in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__,' Element ',Element
147 call wrf_debug ( WARN , msg)
151 deallocate(Buffer, STAT=stat)
153 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
155 'Fatal DEALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
156 call wrf_debug ( FATAL , msg)
159 if(XLen > Count) then
161 Status = WRF_WARN_MORE_DATA_IN_FILE
168 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
170 'Fatal error BAD FILE STATUS in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
171 call wrf_debug ( FATAL , msg)