Various utilities for working with input and output files, as well as some shims/backfills for standard features not present in older compilers.
This module is responsible for setting up the label for the run, run_name, as well as opening the main input file, the error file, and the exit reason file.
Most of the procedures in this module deal with files, and are therefore not 1/thread safe, and you must manually guard any opens/closes.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=run_name_size), | public, | pointer | :: | run_name |
Label for the run. Usually this is the input file without any extensions. Set by init_run_name |
||
character(len=run_name_size), | private, | target | :: | arun_name |
The full input file name, set by get_input_filename |
||
character(len=run_name_size), | private, | target | :: | job_name |
The current job name. See job_manage |
||
character(len=run_name_size), | public, | target | :: | run_name_target |
This array replaces the cbuff array in gs2_main. Having the target array in the same scope as the pointer is much better practice in general. |
||
character(len=run_name_size), | public | :: | list_name |
Label for the list, taken from the command line |
|||
integer, | public, | parameter | :: | stdout_unit | = | 6 |
Unit associated with stdout
FIXME: Use |
integer, | private | :: | input_unit_no |
Unit number for main input file |
|||
integer, | private | :: | error_unit_no | = | stdout_unit |
Unit number for main error file |
|
integer, | private | :: | exit_reason_unit_no | = | stdout_unit |
Unit number for exit reason file |
|
integer, | public | :: | num_input_lines |
Number of lines in input file |
|||
logical, | public | :: | initialized | = | .false. |
Is module initialized? |
Return the input filename as set by the command line
Returns true if input_filename is a list input: that is, if it ends in .list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input_filename |
Rewind the input file to start of namelist nml
, and return the unit of
the file opened by init_input_unit
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | nml |
Name of namelist to find start of |
Similar to input_unit but set exist
to true if nml
was found in the
input file, and false otherwise
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | nml |
Name of namelist to find start of |
||
logical, | intent(out) | :: | exist |
Was |
Returns the file unit number associated with the error file
Returns the file unit number associated with the exit_reason file
Read the run_name from the command line (if not given), and determine from the extension whether this is a list run (i.e. a list of runs has been given). If so or if this is a run with multiple ensembles, open the list description. If not, open the error file and call init_input_unit
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(out) | :: | list |
True if the input file is a list run file (see is_input_file_list) |
||
logical, | intent(in), | optional | :: | input |
If true, open the input file and strip comments (default: true) |
|
logical, | intent(in), | optional | :: | error |
If true, open the error output file (default: true) |
|
logical, | intent(in), | optional | :: | trin_run |
If present, regardless of value, sets |
|
character(len=*), | intent(in), | optional | :: | name |
Set run_name if |
|
integer, | intent(in), | optional | :: | n_ensembles |
Number of run ensembles. If greater than 1, sets list_name and doesn't open any files |
|
character(len=*), | intent(in), | optional | :: | input_file |
Use given input filename instead of reading from command line |
Set run_name and job_name to jobname
. Used
by job_manage
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=run_name_size), | intent(in) | :: | jobname |
Current job name |
Get an unused unit number for I/O.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out) | :: | unit |
A new unit not associated with an open file |
Open an output file to write (replacing any existing) whose name is
<run_name>.<ext>
, and set unit
to the unit number of that output
file. If the binary flag is true, a binary file is opened
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out) | :: | unit |
Unit number of opened file |
||
character(len=*), | intent(in) | :: | ext |
File extension to open, appended to run_name |
||
logical, | intent(in), | optional | :: | binary |
If true, then open a binary (unformatted) file |
Open an output file to write (appending if existing) whose name is
<run_name>.<ext>
, and set unit
to the unit number of that
output file. If the optional run_name_in
variable is present, this
replaces run_name as the root of the output file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out) | :: | unit |
Unit number of opened file, in append mode |
||
character(len=*), | intent(in) | :: | ext |
File extension to open, appended to run_name |
||
character(len=*), | intent(in), | optional | :: | run_name_in |
Optional root name for the output file. If not specified, run_name is used as the root. |
Close the file associated with unit
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | unit |
Unit of file to close |
Open error file and record associated lun/unit
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | open_it |
If true, open the file, otherwise do nothing |
Open exit_reason file and record associated lun/unit
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | open_it |
If true, open the file, otherwise do nothing |
Replaces each horizontal tab with a single space
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(inout) | :: | line |
Text to modify in-place |
Replaces all leading tabs with space. Note we consider any tabs appearing before the first non-space/tab character.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(inout) | :: | line |
Text to modify in-place |
Remove Fortran comments (!
) from line
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(inout) | :: | line |
Text to modify in-place |
Opens the input file, strip out any comments and write them into the file
.<run_name>.in
. Check for includes, read any lines from the includes,
strip any comments from them and add them to the same file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | open_it |
If true, open the file, otherwise do nothing |
Close any files opened by init_file_utils
Returns the file unit number associated with the input file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out) | :: | unit |
Copy namelist, <nml>_<index_in>
, from the input file to namelist NML
in
a temporary file with unit unit
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out) | :: | unit |
Unit of new temporary file containing the indexed namelist |
||
character(len=*), | intent(in) | :: | nml |
Name of indexed namelist to copy |
||
integer, | intent(in) | :: | index_in |
Index number of namelist to copy |
||
logical, | intent(out), | optional | :: | exist |
Does the indexed namelist exist or not? |