| 1 |
!----------------------------------------------------------------- |
| 2 |
! |
| 3 |
! This file is (or was) part of SPLASH, a visualisation tool |
| 4 |
! for Smoothed Particle Hydrodynamics written by Daniel Price: |
| 5 |
! |
| 6 |
! http://users.monash.edu.au/~dprice/splash |
| 7 |
! |
| 8 |
! SPLASH comes with ABSOLUTELY NO WARRANTY. |
| 9 |
! This is free software; and you are welcome to redistribute |
| 10 |
! it under the terms of the GNU General Public License |
| 11 |
! (see LICENSE file for details) and the provision that |
| 12 |
! this notice remains intact. If you modify this file, please |
| 13 |
! note section 2a) of the GPLv2 states that: |
| 14 |
! |
| 15 |
! a) You must cause the modified files to carry prominent notices |
| 16 |
! stating that you changed the files and the date of any change. |
| 17 |
! |
| 18 |
! Copyright (C) 2005-2022 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
!----------------------------------------------------------------- |
| 24 |
! interface routine to convert all of the dump files |
| 25 |
! on the SPLASH command line to a specified output format |
| 26 |
! |
| 27 |
! (c) D. Price 22/01/08 |
| 28 |
!----------------------------------------------------------------- |
| 29 |
module convert |
| 30 |
implicit none |
| 31 |
|
| 32 |
contains |
| 33 |
|
| 34 |
subroutine convert_all(outformat,igotfilenames,useall) |
| 35 |
use particle_data, only:time,gamma,dat,npartoftype,masstype,iamtype |
| 36 |
use settings_data, only:ncolumns,ncalc,required,ntypes,ndim,ndimV,lowmemorymode,& |
| 37 |
buffer_steps_in_file,maxplot |
| 38 |
use filenames, only:rootname,nstepsinfile,nfiles,limitsfile |
| 39 |
use write_sphdata, only:write_sphdump |
| 40 |
use readwrite_griddata, only:isgridformat |
| 41 |
use analysis, only:isanalysis,open_analysis,write_analysis,close_analysis |
| 42 |
use convert_grid, only:convert_to_grid |
| 43 |
use getdata, only:get_data |
| 44 |
use asciiutils, only:ucase |
| 45 |
use limits, only:read_limits |
| 46 |
use system_utils, only:ienvlist |
| 47 |
use labels, only:get_sink_type |
| 48 |
character(len=*), intent(in) :: outformat |
| 49 |
logical, intent(inout) :: igotfilenames |
| 50 |
logical, intent(in) :: useall |
| 51 |
logical :: doanalysis,converttogrid |
| 52 |
integer :: ifile,idump,ntotal,ierr,iloc,isinktype,nsinks |
| 53 |
integer, dimension(maxplot) :: listofcolumns |
| 54 |
character(len=len(rootname)+4) :: filename |
| 55 |
character(len=10) :: string |
| 56 |
|
| 57 |
required = .true. ! read whole dump file by default |
| 58 |
doanalysis = isanalysis(outformat,noprint=.true.) |
| 59 |
converttogrid = isgridformat(outformat) |
| 60 |
lowmemorymode = .false. ! must not be true for first file |
| 61 |
listofcolumns = 0 |
| 62 |
|
| 63 |
if (.not.(doanalysis .or. converttogrid)) then |
| 64 |
! |
| 65 |
!--for format conversion each dump file is independent |
| 66 |
! |
| 67 |
print "(/,5('-'),a,/)",'> CONVERTING SNAPSHOTS TO '//trim(ucase(outformat))//' FORMAT ' |
| 68 |
listofcolumns = ienvlist('SPLASH_CONVERT',ncolumns) |
| 69 |
if (all(listofcolumns==0)) then |
| 70 |
print "(a,/)",' > to output select columns, --convert=1,4 (for columns 1 & 4)' |
| 71 |
else |
| 72 |
print "(a,32(1x,i2),/)",' > WRITING ONLY COLUMNS ',listofcolumns(1:count(listofcolumns > 0)) |
| 73 |
endif |
| 74 |
endif |
| 75 |
|
| 76 |
! |
| 77 |
!--if nfiles = 0 (ie. no files read from command line), then call get_data here |
| 78 |
! to also get nfiles correctly prior to the loop |
| 79 |
! |
| 80 |
if (nfiles==0) then |
| 81 |
call get_data(1,igotfilenames) |
| 82 |
igotfilenames = .true. |
| 83 |
endif |
| 84 |
|
| 85 |
do ifile=1,nfiles |
| 86 |
!--read data from dump file + calculate extra columns |
| 87 |
if (ifile==1) then |
| 88 |
call get_data(ifile,igotfilenames,firsttime=.true.) |
| 89 |
! |
| 90 |
! read plot limits from file (overrides get_data limits settings) |
| 91 |
! |
| 92 |
call read_limits(trim(limitsfile),ierr) |
| 93 |
! |
| 94 |
!--for analysis we need to initialise the output file |
| 95 |
! and close it at the end - do this here so we know |
| 96 |
! the first filename and ndimV, labels etc. |
| 97 |
! |
| 98 |
if (doanalysis) then |
| 99 |
nsinks = 0 |
| 100 |
if (nstepsinfile(ifile) > 0) then |
| 101 |
isinktype = get_sink_type(ntypes) |
| 102 |
if (isinktype > 0) nsinks = npartoftype(isinktype,1) |
| 103 |
endif |
| 104 |
call open_analysis(outformat,required,ncolumns+ncalc,ndim,ndimV,nsinks) |
| 105 |
endif |
| 106 |
else |
| 107 |
call get_data(ifile,.true.) |
| 108 |
endif |
| 109 |
!--dump each step in file to an output file |
| 110 |
do idump = 1,nstepsinfile(ifile) |
| 111 |
if (nstepsinfile(ifile) > 1 .and. .not.buffer_steps_in_file) then |
| 112 |
call get_data(ifile,igotfilenames,.false.,iposinfile=idump) |
| 113 |
iloc = 1 |
| 114 |
else |
| 115 |
iloc = idump |
| 116 |
endif |
| 117 |
if (nstepsinfile(ifile) > 1) then |
| 118 |
write(filename,"(a,'_',i5.5)") trim(rootname(ifile)),idump |
| 119 |
else |
| 120 |
filename = trim(rootname(ifile)) |
| 121 |
endif |
| 122 |
ntotal = sum(npartoftype(1:ntypes,iloc)) |
| 123 |
if (doanalysis) then |
| 124 |
call write_analysis(time(iloc),dat(1:ntotal,:,iloc),ntotal,ntypes, & |
| 125 |
npartoftype(1:ntypes,iloc),masstype(1:ntypes,iloc),iamtype(:,iloc), & |
| 126 |
ncolumns+ncalc,ndim,ndimV,outformat) |
| 127 |
elseif (converttogrid) then |
| 128 |
call convert_to_grid(time(iloc),dat(:,:,iloc),ntypes,& |
| 129 |
npartoftype(1:ntypes,iloc),masstype(1:ntypes,iloc),iamtype(:,iloc), & |
| 130 |
ncolumns+ncalc,filename,outformat,useall) |
| 131 |
else |
| 132 |
call write_sphdump(time(iloc),gamma(iloc),dat(1:ntotal,1:ncolumns+ncalc,iloc),ntotal,ntypes, & |
| 133 |
npartoftype(1:ntypes,iloc),masstype(1:ntypes,iloc),iamtype(:,iloc), & |
| 134 |
ncolumns+ncalc,filename,outformat,listofcolumns(1:ncolumns+ncalc)) |
| 135 |
endif |
| 136 |
enddo |
| 137 |
enddo |
| 138 |
|
| 139 |
!--for analysis we need to start and end differently |
| 140 |
if (doanalysis) then |
| 141 |
call close_analysis(outformat) |
| 142 |
write(string,"(i10)") nfiles |
| 143 |
print "(/,5('-'),a,i5,a,/)",'> FINISHED CALCULATING '//trim(ucase(outformat))//' (USED '//trim(adjustl(string))//' DUMP FILES)' |
| 144 |
else |
| 145 |
print "(/,5('-'),a,/)",'> FINISHED CONVERTING DUMP FILES ' |
| 146 |
endif |
| 147 |
return |
| 148 |
end subroutine convert_all |
| 149 |
|
| 150 |
end module convert |