110 gas_data, gas_state, env_state, index, time, del_t, i_repeat, &
111 record_removals, record_optical, uuid)
114 character(len=*),
intent(in) :: prefix
116 integer,
intent(in) :: output_type
128 integer,
intent(in) :: index
130 real(kind=
dp),
intent(in) :: time
132 real(kind=
dp),
intent(in) :: del_t
134 integer,
intent(in) :: i_repeat
136 logical,
intent(in) :: record_removals
138 logical,
intent(in) :: record_optical
140 character(len=PMC_UUID_LEN),
intent(in) :: uuid
142 integer :: rank, n_proc
147 integer :: ierr, status(MPI_STATUS_SIZE), i_proc, position
148 character,
allocatable :: buffer(:)
157 call output_state_to_file(prefix, aero_data, aero_state, gas_data, &
158 gas_state, env_state, index, time, del_t, i_repeat, &
159 record_removals, record_optical, uuid, rank, n_proc)
161 do i_proc = 1,(n_proc - 1)
163 index, time, del_t, i_repeat, record_removals, &
164 record_optical, uuid, i_proc)
172 call output_state_to_file(prefix, aero_data, aero_state, gas_data, &
173 gas_state, env_state, index, time, del_t, i_repeat, &
174 record_removals, record_optical, uuid, rank, n_proc)
176 if (n_proc == 1)
then
177 call output_state_to_file(prefix, aero_data, aero_state, gas_data, &
178 gas_state, env_state, index, time, del_t, i_repeat, &
179 record_removals, record_optical, uuid, rank, n_proc)
184 env_state_write = env_state
185 gas_state_write = gas_state
190 call output_state_to_file(prefix, aero_data, aero_state_write, &
191 gas_data, gas_state_write, env_state_write, index, time, &
192 del_t, i_repeat, record_removals, record_optical, uuid, &
198 call die_msg(626743323,
"Unknown output_type: " &
208 write_rank, write_n_proc)
211 character(len=*),
intent(out) :: filename
213 character(len=*),
intent(in) :: prefix
215 character(len=*),
intent(in) :: suffix
217 integer,
intent(in),
optional :: index
219 integer,
intent(in),
optional :: i_repeat
221 integer,
intent(in),
optional :: write_rank
223 integer,
intent(in),
optional :: write_n_proc
225 integer :: ncid, use_rank, use_n_proc
226 character(len=100) :: proc_string, index_string, repeat_string
228 if (
present(write_rank))
then
229 use_rank = write_rank
233 if (
present(write_n_proc))
then
234 use_n_proc = write_n_proc
242 if (
present(i_repeat))
write(repeat_string,
'(a,i4.4)')
'_', i_repeat
243 if (use_n_proc > 1)
write(proc_string,
'(a,i4.4)')
'_', (use_rank + 1)
244 if (
present(index))
write(index_string,
'(a,i8.8)')
'_', index
245 write(filename,
'(a,a,a,a,a)') trim(prefix), trim(repeat_string), &
246 trim(proc_string), trim(index_string), trim(suffix)
256 integer,
intent(in) :: ncid
258 real(kind=
dp),
intent(in) :: time
260 real(kind=
dp),
intent(in) :: del_t
262 integer,
intent(in) :: index
265 description=
"time elapsed since simulation start")
267 description=
"current timestep size")
269 description=
"an integer that is 1 on the first timestep, " &
270 //
"2 on the second timestep, etc.")
278 subroutine output_state_to_file(prefix, aero_data, aero_state, gas_data, &
279 gas_state, env_state, index, time, del_t, i_repeat, record_removals, &
280 record_optical, uuid, write_rank, write_n_proc)
283 character(len=*),
intent(in) :: prefix
295 integer,
intent(in) :: index
297 real(kind=
dp),
intent(in) :: time
299 real(kind=
dp),
intent(in) :: del_t
301 integer,
intent(in) :: i_repeat
303 logical,
intent(in) :: record_removals
305 logical,
intent(in) :: record_optical
307 character(len=PMC_UUID_LEN),
intent(in) :: uuid
309 integer,
intent(in),
optional :: write_rank
311 integer,
intent(in),
optional :: write_n_proc
313 character(len=len(prefix)+100) :: filename
363 call make_filename(filename, prefix,
".nc", index, i_repeat, write_rank, &
367 "PartMC version " // trim(
partmc_version), write_rank, write_n_proc)
370 description=
"repeat number of this simulation (starting from 1)")
372 call env_state_output_netcdf(env_state, ncid)
373 call gas_data_output_netcdf(gas_data, ncid)
374 call gas_state_output_netcdf(gas_state, ncid, gas_data)
375 call aero_data_output_netcdf(aero_data, ncid)
376 call aero_state_output_netcdf(aero_state, ncid, aero_data, &
377 record_removals, record_optical)
381 end subroutine output_state_to_file
396 integer :: buffer_size, max_buffer_size, position, ierr
397 character,
allocatable :: buffer(:)
402 max_buffer_size = max_buffer_size &
404 max_buffer_size = max_buffer_size &
406 max_buffer_size = max_buffer_size &
408 allocate(buffer(max_buffer_size))
413 call assert(839343839, position <= max_buffer_size)
414 buffer_size = position
415 call mpi_send(buffer, buffer_size, mpi_character, 0, &
428 time, del_t, i_repeat, record_removals, record_optical, uuid, &
432 character(len=*),
intent(in) :: prefix
438 integer,
intent(in) :: index
440 real(kind=
dp),
intent(in) :: time
442 real(kind=
dp),
intent(in) :: del_t
444 integer,
intent(in) :: i_repeat
446 logical,
intent(in) :: record_removals
448 logical,
intent(in) :: record_optical
450 character(len=PMC_UUID_LEN),
intent(in) :: uuid
452 integer,
intent(in) :: remote_proc
458 integer :: buffer_size, position, status(MPI_STATUS_SIZE)
459 integer :: n_proc, ierr
460 character,
allocatable :: buffer(:)
463 call assert(291452117, remote_proc /= 0)
470 call mpi_get_count(status, mpi_character, buffer_size, ierr)
473 allocate(buffer(buffer_size))
474 call mpi_recv(buffer, buffer_size, mpi_character, remote_proc, &
483 call assert(279581330, position == buffer_size)
486 call output_state_to_file(prefix, aero_data, aero_state, gas_data, &
487 gas_state, env_state, index, time, del_t, i_repeat, &
488 record_removals, record_optical, uuid, remote_proc, n_proc)
496 subroutine input_state(filename, index, time, del_t, i_repeat, uuid, &
497 aero_data, aero_state, gas_data, gas_state, env_state)
500 character(len=*),
intent(in) :: filename
502 integer,
intent(out) :: index
504 real(kind=
dp),
intent(out) :: time
506 real(kind=
dp),
intent(out) :: del_t
508 integer,
intent(out) :: i_repeat
510 character(len=PMC_UUID_LEN),
intent(out) :: uuid
512 type(
aero_data_t),
optional,
intent(inout) :: aero_data
514 type(
aero_state_t),
optional,
intent(inout) :: aero_state
516 type(
gas_data_t),
optional,
intent(inout) :: gas_data
518 type(
gas_state_t),
optional,
intent(inout) :: gas_state
520 type(
env_state_t),
optional,
intent(inout) :: env_state
525 "can only call from process 0")
529 call pmc_nc_check(nf90_get_att(ncid, nf90_global,
"UUID", uuid))
536 if (
present(aero_data))
then
538 if (
present(aero_state))
then
542 call assert_msg(289621231,
present(aero_state) .eqv. .false., &
543 "cannot input aero_state without aero_data")
546 if (
present(gas_data))
then
548 if (
present(gas_state))
then
552 call assert_msg(874298496,
present(gas_state) .eqv. .false., &
553 "cannot input gas_state without gas_data")
556 if (
present(env_state))
then
570 character(len=*),
intent(in) :: prefix
572 character(len=*),
intent(inout),
allocatable :: filename_list(:)
574 integer :: n_file, index, unit, ios
575 character(len=len(prefix)+100) :: filename
579 "can only call from process 0")
584 do while (.not. done)
585 write(filename,
'(a,a,i8.8,a)') trim(prefix),
'_', index,
'.nc'
586 open(unit=unit, file=filename, status=
'old', iostat=ios)
599 write(filename,
'(a,a,i8.8,a)') trim(prefix),
'_', index,
'.nc'
600 filename_list(index) = filename
611 character(len=*),
intent(in) :: prefix
613 integer,
intent(out) :: n_repeat
615 integer,
intent(out) :: n_index
617 integer :: repeat, index, unit, ios
618 character(len=len(prefix)+100) :: filename
622 "can only call from process 0")
629 do while (.not. done)
631 open(unit=unit, file=filename, status=
'old', iostat=ios)
639 n_repeat = repeat - 1
641 "no files found with prefix: " // trim(prefix))
646 do while (.not. done)
648 open(unit=unit, file=filename, status=
'old', iostat=ios)
664 gas_data, gas_state, env_state, index, time, del_t, uuid)
667 character(len=*),
intent(in) :: prefix
681 integer,
intent(in) :: index
683 real(kind=
dp),
intent(in) :: time
685 real(kind=
dp),
intent(in) :: del_t
687 character(len=PMC_UUID_LEN),
intent(in) :: uuid
690 character(len=len(prefix)+100) :: filename
692 write(filename,
'(a,a,i8.8,a)') trim(prefix), &
700 call env_state_output_netcdf(env_state, ncid)
701 call gas_data_output_netcdf(gas_data, ncid)
702 call gas_state_output_netcdf(gas_state, ncid, gas_data)
703 call aero_data_output_netcdf(aero_data, ncid)
704 call aero_binned_output_netcdf(aero_binned, ncid, bin_grid, &
715 aero_data, aero_binned, gas_data, gas_state, env_state)
718 character(len=*),
intent(in) :: filename
720 integer,
intent(out) :: index
722 real(kind=
dp),
intent(out) :: time
724 real(kind=
dp),
intent(out) :: del_t
726 character(len=PMC_UUID_LEN),
intent(out) :: uuid
728 type(
bin_grid_t),
optional,
intent(inout) :: bin_grid
730 type(
aero_data_t),
optional,
intent(inout) :: aero_data
734 type(
gas_data_t),
optional,
intent(inout) :: gas_data
736 type(
gas_state_t),
optional,
intent(inout) :: gas_state
738 type(
env_state_t),
optional,
intent(inout) :: env_state
743 "can only call from process 0")
747 call pmc_nc_check(nf90_get_att(ncid, nf90_global,
"UUID", uuid))
753 if (
present(bin_grid))
then
756 if (
present(aero_data))
then
759 if (
present(aero_binned))
then
761 present(bin_grid) .and.
present(aero_data), &
762 "cannot input aero_binned without bin_grid and aero_data")
767 if (
present(gas_data))
then
769 if (
present(gas_state))
then
773 call assert_msg(214545112,
present(gas_state) .eqv. .false., &
774 "cannot input gas_state without gas_data")
777 if (
present(env_state))
then
789 subroutine spec_file_read_output_type(file, output_type)
794 integer,
intent(out) :: output_type
796 character(len=SPEC_LINE_MAX_VAR_LEN) :: output_type_name
811 if (trim(output_type_name) ==
'central')
then
813 elseif (trim(output_type_name) ==
'dist')
then
815 elseif (trim(output_type_name) ==
'single')
then
819 "Unknown output type: " // trim(output_type_name))
822 end subroutine spec_file_read_output_type