Skip to content

Commit

Permalink
(grid2pdf) working grid2pdf utility; reads all formats from splash to…
Browse files Browse the repository at this point in the history
… grid output
  • Loading branch information
danieljprice committed Dec 9, 2019
1 parent 7e8061b commit f8eac1f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 36 deletions.
14 changes: 6 additions & 8 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1702,20 +1702,18 @@ phantom_pdfs.o: ../src/utils/pdfs.f90
asciiutils.o: checksplash $(SPLASH_DIR)/src/asciiutils.f90
$(FC) $(FFLAGS) -o $@ -c $(SPLASH_DIR)/src/asciiutils.f90

write_griddata.o: checksplash $(SPLASH_DIR)/src/write_griddata.F90
$(FC) $(FFLAGS) -o $@ -c $(SPLASH_DIR)/src/write_griddata.F90

# these are the sources for the grid2pdf utility

ifdef HDF5
OBJG2PDF= io.o utils_filenames.o asciiutils.o \
OBJG2PDF= io.o utils_filenames.o asciiutils.o write_griddata.o \
hdf5utils.o read_grid_hdf5.o write_grid_hdf5.o io_grid.o pdfs.o rhomach.o grid2pdf.o
else
OBJG2PDF= io.o utils_filenames.o asciiutils.o \
io_grid.o pdfs.o rhomach.o grid2pdf.o
endif

.PHONY: grid2pdf
grid2pdf: checksys checkparams $(OBJG2PDF)
grid2pdf: checksys checkparams checkhdf5 $(OBJG2PDF)
@echo "objects are $(OBJG2PDF)"
$(FC) $(FFLAGS) -o $(BINDIR)/grid2pdf $(OBJG2PDF) $(LDFLAGS)
$(FC) $(FFLAGS) -o $(BINDIR)/grid2pdf $(OBJG2PDF) $(LDFLAGS) -L$(HDF5ROOT)/lib -lhdf5
@echo ""
@echo "Grid2pdf: we are Possibly Dangerously Fanatical"
@echo ""
Expand Down
16 changes: 7 additions & 9 deletions src/utils/grid2pdf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
!+
!--------------------------------------------------------------------------
program grid2pdf
use dim, only:tagline
use io, only:set_io_unit_numbers,iprint,idisk1,real4
use pdfs, only:pdf_calc,pdf_write
use rhomach, only:get_rhomach_grid,write_rhomach
Expand All @@ -31,16 +30,17 @@ program grid2pdf
integer :: npixx,npixy,npixz,nbins,ncols
integer :: nargs,ierr,ifile,i,j,k,n
integer, parameter :: iunit = 71
real, allocatable :: xval(:),pdf(:)
real, allocatable :: datgrid(:,:,:,:) !rho, vx, vy, vz
real, allocatable :: rhogrid(:)
real :: time
real(8), allocatable :: xval(:),pdf(:)
real(8), allocatable :: datgrid(:,:,:,:) !rho, vx, vy, vz
real(8), allocatable :: rhogrid(:)
real(8) :: time
real :: binspacing,pdfmin,pdfmax,rhologmin,rhologmax
real :: rmsv,rmsvmw,rhomean,xtmp
real :: rhomeanvw,rhomeanmw,rhovarvw,rhovarmw
real :: smeanvw,smeanmw,svarvw,svarmw
character(len=120) :: gridfile,fileout,tagline
character(len=120) :: gridfile,fileout
character(len=20) :: gridformat
character(len=*), parameter :: tagline = 'Grid2pdf: (c) Daniel Price 2007-2019 (uses SPLASH pdf module)'
logical :: volweighted,iexist

call set_io_unit_numbers
Expand All @@ -58,7 +58,6 @@ program grid2pdf
stop
endif
print "(/,a,/)",' Grid2pdf: we are pleased to do you service'
tagline = 'Grid2pdf: (c) Daniel Price 2007-2010 (uses SPLASH pdf module)'

call get_command_argument(1,gridformat)

Expand All @@ -73,7 +72,6 @@ program grid2pdf
print*,'error reading dumpfile'
cycle over_files
endif
print*,'finished header read, nx,ny,nz = ',npixx,npixy,npixz,' ncols = ',ncols,' ierr = ',ierr

print "(a,2(i4,' x'),i4,a)",' (allocating memory for ',npixx,npixy,npixz,' grid)'
if (.not.allocated(datgrid)) allocate(datgrid(1,npixx,npixy,npixz))
Expand All @@ -85,7 +83,7 @@ program grid2pdf
call read_grid_column(gridformat,gridfile,1,npixx,npixy,npixz,rhogrid,ierr)

rhomean = sum(rhogrid)/size(rhogrid)
rhogrid = rhogrid/rhomean
! rhogrid = rhogrid/rhomean
print*,'rhomean = ',rhomean
n = 0
do k=1,npixz
Expand Down
54 changes: 35 additions & 19 deletions src/utils/io_grid.f90
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
!--------------------------------------------------------------------------
module io_grid
implicit none
integer, parameter, public :: nformats = 1
character(len=4), dimension(nformats) :: labelformat = &
(/'hdf5'/)
integer, parameter :: doub_prec = kind(0.d0)
integer, parameter, public :: nformats = 4
character(len=6), dimension(nformats) :: labelformat = &
(/'ascii ','binary','stream','hdf5 '/)

public :: read_grid_header,read_grid_column
integer, parameter, private :: io_unit = 85

contains

Expand All @@ -41,9 +43,9 @@ subroutine print_grid_formats()

do i=1,nformats
if (i==1) then
print "(i2,') ',a)",i,trim(labelformat(i))//' (default if no format specified)'
print "(1x,a)",'"'//trim(labelformat(i))//'" (default if no format specified)'
else
print "(i2,') ',a)",i,trim(labelformat(i))
print "(1x,a)",'"'//trim(labelformat(i))//'"'
endif
enddo

Expand All @@ -66,7 +68,11 @@ integer function get_grid_format(filename,outfile)
outfile = trim(filename)
get_grid_format = 0
if (index(lcase(filename),'.h5') /= 0) then
get_grid_format = 1
get_grid_format = 4
elseif (index(lcase(filename),'.gridstream') /= 0) then
get_grid_format = 3
elseif (index(lcase(filename),'.grid') /= 0) then
get_grid_format = 2
endif

end function get_grid_format
Expand All @@ -77,14 +83,16 @@ end function get_grid_format
!+
!----------------------------------------------------------------
subroutine read_grid_header(gridformat,filename,nx,ny,nz,ncols,time,ierr)
use hdf5utils, only:read_grid_hdf5_header
use io, only:cstring
use hdf5utils, only:read_grid_hdf5_header
use readwrite_griddata, only:isgridformat,open_gridfile_r
use io, only:cstring
character(len=*), intent(in) :: gridformat,filename
integer, intent(out) :: nx,ny,nz,ncols,ierr
real, intent(out) :: time
real(doub_prec), intent(out) :: time
integer :: npix(3)

ierr = 0
time = 0.
time = 0.d0
nx = 0
ny = 0
nz = 0
Expand All @@ -93,9 +101,13 @@ subroutine read_grid_header(gridformat,filename,nx,ny,nz,ncols,time,ierr)
case('hdf5')
call read_grid_hdf5_header(cstring(filename),nx,ny,nz,ncols,ierr)
case default
print*,' input file format for '//trim(filename)//' not recognised, skipping...'
ierr = 1
return
if (isgridformat('grid'//gridformat)) then
call open_gridfile_r(io_unit,filename,'grid'//trim(gridformat),3,ncols,npix,time,ierr)
nx = npix(1); ny = npix(2); nz = npix(3)
else
print*,' input file format for '//trim(filename)//' not recognised, skipping...'
ierr = 1
endif
end select

end subroutine read_grid_header
Expand All @@ -106,20 +118,24 @@ end subroutine read_grid_header
!+
!----------------------------------------------------------------
subroutine read_grid_column(gridformat,filename,icolumn,nx,ny,nz,datcol,ierr)
use hdf5utils, only:read_grid_hdf5_column
use io, only:cstring
use hdf5utils, only:read_grid_hdf5_column
use readwrite_griddata, only:read_gridcolumn,isgridformat
use io, only:cstring
character(len=*), intent(in) :: gridformat,filename
integer, intent(in) :: icolumn,nx,ny,nz
real, intent(out) :: datcol(:)
real(doub_prec), intent(out) :: datcol(:)
integer, intent(out) :: ierr

select case(gridformat)
case('hdf5')
call read_grid_hdf5_column(cstring(filename),icolumn,nx,ny,nz,datcol,ierr)
case default
print*,' input file format for '//trim(filename)//' not recognised, skipping...'
ierr = 1
return
if (isgridformat('grid'//gridformat)) then
call read_gridcolumn(io_unit,datcol,nx*ny*nz,ierr)
else
print*,' input file format for '//trim(filename)//' not recognised, skipping...'
ierr = 1
endif
end select

end subroutine read_grid_column
Expand Down

0 comments on commit f8eac1f

Please sign in to comment.