121use mpp_mod,
only:
mpp_error, note, warning, fatal, &
122 mpp_set_warn_level, &
124 mpp_pe, mpp_npes, mpp_root_pe, &
126 mpp_clock_begin, mpp_clock_end, &
127 mpp_clock_id, mpp_init, mpp_exit, &
128 mpp_clock_sync, mpp_clock_detailed, &
129 clock_component, clock_subcomponent,&
130 clock_module_driver, clock_module, &
131 clock_routine, clock_loop, &
132 clock_infra, mpp_clock_set_grain, &
133 mpp_set_stack_size, &
134 stdin, stdout, stderr, stdlog, &
135 mpp_error_state, lowercase, &
137 get_unit, read_input_nml
141 mpp_domains_init, mpp_domains_exit, &
146#ifdef use_deprecated_io
147use mpp_io_mod,
only: mpp_io_init, mpp_open, mpp_close, &
148 mpp_ascii, mpp_native, mpp_ieee32, mpp_netcdf, &
149 mpp_rdonly, mpp_wronly, mpp_append, mpp_overwr, &
150 mpp_sequential, mpp_direct, &
151 mpp_single, mpp_multi, mpp_delete, mpp_io_exit, &
155use fms_io_mod,
only : fms_io_init, fms_io_exit, field_size, &
156 read_data, write_data, read_compressed, read_distributed, &
157 open_namelist_file, open_restart_file, open_ieee32_file, close_file, &
159 open_file, open_direct_file, get_mosaic_tile_grid, &
160 get_mosaic_tile_file, get_global_att_value, file_exist, field_exist, &
161 set_domain, nullify_domain
167use platform_mod,
only: r4_kind, r8_kind
169use,
intrinsic :: iso_c_binding
175public :: fms_init, fms_end
178#ifdef use_deprecated_io
179public :: open_namelist_file, open_restart_file, &
185public :: get_domain_decomp, field_size
186public :: get_global_att_value
189public :: get_mosaic_tile_grid, get_mosaic_tile_file
192public :: file_exist, field_exist
194public ::check_nml_error, error_mesg, fms_error_handler
197public :: write_version_number
200public :: lowercase, uppercase, &
201 string_array_index, monotonic_array
202#ifdef use_deprecated_io
203public :: set_domain, nullify_domain
207public ::
mpp_error, note, warning, fatal, &
209 mpp_pe, mpp_npes, mpp_root_pe, &
210 stdin, stdout, stderr, stdlog, &
212public :: input_nml_file
213public :: mpp_clock_id, mpp_clock_begin, mpp_clock_end
214public :: mpp_clock_sync, mpp_clock_detailed
215public :: clock_component, clock_subcomponent, &
216 clock_module_driver, clock_module, &
217 clock_routine, clock_loop, clock_infra
223#ifdef use_deprecated_io
224public :: do_cf_compliance
227interface monotonic_array
228 module procedure :: monotonic_array_r4, monotonic_array_r8
229end interface monotonic_array
234integer,
public :: clock_flag_default
239 INTEGER :: multipleNMLSinFile
242 INTEGER :: missingVar
244 END TYPE nml_errors_type
245 TYPE(nml_errors_type),
SAVE :: nml_errors
252 logical :: read_all_pe = .true.
255 character(len=16) :: clock_grain =
'NONE'
262 character(len=16) :: clock_flags=
'NONE'
268 character(len=8) :: warning_level =
'warning'
272 integer :: stack_size = 0
275 integer :: domains_stack_size = 0
280 logical,
public :: print_memory_usage = .false.
286 namelist /fms_nml/ read_all_pe, clock_grain, clock_flags, &
287 warning_level, stack_size, domains_stack_size, &
292 integer,
private :: num_nml_error_codes, nml_error_codes(20)
293 logical,
private :: do_nml_error_init = .true.
294 private nml_error_init
300#include<file_version.h>
302 logical :: module_is_initialized = .false.
304 logical,
private :: fms_io_initialized = .false.
331subroutine fms_init (localcomm, alt_input_nml_path)
334 use constants_mod,
only: constants_version=>version
335#ifdef use_deprecated_io
336 use fms_io_mod,
only: fms_io_version
340 subroutine maximize_system_stacksize_limit()
bind(C)
344 integer,
intent(in),
optional :: localcomm
345 character(len=*),
intent(in),
optional :: alt_input_nml_path
347 integer :: logunitnum
348 integer :: stdout_unit
350 if (module_is_initialized)
return
351 module_is_initialized = .true.
354 call maximize_system_stacksize_limit
357 if(
present(localcomm))
then
358 if(
present(alt_input_nml_path))
then
359 call mpp_init(localcomm=localcomm, alt_input_nml_path=alt_input_nml_path)
361 call mpp_init(localcomm=localcomm)
364 if(
present(alt_input_nml_path))
then
365 call mpp_init(alt_input_nml_path=alt_input_nml_path)
370 call mpp_domains_init()
371#ifdef use_deprecated_io
375 if(.not.fms_io_initialized)
then
376#ifdef use_deprecated_io
377 call write_version_number(
"FMS_IO_MOD", fms_io_version)
379 fms_io_initialized = .true.
382 logunitnum = stdlog()
385 call nml_error_init()
387 read (input_nml_file, fms_nml, iostat=io)
388 ierr = check_nml_error(io,
'fms_nml')
392 if ( stack_size > 0)
call mpp_set_stack_size ( stack_size)
397 select case( trim(lowercase(warning_level)) )
399 call mpp_set_warn_level ( fatal )
401 call mpp_set_warn_level ( warning )
403 call error_mesg (
'fms_init', &
404 'invalid entry for namelist variable warning_level', fatal )
409 select case( trim(uppercase(clock_grain)) )
411 call mpp_clock_set_grain (0)
413 call mpp_clock_set_grain (clock_component)
414 case(
'SUBCOMPONENT' )
415 call mpp_clock_set_grain (clock_subcomponent)
416 case(
'MODULE_DRIVER' )
417 call mpp_clock_set_grain (clock_module_driver)
419 call mpp_clock_set_grain (clock_module)
421 call mpp_clock_set_grain (clock_routine)
423 call mpp_clock_set_grain (clock_loop)
425 call mpp_clock_set_grain (clock_infra)
427 call error_mesg (
'fms_init', &
428 'invalid entry for namelist variable clock_grain', fatal )
431 select case( trim(uppercase(clock_flags)) )
433 clock_flag_default = 0
435 clock_flag_default = mpp_clock_sync
437 clock_flag_default = mpp_clock_detailed
439 call error_mesg (
'fms_init', &
440 'invalid entry for namelist variable clock_flags', fatal )
445 call write_version_number(
"FMS_MOD", version)
446 if (mpp_pe() == mpp_root_pe())
then
447 stdout_unit = stdlog()
448 write (stdout_unit, nml=fms_nml)
449 write (stdout_unit,*)
'nml_error_codes=', nml_error_codes(1:num_nml_error_codes)
456 call write_version_number(
"CONSTANTS_MOD", constants_version)
459end subroutine fms_init
468subroutine fms_end ( )
470 if (.not.module_is_initialized)
return
473#ifdef use_deprecated_io
476 call mpp_domains_exit
478 module_is_initialized =.false.
480end subroutine fms_end
497 subroutine error_mesg (routine, message, level)
498 character(len=*),
intent(in) :: routine
499 character(len=*),
intent(in) :: message
500 integer,
intent(in) :: level
508 if (.not.module_is_initialized)
call fms_init ( )
509 call mpp_error ( routine, message, level )
511 end subroutine error_mesg
524 function fms_error_handler(routine, message, err_msg)
526 logical :: fms_error_handler
527 character(len=*),
intent(in) :: routine
528 character(len=*),
intent(in) :: message
529 character(len=*),
intent(out),
optional :: err_msg
531 fms_error_handler = .false.
532 if(
present(err_msg))
then
534 fms_error_handler = .true.
536 call mpp_error(trim(routine),trim(message),fatal)
539 end function fms_error_handler
579 INTEGER FUNCTION check_nml_error(IOSTAT, NML_NAME)
580 INTEGER,
INTENT(in) :: IOSTAT
581 CHARACTER(len=*),
INTENT(in) :: NML_NAME
584 CHARACTER(len=256) :: err_str
586 IF ( .NOT.module_is_initialized)
CALL fms_init()
588 check_nml_error = iostat
591 IF ( iostat <= 0 .OR.&
592 & iostat == nml_errors%multipleNMLSinFile .OR.&
593 & iostat == nml_errors%NotInFile)
RETURN
596 IF ( (iostat == nml_errors%badType1 .OR. iostat == nml_errors%badType2) .OR. iostat == nml_errors%missingVar )
THEN
597 WRITE (err_str,*)
'Unknown namelist, or mistyped namelist variable in namelist ',trim(nml_name),
', &
598 & (IOSTAT = ',iostat,
')'
599 CALL error_mesg (
'check_nml_error in fms_mod', err_str, fatal)
602 WRITE (err_str,*)
'Unknown error while reading namelist ',trim(nml_name),
', (IOSTAT = ',iostat,
')'
603 CALL error_mesg (
'check_nml_error in fms_mod', err_str, fatal)
606 END FUNCTION check_nml_error
614 SUBROUTINE nml_error_init
618 INTEGER,
PARAMETER :: unit_begin = 20, unit_end = 1024
619 INTEGER :: fileunit, io_stat
620 INTEGER,
DIMENSION(5) :: nml_iostats
628 namelist /a_nml/ i1, r1
629 namelist /b_nml/ i2, r2, l1
630 namelist /badtype1_nml/ i1, r1
631 namelist /badtype2_nml/ i1, r1
632 namelist /missingvar_nml/ i2, r2
633 namelist /not_in_file_nml/ i2, r2
643 IF ( mpp_pe() == mpp_root_pe() )
THEN
645 file_opened:
DO fileunit = unit_begin, unit_end
646 INQUIRE(unit=fileunit, opened=opened)
647 IF ( .NOT.opened )
EXIT file_opened
650#if defined(__PGI) || defined(_CRAYFTN)
651 OPEN (unit=fileunit, file=
'_read_error.nml', iostat=io_stat)
653 OPEN (unit=fileunit, status=
'SCRATCH', iostat=io_stat)
657 WRITE (unit=fileunit, nml=a_nml, iostat=io_stat)
658 WRITE (unit=fileunit, nml=b_nml, iostat=io_stat)
659 WRITE (unit=fileunit, iostat=io_stat, fmt=
'(/,"&badType1_nml i1=1, r1=''bad'' /",/)')
660 WRITE (unit=fileunit, iostat=io_stat, fmt=
'(/,"&badType2_nml i1=1, r1=.true. /",/)')
661 WRITE (unit=fileunit, iostat=io_stat, fmt=
'(/,"&missingVar_nml i2=1, r2=1.0e0, l1=.true. /",/)')
664 rewind(unit=fileunit)
667 READ (unit=fileunit, nml=b_nml, iostat=nml_iostats(1))
668 rewind(unit=fileunit)
671 READ (unit=fileunit, nml=badtype1_nml, iostat=nml_iostats(2))
672 rewind(unit=fileunit)
675 READ (unit=fileunit, nml=badtype2_nml, iostat=nml_iostats(3))
676 rewind(unit=fileunit)
679 READ (unit=fileunit, nml=missingvar_nml, iostat=nml_iostats(4))
680 rewind(unit=fileunit)
683 READ (unit=fileunit, nml=not_in_file_nml, iostat=nml_iostats(5))
686 CLOSE (unit=fileunit)
689 IF ( nml_iostats(2) * nml_iostats(3) .EQ. 0 )
THEN
690 IF ( nml_iostats(2) .NE. 0 .AND. nml_iostats(3) .EQ. 0 )
THEN
691 nml_iostats(3) = nml_iostats(2)
692 ELSE IF ( nml_iostats(2) .EQ. 0 .AND. nml_iostats(3) .NE.0 )
THEN
693 nml_iostats(2) = nml_iostats(3)
695 nml_iostats(2) = nml_iostats(4)
696 nml_iostats(2) = nml_iostats(4)
703 nml_errors%multipleNMLSinFile = nml_iostats(1)
704 nml_errors%badType1 = nml_iostats(2)
705 nml_errors%badType2 = nml_iostats(3)
706 nml_errors%missingVar = nml_iostats(4)
707 nml_errors%NotInFile = nml_iostats(5)
709 do_nml_error_init = .false.
710 END SUBROUTINE nml_error_init
729function string_array_index ( string, string_array, index )
result (found)
730character(len=*),
intent(in) :: string
731character(len=*),
intent(in) :: string_array(:)
732integer,
optional,
intent(out) :: index
741 if (
present(index)) index = 0
743 do i = 1,
size(string_array(:))
745 if ( trim(string) == trim(string_array(i)) )
then
747 if (
present(index)) index = i
752end function string_array_index
757subroutine write_version_number (version, tag, unit)
758 character(len=*),
intent(in) :: version
759 character(len=*),
intent(in),
optional :: tag
760 integer,
intent(in),
optional :: unit
764 if (.not.module_is_initialized)
call fms_init ( )
768 if (
present(unit))
then
772 if ( mpp_pe() /= mpp_root_pe() )
return
775 if (
present(tag))
then
776 write (logunit,
'(/,80("="),/(a))') trim(version), trim(tag)
778 write (logunit,
'(/,80("="),/(a))') trim(version)
781end subroutine write_version_number
subroutine, public fms2_io_init()
Reads the fms2_io_nml.
Close a netcdf or domain file opened with open_file or open_virtual_file.
Opens a given netcdf or domain file.
Read data from a defined field in a file.
Write data to a defined field within a file Example usage:
character(:) function, allocatable, public string(v, fmt)
Converts a number or a Boolean value to a string.
subroutine, public grid_end
Shutdown the grid2 module.
subroutine, public grid_init
Initialize the grid2 module.
subroutine, public print_memuse_stats(text, unit, always)
Print memory usage stats to stdout, or a particular file.
subroutine, public memutils_init(print_flag)
Initialize the memutils module.
subroutine mpp_domains_set_stack_size(n)
Set user stack size.
Set up a domain decomposition.
These routines retrieve the axis specifications associated with the compute domains....
These routines retrieve the axis specifications associated with the data domains. The domain is a der...
These routines retrieve the axis specifications associated with the global domains....
Fill in a global array from domain-decomposed arrays.
Performs halo updates for a given domain.
The domain2D type contains all the necessary information to define the global, compute and data domai...
subroutine mpp_get_info(unit, ndim, nvar, natt, ntime)
Get some general information about a file.
subroutine mpp_get_fields(unit, variables)
Copy variable information from file (excluding data)
Get file global metadata.
subroutine mpp_sync(pelist, do_self)
Synchronize PEs in list.
Perform parallel broadcasts.
Calculate parallel checksums.
Basic message-passing call.
Converts a C string to a Fortran string.
converts a kind=c_char to type c_ptr