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) :: DateStr
45 character*(*) ,intent(in) :: Var
48 integer ,intent(out) :: Status
49 type(wrf_data_handle) ,pointer :: DH
50 character (VarNameLen) :: VarName
51 character (40+len(Element)) :: Name
54 integer ,allocatable :: Buffer(:)
64 call DateCheck(DateStr,Status)
65 if(Status /= WRF_NO_ERR) then
67 'Warning DATE STRING ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
68 call wrf_debug ( WARN , msg)
71 call GetDH(DataHandle,DH,Status)
72 if(Status /= WRF_NO_ERR) then
74 'Warning Status = ',Status,' in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
75 call wrf_debug ( WARN , msg)
79 call GetName(Element, VarName, Name, Status)
80 if(Status /= WRF_NO_ERR) then
82 'Warning Status = ',Status,' in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
83 call wrf_debug ( WARN , msg)
86 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
87 Status = WRF_WARN_FILE_NOT_OPENED
89 'Warning FILE NOT OPENED in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
90 call wrf_debug ( WARN , msg)
91 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
92 Status = WRF_WARN_WRITE_RONLY_FILE
94 'Warning WRITE READ ONLY FILE in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
95 call wrf_debug ( WARN , msg)
96 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
98 Status = WRF_WARN_ZERO_LENGTH_PUT
102 if(DH%MDVarNames(NVar) == Name) then
103 Status = WRF_WARN_2DRYRUNS_1VARIABLE
105 elseif(DH%MDVarNames(NVar) == NO_NAME) then
106 DH%MDVarNames(NVar) = Name
108 elseif(NVar == MaxVars) then
109 Status = WRF_WARN_TOO_MANY_VARIABLES
111 'Warning TOO MANY VARIABLES in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
112 call wrf_debug ( WARN , msg)
117 if(DH%DimLengths(i) == LENGTH) then
119 elseif(DH%DimLengths(i) == NO_DIM) then
120 stat = NF_DEF_DIM(NCID,DH%DimNames(i),LENGTH,DH%DimIDs(i))
121 call netcdf_err(stat,Status)
122 if(Status /= WRF_NO_ERR) then
124 'NetCDF error in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__,' Element ',Element
125 call wrf_debug ( WARN , msg)
128 DH%DimLengths(i) = LENGTH
130 elseif(i == MaxDims) then
131 Status = WRF_WARN_TOO_MANY_DIMS
133 'Warning TOO MANY DIMENSIONS in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
134 call wrf_debug ( WARN , msg)
138 DH%MDVarDimLens(NVar) = LENGTH
139 VDims(1) = DH%DimIDs(i)
140 VDims(2) = DH%DimUnlimID
141 stat = NF_DEF_VAR(NCID,Name,NF_TYPE,2,VDims,DH%MDVarIDs(NVar))
142 call netcdf_err(stat,Status)
143 if(Status /= WRF_NO_ERR) then
145 'NetCDF error in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__,' Element ',Element
146 call wrf_debug ( WARN , msg)
149 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
151 if(DH%MDVarNames(NVar) == Name) then
153 elseif(DH%MDVarNames(NVar) == NO_NAME) then
154 Status = WRF_WARN_MD_NF
156 'Warning METADATA NOT FOUND in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
157 call wrf_debug ( WARN , msg)
159 elseif(NVar == MaxVars) then
160 Status = WRF_WARN_TOO_MANY_VARIABLES
162 'Warning TOO MANY VARIABLES in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
163 call wrf_debug ( WARN , msg)
167 if(LENGTH > DH%MDVarDimLens(NVar)) then
168 Status = WRF_WARN_COUNT_TOO_LONG
170 'Warning COUNT TOO LONG in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
171 call wrf_debug ( WARN , msg)
173 elseif(LENGTH < 1) then
174 Status = WRF_WARN_ZERO_LENGTH_PUT
176 'Warning ZERO LENGTH PUT in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
177 call wrf_debug ( WARN , msg)
180 call GetTimeIndex('write',DataHandle,DateStr,TimeIndex,Status)
181 if(Status /= WRF_NO_ERR) then
183 'Warning in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
184 call wrf_debug ( WARN , msg)
188 VStart(2) = TimeIndex
192 allocate(Buffer(LENGTH), STAT=stat)
194 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
196 'Fatal ALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
197 call wrf_debug ( FATAL , msg)
207 stat = NF_VAR_PAR_ACCESS(ncid,DH%MDVarIDs(NVar),DH%ind_or_collective)
208 ! call netcdf_err(stat,Status)
209 ! if(Status /= WRF_NO_ERR) then
210 ! write(msg,*) 'NetCDF error in ext_ncdpar_open_for_write_begin ',__FILE__,', line', __LINE__
211 ! call wrf_debug ( WARN , TRIM(msg))
214 stat = NF_ROUTINE (NCID,DH%MDVarIDs(NVar),VStart,VCount,Buffer)
215 deallocate(Buffer, STAT=stat2)
217 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
219 'Fatal DEALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
220 call wrf_debug ( FATAL , msg)
224 stat = NF_ROUTINE (NCID,DH%MDVarIDs(NVar),VStart,VCount,Data)
226 call netcdf_err(stat,Status)
227 if(Status /= WRF_NO_ERR) then
229 'NetCDF error in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__,' Element ',Element
230 call wrf_debug ( WARN , msg)
234 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
236 'Fatal error BAD FILE STATUS in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
237 call wrf_debug ( FATAL , msg)