-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathio_netcdf_file_module.F90
More file actions
608 lines (483 loc) · 22 KB
/
io_netcdf_file_module.F90
File metadata and controls
608 lines (483 loc) · 22 KB
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
module io_netcdf_file_module
use io_netcdf_attribute_module
implicit none
public netcdf_file_type
private
type dim_type
#if !defined(_CRAYFTN)
character(:), allocatable :: name
#else
character(1000) :: name
#endif
integer len
integer ncid
end type dim_type
type att_type_wrapper ! work around Fortran not being able to have polymorphic types in the same array
class(att_type), allocatable :: it
end type att_type_wrapper
type var_type ! todo: use variable type from io_netcdf_module here
#if !defined(_CRAYFTN)
character(:), allocatable :: name
#else
character(1000) :: name
#endif
integer, allocatable :: dim_indices(:)
integer datatype
type(att_type_wrapper) :: atts(15) ! use a fixed size array to store our netcdf variable attributes as nvfortran seems to loose allocation of derived types which contain allocatable types when copying the array
integer :: atts_count = 0
integer ncid
end type var_type
type netcdf_file_type
private
type(dim_type), allocatable :: dims(:)
type(var_type), allocatable :: vars(:)
type(att_type_wrapper), allocatable :: gatts(:)
character(:), allocatable :: filepath
integer ncid
contains
procedure, public :: initialize, add_dim, add_dim_unlimited, add_var_double, add_var_real, add_var_int, open_read, flush_file, close_file, open_write_create, open_write_append
procedure, public :: is_attached, read_var_shape
procedure, public :: ndims
generic, public :: read_var => read_var_r4, read_var_r8, read_var_integer
generic, public :: write_var => write_var_r4, write_var_r8, write_var_integer
generic, public :: read_var1 => read_var1_r4, read_var1_r8, read_var1_integer
generic, public :: add_var_att => add_var_att_text, add_var_att_int
generic, public :: add_global_att => add_global_att_text, add_global_att_int
procedure, private :: read_var_r4, read_var_r8, read_var_integer, attach_dims_vars_to_file, add_var_x, write_var_r4, write_var_r8, write_var_integer, add_var_att_text, add_var_att_int
procedure, private :: read_var1_r4, read_var1_r8, read_var1_integer
procedure, private :: add_global_att_text, add_global_att_int
end type netcdf_file_type
contains
subroutine initialize(this)
class(netcdf_file_type), intent(inout) :: this
this%filepath = ""
allocate(this%dims(0))
allocate(this%vars(0))
allocate(this%gatts(0))
end subroutine initialize
function add_dim_unlimited(this, name) result(dimindex)
class(netcdf_file_type), intent(inout) :: this
character(len=*), intent(in) :: name
integer dimindex
! EO parameters
include "netcdf.inc"
dimindex = this%add_dim(name, nf_unlimited)
end function add_dim_unlimited
function add_dim(this, name, len) result(dimindex)
class(netcdf_file_type), intent(inout) :: this
character(len=*), intent(in) :: name
integer, intent(in) :: len
integer dimindex
! EO parameters
type(dim_type), allocatable :: tmparr(:)
! assume the dims array is allocated
allocate( tmparr(size(this%dims)+1) )
tmparr(1:size(this%dims)) = this%dims
deallocate(this%dims)
call move_alloc(tmparr, this%dims)
dimindex = size(this%dims)
this%dims(dimindex) = dim_type(name=name, len=len, ncid=-1)
end function add_dim
! return number of specified dimensions (which might be less dimensions than an attached file has)
function ndims(this)
class(netcdf_file_type), intent(inout) :: this
integer ndims
! EO parameters
ndims = size(this%dims)
end function ndims
! the sizes of the dims define the global shape of the var
function add_var_double(this, name, dim_indices) result(varindex)
class(netcdf_file_type), intent(inout) :: this
character(len=*), intent(in) :: name
integer, intent(in) :: dim_indices(:)
integer varindex
! EO parameters
include "netcdf.inc"
varindex = this%add_var_x(name, dim_indices, nf_double)
end function add_var_double
! the sizes of the dims define the global shape of the var
function add_var_real(this, name, dim_indices) result(varindex)
class(netcdf_file_type), intent(inout) :: this
character(len=*), intent(in) :: name
integer, intent(in) :: dim_indices(:)
integer varindex
! EO parameters
include "netcdf.inc"
varindex = this%add_var_x(name, dim_indices, nf_real)
end function add_var_real
! the sizes of the dims define the global shape of the var
function add_var_int(this, name, dim_indices) result(varindex)
class(netcdf_file_type), intent(inout) :: this
character(len=*), intent(in) :: name
integer, intent(in) :: dim_indices(:)
integer varindex
! EO parameters
include "netcdf.inc"
varindex = this%add_var_x(name, dim_indices, nf_int)
end function add_var_int
function add_var_x(this, name, dim_indices, netcdf_datatype) result(varindex)
class(netcdf_file_type), intent(inout) :: this
character(len=*), intent(in) :: name
integer, intent(in) :: dim_indices(:)
integer netcdf_datatype
integer varindex
! EO parameters
include "netcdf.inc"
type(var_type), allocatable :: tmparr(:)
! assume the vars array is allocated
allocate( tmparr(size(this%vars)+1) )
tmparr(1:size(this%vars)) = this%vars(:)
deallocate(this%vars)
call move_alloc(tmparr, this%vars)
varindex = size(this%vars)
! this%vars(varindex) = var_type(name=name, dim_indices=dim_indices, datatype=netcdf_datatype, atts=empty_atts, ncid=-1)
! NVIDIA 22.1 compiler didnt like the line above, hence we unfold it unelegantly:
this%vars(varindex)%name = name
this%vars(varindex)%dim_indices= dim_indices
this%vars(varindex)%datatype = netcdf_datatype
this%vars(varindex)%ncid = -1
end function add_var_x
subroutine add_global_att_text(this, att_name, att_text)
class(netcdf_file_type), intent(inout) :: this
character(len=*), intent(in) :: att_name
character(len=*), intent(in) :: att_text
! EO parameters
type(att_type_wrapper), allocatable :: tmparr(:)
allocate( tmparr(size(this%gatts)+1) )
tmparr(1:size(this%gatts)) = this%gatts
deallocate(this%gatts)
call move_alloc(tmparr, this%gatts)
this%gatts( size(this%gatts) )%it = att_type_text(name=att_name, text=att_text)
end subroutine add_global_att_text
subroutine add_global_att_int(this, att_name, att_val)
class(netcdf_file_type), intent(inout) :: this
character(len=*), intent(in) :: att_name
integer, intent(in) :: att_val
! EO parameters
type(att_type_wrapper), allocatable :: tmparr(:)
allocate( tmparr(size(this%gatts)+1) )
tmparr(1:size(this%gatts)) = this%gatts
deallocate(this%gatts)
call move_alloc(tmparr, this%gatts)
this%gatts( size(this%gatts) )%it = att_type_int(name=att_name, val=att_val)
end subroutine add_global_att_int
subroutine add_var_att_text(this, varindex, att_name, att_text)
class(netcdf_file_type), intent(inout) :: this
integer, intent(in) :: varindex
character(len=*), intent(in) :: att_name
character(len=*), intent(in) :: att_text
! EO parameters
type(att_type_wrapper), allocatable :: tmparr(:)
type(att_type_text) att
! add this att_type instance to atts array
this%vars(varindex)%atts_count = this%vars(varindex)%atts_count +1
call assert(size(this%vars(varindex)%atts) >= this%vars(varindex)%atts_count, __LINE__)
att = att_type_text(name=att_name, text=att_text)
allocate( this%vars(varindex)%atts( this%vars(varindex)%atts_count )%it, source=att )
end subroutine add_var_att_text
subroutine add_var_att_int(this, varindex, att_name, att_val)
class(netcdf_file_type), intent(inout) :: this
integer, intent(in) :: varindex
character(len=*), intent(in) :: att_name
integer, intent(in) :: att_val
! EO parameters
type(att_type_wrapper), allocatable :: tmparr(:)
type(att_type_int) att
! add this att_type instance to atts array
this%vars(varindex)%atts_count = this%vars(varindex)%atts_count +1
call assert(size(this%vars(varindex)%atts) >= this%vars(varindex)%atts_count, __LINE__)
att = att_type_int(name=att_name, val=att_val)
allocate( this%vars(varindex)%atts( this%vars(varindex)%atts_count )%it, source=att )
end subroutine add_var_att_int
function is_attached(this) result(x)
class(netcdf_file_type), intent(in) :: this
logical x
! EO parameters
x = (this%filepath .ne. "")
end function is_attached
subroutine open_read(this, filepath)
class(netcdf_file_type), intent(inout) :: this
character(len=*), intent(in) :: filepath
! EO parameters
include "netcdf.inc"
integer mode
mode = nf_nowrite
this%filepath = filepath
call assert_nc( nf_open(this%filepath, mode, this%ncid) , __LINE__)
! attach our dims and vars to their counterparts in the file
call this%attach_dims_vars_to_file()
end subroutine open_read
! return an array with the dimension sizes for all dimensions of the given variable
! this currently only makes sense for variables with unlimited dimensions,
! as all other dimensions must be known when adding the variable to the file specification, e.g before reading the file
subroutine read_var_shape(this, varindex, varshape)
class(netcdf_file_type), target, intent(in) :: this
integer, intent(in) :: varindex
integer, allocatable, intent(out) :: varshape(:)
! EO parameters
include "netcdf.inc"
type(var_type), pointer :: var
integer var_ndims
integer i
var => this%vars(varindex)
var_ndims = size(var%dim_indices)
if(allocated(varshape)) deallocate(varshape)
allocate(varshape(var_ndims))
do i=1, var_ndims
if(this%dims( var%dim_indices(i) )%len == nf_unlimited) then
! actually read from the file
call assert_nc( nf_inq_dimlen(this%ncid, this%dims( var%dim_indices(i) )%ncid, varshape(i)) , __LINE__)
else
! use the dim size which has been set without the file and is thus known anyway to the user
varshape(i) = this%dims( var%dim_indices(i) )%len
end if
end do
end subroutine read_var_shape
! values array is not required to have the same shape as the variable but must fit the product of all items of the sizes array
! this way we can retrieve e.g. data from a 3D variable to a 2D array with one size set to 1 (e.g. to get a single timestep)
! starts and sizes must have the same rank as the variable has dimensions
subroutine read_var_r8(this, varindex, starts, sizes, values)
use, intrinsic :: ISO_C_BINDING
class(netcdf_file_type), intent(in) :: this
integer, intent(in) :: varindex
integer, dimension(:) :: starts, sizes
real(8), intent(inout), target :: values(:) ! must be inout or the allocation might be screwed
! EO parameters
include "netcdf.inc"
real(8), pointer :: values_ptr(:)
call assert(size(sizes) == size(starts), __LINE__)
call assert(size(starts) == size(this%vars(varindex)%dim_indices), __LINE__)
call assert(product(sizes) == product(shape(values)), __LINE__)
call c_f_pointer(c_loc(values), values_ptr, [product(shape(values))])
call assert_nc(nf_get_vara_double(this%ncid, this%vars(varindex)%ncid, starts, sizes, values_ptr), __LINE__)
end subroutine read_var_r8
! see read_var_r8 for usage comment
subroutine read_var_r4(this, varindex, starts, sizes, values)
use, intrinsic :: ISO_C_BINDING
class(netcdf_file_type), intent(in) :: this
integer, intent(in) :: varindex
integer, dimension(:) :: starts, sizes
real(4), intent(inout), target :: values(:) ! must be inout or the allocation might be screwed
! EO parameters
include "netcdf.inc"
real(4), pointer :: values_ptr(:)
call assert(size(sizes) == size(starts), __LINE__)
call assert(size(starts) == size(this%vars(varindex)%dim_indices), __LINE__)
call assert(product(sizes) == product(shape(values)), __LINE__)
call c_f_pointer(c_loc(values), values_ptr, [product(shape(values))])
call assert_nc(nf_get_vara_real(this%ncid, this%vars(varindex)%ncid, starts, sizes, values_ptr), __LINE__)
end subroutine read_var_r4
! see read_var_r8 for usage comment
subroutine read_var_integer(this, varindex, starts, sizes, values)
use, intrinsic :: ISO_C_BINDING
class(netcdf_file_type), intent(in) :: this
integer, intent(in) :: varindex
integer, dimension(:) :: starts, sizes
integer, intent(inout), target :: values(:) ! must be inout or the allocation might be screwed
! EO parameters
include "netcdf.inc"
integer, pointer :: values_ptr(:)
call assert(size(sizes) == size(starts), __LINE__)
call assert(size(starts) == size(this%vars(varindex)%dim_indices), __LINE__)
call assert(product(sizes) == product(shape(values)), __LINE__)
call c_f_pointer(c_loc(values), values_ptr, [product(shape(values))])
call assert_nc(nf_get_vara_int(this%ncid, this%vars(varindex)%ncid, starts, sizes, values_ptr), __LINE__)
end subroutine read_var_integer
! retrieve a single value specified via the indices array
subroutine read_var1_r8(this, varindex, indices, value)
use, intrinsic :: ISO_C_BINDING
class(netcdf_file_type), intent(in) :: this
integer, intent(in) :: varindex
integer, dimension(:) :: indices
real(8), intent(out) :: value
! EO parameters
include "netcdf.inc"
call assert(size(indices) == size(this%vars(varindex)%dim_indices), __LINE__)
call assert_nc(nf_get_var1_double(this%ncid, this%vars(varindex)%ncid, indices, value), __LINE__)
end subroutine read_var1_r8
! see read_var1_r8 for usage comment
subroutine read_var1_r4(this, varindex, indices, value)
use, intrinsic :: ISO_C_BINDING
class(netcdf_file_type), intent(in) :: this
integer, intent(in) :: varindex
integer, dimension(:) :: indices
real(4), intent(out) :: value
! EO parameters
include "netcdf.inc"
call assert(size(indices) == size(this%vars(varindex)%dim_indices), __LINE__)
call assert_nc(nf_get_var1_real(this%ncid, this%vars(varindex)%ncid, indices, value), __LINE__)
end subroutine read_var1_r4
! see read_var1_r8 for usage comment
subroutine read_var1_integer(this, varindex, indices, value)
use, intrinsic :: ISO_C_BINDING
class(netcdf_file_type), intent(in) :: this
integer, intent(in) :: varindex
integer, dimension(:) :: indices
integer, intent(out) :: value
! EO parameters
include "netcdf.inc"
call assert(size(indices) == size(this%vars(varindex)%dim_indices), __LINE__)
call assert_nc(nf_get_var1_int(this%ncid, this%vars(varindex)%ncid, indices, value), __LINE__)
end subroutine read_var1_integer
subroutine open_write_create(this, filepath)
class(netcdf_file_type), target, intent(inout) :: this
character(len=*), intent(in) :: filepath
! EO parameters
include "netcdf.inc"
integer cmode
integer i, ii
integer var_ndims
integer, allocatable :: var_dimids(:)
character(:), pointer :: att_name
character(:), pointer :: att_text
this%filepath = filepath
cmode = ior(nf_noclobber, ior(nf_netcdf4, nf_classic_model))
call assert_nc( nf_create(filepath, cmode, this%ncid) , __LINE__)
! create our dims in the file
do i=1, size(this%dims)
call assert_nc( nf_def_dim(this%ncid, this%dims(i)%name, this%dims(i)%len, this%dims(i)%ncid) , __LINE__)
end do
do i=1, size(this%gatts)
call this%gatts(i)%it%define_in_var(this%ncid, nf_global)
end do
! create our vars in the file
do i=1, size(this%vars)
var_ndims = size(this%vars(i)%dim_indices)
if(allocated(var_dimids)) deallocate(var_dimids)
allocate(var_dimids(var_ndims))
do ii=1, var_ndims
var_dimids(ii) = this%dims( this%vars(i)%dim_indices(ii) )%ncid
end do
call assert_nc( nf_def_var(this%ncid, this%vars(i)%name, this%vars(i)%datatype, var_ndims, var_dimids, this%vars(i)%ncid) , __LINE__)
do ii=1, this%vars(i)%atts_count
call this%vars(i)%atts(ii)%it%define_in_var(this%ncid, this%vars(i)%ncid)
end do
end do
call assert_nc( nf_enddef(this%ncid), __LINE__ )
end subroutine open_write_create
! open an existing file and prepare to write data to it
subroutine open_write_append(this, filepath)
class(netcdf_file_type), intent(inout) :: this
character(len=*), intent(in) :: filepath
! EO parameters
include "netcdf.inc"
integer cmode
this%filepath = filepath
cmode = nf_write
call assert_nc( nf_open(filepath, cmode, this%ncid) , __LINE__)
! make sure that all our dims and vars exist in this file and get hold of them
call this%attach_dims_vars_to_file()
end subroutine open_write_append
subroutine write_var_r8(this, varindex, starts, sizes, values)
use, intrinsic :: ISO_C_BINDING
class(netcdf_file_type), intent(in) :: this
integer, intent(in) :: varindex
integer, dimension(:) :: starts, sizes
real(8), intent(in), target :: values(:) ! must be inout or the allocation might be screwed
! EO parameters
include "netcdf.inc"
real(8), pointer :: values_ptr(:)
call assert(size(sizes) == size(starts), __LINE__)
call assert(size(starts) == size(this%vars(varindex)%dim_indices), __LINE__)
call assert(product(sizes) == product(shape(values)), __LINE__)
call c_f_pointer(c_loc(values), values_ptr, [product(shape(values))])
call assert_nc(nf_put_vara_double(this%ncid, this%vars(varindex)%ncid, starts, sizes, values_ptr), __LINE__)
end subroutine write_var_r8
subroutine write_var_r4(this, varindex, starts, sizes, values)
use, intrinsic :: ISO_C_BINDING
class(netcdf_file_type), intent(in) :: this
integer, intent(in) :: varindex
integer, dimension(:) :: starts, sizes
real(4), intent(in), target :: values(:) ! must be inout or the allocation might be screwed
! EO parameters
include "netcdf.inc"
real(4), pointer :: values_ptr(:)
call assert(size(sizes) == size(starts), __LINE__)
call assert(size(starts) == size(this%vars(varindex)%dim_indices), __LINE__)
call assert(product(sizes) == product(shape(values)), __LINE__)
call c_f_pointer(c_loc(values), values_ptr, [product(shape(values))])
call assert_nc(nf_put_vara_real(this%ncid, this%vars(varindex)%ncid, starts, sizes, values_ptr), __LINE__)
end subroutine write_var_r4
subroutine write_var_integer(this, varindex, starts, sizes, values)
use, intrinsic :: ISO_C_BINDING
class(netcdf_file_type), intent(in) :: this
integer, intent(in) :: varindex
integer, dimension(:) :: starts, sizes
integer, intent(in), target :: values(:) ! must be inout or the allocation might be screwed
! EO parameters
include "netcdf.inc"
integer, pointer :: values_ptr(:)
call assert(size(sizes) == size(starts), __LINE__)
call assert(size(starts) == size(this%vars(varindex)%dim_indices), __LINE__)
call assert(product(sizes) == product(shape(values)), __LINE__)
call c_f_pointer(c_loc(values), values_ptr, [product(shape(values))])
call assert_nc(nf_put_vara_int(this%ncid, this%vars(varindex)%ncid, starts, sizes, values_ptr), __LINE__)
end subroutine write_var_integer
subroutine flush_file(this)
class(netcdf_file_type), intent(inout) :: this
! EO parameters
include "netcdf.inc"
call assert_nc( nf_sync(this%ncid), __LINE__ ) ! flush the file to disk
end subroutine flush_file
subroutine close_file(this)
! do not implicitly close the file (e.g. upon deallocation via destructor), as we might have a copy of this object with access to the same ncid
class(netcdf_file_type), intent(inout) :: this
! EO parameters
include "netcdf.inc"
call assert_nc( nf_close(this%ncid) , __LINE__)
this%filepath = ""
end subroutine close_file
! connect our dims and vars to their counterparts in the NetCDF file, bail out if they do not match
! ignore any additional dims and vars the file might contain
subroutine attach_dims_vars_to_file(this)
class(netcdf_file_type), intent(inout) :: this
! EO parameters
include "netcdf.inc"
integer i, ii
integer actual_len
integer actual_dimcount
integer, allocatable :: actual_dimids(:)
integer exp_dimid, act_dimid
integer actual_datatype
do i=1, size(this%dims)
call assert_nc( nf_inq_dimid(this%ncid, this%dims(i)%name, this%dims(i)%ncid) , __LINE__)
call assert_nc( nf_inq_dimlen(this%ncid, this%dims(i)%ncid, actual_len) , __LINE__)
if(this%dims(i)%len .ne. nf_unlimited) call assert(this%dims(i)%len == actual_len, __LINE__)
end do
do i=1, size(this%vars)
call assert_nc( nf_inq_varid(this%ncid, this%vars(i)%name, this%vars(i)%ncid) , __LINE__)
! see if this var has the expected datatype
call assert_nc( nf_inq_vartype(this%ncid, this%vars(i)%ncid, actual_datatype) , __LINE__)
call assert(this%vars(i)%datatype == actual_datatype, __LINE__)
! see if this var has the expected dims
call assert_nc( nf_inq_varndims(this%ncid, this%vars(i)%ncid, actual_dimcount) , __LINE__)
call assert(size(this%vars(i)%dim_indices) == actual_dimcount, __LINE__)
if(allocated(actual_dimids)) deallocate(actual_dimids)
allocate(actual_dimids(actual_dimcount))
call assert_nc( nf_inq_vardimid(this%ncid, this%vars(i)%ncid, actual_dimids) , __LINE__)
do ii=1, actual_dimcount
exp_dimid = this%dims( this%vars(i)%dim_indices(ii) )%ncid
call assert(exp_dimid == actual_dimids(ii), __LINE__)
end do
end do
end subroutine attach_dims_vars_to_file
subroutine assert(val, line)
logical, intent(in) :: val
integer, intent(in) :: line
! EO parameters
if(.not. val) then
print *, "error in line ",line, __FILE__
stop 1
end if
end subroutine assert
subroutine assert_nc(status, line)
integer, intent(in) :: status
integer, intent(in) :: line
! EO parameters
include "netcdf.inc"
if(status /= nf_noerr) then
print *, "error in line ",line, __FILE__, ' ', trim(nf_strerror(status))
stop 1
endif
end subroutine assert_nc
end module io_netcdf_file_module