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))
50 call
die_msg(514364550,
'unknown option: ' // trim(optopt))
53 call
die_msg(603100341,
'unhandled option: ' // trim(optopt))
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"
71 allocate(filename_list(0))
73 n_file =
size(filename_list)
75 "no NetCDF files found with prefix: " // trim(in_prefix))
77 call
input_state(filename_list(1), index, time, del_t, i_repeat, uuid, &
78 aero_data=aero_data, aero_state=aero_state)
81 allocate(times(n_file))
82 allocate(time_num_concs(n_file))
83 allocate(time_mass_concs(n_file))
84 allocate(time_species_concs(n_file, aero_data%n_spec))
87 call
input_state(filename_list(i_file), index, time, del_t, i_repeat, &
88 uuid, aero_data=aero_data, aero_state=aero_state)
91 "UUID mismatch between " // trim(filename_list(1)) //
" and " &
92 // trim(filename_list(i_file)))
96 time_num_concs(i_file) = sum(particle_num_concs)
98 time_mass_concs(i_file) = sum(particle_masses * particle_num_concs)
99 do i_spec = 1,aero_data%n_spec
101 include=(/aero_data%name(i_spec)/))
102 time_species_concs(i_file, i_spec) &
103 = sum(particle_masses * particle_num_concs)
107 write(*,
'(a,a)')
"Output file: ", trim(out_filename)
108 write(*,
'(a)')
" Each row of output is one time."
109 write(*,
'(a)')
" The columns of output are:"
110 write(*,
'(a)')
" column 1: time (s)"
111 write(*,
'(a)')
" column 2: aerosol number concentration (#/m^3)"
112 write(*,
'(a)')
" column 3: aerosol mass concentration (kg/m^3)"
113 do i_spec = 1,aero_data%n_spec
114 write(*,
'(a,i2,a,a,a)')
" column ", i_spec + 3,
": aerosol ", &
115 trim(aero_data%name(i_spec)),
" concentration (kg/m^3)"
120 write(out_unit,
'(e30.15e3)', advance=
'no') times(i_file)
121 write(out_unit,
'(e30.15e3)', advance=
'no') time_num_concs(i_file)
122 write(out_unit,
'(e30.15e3)', advance=
'no') time_mass_concs(i_file)
123 do i_spec = 1,aero_data%n_spec
124 write(out_unit,
'(e30.15e3)', advance=
'no') &
125 time_species_concs(i_file, i_spec)
127 write(out_unit,
'(a)')
''
132 deallocate(time_num_concs)
133 deallocate(time_mass_concs)
134 deallocate(time_species_concs)
135 deallocate(filename_list)
145 write(*,
'(a)')
'Usage: extract_aero_time [options] <netcdf_prefix>'
147 write(*,
'(a)')
'options are:'
148 write(*,
'(a)')
' -h, --help Print this help message.'
149 write(*,
'(a)')
' -o, --out <file> Output filename.'
151 write(*,
'(a)')
'Examples:'
152 write(*,
'(a)')
' extract_aero_time 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 aero_particle_t structure and associated subroutines.
subroutine aero_state_allocate(aero_state)
Allocates aerosol arrays.
subroutine assert_msg(code, condition_ok, error_msg)
Errors unless condition_ok is true.
real(kind=dp) function, dimension(aero_state%apa%n_part) aero_state_masses(aero_state, aero_data, include, exclude)
Returns the masses of all particles.
subroutine pmc_mpi_finalize()
Shut down MPI.
subroutine pmc_mpi_init()
Initialize MPI.
subroutine aero_data_deallocate(aero_data)
Frees all storage.
The aero_state_t structure and assocated subroutines.
Wrapper functions for MPI.
The current collection of aerosol particles.
subroutine aero_state_deallocate(aero_state)
Deallocates a previously allocated aerosol.
real(kind=dp) function, dimension(aero_state%apa%n_part) aero_state_num_concs(aero_state)
Returns the number concentrations of all particles.
subroutine aero_data_allocate(aero_data)
Allocate storage for aero_data.
Aerosol material properties and associated data.
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().