PartMC  2.6.1
bin_average_comp.F90
Go to the documentation of this file.
1 ! Copyright (C) 2009-2013 Matthew West
2 ! Licensed under the GNU General Public License version 2 or (at your
3 ! option) any later version. See the file COPYING for details.
4 
5 !> \file
6 !> The bin_average_comp program.
7 
8 !> Read a NetCDF file, average the composition of all particles within
9 !> each bin, and write the data out as another NetCDF file.
11 
12  use pmc_aero_state
13  use pmc_gas_data
14  use pmc_gas_state
15  use pmc_env_state
16  use pmc_aero_data
17  use pmc_bin_grid
18  use pmc_output
19  use pmc_rand
20  use netcdf
21 
22  character(len=1000) :: in_filename, out_prefix
23  type(bin_grid_t) :: bin_grid
24  type(aero_data_t) :: aero_data
25  type(aero_state_t) :: aero_state
26  type(gas_data_t) :: gas_data
27  type(gas_state_t) :: gas_state
28  type(env_state_t) :: env_state
29  integer :: n_bin, index, i_repeat, output_type
30  real(kind=dp) :: d_min, d_max, time, del_t
31  character(len=1000) :: tmp_str
32  logical :: record_removals, dry_volume, record_optical
33  character(len=PMC_UUID_LEN) :: uuid
34 
35  ! process commandline arguments
36  if (command_argument_count() .ne. 6) then
37  write(6,*) 'Usage: bin_average_comp <d_min> <d_max> <n_bin> ' &
38  // '<"wet" or "dry"> <input_filename> <output_prefix>'
39  write(6,*) ''
40  write(6,*) ' d_min: minimum bin diameter (m)'
41  write(6,*) ' d_max: maximum bin diameter (m)'
42  write(6,*) ' n_bin: number of bins'
43  write(6,*) ' wet/dry: average wet or dry sizes'
44  write(6,*) ' input_filename: like scenario_0001_00000001.nc'
45  write(6,*) ' output_prefix: like scenario_comp_average'
46  stop 2
47  endif
48  call get_command_argument(1, tmp_str)
49  d_min = string_to_real(tmp_str)
50  call get_command_argument(2, tmp_str)
51  d_max = string_to_real(tmp_str)
52  call get_command_argument(3, tmp_str)
53  n_bin = string_to_integer(tmp_str)
54  call get_command_argument(4, tmp_str)
55  if (trim(tmp_str) == "wet") then
56  dry_volume = .false.
57  elseif (trim(tmp_str) == "dry") then
58  dry_volume = .true.
59  else
60  write(6,*) 'Argument 4 must be "wet" or "dry", not ' &
61  // trim(tmp_str)
62  stop 1
63  end if
64  call get_command_argument(5, in_filename)
65  call get_command_argument(6, out_prefix)
66 
67  call pmc_mpi_init()
68 
69  call bin_grid_make(bin_grid, bin_grid_type_log, n_bin, diam2rad(d_min), &
70  diam2rad(d_max))
71 
72  call input_state(in_filename, index, time, del_t, i_repeat, uuid, &
73  aero_data, aero_state, gas_data, gas_state, env_state)
74 
75  if (dry_volume) then
76  call aero_state_make_dry(aero_state, aero_data)
77  end if
78 
79  call aero_state_bin_average_comp(aero_state, bin_grid, aero_data)
80 
81  output_type = output_type_single
82  record_removals = .false.
83  record_optical = .true.
84  call output_state(out_prefix, output_type, aero_data, aero_state, &
85  gas_data, gas_state, env_state, index, time, del_t, i_repeat, &
86  record_removals, record_optical, uuid)
87 
88  call pmc_mpi_finalize()
89 
90 end program bin_average_comp
pmc_aero_state::aero_state_bin_average_comp
subroutine aero_state_bin_average_comp(aero_state, bin_grid, aero_data)
Set each aerosol particle to have its original total volume, but species volume ratios given by the t...
Definition: aero_state.F90:1896
pmc_mpi::pmc_mpi_init
subroutine pmc_mpi_init()
Initialize MPI.
Definition: mpi.F90:56
pmc_aero_state::aero_state_make_dry
subroutine aero_state_make_dry(aero_state, aero_data)
Make all particles dry (water set to zero).
Definition: aero_state.F90:2157
pmc_gas_data::gas_data_t
Constant gas data.
Definition: gas_data.F90:35
pmc_output::input_state
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.
Definition: output.F90:498
pmc_gas_data
The gas_data_t structure and associated subroutines.
Definition: gas_data.F90:9
pmc_constants::dp
integer, parameter dp
Kind of a double precision real number.
Definition: constants.F90:12
pmc_output::output_state
subroutine output_state(prefix, output_type, aero_data, aero_state, gas_data, gas_state, env_state, index, time, del_t, i_repeat, record_removals, record_optical, uuid)
Write the current state.
Definition: output.F90:112
pmc_env_state::env_state_t
Current environment state.
Definition: env_state.F90:29
pmc_util::string_to_integer
integer function string_to_integer(string)
Convert a string to an integer.
Definition: util.F90:688
pmc_aero_state
The aero_state_t structure and assocated subroutines.
Definition: aero_state.F90:9
pmc_gas_state
The gas_state_t structure and associated subroutines.
Definition: gas_state.F90:9
pmc_mpi::pmc_mpi_finalize
subroutine pmc_mpi_finalize()
Shut down MPI.
Definition: mpi.F90:89
pmc_util::diam2rad
real(kind=dp) elemental function diam2rad(d)
Convert diameter (m) to radius (m).
Definition: util.F90:277
pmc_output::output_type_single
integer, parameter output_type_single
Type code for single output (one file for all processes, written by process 0).
Definition: output.F90:97
pmc_rand
Random number generators.
Definition: rand.F90:9
pmc_env_state
The env_state_t structure and associated subroutines.
Definition: env_state.F90:9
pmc_gas_state::gas_state_t
Current state of the gas mixing ratios in the system.
Definition: gas_state.F90:33
pmc_aero_data::aero_data_t
Aerosol material properties and associated data.
Definition: aero_data.F90:49
pmc_output
Write data in NetCDF format.
Definition: output.F90:68
pmc_bin_grid
The bin_grid_t structure and associated subroutines.
Definition: bin_grid.F90:9
bin_average_comp
program bin_average_comp
Read a NetCDF file, average the composition of all particles within each bin, and write the data out ...
Definition: bin_average_comp.F90:10
pmc_aero_data
The aero_data_t structure and associated subroutines.
Definition: aero_data.F90:9
pmc_bin_grid::bin_grid_t
1D grid, either logarithmic or linear.
Definition: bin_grid.F90:33
pmc_bin_grid::bin_grid_type_log
integer, parameter bin_grid_type_log
Logarithmically spaced bin grid.
Definition: bin_grid.F90:23
pmc_bin_grid::bin_grid_make
subroutine bin_grid_make(bin_grid, type, n_bin, min, max)
Generates the bin grid given the range and number of bins.
Definition: bin_grid.F90:84
pmc_aero_state::aero_state_t
The current collection of aerosol particles.
Definition: aero_state.F90:63
string_to_real
real(kind=dp) function string_to_real(string)
Convert a string to a real.
Definition: numeric_average.F90:108