Commit 5e2482a0 authored by Loikki's avatar Loikki

Check if snapshot directory exists and add a digit to the output #321

parent 81269f6a
......@@ -34,7 +34,7 @@ import sys
stats_filename = "./energy.txt"
# First snapshot
snap_filename = "coolingBox_000.hdf5"
snap_filename = "coolingBox_0000.hdf5"
# Some constants in cgs units
k_b = 1.38E-16 #boltzmann
......@@ -104,7 +104,7 @@ print "Cooling time:", cooling_time_cgs, "[s]"
u_snapshots_cgs = zeros(25)
t_snapshots_cgs = zeros(25)
for i in range(25):
snap = h5.File("coolingBox_%0.3d.hdf5"%i,'r')
snap = h5.File("coolingBox_%0.4d.hdf5"%i,'r')
u_snapshots_cgs[i] = sum(snap["/PartType0/InternalEnergy"][:] * snap["/PartType0/Masses"][:]) / total_mass[0] * unit_length**2 / (unit_time)**2
t_snapshots_cgs[i] = snap["/Header"].attrs["Time"] * unit_time
......
......@@ -20,7 +20,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "Hydrostatic_000.hdf5"
filename = "Hydrostatic_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -39,7 +39,7 @@ M_vir_cgs = r_vir_cgs * v_c_cgs**2 / CONST_G_CGS
for i in range(n_snaps):
filename = "Hydrostatic_%03d.hdf5" %i
filename = "Hydrostatic_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -38,7 +38,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "Hydrostatic_000.hdf5"
filename = "Hydrostatic_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -57,7 +57,7 @@ M_vir_cgs = r_vir_cgs * v_c_cgs**2 / CONST_G_CGS
for i in range(n_snaps):
filename = "Hydrostatic_%03d.hdf5" %i
filename = "Hydrostatic_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -17,7 +17,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "CoolingHalo_000.hdf5"
filename = "CoolingHalo_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -41,7 +41,7 @@ time_array_cgs = []
for i in range(n_snaps):
filename = "CoolingHalo_%03d.hdf5" %i
filename = "CoolingHalo_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -39,7 +39,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "CoolingHalo_000.hdf5"
filename = "CoolingHalo_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -58,7 +58,7 @@ M_vir_cgs = r_vir_cgs * v_c_cgs**2 / CONST_G_CGS
for i in range(n_snaps):
filename = "CoolingHalo_%03d.hdf5" %i
filename = "CoolingHalo_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -21,7 +21,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "CoolingHalo_000.hdf5"
filename = "CoolingHalo_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -42,7 +42,7 @@ M_vir_cgs = r_vir_cgs * v_c_cgs**2 / CONST_G_CGS
for i in range(n_snaps):
filename = "CoolingHalo_%03d.hdf5" %i
filename = "CoolingHalo_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -39,7 +39,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "CoolingHalo_000.hdf5"
filename = "CoolingHalo_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -60,7 +60,7 @@ M_vir_cgs = r_vir_cgs * v_c_cgs**2 / CONST_G_CGS
for i in range(n_snaps):
filename = "CoolingHalo_%03d.hdf5" %i
filename = "CoolingHalo_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -20,7 +20,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "CoolingHalo_000.hdf5"
filename = "CoolingHalo_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -44,7 +44,7 @@ time_array_cgs = []
for i in range(n_snaps):
filename = "CoolingHalo_%03d.hdf5" %i
filename = "CoolingHalo_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -39,7 +39,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "CoolingHalo_000.hdf5"
filename = "CoolingHalo_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -58,7 +58,7 @@ M_vir_cgs = r_vir_cgs * v_c_cgs**2 / CONST_G_CGS
for i in range(n_snaps):
filename = "CoolingHalo_%03d.hdf5" %i
filename = "CoolingHalo_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -34,7 +34,7 @@ import sys
stats_filename = "./energy.txt"
# First snapshot
snap_filename = "pointMass_000.hdf5"
snap_filename = "pointMass_0000.hdf5"
f = h5.File(snap_filename,'r')
# Read the units parameters from the snapshot
......@@ -71,7 +71,7 @@ Lz_snap = np.zeros(402)
# Read all the particles from the snapshots
for i in range(402):
snap_filename = "pointMass_%0.3d.hdf5"%i
snap_filename = "pointMass_%0.4d.hdf5"%i
f = h5.File(snap_filename,'r')
pos_x = f["PartType1/Coordinates"][:,0]
......
......@@ -2,12 +2,12 @@
python makeICs.py stretched
../swift -s -t 2 gradientsStretched.yml
python plot.py gradients_stretched_001.hdf5 stretched
python plot.py gradients_stretched_0001.hdf5 stretched
python makeICs.py cartesian
../swift -s -t 2 gradientsCartesian.yml
python plot.py gradients_cartesian_001.hdf5 cartesian
python plot.py gradients_cartesian_0001.hdf5 cartesian
python makeICs.py random
../swift -s -t 2 gradientsRandom.yml
python plot.py gradients_random_001.hdf5 random
python plot.py gradients_random_0001.hdf5 random
......@@ -83,7 +83,7 @@ solution_s = solution_P / solution_rho**gas_gamma
solution_u = solution_P /((gas_gamma - 1.)*solution_rho)
# Read the simulation data
sim = h5py.File("gresho_%03d.hdf5"%snap, "r")
sim = h5py.File("gresho_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -42,7 +42,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "Hydrostatic_000.hdf5"
filename = "Hydrostatic_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -63,7 +63,7 @@ M_vir_cgs = r_vir_cgs * v_c_cgs**2 / CONST_G_CGS
for i in range(n_snaps):
filename = "Hydrostatic_%03d.hdf5" %i
filename = "Hydrostatic_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -60,7 +60,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "Hydrostatic_000.hdf5"
filename = "Hydrostatic_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -79,7 +79,7 @@ M_vir_cgs = r_vir_cgs * v_c_cgs**2 / CONST_G_CGS
for i in range(n_snaps):
filename = "Hydrostatic_%03d.hdf5" %i
filename = "Hydrostatic_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -38,7 +38,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "Hydrostatic_000.hdf5"
filename = "Hydrostatic_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -62,7 +62,7 @@ time_array_cgs = []
for i in range(n_snaps):
filename = "Hydrostatic_%03d.hdf5" %i
filename = "Hydrostatic_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -60,7 +60,7 @@ H_0_cgs = 100. * h * KM_PER_SEC_IN_CGS / (1.0e6 * PARSEC_IN_CGS)
#read some header/parameter information from the first snapshot
filename = "Hydrostatic_000.hdf5"
filename = "Hydrostatic_0000.hdf5"
f = h5.File(filename,'r')
params = f["Parameters"]
unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
......@@ -79,7 +79,7 @@ M_vir_cgs = r_vir_cgs * v_c_cgs**2 / CONST_G_CGS
for i in range(n_snaps):
filename = "Hydrostatic_%03d.hdf5" %i
filename = "Hydrostatic_%04d.hdf5" %i
f = h5.File(filename,'r')
coords_dset = f["PartType0/Coordinates"]
coords = np.array(coords_dset)
......
......@@ -34,7 +34,7 @@ import sys
stats_filename = "./energy.txt"
# First snapshot
snap_filename = "Isothermal_000.hdf5"
snap_filename = "Isothermal_0000.hdf5"
f = h5.File(snap_filename,'r')
# Read the units parameters from the snapshot
......@@ -70,7 +70,7 @@ Lz_snap = np.zeros(402)
# Read all the particles from the snapshots
for i in range(402):
snap_filename = "Isothermal_%0.3d.hdf5"%i
snap_filename = "Isothermal_%0.4d.hdf5"%i
f = h5.File(snap_filename,'r')
pos_x = f["PartType1/Coordinates"][:,0]
......
......@@ -63,7 +63,7 @@ rc('font',**{'family':'sans-serif','sans-serif':['Times']})
snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("kelvinHelmholtz_%03d.hdf5"%snap, "r")
sim = h5py.File("kelvinHelmholtz_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -58,7 +58,7 @@ snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("noh_%03d.hdf5"%snap, "r")
sim = h5py.File("noh_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -58,7 +58,7 @@ rc('font',**{'family':'sans-serif','sans-serif':['Times']})
snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("noh_%03d.hdf5"%snap, "r")
sim = h5py.File("noh_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -59,7 +59,7 @@ snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("noh_%03d.hdf5"%snap, "r")
sim = h5py.File("noh_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -64,7 +64,7 @@ snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("sedov_%03d.hdf5"%snap, "r")
sim = h5py.File("sedov_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -65,7 +65,7 @@ snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("sedov_%03d.hdf5"%snap, "r")
sim = h5py.File("sedov_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -65,7 +65,7 @@ snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("sedov_%03d.hdf5"%snap, "r")
sim = h5py.File("sedov_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -67,7 +67,7 @@ snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("sodShock_%03d.hdf5"%snap, "r")
sim = h5py.File("sodShock_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -68,7 +68,7 @@ snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("sodShock_%03d.hdf5"%snap, "r")
sim = h5py.File("sodShock_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -68,7 +68,7 @@ snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("sodShock_%03d.hdf5"%snap, "r")
sim = h5py.File("sodShock_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -63,7 +63,7 @@ rc('font',**{'family':'sans-serif','sans-serif':['Times']})
snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("square_%03d.hdf5"%snap, "r")
sim = h5py.File("square_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
......
......@@ -27,6 +27,7 @@
/* Some standard headers. */
#include <fenv.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -633,6 +634,21 @@ int main(int argc, char *argv[]) {
/* Initialise the particles */
engine_init_particles(&e, flag_entropy_ICs, clean_h_values);
/* Check if output directory exists */
char dir[200];
int test;
/* get output directory */
strcpy(dir, e.snapshotBaseName);
dirname(dir);
/* test if directory is current directory and update name if yes */
test = strchr(e.snapshotBaseName, '/') == NULL;
if (test) strcpy(dir, "./");
/* Check if user has write permission */
test = access(dir, W_OK);
if (-1 == test)
error("Directory %s does not exist or you do not have write permission",
dir);
/* Write the state of the system before starting time integration. */
engine_dump_snapshot(&e);
......
......@@ -667,7 +667,7 @@ void write_output_parallel(struct engine* e, const char* baseName,
/* File name */
char fileName[FILENAME_BUFFER_SIZE];
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%03i.hdf5", baseName,
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
outputCount);
/* First time, we need to create the XMF file */
......
......@@ -738,7 +738,7 @@ void write_output_serial(struct engine* e, const char* baseName,
/* File name */
char fileName[FILENAME_BUFFER_SIZE];
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%03i.hdf5", baseName,
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
outputCount);
/* Compute offset in the file and total number of particles */
......
......@@ -606,7 +606,7 @@ void write_output_single(struct engine* e, const char* baseName,
/* File name */
char fileName[FILENAME_BUFFER_SIZE];
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%03i.hdf5", baseName,
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
outputCount);
/* First time, we need to create the XMF file */
......
......@@ -135,7 +135,7 @@ void xmf_write_outputfooter(FILE* xmfFile, int output, float time) {
/* Write end of the section of this time step */
fprintf(xmfFile,
"\n</Grid> <!-- End of meta-data for output=%03i, time=%f -->\n",
"\n</Grid> <!-- End of meta-data for output=%04i, time=%f -->\n",
output, time);
fprintf(xmfFile, "\n</Grid> <!-- timeSeries -->\n");
fprintf(xmfFile, "</Domain>\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment