PartMC
2.2.0
|
00001 ! Copyright (C) 2009-2011 Matthew West 00002 ! Licensed under the GNU General Public License version 2 or (at your 00003 ! option) any later version. See the file COPYING for details. 00004 00005 !> \file 00006 !> The bin_average_comp program. 00007 00008 !> Read a NetCDF file, average the composition of all particles within 00009 !> each bin, and write the data out as another NetCDF file. 00010 program bin_average_comp 00011 00012 use pmc_aero_state 00013 use pmc_gas_data 00014 use pmc_gas_state 00015 use pmc_env_state 00016 use pmc_aero_data 00017 use pmc_bin_grid 00018 use pmc_output 00019 use pmc_rand 00020 use netcdf 00021 00022 character(len=1000) :: in_filename, out_prefix 00023 type(bin_grid_t) :: bin_grid 00024 type(aero_data_t) :: aero_data 00025 type(aero_state_t) :: aero_state 00026 type(gas_data_t) :: gas_data 00027 type(gas_state_t) :: gas_state 00028 type(env_state_t) :: env_state 00029 integer :: n_bin, index, i_repeat, output_type 00030 real(kind=dp) :: d_min, d_max, time, del_t 00031 character(len=1000) :: tmp_str 00032 logical :: record_removals, dry_volume, record_optical 00033 character(len=PMC_UUID_LEN) :: uuid 00034 00035 ! process commandline arguments 00036 if (command_argument_count() .ne. 6) then 00037 write(6,*) 'Usage: bin_average_comp <d_min> <d_max> <n_bin> ' & 00038 // '<"wet" or "dry"> <input_filename> <output_prefix>' 00039 write(6,*) '' 00040 write(6,*) ' d_min: minimum bin diameter (m)' 00041 write(6,*) ' d_max: maximum bin diameter (m)' 00042 write(6,*) ' n_bin: number of bins' 00043 write(6,*) ' wet/dry: average wet or dry sizes' 00044 write(6,*) ' input_filename: like scenario_0001_00000001.nc' 00045 write(6,*) ' output_prefix: like scenario_comp_average' 00046 stop 2 00047 endif 00048 call get_command_argument(1, tmp_str) 00049 d_min = string_to_real(tmp_str) 00050 call get_command_argument(2, tmp_str) 00051 d_max = string_to_real(tmp_str) 00052 call get_command_argument(3, tmp_str) 00053 n_bin = string_to_integer(tmp_str) 00054 call get_command_argument(4, tmp_str) 00055 if (trim(tmp_str) == "wet") then 00056 dry_volume = .false. 00057 elseif (trim(tmp_str) == "dry") then 00058 dry_volume = .true. 00059 else 00060 write(6,*) 'Argument 4 must be "wet" or "dry", not ' & 00061 // trim(tmp_str) 00062 stop 1 00063 end if 00064 call get_command_argument(5, in_filename) 00065 call get_command_argument(6, out_prefix) 00066 00067 call pmc_mpi_init() 00068 00069 call bin_grid_allocate(bin_grid) 00070 call aero_data_allocate(aero_data) 00071 call aero_state_allocate(aero_state) 00072 call gas_data_allocate(gas_data) 00073 call gas_state_allocate(gas_state) 00074 call env_state_allocate(env_state) 00075 00076 call bin_grid_make(bin_grid, n_bin, diam2rad(d_min), diam2rad(d_max)) 00077 00078 call input_state(in_filename, index, time, del_t, i_repeat, uuid, & 00079 aero_data, aero_state, gas_data, gas_state, env_state) 00080 00081 if (dry_volume) then 00082 call aero_state_make_dry(aero_state, aero_data) 00083 end if 00084 00085 call aero_state_bin_average_comp(aero_state, bin_grid, aero_data, & 00086 dry_volume) 00087 00088 output_type = OUTPUT_TYPE_SINGLE 00089 record_removals = .false. 00090 record_optical = .true. 00091 call output_state(out_prefix, output_type, aero_data, aero_state, & 00092 gas_data, gas_state, env_state, index, time, del_t, i_repeat, & 00093 record_removals, record_optical, uuid) 00094 00095 call bin_grid_deallocate(bin_grid) 00096 call aero_data_deallocate(aero_data) 00097 call aero_state_deallocate(aero_state) 00098 call gas_data_deallocate(gas_data) 00099 call gas_state_deallocate(gas_state) 00100 call env_state_deallocate(env_state) 00101 00102 call pmc_mpi_finalize() 00103 00104 end program bin_average_comp