process_input Module

Module containing the routines that perform the actual reading and parsing of the input file author: P J Knight, CCFE, Culham Science Centre N/A This module provides a set of routines to read in data from the main PROCESS input file (IN.DAT). The format of the file is similar to the F90 NAMELIST structure, but with a few additional features:

  1. Comments can be read in that are copied to the standard output channel - these are lines with five (or more) consecutive '*' characters at the start.

  2. Other lines within the file can contain simple comments for the user - these are not copied to the standard output channel. They start with one to four '*' characters.

Character strings, integers and double precision values can be read in.

The following rules must be obeyed when writing an input file:

  • Each variable must be on a separate line.

  • Leading spaces are ignored.

  • Variable names can be upper case, lower case, or a mixture of both.

  • Spaces may not appear within a variable name or data value.

  • Other spaces within a line, and trailing spaces, are ignored.

  • Commas are not necessary between variables.

  • Data can extend over more than one line.

  • One-dimensional arrays can be explicitly subscripted, or unscripted, in which case the following element order is assumed: A(1), A(2), A(3), ...

  • At present, multiple dimension arrays can only be handled without reference to explicit subscripts, in which case the following element order is assumed: B(1,1), B(2,1), B(3,1), etc. The use of the input file to specify multiple dimension array elements is prone to error.

  • Unscripted array elements must be separated by commas.

  • Blank lines are allowed anywhere in the input file.

  • Lines starting with a * are assumed to be comments.

  • Comment lines starting with five or more asterisks (i.e. *****) are reproduced verbatim in the output file. These should be used copiously to give a great deal of information about the run being performed, and should be updated before every single run of the code, as it is very easy to lose track of what is being attempted.
A User's Guide to the PROCESS Systems Code, P. J. Knight, AEA Fusion Report AEA FUS 251, 1993

Contents


Variables

TypeVisibility AttributesNameInitial
integer, public, parameter:: nin =10
integer, private, parameter:: maxlen =2000
character(len=maxlen), private :: line
integer, private :: linelen
integer, private :: lineno
integer, private :: iptr
integer, private :: infile
integer, private :: outfile
integer, private :: report_changes
integer, private :: icode
logical, private :: subscript_present
logical, private :: error
character(len=78), private :: error_message
integer, private :: show_changes
logical, private :: constraints_exist

Subroutines

public subroutine init_input()

Initialise module variables

Arguments

None

public subroutine input()

Routine that calls the main input file parsing routines author: P J Knight, CCFE, Culham Science Centre None This routine provides the interface between the input file reading routines and the rest of PROCESS. A User's Guide to the PROCESS Systems Code, P. J. Knight, AEA Fusion Report AEA FUS 251, 1993

Arguments

None

private subroutine devtyp()

Set icase description based on device type

Arguments

None

private subroutine parse_input_file(in_file, out_file, show_changes)

Routine that parses the contents of the input file author: P J Knight, CCFE, Culham Science Centre author: J Morris, CCFE, Culham Science Centre author: F Warmer, IPP Greifswald in_file : input integer : Fortran input unit identifier out_file : input integer : Fortran output unit identifier show_changes : input integer : switch to turn on (1) or off (0) reporting of changed values This routine reads the data from the PROCESS input file (IN.DAT), dealing with comments or blank lines correctly, and sets the value of any variables found in the file. Any changes from the default values may be reported if required.

Each possible variable in this block is dealt with individually. (To add additional input variables, simply copy and edit one of the similar existing examples.) The routine also does the extremely useful function of checking that the given value for a variable lies within a sensible predefined range, and stops the program if apparently nonsensical values are attempted. A User's Guide to the PROCESS Systems Code, P. J. Knight, AEA Fusion Report AEA FUS 251, 1993

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: in_file
integer, intent(in) :: out_file
integer, intent(in) :: show_changes

private subroutine parse_real_variable(varnam, varval, vmin, vmax, description)

Routine that obtains the value of a real variable from the input file and checks that it lies within the expected range author: P J Knight, CCFE, Culham Science Centre varnam : input string : name of the variable varval : input/output real : value of the variable vmin : input real : minimum allowed value for the variable vmax : input real : maximum allowed value for the variable description : input string : brief description of the variable This routine parses a line containing a 'name = value' pair for a real variable, extracting the value from the line and checking whether it lies between user-defined lower and upper limits. None

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: varnam
real(kind=dp), intent(inout) :: varval
real(kind=dp), intent(in) :: vmin
real(kind=dp), intent(in) :: vmax
character(len=*), intent(in) :: description

private subroutine parse_int_variable(varnam, varval, vmin, vmax, description)

Routine that obtains the value of an integer variable from the input file and checks that it lies within the expected range author: P J Knight, CCFE, Culham Science Centre varnam : input string : name of the variable varval : input/output integer : value of the variable vmin : input integer : minimum allowed value for the variable vmax : input integer : maximum allowed value for the variable description : input string : brief description of the variable This routine parses a line containing a 'name = value' pair for an integer variable, extracting the value from the line and checking whether it lies between user-defined lower and upper limits. None

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: varnam
integer, intent(inout) :: varval
integer, intent(in) :: vmin
integer, intent(in) :: vmax
character(len=*), intent(in) :: description

private subroutine parse_string_variable(varnam, varval, description)

Routine that obtains the value of a string variable from the input file author: P J Knight, CCFE, Culham Science Centre varnam : input string : name of the variable varval : input/output string : value of the variable description : input string : brief description of the variable This routine parses a line containing a 'name = value' pair for a string variable, extracting the value from the line. None

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: varnam
character(len=*), intent(inout) :: varval
character(len=*), intent(in) :: description

private subroutine parse_real_array(varnam, varval, isub1, n, description, icode)

Routine that obtains the values of a real array from the input file author: P J Knight, CCFE, Culham Science Centre varnam : input string : name of the variable varval(n) : input/output real array : value of the variable isub1 : input integer : array element pointer n : input integer : size of varval array icode : output integer : diagnostic flag description : input string : brief description of the variable This routine parses a line in one of the two following forms:

 name = v1[, v2, ...]
 name(element) = v
 

Read more…

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: varnam
real(kind=dp), intent(inout), dimension(n):: varval
integer, intent(inout) :: isub1
integer, intent(in) :: n
character(len=*), intent(in) :: description
integer, intent(out) :: icode

private subroutine parse_int_array(varnam, varval, isub1, n, description, icode, startindex)

Routine that obtains the values of an integer array from the input file author: P J Knight, CCFE, Culham Science Centre varnam : input string : name of the variable varval(n) : input/output integer array : value of the variable isub1 : input integer : array element pointer n : input integer : size of varval array icode : output integer : diagnostic flag description : input string : brief description of the variable This routine parses a line in one of the two following forms:

 name = v1[, v2, ...]
 name(element) = v
 

Read more…

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: varnam
integer, intent(inout), dimension(n):: varval
integer, intent(inout) :: isub1
integer, intent(in) :: n
character(len=*), intent(in) :: description
integer, intent(out) :: icode
integer, intent(in), optional :: startindex

private subroutine string_to_int(string, length, ivar, icode)

Routine that converts the ASCII digits in a string to an integer author: P J Knight, CCFE, Culham Science Centre string : input string : contains digits of the number length : input integer : useful length of character string ivar : output integer : value stored in the string icode : output integer : diagnostic flag This routine converts the ASCII digits in string(1:length) to the integer ivar. It is equivalent to doing 'READ(STRING(1:LENGTH),I) IVAR' but this routine conforms to the ANSI standard. Each digit is parsed in turn, the current total is multiplied by ten and the new digit is added. None

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: string
integer, intent(in) :: length
integer, intent(out) :: ivar
integer, intent(out) :: icode

private subroutine string_to_real(string, length, rval, icode)

Routine that converts the ASCII digits in a string to a real value author: P J Knight, CCFE, Culham Science Centre string : input string : contains digits of the number length : input integer : useful length of character string rvar : output real : value stored in the string icode : output integer : diagnostic flag This routine converts the ASCII digits in string(1:length) to the real variable rvar. The string is parsed one character at a time, from the left, handling the mantissa, and all other components of the real number separately, combining them at the end. None

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: string
integer, intent(in) :: length
real(kind=dp), intent(out) :: rval
integer, intent(out) :: icode

private subroutine get_value_int(ival, icode)

Routine that extracts an integer value from a line of the input file author: P J Knight, CCFE, Culham Science Centre ival : output integer : extracted integer value icode : output integer : diagnostic flag This routine extracts an integer value from the current line of the input file, i.e. the value of an integer variable as specified by the user. None

Arguments

Type IntentOptional AttributesName
integer, intent(out) :: ival
integer, intent(out) :: icode

private subroutine get_value_real(rval, icode)

Routine that extracts a real value from a line of the input file author: P J Knight, CCFE, Culham Science Centre rval : output real : extracted real value icode : output integer : diagnostic flag This routine extracts a real value from the current line of the input file, i.e. the value of a real variable as specified by the user. None

Arguments

Type IntentOptional AttributesName
real(kind=dp), intent(out) :: rval
integer, intent(out) :: icode

private subroutine get_substring(string, icode)

Routine that extracts a substring from a line of the input file author: P J Knight, CCFE, Culham Science Centre string : output string : extracted string icode : output integer : diagnostic flag This routine extracts a string from the current line of the input file, i.e. the value of a string variable as specified by the user. Unlike routine get_substring_trim, this routine does not truncate the string found at its first non-leading blank. None

Arguments

Type IntentOptional AttributesName
character(len=*), intent(out) :: string
integer, intent(out) :: icode

private subroutine get_subscript(isub1, isub2, icode)

Routine that extracts any subscripts present in a line of the input file author: P J Knight, CCFE, Culham Science Centre isub1 : output integer : first subscript found isub2 : output integer : second subscript found icode : output integer : diagnostic flag This routine extracts any subscripts from the current line of the input file, i.e. if any array elements are specified by the user. It looks at the next non-space character in the line, and if it is a left bracket, it assumes that at least one subscript is to follow and extracts it/them. None

Arguments

Type IntentOptional AttributesName
integer, intent(out) :: isub1
integer, intent(out) :: isub2
integer, intent(out) :: icode

private subroutine get_variable_name(varnam, varlen, isub1, isub2)

Routine that extracts a variable name from a line of the input file author: P J Knight, CCFE, Culham Science Centre varnam : output string : extracted variable name varlen : output integer : length of variable name isub1 : output integer : first subscript found isub2 : output integer : second subscript found This routine extracts a variable name from the current line of the input file. It also extracts any subscripts present. On exit, the counter iptr points to the first character of the value to be assigned to the variable. If the routine finds an error a value of 0 is returned in variable varlen. None

Arguments

Type IntentOptional AttributesName
character(len=*), intent(out) :: varnam
integer, intent(out) :: varlen
integer, intent(out) :: isub1
integer, intent(out) :: isub2

public subroutine check_range_int(cvar, varval, min_value, max_value)

Routine that checks whether an integer variable lies within the desired range author: P J Knight, CCFE, Culham Science Centre outfile : input integer : Fortran output unit identifier cvar : input string : name of variable varval : input integer : value of variable min_value : input integer : minimum allowed value of variable max_value : input integer : maximum allowed value of variable This routine checks whether an integer variable lies within the range predetermined by the user, and reports an error and stops if it doesn't. None

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: cvar
integer, intent(in) :: varval
integer, intent(in) :: min_value
integer, intent(in) :: max_value

public subroutine check_range_real(cvar, varval, min_value, max_value)

Routine that checks whether a real variable lies within the desired range author: P J Knight, CCFE, Culham Science Centre cvar : input string : name of variable varval : input real : value of variable min_value : input real : minimum allowed value of variable max_value : input real : maximum allowed value of variable This routine checks whether a real variable lies within the range predetermined by the user, and reports an error and stops if it doesn't. None

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: cvar
real(kind=dp), intent(in) :: varval
real(kind=dp), intent(in) :: min_value
real(kind=dp), intent(in) :: max_value

public subroutine lower_case(string, start, finish)

Routine that converts a (sub-)string to lowercase author: P J Knight, CCFE, Culham Science Centre string : input string : character string of interest start : optional input integer : starting character for conversion finish : optional input integer : final character for conversion This routine converts the specified section of a string to lowercase. By default, the whole string will be converted. None

Arguments

Type IntentOptional AttributesName
character(len=*), intent(inout) :: string
integer, intent(in), optional :: start
integer, intent(in), optional :: finish