17 character(len=PMC_MAX_FILENAME_LEN) :: in_prefix, out_filename
18 character(len=PMC_MAX_FILENAME_LEN),
allocatable :: filename_list(:)
22 integer :: index, out_unit
23 integer :: i_file, n_file, i_spec
24 real(kind=dp) :: time, del_t
25 character(len=PMC_UUID_LEN) :: uuid, run_uuid
26 real(kind=dp),
allocatable :: times(:), time_num_concs(:), time_mass_concs(:)
27 real(kind=dp),
allocatable :: time_species_concs(:,:)
32 opts(1) =
option_s(
"help", .false.,
'h')
33 opts(2) =
option_s(
"output", .true.,
'o')
38 select case(
getopt(
"ho:", opts))
48 call
die_msg(559277549,
'unknown option: ' // trim(optopt))
51 call
die_msg(247146202,
'unhandled option: ' // trim(optopt))
55 if (optind /= command_argument_count())
then
57 call
die_msg(959981535,
'expected exactly one non-option prefix argument')
60 call get_command_argument(optind, in_prefix)
62 if (out_filename ==
"")
then
63 out_filename = trim(in_prefix) //
"_aero_time.txt"
70 allocate(filename_list(0))
72 n_file =
size(filename_list)
74 "no NetCDF files found with prefix: " // trim(in_prefix))
77 bin_grid=bin_grid, aero_data=aero_data, aero_binned=aero_binned)
80 allocate(times(n_file))
81 allocate(time_num_concs(n_file))
82 allocate(time_mass_concs(n_file))
83 allocate(time_species_concs(n_file, aero_data%n_spec))
87 bin_grid=bin_grid, aero_data=aero_data, aero_binned=aero_binned)
90 "UUID mismatch between " // trim(filename_list(1)) //
" and " &
91 // trim(filename_list(i_file)))
94 time_num_concs(i_file) = sum(aero_binned%num_conc * bin_grid%widths)
96 time_species_concs(i_file, :) = sum(aero_binned%vol_conc &
97 * bin_grid%widths(1), 1) * aero_data%density
98 time_mass_concs(i_file) = sum(time_species_concs(i_file, :))
101 write(*,
'(a,a)')
"Output file: ", trim(out_filename)
102 write(*,
'(a)')
" Each row of output is one time."
103 write(*,
'(a)')
" The columns of output are:"
104 write(*,
'(a)')
" column 1: time (s)"
105 write(*,
'(a)')
" column 2: aerosol number concentration (#/m^3)"
106 write(*,
'(a)')
" column 3: aerosol mass concentration (kg/m^3)"
107 do i_spec = 1,aero_data%n_spec
108 write(*,
'(a,i2,a,a,a)')
" column ", i_spec + 3,
": aerosol ", &
109 trim(aero_data%name(i_spec)),
" concentration (kg/m^3)"
114 write(out_unit,
'(e30.15e3)', advance=
'no') times(i_file)
115 write(out_unit,
'(e30.15e3)', advance=
'no') time_num_concs(i_file)
116 write(out_unit,
'(e30.15e3)', advance=
'no') time_mass_concs(i_file)
117 do i_spec = 1,aero_data%n_spec
118 write(out_unit,
'(e30.15e3)', advance=
'no') &
119 time_species_concs(i_file, i_spec)
121 write(out_unit,
'(a)')
''
126 deallocate(time_num_concs)
127 deallocate(time_mass_concs)
128 deallocate(time_species_concs)
129 deallocate(filename_list)
140 write(*,
'(a)')
'Usage: extract_sectional_aero_time [options] ' &
143 write(*,
'(a)')
'options are:'
144 write(*,
'(a)')
' -h, --help Print this help message.'
145 write(*,
'(a)')
' -n, --num Output number distribution.'
146 write(*,
'(a)')
' -m, --mass Output mass distribution.'
147 write(*,
'(a)')
' -o, --out <file> Output filename.'
149 write(*,
'(a)')
'Examples:'
150 write(*,
'(a)')
' extract_sectional_aero_time --num data_0001'
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 aero_binned_deallocate(aero_binned)
Free internal memory in an aero_binned_t structure.
subroutine assert_msg(code, condition_ok, error_msg)
Errors unless condition_ok is true.
subroutine aero_binned_allocate(aero_binned)
Allocate an aero_binned_t.
subroutine pmc_mpi_finalize()
Shut down MPI.
subroutine pmc_mpi_init()
Initialize MPI.
subroutine bin_grid_allocate(bin_grid)
Allocates a bin_grid.
subroutine aero_data_deallocate(aero_data)
Frees all storage.
Wrapper functions for MPI.
subroutine input_sectional(filename, index, time, del_t, uuid, bin_grid, aero_data, aero_binned, gas_data, gas_state, env_state)
Input sectional data.
1D grid, either logarithmic or linear.
The aero_binned_t structure and associated subroutines.
subroutine aero_data_allocate(aero_data)
Allocate storage for aero_data.
Aerosol material properties and associated data.
Write data in NetCDF format.
Aerosol number and volume distributions stored per bin.
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().