! $Id: snapshot.f90 12535 2009-12-13 07:49:11Z AxelBrandenburg $ ! ! Write snapshot files (variables and power spectra). ! module Snapshot ! use Cdata use Cparam use Messages ! implicit none ! private ! integer :: lun_output=92 ! public :: rsnap, wsnap public :: output_globals, input_globals ! contains !*********************************************************************** subroutine wsnap(chsnap,a,msnap,enum,flist,noghost) ! ! Write snapshot file, labelled consecutively if enum==.true. ! Otherwise just write a snapshot without label (used for var.dat). ! ! 30-sep-97/axel: coded ! 08-oct-02/tony: expanded file to handle 120 character datadir // '/tsnap.dat' ! 5-apr-03/axel: possibility for additional (hard-to-get) output ! 31-may-03/axel: wsnap can write either w/ or w/o auxiliary variables ! use Mpicomm use Boundcond, only: update_ghosts use General, only: safe_character_assign use Sub, only: read_snaptime,update_snaptime use IO, only: log_filename_to_file ! ! The dimension msnap can either be mfarray (for f-array in run.f90) ! or just mvar (for f-array in start.f90 or df-array in run.f90 ! character (len=*) :: chsnap, flist real, dimension (mx,my,mz,msnap) :: a integer :: msnap logical :: enum, noghost optional :: enum, flist, noghost ! real, save :: tsnap integer, save :: ifirst=0,nsnap logical :: lsnap character (len=fnlen) :: file character (len=5) :: ch ! ! Output snapshot with label in 'tsnap' time intervals. ! File keeps the information about number and time of last snapshot. ! if (enum) then call safe_character_assign(file,trim(datadir)//'/tsnap.dat') ! ! At first call, need to initialize tsnap. ! tsnap calculated in read_snaptime, but only available to root processor. ! if (ifirst==0) then call read_snaptime(file,tsnap,nsnap,dsnap,t) ifirst=1 endif ! ! Check whether we want to output snapshot. If so, then ! update ghost zones for var.dat (cheap, since done infrequently). ! call update_snaptime(file,tsnap,nsnap,dsnap,t,lsnap,ch,ENUM=.true.) if (lsnap) then call update_ghosts(a) if (msnap==mfarray) call update_auxiliaries(a) call output_snap(chsnap//ch,a,msnap) if (ip<=10.and.lroot) print*,'wsnap: written snapshot ',chsnap//ch if (present(flist)) call log_filename_to_file(chsnap//ch,flist) endif ! else ! ! Write snapshot without label (typically, var.dat). For dvar.dat we need to ! make sure that ghost zones are not set on df! ! if (present(noghost)) then if (.not. noghost) call update_ghosts(a) else call update_ghosts(a) endif if (msnap==mfarray) call update_auxiliaries(a) ! Not if e.g. dvar.dat. call output_snap(chsnap,a,msnap) if (present(flist)) call log_filename_to_file(chsnap,flist) endif ! endsubroutine wsnap !*********************************************************************** subroutine rsnap(chsnap,f,msnap) ! ! Read snapshot file. ! ! 24-jun-05/tony: coded from snap reading code in run.f90 ! use Mpicomm ! ! The dimension msnap can either be mfarray (for f-array in run.f90) ! or just mvar (for f-array in start.f90 or df-array in run.f90. ! integer :: msnap real, dimension (mx,my,mz,msnap) :: f character (len=*) :: chsnap integer :: ivar ! if (ip<=6.and.lroot) print*,'reading var files' ! ! No need to read maux variables as they will be calculated ! at the first time step -- even if lwrite_aux is set. ! Allow for the possibility to read in files that didn't ! have magnetic fields or passive scalar in it. ! NOTE: for this to work one has to modify *manually* data/param.nml ! by adding an entry for MAGNETIC_INIT_PARS or PSCALAR_INIT_PARS. ! !DM: I do not understand why we need to shift the data below. ! I seem to need to set f(:,:,:,iax:iaz) = 0 . Otherwise ! the vector potential is initialised as junk data. And then ! init_aa just adds to it, so junk remains junk. Anyhow ! the initialisation to zero cannot do any harm. ! if (lread_oldsnap_nomag) then f(:,:,:,iax:iaz)=0. print*,'read old snapshot file (but without magnetic field)' call input_snap(trim(directory_snap)//'/var.dat',f,msnap-3,1) ! shift the rest of the data if (iaz