File: nf_vario.F90

package info (click to toggle)
netcdf-fortran 4.4.4%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,420 kB
  • ctags: 8,797
  • sloc: fortran: 51,087; f90: 20,357; sh: 11,601; ansic: 7,034; makefile: 548; pascal: 313; xml: 173
file content (432 lines) | stat: -rwxr-xr-x 10,656 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#include "nfconfig.inc"
!------------ Array/string put/get routines for a given varid ----------------

! Replacement for fort-vario.c

! Written by: Richard Weed, Ph.D.
!             Center For Advanced Vehicular Systems 
!             Mississippi State University
!             rweed@cavs.msstate.edu
  

! License (and other Lawyer Language)
 
! This software is released under the Apache 2.0 Open Source License. The
! full text of the License can be viewed at :
!
!   http:www.apache.org/licenses/LICENSE-2.0.html
!
! The author grants to the University Corporation for Atmospheric Research
! (UCAR), Boulder, CO, USA the right to revise and extend the software
! without restriction. However, the author retains all copyrights and
! intellectual property rights explicitly stated in or implied by the
! Apache license

! Version 1.: Sept. 2005 - Initial Cray X1 version
! Version 2.: May   2006 - Updated to support g95
! Version 3.: April 2009 - Updated for netCDF 4.0.1
! Version 4.: April 2010 - Updated for netCDF 4.1.1
!                          Added preprocessor tests for int and real types
! Version 5.: Jan.  2016 - Some minor code cleanup

!--------------------------------- nf_put_var_text -----------------------
 Function nf_put_var_text(ncid, varid, text) RESULT(status)

! Write out a character string to dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,          Intent(IN) :: ncid, varid
 Character(LEN=*), Intent(IN) :: text

 Integer                      :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

 cstatus = nc_put_var_text(cncid, cvarid, text)

 status = cstatus

 End Function nf_put_var_text
!--------------------------------- nf_put_var_text_a -----------------------
 Function nf_put_var_text_a(ncid, varid, text) RESULT(status)

! Write out array of characters to dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,          Intent(IN) :: ncid, varid
 Character(LEN=1), Intent(IN) :: text(*)

 Integer                      :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

 cstatus = nc_put_var_text(cncid, cvarid, text)

 status = cstatus

 End Function nf_put_var_text_a
!--------------------------------- nf_put_var_int1 -------------------------
 Function nf_put_var_int1(ncid, varid, i1vals) RESULT(status)

! Write out 8 bit integer array to dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,         Intent(IN) :: ncid, varid
 Integer(NFINT1), Intent(IN) :: i1vals(*)

 Integer                     :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 If (C_SIGNED_CHAR < 0) Then ! schar not supported by processor
   status = NC_EBADTYPE
   RETURN
 EndIf

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

#if NF_INT1_IS_C_SIGNED_CHAR
 cstatus = nc_put_var_schar(cncid, cvarid, i1vals)
#elif NF_INT1_IS_C_SHORT
 cstatus = nc_put_var_short(cncid, cvarid, i1vals)
#elif NF_INT1_IS_C_INT
 cstatus = nc_put_var_int(cncid, cvarid, i1vals)
#elif NF_INT1_IS_C_LONG
 cstatus = nc_put_var_long(cncid, cvarid, i1vals)
#endif

 status = cstatus

 End Function nf_put_var_int1
!--------------------------------- nf_put_var_int2 -------------------------
 Function nf_put_var_int2(ncid, varid, i2vals) RESULT(status)

! Write out 16 bit integer array to dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,         Intent(IN) :: ncid, varid
 Integer(NFINT2), Intent(IN) :: i2vals(*)

 Integer                     :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 If (C_SHORT < 0) Then ! short not supported by processor
   status = NC_EBADTYPE
   RETURN
 EndIf

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

#if NF_INT2_IS_C_SHORT
 cstatus = nc_put_var_short(cncid, cvarid, i2vals)
#elif NF_INT2_IS_C_INT
 cstatus = nc_put_var_int(cncid, cvarid, i2vals)
#elif NF_INT2_IS_C_LONG
 cstatus = nc_put_var_long(cncid, cvarid, i2vals)
#endif

 status = cstatus

 End Function nf_put_var_int2
!--------------------------------- nf_put_var_int --------------------------
 Function nf_put_var_int(ncid, varid, ivals) RESULT(status)

! Write out 32 bit integer array to dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,        Intent(IN) :: ncid, varid
 Integer(NFINT), Intent(IN) :: ivals(*)

 Integer                    :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

#if NF_INT_IS_C_INT
 cstatus = nc_put_var_int(cncid, cvarid, ivals)
#elif NF_INT_IS_C_LONG
 cstatus = nc_put_var_long(cncid, cvarid, ivals)
#endif

 status = cstatus

 End Function nf_put_var_int
!--------------------------------- nf_put_var_real -------------------------
 Function nf_put_var_real(ncid, varid, rvals) RESULT(status)

! Write out 32 bit real array to dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,         Intent(IN) :: ncid, varid
 Real(NFREAL),    Intent(IN) :: rvals(*)

 Integer                     :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

#if NF_REAL_IS_C_DOUBLE
 cstatus = nc_put_var_double(cncid, cvarid, rvals)
#else
 cstatus = nc_put_var_float(cncid, cvarid, rvals)
#endif

 status = cstatus

 End Function nf_put_var_real
!--------------------------------- nf_put_var_double -----------------------
 Function nf_put_var_double(ncid, varid, dvals) RESULT(status)

! Write out 64 bit real array to dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,   Intent(IN) :: ncid, varid
 Real(RK8), Intent(IN) :: dvals(*)

 Integer               :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

 cstatus = nc_put_var_double(cncid, cvarid, dvals)

 status = cstatus

 End Function nf_put_var_double
!--------------------------------- nf_get_var_text -----------------------
 Function nf_get_var_text(ncid, varid, text) RESULT(status)

! Read in a character string from dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,          Intent(IN)  :: ncid, varid
 Character(LEN=*), Intent(OUT) :: text

 Integer                       :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid
 text   = REPEAT(" ", LEN(text))

 cstatus = nc_get_var_text(cncid, cvarid, text)

 status = cstatus

 End Function nf_get_var_text
!--------------------------------- nf_get_var_text_a -----------------------
 Function nf_get_var_text_a(ncid, varid, text) RESULT(status)

! Read in array of characters from dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,          Intent(IN)  :: ncid, varid
 Character(LEN=1), Intent(OUT) :: text(*)

 Integer                       :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

 cstatus = nc_get_var_text(cncid, cvarid, text)

 status = cstatus

 End Function nf_get_var_text_a
!--------------------------------- nf_get_var_int1 -------------------------
 Function nf_get_var_int1(ncid, varid, i1vals) RESULT(status)

! Read in 8 bit integer array from dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,         Intent(IN)  :: ncid, varid
 Integer(NFINT1), Intent(OUT) :: i1vals(*)

 Integer                      :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 If (C_SIGNED_CHAR < 0) Then ! schar not supported by processor
   status = NC_EBADTYPE
   RETURN
 EndIf

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

#if NF_INT1_IS_C_SIGNED_CHAR
 cstatus = nc_get_var_schar(cncid, cvarid, i1vals)
#elif NF_INT1_IS_C_SHORT
 cstatus = nc_get_var_short(cncid, cvarid, i1vals)
#elif NF_INT1_IS_C_INT
 cstatus = nc_get_var_int(cncid, cvarid, i1vals)
#elif NF_INT1_IS_C_LONG
 cstatus = nc_get_var_long(cncid, cvarid, i1vals)
#endif

 status = cstatus

 End Function nf_get_var_int1
!--------------------------------- nf_get_var_int2 -------------------------
 Function nf_get_var_int2(ncid, varid, i2vals) RESULT(status)

! Read in 16 bit integer array from dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,         Intent(IN)  :: ncid, varid
 Integer(NFINT2), Intent(OUT) :: i2vals(*)

 Integer                      :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 If (C_SHORT < 0) Then ! short not supported by processor
   status = NC_EBADTYPE
   RETURN
 EndIf

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

#if NF_INT2_IS_C_SHORT
 cstatus = nc_get_var_short(cncid, cvarid, i2vals)
#elif NF_INT2_IS_C_INT
 cstatus = nc_get_var_int(cncid, cvarid, i2vals)
#elif NF_INT2_IS_C_LONG
 cstatus = nc_get_var_long(cncid, cvarid, i2vals)
#endif

 status = cstatus

 End Function nf_get_var_int2
!--------------------------------- nf_get_var_int --------------------------
 Function nf_get_var_int(ncid, varid, ivals) RESULT(status)

! Read in default integer array from dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,        Intent(IN)  :: ncid, varid
 Integer(NFINT), Intent(OUT) :: ivals(*)

 Integer                     :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

#if NF_INT_IS_C_INT
 cstatus = nc_get_var_int(cncid, cvarid, ivals)
#elif NF_INT_IS_C_LONG
 cstatus = nc_get_var_long(cncid, cvarid, ivals)
#endif

 status = cstatus

 End Function nf_get_var_int
!--------------------------------- nf_get_var_real -------------------------
 Function nf_get_var_real(ncid, varid, rvals) RESULT(status)

! Read in 32 bit real array from dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,      Intent(IN)  :: ncid, varid
 Real(NFREAL), Intent(OUT) :: rvals(*)

 Integer                   :: status

 Integer(C_INT) :: cncid, cvarid,  cstatus

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

#if NF_REAL_IS_C_DOUBLE
 cstatus = nc_get_var_double(cncid, cvarid, rvals)
#else
 cstatus = nc_get_var_float(cncid, cvarid, rvals)
#endif

 status = cstatus

 End Function nf_get_var_real
!--------------------------------- nf_get_var_double -----------------------
 Function nf_get_var_double(ncid, varid, dvals) RESULT(status)

! Read in 64 bit real array from dataset

 USE netcdf_nc_interfaces

 Implicit NONE

 Integer,   Intent(IN)  :: ncid, varid
 Real(RK8), Intent(OUT) :: dvals(*)

 Integer                :: status

 Integer(C_INT) :: cncid, cvarid, cstatus

 cncid  = ncid
 cvarid = varid - 1 ! Subtract 1 to get C varid

 cstatus = nc_get_var_double(cncid, cvarid, dvals)

 status = cstatus

 End Function nf_get_var_double