17 character(len=PMC_MAX_FILENAME_LEN) :: in_prefix, out_filename
18 character(len=PMC_MAX_FILENAME_LEN),
allocatable :: filename_list(:)
19 character(len=1000) :: tmp_str
20 type(gas_data_t) :: gas_data
22 integer :: index, i_repeat, i_spec, out_unit
23 integer :: i_file, n_file
24 real(kind=dp) :: time, del_t
25 character(len=PMC_UUID_LEN) :: uuid, run_uuid
26 real(kind=dp),
allocatable :: times(:), gas_mixing_ratios(:,:)
31 opts(1) =
option_s(
"help", .false.,
'h')
32 opts(2) =
option_s(
"output", .true.,
'o')
37 select case(
getopt(
"ho:", opts))
54 if (
optind /= command_argument_count())
then 56 call die_msg(744333329,
'expected exactly one non-option prefix argument')
59 call get_command_argument(
optind, in_prefix)
61 if (out_filename ==
"")
then 62 out_filename = trim(in_prefix) //
"_gas.txt" 65 allocate(filename_list(0))
67 n_file =
size(filename_list)
69 "no NetCDF files found with prefix: " // trim(in_prefix))
71 call input_state(filename_list(1), index, time, del_t, i_repeat, uuid, &
72 gas_data=gas_data, gas_state=gas_state)
75 allocate(times(n_file))
76 allocate(gas_mixing_ratios(n_file, gas_data_n_spec(gas_data)))
79 call input_state(filename_list(i_file), index, time, del_t, i_repeat, &
80 uuid, gas_data=gas_data, gas_state=gas_state)
83 "UUID mismatch between " // trim(filename_list(1)) //
" and " &
84 // trim(filename_list(i_file)))
87 gas_mixing_ratios(i_file, :) = gas_state%mix_rat
90 write(*,
'(a,a)')
"Output file: ", trim(out_filename)
91 write(*,
'(a)')
" Each row of output is one time." 92 write(*,
'(a)')
" The columns of output are:" 93 write(*,
'(a)')
" column 1: time (s)" 94 do i_spec = 1,gas_data_n_spec(gas_data)
95 write(*,
'(a,i2,a,a,a)')
" column ", i_spec + 1,
": gas ", &
96 trim(gas_data%name(i_spec)),
" mixing ratio (ppb)" 101 write(out_unit,
'(e30.15e3)', advance=
'no') times(i_file)
102 do i_spec = 1,gas_data_n_spec(gas_data)
103 write(out_unit,
'(e30.15e3)', advance=
'no') &
104 gas_mixing_ratios(i_file, i_spec)
106 write(out_unit,
'(a)')
'' 111 deallocate(gas_mixing_ratios)
119 write(*,
'(a)')
'Usage: extract_gas [options] <netcdf_prefix>' 121 write(*,
'(a)')
'options are:' 122 write(*,
'(a)')
' -h, --help Print this help message.' 123 write(*,
'(a)')
' -o, --out <file> Output filename.' 125 write(*,
'(a)')
'Examples:' 126 write(*,
'(a)')
' extract_gas data_0001' subroutine assert_msg(code, condition_ok, error_msg)
Errors unless condition_ok is true.
subroutine close_file(unit)
Close a file and de-assign the unit.
character function getopt(optstring, longopts)
subroutine input_filename_list(prefix, filename_list)
Find all NetCDF (.nc) filenames that match the given prefix.
subroutine die_msg(code, error_msg)
Error immediately.
Write data in NetCDF format.
The gas_state_t structure and associated subroutines.
Current state of the gas mixing ratios in the system.
subroutine input_state(filename, index, time, del_t, i_repeat, uuid, aero_data, aero_state, gas_data, gas_state, env_state)
Read the current state.
subroutine pmc_mpi_finalize()
Shut down MPI.
subroutine open_file_write(filename, unit)
Open a file for writing with an automatically assigned unit and test that it succeeds. The file should be closed with close_file().
subroutine pmc_mpi_init()
Initialize MPI.
Wrapper functions for MPI.