Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra columns from separate file via "--extracols" flag #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions src/read_data_sphNG.f90
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module sphNGread
implicit none
real(doub_prec) :: udist,umass,utime,umagfd
real :: tfreefall,dtmax
integer :: istartmhd,istartrt,nmhd,idivvcol,idivvxcol,icurlvxcol,icurlvycol,icurlvzcol,iHIIcol,iHeIIcol,iHeIIIcol
integer :: istartmhd,istartrt,nmhd,idivvcol,idivvxcol,icurlvxcol,icurlvycol,icurlvzcol,iHIIcol,iHeIIcol,iHeIIIcol,iextracols
integer :: nhydroreal4,istart_extra_real4
integer :: itempcol = 0
integer :: ncolstepfirst = 0
Expand Down Expand Up @@ -1386,7 +1386,7 @@ subroutine read_data_sphNG(rootname,indexstart,iposn,nstepsread)
use settings_data, only:ndim,ndimV,ncolumns,ncalc,required,ipartialread,&
lowmemorymode,ntypes,iverbose,ndusttypes
use mem_allocation, only:alloc
use system_utils, only:lenvironment,renvironment
use system_utils, only:lenvironment,renvironment,envlist
use labels, only:ipmass,irho,ih,ix,ivx,labeltype,print_types,headertags,&
iutherm,itemp,ikappa,irhorestframe,labelreq,nreq
use calcquantities, only:calc_quantities
Expand All @@ -1397,7 +1397,7 @@ subroutine read_data_sphNG(rootname,indexstart,iposn,nstepsread)
integer, intent(in) :: indexstart,iposn
integer, intent(out) :: nstepsread
character(len=*), intent(in) :: rootname
integer :: i,j,k,ierr,iunit
integer :: i,j,k,ierr,iunit,iu_extra
integer :: intg1,int2,int3,ilocvx,iversion
integer :: i1,iarr,i2,iptmass1,iptmass2
integer :: npart_max,nstep_max,ncolstep,icolumn,idustarr,nptmasstot
Expand All @@ -1407,13 +1407,14 @@ subroutine read_data_sphNG(rootname,indexstart,iposn,nstepsread)
integer :: ipos,nptmass,nptmassi,ndust,nstar,nunknown,ilastrequired
integer :: imaxcolumnread,nhydroarraysinfile,nhdr,nkilled
integer :: itype,iphaseminthistype,iphasemaxthistype,nthistype,iloc,idenscol
integer :: icentre,icomp_col_start,ncomp
integer :: icentre,icomp_col_start,ncomp,nextracols
integer, dimension(maxparttypes) :: npartoftypei
real, dimension(maxparttypes) :: massoftypei
logical :: iexist, doubleprec,imadepmasscolumn,gotbinary,gotiphase

character(len=len(rootname)+10) :: dumpfile,compfile
character(len=100) :: fileident
character(len=30), dimension(10) :: labelextra

integer*8, dimension(maxarrsizes) :: isize
integer, dimension(maxarrsizes) :: nint,nint1,nint2,nint4,nint8,nreal,nreal4,nreal8
Expand All @@ -1436,11 +1437,13 @@ subroutine read_data_sphNG(rootname,indexstart,iposn,nstepsread)
real, parameter :: Xfrac_default=0.69843,Yfrac_default=0.28731

nstepsread = 0
nextracols = 0
nstep_max = 0
npart_max = maxpart
npart = 0
iunit = 15
ipmass = 4
iextracols = 0
idivvcol = 0
idivvxcol = 0
icurlvxcol = 0
Expand Down Expand Up @@ -1486,6 +1489,8 @@ subroutine read_data_sphNG(rootname,indexstart,iposn,nstepsread)
get_kappa_tot = lenvironment("SPLASH_GET_KAPPATOT")
get_kappa = lenvironment("SPLASH_GET_KAPPA") .or. get_kappa_tot
get_ionfrac = lenvironment("SPLASH_GET_ION")
call envlist('SPLASH_EXTRACOLS',nextracols,labelextra)

if ((get_temperature .or. get_kappa) .and. itempcol > 0 .and. required(itempcol)) then
required(irho) = .true.
required(irhorestframe) = .true.
Expand Down Expand Up @@ -1745,6 +1750,11 @@ subroutine read_data_sphNG(rootname,indexstart,iposn,nstepsread)
elseif (ncolstep < ncolstepfirst) then
ncolstep = ncolstepfirst ! used saved number of columns
endif
if (nextracols > 0) then
print "(a,i2,a)",' READING ',nextracols,' EXTRA COLUMNS '
iextracols = ncolstep + 1
ncolstep = ncolstep + nextracols
endif
inquire(file=trim(dumpfile)//'.divv',exist=iexist)
if (iexist) then
idivvxcol = ncolstep + 1
Expand Down Expand Up @@ -2217,6 +2227,22 @@ subroutine read_data_sphNG(rootname,indexstart,iposn,nstepsread)
close(66)
endif
endif
!
!--read extra columns for phantom dumps
!
if (phantomdump .and. iextracols /= 0) then
do i=1,nextracols
print "(a)",' reading extra columns from '//trim(dumpfile)//'.'//trim(labelextra(i))//'.extras'
open(newunit=iu_extra,file=trim(dumpfile)//'.'//trim(labelextra(i))//'.extras',form='unformatted',status='old',iostat=ierr)
if (ierr /= 0) then
print "(a)",' ERROR opening '//trim(dumpfile)//'.'//trim(labelextra(i))//'.extras'
else
read(iu_extra,iostat=ierr) dat(1:ntotal,iextracols+i-1,j)
if (ierr /= 0) print "(a)",' WARNING: ERRORS reading extra columns from file'
close(iu_extra)
endif
enddo
endif

if (icomp_col_start > 0 .and. any(required(icomp_col_start:icomp_col_start+ncomp))) then
call read_kepler_composition(compfile,ntotal,dat(:,:,j),icomp_col_start,ncomp)
Expand Down Expand Up @@ -2573,11 +2599,12 @@ subroutine set_labels_sphNG
get_nearest_mass_unit,get_nearest_velocity_unit
use sphNGread
use asciiutils, only:lcase,make_tags_unique,match_tag
use system_utils, only:lenvironment,get_environment_or_flag
integer :: i,j,idustlast
use system_utils, only:lenvironment,get_environment_or_flag,envlist
integer :: i,j,idustlast,nextracols
real(doub_prec) :: unitx,unitvel,unitmass
character(len=20) :: string,unitlabelx,unitlabelv
character(len=20) :: deltav_string
character(len=30), dimension(10) :: labelextra

if (ndim <= 0 .or. ndim > 3) then
print*,'*** ERROR: ndim = ',ndim,' in set_labels_sphNG ***'
Expand Down Expand Up @@ -2756,6 +2783,14 @@ subroutine set_labels_sphNG
if (iHIIcol > 0) label(iHIIcol) = 'HII fraction'
if (iHeIIcol > 0) label(iHeIIcol) = 'HeII fraction'
if (iHeIIIcol > 0) label(iHeIIIcol) = 'HeIII fraction'

! Labels for extra columns
call envlist('SPLASH_EXTRACOLS',nextracols,labelextra)
if (nextracols > 0) then
do i=iextracols,iextracols+nextracols-1
label(i) = trim(labelextra(i-iextracols+1))
enddo
endif
if (icurlvxcol > 0 .and. icurlvycol > 0 .and. icurlvzcol > 0) then
call make_vector_label('curl v',icurlvxcol,ndimV,iamvec,labelvec,label,labelcoord(:,1))
endif
Expand Down
Loading