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))
47 call
die_msg(478715112,
'unknown option: ' // trim(optopt))
50 call
die_msg(935521190,
'unhandled option: ' // trim(optopt))
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"
68 allocate(filename_list(0))
70 n_file =
size(filename_list)
72 "no NetCDF files found with prefix: " // trim(in_prefix))
74 call
input_state(filename_list(1), index, time, del_t, i_repeat, uuid, &
75 gas_data=gas_data, gas_state=gas_state)
78 allocate(times(n_file))
79 allocate(gas_mixing_ratios(n_file, gas_data%n_spec))
82 call
input_state(filename_list(i_file), index, time, del_t, i_repeat, &
83 uuid, gas_data=gas_data, gas_state=gas_state)
86 "UUID mismatch between " // trim(filename_list(1)) //
" and " &
87 // trim(filename_list(i_file)))
90 gas_mixing_ratios(i_file, :) = gas_state%mix_rat
93 write(*,
'(a,a)')
"Output file: ", trim(out_filename)
94 write(*,
'(a)')
" Each row of output is one time."
95 write(*,
'(a)')
" The columns of output are:"
96 write(*,
'(a)')
" column 1: time (s)"
97 do i_spec = 1,gas_data%n_spec
98 write(*,
'(a,i2,a,a,a)')
" column ", i_spec + 1,
": gas ", &
99 trim(gas_data%name(i_spec)),
" mixing ratio (ppb)"
104 write(out_unit,
'(e30.15e3)', advance=
'no') times(i_file)
105 do i_spec = 1,gas_data%n_spec
106 write(out_unit,
'(e30.15e3)', advance=
'no') &
107 gas_mixing_ratios(i_file, i_spec)
109 write(out_unit,
'(a)')
''
114 deallocate(gas_mixing_ratios)
124 write(*,
'(a)')
'Usage: extract_gas [options] <netcdf_prefix>'
126 write(*,
'(a)')
'options are:'
127 write(*,
'(a)')
' -h, --help Print this help message.'
128 write(*,
'(a)')
' -o, --out <file> Output filename.'
130 write(*,
'(a)')
'Examples:'
131 write(*,
'(a)')
' extract_gas data_0001'
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 die_msg(code, error_msg)
Error immediately.
character function getopt(optstring, longopts)
subroutine input_filename_list(prefix, filename_list)
Find all NetCDF (.nc) filenames that match the given prefix.
subroutine close_file(unit)
Close a file and de-assign the unit.
subroutine assert_msg(code, condition_ok, error_msg)
Errors unless condition_ok is true.
subroutine pmc_mpi_finalize()
Shut down MPI.
subroutine pmc_mpi_init()
Initialize MPI.
subroutine gas_data_deallocate(gas_data)
Free all storage.
Wrapper functions for MPI.
subroutine gas_state_deallocate(gas_state)
Free all storage.
The gas_state_t structure and associated subroutines.
subroutine gas_state_allocate(gas_state)
Allocate storage for gas species.
subroutine gas_data_allocate(gas_data)
Allocate storage for gas species.
Current state of the gas mixing ratios in the system.
Write data in NetCDF format.
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().