18 character(len=PMC_MAX_FILENAME_LEN) :: in_prefix, out_filename
19 character(len=PMC_MAX_FILENAME_LEN),
allocatable :: filename_list(:)
20 character(len=1000) :: tmp_str
23 integer :: index, i_repeat, i_spec, out_unit
24 integer :: i_file, n_file
25 real(kind=
dp) :: time, del_t
26 character(len=PMC_UUID_LEN) :: uuid, run_uuid
27 real(kind=
dp),
allocatable :: particle_num_concs(:), particle_masses(:)
28 real(kind=
dp),
allocatable :: times(:), time_num_concs(:), time_mass_concs(:)
29 real(kind=
dp),
allocatable :: time_species_concs(:,:)
34 opts(1) =
option_s(
"help", .false.,
'h')
35 opts(2) =
option_s(
"output", .true.,
'o')
40 select case(
getopt(
"ho:", opts))
57 if (
optind /= command_argument_count())
then
59 call die_msg(967032896,
'expected exactly one non-option prefix argument')
62 call get_command_argument(
optind, in_prefix)
64 if (out_filename ==
"")
then
65 out_filename = trim(in_prefix) //
"_aero_time.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 aero_data=aero_data, aero_state=aero_state)
78 allocate(times(n_file))
79 allocate(time_num_concs(n_file))
80 allocate(time_mass_concs(n_file))
84 call input_state(filename_list(i_file), index, time, del_t, i_repeat, &
85 uuid, aero_data=aero_data, aero_state=aero_state)
88 "UUID mismatch between " // trim(filename_list(1)) //
" and " &
89 // trim(filename_list(i_file)))
93 time_num_concs(i_file) = sum(particle_num_concs)
95 time_mass_concs(i_file) = sum(particle_masses * particle_num_concs)
98 include=(/aero_data%name(i_spec)/))
99 time_species_concs(i_file, i_spec) &
100 = sum(particle_masses * particle_num_concs)
104 write(*,
'(a,a)')
"Output file: ", trim(out_filename)
105 write(*,
'(a)')
" Each row of output is one time."
106 write(*,
'(a)')
" The columns of output are:"
107 write(*,
'(a)')
" column 1: time (s)"
108 write(*,
'(a)')
" column 2: aerosol number concentration (#/m^3)"
109 write(*,
'(a)')
" column 3: aerosol mass concentration (kg/m^3)"
111 write(*,
'(a,i2,a,a,a)')
" column ", i_spec + 3,
": aerosol ", &
112 trim(aero_data%name(i_spec)),
" concentration (kg/m^3)"
117 write(out_unit,
'(e30.15e3)', advance=
'no') times(i_file)
118 write(out_unit,
'(e30.15e3)', advance=
'no') time_num_concs(i_file)
119 write(out_unit,
'(e30.15e3)', advance=
'no') time_mass_concs(i_file)
121 write(out_unit,
'(e30.15e3)', advance=
'no') &
122 time_species_concs(i_file, i_spec)
124 write(out_unit,
'(a)')
''
129 deallocate(time_num_concs)
130 deallocate(time_mass_concs)
131 deallocate(time_species_concs)
132 deallocate(filename_list)
140 write(*,
'(a)')
'Usage: extract_aero_time [options] <netcdf_prefix>'
142 write(*,
'(a)')
'options are:'
143 write(*,
'(a)')
' -h, --help Print this help message.'
144 write(*,
'(a)')
' -o, --out <file> Output filename.'
146 write(*,
'(a)')
'Examples:'
147 write(*,
'(a)')
' extract_aero_time data_0001'