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_pnc_support_routines
40 # include "pnetcdf.inc"
41 include 'wrf_status_codes.h'
42 integer ,intent(in) :: DataHandle
43 character*(*) ,intent(in) :: Element
44 character (DateStrLen),intent(in) :: DateStr
45 character*(*) ,intent(in) :: Var
49 integer ,intent(out) :: Status
50 type(wrf_data_handle) ,pointer :: DH
51 character (VarNameLen) :: VarName
52 character (40+len(Element)) :: Name
53 character (40+len(Element)) :: FName
55 TYPE_BUFFER ,allocatable :: Buffer(:)
58 integer(KIND=MPI_OFFSET_KIND) :: VStart(2)
59 integer(KIND=MPI_OFFSET_KIND) :: VCount(2)
68 integer(KIND=MPI_OFFSET_KIND) :: Len1_okind
72 Status = WRF_WARN_ZERO_LENGTH_GET
74 'Warning ZERO LENGTH GET in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
75 call wrf_debug ( WARN , msg)
79 call DateCheck(DateStr,Status)
80 if(Status /= WRF_NO_ERR) then
82 'Warning DATE STRING ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
83 call wrf_debug ( WARN , msg)
86 call GetDH(DataHandle,DH,Status)
87 if(Status /= WRF_NO_ERR) then
89 'Warning Status = ',Status,' in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
90 call wrf_debug ( WARN , msg)
94 call GetName(Element, VarName, Name, Status)
95 if(Status /= WRF_NO_ERR) then
97 'Warning Status = ',Status,' in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
98 call wrf_debug ( WARN , msg)
101 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
102 Status = WRF_WARN_FILE_NOT_OPENED
104 'Warning FILE NOT OPENED in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
105 call wrf_debug ( WARN , msg)
106 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
107 Status = WRF_WARN_DRYRUN_READ
109 'Warning DRYRUN READ in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
110 call wrf_debug ( WARN , msg)
111 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
112 Status = WRF_WARN_READ_WONLY_FILE
114 'Warning READ WONLY FILE in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
115 call wrf_debug ( WARN , msg)
116 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
117 stat = NFMPI_INQ_VARID(NCID,Name,VarID)
118 call netcdf_err(stat,Status)
119 if(Status /= WRF_NO_ERR) then
121 'NetCDF error in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__,' Element ',Element
122 call wrf_debug ( WARN , msg)
125 stat = NFMPI_INQ_VAR(NCID,VarID,FName,XType,NDims,DimIDs,NAtts)
126 call netcdf_err(stat,Status)
127 if(Status /= WRF_NO_ERR) then
129 'NetCDF error in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__,' Element ',Element
130 call wrf_debug ( WARN , msg)
133 if ( NF_TYPE == NF_DOUBLE .OR. NF_TYPE == NF_FLOAT ) then
134 if( .NOT. ( XType==NF_FLOAT .OR. XType==NF_DOUBLE) ) then
135 Status = WRF_WARN_TYPE_MISMATCH
137 'Warning TYPE MISMATCH in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
138 call wrf_debug ( WARN , msg)
142 if(XType /= NF_TYPE) then
143 Status = WRF_WARN_TYPE_MISMATCH
145 'Warning TYPE MISMATCH in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
146 call wrf_debug ( WARN , msg)
150 if(NDims /= NMDVarDims) then
151 Status = WRF_ERR_FATAL_MDVAR_DIM_NOT_1D
153 'Fatal MDVAR DIM NOT 1D in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
154 call wrf_debug ( FATAL , msg)
157 stat = NFMPI_INQ_DIMLEN(NCID,DimIDs(1),Len1_okind)
158 call netcdf_err(stat,Status)
159 if(Status /= WRF_NO_ERR) then
161 'NetCDF error in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__,' DimIDs(1) ',DimIDs(1)
162 call wrf_debug ( WARN , msg)
166 call GetTimeIndex('read',DataHandle,DateStr,TimeIndex,Status)
167 if(Status /= WRF_NO_ERR) then
169 'Warning in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
170 call wrf_debug ( WARN , msg)
174 VStart(2) = TimeIndex
178 allocate(Buffer(VCount(1)), STAT=stat)
180 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
182 'Fatal ALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
183 call wrf_debug ( FATAL , msg)
186 stat = NF_ROUTINE (NCID,VarID,VStart,VCount,Buffer)
188 if(Len1 > len(Data)) then
189 Status = WRF_WARN_CHARSTR_GT_LENDATA
191 'Warning LEN CHAR STRING > LEN DATA in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
192 call wrf_debug ( WARN , msg)
196 stat = NFMPI_GET_VARA_TEXT_ALL (NCID,VarID,VStart,VCount,Data)
198 call netcdf_err(stat,Status)
199 if(Status /= WRF_NO_ERR) then
201 'NetCDF error in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
202 call wrf_debug ( WARN , msg)
207 deallocate(Buffer, STAT=stat)
209 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
211 'Fatal DEALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
212 call wrf_debug ( FATAL , msg)
215 if(Len1 > Count) then
217 Status = WRF_WARN_MORE_DATA_IN_FILE
224 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
226 'Fatal error BAD FILE STATUS in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
227 call wrf_debug ( FATAL , msg)