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))
47 call
die_msg(909107230,
'unknown option: ' // trim(optopt))
50 call
die_msg(368158543,
'unhandled option: ' // trim(optopt))
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"
67 allocate(filename_list(0))
69 n_file =
size(filename_list)
71 "no NetCDF files found with prefix: " // trim(in_prefix))
73 call
input_state(filename_list(1), index, time, del_t, i_repeat, uuid, &
77 allocate(times(n_file))
78 allocate(temps(n_file))
79 allocate(rel_humids(n_file))
80 allocate(pressures(n_file))
81 allocate(mix_heights(n_file))
84 call
input_state(filename_list(i_file), index, time, del_t, i_repeat, &
85 uuid, env_state=env_state)
88 "UUID mismatch between " // trim(filename_list(1)) //
" and " &
89 // trim(filename_list(i_file)))
92 temps(i_file) = env_state%temp
93 rel_humids(i_file) = env_state%rel_humid
94 pressures(i_file) = env_state%pressure
95 mix_heights(i_file) = env_state%height
98 write(*,
'(a,a)')
"Output file: ", trim(out_filename)
99 write(*,
'(a)')
" Each row of output is one time."
100 write(*,
'(a)')
" The columns of output are:"
101 write(*,
'(a)')
" column 1: time (s)"
102 write(*,
'(a)')
" column 2: temperature (K)"
103 write(*,
'(a)')
" column 3: relative_humidity (1)"
104 write(*,
'(a)')
" column 4: pressure (Pa)"
105 write(*,
'(a)')
" column 5: mixing height (m)"
109 write(out_unit,
'(e30.15e3)', advance=
'no') times(i_file)
110 write(out_unit,
'(e30.15e3)', advance=
'no') temps(i_file)
111 write(out_unit,
'(e30.15e3)', advance=
'no') rel_humids(i_file)
112 write(out_unit,
'(e30.15e3)', advance=
'no') pressures(i_file)
113 write(out_unit,
'(e30.15e3)', advance=
'no') mix_heights(i_file)
114 write(out_unit,
'(a)')
''
120 deallocate(rel_humids)
121 deallocate(pressures)
122 deallocate(mix_heights)
131 write(*,
'(a)')
'Usage: extract_env [options] <netcdf_prefix>'
133 write(*,
'(a)')
'options are:'
134 write(*,
'(a)')
' -h, --help Print this help message.'
135 write(*,
'(a)')
' -o, --out <file> Output filename.'
137 write(*,
'(a)')
'Examples:'
138 write(*,
'(a)')
' extract_env 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.
The env_state_t structure and associated subroutines.
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.
Current environment state.
subroutine env_state_deallocate(env_state)
Free all storage.
Wrapper functions for MPI.
subroutine env_state_allocate(env_state)
Allocate an empty environment.
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().