28 real(kind=dp),
pointer :: mix_rat(:)
41 allocate(gas_state%mix_rat(0))
53 integer,
intent(in) :: n_spec
55 allocate(gas_state%mix_rat(n_spec))
68 deallocate(gas_state%mix_rat)
80 gas_state%mix_rat = 0d0
96 n_spec =
size(from_state%mix_rat)
97 deallocate(to_state%mix_rat)
98 allocate(to_state%mix_rat(n_spec))
99 to_state%mix_rat = from_state%mix_rat
111 real(kind=dp),
intent(in) :: alpha
113 gas_state%mix_rat = gas_state%mix_rat * alpha
127 gas_state%mix_rat = gas_state%mix_rat + gas_state_delta%mix_rat
143 real(kind=dp),
intent(in) :: alpha
145 gas_state%mix_rat = gas_state%mix_rat + alpha * gas_state_delta%mix_rat
159 gas_state%mix_rat = gas_state%mix_rat - gas_state_delta%mix_rat
171 gas_state%mix_rat = max(gas_state%mix_rat, 0d0)
185 gas_state%mix_rat = gas_state%mix_rat &
195 rate_list, time, gas_state, rate)
200 real(kind=dp),
intent(in) :: time_list(size(gas_state_list))
202 real(kind=dp),
intent(in) :: rate_list(size(gas_state_list))
204 real(kind=dp),
intent(in) :: time
208 real(kind=dp),
intent(out) :: rate
211 real(kind=dp) :: y, alpha
213 n =
size(gas_state_list)
214 p =
find_1d(n, time_list, time)
234 subroutine spec_file_read_gas_state(file, gas_data, gas_state)
243 integer :: n_species, species, i
244 character(len=SPEC_LINE_MAX_VAR_LEN),
pointer :: species_name(:)
245 real(kind=dp),
pointer :: species_data(:,:)
270 allocate(species_name(0))
271 allocate(species_data(0,0))
276 n_species =
size(species_data, 1)
277 if (.not. ((
size(species_data, 2) == 1) .or. (n_species == 0)))
then
278 call
die_msg(686719840,
'each line in ' // trim(file%name) &
279 //
' must contain exactly one data value')
285 gas_state%mix_rat = 0d0
288 if (species == 0)
then
289 call
die_msg(129794076,
'unknown species ' // &
290 trim(species_name(i)) //
' in file ' // trim(file%name))
292 gas_state%mix_rat(species) = species_data(i,1)
294 deallocate(species_name)
295 deallocate(species_data)
297 end subroutine spec_file_read_gas_state
303 subroutine spec_file_read_gas_states_times_rates(file, gas_data, &
304 times, rates, gas_states)
311 real(kind=dp),
pointer :: times(:)
313 real(kind=dp),
pointer :: rates(:)
317 integer :: n_lines, species, i, n_time, i_time
318 character(len=SPEC_LINE_MAX_VAR_LEN),
pointer :: species_name(:)
319 real(kind=dp),
pointer :: species_data(:,:)
386 allocate(species_name(0))
387 allocate(species_data(0,0))
392 n_lines =
size(species_data, 1)
393 if (n_lines < 2)
then
394 call
die_msg(291542946,
'insufficient data lines in file ' &
397 if (trim(species_name(1)) /=
'time')
then
398 call
die_msg(525127793,
'row 1 in file ' &
399 // trim(file%name) //
' must start with: time')
401 if (trim(species_name(2)) /=
'rate')
then
402 call
die_msg(506981322,
'row 2 in file ' &
403 // trim(file%name) //
' must start with: rate')
405 n_time =
size(species_data, 2)
407 call
die_msg(398532628,
'each line in file ' &
408 // trim(file%name) //
' must contain at least one data value')
412 do i_time = 1,
size(gas_states)
415 deallocate(gas_states)
418 allocate(gas_states(n_time))
419 allocate(times(n_time))
420 allocate(rates(n_time))
423 times(i_time) = species_data(1,i_time)
424 rates(i_time) = species_data(2,i_time)
428 if (species == 0)
then
429 call
die_msg(806500079,
'unknown species ' &
430 // trim(species_name(i)) //
' in file ' &
434 gas_states(i_time)%mix_rat(species) = species_data(i,i_time)
437 deallocate(species_name)
438 deallocate(species_data)
440 end subroutine spec_file_read_gas_states_times_rates
455 val%mix_rat = val_avg%mix_rat
476 val%mix_rat = val_avg%mix_rat
502 character,
intent(inout) :: buffer(:)
504 integer,
intent(inout) :: position
509 integer :: prev_position
511 prev_position = position
525 character,
intent(inout) :: buffer(:)
527 integer,
intent(inout) :: position
532 integer :: prev_position
534 prev_position = position
560 subroutine gas_state_output_netcdf(gas_state, ncid, gas_data)
565 integer,
intent(in) :: ncid
569 integer :: dimid_gas_species
589 "gas_mixing_ratio", (/ dimid_gas_species /), unit=
"ppb", &
590 long_name=
"mixing ratios of gas species")
592 end subroutine gas_state_output_netcdf
602 integer,
intent(in) :: ncid
subroutine pmc_nc_write_real_1d(ncid, var, name, dimids, dim_name, unit, long_name, standard_name, description)
Write a simple real array to a NetCDF file.
integer function pmc_mpi_pack_size_real_array(val)
Determines the number of bytes required to pack the given value.
subroutine gas_state_zero(gas_state)
Zeros the state.
An input file with extra data for printing messages.
subroutine die_msg(code, error_msg)
Error immediately.
integer function pmc_mpi_pack_size_gas_state(val)
Determines the number of bytes required to pack the given value.
integer function find_1d(n, x_vals, x)
Find the position of a real number in an arbitrary 1D array.
The env_state_t structure and associated subroutines.
subroutine gas_state_sub(gas_state, gas_state_delta)
Subtracts the given gas_state_delta.
subroutine pmc_mpi_pack_gas_state(buffer, position, val)
Packs the given value into the buffer, advancing position.
subroutine pmc_mpi_reduce_avg_gas_state(val, val_avg)
Computes the average of val across all processes, storing the result in val_avg on the root process...
subroutine gas_state_add(gas_state, gas_state_delta)
Adds the given gas_state_delta.
subroutine gas_state_add_scaled(gas_state, gas_state_delta, alpha)
Adds the given gas_state_delta scaled by alpha.
subroutine pmc_mpi_reduce_avg_real_array(val, val_avg)
Computes the average of val across all processes, storing the result in val_avg on the root process...
The gas_data_t structure and associated subroutines.
subroutine spec_file_read_real_named_array(file, max_lines, names, vals)
Read an array of named lines with real data. All lines must have the same number of data elements...
Common utility subroutines.
subroutine pmc_mpi_unpack_real_array(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Current environment state.
subroutine pmc_nc_read_real_1d(ncid, var, name, must_be_present)
Read a simple real array from a NetCDF file.
subroutine pmc_mpi_allreduce_average_real_array(val, val_avg)
Computes the average of val across all processes, storing the result in val_avg on all processes...
integer function pmc_mpi_rank()
Returns the rank of the current process.
Wrapper functions for MPI.
subroutine gas_state_deallocate(gas_state)
Free all storage.
The gas_state_t structure and associated subroutines.
subroutine gas_state_allocate(gas_state)
Allocate storage for gas species.
integer function gas_data_spec_by_name(gas_data, name)
Returns the number of the species in gas with the given name, or returns 0 if there is no such specie...
subroutine gas_state_scale(gas_state, alpha)
Scale a gas state.
subroutine gas_state_ensure_nonnegative(gas_state)
Set any negative values to zero.
Reading formatted text input.
subroutine gas_state_input_netcdf(gas_state, ncid, gas_data)
Read full state.
Wrapper functions for NetCDF. These all take a NetCDF ncid in data mode and return with it again in d...
real(kind=dp) function env_state_air_molar_den(env_state)
Air molar density (mol m^{-3}).
subroutine gas_state_mix(val)
Average val over all processes.
Current state of the gas mixing ratios in the system.
subroutine gas_data_netcdf_dim_gas_species(gas_data, ncid, dimid_gas_species)
Write the gas species dimension to the given NetCDF file if it is not already present and in any case...
subroutine pmc_mpi_pack_real_array(buffer, position, val)
Packs the given value into the buffer, advancing position.
subroutine gas_state_allocate_size(gas_state, n_spec)
Allocate storage for gas species of the given size.
subroutine gas_state_interp_1d(gas_state_list, time_list, rate_list, time, gas_state, rate)
Determine the current gas_state and rate by interpolating at the current time with the lists of gas_s...
subroutine gas_state_mole_dens_to_ppb(gas_state, env_state)
Convert (mol m^{-3}) to (ppb).
subroutine assert(code, condition_ok)
Errors unless condition_ok is true.
subroutine gas_state_reduce_avg(val)
Average val over all processes, with the result only on the root process.
subroutine gas_state_copy(from_state, to_state)
Copy to an already allocated to_state.
subroutine pmc_mpi_unpack_gas_state(buffer, position, val)
Unpacks the given value from the buffer, advancing position.