repo migration

This commit is contained in:
2006-09-11 20:19:10 +00:00
commit 41511462f9
167 changed files with 64535 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
# tools level Makefile.am
# PATH SETTING
HDF5ROOT = @HDF5ROOT@
# COMPILER SETTING
CXX = @CXX@
TOOLS_CXX = @TOOLS_CXX@
# COMPILER FLAG SETTING
CFLAGS = @CFLAGS@
# # -L$(HDF5ROOT)/lib -lhdf5
# LIBRARIES
SZLIB = @SZLIB@
HDFLIB = @TOOLS_HDFLIB@ -lz $(SZLIB)
LIBS = $(HDFLIB) $(MPILIB) -lm @STDCXX@ @LDFLAGS@
# H5Part compiled library location
# H5PLIB = -L@prefix@/lib
H5PLIB = -L@H5P_LIB_LOC@ @TOOLS_H5PART_LIB@
# INCLUDES
HDFINC = -I$(HDF5ROOT)/include
INC = $(HDFINC) $(H5PINC)
# H5Part header file location
# H5PINC = -I@prefix@/include
H5PINC = -I@H5P_LIB_LOC@
# What to build... make install will place these files in the $(prefix)/bin directory.
bin_PROGRAMS = @BUILD_TOOLS@
# Listing of all programs that maybe built. (Has to know statically...)
EXTRA_PROGRAMS = h5pAttrib h5pToGNUplot
# Extra files that I wish to include in the dist tar ball.
EXTRA_DIST = h5pAttrib.cc h5pToGNUplot.cc## TO BE TAILORED LATER...
# Listing of sources
h5pAttrib_SOURCES = h5pAttrib.cc
h5pToGNUplot_SOURCES = h5pToGNUplot.cc
# Specific building instruction (What compilers to use...)
# ------------ Build Tools ------------
h5pAttrib: h5pAttrib.o
$(TOOLS_CXX) -o h5pAttrib h5pAttrib.o $(H5PLIB) $(LIBS)
h5pAttrib.o: h5pAttrib.cc
$(TOOLS_CXX) $(CFLAGS) $(INC) -g -c h5pAttrib.cc
h5pToGNUplot: h5pToGNUplot.o
$(TOOLS_CXX) -o h5pToGNUplot h5pToGNUplot.o $(H5PLIB) $(LIBS)
h5pToGNUplot.o: h5pToGNUplot.cc
$(TOOLS_CXX) $(CFLAGS) $(INC) -g -c h5pToGNUplot.cc
clean:
rm -f *~ *.o h5pAttrib h5pToGNUplot
distclean: clean
rm -rf .deps
rm -rf Makefile
# # bash-3.00$ /usr/bin/mpcc_r -g -O2 -I/scratch/scratchdirs/cristina/hdf5/hdf5_par/include -I/u2/antino/trunk/src -c h5pAttrib.cc
# # bash-3.00$ /usr/bin/mpcc_r -o h5pAttrib h5pAttrib.o -L/u2/antino/trunk/src -lpH5Part -L/scratch/scratchdirs/cristina/hdf5/hdf5_par/lib -lhdf5 -lz -lm
#####################################################################################################################
+356
View File
@@ -0,0 +1,356 @@
TABLE OF CONTENTS
--------------------
[1] Quick Guide
--- For h5pAttrib
[2] To see number of timesteps in a h5part file
[3] To see file attributes in a h5part file
[4] To see step attributes in a h5part file
[5] To see dataset in a h5part file
[6] Providing more than one flag at once for h5pAttrib
--- For h5pToGNUplot
[7] What parameters to provide
[8] How to create an input file to GNUplot
************************************************************************************************
[1] Quick Guide
------------------
--> -h option will display a concise help page.
$>> ./h5pAttrib -h
usage: h5pAttrib [OPTIONS] file
OPTIONS
-h, --help Print help page
-n, --nstep Print number of steps
-A, --fileA Print file attributes
-a, --stepA Print step attributes & values for time step n
-d, --dataset Print data sets names & values for time step n
-H, --header Print shorter version without the values
Examples:
1) Show file attribute names & values of sample.h5part
h5pAttrib -A sample.h5part
2) Show step attribute names for time step 5 of sample.h5part
h5pAttrib -a 5 -H sample.h5part
$>> ./h5pToGNUplot -h
usage: h5pToGNUplot -t TIMESTEP -1 VARIABLE#1 -2 VARIABLE#2 -i INPUTFILE [OPTIONAL_FLAGS]
FLAGS
-h, --help Print help page
-1, --1var (REQUIRED) Takes first variable parameter
-2, --2var (REQUIRED) Takes second variable parameter
-i, --input (REQUIRED) Takes input file name
-t, --timestep (REQUIRED) Sets the timestep (Value -1 will result in dumping values of all timesteps.)
-o, --output (OPTIONAL) Takes output file name (without this flag, the program will print to stdout)
-n, --number (OPTIONAL) Sets number of output points
-s, --start (OPTIONAL) Sets the starting particle index
Examples:
1) Create GNU plot file output.txt from sample.h5part by ploting x vs px for timestep 54
h5pToGNUplot -t 54 -1 x -2 px -i sample.h5part -o output.txt
2) Create GNU plot file output.txt from sample.h5part by ploting x vs px for timestep 54
using 1200 points from particle index 76
h5pToGNUplot -t 54 -1 x -2 px -i sample.h5part -o output.txt -s 76 -n 1200
************************************************************************************************
--- For h5pAttrib
************************************************************************************************
[2] To see number of timesteps in a h5part file
--------------------------------------------------
EXAMPLE>>
$>> ./h5pAttrib -n sample.h5part
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Printing number of timesteps for: sample.h5part ...
There are total 252 number of timesteps.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
done
[3] To see file attributes in a h5part file
----------------------------------------------
EXAMPLE>>
$>> ./h5pAttrib -A sample.h5part
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Printing file attributes for: sample.h5part ...
The number of file attributes for file sample.h5part is 0 ...
There are no file attributes.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
done
NOTE: -H option will omit the list of values of file attributes.
[4] To see step attributes in a h5part file
----------------------------------------------
EXAMPLE>>
$>> ./h5pAttrib -a 2 sample.h5part
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Printing step attributes for: sample.h5part ...
The number of step attributes for timestep #2 is 10 ...
Attribute #0 = Step
There are 1 elements in the attribute
Attribute Type is H5T_NATIVE_INT64
Printing 1 element value(s):
COUNT[0]: 2
Attribute #1 = Spos
There are 1 elements in the attribute
Attribute Type is H5T_NATIVE_DOUBLE
Printing 1 element value(s):
COUNT[0]: 0.143580
Attribute #2 = structLen
There are 1 elements in the attribute
Attribute Type is H5T_NATIVE_DOUBLE
Printing 1 element value(s):
COUNT[0]: 2.393000
.
.
.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
done
NOTE: -H option will omit the list of values of step attributes.
[5] To see dataset in a h5part file
--------------------------------------
EXAMPLE>>
$>> ./h5pAttrib -d 2 -H sample.h5part
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Printing names of datasets for: sample.h5part ...
The number of datasets for timestep #2 is 7 ...
Dataset Name #0 = id
Dataset Type is H5T_NATIVE_INT64
Number of elements: 67587
Dataset Name #1 = px
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 67587
Dataset Name #2 = py
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 67587
Dataset Name #3 = pz
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 67587
Dataset Name #4 = x
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 67587
Dataset Name #5 = y
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 67587
Dataset Name #6 = z
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 67587
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
done
NOTE: -H option will omit the list of values of dataset attributes.
[6] Providing more than one flag at once
-------------------------------------------
When more than one flags are provided, one result after another will be displayed.
EXAMPLE>>
$>> ./h5pAttrib -H -a 1 -d 1 sample.h5part
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Printing step attributes for: sample.h5part ...
The number of step attributes for timestep #1 is 10 ...
Attribute #0 = Step
Attribute #1 = Spos
Attribute #2 = structLen
Attribute #3 = org
Attribute #4 = maxX
Attribute #5 = minX
Attribute #6 = maxP
Attribute #7 = minP
Attribute #8 = centroid
Attribute #9 = nloc
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Printing names of datasets for: sample.h5part ...
The number of datasets for timestep #1 is 7 ...
Dataset Name #0 = id
Dataset Type is H5T_NATIVE_INT64
Number of elements: 60214
Dataset Name #1 = px
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 60214
Dataset Name #2 = py
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 60214
Dataset Name #3 = pz
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 60214
Dataset Name #4 = x
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 60214
Dataset Name #5 = y
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 60214
Dataset Name #6 = z
Dataset Type is H5T_NATIVE_DOUBLE
Number of elements: 60214
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
done
************************************************************************************************
--- For h5pAttrib
************************************************************************************************
[7] What parameters to provide
---------------------------------
When you execute the program with -h option, it displays what flags are necessary and what flags
are optional.
-h, --help Print help page
-1, --1var (REQUIRED) Takes first variable parameter
-2, --2var (REQUIRED) Takes second variable parameter
-i, --input (REQUIRED) Takes input file name
-t, --timestep (REQUIRED) Sets the timestep (Value -1 will result in dumping values of all timesteps.)
-o, --output (OPTIONAL) Takes output file name (without this flag, the program will print to stdout)
-n, --number (OPTIONAL) Sets number of output points
-s, --start (OPTIONAL) Sets the starting particle index
[8] How to create an input file to GNUplot
---------------------------------------------
EXAMPLE>>
Create input file to GNUplot that plots x vs. y.
$>> ./h5pToGNUplot -1 x -2 y -t 1 -i sample.h5part -o output.txt
$>> cat output.txt
-0.390779 -0.254793
-0.396527 -0.252781
-0.375362 -0.285137
-0.396527 -0.252781
-0.379917 -0.283147
-0.390779 -0.254793
-0.387536 -0.287346
-0.371787 -0.319797
-0.379917 -0.283147
-0.378967 -0.326058
-0.378976 -0.326078
-0.387536 -0.287346
-0.378957 -0.326069
-0.379917 -0.283147
-0.388762 -0.265390
-0.371787 -0.319797
-0.390779 -0.254793
-0.376825 -0.266804
-0.379917 -0.283147
-0.375362 -0.285137
...
Then run GNUplot...
$>> gnuplot
G N U P L O T
Version 4.0 patchlevel 0
last modified Thu Apr 15 14:44:22 CEST 2004
System: Linux 2.6.11.4-21.11-smp
Copyright (C) 1986 - 1993, 1998, 2004
Thomas Williams, Colin Kelley and many others
This is gnuplot version 4.0. Please refer to the documentation
for command syntax changes. The old syntax will be accepted
throughout the 4.0 series, but all save files use the new syntax.
Type `help` to access the on-line reference manual.
The gnuplot FAQ is available from
http://www.gnuplot.info/faq/
Send comments and requests for help to
<gnuplot-info@lists.sourceforge.net>
Send bugs, suggestions and mods to
<gnuplot-bugs@lists.sourceforge.net>
Terminal type set to 'x11'
gnuplot> plot "output.txt"
This will open a GNUplot window that plots output.txt.
+1259
View File
File diff suppressed because it is too large Load Diff
+461
View File
@@ -0,0 +1,461 @@
/* h5pToGNUplot.cc
Antino Kim
This utility will output a GNU Plot input file accodring to the flags provided from the command line.
The parser was imported from the example of h5dump utility with slight modifications.
*/
#include <stdio.h>
#include <stdlib.h>
#include <cctype>
#include <string.h>
#include <hdf5.h>
#include "H5Part.hh"
#define MAX_LEN 100
/* Function headers */
int get_option(int argc, const char **argv, const char *opts, const struct long_options *l_opts);
static void print_help();
static void variable_assign(int argc, const char *argv[]);
/* Global variables */
static char* var_1 = NULL;
static char* var_2 = NULL;
static char* input_name = NULL;
static char* output_name = NULL;
static char* timestep = NULL;
static char* start = NULL;
static char* npoints = NULL;
static int print_all = 0;
/* `get_option' variables */
int opt_err = 1; /*get_option prints errors if this is on */
int opt_ind = 1; /*token pointer */
const char *opt_arg = NULL; /*flag argument (or value) */
/* indication whether the flag (option) requires an argument or not */
enum {
no_arg = 0, /* doesn't take an argument */
require_arg, /* requires an argument */
};
/* struct for flags (options) */
typedef struct long_options
{
const char *name; /* name of the long option */
int has_arg; /* whether we should look for an arg */
char shortval; /* the shortname equivalent of long arg
* this gets returned from get_option */
} long_options;
/* List of options in single characters */
static const char *s_opts = "h1:2:i:o:n:t:s:";
/* List of options in full words */
static struct long_options l_opts[] =
{
{ "help", no_arg, 'h' }, // Print help page
{ "1var", require_arg, '1' }, // Takes first variable parameter
{ "2var", require_arg, '2' }, // Takes second variable parameter
{ "input", require_arg, 'i' }, // Takes input file name
{ "output", require_arg, 'o' }, // Takes output file name (without this flag, the program will print to stdout)
{ "number", require_arg, 'n' }, // Sets number of output points
{ "start", require_arg, 's' }, // Sets the starting particle index
{ "timestep", require_arg, 't' }, // Sets the timestep
{ NULL, 0, '\0' }
};
/************************************************************************************
*********************************** FUNCTIONS *************************************
*************************************************************************************/
/* get_option is the parsing function that was majorly ported from h5dump utility */
int get_option(int argc, const char **argv, const char *opts, const struct long_options *l_opts)
{
static int sp = 1; /* character index in current token */
int opt_opt = '?'; /* option character passed back to user */
if (sp == 1)
{
/* check for more flag-like tokens */
if (opt_ind >= argc || argv[opt_ind][0] != '-' || argv[opt_ind][1] == '\0')
{
return EOF;
}
else if (strcmp(argv[opt_ind], "--") == 0)
{
opt_ind++;
return EOF;
}
}
if (sp == 1 && argv[opt_ind][0] == '-' && argv[opt_ind][1] == '-')
{
/* long command line option */
const char *arg = &argv[opt_ind][2];
int i;
for (i = 0; l_opts && l_opts[i].name; i++)
{
size_t len = strlen(l_opts[i].name);
if (strncmp(arg, l_opts[i].name, len) == 0)
{
/* we've found a matching long command line flag */
opt_opt = l_opts[i].shortval;
if (l_opts[i].has_arg != no_arg)
{
if (arg[len] == '=')
{
opt_arg = &arg[len + 1];
}
else if (opt_ind < (argc - 1) && argv[opt_ind + 1][0] != '-')
{
opt_arg = argv[++opt_ind];
}
else if (l_opts[i].has_arg == require_arg)
{
if (opt_err)
fprintf(stderr, "%s: option required for \"--%s\" flag\n", argv[0], arg);
opt_opt = '?';
}
}
else
{
if (arg[len] == '=')
{
if (opt_err)
fprintf(stderr, "%s: no option required for \"%s\" flag\n", argv[0], arg);
opt_opt = '?';
}
opt_arg = NULL;
}
break;
}
}
if (l_opts[i].name == NULL)
{
/* exhausted all of the l_opts we have and still didn't match */
if (opt_err)
fprintf(stderr, "%s: unknown option \"%s\"\n", argv[0], arg);
opt_opt = '?';
}
opt_ind++;
sp = 1;
}
else
{
register char *cp; /* pointer into current token */
/* short command line option */
opt_opt = argv[opt_ind][sp];
if (opt_opt == ':' || (cp = strchr(opts, opt_opt)) == 0)
{
if (opt_err)
fprintf(stderr, "%s: unknown option \"%c\"\n", argv[0], opt_opt);
/* if no chars left in this token, move to next token */
if (argv[opt_ind][++sp] == '\0')
{
opt_ind++;
sp = 1;
}
return '?';
}
if (*++cp == ':')
{
/* if a value is expected, get it */
if (argv[opt_ind][sp + 1] != '\0')
{
/* flag value is rest of current token */
opt_arg = &argv[opt_ind++][sp + 1];
}
else if (++opt_ind >= argc)
{
if (opt_err)
{
fprintf(stderr, "%s: value expected for option \"%c\"\n", argv[0], opt_opt);
}
opt_opt = '?';
}
else
{
/* flag value is next token */
opt_arg = argv[opt_ind++];
}
sp = 1;
}
else
{
/* set up to look at next char in token, next time */
if (argv[opt_ind][++sp] == '\0')
{
/* no more in current token, so setup next token */
opt_ind++;
sp = 1;
}
opt_arg = NULL;
}
}
/* return the current flag character found */
return opt_opt;
}
/* Assigns functions according to the parsed result */
static void variable_assign(int argc, const char *argv[])
{
int option;
/* set options according to the command line */
while ((option = get_option(argc, argv, s_opts, l_opts)) != EOF)
{
switch ((char)option)
{
case 'h': // Print help page
print_help();
exit(1);
case '1': // Print file attributes
var_1 = strdup(opt_arg);
break;
case '2': // Print step attributes & values for time step n
var_2 = strdup(opt_arg);
break;
case 'i': // Print data sets names & values for time step n
input_name = strdup(opt_arg);
break;
case 'o': // Print number of steps
output_name = strdup(opt_arg);
break;
case 'n': // Print shorter version without the values
npoints = strdup(opt_arg);
break;
case 's': // Print shorter version without the values
start = strdup(opt_arg);
break;
case 't': // Print shorter version without the values
timestep = strdup(opt_arg);
if(atoi(timestep)==-1)
{
print_all = 1;
}
break;
default:
print_help();
exit(1);
}
}
}
/* For printing help page */
static void print_help()
{
fflush(stdout);
fprintf(stdout, "\nusage: h5pToGNUplot -t TIMESTEP -1 VARIABLE#1 -2 VARIABLE#2 -i INPUTFILE [OPTIONAL_FLAGS]\n");
fprintf(stdout, "\n");
fprintf(stdout, " FLAGS\n");
fprintf(stdout, " -h, --help Print help page\n");
fprintf(stdout, " -1 par, --1var par (REQUIRED) Takes first variable parameter to \"par\"\n");
fprintf(stdout, " -2 par, --2var par (REQUIRED) Takes second variable parameter to \"par\"\n");
fprintf(stdout, " -i file, --input file (REQUIRED) Takes input file name to \"file\"\n");
fprintf(stdout, " -t step, --timestep step (REQUIRED) Sets the timestep to \"step\" (Value -1 will result in dumping values of all timesteps.)\n");
fprintf(stdout, " -o file, --output file (OPTIONAL) Takes output file name to \"file\" (without this flag, the program will print to stdout)\n");
fprintf(stdout, " -n num, --number num (OPTIONAL) Sets number of output points to \"num\"\n");
fprintf(stdout, " -s idx, --start idx (OPTIONAL) Sets the starting particle index to \"idx\"\n");
fprintf(stdout, "\n");
fprintf(stdout, " Examples:\n");
fprintf(stdout, "\n");
fprintf(stdout, " 1) Create GNU plot file output.txt from sample.h5part by ploting x vs px for timestep 54\n");
fprintf(stdout, "\n");
fprintf(stdout, " h5pToGNUplot -t 54 -1 x -2 px -i sample.h5part -o output.txt\n");
fprintf(stdout, "\n");
fprintf(stdout, " 2) Create GNU plot file output.txt from sample.h5part by ploting x vs px for timestep 54 \n using 1200 points from particle index 76\n");
fprintf(stdout, "\n");
fprintf(stdout, " h5pToGNUplot -t 54 -1 x -2 px -i sample.h5part -o output.txt -s 76 -n 1200\n");
fprintf(stdout, "\n");
}
int main(int argc, const char *argv[])
{
/* Numerous variables */
H5PartFile *h5file = NULL;
char data_name[MAX_LEN];
int i, j, start_indx = 0;
h5part_int64_t type;
hid_t type_1;
hid_t type_2;
int num_dataset;
h5part_int64_t nparticles;
int stop = 0;
void* value_1 = NULL;
void* value_2 = NULL;
FILE * outFile;
int ntime_step = 0;
variable_assign(argc, argv);
if(input_name == NULL)
{
fprintf(stdout, "missing file name\n");
print_help();
exit(1);
}
if(var_1 == NULL || var_2 == NULL || timestep == NULL)
{
fprintf(stdout, "missing required parameters\n");
print_help();
exit(1);
}
h5file = H5PartOpenFile(input_name, H5PART_READ);
if( h5file == NULL )
{
fprintf(stdout, "unable to open file %s\n", input_name);
print_help();
exit(1);
}
j = atoi(timestep);
ntime_step = j+1;
if(print_all)
{
j=0;
ntime_step = H5PartGetNumSteps(h5file);
}
for (; j<ntime_step; j++)
{
H5PartSetStep(h5file,j);
num_dataset = H5PartGetNumDatasets(h5file);
for(i=0; i<num_dataset; i++)
{
H5PartGetDatasetInfo(h5file, i, data_name, MAX_LEN, &type, &nparticles);
if(strcmp(data_name, var_1))
{
type_1=type;
}
if(strcmp(data_name, var_2))
{
type_2=type;
}
}
if (type_1 == H5T_NATIVE_INT64)
{
value_1 = (h5part_int64_t*)malloc(sizeof(h5part_int64_t)*nparticles);
H5PartReadDataInt64(h5file, var_1, (h5part_int64_t*)value_1);
}
else if (type_1 == H5T_NATIVE_DOUBLE)
{
value_1 = (double*)malloc(sizeof(double)*nparticles);
H5PartReadDataFloat64(h5file, var_1, (double*)value_1);
}
else
{
fprintf(stdout, "Dataset Type is UNKNOWN for %s. (Check the variable name.)\n", var_1);
exit(1);
}
if (type_2 == H5T_NATIVE_INT64)
{
value_2 = (h5part_int64_t*)malloc(sizeof(h5part_int64_t)*nparticles);
H5PartReadDataInt64(h5file, var_2, (h5part_int64_t*)value_2);
}
else if (type_2 == H5T_NATIVE_DOUBLE)
{
value_2 = (double*)malloc(sizeof(double)*nparticles);
H5PartReadDataFloat64(h5file, var_2, (double*)value_2);
}
else
{
fprintf(stdout, "Dataset Type is UNKNOWN for %s. (Check the variable name.)\n", var_2);
exit(1);
}
if(start != NULL)
{
start_indx = atoi(start);
}
if(npoints != NULL)
{
stop = atoi(npoints) + start_indx;
}
else
{
stop = nparticles;
}
if(stop > nparticles)
{
stop = nparticles;
}
if(output_name != NULL)
{
outFile = fopen (output_name,"w");
for(i=start_indx; i<stop; i++)
{
if (type_1 == H5T_NATIVE_INT64)
fprintf(outFile, "%lld", ((h5part_int64_t*)value_1)[i]);
else if (type_1 == H5T_NATIVE_DOUBLE)
fprintf(outFile, "%lf", ((double*)value_1)[i]);
if (type_2 == H5T_NATIVE_INT64)
fprintf(outFile, "\t%lld", ((h5part_int64_t*)value_2)[i]);
else if (type_2 == H5T_NATIVE_DOUBLE)
fprintf(outFile, "\t%lf", ((double*)value_2)[i]);
fprintf(outFile, "\n");
}
fprintf(outFile, "\n");
fclose (outFile);
}
else
{
for(i=start_indx; i<stop; i++)
{
if (type_1 == H5T_NATIVE_INT64)
fprintf(stdout, "%lld", ((h5part_int64_t*)value_1)[i]);
else if (type_1 == H5T_NATIVE_DOUBLE)
fprintf(stdout, "%lf", ((double*)value_1)[i]);
if (type_2 == H5T_NATIVE_INT64)
fprintf(stdout, "\t%lld", ((h5part_int64_t*)value_2)[i]);
else if (type_2 == H5T_NATIVE_DOUBLE)
fprintf(stdout, "\t%lf", ((double*)value_2)[i]);
fprintf(stdout, "\n");
}
fprintf(stdout, "\n");
}
free(value_1);
free(value_2);
}
H5PartCloseFile(h5file);
return 0;
}
+142
View File
@@ -0,0 +1,142 @@
#!/usr/bin/python
import string, sys
sys.path.append('../src/')
import H5Part
from optparse import OptionParser
parser = OptionParser()
print_all=0
parser.add_option("-1", "--1var", dest="var_1",
help="(REQUIRED) Takes first variable parameter")
parser.add_option("-2", "--2var", dest="var_2",
help="(REQUIRED) Takes second variable parameter")
parser.add_option("-i", "--input", dest="input_file",
help="(REQUIRED) Takes input file name")
parser.add_option("-t", "--timestep", dest="timestep", type="int",
help="(REQUIRED) Sets the timestep (Value -1 will result in dumping values of all timesteps.)")
parser.add_option("-o", "--output", dest="output_file",
help="(OPTIONAL) Takes output file name (without this flag, the program will print to stdout)")
parser.add_option("-n", "--number", dest="nparticle", type="int",
help="(OPTIONAL) Sets number of output points")
parser.add_option("-s", "--start", dest="start", type="int",
help="(OPTIONAL) Sets the starting particle index")
(options, args) = parser.parse_args()
if options.timestep == -1:
print_all = 1
MAX_LEN = 100
stop = 0
start_indx = 0
h5file = H5Part.H5PartOpenFile(options.input_file, H5Part.H5PART_READ)
if H5Part.H5PartFileIsValid(h5file)==0 :
print "unable to open input file"
parser.print_help()
sys.exit(1)
j = options.timestep
ntime_step = j+1
if print_all == 1:
j=0
ntime_step = H5Part.H5PartGetNumSteps(h5file)
for j in range(j, ntime_step):
H5Part.H5PartSetStep(h5file,j)
num_dataset = H5Part.H5PartGetNumDatasets(h5file)
for i in range(0, num_dataset):
data_name, data_type, nparticle = H5Part.H5PartGetDatasetInfo(h5file, i, MAX_LEN)
if data_name == options.var_1:
type_1=data_type
if data_name == options.var_2:
type_2=data_type
# # # # # # # # # # # # # # # # I MUST FIND A WAY... hid_t & H5T_NATIVE_INT64 etc undefined problem... Currently treated as int...
#temp = H5Part.hid_tArray(2)
#temp[0] = H5T_NATIVE_INT64
#print temp[0]
if type_1 == 201326626: # H5Part.H5T_NATIVE_INT64:
value_1 = H5Part.longArray(nparticle)
H5Part.H5PartReadDataInt64(h5file, options.var_1, value_1)
elif type_1 == 201326635: # H5Part.H5T_NATIVE_DOUBLE:
value_1 = H5Part.doubleArray(nparticle)
H5Part.H5PartReadDataFloat64(h5file, options.var_1, value_1)
else:
print "Dataset Type is UNKNOWN for %s. (Check the variable name.)\n" % options.var_1
sys.exit(1)
if type_2 == 201326626: # H5Part.H5T_NATIVE_INT64:
value_2 = H5Part.longArray(nparticle)
H5Part.H5PartReadDataInt64(h5file, options.var_2, value_2)
elif type_2 == 201326635: # H5Part.H5T_NATIVE_DOUBLE:
value_2 = H5Part.doubleArray(nparticle)
H5Part.H5PartReadDataFloat64(h5file, options.var_2, value_2)
else:
print "Dataset Type is UNKNOWN for %s. (Check the variable name.)\n" % options.var_2
sys.exit(1)
if options.start != None:
start_indx = options.start
if options.nparticle != None:
stop = options.nparticle + start_indx
else:
stop = nparticle
if stop > nparticle:
stop = nparticle
if options.output_file != None:
outFile = open(options.output_file,"w")
for x in range(start_indx, stop):
if type_1 == 201326626: # H5Part.H5T_NATIVE_INT64:
outFile.write("%ld" % value_1[x])
elif type_1 == 201326635: # H5Part.H5T_NATIVE_DOUBLE:
outFile.write("%lf" % value_1[x])
if type_2 == 201326626: # H5Part.H5T_NATIVE_INT64:
outFile.write("\t%ld" % value_2[x])
outFile.write("\n")
elif type_2 == 201326635: # H5Part.H5T_NATIVE_DOUBLE:
outFile.write("\t%lf" % value_2[x])
outFile.write("\n")
outFile.write("\n")
outFile.close()
else:
for y in range(start_indx, stop):
if type_1 == 201326626: # H5Part.H5T_NATIVE_INT64:
print "%ld" % value_1[y],
elif type_1 == 201326635: # H5Part.H5T_NATIVE_DOUBLE:
print "%lf" % value_1[y],
if type_2 == 201326626: # H5Part.H5T_NATIVE_INT64:
print "\t%ld" % value_2[y]
elif type_2 == 201326635: # H5Part.H5T_NATIVE_DOUBLE:
print "\t%lf" % value_2[y]
print "\n"
H5Part.H5PartCloseFile(h5file)
# if __name__ == "__main__":
# print "I'M RUNNING AS A MAIN PROGRAM!!!"