forked from mom-ocean/MOM6
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathMOM_io_infra.F90
1960 lines (1685 loc) · 99.9 KB
/
MOM_io_infra.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
!> This module contains a thin inteface to mpp and fms I/O code
module MOM_io_infra
! This file is part of MOM6. See LICENSE.md for the license.
use MOM_domain_infra, only : MOM_domain_type, rescale_comp_data, AGRID, BGRID_NE, CGRID_NE
use MOM_domain_infra, only : domain2d, domain1d, CENTER, CORNER, NORTH_FACE, EAST_FACE
use MOM_error_infra, only : MOM_error=>MOM_err, NOTE, FATAL, WARNING, is_root_PE
use MOM_string_functions, only : lowercase
use fms2_io_mod, only : fms2_open_file => open_file, check_if_open, fms2_close_file => close_file
use fms2_io_mod, only : FmsNetcdfDomainFile_t, FmsNetcdfFile_t, fms2_read_data => read_data
use fms2_io_mod, only : get_unlimited_dimension_name, get_num_dimensions, get_num_variables
use fms2_io_mod, only : get_variable_names, variable_exists, get_variable_size, get_variable_units
use fms2_io_mod, only : register_field, write_data, register_variable_attribute, register_global_attribute
use fms2_io_mod, only : variable_att_exists, get_variable_attribute, get_variable_num_dimensions
use fms2_io_mod, only : get_variable_dimension_names, is_dimension_registered, get_dimension_size
use fms2_io_mod, only : is_dimension_unlimited, register_axis, unlimited
use fms2_io_mod, only : get_global_io_domain_indices
use fms_io_utils_mod, only : fms2_file_exist => file_exists
use fms_mod, only : write_version_number, open_namelist_file, check_nml_error
use fms_io_mod, only : file_exist, field_exist, field_size, read_data
use fms_io_mod, only : fms_io_exit, get_filename_appendix
use mpp_domains_mod, only : mpp_get_compute_domain, mpp_get_global_domain
use mpp_io_mod, only : mpp_open, mpp_close, mpp_flush
use mpp_io_mod, only : mpp_write_meta, mpp_write
use mpp_io_mod, only : mpp_get_atts, mpp_attribute_exist
use mpp_io_mod, only : mpp_get_axes, mpp_axistype=>axistype, mpp_get_axis_data
use mpp_io_mod, only : mpp_get_fields, mpp_fieldtype=>fieldtype
use mpp_io_mod, only : mpp_get_info, mpp_get_times
use mpp_io_mod, only : mpp_io_init
use mpp_mod, only : stdout_if_root=>stdout
! These are encoding constants.
use mpp_io_mod, only : APPEND_FILE=>MPP_APPEND, WRITEONLY_FILE=>MPP_WRONLY
use mpp_io_mod, only : OVERWRITE_FILE=>MPP_OVERWR, READONLY_FILE=>MPP_RDONLY
use mpp_io_mod, only : NETCDF_FILE=>MPP_NETCDF, ASCII_FILE=>MPP_ASCII
use mpp_io_mod, only : MULTIPLE=>MPP_MULTI, SINGLE_FILE=>MPP_SINGLE
use iso_fortran_env, only : int64
implicit none ; private
! These interfaces are actually implemented or have explicit interfaces in this file.
public :: open_file, open_ASCII_file, file_is_open, close_file, flush_file, file_exists
public :: get_file_info, get_file_fields, get_file_times, get_filename_suffix
public :: read_field, read_vector, write_metadata, write_field
public :: field_exists, get_field_atts, get_field_size, get_axis_data, read_field_chksum
public :: io_infra_init, io_infra_end, MOM_namelist_file, check_namelist_error, write_version
public :: stdout_if_root
! These types act as containers for information about files, fields and axes, respectively,
! and may also wrap opaque types from the underlying infrastructure.
public :: file_type, fieldtype, axistype
! These are encoding constant parmeters.
public :: ASCII_FILE, NETCDF_FILE, SINGLE_FILE, MULTIPLE
public :: APPEND_FILE, READONLY_FILE, OVERWRITE_FILE, WRITEONLY_FILE
public :: CENTER, CORNER, NORTH_FACE, EAST_FACE
!> Indicate whether a file exists, perhaps with domain decomposition
interface file_exists
module procedure FMS_file_exists
module procedure MOM_file_exists
end interface
!> Open a file (or fileset) for parallel or single-file I/O.
interface open_file
module procedure open_file_type, open_file_unit
end interface open_file
!> Read a data field from a file
interface read_field
module procedure read_field_4d
module procedure read_field_3d
module procedure read_field_2d, read_field_2d_region
module procedure read_field_1d, read_field_1d_int
module procedure read_field_0d, read_field_0d_int
end interface
!> Write a registered field to an output file
interface write_field
module procedure write_field_4d
module procedure write_field_3d
module procedure write_field_2d
module procedure write_field_1d
module procedure write_field_0d
module procedure MOM_write_axis
end interface write_field
!> Read a pair of data fields representing the two components of a vector from a file
interface read_vector
module procedure read_vector_3d
module procedure read_vector_2d
end interface read_vector
!> Write metadata about a variable or axis to a file and store it for later reuse
interface write_metadata
module procedure write_metadata_axis, write_metadata_field, write_metadata_global
end interface write_metadata
!> Close a file (or fileset). If the file handle does not point to an open file,
!! close_file simply returns without doing anything.
interface close_file
module procedure close_file_type, close_file_unit
end interface close_file
!> Ensure that the output stream associated with a file handle is fully sent to disk
interface flush_file
module procedure flush_file_type, flush_file_unit
end interface flush_file
!> Type for holding a handle to an open file and related information
type :: file_type ; private
integer :: unit = -1 !< The framework identfier or netCDF unit number of an output file
type(FmsNetcdfDomainFile_t), pointer :: fileobj => NULL() !< A domain-decomposed
!! file object that is open for writing
character(len=:), allocatable :: filename !< The path to this file, if it is open
logical :: open_to_read = .false. !< If true, this file or fileset can be read
logical :: open_to_write = .false. !< If true, this file or fileset can be written to
integer :: num_times !< The number of time levels in this file
real :: file_time !< The time of the latest entry in the file.
logical :: FMS2_file !< If true, this file-type is to be used with FMS2 interfaces.
end type file_type
!> This type is a container for information about a variable in a file.
type :: fieldtype ; private
character(len=256) :: name !< The name of this field in the files.
type(mpp_fieldtype) :: FT !< The FMS1 field-type that this type wraps
character(len=:), allocatable :: longname !< The long name for this field
character(len=:), allocatable :: units !< The units for this field
integer(kind=int64) :: chksum_read !< A checksum that has been read from a file
logical :: valid_chksum !< If true, this field has a valid checksum value.
logical :: FMS2_field !< If true, this field-type should be used with FMS2 interfaces.
end type fieldtype
!> This type is a container for information about an axis in a file.
type :: axistype ; private
character(len=256) :: name !< The name of this axis in the files.
type(mpp_axistype) :: AT !< The FMS1 axis-type that this type wraps
real, allocatable, dimension(:) :: ax_data !< The values of the data on the axis.
logical :: domain_decomposed = .false. !< True if axis is domain-decomposed
end type axistype
!> For now, these module-variables are hard-coded to exercise the new FMS2 interfaces.
logical :: FMS2_reads = .true.
logical :: FMS2_writes = .true.
contains
!> Reads the checksum value for a field that was recorded in a file, along with a flag indicating
!! whether the file contained a valid checksum for this field.
subroutine read_field_chksum(field, chksum, valid_chksum)
type(fieldtype), intent(in) :: field !< The field whose checksum attribute is to be read.
integer(kind=int64), intent(out) :: chksum !< The checksum for the field.
logical, intent(out) :: valid_chksum !< If true, chksum has been successfully read.
chksum = -1
valid_chksum = field%valid_chksum
if (valid_chksum) chksum = field%chksum_read
end subroutine read_field_chksum
!> Returns true if the named file or its domain-decomposed variant exists.
logical function MOM_file_exists(filename, MOM_Domain)
character(len=*), intent(in) :: filename !< The name of the file being inquired about
type(MOM_domain_type), intent(in) :: MOM_Domain !< The MOM_Domain that describes the decomposition
! This function uses the fms_io function file_exist to determine whether
! a named file (or its decomposed variant) exists.
MOM_file_exists = file_exist(filename, MOM_Domain%mpp_domain)
end function MOM_file_exists
!> Returns true if the named file or its domain-decomposed variant exists.
logical function FMS_file_exists(filename)
character(len=*), intent(in) :: filename !< The name of the file being inquired about
! This function uses the fms_io function file_exist to determine whether
! a named file (or its decomposed variant) exists.
FMS_file_exists = fms2_file_exist(filename)
end function FMS_file_exists
!> indicates whether an I/O handle is attached to an open file
logical function file_is_open(IO_handle)
type(file_type), intent(in) :: IO_handle !< Handle to a file to inquire about
file_is_open = ((IO_handle%unit >= 0) .or. associated(IO_handle%fileobj))
end function file_is_open
!> closes a file (or fileset). If the file handle does not point to an open file,
!! close_file_type simply returns without doing anything.
subroutine close_file_type(IO_handle)
type(file_type), intent(inout) :: IO_handle !< The I/O handle for the file to be closed
if (associated(IO_handle%fileobj)) then
call fms2_close_file(IO_handle%fileobj)
deallocate(IO_handle%fileobj)
else
call mpp_close(IO_handle%unit)
endif
if (allocated(IO_handle%filename)) deallocate(IO_handle%filename)
IO_handle%open_to_read = .false. ; IO_handle%open_to_write = .false.
IO_handle%num_times = 0 ; IO_handle%file_time = 0.0
IO_handle%FMS2_file = .false.
end subroutine close_file_type
!> closes a file. If the unit does not point to an open file,
!! close_file_unit simply returns without doing anything.
subroutine close_file_unit(unit)
integer, intent(inout) :: unit !< The I/O unit for the file to be closed
call mpp_close(unit)
end subroutine close_file_unit
!> Ensure that the output stream associated with a file handle is fully sent to disk.
subroutine flush_file_type(IO_handle)
type(file_type), intent(in) :: IO_handle !< The I/O handle for the file to flush
if (associated(IO_handle%fileobj)) then
! There does not appear to be an fms2 flush call.
else
call mpp_flush(IO_handle%unit)
endif
end subroutine flush_file_type
!> Ensure that the output stream associated with a unit is fully sent to disk.
subroutine flush_file_unit(unit)
integer, intent(in) :: unit !< The I/O unit for the file to flush
call mpp_flush(unit)
end subroutine flush_file_unit
!> Initialize the underlying I/O infrastructure
subroutine io_infra_init(maxunits)
integer, optional, intent(in) :: maxunits !< An optional maximum number of file
!! unit numbers that can be used.
call mpp_io_init(maxunit=maxunits)
end subroutine io_infra_init
!> Gracefully close out and terminate the underlying I/O infrastructure
subroutine io_infra_end()
call fms_io_exit()
end subroutine io_infra_end
!> Open a single namelist file that is potentially readable by all PEs.
function MOM_namelist_file(file) result(unit)
character(len=*), optional, intent(in) :: file !< The file to open, by default "input.nml".
integer :: unit !< The opened unit number of the namelist file
unit = open_namelist_file(file)
end function MOM_namelist_file
!> Checks the iostat argument that is returned after reading a namelist variable and writes a
!! message if there is an error.
subroutine check_namelist_error(IOstat, nml_name)
integer, intent(in) :: IOstat !< An I/O status field from a namelist read call
character(len=*), intent(in) :: nml_name !< The name of the namelist
integer :: ierr
ierr = check_nml_error(IOstat, nml_name)
end subroutine check_namelist_error
!> Write a file version number to the log file or other output file
subroutine write_version(version, tag, unit)
character(len=*), intent(in) :: version !< A string that contains the routine name and version
character(len=*), optional, intent(in) :: tag !< A tag name to add to the message
integer, optional, intent(in) :: unit !< An alternate unit number for output
call write_version_number(version, tag, unit)
end subroutine write_version
!> open_file opens a file for parallel or single-file I/O.
subroutine open_file_unit(unit, filename, action, form, threading, fileset, nohdrs, domain, MOM_domain)
integer, intent(out) :: unit !< The I/O unit for the opened file
character(len=*), intent(in) :: filename !< The name of the file being opened
integer, optional, intent(in) :: action !< A flag indicating whether the file can be read
!! or written to and how to handle existing files.
integer, optional, intent(in) :: form !< A flag indicating the format of a new file. The
!! default is ASCII_FILE, but NETCDF_FILE is also common.
integer, optional, intent(in) :: threading !< A flag indicating whether one (SINGLE_FILE)
!! or multiple PEs (MULTIPLE) participate in I/O.
!! With the default, the root PE does I/O.
integer, optional, intent(in) :: fileset !< A flag indicating whether multiple PEs doing I/O due
!! to threading=MULTIPLE write to the same file (SINGLE_FILE)
!! or to one file per PE (MULTIPLE, the default).
logical, optional, intent(in) :: nohdrs !< If nohdrs is .TRUE., headers are not written to
!! ASCII files. The default is .false.
type(domain2d), optional, intent(in) :: domain !< A domain2d type that describes the decomposition
type(MOM_domain_type), optional, intent(in) :: MOM_Domain !< A MOM_Domain that describes the decomposition
if (present(MOM_Domain)) then
call mpp_open(unit, filename, action=action, form=form, threading=threading, fileset=fileset, &
nohdrs=nohdrs, domain=MOM_Domain%mpp_domain)
else
call mpp_open(unit, filename, action=action, form=form, threading=threading, fileset=fileset, &
nohdrs=nohdrs, domain=domain)
endif
end subroutine open_file_unit
!> open_file opens a file for parallel or single-file I/O.
subroutine open_file_type(IO_handle, filename, action, MOM_domain, threading, fileset)
type(file_type), intent(inout) :: IO_handle !< The handle for the opened file
character(len=*), intent(in) :: filename !< The path name of the file being opened
integer, optional, intent(in) :: action !< A flag indicating whether the file can be read
!! or written to and how to handle existing files.
!! The default is WRITE_ONLY.
type(MOM_domain_type), &
optional, intent(in) :: MOM_Domain !< A MOM_Domain that describes the decomposition
integer, optional, intent(in) :: threading !< A flag indicating whether one (SINGLE_FILE)
!! or multiple PEs (MULTIPLE) participate in I/O.
!! With the default, the root PE does I/O.
integer, optional, intent(in) :: fileset !< A flag indicating whether multiple PEs doing I/O due
!! to threading=MULTIPLE write to the same file (SINGLE_FILE)
!! or to one file per PE (MULTIPLE, the default).
! Local variables
type(FmsNetcdfDomainFile_t) :: fileobj_read ! A handle to a domain-decomposed file for obtaining information
! about the exiting time axis entries in append mode.
logical :: success ! If true, the file was opened successfully
integer :: file_mode ! An integer that encodes whether the file is to be opened for
! reading, writing or appending
character(len=40) :: mode ! A character string that encodes whether the file is to be opened for
! reading, writing or appending
character(len=:), allocatable :: filename_tmp ! A copy of filename with .nc appended if necessary.
character(len=256) :: dim_unlim_name ! name of the unlimited dimension in the file
integer :: index_nc
if (IO_handle%open_to_write) then
call MOM_error(WARNING, "open_file_type called for file "//trim(filename)//&
" with an IO_handle that is already open to to write.")
return
endif
if (IO_handle%open_to_read) then
call MOM_error(FATAL, "open_file_type called for file "//trim(filename)//&
" with an IO_handle that is already open to to read.")
endif
file_mode = WRITEONLY_FILE ; if (present(action)) file_mode = action
if (FMS2_writes .and. present(MOM_Domain)) then
if (.not.associated(IO_handle%fileobj)) allocate (IO_handle%fileobj)
! The FMS1 interface automatically appends .nc if necessary, but FMS2 interface does not.
index_nc = index(trim(filename), ".nc")
if (index_nc > 0) then
filename_tmp = trim(filename)
else
filename_tmp = trim(filename)//".nc"
if (is_root_PE()) call MOM_error(WARNING, "Open_file is appending .nc to the filename "//trim(filename))
endif
if (file_mode == WRITEONLY_FILE) then ; mode = "write"
elseif (file_mode == APPEND_FILE) then ; mode = "append"
elseif (file_mode == OVERWRITE_FILE) then ; mode = "overwrite"
elseif (file_mode == READONLY_FILE) then ; mode = "read"
else
call MOM_error(FATAL, "open_file_type called with unrecognized action.")
endif
IO_handle%num_times = 0
IO_handle%file_time = 0.0
if ((file_mode == APPEND_FILE) .and. file_exists(filename_tmp, MOM_Domain)) then
! Determine the latest file time and number of records so far.
success = fms2_open_file(fileObj_read, trim(filename_tmp), "read", MOM_domain%mpp_domain)
call get_unlimited_dimension_name(fileObj_read, dim_unlim_name)
if (len_trim(dim_unlim_name) > 0) &
call get_dimension_size(fileObj_read, trim(dim_unlim_name), IO_handle%num_times)
if (IO_handle%num_times > 0) &
call fms2_read_data(fileObj_read, trim(dim_unlim_name), IO_handle%file_time, &
unlim_dim_level=IO_handle%num_times)
call fms2_close_file(fileObj_read)
endif
success = fms2_open_file(IO_handle%fileobj, trim(filename_tmp), trim(mode), MOM_domain%mpp_domain)
if (.not.success) call MOM_error(FATAL, "Unable to open file "//trim(filename_tmp))
IO_handle%FMS2_file = .true.
elseif (present(MOM_Domain)) then
call mpp_open(IO_handle%unit, filename, action=file_mode, form=NETCDF_FILE, threading=threading, &
fileset=fileset, domain=MOM_Domain%mpp_domain)
IO_handle%FMS2_file = .false.
else
call mpp_open(IO_handle%unit, filename, action=file_mode, form=NETCDF_FILE, threading=threading, &
fileset=fileset)
IO_handle%FMS2_file = .false.
endif
IO_handle%filename = trim(filename)
if (file_mode == READONLY_FILE) then
IO_handle%open_to_read = .true. ; IO_handle%open_to_write = .false.
else
IO_handle%open_to_read = .false. ; IO_handle%open_to_write = .true.
endif
end subroutine open_file_type
!> open_file opens an ascii file for parallel or single-file I/O using Fortran read and write calls.
subroutine open_ASCII_file(unit, file, action, threading, fileset)
integer, intent(out) :: unit !< The I/O unit for the opened file
character(len=*), intent(in) :: file !< The name of the file being opened
integer, optional, intent(in) :: action !< A flag indicating whether the file can be read
!! or written to and how to handle existing files.
integer, optional, intent(in) :: threading !< A flag indicating whether one (SINGLE_FILE)
!! or multiple PEs (MULTIPLE) participate in I/O.
!! With the default, the root PE does I/O.
integer, optional, intent(in) :: fileset !< A flag indicating whether multiple PEs doing I/O due
!! to threading=MULTIPLE write to the same file (SINGLE_FILE)
!! or to one file per PE (MULTIPLE, the default).
call mpp_open(unit, file, action=action, form=ASCII_FILE, threading=threading, fileset=fileset, &
nohdrs=.true.)
end subroutine open_ASCII_file
!> Provide a string to append to filenames, to differentiate ensemble members, for example.
subroutine get_filename_suffix(suffix)
character(len=*), intent(out) :: suffix !< A string to append to filenames
call get_filename_appendix(suffix)
end subroutine get_filename_suffix
!> Get information about the number of dimensions, variables and time levels
!! in the file associated with an open file unit
subroutine get_file_info(IO_handle, ndim, nvar, ntime)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for I/O
integer, optional, intent(out) :: ndim !< The number of dimensions in the file
integer, optional, intent(out) :: nvar !< The number of variables in the file
integer, optional, intent(out) :: ntime !< The number of time levels in the file
! Local variables
character(len=256) :: dim_unlim_name ! name of the unlimited dimension in the file
integer :: ndims, nvars, natts, ntimes
if (IO_handle%FMS2_file) then
if (present(ndim)) ndim = get_num_dimensions(IO_handle%fileobj)
if (present(nvar)) nvar = get_num_variables(IO_handle%fileobj)
if (present(ntime)) then
ntime = 0
call get_unlimited_dimension_name(IO_handle%fileobj, dim_unlim_name)
if (len_trim(dim_unlim_name) > 0) &
call get_dimension_size(IO_handle%fileobj, trim(dim_unlim_name), ntime)
endif
else
call mpp_get_info(IO_handle%unit, ndims, nvars, natts, ntimes )
if (present(ndim)) ndim = ndims
if (present(nvar)) nvar = nvars
if (present(ntime)) ntime = ntimes
endif
end subroutine get_file_info
!> Get the times of records from a file
subroutine get_file_times(IO_handle, time_values, ntime)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for I/O
real, allocatable, dimension(:), intent(inout) :: time_values !< The real times for the records in file.
integer, optional, intent(out) :: ntime !< The number of time levels in the file
character(len=256) :: dim_unlim_name ! name of the unlimited dimension in the file
integer :: ntimes ! The number of time levels in the file
!### Modify this routine to optionally convert to time_type, using information about the dimensions?
if (allocated(time_values)) deallocate(time_values)
call get_file_info(IO_handle, ntime=ntimes)
if (present(ntime)) ntime = ntimes
if (ntimes > 0) then
allocate(time_values(ntimes))
if (IO_handle%FMS2_file) then
call get_unlimited_dimension_name(IO_handle%fileobj, dim_unlim_name)
call fms2_read_data(IO_handle%fileobj, trim(dim_unlim_name), time_values)
else
call mpp_get_times(IO_handle%unit, time_values)
endif
endif
end subroutine get_file_times
!> Set up the field information (e.g., names and metadata) for all of the variables in a file. The
!! argument fields must be allocated with a size that matches the number of variables in a file.
subroutine get_file_fields(IO_handle, fields)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for I/O
type(fieldtype), dimension(:), intent(inout) :: fields !< Field-type descriptions of all of
!! the variables in a file.
type(mpp_fieldtype), dimension(size(fields)) :: mpp_fields ! Fieldtype structures for the variables
character(len=256), dimension(size(fields)) :: var_names ! The names of all variables
character(len=256) :: units ! The units of a variable as recorded in the file
character(len=2048) :: longname ! The long-name of a variable as recorded in the file
character(len=64) :: checksum_char ! The hexadecimal checksum read from the file
integer(kind=int64), dimension(3) :: checksum_file ! The checksums for a variable in the file
integer :: nvar ! The number of variables in the file
integer :: i
nvar = size(fields)
! Local variables
if (IO_handle%FMS2_file) then
call get_variable_names(IO_handle%fileobj, var_names)
do i=1,nvar
fields(i)%name = trim(var_names(i))
longname = ""
if (variable_att_exists(IO_handle%fileobj, var_names(i), "long_name")) &
call get_variable_attribute(IO_handle%fileobj, var_names(i), "long_name", longname)
fields(i)%longname = trim(longname)
units = ""
if (variable_att_exists(IO_handle%fileobj, var_names(i), "units")) &
call get_variable_attribute(IO_handle%fileobj, var_names(i), "units", units)
fields(i)%units = trim(units)
fields(i)%valid_chksum = variable_att_exists(IO_handle%fileobj, var_names(i), "checksum")
if (fields(i)%valid_chksum) then
call get_variable_attribute(IO_handle%fileobj, var_names(i), 'checksum', checksum_char)
! If there are problems, there might need to be code added to handle commas.
read (checksum_char(1:16), '(Z16)') fields(i)%chksum_read
endif
enddo
else
call mpp_get_fields(IO_handle%unit, mpp_fields)
do i=1,nvar
fields(i)%FT = mpp_fields(i)
call mpp_get_atts(fields(i)%FT, name=fields(i)%name, units=units, longname=longname, &
checksum=checksum_file)
fields(i)%longname = trim(longname)
fields(i)%units = trim(units)
fields(i)%valid_chksum = mpp_attribute_exist(fields(i)%FT, "checksum")
if (fields(i)%valid_chksum) fields(i)%chksum_read = checksum_file(1)
enddo
endif
end subroutine get_file_fields
!> Extract information from a field type, as stored or as found in a file
subroutine get_field_atts(field, name, units, longname, checksum)
type(fieldtype), intent(in) :: field !< The field to extract information from
character(len=*), optional, intent(out) :: name !< The variable name
character(len=*), optional, intent(out) :: units !< The units of the variable
character(len=*), optional, intent(out) :: longname !< The long name of the variable
integer(kind=int64), dimension(:), &
optional, intent(out) :: checksum !< The checksums of the variable in a file
if (present(name)) name = trim(field%name)
if (present(units)) units = trim(field%units)
if (present(longname)) longname = trim(field%longname)
if (present(checksum)) checksum = field%chksum_read
end subroutine get_field_atts
!> Field_exists returns true if the field indicated by field_name is present in the
!! file file_name. If file_name does not exist, it returns false.
function field_exists(filename, field_name, domain, no_domain, MOM_domain)
character(len=*), intent(in) :: filename !< The name of the file being inquired about
character(len=*), intent(in) :: field_name !< The name of the field being sought
type(domain2d), target, optional, intent(in) :: domain !< A domain2d type that describes the decomposition
logical, optional, intent(in) :: no_domain !< This file does not use domain decomposition
type(MOM_domain_type), optional, intent(in) :: MOM_Domain !< A MOM_Domain that describes the decomposition
logical :: field_exists !< True if filename exists and field_name is in filename
! Local variables
type(FmsNetcdfDomainFile_t) :: fileObj_dd ! A handle to a domain-decomposed file for obtaining information
! about the exiting time axis entries in append mode.
type(FmsNetcdfFile_t) :: fileObj_simple ! A handle to a non-domain-decomposed file for obtaining information
! about the exiting time axis entries in append mode.
logical :: success ! If true, the file was opened successfully
logical :: domainless ! If true, this file does not use a domain-decomposed file.
domainless = .not.(present(MOM_domain) .or. present(domain))
if (present(no_domain)) then
if (domainless .and. .not.no_domain) call MOM_error(FATAL, &
"field_exists: When no_domain is present and false, a domain must be supplied in query about "//&
trim(field_name)//" in file "//trim(filename))
domainless = no_domain
endif
if (FMS2_reads) then
field_exists = .false.
if (file_exists(filename)) then
if (domainless) then
success = fms2_open_file(fileObj_simple, trim(filename), "read")
if (success) then
field_exists = variable_exists(fileObj_simple, field_name)
call fms2_close_file(fileObj_simple)
endif
else
if (present(MOM_domain)) then
success = fms2_open_file(fileObj_dd, trim(filename), "read", MOM_domain%mpp_domain)
else
success = fms2_open_file(fileObj_dd, trim(filename), "read", domain)
endif
if (success) then
field_exists = variable_exists(fileobj_dd, field_name)
call fms2_close_file(fileObj_dd)
endif
endif
endif
elseif (present(MOM_domain)) then
field_exists = field_exist(filename, field_name, domain=MOM_domain%mpp_domain, no_domain=no_domain)
else
field_exists = field_exist(filename, field_name, domain=domain, no_domain=no_domain)
endif
end function field_exists
!> Given filename and fieldname, this subroutine returns the size of the field in the file
subroutine get_field_size(filename, fieldname, sizes, field_found, no_domain)
character(len=*), intent(in) :: filename !< The name of the file to read
character(len=*), intent(in) :: fieldname !< The name of the variable whose sizes are returned
integer, dimension(:), intent(inout) :: sizes !< The sizes of the variable in each dimension
logical, optional, intent(out) :: field_found !< This indicates whether the field was found in
!! the input file. Without this argument, there
!! is a fatal error if the field is not found.
logical, optional, intent(in) :: no_domain !< If present and true, do not check for file
!! names with an appended tile number
! Local variables
type(FmsNetcdfFile_t) :: fileobj_read ! A handle to a non-domain-decomposed file for obtaining information
! about the exiting time axis entries in append mode.
logical :: success ! If true, the file was opened successfully
logical :: field_exists ! True if filename exists and field_name is in filename
integer :: i, ndims
if (FMS2_reads) then
field_exists = .false.
if (file_exists(filename)) then
success = fms2_open_file(fileObj_read, trim(filename), "read")
if (success) then
field_exists = variable_exists(fileobj_read, fieldname)
if (field_exists) then
ndims = get_variable_num_dimensions(fileobj_read, fieldname)
if (ndims > size(sizes)) call MOM_error(FATAL, &
"get_field_size called with too few sizes for "//trim(fieldname)//" in "//trim(filename))
call get_variable_size(fileobj_read, fieldname, sizes(1:ndims))
do i=ndims+1,size(sizes) ; sizes(i) = 0 ; enddo
! This preserves previous behavior when reading time-varying data without
! a vertical extent.
if (size(sizes)==ndims+1) then
sizes(ndims+1)=sizes(ndims)
sizes(ndims)=1
endif
endif
endif
endif
if (present(field_found)) field_found = field_exists
else
call field_size(filename, fieldname, sizes, field_found=field_found, no_domain=no_domain)
endif
end subroutine get_field_size
!> Extracts and returns the axis data stored in an axistype.
subroutine get_axis_data( axis, dat )
type(axistype), intent(in) :: axis !< An axis type
real, dimension(:), intent(out) :: dat !< The data in the axis variable
integer :: i
! This routine might not be needed for MOM6.
if (allocated(axis%ax_data)) then
if (size(axis%ax_data) > size(dat)) call MOM_error(FATAL, &
"get_axis_data called with too small of an output data array for "//trim(axis%name))
do i=1,size(axis%ax_data) ; dat(i) = axis%ax_data(i) ; enddo
elseif (.not.FMS2_writes) then
call mpp_get_axis_data( axis%AT, dat )
endif
end subroutine get_axis_data
!> This routine uses the fms_io subroutine read_data to read a scalar named
!! "fieldname" from a single or domain-decomposed file "filename".
subroutine read_field_0d(filename, fieldname, data, timelevel, scale, MOM_Domain, &
global_file, file_may_be_4d)
character(len=*), intent(in) :: filename !< The name of the file to read
character(len=*), intent(in) :: fieldname !< The variable name of the data in the file
real, intent(inout) :: data !< The 1-dimensional array into which the data
integer, optional, intent(in) :: timelevel !< The time level in the file to read
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before it is returned.
type(MOM_domain_type), &
optional, intent(in) :: MOM_Domain !< The MOM_Domain that describes the decomposition
logical, optional, intent(in) :: global_file !< If true, read from a single global file
logical, optional, intent(in) :: file_may_be_4d !< If true, this file may have 4-d arrays, but
!! with the FMS2 I/O interfaces this does not matter.
! Local variables
type(FmsNetcdfFile_t) :: fileObj ! A handle to a non-domain-decomposed file
type(FmsNetcdfDomainFile_t) :: fileobj_DD ! A handle to a domain-decomposed file object
character(len=96) :: var_to_read ! Name of variable to read from the netcdf file
logical :: has_time_dim ! True if the variable has an unlimited time axis.
logical :: success ! True if the file was successfully opened
if (present(MOM_Domain) .and. FMS2_reads) then
! Open the FMS2 file-set.
success = fms2_open_file(fileobj_DD, filename, "read", MOM_domain%mpp_domain)
if (.not.success) call MOM_error(FATAL, "Failed to open "//trim(filename))
! Find the matching case-insensitive variable name in the file and prepare to read it.
call prepare_to_read_var(fileobj_DD, fieldname, "read_field_0d: ", filename, &
var_to_read, has_time_dim, timelevel)
! Read the data.
if (present(timelevel) .and. has_time_dim) then
call fms2_read_data(fileobj_DD, var_to_read, data, unlim_dim_level=timelevel)
else
call fms2_read_data(fileobj_DD, var_to_read, data)
endif
! Close the file-set.
if (check_if_open(fileobj_DD)) call fms2_close_file(fileobj_DD)
elseif (FMS2_reads) then
! Open the FMS2 file-set.
success = fms2_open_file(fileObj, trim(filename), "read")
if (.not.success) call MOM_error(FATAL, "Failed to open "//trim(filename))
! Find the matching case-insensitive variable name in the file, and determine whether it
! has a time dimension.
call find_varname_in_file(fileObj, fieldname, "read_field_0d: ", filename, &
var_to_read, has_time_dim, timelevel)
! Read the data.
if (present(timelevel) .and. has_time_dim) then
call fms2_read_data(fileobj, var_to_read, data, unlim_dim_level=timelevel)
else
call fms2_read_data(fileobj, var_to_read, data)
endif
! Close the file-set.
if (check_if_open(fileobj)) call fms2_close_file(fileobj)
elseif (present(MOM_Domain)) then ! Read the variable using the FMS-1 interface.
call read_data(filename, fieldname, data, MOM_Domain%mpp_domain, timelevel=timelevel)
else
call read_data(filename, fieldname, data, timelevel=timelevel, no_domain=.true.)
endif
if (present(scale)) then ; if (scale /= 1.0) then
data = scale*data
endif ; endif
end subroutine read_field_0d
!> This routine uses the fms_io subroutine read_data to read a 1-D data field named
!! "fieldname" from a single or domain-decomposed file "filename".
subroutine read_field_1d(filename, fieldname, data, timelevel, scale, MOM_Domain, &
global_file, file_may_be_4d)
character(len=*), intent(in) :: filename !< The name of the file to read
character(len=*), intent(in) :: fieldname !< The variable name of the data in the file
real, dimension(:), intent(inout) :: data !< The 1-dimensional array into which the data
integer, optional, intent(in) :: timelevel !< The time level in the file to read
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before they are returned.
type(MOM_domain_type), &
optional, intent(in) :: MOM_Domain !< The MOM_Domain that describes the decomposition
logical, optional, intent(in) :: global_file !< If true, read from a single global file
logical, optional, intent(in) :: file_may_be_4d !< If true, this file may have 4-d arrays, but
!! with the FMS2 I/O interfaces this does not matter.
! Local variables
type(FmsNetcdfFile_t) :: fileObj ! A handle to a non-domain-decomposed file
type(FmsNetcdfDomainFile_t) :: fileobj_DD ! A handle to a domain-decomposed file object
character(len=96) :: var_to_read ! Name of variable to read from the netcdf file
logical :: has_time_dim ! True if the variable has an unlimited time axis.
logical :: success ! True if the file was successfully opened
if (present(MOM_Domain) .and. FMS2_reads) then
! Open the FMS2 file-set.
success = fms2_open_file(fileobj_DD, filename, "read", MOM_domain%mpp_domain)
if (.not.success) call MOM_error(FATAL, "Failed to open "//trim(filename))
! Find the matching case-insensitive variable name in the file and prepare to read it.
call prepare_to_read_var(fileobj_DD, fieldname, "read_field_1d: ", filename, &
var_to_read, has_time_dim, timelevel)
! Read the data.
if (present(timelevel) .and. has_time_dim) then
call fms2_read_data(fileobj_DD, var_to_read, data, unlim_dim_level=timelevel)
else
call fms2_read_data(fileobj_DD, var_to_read, data)
endif
! Close the file-set.
if (check_if_open(fileobj_DD)) call fms2_close_file(fileobj_DD)
elseif (FMS2_reads) then
! Open the FMS2 file-set.
success = fms2_open_file(fileObj, trim(filename), "read")
if (.not.success) call MOM_error(FATAL, "Failed to open "//trim(filename))
! Find the matching case-insensitive variable name in the file, and determine whether it
! has a time dimension.
call find_varname_in_file(fileObj, fieldname, "read_field_1d: ", filename, &
var_to_read, has_time_dim, timelevel)
! Read the data.
if (present(timelevel) .and. has_time_dim) then
call fms2_read_data(fileobj, var_to_read, data, unlim_dim_level=timelevel)
else
call fms2_read_data(fileobj, var_to_read, data)
endif
! Close the file-set.
if (check_if_open(fileobj)) call fms2_close_file(fileobj)
elseif (present(MOM_Domain)) then ! Read the variable using the FMS-1 interface.
call read_data(filename, fieldname, data, MOM_Domain%mpp_domain, timelevel=timelevel)
else
call read_data(filename, fieldname, data, timelevel=timelevel, no_domain=.true.)
endif
if (present(scale)) then ; if (scale /= 1.0) then
data(:) = scale*data(:)
endif ; endif
end subroutine read_field_1d
!> This routine uses the fms_io subroutine read_data to read a distributed
!! 2-D data field named "fieldname" from file "filename". Valid values for
!! "position" include CORNER, CENTER, EAST_FACE and NORTH_FACE.
subroutine read_field_2d(filename, fieldname, data, MOM_Domain, &
timelevel, position, scale, global_file, file_may_be_4d)
character(len=*), intent(in) :: filename !< The name of the file to read
character(len=*), intent(in) :: fieldname !< The variable name of the data in the file
real, dimension(:,:), intent(inout) :: data !< The 2-dimensional array into which the data
!! should be read
type(MOM_domain_type), intent(in) :: MOM_Domain !< The MOM_Domain that describes the decomposition
integer, optional, intent(in) :: timelevel !< The time level in the file to read
integer, optional, intent(in) :: position !< A flag indicating where this data is located
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before it is returned.
logical, optional, intent(in) :: global_file !< If true, read from a single global file
logical, optional, intent(in) :: file_may_be_4d !< If true, this file may have 4-d arrays, but
!! with the FMS2 I/O interfaces this does not matter.
! Local variables
type(FmsNetcdfDomainFile_t) :: fileobj ! A handle to a domain-decomposed file object
character(len=96) :: var_to_read ! Name of variable to read from the netcdf file
logical :: has_time_dim ! True if the variable has an unlimited time axis.
logical :: success ! True if the file was successfully opened
if (FMS2_reads) then
! Open the FMS2 file-set.
success = fms2_open_file(fileobj, filename, "read", MOM_domain%mpp_domain)
if (.not.success) call MOM_error(FATAL, "Failed to open "//trim(filename))
! Find the matching case-insensitive variable name in the file and prepare to read it.
call prepare_to_read_var(fileobj, fieldname, "read_field_2d: ", filename, &
var_to_read, has_time_dim, timelevel, position)
! Read the data.
if (present(timelevel) .and. has_time_dim) then
call fms2_read_data(fileobj, var_to_read, data, unlim_dim_level=timelevel)
else
call fms2_read_data(fileobj, var_to_read, data)
endif
! Close the file-set.
if (check_if_open(fileobj)) call fms2_close_file(fileobj)
else ! Read the variable using the FMS-1 interface.
call read_data(filename, fieldname, data, MOM_Domain%mpp_domain, &
timelevel=timelevel, position=position)
endif
if (present(scale)) then ; if (scale /= 1.0) then
call rescale_comp_data(MOM_Domain, data, scale)
endif ; endif
end subroutine read_field_2d
!> This routine uses the fms_io subroutine read_data to read a region from a distributed or
!! global 2-D data field named "fieldname" from file "filename".
subroutine read_field_2d_region(filename, fieldname, data, start, nread, MOM_domain, &
no_domain, scale)
character(len=*), intent(in) :: filename !< The name of the file to read
character(len=*), intent(in) :: fieldname !< The variable name of the data in the file
real, dimension(:,:), intent(inout) :: data !< The 2-dimensional array into which the data
!! should be read
integer, dimension(:), intent(in) :: start !< The starting index to read in each of 4
!! dimensions. For this 2-d read, the 3rd
!! and 4th values are always 1.
integer, dimension(:), intent(in) :: nread !< The number of points to read in each of 4
!! dimensions. For this 2-d read, the 3rd
!! and 4th values are always 1.
type(MOM_domain_type), &
optional, intent(in) :: MOM_Domain !< The MOM_Domain that describes the decomposition
logical, optional, intent(in) :: no_domain !< If present and true, this variable does not
!! use domain decomposion.
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before it is returned.
! Local variables
type(FmsNetcdfFile_t) :: fileObj ! A handle to a non-domain-decomposed file
type(FmsNetcdfDomainFile_t) :: fileobj_DD ! A handle to a domain-decomposed file object
character(len=96) :: var_to_read ! Name of variable to read from the netcdf file
logical :: success ! True if the file was successfully opened
if (present(MOM_Domain) .and. FMS2_reads) then
! Open the FMS2 file-set.
success = fms2_open_file(fileobj_DD, filename, "read", MOM_domain%mpp_domain)
if (.not.success) call MOM_error(FATAL, "Failed to open "//trim(filename))
! Find the matching case-insensitive variable name in the file and prepare to read it.
call prepare_to_read_var(fileobj_DD, fieldname, "read_field_2d_region: ", &
filename, var_to_read)
! Read the data.
call fms2_read_data(fileobj_DD, var_to_read, data, corner=start(1:2), edge_lengths=nread(1:2))
! Close the file-set.
if (check_if_open(fileobj_DD)) call fms2_close_file(fileobj_DD)
elseif (FMS2_reads) then
! Open the FMS2 file-set.
success = fms2_open_file(fileObj, trim(filename), "read")
if (.not.success) call MOM_error(FATAL, "Failed to open "//trim(filename))
! Find the matching case-insensitive variable name in the file, and determine whether it
! has a time dimension.
call find_varname_in_file(fileObj, fieldname, "read_field_2d_region: ", filename, var_to_read)
! Read the data.
call fms2_read_data(fileobj, var_to_read, data, corner=start(1:2), edge_lengths=nread(1:2))
! Close the file-set.
if (check_if_open(fileobj)) call fms2_close_file(fileobj)
elseif (present(MOM_Domain)) then ! Read the variable using the FMS-1 interface.
call read_data(filename, fieldname, data, start, nread, domain=MOM_Domain%mpp_domain, &
no_domain=no_domain)
else
call read_data(filename, fieldname, data, start, nread, no_domain=no_domain)
endif
if (present(scale)) then ; if (scale /= 1.0) then
if (present(MOM_Domain)) then
call rescale_comp_data(MOM_Domain, data, scale)
else
! Dangerously rescale the whole array
data(:,:) = scale*data(:,:)
endif
endif ; endif
end subroutine read_field_2d_region
!> This routine uses the fms_io subroutine read_data to read a distributed
!! 3-D data field named "fieldname" from file "filename". Valid values for
!! "position" include CORNER, CENTER, EAST_FACE and NORTH_FACE.
subroutine read_field_3d(filename, fieldname, data, MOM_Domain, &
timelevel, position, scale, global_file, file_may_be_4d)
character(len=*), intent(in) :: filename !< The name of the file to read
character(len=*), intent(in) :: fieldname !< The variable name of the data in the file
real, dimension(:,:,:), intent(inout) :: data !< The 3-dimensional array into which the data
!! should be read
type(MOM_domain_type), intent(in) :: MOM_Domain !< The MOM_Domain that describes the decomposition
integer, optional, intent(in) :: timelevel !< The time level in the file to read
integer, optional, intent(in) :: position !< A flag indicating where this data is located
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before it is returned.
logical, optional, intent(in) :: global_file !< If true, read from a single global file
logical, optional, intent(in) :: file_may_be_4d !< If true, this file may have 4-d arrays, but
!! with the FMS2 I/O interfaces this does not matter.
! Local variables
type(FmsNetcdfDomainFile_t) :: fileobj ! A handle to a domain-decomposed file object
character(len=96) :: var_to_read ! Name of variable to read from the netcdf file
logical :: has_time_dim ! True if the variable has an unlimited time axis.
logical :: success ! True if the file was successfully opened
if (FMS2_reads) then
! Open the FMS2 file-set.
success = fms2_open_file(fileobj, filename, "read", MOM_domain%mpp_domain)
if (.not.success) call MOM_error(FATAL, "Failed to open "//trim(filename))
! Find the matching case-insensitive variable name in the file and prepare to read it.
call prepare_to_read_var(fileobj, fieldname, "read_field_3d: ", filename, &
var_to_read, has_time_dim, timelevel, position)
! Read the data.
if (present(timelevel) .and. has_time_dim) then
call fms2_read_data(fileobj, var_to_read, data, unlim_dim_level=timelevel)
else
call fms2_read_data(fileobj, var_to_read, data)
endif
! Close the file-set.
if (check_if_open(fileobj)) call fms2_close_file(fileobj)
else ! Read the variable using the FMS-1 interface.
call read_data(filename, fieldname, data, MOM_Domain%mpp_domain, &
timelevel=timelevel, position=position)
endif
if (present(scale)) then ; if (scale /= 1.0) then
call rescale_comp_data(MOM_Domain, data, scale)
endif ; endif
end subroutine read_field_3d
!> This routine uses the fms_io subroutine read_data to read a distributed
!! 4-D data field named "fieldname" from file "filename". Valid values for
!! "position" include CORNER, CENTER, EAST_FACE and NORTH_FACE.
subroutine read_field_4d(filename, fieldname, data, MOM_Domain, &
timelevel, position, scale, global_file)
character(len=*), intent(in) :: filename !< The name of the file to read
character(len=*), intent(in) :: fieldname !< The variable name of the data in the file
real, dimension(:,:,:,:), intent(inout) :: data !< The 4-dimensional array into which the data
!! should be read
type(MOM_domain_type), intent(in) :: MOM_Domain !< The MOM_Domain that describes the decomposition
integer, optional, intent(in) :: timelevel !< The time level in the file to read
integer, optional, intent(in) :: position !< A flag indicating where this data is located
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before it is returned.