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
21 integer :: index, i_repeat, i_spec, out_unit
22 integer :: i_file, n_file
23 real(kind=
dp) :: time, del_t
24 character(len=PMC_UUID_LEN) :: uuid, run_uuid
25 real(kind=
dp),
allocatable :: times(:), temps(:), rel_humids(:)
26 real(kind=
dp),
allocatable :: pressures(:), mix_heights(:)
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(410427558,
'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) //
"_env.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, &
75 allocate(times(n_file))
76 allocate(temps(n_file))
77 allocate(rel_humids(n_file))
78 allocate(pressures(n_file))
79 allocate(mix_heights(n_file))
82 call input_state(filename_list(i_file), index, time, del_t, i_repeat, &
83 uuid, env_state=env_state)
86 "UUID mismatch between " // trim(filename_list(1)) //
" and " &
87 // trim(filename_list(i_file)))
90 temps(i_file) = env_state%temp
91 rel_humids(i_file) = env_state%rel_humid
92 pressures(i_file) = env_state%pressure
93 mix_heights(i_file) = env_state%height
96 write(*,
'(a,a)')
"Output file: ", trim(out_filename)
97 write(*,
'(a)')
" Each row of output is one time."
98 write(*,
'(a)')
" The columns of output are:"
99 write(*,
'(a)')
" column 1: time (s)"
100 write(*,
'(a)')
" column 2: temperature (K)"
101 write(*,
'(a)')
" column 3: relative_humidity (1)"
102 write(*,
'(a)')
" column 4: pressure (Pa)"
103 write(*,
'(a)')
" column 5: mixing height (m)"
107 write(out_unit,
'(e30.15e3)', advance=
'no') times(i_file)
108 write(out_unit,
'(e30.15e3)', advance=
'no') temps(i_file)
109 write(out_unit,
'(e30.15e3)', advance=
'no') rel_humids(i_file)
110 write(out_unit,
'(e30.15e3)', advance=
'no') pressures(i_file)
111 write(out_unit,
'(e30.15e3)', advance=
'no') mix_heights(i_file)
112 write(out_unit,
'(a)')
''
118 deallocate(rel_humids)
119 deallocate(pressures)
120 deallocate(mix_heights)
128 write(*,
'(a)')
'Usage: extract_env [options] <netcdf_prefix>'
130 write(*,
'(a)')
'options are:'
131 write(*,
'(a)')
' -h, --help Print this help message.'
132 write(*,
'(a)')
' -o, --out <file> Output filename.'
134 write(*,
'(a)')
'Examples:'
135 write(*,
'(a)')
' extract_env data_0001'