Line data Source code
1 : !------------------------------------------------------------------------------
2 : ! NcdfUtilities: by Harvard Atmospheric Chemistry Modeling Group !
3 : ! and NASA/GSFC, SIVO, Code 610.3 !
4 : !------------------------------------------------------------------------------
5 : !BOP
6 : !
7 : ! !MODULE: HCO_m_netcdf_io_checks.F90
8 : !
9 : ! !INTERFACE:
10 : !
11 : module HCO_m_netcdf_io_checks
12 : !
13 : implicit none
14 : !
15 : ! !PUBLIC MEMBER FUNCTIONS:
16 : !
17 : public Ncdoes_Udim_Exist
18 : public Ncdoes_Var_Exist
19 : public Ncdoes_Attr_Exist
20 : !
21 : ! !DESCRIPTION: Routines to check if a netCDF file contains a specified
22 : ! variable.
23 : !\\
24 : !\\
25 : ! !AUTHOR:
26 : ! Jules Kouatchou
27 : !
28 : ! !REVISION HISTORY:
29 : ! See https://github.com/geoschem/ncdfutil for complete history
30 : !EOP
31 : !-------------------------------------------------------------------------
32 : !BOC
33 : CONTAINS
34 : !EOC
35 : !------------------------------------------------------------------------------
36 : ! NcdfUtilities: by Harvard Atmospheric Chemistry Modeling Group !
37 : ! and NASA/GSFC, SIVO, Code 610.3 !
38 : !------------------------------------------------------------------------------
39 : !BOP
40 : !
41 : ! !FUNCTION: Ncdoes_Udim_Exist
42 : !
43 : ! !INTERFACE:
44 : !
45 0 : function Ncdoes_Udim_Exist (ncid)
46 : !
47 : implicit none
48 : !
49 : include "netcdf.inc"
50 : !
51 : ! !INPUT PARAMETERS:
52 : !! ncid : netCDF file id to check
53 : integer, intent (in) :: ncid
54 : !
55 : ! !DESCRIPTION: Checks a given netCDF file to see if it contains an
56 : ! unlimited dimension.
57 : !\\
58 : !\\
59 : ! !RETURN VALUE:
60 : logical :: Ncdoes_Udim_Exist
61 : !
62 : ! !AUTHOR:
63 : ! John Tannahill (LLNL) and Jules Kouatchou
64 : !
65 : ! !REVISION HISTORY:
66 : ! See https://github.com/geoschem/ncdfutil for complete history
67 : !EOP
68 : !------------------------------------------------------------------------------
69 : !BOC
70 : !
71 : ! !LOCAL VARIABLES:
72 : integer :: ierr
73 : integer :: udimid
74 : !
75 0 : ierr = Nf_Inq_Unlimdim (ncid, udimid)
76 :
77 0 : if (ierr == NF_NOERR) then
78 : Ncdoes_Udim_Exist = .true.
79 : else
80 0 : Ncdoes_Udim_Exist = .false.
81 : end if
82 :
83 : return
84 :
85 : end function Ncdoes_Udim_Exist
86 : !EOC
87 : !------------------------------------------------------------------------------
88 : ! NcdfUtilities: by Harvard Atmospheric Chemistry Modeling Group !
89 : ! and NASA/GSFC, SIVO, Code 610.3 !
90 : !------------------------------------------------------------------------------
91 : !BOP
92 : !
93 : ! !FUNCTION: Ncdoes_Var_Exist
94 : !
95 : ! !INTERFACE:
96 : !
97 0 : function Ncdoes_Var_Exist (ncid, varname)
98 : !
99 : implicit none
100 : !
101 : include "netcdf.inc"
102 : !
103 : ! !INPUT PARAMETERS:
104 : !! ncid : netCDF file id to check
105 : !! varname : netCDF variable name to check
106 : integer, intent (in) :: ncid
107 : character (len=*), intent (in) :: varname
108 : !
109 : ! !DESCRIPTION: Checks a given netCDF file to see if a given netCDF variable
110 : ! exists in it.
111 : !\\
112 : !\\
113 : ! !RETURN VALUE:
114 : logical :: Ncdoes_Var_Exist
115 : !
116 : ! !AUTHOR:
117 : ! John Tannahill (LLNL) and Jules Kouatchou
118 : !
119 : ! !REVISION HISTORY:
120 : ! See https://github.com/geoschem/ncdfutil for complete history
121 : !EOP
122 : !------------------------------------------------------------------------------
123 : !BOC
124 : !
125 : ! !LOCAL VARIABLES:
126 : integer :: ierr
127 : integer :: varid
128 : !
129 0 : ierr = Nf_Inq_Varid (ncid, varname, varid)
130 :
131 0 : if (ierr == NF_NOERR) then
132 : Ncdoes_Var_Exist = .true.
133 : else
134 0 : Ncdoes_Var_Exist = .false.
135 : end if
136 :
137 : return
138 :
139 : end function Ncdoes_Var_Exist
140 : !EOC
141 : !------------------------------------------------------------------------------
142 : ! NcdfUtilities: by Harvard Atmospheric Chemistry Modeling Group !
143 : ! and NASA/GSFC, SIVO, Code 610.3 !
144 : !------------------------------------------------------------------------------
145 : !BOP
146 : !
147 : ! !FUNCTION: Ncdoes_Attr_Exist
148 : !
149 : ! !INTERFACE:
150 : !
151 0 : function Ncdoes_Attr_Exist (ncid, varname, attname, attType)
152 : !
153 : implicit none
154 : !
155 : include "netcdf.inc"
156 : !
157 : ! !INPUT PARAMETERS:
158 : !! ncid : netCDF file id to check
159 : !! varname : netCDF variable name to check
160 : !! attname : netCDF attribute name to check
161 : integer, intent (in) :: ncid
162 : character (len=*), intent (in) :: varname
163 : character (len=*), intent (in) :: attname
164 : !
165 : ! !OUTPUT PARAMETERS:
166 : !
167 : !! attType : Attribute type. This value is will be set to one of the
168 : !! following: NF_BYTE, NF_CHAR, NF_SHORT, NF_INT, NF_FLOAT, or NF_DOUBLE.
169 : INTEGER, INTENT(OUT) :: attType
170 : !
171 : ! !DESCRIPTION: Checks a given netCDF file to see if a given netCDF variable
172 : ! exists in it.
173 : !\\
174 : !\\
175 : ! !RETURN VALUE:
176 : logical :: Ncdoes_Attr_Exist
177 : !
178 : ! !AUTHOR:
179 : ! John Tannahill (LLNL) and Jules Kouatchou
180 : !
181 : ! !REVISION HISTORY:
182 : ! See https://github.com/geoschem/ncdfutil for complete history
183 : !EOP
184 : !------------------------------------------------------------------------------
185 : !BOC
186 : !
187 : ! !LOCAL VARIABLES:
188 : integer :: ierr
189 : integer :: varid
190 : INTEGER :: attLen
191 :
192 : ! Init
193 0 : Ncdoes_Attr_Exist = .false.
194 0 : attType = -1
195 :
196 : ! First check the variable
197 0 : ierr = Nf_Inq_Varid (ncid, varname, varid)
198 :
199 : ! Check the attribute if variable was found
200 0 : IF ( ierr == NF_NOERR ) THEN
201 0 : ierr = Nf_Inq_Att( ncId, varId, attName, attType, attLen )
202 0 : IF ( ierr == NF_NOERR ) THEN
203 0 : NcDoes_Attr_Exist = .TRUE.
204 : ENDIF
205 : ENDIF
206 :
207 : return
208 :
209 : end function Ncdoes_Attr_Exist
210 : !EOC
211 : !------------------------------------------------------------------------------
212 : ! NcdfUtilities: by Harvard Atmospheric Chemistry Modeling Group !
213 : ! and NASA/GSFC, SIVO, Code 610.3 !
214 : !------------------------------------------------------------------------------
215 : !BOP
216 : !
217 : ! !FUNCTION: Ncdoes_Dim_Exist
218 : !
219 : ! !INTERFACE:
220 : !
221 0 : function Ncdoes_Dim_Exist (ncid, dimname )
222 : !
223 : implicit none
224 : !
225 : include "netcdf.inc"
226 : !
227 : ! !INPUT PARAMETERS:
228 : !! ncid : netCDF file id to check
229 : !! dimname : netCDF dimenison name to check
230 : integer, intent (in) :: ncid
231 : character (len=*), intent (in) :: dimname
232 : !
233 : ! !DESCRIPTION: Checks a given netCDF file to see if a given netCDF variable
234 : ! exists in it.
235 : !\\
236 : !\\
237 : ! !RETURN VALUE:
238 : logical :: Ncdoes_Dim_Exist
239 : !
240 : ! !AUTHOR:
241 : ! John Tannahill (LLNL) and Jules Kouatchou
242 : !
243 : ! !REVISION HISTORY:
244 : ! See https://github.com/geoschem/ncdfutil for complete history
245 : !EOP
246 : !-----------------------------------------------------------------------------
247 : !BOC
248 : !
249 : ! !LOCAL VARIABLES:
250 : integer :: ierr
251 : integer :: dimid
252 :
253 : ! First check the variable
254 0 : ierr = Nf_Inq_Dimid (ncid, dimname, dimid)
255 :
256 : ! Check the attribute if variable was found
257 0 : if (ierr == NF_NOERR) then
258 : Ncdoes_Dim_Exist = .true.
259 : else
260 0 : Ncdoes_Dim_Exist = .false.
261 : end if
262 :
263 : return
264 :
265 : end function Ncdoes_Dim_Exist
266 : !EOC
267 : end module HCO_m_netcdf_io_checks
|