forked from ESCOMP/POP2-CESM
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathio_types.F90
3639 lines (2824 loc) · 110 KB
/
io_types.F90
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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
module io_types
!BOP
!
! !MODULE: io_types
!
! !DESCRIPTION:
! This module contains the declarations for all required io
! data types and several operators for those data types. It also
! contains several global parameters used by various io operations
! and an io unit manager.
!
! !REVISION HISTORY:
! SVN:$Id$
! !USES:
use POP_KindsMod
use POP_IOUnitsMod
use kinds_mod
use constants
use communicate
use broadcast
use exit_mod
#ifdef CCSMCOUPLED
use shr_file_mod
use pio
#endif
implicit none
private
save
! !PUBLIC TYPES:
type, public :: io_dim
integer(i4) :: id
integer(i4) :: length ! 1 to n, but 0 means unlimited
integer(i4) :: start, stop, stride ! For slicing and dicing
logical(log_kind) :: active
character(char_len) :: name
character(char_len) :: units
end type
! Generic IO field descriptor
type, public :: io_field_desc
character(char_len) :: short_name
character(char_len) :: long_name
character(char_len) :: units
character(char_len) :: coordinates
character(4) :: grid_loc
real(r4), dimension(2) :: valid_range
integer(i4) :: id
integer(i4) :: nfield_dims
integer(i4) :: field_loc
integer(i4) :: field_type
type (io_dim), dimension(4) :: field_dim
character(char_len), dimension(:), pointer :: add_attrib_cname
character(char_len), dimension(:), pointer :: add_attrib_cval
character(char_len), dimension(:), pointer :: add_attrib_lname
logical (log_kind), dimension(:), pointer :: add_attrib_lval
character(char_len), dimension(:), pointer :: add_attrib_iname
integer (i4), dimension(:), pointer :: add_attrib_ival
character(char_len), dimension(:), pointer :: add_attrib_rname
real (r4), dimension(:), pointer :: add_attrib_rval
character(char_len), dimension(:), pointer :: add_attrib_dname
real (r8), dimension(:), pointer :: add_attrib_dval
! Only one of these next 12 pointers can be associated.
! The others must be nullified. For convenience in
! initialization, these declarations are the last listed
! in this type.
integer(i4), dimension(:), pointer :: field_i_1d
integer(i4), dimension(:,:,:), pointer :: field_i_2d
integer(i4), dimension(:,:,:,:), pointer :: field_i_3d
real(r4), pointer :: field_r_0d
real(r4), dimension(:), pointer :: field_r_1d
real(r4), dimension(:,:,:), pointer :: field_r_2d
real(r4), dimension(:,:,:,:), pointer :: field_r_3d
real(r8), pointer :: field_d_0d
real(r8), dimension(:), pointer :: field_d_1d
real(r8), dimension(:,:,:), pointer :: field_d_2d
real(r8), dimension(:,:,:,:), pointer :: field_d_3d
type (VAR_desc_t) :: varDesc
type (IO_desc_t), pointer :: ioDesc
logical :: set_ioDesc
logical :: set_ioFrame
end type
! Generic data file descriptor
type, public :: datafile
character(char_len) :: full_name
character(char_len) :: data_format ! .bin or
! .nc or
! piobin or pioncd
character(char_len) :: root_name
character(char_len) :: file_suffix
integer(i4), dimension (2) :: id ! LUN (binary) or
! NCID (netcdf)
character(char_len) :: title
character(char_len) :: history
character(char_len) :: conventions
character(char_len), dimension(:), pointer :: add_attrib_cname
character(char_len), dimension(:), pointer :: add_attrib_cval
logical (log_kind), dimension(:), pointer :: add_attrib_cval_from_file
character(char_len), dimension(:), pointer :: add_attrib_lname
logical (log_kind), dimension(:), pointer :: add_attrib_lval
logical (log_kind), dimension(:), pointer :: add_attrib_lval_from_file
character(char_len), dimension(:), pointer :: add_attrib_iname
integer (i4), dimension(:), pointer :: add_attrib_ival
logical (log_kind), dimension(:), pointer :: add_attrib_ival_from_file
character(char_len), dimension(:), pointer :: add_attrib_rname
real (r4), dimension(:), pointer :: add_attrib_rval
logical (log_kind), dimension(:), pointer :: add_attrib_rval_from_file
character(char_len), dimension(:), pointer :: add_attrib_dname
real (r8), dimension(:), pointer :: add_attrib_dval
logical (log_kind), dimension(:), pointer :: add_attrib_dval_from_file
integer(i4) :: num_iotasks
integer(i4) :: record_length
integer(i4) :: current_record ! bin
logical(log_kind) :: readonly
logical(log_kind) :: ldefine
type (File_desc_t) :: File
end type
! !PUBLIC MEMBER FUNCTIONS:
public :: get_unit, &
release_unit, &
construct_file, &
destroy_file, &
add_attrib_file, &
extract_attrib_file, &
construct_io_field, &
destroy_io_field, &
construct_io_dim, &
add_attrib_io_field, &
extract_attrib_io_field, &
init_io
! !PUBLIC DATA MEMBERS:
#ifndef CCSMCOUPLED
integer (i4), parameter, public :: &
nml_in = 10, &! reserved unit for namelist input
stdin = 5, &! reserved unit for standard input
stdout = 6, &! reserved unit for standard output
stderr = 6 ! reserved unit for standard error
#else
integer (i4), public :: &
nml_in ! reserved unit for namelist input
integer (i4), public :: &
stdout = 6, &! reserved unit for standard output
stdin = 5, &! reserved unit for standard input
stderr = 6 ! reserved unit for standard error
#endif
integer (i4), parameter, public :: &
rec_type_int = -1, &! ids to use for inquiring the
rec_type_real = -2, &! record length to use for binary files
rec_type_dbl = -3 !
character (12), public :: &
nml_filename = 'pop_in' ! namelist input file name
integer (i4), public :: &
num_iotasks ! num of procs to use for parallel io
! if output format is 'netcdf'. Then it is 1.
logical (log_kind), public :: &
luse_pointer_files ! use files to point to location of restarts
character (char_len), public :: &
pointer_filename ! filename to use for pointer files
!EOP
!BOC
!-----------------------------------------------------------------------
!
! io unit manager variables
!
!-----------------------------------------------------------------------
integer (i4), parameter, private :: &
max_units = 99 ! maximum number of open units
logical (log_kind), dimension(max_units), private :: &
in_use ! flag=.true. if unit currently open
!-----------------------------------------------------------------------
!
! other module variables
!
!-----------------------------------------------------------------------
logical (log_kind), private :: &
lredirect_stdout ! redirect stdout to log file
character (char_len), private :: &
log_filename ! root name for log file
!-----------------------------------------------------------------------
!
! generic interface definitions
!
!-----------------------------------------------------------------------
interface add_attrib_file
module procedure add_attrib_file_char, &
add_attrib_file_log, &
add_attrib_file_int, &
add_attrib_file_real, &
add_attrib_file_dbl
end interface
interface extract_attrib_file
module procedure extract_attrib_file_char, &
extract_attrib_file_log, &
extract_attrib_file_int, &
extract_attrib_file_real, &
extract_attrib_file_dbl
end interface
interface add_attrib_io_field
module procedure add_attrib_io_field_char, &
add_attrib_io_field_log, &
add_attrib_io_field_int, &
add_attrib_io_field_real, &
add_attrib_io_field_dbl
end interface
interface extract_attrib_io_field
module procedure extract_attrib_io_field_char, &
extract_attrib_io_field_log, &
extract_attrib_io_field_int, &
extract_attrib_io_field_real, &
extract_attrib_io_field_dbl
end interface
!EOC
!***********************************************************************
contains
!***********************************************************************
!BOP
! !IROUTINE: construct_file
! !INTERFACE:
function construct_file ( &
data_format, &
! Optional arguments begin here
full_name, &
root_name, &
file_suffix, &
id, &
title, &
history, &
conventions, &
record_length, &
recl_words, &
current_record, &
input_num_iotasks &
) &
result (descriptor)
! !DESCRIPTION:
! This routine constructs a file descriptor for use in io routines.
! It fills in every field to guarantee that the descriptor
! will contain no illegal field values upon exit. The data format
! is required together with either a full name or root name.
! If full name is supplied, that name will be used in all file
! operations. If root name is supplied, the full name will be
! constructed using rootname.suffix.dataformat.
!
! !REVISION HISTORY:
! same as module
! !INPUT PARAMETERS:
character(*), intent(in) :: &
data_format ! bin (binary) or nc (netCDF)
character(*), intent(in), optional :: &
full_name, &! name (and path) for file
root_name, &! file name root
file_suffix, &! suffix (eg model day, step)
title, &! descriptive name for the file
history, &! file history string
conventions ! conventions for file
integer (i4), dimension (2), intent(in), optional :: &
id ! unit numbers for binary file & hdr
! netCDF id for netCDF file
integer (i4), intent(in), optional :: &
input_num_iotasks, &! to override default iotasks
record_length, &! record length type for binary files
recl_words, &! num words per record for binary files
current_record ! current record number in binary file
! !OUTPUT PARAMETERS:
type (datafile) :: descriptor ! data file descriptor
!EOP
!BOC
!-----------------------------------------------------------------------
!
! local variables
!
!-----------------------------------------------------------------------
integer (i4) :: &
n, &! loop index
io_record_length ! actual record length
integer (i4), dimension(:), allocatable :: work_i
real (r4), dimension(:), allocatable :: work_r
real (r8), dimension(:), allocatable :: work_d
!-----------------------------------------------------------------------
!
! define data format
!
!-----------------------------------------------------------------------
descriptor%data_format = char_blank
descriptor%data_format = trim(data_format)
!-----------------------------------------------------------------------
!
! file naming stuff
! if full name is present, use that as filename
! if root name and suffix supplied, construct file name from those
!
!-----------------------------------------------------------------------
if (present(full_name)) then
descriptor%full_name = char_blank
descriptor%full_name = trim(full_name)
else if (present(root_name)) then
descriptor%root_name = char_blank
descriptor%root_name = trim(root_name)
descriptor%file_suffix = char_blank
if (present(file_suffix)) then
if (trim(data_format) == 'nc') then
if (trim(file_suffix) == '') then
descriptor%file_suffix = trim(file_suffix)/&
&/trim(data_format)
else
descriptor%file_suffix = trim(file_suffix)/&
&/'.'/&
&/trim(data_format)
endif
else
descriptor%file_suffix = trim(file_suffix)
endif
else
if (trim(data_format) == 'nc') &
descriptor%file_suffix = trim(data_format)
end if
descriptor%full_name = char_blank
if (trim(descriptor%file_suffix) /= '') then
descriptor%full_name = trim(descriptor%root_name)/&
&/'.'/&
&/trim(descriptor%file_suffix)
else
descriptor%full_name = trim(descriptor%root_name)/&
&/'.'/&
&/trim(descriptor%file_suffix)
endif
else
call exit_POP(sigAbort, &
'construct_file: can not determine file name')
endif
!-----------------------------------------------------------------------
!
! parameters specific to binary files
!
!-----------------------------------------------------------------------
if (descriptor%data_format=='bin') then
!*** assign unit numbers as file id
!*** if not assigned as input, assign later during file open
if (present(id)) then
descriptor%id = id
else
descriptor%id = 0
endif
!*** number of io tasks for parallel io
if (present(input_num_iotasks)) then
!*** override namelist input - useful if you need
!*** to serial i/o for a particular file in binary mode
descriptor%num_iotasks = input_num_iotasks
else
descriptor%num_iotasks = num_iotasks ! namelist input
endif
!*** compute record length
if (present(record_length)) then
if (.not. present(recl_words)) &
call exit_POP(sigAbort, &
'construct_file: must supply recl_words')
select case (record_length)
case (rec_type_int)
io_record_length = POP_i4_size*recl_words
!MEMSAVE allocate (work_i(recl_words))
!MEMSAVE inquire (iolength=io_record_length) work_i
!MEMSAVE deallocate (work_i)
case (rec_type_real)
io_record_length = POP_r4_size*recl_words
!MEMSAVE allocate (work_r(recl_words))
!MEMSAVE inquire (iolength=io_record_length) work_r
!MEMSAVE deallocate (work_r)
case (rec_type_dbl)
io_record_length = POP_r8_size*recl_words
!MEMSAVE allocate (work_d(recl_words))
!MEMSAVE inquire (iolength=io_record_length) work_d
!MEMSAVE deallocate (work_d)
case default
io_record_length = 0
end select
else
io_record_length = 0
endif
descriptor%record_length = io_record_length
!*** initialize first record
if (present(current_record)) then
descriptor%current_record = current_record
else
descriptor%current_record = 1
endif
!-----------------------------------------------------------------------
!
! parameters specific to netCDF files
!
!-----------------------------------------------------------------------
else
!*** set id if already known, otherwise defined during file open
if (present(id)) then
descriptor%id = id
else
descriptor%id = 0 ! to be defined during open
endif
descriptor%num_iotasks = 1 ! netCDF can only do serial i/o
descriptor%record_length = 0 ! not used for netCDF
descriptor%current_record = 0 ! not used for netCDF
endif
!-----------------------------------------------------------------------
!
! general descriptive info for files
!
!-----------------------------------------------------------------------
descriptor%title = char_blank
if (present(title)) then
descriptor%title = trim(title)
else
descriptor%title = 'none'
endif
descriptor%history = char_blank
if (present(history)) then
descriptor%history = trim(history)
else
descriptor%history = 'none'
endif
descriptor%conventions = char_blank
if (present(conventions)) then
descriptor%conventions = trim(conventions)
else
descriptor%conventions = 'none'
endif
!-----------------------------------------------------------------------
!
! initialize global file attributes - these must be set separately
! in the routine add_attrib_file.
!
!-----------------------------------------------------------------------
descriptor%readonly = .false. ! reset later if necessary
nullify (descriptor%add_attrib_cname)
nullify (descriptor%add_attrib_cval)
nullify (descriptor%add_attrib_cval_from_file)
nullify (descriptor%add_attrib_lname)
nullify (descriptor%add_attrib_lval)
nullify (descriptor%add_attrib_lval_from_file)
nullify (descriptor%add_attrib_iname)
nullify (descriptor%add_attrib_ival)
nullify (descriptor%add_attrib_ival_from_file)
nullify (descriptor%add_attrib_rname)
nullify (descriptor%add_attrib_rval)
nullify (descriptor%add_attrib_rval_from_file)
nullify (descriptor%add_attrib_dname)
nullify (descriptor%add_attrib_dval)
nullify (descriptor%add_attrib_dval_from_file)
!-----------------------------------------------------------------------
!EOC
end function construct_file
!***********************************************************************
!BOP
! !IROUTINE: add_attrib_file_char
! !INTERFACE:
subroutine add_attrib_file_char(file_descr, att_name, att_value, from_file)
! !DESCRIPTION:
! This routine adds a global file attribute to an io file. This
! particular instantiation adds a character attribute, but is aliased
! to the generic routine name add\_attrib\_file.
!
! !REVISION HISTORY:
! same as module
! !INPUT PARAMETERS:
character (*), intent(in) :: &
att_name, &! name of attribute to be added
att_value ! value of attribute to be added
logical (log_kind), optional, intent(in) :: &
from_file ! is att_value known to be from a file?
! !INPUT/OUTPUT PARAMETERS:
type (datafile), intent(inout) :: &
file_descr ! data file descriptor
!EOP
!BOC
!-----------------------------------------------------------------------
!
! local variables
!
!-----------------------------------------------------------------------
integer (i4) :: &
n, &! loop index
num_attribs ! current number of attributes defined
character (char_len), dimension(:), allocatable :: &
name_tmp, &! temp space for resizing attrib name array
val_tmp ! temp space for resizing attrib value array
logical (log_kind), dimension(:), allocatable :: &
val_from_file_tmp ! temp space for resizing attrib val_from_file array
logical (log_kind) :: &
att_exists, &! attribute already defined
from_file_loc ! local value of from_file
!-----------------------------------------------------------------------
from_file_loc = .false.
if (present(from_file)) from_file_loc = from_file
!-----------------------------------------------------------------------
!
! if this is the first attribute, allocate space and set the attribute
!
!-----------------------------------------------------------------------
if (.not. associated(file_descr%add_attrib_cval)) then
allocate(file_descr%add_attrib_cval(1), &
file_descr%add_attrib_cname(1), &
file_descr%add_attrib_cval_from_file(1))
file_descr%add_attrib_cval (1) = char_blank
file_descr%add_attrib_cname(1) = char_blank
file_descr%add_attrib_cval (1) = trim(att_value)
file_descr%add_attrib_cname(1) = trim(att_name)
file_descr%add_attrib_cval_from_file(1) = from_file_loc
!-----------------------------------------------------------------------
!
! if not the first, see if it already exists and over-write value
! if does not exist, resize the attribute array and store the
! attributes
!
!-----------------------------------------------------------------------
else
att_exists = .false.
num_attribs = size(file_descr%add_attrib_cval(:))
att_search: do n=1,num_attribs
if (trim(file_descr%add_attrib_cname(n)) == trim(att_name)) then
file_descr%add_attrib_cval(n) = char_blank
file_descr%add_attrib_cval(n) = trim(att_value)
file_descr%add_attrib_cval_from_file(n) = from_file_loc
att_exists = .true.
exit att_search
endif
end do att_search
if (.not. att_exists) then
allocate(name_tmp(num_attribs), val_tmp(num_attribs), val_from_file_tmp(num_attribs))
name_tmp(:) = file_descr%add_attrib_cname(:)
val_tmp (:) = file_descr%add_attrib_cval (:)
val_from_file_tmp(:) = file_descr%add_attrib_cval_from_file(:)
deallocate(file_descr%add_attrib_cname)
deallocate(file_descr%add_attrib_cval )
deallocate(file_descr%add_attrib_cval_from_file)
num_attribs = num_attribs + 1
allocate(file_descr%add_attrib_cname(num_attribs), &
file_descr%add_attrib_cval (num_attribs), &
file_descr%add_attrib_cval_from_file(num_attribs))
file_descr%add_attrib_cname(:) = char_blank
file_descr%add_attrib_cval (:) = char_blank
do n=1,num_attribs-1
file_descr%add_attrib_cname(n) = trim(name_tmp(n))
file_descr%add_attrib_cval (n) = trim( val_tmp(n))
file_descr%add_attrib_cval_from_file(n) = val_from_file_tmp(n)
end do
file_descr%add_attrib_cname(num_attribs) = trim(att_name)
file_descr%add_attrib_cval (num_attribs) = trim(att_value)
file_descr%add_attrib_cval_from_file(num_attribs) = from_file_loc
deallocate(name_tmp,val_tmp,val_from_file_tmp)
endif
endif
!-----------------------------------------------------------------------
!EOC
end subroutine add_attrib_file_char
!***********************************************************************
!BOP
! !IROUTINE: add_attrib_file_log
! !INTERFACE:
subroutine add_attrib_file_log(file_descr, att_name, att_value, from_file)
! !DESCRIPTION:
! This routine adds a global file attribute to an io file. This
! particular instantiation adds a logical attribute, but is aliased
! to the generic routine name add\_attrib\_file.
!
! !REVISION HISTORY:
! same as module
! !INPUT PARAMETERS:
character (*), intent(in) :: &
att_name ! name of attribute to be added
logical (log_kind), intent(in) :: &
att_value ! value of attribute to be added
logical (log_kind), optional, intent(in) :: &
from_file ! is att_value known to be from a file?
! !INPUT/OUTPUT PARAMETERS:
type (datafile), intent(inout) :: &
file_descr ! data file descriptor
!EOP
!BOC
!-----------------------------------------------------------------------
!
! local variables
!
!-----------------------------------------------------------------------
integer (i4) :: &
n, &! loop index
num_attribs ! current number of attributes defined
character (char_len), dimension(:), allocatable :: &
name_tmp ! temp space for resizing attrib name array
logical (log_kind), dimension(:), allocatable :: &
val_tmp, &! temp space for resizing attrib value array
val_from_file_tmp ! temp space for resizing attrib val_from_file array
logical (log_kind) :: &
att_exists, &! attribute already defined
from_file_loc ! local value of from_file
!-----------------------------------------------------------------------
from_file_loc = .false.
if (present(from_file)) from_file_loc = from_file
!-----------------------------------------------------------------------
!
! if this is the first attribute, allocate space and set the attribute
!
!-----------------------------------------------------------------------
if (.not. associated(file_descr%add_attrib_lval)) then
allocate(file_descr%add_attrib_lval(1), &
file_descr%add_attrib_lname(1), &
file_descr%add_attrib_lval_from_file(1))
file_descr%add_attrib_lval (1) = att_value
file_descr%add_attrib_lname(1) = char_blank
file_descr%add_attrib_lname(1) = trim(att_name)
file_descr%add_attrib_lval_from_file(1) = from_file_loc
!-----------------------------------------------------------------------
!
! if not the first, see if it already exists and over-write value
! if does not exist, resize the attribute array and store the
! attributes
!
!-----------------------------------------------------------------------
else
att_exists = .false.
num_attribs = size(file_descr%add_attrib_lval(:))
att_search: do n=1,num_attribs
if (trim(file_descr%add_attrib_lname(n)) == trim(att_name)) then
file_descr%add_attrib_lval(n) = att_value
file_descr%add_attrib_lval_from_file(n) = from_file_loc
att_exists = .true.
exit att_search
endif
end do att_search
if (.not. att_exists) then
allocate(name_tmp(num_attribs), val_tmp(num_attribs), val_from_file_tmp(num_attribs))
name_tmp(:) = file_descr%add_attrib_lname(:)
val_tmp (:) = file_descr%add_attrib_lval (:)
val_from_file_tmp(:) = file_descr%add_attrib_lval_from_file(:)
deallocate(file_descr%add_attrib_lname, &
file_descr%add_attrib_lval, &
file_descr%add_attrib_lval_from_file )
num_attribs = num_attribs + 1
allocate(file_descr%add_attrib_lname(num_attribs), &
file_descr%add_attrib_lval (num_attribs), &
file_descr%add_attrib_lval_from_file (num_attribs))
file_descr%add_attrib_lname(:) = char_blank
do n=1,num_attribs-1
file_descr%add_attrib_lname(n) = trim(name_tmp(n))
file_descr%add_attrib_lval (n) = val_tmp(n)
file_descr%add_attrib_lval_from_file(n) = val_from_file_tmp(n)
end do
file_descr%add_attrib_lname(num_attribs) = trim(att_name)
file_descr%add_attrib_lval (num_attribs) = att_value
file_descr%add_attrib_lval_from_file(num_attribs) = from_file_loc
deallocate(name_tmp,val_tmp,val_from_file_tmp)
endif
endif
!-----------------------------------------------------------------------
!EOC
end subroutine add_attrib_file_log
!***********************************************************************
!BOP
! !IROUTINE: add_attrib_file_int
! !INTERFACE:
subroutine add_attrib_file_int(file_descr, att_name, att_value, from_file)
! !DESCRIPTION:
! This routine adds a global file attribute to an io file. This
! particular instantiation adds an integer attribute, but is aliased
! to the generic routine name add\_attrib\_file.
!
! !REVISION HISTORY:
! same as module
! !INPUT PARAMETERS:
character (*), intent(in) :: &
att_name ! name of attribute to be added
integer (i4), intent(in) :: &
att_value ! value of attribute to be added
logical (log_kind), optional, intent(in) :: &
from_file ! is att_value known to be from a file?
! !INPUT/OUTPUT PARAMETERS:
type (datafile), intent(inout) :: &
file_descr ! data file descriptor
!EOP
!BOC
!-----------------------------------------------------------------------
!
! local variables
!
!-----------------------------------------------------------------------
integer (i4) :: &
n, &! loop index
num_attribs ! current number of attributes defined
character (char_len), dimension(:), allocatable :: &
name_tmp ! temp space for resizing attrib name array
integer (i4), dimension(:), allocatable :: &
val_tmp ! temp space for resizing attrib value array
logical (log_kind), dimension(:), allocatable :: &
val_from_file_tmp ! temp space for resizing attrib val_from_file array
logical (log_kind) :: &
att_exists, &! attribute already defined
from_file_loc ! local value of from_file
!-----------------------------------------------------------------------
from_file_loc = .false.
if (present(from_file)) from_file_loc = from_file
!-----------------------------------------------------------------------
!
! if this is the first attribute, allocate space and set the attribute
!
!-----------------------------------------------------------------------
if (.not. associated(file_descr%add_attrib_ival)) then
allocate(file_descr%add_attrib_ival(1), &
file_descr%add_attrib_iname(1), &
file_descr%add_attrib_ival_from_file(1))
file_descr%add_attrib_ival (1) = att_value
file_descr%add_attrib_iname(1) = char_blank
file_descr%add_attrib_iname(1) = trim(att_name)
file_descr%add_attrib_ival_from_file(1) = from_file_loc
!-----------------------------------------------------------------------
!
! if not the first, see if it already exists and over-write value
! if does not exist, resize the attribute array and store the
! attributes
!
!-----------------------------------------------------------------------
else
att_exists = .false.
num_attribs = size(file_descr%add_attrib_ival(:))
att_search: do n=1,num_attribs
if (trim(file_descr%add_attrib_iname(n)) == trim(att_name)) then
file_descr%add_attrib_ival(n) = att_value
file_descr%add_attrib_ival_from_file(n) = from_file_loc
att_exists = .true.
exit att_search
endif
end do att_search
if (.not. att_exists) then
allocate(name_tmp(num_attribs), val_tmp(num_attribs), val_from_file_tmp(num_attribs))
name_tmp(:) = file_descr%add_attrib_iname(:)
val_tmp (:) = file_descr%add_attrib_ival (:)
val_from_file_tmp(:) = file_descr%add_attrib_ival_from_file(:)
deallocate(file_descr%add_attrib_iname, &
file_descr%add_attrib_ival, &
file_descr%add_attrib_ival_from_file )
num_attribs = num_attribs + 1
allocate(file_descr%add_attrib_iname(num_attribs), &
file_descr%add_attrib_ival (num_attribs), &
file_descr%add_attrib_ival_from_file(num_attribs))
file_descr%add_attrib_iname(:) = char_blank
do n=1,num_attribs-1
file_descr%add_attrib_iname(n) = trim(name_tmp(n))
file_descr%add_attrib_ival (n) = val_tmp(n)
file_descr%add_attrib_ival_from_file(n) = val_from_file_tmp(n)
end do
file_descr%add_attrib_iname(num_attribs) = trim(att_name)
file_descr%add_attrib_ival (num_attribs) = att_value
file_descr%add_attrib_ival_from_file(num_attribs) = from_file_loc
deallocate(name_tmp,val_tmp,val_from_file_tmp)
endif
endif
!-----------------------------------------------------------------------
!EOC
end subroutine add_attrib_file_int
!***********************************************************************
!BOP
! !IROUTINE: add_attrib_file_real
! !INTERFACE:
subroutine add_attrib_file_real(file_descr, att_name, att_value, from_file)
! !DESCRIPTION:
! This routine adds a global file attribute to an io file. This
! particular instantiation adds a real attribute, but is aliased
! to the generic routine name add\_attrib\_file.
!
! !REVISION HISTORY:
! same as module
! !INPUT PARAMETERS:
character (*), intent(in) :: &
att_name ! name of attribute to be added
real (r4), intent(in) :: &
att_value ! value of attribute to be added
logical (log_kind), optional, intent(in) :: &
from_file ! is att_value known to be from a file?
! !INPUT/OUTPUT PARAMETERS:
type (datafile), intent(inout) :: &
file_descr ! data file descriptor
!EOP
!BOC
!-----------------------------------------------------------------------
!
! local variables
!
!-----------------------------------------------------------------------
integer (i4) :: &
n, &! loop index
num_attribs ! current number of attributes defined
character (char_len), dimension(:), allocatable :: &
name_tmp ! temp space for resizing attrib name array
real (r4), dimension(:), allocatable :: &
val_tmp ! temp space for resizing attrib value array
logical (log_kind), dimension(:), allocatable :: &
val_from_file_tmp ! temp space for resizing attrib val_from_file array
logical (log_kind) :: &
att_exists, &! attribute already defined
from_file_loc ! local value of from_file
!-----------------------------------------------------------------------
from_file_loc = .false.
if (present(from_file)) from_file_loc = from_file
!-----------------------------------------------------------------------
!
! if this is the first attribute, allocate space and set the attribute
!
!-----------------------------------------------------------------------