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'