111 gas_data, gas_state, env_state, index, time, del_t, i_repeat, &
112 record_removals, record_optical, uuid)
115 character(len=*),
intent(in) :: prefix
117 integer,
intent(in) :: output_type
129 integer,
intent(in) :: index
131 real(kind=
dp),
intent(in) :: time
133 real(kind=
dp),
intent(in) :: del_t
135 integer,
intent(in) :: i_repeat
137 logical,
intent(in) :: record_removals
139 logical,
intent(in) :: record_optical
141 character(len=PMC_UUID_LEN),
intent(in) :: uuid
143 integer :: rank, n_proc
148 integer :: ierr, status(MPI_STATUS_SIZE), i_proc, position
149 character,
allocatable :: buffer(:)
158 call output_state_to_file(prefix, aero_data, aero_state, gas_data, &
159 gas_state, env_state, index, time, del_t, i_repeat, &
160 record_removals, record_optical, uuid, rank, n_proc)
162 do i_proc = 1,(n_proc - 1)
164 index, time, del_t, i_repeat, record_removals, &
165 record_optical, uuid, i_proc)
173 call output_state_to_file(prefix, aero_data, aero_state, gas_data, &
174 gas_state, env_state, index, time, del_t, i_repeat, &
175 record_removals, record_optical, uuid, rank, n_proc)
177 if (n_proc == 1)
then
178 call output_state_to_file(prefix, aero_data, aero_state, gas_data, &
179 gas_state, env_state, index, time, del_t, i_repeat, &
180 record_removals, record_optical, uuid, rank, n_proc)
185 env_state_write = env_state
186 gas_state_write = gas_state
191 call output_state_to_file(prefix, aero_data, aero_state_write, &
192 gas_data, gas_state_write, env_state_write, index, time, &
193 del_t, i_repeat, record_removals, record_optical, uuid, &
199 call die_msg(626743323,
"Unknown output_type: " &
209 write_rank, write_n_proc)
212 character(len=*),
intent(out) :: filename
214 character(len=*),
intent(in) :: prefix
216 character(len=*),
intent(in) :: suffix
218 integer,
intent(in),
optional :: index
220 integer,
intent(in),
optional :: i_repeat
222 integer,
intent(in),
optional :: write_rank
224 integer,
intent(in),
optional :: write_n_proc
226 integer :: ncid, use_rank, use_n_proc
227 character(len=100) :: proc_string, index_string, repeat_string
229 if (
present(write_rank))
then
230 use_rank = write_rank
234 if (
present(write_n_proc))
then
235 use_n_proc = write_n_proc
243 if (
present(i_repeat))
write(repeat_string,
'(a,i4.4)')
'_', i_repeat
244 if (use_n_proc > 1)
write(proc_string,
'(a,i4.4)')
'_', (use_rank + 1)
245 if (
present(index))
write(index_string,
'(a,i8.8)')
'_', index
246 write(filename,
'(a,a,a,a,a)') trim(prefix), trim(repeat_string), &
247 trim(proc_string), trim(index_string), trim(suffix)
257 integer,
intent(in) :: ncid
259 real(kind=
dp),
intent(in) :: time
261 real(kind=
dp),
intent(in) :: del_t
263 integer,
intent(in) :: index
266 description=
"time elapsed since simulation start")
268 description=
"current timestep size")
270 description=
"an integer that is 1 on the first timestep, " &
271 //
"2 on the second timestep, etc.")
279 subroutine output_state_to_file(prefix, aero_data, aero_state, gas_data, &
280 gas_state, env_state, index, time, del_t, i_repeat, record_removals, &
281 record_optical, uuid, write_rank, write_n_proc)
284 character(len=*),
intent(in) :: prefix
296 integer,
intent(in) :: index
298 real(kind=
dp),
intent(in) :: time
300 real(kind=
dp),
intent(in) :: del_t
302 integer,
intent(in) :: i_repeat
304 logical,
intent(in) :: record_removals
306 logical,
intent(in) :: record_optical
308 character(len=PMC_UUID_LEN),
intent(in) :: uuid
310 integer,
intent(in),
optional :: write_rank
312 integer,
intent(in),
optional :: write_n_proc
314 character(len=len(prefix)+100) :: filename
364 call make_filename(filename, prefix,
".nc", index, i_repeat, write_rank, &
368 "PartMC version " // trim(
partmc_version), write_rank, write_n_proc)
371 description=
"repeat number of this simulation (starting from 1)")
373 call env_state_output_netcdf(env_state, ncid)
374 call gas_data_output_netcdf(gas_data, ncid)
375 call gas_state_output_netcdf(gas_state, ncid, gas_data)
376 call aero_data_output_netcdf(aero_data, ncid)
377 call aero_state_output_netcdf(aero_state, ncid, aero_data, &
378 record_removals, record_optical)
382 end subroutine output_state_to_file
397 integer :: buffer_size, max_buffer_size, position, ierr
398 character,
allocatable :: buffer(:)
403 max_buffer_size = max_buffer_size &
405 max_buffer_size = max_buffer_size &
407 max_buffer_size = max_buffer_size &
409 allocate(buffer(max_buffer_size))
414 call assert(839343839, position <= max_buffer_size)
415 buffer_size = position
416 call mpi_send(buffer, buffer_size, mpi_character, 0, &
429 time, del_t, i_repeat, record_removals, record_optical, uuid, &
433 character(len=*),
intent(in) :: prefix
439 integer,
intent(in) :: index
441 real(kind=
dp),
intent(in) :: time
443 real(kind=
dp),
intent(in) :: del_t
445 integer,
intent(in) :: i_repeat
447 logical,
intent(in) :: record_removals
449 logical,
intent(in) :: record_optical
451 character(len=PMC_UUID_LEN),
intent(in) :: uuid
453 integer,
intent(in) :: remote_proc
459 integer :: buffer_size, position, status(MPI_STATUS_SIZE)
460 integer :: n_proc, ierr
461 character,
allocatable :: buffer(:)
464 call assert(291452117, remote_proc /= 0)
471 call mpi_get_count(status, mpi_character, buffer_size, ierr)
474 allocate(buffer(buffer_size))
475 call mpi_recv(buffer, buffer_size, mpi_character, remote_proc, &
484 call assert(279581330, position == buffer_size)
487 call output_state_to_file(prefix, aero_data, aero_state, gas_data, &
488 gas_state, env_state, index, time, del_t, i_repeat, &
489 record_removals, record_optical, uuid, remote_proc, n_proc)
497 subroutine input_state(filename, index, time, del_t, i_repeat, uuid, &
498 aero_data, aero_state, gas_data, gas_state, env_state)
501 character(len=*),
intent(in) :: filename
503 integer,
intent(out) :: index
505 real(kind=
dp),
intent(out) :: time
507 real(kind=
dp),
intent(out) :: del_t
509 integer,
intent(out) :: i_repeat
511 character(len=PMC_UUID_LEN),
intent(out) :: uuid
513 type(
aero_data_t),
optional,
intent(inout) :: aero_data
515 type(
aero_state_t),
optional,
intent(inout) :: aero_state
517 type(
gas_data_t),
optional,
intent(inout) :: gas_data
519 type(
gas_state_t),
optional,
intent(inout) :: gas_state
521 type(
env_state_t),
optional,
intent(inout) :: env_state
526 "can only call from process 0")
530 call pmc_nc_check(nf90_get_att(ncid, nf90_global,
"UUID", uuid))
537 if (
present(aero_data))
then
539 if (
present(aero_state))
then
543 call assert_msg(289621231,
present(aero_state) .eqv. .false., &
544 "cannot input aero_state without aero_data")
547 if (
present(gas_data))
then
549 if (
present(gas_state))
then
553 call assert_msg(874298496,
present(gas_state) .eqv. .false., &
554 "cannot input gas_state without gas_data")
557 if (
present(env_state))
then
571 character(len=*),
intent(in) :: prefix
573 character(len=*),
intent(inout),
allocatable :: filename_list(:)
575 integer :: n_file, index, unit, ios
576 character(len=len(prefix)+100) :: filename
580 "can only call from process 0")
585 do while (.not. done)
586 write(filename,
'(a,a,i8.8,a)') trim(prefix),
'_', index,
'.nc'
587 open(unit=unit, file=filename, status=
'old', iostat=ios)
600 write(filename,
'(a,a,i8.8,a)') trim(prefix),
'_', index,
'.nc'
601 filename_list(index) = filename
612 character(len=*),
intent(in) :: prefix
614 integer,
intent(out) :: n_repeat
616 integer,
intent(out) :: n_index
618 integer :: repeat, index, unit, ios
619 character(len=len(prefix)+100) :: filename
623 "can only call from process 0")
630 do while (.not. done)
632 open(unit=unit, file=filename, status=
'old', iostat=ios)
640 n_repeat = repeat - 1
642 "no files found with prefix: " // trim(prefix))
647 do while (.not. done)
649 open(unit=unit, file=filename, status=
'old', iostat=ios)
665 gas_data, gas_state, env_state, index, time, del_t, uuid)
668 character(len=*),
intent(in) :: prefix
682 integer,
intent(in) :: index
684 real(kind=
dp),
intent(in) :: time
686 real(kind=
dp),
intent(in) :: del_t
688 character(len=PMC_UUID_LEN),
intent(in) :: uuid
691 character(len=len(prefix)+100) :: filename
693 write(filename,
'(a,a,i8.8,a)') trim(prefix), &
701 call env_state_output_netcdf(env_state, ncid)
702 call gas_data_output_netcdf(gas_data, ncid)
703 call gas_state_output_netcdf(gas_state, ncid, gas_data)
704 call aero_data_output_netcdf(aero_data, ncid)
705 call aero_binned_output_netcdf(aero_binned, ncid, bin_grid, &
716 aero_data, aero_binned, gas_data, gas_state, env_state)
719 character(len=*),
intent(in) :: filename
721 integer,
intent(out) :: index
723 real(kind=
dp),
intent(out) :: time
725 real(kind=
dp),
intent(out) :: del_t
727 character(len=PMC_UUID_LEN),
intent(out) :: uuid
729 type(
bin_grid_t),
optional,
intent(inout) :: bin_grid
731 type(
aero_data_t),
optional,
intent(inout) :: aero_data
735 type(
gas_data_t),
optional,
intent(inout) :: gas_data
737 type(
gas_state_t),
optional,
intent(inout) :: gas_state
739 type(
env_state_t),
optional,
intent(inout) :: env_state
744 "can only call from process 0")
748 call pmc_nc_check(nf90_get_att(ncid, nf90_global,
"UUID", uuid))
754 if (
present(bin_grid))
then
757 if (
present(aero_data))
then
760 if (
present(aero_binned))
then
762 present(bin_grid) .and.
present(aero_data), &
763 "cannot input aero_binned without bin_grid and aero_data")
768 if (
present(gas_data))
then
770 if (
present(gas_state))
then
774 call assert_msg(214545112,
present(gas_state) .eqv. .false., &
775 "cannot input gas_state without gas_data")
778 if (
present(env_state))
then
790 env_state, gas_data, gas_state, bin_grid, &
791 scenario, index, time, del_t, uuid)
794 character(len=*),
intent(in) :: prefix
798 type(aero_dist_t),
intent(in) :: aero_dist
812 integer,
intent(in) :: index
814 real(kind=
dp),
intent(in) :: time
816 real(kind=
dp),
intent(in) :: del_t
818 character(len=PMC_UUID_LEN),
intent(in) :: uuid
821 character(len=len(prefix)+100) :: filename
823 write(filename,
'(a,a,i8.8,a)') trim(prefix),
'_', index,
'.nc'
830 call aero_binned_output_netcdf(aero_binned, ncid, bin_grid, aero_data)
831 call aero_dist_output_netcdf(aero_dist, ncid)
832 call env_state_output_netcdf(env_state, ncid)
833 call gas_data_output_netcdf(gas_data, ncid)
834 call gas_state_output_netcdf(gas_state, ncid, gas_data)
835 call aero_data_output_netcdf(aero_data, ncid)
846 subroutine input_modal(filename, index, time, del_t, uuid, aero_dist, &
847 aero_binned, aero_data, env_state, gas_data, gas_state, bin_grid, &
851 character(len=*),
intent(in) :: filename
853 integer,
intent(out) :: index
855 real(kind=
dp),
intent(out) :: time
857 real(kind=
dp),
intent(out) :: del_t
859 character(len=PMC_UUID_LEN),
intent(out) :: uuid
861 type(aero_dist_t),
optional,
intent(inout) :: aero_dist
865 type(
aero_data_t),
optional,
intent(inout) :: aero_data
867 type(
env_state_t),
optional,
intent(inout) :: env_state
869 type(
gas_data_t),
optional,
intent(inout) :: gas_data
871 type(
gas_state_t),
optional,
intent(inout) :: gas_state
873 type(
bin_grid_t),
optional,
intent(inout) :: bin_grid
875 type(
scenario_t),
optional,
intent(inout) :: scenario
880 "can only call from process 0")
884 call pmc_nc_check(nf90_get_att(ncid, nf90_global,
"UUID", uuid))
890 if (
present(aero_data))
then
894 if (
present(aero_dist))
then
895 call aero_dist_input_netcdf(aero_dist, ncid)
898 if (
present(env_state))
then
902 if (
present(gas_data))
then
904 if (
present(gas_state))
then
908 call assert_msg(739182654,
present(gas_state) .eqv. .false., &
909 "cannot input gas_state without gas_data")
912 if (
present(bin_grid))
then
914 if (
present(aero_binned))
then
918 call assert_msg(582491376,
present(aero_binned) .eqv. .false., &
919 "cannot input aero_binned without bin_grid")
922 if (
present(scenario))
then
932 subroutine spec_file_read_output_type(file, output_type)
937 integer,
intent(out) :: output_type
939 character(len=SPEC_LINE_MAX_VAR_LEN) :: output_type_name
954 if (trim(output_type_name) ==
'central')
then
956 elseif (trim(output_type_name) ==
'dist')
then
958 elseif (trim(output_type_name) ==
'single')
then
962 "Unknown output type: " // trim(output_type_name))
965 end subroutine spec_file_read_output_type
971 gas_states, env_states, nz, index, time, del_t, i_repeat, &
972 record_removals, record_optical, uuid, write_rank, write_n_proc)
975 character(len=*),
intent(in) :: prefix
979 type(
aero_state_t),
dimension(nz),
intent(in) :: aero_states
983 type(
gas_state_t),
dimension(nz),
intent(in) :: gas_states
985 type(
env_state_t),
dimension(nz),
intent(in) :: env_states
987 integer,
intent(in) :: nz
989 integer,
intent(in) :: index
991 real(kind=
dp),
intent(in) :: time
993 real(kind=
dp),
intent(in) :: del_t
995 integer,
intent(in) :: i_repeat
997 logical,
intent(in) :: record_removals
999 logical,
intent(in) :: record_optical
1001 character(len=PMC_UUID_LEN),
intent(in) :: uuid
1003 integer,
intent(in),
optional :: write_rank
1005 integer,
intent(in),
optional :: write_n_proc
1007 character(len=len(prefix)+100) :: filename
1009 character(len=50) :: group_name
1010 integer :: ncid_group
1014 write(filename,
'(a,a,i3.3,a,i3.3,a,i8.8,a)') trim(prefix),
'_', &
1015 env_states(1)%cell_ix,
'_', env_states(1)%cell_iy,
'_', index,
'.nc'
1022 call gas_data_output_netcdf(gas_data, ncid)
1023 call aero_data_output_netcdf(aero_data, ncid)
1027 write(group_name,
'(a,i2.2)')
'level_', env_states(k)%cell_iz
1028 call pmc_nc_check(nf90_def_grp(ncid, group_name, ncid_group))
1030 call env_state_output_netcdf(env_states(k), ncid_group)
1031 call gas_state_output_netcdf(gas_states(k), ncid_group, gas_data)
1032 call aero_state_output_netcdf(aero_states(k), ncid_group, aero_data, &
1033 record_removals, record_optical)
1045 uuid, aero_data, aero_states, gas_data, gas_states, env_states)
1048 character(len=*),
intent(in) :: filename
1052 type(
aero_state_t),
dimension(nz),
intent(inout) :: aero_states
1056 type(
gas_state_t),
dimension(nz),
intent(inout) :: gas_states
1058 type(
env_state_t),
dimension(nz),
intent(inout) :: env_states
1060 integer,
intent(in) :: nz
1062 integer,
intent(out) :: index
1064 real(kind=
dp),
intent(out) :: time
1066 real(kind=
dp),
intent(out) :: del_t
1068 integer,
intent(out) :: i_repeat
1070 character(len=PMC_UUID_LEN),
intent(out) :: uuid
1073 character(len=50) :: group_name
1074 integer :: ncid_group
1076 integer,
allocatable :: ncid_groups(:)
1082 call pmc_nc_check(nf90_get_att(ncid, nf90_global,
"UUID", uuid))
1090 call pmc_nc_check(nf90_inq_grps(ncid, n_groups, ncid_groups))
1092 call assert_msg(819739350,
size(aero_states) == n_groups, &
1093 "number of levels in file do not match expected number of levels")
1096 write(group_name,
'(a,i2.2)')
'level_', k
1097 call pmc_nc_check(nf90_inq_ncid(ncid, group_name, ncid_group))