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/hemco 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 : use netCDF
48 : !
49 : ! !INPUT PARAMETERS:
50 : !! ncid : netCDF file id to check
51 : integer, intent (in) :: ncid
52 : !
53 : ! !DESCRIPTION: Checks a given netCDF file to see if it contains an
54 : ! unlimited dimension.
55 : !\\
56 : !\\
57 : ! !RETURN VALUE:
58 : logical :: Ncdoes_Udim_Exist
59 : !
60 : ! !AUTHOR:
61 : ! John Tannahill (LLNL) and Jules Kouatchou
62 : !
63 : ! !REVISION HISTORY:
64 : ! See https://github.com/geoschem/hemco for complete history
65 : !EOP
66 : !------------------------------------------------------------------------------
67 : !BOC
68 : !
69 : ! !LOCAL VARIABLES:
70 : integer :: ierr, udim_id
71 :
72 0 : Ncdoes_Udim_Exist = .false.
73 0 : ierr = NF90_Inquire(ncid, unlimitedDimId=udim_id)
74 0 : IF ( ierr /= NF90_NOERR ) Ncdoes_Udim_Exist = .true.
75 :
76 0 : end function Ncdoes_Udim_Exist
77 : !EOC
78 : !------------------------------------------------------------------------------
79 : ! NcdfUtilities: by Harvard Atmospheric Chemistry Modeling Group !
80 : ! and NASA/GSFC, SIVO, Code 610.3 !
81 : !------------------------------------------------------------------------------
82 : !BOP
83 : !
84 : ! !FUNCTION: Ncdoes_Var_Exist
85 : !
86 : ! !INTERFACE:
87 : !
88 0 : function Ncdoes_Var_Exist (ncid, varname)
89 : !
90 : use netCDF
91 : !
92 : ! !INPUT PARAMETERS:
93 : !! ncid : netCDF file id to check
94 : !! varname : netCDF variable name to check
95 : integer, intent (in) :: ncid
96 : character (len=*), intent (in) :: varname
97 : !
98 : ! !DESCRIPTION: Checks a given netCDF file to see if a given netCDF variable
99 : ! exists in it.
100 : !\\
101 : !\\
102 : ! !RETURN VALUE:
103 : logical :: Ncdoes_Var_Exist
104 : !
105 : ! !AUTHOR:
106 : ! John Tannahill (LLNL) and Jules Kouatchou
107 : !
108 : ! !REVISION HISTORY:
109 : ! See https://github.com/geoschem/hemco for complete history
110 : !EOP
111 : !------------------------------------------------------------------------------
112 : !BOC
113 : !
114 : ! !LOCAL VARIABLES:
115 : integer :: ierr
116 : integer :: varid
117 : !
118 0 : ierr = NF90_Inq_Varid(ncid, varname, varid)
119 0 : Ncdoes_Var_Exist = .false.
120 0 : if (ierr == NF90_NOERR) Ncdoes_Var_Exist = .true.
121 :
122 0 : end function Ncdoes_Var_Exist
123 : !EOC
124 : !------------------------------------------------------------------------------
125 : ! NcdfUtilities: by Harvard Atmospheric Chemistry Modeling Group !
126 : ! and NASA/GSFC, SIVO, Code 610.3 !
127 : !------------------------------------------------------------------------------
128 : !BOP
129 : !
130 : ! !FUNCTION: Ncdoes_Attr_Exist
131 : !
132 : ! !INTERFACE:
133 : !
134 0 : function Ncdoes_Attr_Exist(ncid, varname, attname, attType)
135 : !
136 : use netCDF
137 : !
138 : ! !INPUT PARAMETERS:
139 : !! ncid : netCDF file id to check
140 : !! varname : netCDF variable name to check
141 : !! attname : netCDF attribute name to check
142 : integer, intent (in) :: ncid
143 : character (len=*), intent (in) :: varname
144 : character (len=*), intent (in) :: attname
145 : !
146 : ! !OUTPUT PARAMETERS:
147 : !
148 : !! attType : Attribute type. This value is will be set to one of the
149 : !! following: NF_BYTE, NF_CHAR, NF_SHORT, NF_INT, NF_FLOAT, or NF_DOUBLE.
150 : INTEGER, INTENT(OUT) :: attType
151 : !
152 : ! !DESCRIPTION: Checks a given netCDF file to see if a given netCDF variable
153 : ! exists in it.
154 : !\\
155 : !\\
156 : ! !RETURN VALUE:
157 : logical :: Ncdoes_Attr_Exist
158 : !
159 : ! !AUTHOR:
160 : ! John Tannahill (LLNL) and Jules Kouatchou
161 : !
162 : ! !REVISION HISTORY:
163 : ! See https://github.com/geoschem/hemco for complete history
164 : !EOP
165 : !------------------------------------------------------------------------------
166 : !BOC
167 : !
168 : ! !LOCAL VARIABLES:
169 : INTEGER :: ierr, varId, attLen, attNum
170 :
171 : ! Init
172 0 : Ncdoes_Attr_Exist = .false.
173 0 : attType = -1
174 :
175 : ! First check the variable
176 0 : ierr = NF90_Inq_Varid (ncid, varname, varid)
177 :
178 : ! Check the attribute if variable was found
179 0 : IF ( ierr == NF90_NOERR ) THEN
180 : ierr = NF90_Inquire_Attribute( ncId, varId, attName, &
181 0 : attType, attLen, attNum )
182 0 : IF ( ierr == NF90_NOERR ) THEN
183 0 : NcDoes_Attr_Exist = .TRUE.
184 : ENDIF
185 : ENDIF
186 :
187 0 : end function Ncdoes_Attr_Exist
188 : !EOC
189 : !------------------------------------------------------------------------------
190 : ! NcdfUtilities: by Harvard Atmospheric Chemistry Modeling Group !
191 : ! and NASA/GSFC, SIVO, Code 610.3 !
192 : !------------------------------------------------------------------------------
193 : !BOP
194 : !
195 : ! !FUNCTION: Ncdoes_Dim_Exist
196 : !
197 : ! !INTERFACE:
198 : !
199 0 : function Ncdoes_Dim_Exist (ncid, dimname )
200 : !
201 : use netCDF
202 : !
203 : ! !INPUT PARAMETERS:
204 : !! ncid : netCDF file id to check
205 : !! dimname : netCDF dimenison name to check
206 : integer, intent (in) :: ncid
207 : character (len=*), intent (in) :: dimname
208 : !
209 : ! !DESCRIPTION: Checks a given netCDF file to see if a given netCDF variable
210 : ! exists in it.
211 : !\\
212 : !\\
213 : ! !RETURN VALUE:
214 : logical :: Ncdoes_Dim_Exist
215 : !
216 : ! !AUTHOR:
217 : ! John Tannahill (LLNL) and Jules Kouatchou
218 : !
219 : ! !REVISION HISTORY:
220 : ! See https://github.com/geoschem/hemco for complete history
221 : !EOP
222 : !-----------------------------------------------------------------------------
223 : !BOC
224 : !
225 : ! !LOCAL VARIABLES:
226 : integer :: ierr
227 : integer :: dimid
228 :
229 : ! First check the variable
230 0 : ierr = NF90_Inq_Dimid(ncid, dimname, dimid)
231 :
232 : ! Check the attribute if variable was found
233 0 : Ncdoes_Dim_Exist = .false.
234 0 : if (ierr == NF90_NOERR) Ncdoes_Dim_Exist = .true.
235 :
236 : return
237 :
238 : end function Ncdoes_Dim_Exist
239 : !EOC
240 : end module HCO_m_netcdf_io_checks
|