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...
 

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 711 of file MOM_file_parser.F90.

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

◆ 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 734 of file MOM_file_parser.F90.

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

◆ 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 572 of file MOM_file_parser.F90.

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

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

772  type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
773  !! it is also a structure to parse for run-time parameters
774  character(len=*), intent(in) :: varname !< The case-sensitive name of the parameter to read
775  logical, intent(inout) :: value !< The value of the parameter that may be
776  !! read from the parameter file
777  logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
778  !! if this variable is not found in the parameter file
779 
780  ! Local variables
781  character(len=INPUT_STR_LENGTH) :: value_string(1)
782  logical :: found, defined
783 
784  call get_variable_line(cs, varname, found, defined, value_string, paramislogical=.true.)
785  if (found) then
786  value = defined
787  elseif (present(fail_if_missing)) then ; if (fail_if_missing) then
788  call mom_error(fatal,'Unable to find variable '//trim(varname)// &
789  ' in any input files.')
790  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 637 of file MOM_file_parser.F90.

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

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

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

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