subroutine output_initialise_user_input
! Read and interpret output namelist parameters
use utilities, only: &
extend_unique_string, &
string_index, &
open_file, &
log_create, &
master_log
use input, only: get_config_fid
integer ios, i, v
character(len=identifier_max_length) :: &
name, format, variables(output_max_variables), space, time
namelist / file / &
name, format, variables, space, time
! General options from central config nml
read(get_config_fid(), nml=OUTPUT_PARAMETERS)
! Create master log file
master_log = log_create(trim(output_dir)//"/"//trim(master_logfile), &
log_stderr_level, log_stdout_level, log_file_level)
! count requested output files
output_specs_fid = open_file(output_specs_path)
output_nfiles = -1
ios = 0
do while (ios /= -1)
output_nfiles = output_nfiles + 1
read(output_specs_fid, nml=file, iostat=ios)
end do
rewind(output_specs_fid)
if (output_nfiles == 0) &
call log_error("output_initialise_user_input", &
"No output file definition found in "//output_specs_path)
! Allocate arrays of nfiles length
allocate(output_files(output_nfiles))
do i = 1, output_nfiles
name = ''
format = output_default_format
variables = ''
space = ''
time = ''
read(output_specs_fid, nml=file)
! Check input and store
if (trim(name) == '') &
call log_error("output_initialise_user_input", "No name given for output file.")
output_files(i)%name = name
output_files(i)%nvars = string_index('', variables) - 1
if (output_files(i)%nvars == 0) &
call log_error("output_initialise_user_input", &
"No variables define for output file "//trim(name))
output_files(i)%variables = variables
output_files(i)%space = string_index(space, output_space_dim)
if (output_files(i)%space == 0) call log_error("output_initialise_user_input", &
trim(space)//" is not a valid output space domain in file "//trim(name))
output_files(i)%time = string_index(time, output_time_dim)
if (output_files(i)%time == 0) call log_error("output_initialise_user_input", &
trim(time)//" is not a valid output time domain in file "//trim(name))
output_files(i)%format = string_index(format, output_format_dim)
if (output_files(i)%format == 0) call log_error("output_initialise_user_input", &
trim(format)//" is not a valid output format in file "//trim(name))
! Store unique variables
call extend_unique_string(variables, output_requested_vars)
end do
! Get variable indeces for each file%variables in output_requested_vars
do i = 1, output_nfiles
do v = 1, output_files(i)%nvars
output_files(i)%variable_ix(v) = string_index(output_files(i)%variables(v), &
output_requested_vars)
end do
end do
! Count all requested variables
output_nvars = string_index("", output_requested_vars) - 1
allocate(output_var_state(output_nvars))
output_var_state = .True.
end subroutine output_initialise_user_input