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 'wrf_status_codes.h'
41 # include "pnetcdf.inc"
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
51 integer(KIND=MPI_OFFSET_KIND) :: XLen_offset
53 character (VarNameLen) :: VarName
59 Status = WRF_WARN_ZERO_LENGTH_GET
61 'Warning ZERO LENGTH GET in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
62 call wrf_debug ( WARN , msg)
66 call GetDH(DataHandle,DH,Status)
67 if(Status /= WRF_NO_ERR) then
69 'Warning Status = ',Status,' in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
70 call wrf_debug ( WARN , msg)
73 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
74 Status = WRF_WARN_FILE_NOT_OPENED
76 'Warning FILE NOT OPENED in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
77 call wrf_debug ( WARN , msg)
78 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
79 Status = WRF_WARN_DRYRUN_READ
81 'Warning DRYRUN READ in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
82 call wrf_debug ( WARN , msg)
83 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
84 Status = WRF_WARN_READ_WONLY_FILE
86 'Warning READ WONLY FILE in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
87 call wrf_debug ( WARN , msg)
88 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
90 if(DH%VarNames(NVar) == VarName) then
92 elseif(NVar == DH%NumVars) then
93 Status = WRF_WARN_VAR_NF
95 'Warning VARIABLE NOT FOUND in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
96 call wrf_debug ( WARN , msg)
100 XLen_offset = i2offset(XLen)
101 stat = NFMPI_INQ_ATT(DH%NCID,DH%VarIDs(NVar),trim(Element),XType,XLen_offset)
103 call netcdf_err(stat,Status)
104 if(Status /= WRF_NO_ERR) then
106 'NetCDF error in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__,' Element ',Element
107 call wrf_debug ( WARN , msg)
109 if ( NF_TYPE == NF_DOUBLE .OR. NF_TYPE == NF_FLOAT ) then
110 if( .NOT. ( XType==NF_FLOAT .OR. XType==NF_DOUBLE) ) then
111 Status = WRF_WARN_TYPE_MISMATCH
113 'Warning TYPE MISMATCH in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
114 call wrf_debug ( WARN , msg)
118 if(XType /= NF_TYPE) then
119 Status = WRF_WARN_TYPE_MISMATCH
121 'Warning TYPE MISMATCH in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
122 call wrf_debug ( WARN , msg)
127 allocate(Buffer(XLen), STAT=stat)
129 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
131 'Fatal ALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
132 call wrf_debug ( FATAL , msg)
135 stat = NF_ROUTINE(DH%NCID,DH%VarIDs(NVar),trim(Element), Buffer )
137 if(XLen > len(Data)) then
138 Status = WRF_WARN_CHARSTR_GT_LENDATA
140 'Warning LEN CHAR STRING > LEN DATA in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
141 call wrf_debug ( WARN , msg)
144 stat = NF_ROUTINE(DH%NCID,DH%VarIDs(NVar),trim(Element), Data )
146 call netcdf_err(stat,Status)
147 if(Status /= WRF_NO_ERR) then
149 'NetCDF error in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__,' Element ',Element
150 call wrf_debug ( WARN , msg)
154 deallocate(Buffer, STAT=stat)
156 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
158 'Fatal DEALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
159 call wrf_debug ( FATAL , msg)
162 if(XLen > Count) then
164 Status = WRF_WARN_MORE_DATA_IN_FILE
171 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
173 'Fatal error BAD FILE STATUS in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
174 call wrf_debug ( FATAL , msg)