From e08ed097e82ce3be57e3c3e61abe1b0685ef2d6f Mon Sep 17 00:00:00 2001 From: David A Minton Date: Tue, 23 Nov 2021 17:00:27 -0500 Subject: [PATCH] Fixed issue involving reading in NetCDF files when there are no test particles (and/or no planets) --- src/netcdf/netcdf.f90 | 80 ++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index 7acc79b02..6c1e05e7a 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -544,55 +544,55 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) ! Now read in each variable and split the outputs by body type if ((param%in_form == XV) .or. (param%in_form == XVEL)) then call check( nf90_get_var(iu%ncid, iu%xhx_varid, rtemp, start=[1, tslot]) ) - pl%xh(1,:) = pack(rtemp, plmask) - tp%xh(1,:) = pack(rtemp, tpmask) + if (npl > 0) pl%xh(1,:) = pack(rtemp, plmask) + if (ntp > 0) tp%xh(1,:) = pack(rtemp, tpmask) call check( nf90_get_var(iu%ncid, iu%xhy_varid, rtemp, start=[1, tslot]) ) - pl%xh(2,:) = pack(rtemp, plmask) - tp%xh(2,:) = pack(rtemp, tpmask) + if (npl > 0) pl%xh(2,:) = pack(rtemp, plmask) + if (ntp > 0) tp%xh(2,:) = pack(rtemp, tpmask) call check( nf90_get_var(iu%ncid, iu%xhz_varid, rtemp, start=[1, tslot]) ) - pl%xh(3,:) = pack(rtemp, plmask) - tp%xh(3,:) = pack(rtemp, tpmask) + if (npl > 0) pl%xh(3,:) = pack(rtemp, plmask) + if (ntp > 0) tp%xh(3,:) = pack(rtemp, tpmask) call check( nf90_get_var(iu%ncid, iu%vhx_varid, rtemp, start=[1, tslot]) ) - pl%vh(1,:) = pack(rtemp, plmask) - tp%vh(1,:) = pack(rtemp, tpmask) + if (npl > 0) pl%vh(1,:) = pack(rtemp, plmask) + if (ntp > 0) tp%vh(1,:) = pack(rtemp, tpmask) call check( nf90_get_var(iu%ncid, iu%vhy_varid, rtemp, start=[1, tslot]) ) - pl%vh(2,:) = pack(rtemp, plmask) - tp%vh(2,:) = pack(rtemp, tpmask) + if (npl > 0) pl%vh(2,:) = pack(rtemp, plmask) + if (ntp > 0) tp%vh(2,:) = pack(rtemp, tpmask) call check( nf90_get_var(iu%ncid, iu%vhz_varid, rtemp, start=[1, tslot]) ) - pl%vh(3,:) = pack(rtemp, plmask) - tp%vh(3,:) = pack(rtemp, tpmask) + if (npl > 0) pl%vh(3,:) = pack(rtemp, plmask) + if (ntp > 0) tp%vh(3,:) = pack(rtemp, tpmask) end if if ((param%in_form == EL) .or. (param%in_form == XVEL)) then call check( nf90_get_var(iu%ncid, iu%a_varid, rtemp, start=[1, tslot]) ) - pl%a(:) = pack(rtemp, plmask) - tp%a(:) = pack(rtemp, tpmask) + if (npl > 0) pl%a(:) = pack(rtemp, plmask) + if (ntp > 0) tp%a(:) = pack(rtemp, tpmask) call check( nf90_get_var(iu%ncid, iu%e_varid, rtemp, start=[1, tslot]) ) - pl%e(:) = pack(rtemp, plmask) - tp%e(:) = pack(rtemp, tpmask) + if (npl > 0) pl%e(:) = pack(rtemp, plmask) + if (ntp > 0) tp%e(:) = pack(rtemp, tpmask) call check( nf90_get_var(iu%ncid, iu%inc_varid, rtemp, start=[1, tslot]) ) - pl%inc(:) = pack(rtemp, plmask) - tp%inc(:) = pack(rtemp, tpmask) + if (npl > 0) pl%inc(:) = pack(rtemp, plmask) + if (ntp > 0) tp%inc(:) = pack(rtemp, tpmask) call check( nf90_get_var(iu%ncid, iu%capom_varid, rtemp, start=[1, tslot]) ) - pl%capom(:) = pack(rtemp, plmask) - tp%capom(:) = pack(rtemp, tpmask) + if (npl > 0) pl%capom(:) = pack(rtemp, plmask) + if (ntp > 0) tp%capom(:) = pack(rtemp, tpmask) call check( nf90_get_var(iu%ncid, iu%omega_varid, rtemp, start=[1, tslot]) ) - pl%omega(:) = pack(rtemp, plmask) - tp%omega(:) = pack(rtemp, tpmask) + if (npl > 0) pl%omega(:) = pack(rtemp, plmask) + if (ntp > 0) tp%omega(:) = pack(rtemp, tpmask) call check( nf90_get_var(iu%ncid, iu%capm_varid, rtemp, start=[1, tslot]) ) - pl%capm(:) = pack(rtemp, plmask) - tp%capm(:) = pack(rtemp, tpmask) + if (npl > 0) pl%capm(:) = pack(rtemp, plmask) + if (ntp > 0) tp%capm(:) = pack(rtemp, tpmask) end if @@ -600,57 +600,59 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) cb%Gmass = rtemp(1) cb%mass = cb%Gmass / param%GU - pl%Gmass(:) = pack(rtemp, plmask) - pl%mass(:) = pl%Gmass(:) / param%GU + if (npl > 0) then + pl%Gmass(:) = pack(rtemp, plmask) + pl%mass(:) = pl%Gmass(:) / param%GU - if (param%lrhill_present) then - call check( nf90_get_var(iu%ncid, iu%rhill_varid, rtemp, start=[1, tslot]) ) - pl%rhill(:) = pack(rtemp, plmask) + if (param%lrhill_present) then + call check( nf90_get_var(iu%ncid, iu%rhill_varid, rtemp, start=[1, tslot]) ) + pl%rhill(:) = pack(rtemp, plmask) + end if end if if (param%lclose) then call check( nf90_get_var(iu%ncid, iu%radius_varid, rtemp, start=[1, tslot]) ) cb%radius = rtemp(1) - pl%radius(:) = pack(rtemp, plmask) + if (npl > 0) pl%radius(:) = pack(rtemp, plmask) else cb%radius = param%rmin - pl%radius(:) = 0.0_DP + if (npl > 0) pl%radius(:) = 0.0_DP end if if (param%lrotation) then call check( nf90_get_var(iu%ncid, iu%Ip1_varid, rtemp, start=[1, tslot]) ) cb%Ip(1) = rtemp(1) - pl%Ip(1,:) = pack(rtemp, plmask) + if (npl > 0) pl%Ip(1,:) = pack(rtemp, plmask) call check( nf90_get_var(iu%ncid, iu%Ip2_varid, rtemp, start=[1, tslot]) ) cb%Ip(2) = rtemp(1) - pl%Ip(2,:) = pack(rtemp, plmask) + if (npl > 0) pl%Ip(2,:) = pack(rtemp, plmask) call check( nf90_get_var(iu%ncid, iu%Ip3_varid, rtemp, start=[1, tslot]) ) cb%Ip(3) = rtemp(1) - pl%Ip(3,:) = pack(rtemp, plmask) + if (npl > 0) pl%Ip(3,:) = pack(rtemp, plmask) call check( nf90_get_var(iu%ncid, iu%rotx_varid, rtemp, start=[1, tslot]) ) cb%rot(1) = rtemp(1) - pl%rot(1,:) = pack(rtemp, plmask) + if (npl > 0) pl%rot(1,:) = pack(rtemp, plmask) call check( nf90_get_var(iu%ncid, iu%roty_varid, rtemp, start=[1, tslot]) ) cb%rot(2) = rtemp(1) - pl%rot(2,:) = pack(rtemp, plmask) + if (npl > 0) pl%rot(2,:) = pack(rtemp, plmask) call check( nf90_get_var(iu%ncid, iu%rotz_varid, rtemp, start=[1, tslot]) ) cb%rot(3) = rtemp(1) - pl%rot(3,:) = pack(rtemp, plmask) + if (npl > 0) pl%rot(3,:) = pack(rtemp, plmask) end if if (param%ltides) then call check( nf90_get_var(iu%ncid, iu%k2_varid, rtemp, start=[1, tslot]) ) cb%k2 = rtemp(1) - pl%k2(:) = pack(rtemp, plmask) + if (npl > 0) pl%k2(:) = pack(rtemp, plmask) call check( nf90_get_var(iu%ncid, iu%Q_varid, rtemp, start=[1, tslot]) ) cb%Q = rtemp(1) - pl%Q(:) = pack(rtemp, plmask) + if (npl > 0) pl%Q(:) = pack(rtemp, plmask) end if call self%read_particle_info(iu, param, plmask, tpmask)