MOM6
mom_file_parser::read_param Interface Reference

Detailed Description

An overloaded interface to read various types of parameters.

Definition at line 90 of file MOM_file_parser.F90.

Private functions

subroutine read_param_int (CS, varname, value, fail_if_missing)
 This subroutine reads the value of an integer model parameter from a parameter file. More...
 
subroutine read_param_real (CS, varname, value, fail_if_missing, scale)
 This subroutine reads the value of a real model parameter from a parameter file. More...
 
subroutine read_param_logical (CS, varname, value, fail_if_missing)
 This subroutine reads the value of a logical model parameter from a parameter file. More...
 
subroutine read_param_char (CS, varname, value, fail_if_missing)
 This subroutine reads the value of a character string model parameter from a parameter file. More...
 
subroutine read_param_char_array (CS, varname, value, fail_if_missing)
 This subroutine reads the values of an array of character string model parameters from a parameter file. More...
 
subroutine read_param_time (CS, varname, value, timeunit, fail_if_missing, date_format)
 This subroutine reads the value of a time_type model parameter from a parameter file. More...
 
subroutine read_param_int_array (CS, varname, value, fail_if_missing)
 This subroutine reads the values of an array of integer model parameters from a parameter file. More...
 
subroutine read_param_real_array (CS, varname, value, fail_if_missing, scale)
 This subroutine reads the values of an array of real model parameters from a parameter file. More...
 

Detailed Description

An overloaded interface to read various types of parameters.

Definition at line 90 of file MOM_file_parser.F90.

Functions and subroutines

◆ read_param_char()

subroutine mom_file_parser::read_param::read_param_char ( type(param_file_type), intent(in)  CS,
character(len=*), intent(in)  varname,
character(len=*), intent(inout)  value,
logical, intent(in), optional  fail_if_missing 
)
private

This subroutine reads the value of a character string model parameter from a parameter file.

Parameters
[in]csThe control structure for the file_parser module, it is also a structure to parse for run-time parameters
[in]varnameThe case-sensitive name of the parameter to read
[in,out]valueThe value of the parameter that may be read from the parameter file
[in]fail_if_missingIf present and true, a fatal error occurs if this variable is not found in the parameter file

Definition at line 719 of file MOM_file_parser.F90.

720  type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
721  !! it is also a structure to parse for run-time parameters
722  character(len=*), intent(in) :: varname !< The case-sensitive name of the parameter to read
723  character(len=*), intent(inout) :: value !< The value of the parameter that may be
724  !! read from the parameter file
725  logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
726  !! if this variable is not found in the parameter file
727  ! Local variables
728  character(len=INPUT_STR_LENGTH) :: value_string(1)
729  logical :: found, defined
730 
731  call get_variable_line(cs, varname, found, defined, value_string)
732  if (found) then
733  value = trim(strip_quotes(value_string(1)))
734  elseif (present(fail_if_missing)) then ; if (fail_if_missing) then
735  call mom_error(fatal,'Unable to find variable '//trim(varname)// &
736  ' in any input files.')
737  endif ; endif
738 

◆ read_param_char_array()

subroutine mom_file_parser::read_param::read_param_char_array ( type(param_file_type), intent(in)  CS,
character(len=*), intent(in)  varname,
character(len=*), dimension(:), intent(inout)  value,
logical, intent(in), optional  fail_if_missing 
)
private

This subroutine reads the values of an array of character string model parameters from a parameter file.

Parameters
[in]csThe control structure for the file_parser module, it is also a structure to parse for run-time parameters
[in]varnameThe case-sensitive name of the parameter to read
[in,out]valueThe value of the parameter that may be read from the parameter file
[in]fail_if_missingIf present and true, a fatal error occurs if this variable is not found in the parameter file

Definition at line 742 of file MOM_file_parser.F90.

743  type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
744  !! it is also a structure to parse for run-time parameters
745  character(len=*), intent(in) :: varname !< The case-sensitive name of the parameter to read
746  character(len=*), dimension(:), intent(inout) :: value !< The value of the parameter that may be
747  !! read from the parameter file
748  logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
749  !! if this variable is not found in the parameter file
750 
751  ! Local variables
752  character(len=INPUT_STR_LENGTH) :: value_string(1), loc_string
753  logical :: found, defined
754  integer :: i, i_out
755 
756  call get_variable_line(cs, varname, found, defined, value_string)
757  if (found) then
758  loc_string = trim(value_string(1))
759  i = index(loc_string,",")
760  i_out = 1
761  do while(i>0)
762  value(i_out) = trim(strip_quotes(loc_string(:i-1)))
763  i_out = i_out+1
764  loc_string = trim(adjustl(loc_string(i+1:)))
765  i = index(loc_string,",")
766  enddo
767  if (len_trim(loc_string)>0) then
768  value(i_out) = trim(strip_quotes(adjustl(loc_string)))
769  i_out = i_out+1
770  endif
771  do i=i_out,SIZE(value) ; value(i) = " " ; enddo
772  elseif (present(fail_if_missing)) then ; if (fail_if_missing) then
773  call mom_error(fatal,'Unable to find variable '//trim(varname)// &
774  ' in any input files.')
775  endif ; endif
776 

◆ read_param_int()

subroutine mom_file_parser::read_param::read_param_int ( type(param_file_type), intent(in)  CS,
character(len=*), intent(in)  varname,
integer, intent(inout)  value,
logical, intent(in), optional  fail_if_missing 
)
private

This subroutine reads the value of an integer model parameter from a parameter file.

Parameters
[in]csThe control structure for the file_parser module, it is also a structure to parse for run-time parameters
[in]varnameThe case-sensitive name of the parameter to read
[in,out]valueThe value of the parameter that may be read from the parameter file
[in]fail_if_missingIf present and true, a fatal error occurs if this variable is not found in the parameter file

Definition at line 580 of file MOM_file_parser.F90.

581  type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
582  !! it is also a structure to parse for run-time parameters
583  character(len=*), intent(in) :: varname !< The case-sensitive name of the parameter to read
584  integer, intent(inout) :: value !< The value of the parameter that may be
585  !! read from the parameter file
586  logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
587  !! if this variable is not found in the parameter file
588  ! Local variables
589  character(len=INPUT_STR_LENGTH) :: value_string(1)
590  logical :: found, defined
591 
592  call get_variable_line(cs, varname, found, defined, value_string)
593  if (found .and. defined .and. (len_trim(value_string(1)) > 0)) then
594  read(value_string(1),*,err = 1001) value
595  else
596  if (present(fail_if_missing)) then ; if (fail_if_missing) then
597  if (.not.found) then
598  call mom_error(fatal,'read_param_int: Unable to find variable '//trim(varname)// &
599  ' in any input files.')
600  else
601  call mom_error(fatal,'read_param_int: Variable '//trim(varname)// &
602  ' found but not set in input files.')
603  endif
604  endif ; endif
605  endif
606  return
607  1001 call mom_error(fatal,'read_param_int: read error for integer variable '//trim(varname)// &
608  ' parsing "'//trim(value_string(1))//'"')

◆ read_param_int_array()

subroutine mom_file_parser::read_param::read_param_int_array ( type(param_file_type), intent(in)  CS,
character(len=*), intent(in)  varname,
integer, dimension(:), intent(inout)  value,
logical, intent(in), optional  fail_if_missing 
)
private

This subroutine reads the values of an array of integer model parameters from a parameter file.

Parameters
[in]csThe control structure for the file_parser module, it is also a structure to parse for run-time parameters
[in]varnameThe case-sensitive name of the parameter to read
[in,out]valueThe value of the parameter that may be read from the parameter file
[in]fail_if_missingIf present and true, a fatal error occurs if this variable is not found in the parameter file

Definition at line 612 of file MOM_file_parser.F90.

613  type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
614  !! it is also a structure to parse for run-time parameters
615  character(len=*), intent(in) :: varname !< The case-sensitive name of the parameter to read
616  integer, dimension(:), intent(inout) :: value !< The value of the parameter that may be
617  !! read from the parameter file
618  logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
619  !! if this variable is not found in the parameter file
620  ! Local variables
621  character(len=INPUT_STR_LENGTH) :: value_string(1)
622  logical :: found, defined
623 
624  call get_variable_line(cs, varname, found, defined, value_string)
625  if (found .and. defined .and. (len_trim(value_string(1)) > 0)) then
626  read(value_string(1),*,end=991,err=1002) value
627  991 return
628  else
629  if (present(fail_if_missing)) then ; if (fail_if_missing) then
630  if (.not.found) then
631  call mom_error(fatal,'read_param_int_array: Unable to find variable '//trim(varname)// &
632  ' in any input files.')
633  else
634  call mom_error(fatal,'read_param_int_array: Variable '//trim(varname)// &
635  ' found but not set in input files.')
636  endif
637  endif ; endif
638  endif
639  return
640  1002 call mom_error(fatal,'read_param_int_array: read error for integer array '//trim(varname)// &
641  ' parsing "'//trim(value_string(1))//'"')

◆ read_param_logical()

subroutine mom_file_parser::read_param::read_param_logical ( type(param_file_type), intent(in)  CS,
character(len=*), intent(in)  varname,
logical, intent(inout)  value,
logical, intent(in), optional  fail_if_missing 
)
private

This subroutine reads the value of a logical model parameter from a parameter file.

Parameters
[in]csThe control structure for the file_parser module, it is also a structure to parse for run-time parameters
[in]varnameThe case-sensitive name of the parameter to read
[in,out]valueThe value of the parameter that may be read from the parameter file
[in]fail_if_missingIf present and true, a fatal error occurs if this variable is not found in the parameter file

Definition at line 780 of file MOM_file_parser.F90.

781  type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
782  !! it is also a structure to parse for run-time parameters
783  character(len=*), intent(in) :: varname !< The case-sensitive name of the parameter to read
784  logical, intent(inout) :: value !< The value of the parameter that may be
785  !! read from the parameter file
786  logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
787  !! if this variable is not found in the parameter file
788 
789  ! Local variables
790  character(len=INPUT_STR_LENGTH) :: value_string(1)
791  logical :: found, defined
792 
793  call get_variable_line(cs, varname, found, defined, value_string, paramislogical=.true.)
794  if (found) then
795  value = defined
796  elseif (present(fail_if_missing)) then ; if (fail_if_missing) then
797  call mom_error(fatal,'Unable to find variable '//trim(varname)// &
798  ' in any input files.')
799  endif ; endif

◆ read_param_real()

subroutine mom_file_parser::read_param::read_param_real ( type(param_file_type), intent(in)  CS,
character(len=*), intent(in)  varname,
real, intent(inout)  value,
logical, intent(in), optional  fail_if_missing,
real, intent(in), optional  scale 
)
private

This subroutine reads the value of a real model parameter from a parameter file.

Parameters
[in]csThe control structure for the file_parser module, it is also a structure to parse for run-time parameters
[in]varnameThe case-sensitive name of the parameter to read
[in,out]valueThe value of the parameter that may be read from the parameter file
[in]fail_if_missingIf present and true, a fatal error occurs if this variable is not found in the parameter file
[in]scaleA scaling factor that the parameter is multiplied by before it is returned.

Definition at line 645 of file MOM_file_parser.F90.

646  type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
647  !! it is also a structure to parse for run-time parameters
648  character(len=*), intent(in) :: varname !< The case-sensitive name of the parameter to read
649  real, intent(inout) :: value !< The value of the parameter that may be
650  !! read from the parameter file
651  logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
652  !! if this variable is not found in the parameter file
653  real, optional, intent(in) :: scale !< A scaling factor that the parameter is multiplied
654  !! by before it is returned.
655 
656  ! Local variables
657  character(len=INPUT_STR_LENGTH) :: value_string(1)
658  logical :: found, defined
659 
660  call get_variable_line(cs, varname, found, defined, value_string)
661  if (found .and. defined .and. (len_trim(value_string(1)) > 0)) then
662  read(value_string(1),*,err=1003) value
663  if (present(scale)) value = scale*value
664  else
665  if (present(fail_if_missing)) then ; if (fail_if_missing) then
666  if (.not.found) then
667  call mom_error(fatal,'read_param_real: Unable to find variable '//trim(varname)// &
668  ' in any input files.')
669  else
670  call mom_error(fatal,'read_param_real: Variable '//trim(varname)// &
671  ' found but not set in input files.')
672  endif
673  endif ; endif
674  endif
675  return
676  1003 call mom_error(fatal,'read_param_real: read error for real variable '//trim(varname)// &
677  ' parsing "'//trim(value_string(1))//'"')

◆ read_param_real_array()

subroutine mom_file_parser::read_param::read_param_real_array ( type(param_file_type), intent(in)  CS,
character(len=*), intent(in)  varname,
real, dimension(:), intent(inout)  value,
logical, intent(in), optional  fail_if_missing,
real, intent(in), optional  scale 
)
private

This subroutine reads the values of an array of real model parameters from a parameter file.

Parameters
[in]csThe control structure for the file_parser module, it is also a structure to parse for run-time parameters
[in]varnameThe case-sensitive name of the parameter to read
[in,out]valueThe value of the parameter that may be read from the parameter file
[in]fail_if_missingIf present and true, a fatal error occurs if this variable is not found in the parameter file
[in]scaleA scaling factor that the parameter is multiplied by before it is returned.

Definition at line 681 of file MOM_file_parser.F90.

682  type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
683  !! it is also a structure to parse for run-time parameters
684  character(len=*), intent(in) :: varname !< The case-sensitive name of the parameter to read
685  real, dimension(:), intent(inout) :: value !< The value of the parameter that may be
686  !! read from the parameter file
687  logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
688  !! if this variable is not found in the parameter file
689  real, optional, intent(in) :: scale !< A scaling factor that the parameter is multiplied
690  !! by before it is returned.
691 
692  ! Local variables
693  character(len=INPUT_STR_LENGTH) :: value_string(1)
694  logical :: found, defined
695 
696  call get_variable_line(cs, varname, found, defined, value_string)
697  if (found .and. defined .and. (len_trim(value_string(1)) > 0)) then
698  read(value_string(1),*,end=991,err=1004) value
699 991 continue
700  if (present(scale)) value(:) = scale*value(:)
701  return
702  else
703  if (present(fail_if_missing)) then ; if (fail_if_missing) then
704  if (.not.found) then
705  call mom_error(fatal,'read_param_real_array: Unable to find variable '//trim(varname)// &
706  ' in any input files.')
707  else
708  call mom_error(fatal,'read_param_real_array: Variable '//trim(varname)// &
709  ' found but not set in input files.')
710  endif
711  endif ; endif
712  endif
713  return
714  1004 call mom_error(fatal,'read_param_real_array: read error for real array '//trim(varname)// &
715  ' parsing "'//trim(value_string(1))//'"')

◆ read_param_time()

subroutine mom_file_parser::read_param::read_param_time ( type(param_file_type), intent(in)  CS,
character(len=*), intent(in)  varname,
type(time_type), intent(inout)  value,
real, intent(in), optional  timeunit,
logical, intent(in), optional  fail_if_missing,
logical, intent(out), optional  date_format 
)
private

This subroutine reads the value of a time_type model parameter from a parameter file.

Parameters
[in]csThe control structure for the file_parser module, it is also a structure to parse for run-time parameters
[in]varnameThe case-sensitive name of the parameter to read
[in,out]valueThe value of the parameter that may be read from the parameter file
[in]timeunitThe number of seconds in a time unit for real-number input.
[in]fail_if_missingIf present and true, a fatal error occurs if this variable is not found in the parameter file
[out]date_formatIf present, this indicates whether this parameter was read in a date format, so that it can later be logged in the same format.

Definition at line 803 of file MOM_file_parser.F90.

804  type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
805  !! it is also a structure to parse for run-time parameters
806  character(len=*), intent(in) :: varname !< The case-sensitive name of the parameter to read
807  type(time_type), intent(inout) :: value !< The value of the parameter that may be
808  !! read from the parameter file
809  real, optional, intent(in) :: timeunit !< The number of seconds in a time unit for real-number input.
810  logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
811  !! if this variable is not found in the parameter file
812  logical, optional, intent(out) :: date_format !< If present, this indicates whether this
813  !! parameter was read in a date format, so that it can
814  !! later be logged in the same format.
815 
816  ! Local variables
817  character(len=INPUT_STR_LENGTH) :: value_string(1)
818  character(len=240) :: err_msg
819  logical :: found, defined
820  real :: real_time, time_unit
821  integer :: vals(7)
822 
823  if (present(date_format)) date_format = .false.
824 
825  call get_variable_line(cs, varname, found, defined, value_string)
826  if (found .and. defined .and. (len_trim(value_string(1)) > 0)) then
827  ! Determine whether value string should be parsed for a real number
828  ! or a date, in either a string format or a comma-delimited list of values.
829  if ((index(value_string(1),'-') > 0) .and. &
830  (index(value_string(1),'-',back=.true.) > index(value_string(1),'-'))) then
831  ! There are two dashes, so this must be a date format.
832  value = set_date(value_string(1), err_msg=err_msg)
833  if (len_trim(err_msg) > 0) call mom_error(fatal,'read_param_time: '//&
834  trim(err_msg)//' in integer list read error for time-type variable '//&
835  trim(varname)// ' parsing "'//trim(value_string(1))//'"')
836  if (present(date_format)) date_format = .true.
837  elseif (index(value_string(1),',') > 0) then
838  ! Initialize vals with an invalid date.
839  vals(:) = (/ -999, -999, -999, 0, 0, 0, 0 /)
840  read(value_string(1),*,end=995,err=1005) vals
841  995 continue
842  if ((vals(1) < 0) .or. (vals(2) < 0) .or. (vals(3) < 0)) &
843  call mom_error(fatal,'read_param_time: integer list read error for time-type variable '//&
844  trim(varname)// ' parsing "'//trim(value_string(1))//'"')
845  value = set_date(vals(1), vals(2), vals(3), vals(4), vals(5), vals(6), &
846  vals(7), err_msg=err_msg)
847  if (len_trim(err_msg) > 0) call mom_error(fatal,'read_param_time: '//&
848  trim(err_msg)//' in integer list read error for time-type variable '//&
849  trim(varname)// ' parsing "'//trim(value_string(1))//'"')
850  if (present(date_format)) date_format = .true.
851  else
852  time_unit = 1.0 ; if (present(timeunit)) time_unit = timeunit
853  read( value_string(1), *) real_time
854  value = real_to_time(real_time*time_unit)
855  endif
856  else
857  if (present(fail_if_missing)) then ; if (fail_if_missing) then
858  if (.not.found) then
859  call mom_error(fatal,'Unable to find variable '//trim(varname)// &
860  ' in any input files.')
861  else
862  call mom_error(fatal,'Variable '//trim(varname)// &
863  ' found but not set in input files.')
864  endif
865  endif ; endif
866  endif
867  return
868  1005 call mom_error(fatal,'read_param_time: read error for time-type variable '//&
869  trim(varname)// ' parsing "'//trim(value_string(1))//'"')

The documentation for this interface was generated from the following file: