18 character(len=PMC_MAX_FILENAME_LEN) :: in_filename, out_filename
21 integer :: index, i_repeat, i_part, i_spec, out_unit, i_char
22 real(kind=dp) :: time, del_t
23 character(len=PMC_UUID_LEN) :: uuid
29 opts(1) =
option_s(
"help", .false.,
'h')
30 opts(2) =
option_s(
"output", .true.,
'o')
35 select case(
getopt(
"ho:", opts))
45 call
die_msg(885067714,
'unknown option: ' // trim(optopt))
48 call
die_msg(516704561,
'unhandled option: ' // trim(optopt))
52 if (optind /= command_argument_count())
then
55 'expected exactly one non-option filename argument')
58 call get_command_argument(optind, in_filename)
60 if (out_filename ==
"")
then
61 i_char = scan(in_filename,
'.', back=.true.)
63 out_filename = trim(in_filename) //
"_aero_particles.txt"
65 out_filename = trim(in_filename(1:(i_char - 1))) &
66 //
"_aero_particles.txt"
73 call
input_state(in_filename, index, time, del_t, i_repeat, uuid, &
74 aero_data=aero_data, aero_state=aero_state)
76 write(*,
'(a)')
"Output file: " // trim(out_filename)
77 write(*,
'(a)')
" Output data is for time = " &
79 write(*,
'(a)')
" Each row of output is one particle."
80 write(*,
'(a)')
" The columns of output are:"
81 write(*,
'(a)')
" column 1: particle ID number"
82 write(*,
'(a)')
" column 2: number concentration (m^{-3})"
83 write(*,
'(a)')
" column 3: particle diameter (m)"
84 write(*,
'(a)')
" column 4: particle total mass (kg)"
85 do i_spec = 1,aero_data%n_spec
86 write(*,
'(a,i2,a,a,a,e10.4,a)')
' column ', i_spec + 4,
': ', &
87 trim(aero_data%name(i_spec)),
' mass (kg) - density = ', &
88 aero_data%density(i_spec),
' (kg/m^3)'
92 do i_part = 1,aero_state%apa%n_part
93 aero_particle => aero_state%apa%particle(i_part)
94 write(out_unit,
'(i15,e30.15e3,e30.15e3,e30.15e3)', advance=
'no') &
99 do i_spec = 1,aero_data%n_spec
100 write(out_unit,
'(e30.15e3)', advance=
'no') &
103 write(out_unit, *)
''
116 write(*,
'(a)')
'Usage: extract_aero_particles [options] <netcdf_prefix>'
118 write(*,
'(a)')
'options are:'
119 write(*,
'(a)')
' -h, --help Print this help message.'
120 write(*,
'(a)')
' -o, --out <file> Output filename.'
122 write(*,
'(a)')
'Examples:'
123 write(*,
'(a)')
' extract_aero_particles data_0001_00000001.nc'
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 close_file(unit)
Close a file and de-assign the unit.
The aero_particle_t structure and associated subroutines.
elemental real(kind=dp) function aero_particle_species_mass(aero_particle, i_spec, aero_data)
Mass of a single species in the particle (kg).
subroutine aero_state_allocate(aero_state)
Allocates aerosol arrays.
elemental real(kind=dp) function aero_particle_diameter(aero_particle)
Total diameter of the particle (m).
subroutine pmc_mpi_finalize()
Shut down MPI.
subroutine pmc_mpi_init()
Initialize MPI.
real(kind=dp) function aero_state_particle_num_conc(aero_state, aero_particle)
The number concentration of a single particle (m^{-3}).
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.
Single aerosol particle data structure.
subroutine aero_state_deallocate(aero_state)
Deallocates a previously allocated aerosol.
program extract_aero_particles
Read NetCDF output files and write out the individual particle masses.
elemental real(kind=dp) function aero_particle_mass(aero_particle, aero_data)
Total mass of the particle (kg).
subroutine aero_data_allocate(aero_data)
Allocate storage for aero_data.
character(len=pmc_util_convert_string_len) function real_to_string(val)
Convert a real to a string format.
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().