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 extract_sectional_aero_size program. 00007 00008 !> Read NetCDF sectional output files and write out the aerosol size 00009 !> distribution in text format. 00010 program extract_sectional_aero_size 00011 00012 use pmc_aero_binned 00013 use pmc_output 00014 use pmc_mpi 00015 use getopt_m 00016 00017 character(len=PMC_MAX_FILENAME_LEN) :: in_prefix, out_filename 00018 character(len=PMC_MAX_FILENAME_LEN), allocatable :: filename_list(:) 00019 type(bin_grid_t) :: bin_grid 00020 type(aero_data_t) :: aero_data 00021 type(aero_binned_t) :: aero_binned 00022 integer :: index, out_unit 00023 integer :: i_file, n_file, i_spec 00024 real(kind=dp) :: time, del_t 00025 character(len=PMC_UUID_LEN) :: uuid, run_uuid 00026 real(kind=dp), allocatable :: times(:), time_num_concs(:), time_mass_concs(:) 00027 real(kind=dp), allocatable :: time_species_concs(:,:) 00028 type(option_s) :: opts(2) 00029 00030 call pmc_mpi_init() 00031 00032 opts(1) = option_s("help", .false., 'h') 00033 opts(2) = option_s("output", .true., 'o') 00034 00035 out_filename = "" 00036 00037 do 00038 select case(getopt("ho:", opts)) 00039 case(char(0)) 00040 exit 00041 case('h') 00042 call print_help() 00043 stop 00044 case('o') 00045 out_filename = optarg 00046 case( '?' ) 00047 call print_help() 00048 call die_msg(559277549, 'unknown option: ' // trim(optopt)) 00049 case default 00050 call print_help() 00051 call die_msg(247146202, 'unhandled option: ' // trim(optopt)) 00052 end select 00053 end do 00054 00055 if (optind /= command_argument_count()) then 00056 call print_help() 00057 call die_msg(959981535, 'expected exactly one non-option prefix argument') 00058 end if 00059 00060 call get_command_argument(optind, in_prefix) 00061 00062 if (out_filename == "") then 00063 out_filename = trim(in_prefix) // "_aero_time.txt" 00064 end if 00065 00066 call bin_grid_allocate(bin_grid) 00067 call aero_data_allocate(aero_data) 00068 call aero_binned_allocate(aero_binned) 00069 00070 allocate(filename_list(0)) 00071 call input_filename_list(in_prefix, filename_list) 00072 n_file = size(filename_list) 00073 call assert_msg(875939143, n_file > 0, & 00074 "no NetCDF files found with prefix: " // trim(in_prefix)) 00075 00076 call input_sectional(filename_list(1), index, time, del_t, uuid, & 00077 bin_grid=bin_grid, aero_data=aero_data, aero_binned=aero_binned) 00078 run_uuid = uuid 00079 00080 allocate(times(n_file)) 00081 allocate(time_num_concs(n_file)) 00082 allocate(time_mass_concs(n_file)) 00083 allocate(time_species_concs(n_file, aero_data%n_spec)) 00084 00085 do i_file = 1,n_file 00086 call input_sectional(filename_list(i_file), index, time, del_t, uuid, & 00087 bin_grid=bin_grid, aero_data=aero_data, aero_binned=aero_binned) 00088 00089 call assert_msg(865522513, uuid == run_uuid, & 00090 "UUID mismatch between " // trim(filename_list(1)) // " and " & 00091 // trim(filename_list(i_file))) 00092 00093 times(i_file) = time 00094 time_num_concs(i_file) = sum(aero_binned%num_conc * bin_grid%log_width) 00095 time_species_concs(i_file, :) = sum(aero_binned%vol_conc & 00096 * bin_grid%log_width, 1) * aero_data%density 00097 time_mass_concs(i_file) = sum(time_species_concs(i_file, :)) 00098 end do 00099 00100 write(*,'(a,a)') "Output file: ", trim(out_filename) 00101 write(*,'(a)') " Each row of output is one time." 00102 write(*,'(a)') " The columns of output are:" 00103 write(*,'(a)') " column 1: time (s)" 00104 write(*,'(a)') " column 2: aerosol number concentration (#/m^3)" 00105 write(*,'(a)') " column 3: aerosol mass concentration (kg/m^3)" 00106 do i_spec = 1,aero_data%n_spec 00107 write(*,'(a,i2,a,a,a)') " column ", i_spec + 3, ": aerosol ", & 00108 trim(aero_data%name(i_spec)), " concentration (kg/m^3)" 00109 end do 00110 00111 call open_file_write(out_filename, out_unit) 00112 do i_file = 1,n_file 00113 write(out_unit, '(e30.15e3)', advance='no') times(i_file) 00114 write(out_unit, '(e30.15e3)', advance='no') time_num_concs(i_file) 00115 write(out_unit, '(e30.15e3)', advance='no') time_mass_concs(i_file) 00116 do i_spec = 1,aero_data%n_spec 00117 write(out_unit, '(e30.15e3)', advance='no') & 00118 time_species_concs(i_file, i_spec) 00119 end do 00120 write(out_unit, '(a)') '' 00121 end do 00122 call close_file(out_unit) 00123 00124 deallocate(times) 00125 deallocate(time_num_concs) 00126 deallocate(time_mass_concs) 00127 deallocate(time_species_concs) 00128 deallocate(filename_list) 00129 call bin_grid_allocate(bin_grid) 00130 call aero_data_deallocate(aero_data) 00131 call aero_binned_deallocate(aero_binned) 00132 00133 call pmc_mpi_finalize() 00134 00135 contains 00136 00137 subroutine print_help() 00138 00139 write(*,'(a)') 'Usage: extract_sectional_aero_time [options] <netcdf_prefix>' 00140 write(*,'(a)') '' 00141 write(*,'(a)') 'options are:' 00142 write(*,'(a)') ' -h, --help Print this help message.' 00143 write(*,'(a)') ' -n, --num Output number distribution.' 00144 write(*,'(a)') ' -m, --mass Output mass distribution.' 00145 write(*,'(a)') ' -o, --out <file> Output filename.' 00146 write(*,'(a)') '' 00147 write(*,'(a)') 'Examples:' 00148 write(*,'(a)') ' extract_sectional_aero_time --num data_0001' 00149 write(*,'(a)') '' 00150 00151 end subroutine print_help 00152 00153 end program extract_sectional_aero_size