gadget_io_mod Module Reference

An attempt to practice object oriented Fortran 90 and to make some useful tools for reading Gadget snapshots. I have chosen to add overhead to the number of reads done (ie sometimes sections of a file need to be read multiple times to get the required data) in exchange for preserving memory and ease of coding and use. Note that my particle arrays go from 1-6 and not 0-5. More...


Data Types

type  gadget_header_type
 a gadget header type More...

Functions/Subroutines

integer check_f (snapfile, routine)
 Checks if a file can be found on disk.
integer check_i1 (arr, ghead, read1, pmask, routine)
 Checks if a 1 dimensional integer array conforms to the data to be read.
integer check_r1 (arr, ghead, read1, pmask, routine)
 Checks if a 1 dimensional real array conforms to the data to be read.
integer check_r2 (arr, ghead, read1, pmask, routine)
 Checks if a 2 dimensional real array conforms to the data to be read.
integer gadgetquery_nfiles (snapbase)
 Checks how many files are in a snapshot.
logical, dimension(6) gadgetquery_vmass (snapfile)
 Checks which particle types are variable mass.
subroutine gadgetread_posN (snapbase, pmask, pos)
 Reads positions from a whole snapshot.
subroutine gadgetread_pos1 (snapfile, pmask, pos)
 Reads positions from a single file.
subroutine gadgetread_velN (snapbase, pmask, vel)
 Reads velocities from a whole snapshot.
subroutine gadgetread_vel1 (snapfile, pmask, vel)
 Reads velocities from a single file.
subroutine gadgetread_idN (snapbase, pmask, id)
 Reads velocities from a whole snapshot.
subroutine gadgetread_id1 (snapfile, pmask, id)
 Reads IDs from a single file.
subroutine gadgetread_massN (snapbase, pmask, mass)
 Reads masses from a whole snapshot. Any particles that are constant mass will have their section of the array filled in with the header value gheadmass(ptype).
subroutine gadgetread_mass1 (snapfile, pmask, mass)
 Reads mass from a single file. If there are no variable mass particles for a given type, that section of the array will be filled in with the value from the header.
subroutine gadgetread_gasuN (snapbase, u)
 Reads gas internal energies from a whole snapshot.
subroutine gadgetread_gasu1 (snapfile, u)
 Reads gas internal energies from a single file.
subroutine gadgetread_gasrhoN (snapbase, rho)
 Reads gas densities from a whole snapshot.
subroutine gadgetread_gasrho1 (snapfile, rho)
 Reads gas densities from a single file.
subroutine gadgetread_gasyeN (snapbase, ye)
 Reads gas electron fraction ye=ne/nH from a whole snapshot.
subroutine gadgetread_gasye1 (snapfile, ye)
 Reads gas electron fraction ye = ne/nH from a single file.
subroutine gadgetread_gasxHIN (snapbase, xHI)
 Reads gas H ionization fractions = nHI/nH from a whole snapshot.
subroutine gadgetread_gasxHI1 (snapfile, xHI)
 Reads gas H ionization fraction xHI = nHI/nH from a single file.
subroutine gadgetread_gashsmlN (snapbase, hsml)
 Reads gas smoothing lengths from a whole snapshot. note: gadget smoothing kernels go to 0 at h not 2h.
subroutine gadgetread_gashsml1 (snapfile, hsml)
 Reads gas smoothing lengths from a single file note: gadget smoothing kernels go to 0 at h not 2h.
subroutine gadgetread_gassfrN (snapbase, sfr)
 Reads gas star formation rate from a whole snapshot.
subroutine gadgetread_gassfr1 (snapfile, sfr)
 Reads gas star formation rate from a single file.
subroutine gadgetread_header (snapfile, ghead)
 Loads the header from snapfile into ghead.
subroutine gadgetread_firstheader (snapbase, ghead)
 Loads the header from the first file in a snapshot into ghead.
subroutine gadgetwrite_header (ghead, lun)
 Writes out gadget header data. if lun = -1 then it goes to the screen, otherwise puts it in the file associated with lun.

Variables

integer, parameter r4b = selected_real_kind(6,37)
 4 byte real type
integer, parameter r8b = selected_real_kind(15,307)
 8 byte real type
integer, parameter i4b = selected_int_kind(9)
 4 byte integer type
character(5), dimension(6),
parameter 
parnames = (/,,,,,/)
 particle type names
real(r8b), parameter GLen = 3.085678d21
 default Gadget length unit [cm/h]
real(r8b), parameter GMass = 1.989d43
 default Gadget mass unit [g/h]
real(r8b), parameter GVel = 1.0d5
 default Gadget velocity unit [cm/s]
real(r8b), parameter GTime = GLen / GVel
 default Gadget time unit [s/h]
real(r8b), parameter GRho = GMass / GLen**3
 default Gadget density unit [cgs*h^2]
real(r8b), parameter GPres = GMass / GLen / GTime**2
 default Gadget pressure unit [cgs*h^2]
real(r8b), parameter GEnrg = GMass * GVel**2
 default Gadget energy unit [ergs/h]
integer(i4b), parameter blank = (256 - (25*4+12*8))/4
 blank space left after header variables


Detailed Description

An attempt to practice object oriented Fortran 90 and to make some useful tools for reading Gadget snapshots. I have chosen to add overhead to the number of reads done (ie sometimes sections of a file need to be read multiple times to get the required data) in exchange for preserving memory and ease of coding and use. Note that my particle arrays go from 1-6 and not 0-5.

Function/Subroutine Documentation

integer gadget_io_mod::check_f ( character(*)  snapfile,
character(*)  routine 
) [private]

Checks if a file can be found on disk.

Parameters:
snapfile  file to check for
routine  name of calling routine

Definition at line 88 of file gadget_io.f90.

integer gadget_io_mod::check_i1 ( integer,dimension(:)  arr,
type(gadget_header_type)  ghead,
logical  read1,
logical,dimension(6)  pmask,
character(*)  routine 
) [private]

Checks if a 1 dimensional integer array conforms to the data to be read.

Parameters:
arr  array that will hold the particle data
ghead  gadget header to check particle numbers
read1  true if reading only one file
pmask  particle mask
routine  name of calling routine

Definition at line 105 of file gadget_io.f90.

integer gadget_io_mod::check_r1 ( real,dimension(:)  arr,
type(gadget_header_type)  ghead,
logical  read1,
logical,dimension(6)  pmask,
character(*)  routine 
) [private]

Checks if a 1 dimensional real array conforms to the data to be read.

Parameters:
arr  array that will hold the particle data
ghead  gadget header to check particle numbers
read1  true if reading only one file
pmask  particle mask
routine  name of calling routine

Definition at line 151 of file gadget_io.f90.

integer gadget_io_mod::check_r2 ( real,dimension(:,:)  arr,
type(gadget_header_type)  ghead,
logical  read1,
logical,dimension(6)  pmask,
character(*)  routine 
) [private]

Checks if a 2 dimensional real array conforms to the data to be read.

Parameters:
arr  array that will hold the particle data
ghead  gadget header to check particle numbers
read1  true if reading only one file
pmask  particle mask
routine  name of calling routine

Definition at line 197 of file gadget_io.f90.

integer gadget_io_mod::gadgetquery_nfiles ( character(*)  snapbase  ) 

Checks how many files are in a snapshot.

Parameters:
snapbase  snapshot base name

Definition at line 247 of file gadget_io.f90.

logical,dimension(6) gadget_io_mod::gadgetquery_vmass ( character(*)  snapfile  ) 

Checks which particle types are variable mass.

Returns:
vmass
Parameters:
snapfile  snapshot file to check

Definition at line 272 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_firstheader ( character(*),intent(in)  snapbase,
type(gadget_header_type)  ghead 
)

Loads the header from the first file in a snapshot into ghead.

Parameters:
snapbase  base name of snapshot with path (no file number)
ghead  gadget header to return

Definition at line 1360 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gashsml1 ( character(*),intent(in)  snapfile,
real,dimension(:),intent(out)  hsml 
)

Reads gas smoothing lengths from a single file note: gadget smoothing kernels go to 0 at h not 2h.

Parameters:
snapfile  snapfile to read
hsml  array of smoothing lengths to return [npar]

Definition at line 1184 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gashsmlN ( character(*),intent(in)  snapbase,
real,dimension(:),intent(out)  hsml 
)

Reads gas smoothing lengths from a whole snapshot. note: gadget smoothing kernels go to 0 at h not 2h.

Parameters:
snapbase  snapfile to read
hsml  array of smoothing lengths to return [npar]

Definition at line 1134 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gasrho1 ( character(*),intent(in)  snapfile,
real,dimension(:),intent(out)  rho 
)

Reads gas densities from a single file.

Parameters:
snapfile  snapfile to read
rho  array of densities to return [npar]

Definition at line 892 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gasrhoN ( character(*),intent(in)  snapbase,
real,dimension(:),intent(out)  rho 
)

Reads gas densities from a whole snapshot.

Parameters:
snapbase  snapfile to read
rho  array of densities to return [npar]

Definition at line 842 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gassfr1 ( character(*),intent(in)  snapfile,
real,dimension(:),intent(out)  sfr 
)

Reads gas star formation rate from a single file.

Parameters:
snapfile  snapfile to read
sfr  array of star formation rates to return [npar]

Definition at line 1278 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gassfrN ( character(*),intent(in)  snapbase,
real,dimension(:),intent(out)  sfr 
)

Reads gas star formation rate from a whole snapshot.

Parameters:
snapbase  snapfile to read
sfr  array of star formation rates to return [npar]

Definition at line 1228 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gasu1 ( character(*),intent(in)  snapfile,
real,dimension(:),intent(out)  u 
)

Reads gas internal energies from a single file.

Parameters:
snapfile  snapfile to read
u  array of internal energies to return [npar]

Definition at line 802 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gasuN ( character(*),intent(in)  snapbase,
real,dimension(:),intent(out)  u 
)

Reads gas internal energies from a whole snapshot.

Parameters:
snapbase  snapfile to read
u  array of internal energies to return [npar]

Definition at line 753 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gasxHI1 ( character(*),intent(in)  snapfile,
real,dimension(:),intent(out)  xHI 
)

Reads gas H ionization fraction xHI = nHI/nH from a single file.

Parameters:
snapfile  snapfile to read
xHI  array of xHI to return [npar]

Definition at line 1083 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gasxHIN ( character(*),intent(in)  snapbase,
real,dimension(:),intent(out)  xHI 
)

Reads gas H ionization fractions = nHI/nH from a whole snapshot.

Parameters:
snapbase  snapfile to read
xHI  array of ionization fractions xHI=nHI/nH to return [npar]

Definition at line 1033 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gasye1 ( character(*),intent(in)  snapfile,
real,dimension(:),intent(out)  ye 
)

Reads gas electron fraction ye = ne/nH from a single file.

Parameters:
snapfile  snapfile to read
ye  array of electron fractions to return [npar]

Definition at line 984 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_gasyeN ( character(*),intent(in)  snapbase,
real,dimension(:),intent(out)  ye 
)

Reads gas electron fraction ye=ne/nH from a whole snapshot.

Parameters:
snapbase  snapfile to read
ye  array of electron fractions ye=ne/nH to return [npar]

Definition at line 934 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_header ( character(*),intent(in)  snapfile,
type(gadget_header_type)  ghead 
)

Loads the header from snapfile into ghead.

Parameters:
snapfile  snapshot file to read
ghead  gadget header to return

Definition at line 1336 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_id1 ( character(*),intent(in)  snapfile,
logical,dimension(6),intent(in)  pmask,
integer,dimension(:),intent(out)  id 
)

Reads IDs from a single file.

Parameters:
snapfile  snapfile to read
pmask  pmask(1)=T read gas, pmask(2)=T read halo, ...
id  array of ids to return [npar]

Definition at line 576 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_idN ( character(*),intent(in)  snapbase,
logical,dimension(6),intent(in)  pmask,
integer,dimension(:),intent(out)  id 
)

Reads velocities from a whole snapshot.

Parameters:
snapbase  snapfile to read
pmask  pmask(1)=T read gas, pmask(2)=T read halo, ...
id  array of IDs to return [npar]

Definition at line 512 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_mass1 ( character(*),intent(in)  snapfile,
logical,dimension(6),intent(in)  pmask,
real,dimension(:),intent(out)  mass 
)

Reads mass from a single file. If there are no variable mass particles for a given type, that section of the array will be filled in with the value from the header.

Parameters:
snapfile  snapfile to read
pmask  pmask(1)=T read gas, pmask(2)=T read halo, ...
mass  array of masses to return [npar]

Definition at line 691 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_massN ( character(*),intent(in)  snapbase,
logical,dimension(6),intent(in)  pmask,
real,dimension(:),intent(out)  mass 
)

Reads masses from a whole snapshot. Any particles that are constant mass will have their section of the array filled in with the header value gheadmass(ptype).

Parameters:
snapbase  snapfile to read
pmask  pmask(1)=T read gas, pmask(2)=T read halo, ...
mass  array of masses to return [npar]

Definition at line 626 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_pos1 ( character(*),intent(in)  snapfile,
logical,dimension(6),intent(in)  pmask,
real,dimension(:,:),intent(out)  pos 
)

Reads positions from a single file.

Parameters:
snapfile  snapfile to read
pmask  pmask(1)=T read gas, pmask(2)=T read halo, ...
pos  array of positions to return [ndim,npar]

Definition at line 355 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_posN ( character(*),intent(in)  snapbase,
logical,dimension(6),intent(in)  pmask,
real,dimension(:,:),intent(out)  pos 
)

Reads positions from a whole snapshot.

Parameters:
snapbase  snapfile to read
pmask  pmask(1)=T read gas, pmask(2)=T read halo, ...
pos  array of positions to return [ndim,npar]

Definition at line 292 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_vel1 ( character(*),intent(in)  snapfile,
logical,dimension(6),intent(in)  pmask,
real,dimension(:,:),intent(out)  vel 
)

Reads velocities from a single file.

Parameters:
snapfile  snapfile to read
pmask  pmask(1)=T read gas, pmask(2)=T read halo, ...
vel  array of velocities to return [ndim,npar]

Definition at line 465 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetread_velN ( character(*),intent(in)  snapbase,
logical,dimension(6),intent(in)  pmask,
real,dimension(:,:),intent(out)  vel 
)

Reads velocities from a whole snapshot.

Parameters:
snapbase  snapfile to read
pmask  pmask(1)=T read gas, pmask(2)=T read halo, ...
vel  array of velocities to return [ndim,npar]

Definition at line 402 of file gadget_io.f90.

subroutine gadget_io_mod::gadgetwrite_header ( type(gadget_header_type),intent(in)  ghead,
integer,intent(in)  lun 
)

Writes out gadget header data. if lun = -1 then it goes to the screen, otherwise puts it in the file associated with lun.

Parameters:
ghead  gadget header to write
lun  lun for IO. if lun=-1 output goes to screen

Definition at line 1382 of file gadget_io.f90.


Variable Documentation

integer(i4b),parameter gadget_io_mod::blank = (256 - (25*4+12*8))/4

blank space left after header variables

Definition at line 56 of file gadget_io.f90.

real(r8b),parameter gadget_io_mod::GEnrg = GMass * GVel**2

default Gadget energy unit [ergs/h]

Definition at line 53 of file gadget_io.f90.

real(r8b),parameter gadget_io_mod::GLen = 3.085678d21

default Gadget length unit [cm/h]

Definition at line 46 of file gadget_io.f90.

real(r8b),parameter gadget_io_mod::GMass = 1.989d43

default Gadget mass unit [g/h]

Definition at line 47 of file gadget_io.f90.

real(r8b),parameter gadget_io_mod::GPres = GMass / GLen / GTime**2

default Gadget pressure unit [cgs*h^2]

Definition at line 52 of file gadget_io.f90.

real(r8b),parameter gadget_io_mod::GRho = GMass / GLen**3

default Gadget density unit [cgs*h^2]

Definition at line 51 of file gadget_io.f90.

real(r8b),parameter gadget_io_mod::GTime = GLen / GVel

default Gadget time unit [s/h]

Definition at line 50 of file gadget_io.f90.

real(r8b),parameter gadget_io_mod::GVel = 1.0d5

default Gadget velocity unit [cm/s]

Definition at line 48 of file gadget_io.f90.

integer,parameter gadget_io_mod::i4b = selected_int_kind(9)

4 byte integer type

Definition at line 41 of file gadget_io.f90.

character(5),dimension(6),parameter gadget_io_mod::parnames = (/,,,,,/)

particle type names

Definition at line 43 of file gadget_io.f90.

integer,parameter gadget_io_mod::r4b = selected_real_kind(6,37)

4 byte real type

Definition at line 39 of file gadget_io.f90.

integer,parameter gadget_io_mod::r8b = selected_real_kind(15,307)

8 byte real type

Definition at line 40 of file gadget_io.f90.


Generated on Sun Mar 8 20:23:08 2009 for Fortran 90 Gadget-2 IO Tools by  doxygen 1.5.5