PartMC
2.1.5
|
00001 ! Copyright (C) 2009-2010 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_aero_weight 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_weight_t) :: aero_weight 00026 type(aero_state_t) :: aero_state 00027 type(gas_data_t) :: gas_data 00028 type(gas_state_t) :: gas_state 00029 type(env_state_t) :: env_state 00030 integer :: n_bin, index, i_repeat, output_type 00031 real(kind=dp) :: d_min, d_max, time, del_t 00032 character(len=1000) :: tmp_str 00033 logical :: record_removals, dry_volume, record_optical 00034 character(len=PMC_UUID_LEN) :: uuid 00035 00036 ! process commandline arguments 00037 if (command_argument_count() .ne. 6) then 00038 write(6,*) 'Usage: bin_average_comp <d_min> <d_max> <n_bin> ' & 00039 // '<"wet" or "dry"> <input_filename> <output_prefix>' 00040 write(6,*) '' 00041 write(6,*) ' d_min: minimum bin diameter (m)' 00042 write(6,*) ' d_max: maximum bin diameter (m)' 00043 write(6,*) ' n_bin: number of bins' 00044 write(6,*) ' wet/dry: average wet or dry sizes' 00045 write(6,*) ' input_filename: like scenario_0001_00000001.nc' 00046 write(6,*) ' output_prefix: like scenario_comp_average' 00047 stop 2 00048 endif 00049 call get_command_argument(1, tmp_str) 00050 d_min = string_to_real(tmp_str) 00051 call get_command_argument(2, tmp_str) 00052 d_max = string_to_real(tmp_str) 00053 call get_command_argument(3, tmp_str) 00054 n_bin = string_to_integer(tmp_str) 00055 call get_command_argument(4, tmp_str) 00056 if (trim(tmp_str) == "wet") then 00057 dry_volume = .false. 00058 elseif (trim(tmp_str) == "dry") then 00059 dry_volume = .true. 00060 else 00061 write(6,*) 'Argument 4 must be "wet" or "dry", not ' & 00062 // trim(tmp_str) 00063 stop 1 00064 end if 00065 call get_command_argument(5, in_filename) 00066 call get_command_argument(6, out_prefix) 00067 00068 call pmc_mpi_init() 00069 00070 call bin_grid_allocate(bin_grid) 00071 call aero_data_allocate(aero_data) 00072 call aero_weight_allocate(aero_weight) 00073 call aero_state_allocate(aero_state) 00074 call gas_data_allocate(gas_data) 00075 call gas_state_allocate(gas_state) 00076 call env_state_allocate(env_state) 00077 00078 call bin_grid_make(bin_grid, n_bin, diam2rad(d_min), diam2rad(d_max)) 00079 00080 call input_state(in_filename, bin_grid, aero_data, & 00081 aero_weight, aero_state, gas_data, gas_state, env_state, & 00082 index, time, del_t, i_repeat, uuid) 00083 00084 if (dry_volume) then 00085 call aero_state_make_dry(aero_state, bin_grid, aero_data) 00086 end if 00087 00088 call aero_state_bin_average_comp(aero_state, bin_grid, aero_data, & 00089 aero_weight, dry_volume) 00090 00091 output_type = OUTPUT_TYPE_SINGLE 00092 record_removals = .false. 00093 record_optical = .true. 00094 call output_state(out_prefix, output_type, bin_grid, aero_data, & 00095 aero_weight, aero_state, gas_data, gas_state, env_state, & 00096 index, time, del_t, i_repeat, record_removals, record_optical, uuid) 00097 00098 call bin_grid_deallocate(bin_grid) 00099 call aero_data_deallocate(aero_data) 00100 call aero_weight_deallocate(aero_weight) 00101 call aero_state_deallocate(aero_state) 00102 call gas_data_deallocate(gas_data) 00103 call gas_state_deallocate(gas_state) 00104 call env_state_deallocate(env_state) 00105 00106 call pmc_mpi_finalize() 00107 00108 end program bin_average_comp