summaryrefslogtreecommitdiffstats
path: root/hl/tools
diff options
context:
space:
mode:
Diffstat (limited to 'hl/tools')
-rw-r--r--hl/tools/gif2h5/decompress.c23
-rw-r--r--hl/tools/gif2h5/hdf2gif.c74
-rw-r--r--hl/tools/gif2h5/hdfgifwr.c96
-rw-r--r--hl/tools/h5watch/h5watch.c70
4 files changed, 158 insertions, 105 deletions
diff --git a/hl/tools/gif2h5/decompress.c b/hl/tools/gif2h5/decompress.c
index 8cd8a8e..129fa60 100644
--- a/hl/tools/gif2h5/decompress.c
+++ b/hl/tools/gif2h5/decompress.c
@@ -57,12 +57,12 @@ GIFBYTE *Raster; /* The raster data stream, unblocked *
/* The hash table used by the decompressor */
-int Prefix[4096];
-int Suffix[4096];
+int *Prefix;
+int *Suffix;
/* An output array used by the decompressor */
-int OutCode[1025];
+int *OutCode;
/* The color map, read from the GIF header */
@@ -159,6 +159,19 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead)
{
int i;
+ if (!(Prefix = calloc(4096, sizeof(int)))) {
+ printf("Out of memory");
+ exit(EXIT_FAILURE);
+ }
+ if (!(Suffix = calloc(4096, sizeof(int)))) {
+ printf("Out of memory");
+ exit(EXIT_FAILURE);
+ }
+ if (!(OutCode = calloc(1024, sizeof(int)))) {
+ printf("Out of memory");
+ exit(EXIT_FAILURE);
+ }
+
XC = 0;
YC = 0;
Pass = 0;
@@ -309,5 +322,9 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead)
Code = ReadCode();
}
+ free(Prefix);
+ free(Suffix);
+ free(OutCode);
+
return Image;
}
diff --git a/hl/tools/gif2h5/hdf2gif.c b/hl/tools/gif2h5/hdf2gif.c
index e32facb..1833c92 100644
--- a/hl/tools/gif2h5/hdf2gif.c
+++ b/hl/tools/gif2h5/hdf2gif.c
@@ -18,8 +18,11 @@
#include "h5tools.h"
#include "h5tools_utils.h"
-#define IMAGE_WIDTH_MAX 65535 /* unsigned 16bits integer */
-#define IMAGE_HEIGHT_MAX 65535 /* unsigned 16bits integer */
+/* Name of tool */
+#define PROGRAMNAME "hdf2gif"
+
+#define IMAGE_WIDTH_MAX 65535 /* unsigned 16bits integer */
+#define IMAGE_HEIGHT_MAX 65535 /* unsigned 16bits integer */
int EndianOrder;
@@ -42,12 +45,17 @@ usage(void)
}
+static void
+leave(int ret)
+{
+ h5tools_close();
+ HDexit(ret);
+}
+
FILE *fpGif = NULL;
int main(int argc , char **argv)
{
GIFBYTE *Image;
- void *edata;
- H5E_auto2_t func;
/* compression structs */
GIFCHAR *HDFName = NULL;
@@ -73,9 +81,8 @@ int main(int argc , char **argv)
char *image_name = NULL;
int idx;
- /* Disable error reporting */
- H5Eget_auto2(H5E_DEFAULT, &func, &edata);
- H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
+ h5tools_setprogname(PROGRAMNAME);
+ h5tools_setstatus(EXIT_SUCCESS);
/* Initialize h5tools lib */
h5tools_init();
@@ -83,8 +90,7 @@ int main(int argc , char **argv)
if ( argv[1] && (strcmp("-V",argv[1])==0) )
{
print_version("gif2h5");
- exit(EXIT_SUCCESS);
-
+ h5tools_setstatus(EXIT_SUCCESS);
}
@@ -92,7 +98,7 @@ int main(int argc , char **argv)
{
/* they didn't supply at least one image -- bail */
usage();
- return EXIT_FAILURE;
+ h5tools_setstatus(EXIT_FAILURE);
}
HDFName = argv[1];
@@ -149,30 +155,41 @@ int main(int argc , char **argv)
goto out;
}
- /* read image */
+ /* get image's information */
if ( H5IMget_image_info( fid, image_name, &width, &height, &planes, interlace, &npals ) < 0 )
+ {
+ fprintf(stderr , "Unable to get information of the image. Aborting.\n");
goto out;
+ }
- if (width > IMAGE_WIDTH_MAX || height > IMAGE_HEIGHT_MAX){
- fprintf(stderr, "HDF5 image is too large. Limit is %d by %d.\n", IMAGE_WIDTH_MAX, IMAGE_HEIGHT_MAX);
- goto out;
- }
+ if (width > IMAGE_WIDTH_MAX || height > IMAGE_HEIGHT_MAX)
+ {
+ fprintf(stderr, "HDF5 image is too large. Limit is %d by %d.\n", IMAGE_WIDTH_MAX, IMAGE_HEIGHT_MAX);
+ goto out;
+ }
- /* tool can handle single plane images only. */
- if (planes > 1){
- fprintf(stderr, "Cannot handle multiple planes image\n");
- goto out;
- }
+ /* tool can handle single plane images only. */
+ if (planes > 1)
+ {
+ fprintf(stderr, "Cannot handle multiple planes image\n");
+ goto out;
+ }
Image = (GIFBYTE*) malloc( (size_t) width * (size_t) height );
if ( H5IMread_image( fid, image_name, Image ) < 0 )
+ {
+ fprintf(stderr , "Unable to read the image. Aborting.\n");
goto out;
+ }
if (npals)
{
if ( H5IMget_palette_info( fid, image_name, 0, pal_dims ) < 0 )
+ {
+ fprintf(stderr , "Unable to get information of the palette. Aborting.\n");
goto out;
+ }
pal = (GIFBYTE*) malloc( (size_t) pal_dims[0] * (size_t) pal_dims[1] );
@@ -211,9 +228,9 @@ int main(int argc , char **argv)
numcols = 256;
for (i = 0 ; i < numcols ; i++)
{
- Red[i] = (GIFBYTE)(255 - i);
- Green[i] = (GIFBYTE)(255 - i);
- Blue[i] = (GIFBYTE)(255 - i);
+ Red[i] = (GIFBYTE)(255 - i);
+ Green[i] = (GIFBYTE)(255 - i);
+ Blue[i] = (GIFBYTE)(255 - i);
}
}
else
@@ -246,7 +263,7 @@ int main(int argc , char **argv)
if (j==i)
{
/* wasn't found */
- pc2nc[i] = (GIFBYTE)nc;
+ pc2nc[i] = (GIFBYTE)nc;
r1[nc] = Red[i];
g1[nc] = Green[i];
b1[nc] = Blue[i];
@@ -334,9 +351,7 @@ int main(int argc , char **argv)
if (image_name != NULL)
free(image_name);
- H5Eset_auto2(H5E_DEFAULT, func, edata);
-
- return EXIT_SUCCESS;
+ leave(h5tools_getstatus());
out:
@@ -346,7 +361,6 @@ out:
if (image_name != NULL)
free(image_name);
- H5Eset_auto2(H5E_DEFAULT, func, edata);
-
- return EXIT_FAILURE;
+ h5tools_setstatus(EXIT_FAILURE);
+ leave(h5tools_getstatus());
}
diff --git a/hl/tools/gif2h5/hdfgifwr.c b/hl/tools/gif2h5/hdfgifwr.c
index ed3e9e9..d44ff7a 100644
--- a/hl/tools/gif2h5/hdfgifwr.c
+++ b/hl/tools/gif2h5/hdfgifwr.c
@@ -69,45 +69,6 @@ static void char_init(), char_out(), flush_char();
static byte pc2nc[256];
-/*************************************************************/
-int hdfWriteGIF(FILE *fp, byte *pic, int ptype, int w, int h, byte *rmap,
- byte *gmap, byte *bmap, byte *pc2ncmap, int numcols,
- int colorstyle, int BitsPerPixel)
-{
- int InitCodeSize;
- int i;
- byte *pic8 = pic;
-
- /* Shut compiler up... */
- ptype=ptype;
- rmap=rmap;
- gmap=gmap;
- bmap=bmap;
- numcols=numcols;
- colorstyle=colorstyle;
-
- for (i = 0; i < 256; i++) {
- pc2nc[i] = pc2ncmap[i];
- }
-
- if (BitsPerPixel <= 1)
- InitCodeSize = 2;
- else
- InitCodeSize = BitsPerPixel;
-
- if (!fp) {
- fprintf(stderr, "WriteGIF: file not open for writing\n" );
- return (1);
- }
-
- compress(InitCodeSize+1, fp, pic8, w*h);
-
- if (ferror(fp))
- return -1;
-
- return 0 ;
-}
-
/***********************************************************************/
static unsigned long cur_accum = 0;
static int cur_bits = 0;
@@ -123,8 +84,8 @@ static int maxbits = XV_BITS; /* user settable max # bits/code */
static int maxcode; /* maximum code, given n_bits */
static int maxmaxcode = 1 << XV_BITS; /* NEVER generate this */
-static count_int htab [HSIZE];
-static unsigned short codetab [HSIZE];
+static count_int *htab;
+static unsigned short *codetab;
#define HashTabOf(i) htab[i]
#define CodeTabOf(i) codetab[i]
@@ -173,6 +134,57 @@ static FILE *g_outfile;
static int ClearCode;
static int EOFCode;
+/*************************************************************/
+int hdfWriteGIF(FILE *fp, byte *pic, int ptype, int w, int h, byte *rmap,
+ byte *gmap, byte *bmap, byte *pc2ncmap, int numcols,
+ int colorstyle, int BitsPerPixel)
+{
+ int InitCodeSize;
+ int i;
+ byte *pic8 = pic;
+
+ if (!(htab = calloc(HSIZE, sizeof(count_int)))) {
+ fprintf(stderr, "Out of memory");
+ return 1;
+ }
+ if (!(codetab = calloc(HSIZE, sizeof(unsigned short)))) {
+ fprintf(stderr, "Out of memory");
+ return 1;
+ }
+
+ /* Shut compiler up... */
+ ptype=ptype;
+ rmap=rmap;
+ gmap=gmap;
+ bmap=bmap;
+ numcols=numcols;
+ colorstyle=colorstyle;
+
+ for (i = 0; i < 256; i++) {
+ pc2nc[i] = pc2ncmap[i];
+ }
+
+ if (BitsPerPixel <= 1)
+ InitCodeSize = 2;
+ else
+ InitCodeSize = BitsPerPixel;
+
+ if (!fp) {
+ fprintf(stderr, "WriteGIF: file not open for writing\n");
+ return 1;
+ }
+
+ compress(InitCodeSize+1, fp, pic8, w*h);
+
+ free(htab);
+ free(codetab);
+
+ if (ferror(fp))
+ return -1;
+
+ return 0 ;
+}
+
/********************************************************/
static void compress(int init_bits, FILE *outfile, byte *data, int len)
{
@@ -194,8 +206,6 @@ static void compress(int init_bits, FILE *outfile, byte *data, int len)
/* initialize 'compress' globals */
maxbits = XV_BITS;
maxmaxcode = 1<<XV_BITS;
- memset(htab, 0, sizeof(htab));
- memset(codetab, 0, sizeof(codetab));
hsize = HSIZE;
free_ent = 0;
clear_flg = 0;
diff --git a/hl/tools/h5watch/h5watch.c b/hl/tools/h5watch/h5watch.c
index b7f583c..a05c63b 100644
--- a/hl/tools/h5watch/h5watch.c
+++ b/hl/tools/h5watch/h5watch.c
@@ -821,8 +821,6 @@ main(int argc, const char *argv[])
char drivername[50]; /* VFD name */
char *fname = NULL; /* File name */
char *dname = NULL; /* Dataset name */
- void *edata; /* Error reporting */
- H5E_auto2_t func; /* Error reporting */
char *x; /* Temporary string pointer */
hid_t fid = -1; /* File ID */
hid_t fapl = -1; /* File access property list */
@@ -831,10 +829,6 @@ main(int argc, const char *argv[])
h5tools_setprogname(PROGRAMNAME);
h5tools_setstatus(EXIT_SUCCESS);
- /* Disable error reporting */
- H5Eget_auto2(H5E_DEFAULT, &func, &edata);
- H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
-
/* Initialize h5tools lib */
h5tools_init();
@@ -859,6 +853,9 @@ main(int argc, const char *argv[])
leave(EXIT_FAILURE);
}
+ /* enable error reporting if command line option */
+ h5tools_error_report();
+
/* Mostly copied from tools/h5ls coding & modified accordingly */
/*
* [OBJECT] is specified as
@@ -875,22 +872,26 @@ main(int argc, const char *argv[])
* doesn't exist).
*/
if((fname = HDstrdup(argv[opt_ind])) == NULL) {
- error_msg("memory allocation failed (file %s:line %d)\n",
- __FILE__, __LINE__);
+ error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__);
h5tools_setstatus(EXIT_FAILURE);
+ goto done;
}
/* Create a copy of file access property list */
- if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
- return -1;
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
+ }
/* Set to use the latest library format */
- if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
- return -1;
+ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) {
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
+ }
do {
while(fname && *fname) {
- fid = h5tools_fopen(fname, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl, NULL, drivername, sizeof drivername);
+ fid = h5tools_fopen(fname, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl, FALSE, drivername, sizeof drivername);
if(fid >= 0) {
HDfprintf(stdout, "Opened \"%s\" with %s driver.\n", fname, drivername);
@@ -911,30 +912,37 @@ main(int argc, const char *argv[])
if(fid < 0) {
error_msg("unable to open file \"%s\"\n", fname);
- if(fname) HDfree(fname);
- if(fapl >= 0) H5Pclose(fapl);
- leave(EXIT_FAILURE);
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
}
if(!dname) {
error_msg("no dataset specified\n");
h5tools_setstatus(EXIT_FAILURE);
- } else {
+ goto done;
+ }
+ else {
*dname = '/';
x = dname;
if((dname = HDstrdup(dname)) == NULL) {
- error_msg("memory allocation failed (file %s:line %d)\n",
- __FILE__, __LINE__);
+ error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__);
h5tools_setstatus(EXIT_FAILURE);
- } else {
+ goto done;
+ }
+ else {
*x = '\0';
/* Validate dataset */
- if(check_dataset(fid, dname) < 0)
+ if(check_dataset(fid, dname) < 0) {
h5tools_setstatus(EXIT_FAILURE);
+ goto done;
+ }
/* Validate input "fields" */
- else if(g_list_of_fields && *g_list_of_fields)
- if(process_cmpd_fields(fid, dname) < 0)
+ else if(g_list_of_fields && *g_list_of_fields) {
+ if(process_cmpd_fields(fid, dname) < 0) {
h5tools_setstatus(EXIT_FAILURE);
+ goto done;
+ }
+ }
}
}
@@ -943,15 +951,20 @@ main(int argc, const char *argv[])
if(monitor_dataset(fid, dname) < 0)
h5tools_setstatus(EXIT_FAILURE);
+done:
/* Free spaces */
- if(fname) HDfree(fname);
- if(dname) HDfree(dname);
- if(g_list_of_fields) HDfree(g_list_of_fields);
+ if(fname)
+ HDfree(fname);
+ if(dname)
+ HDfree(dname);
+ if(g_list_of_fields)
+ HDfree(g_list_of_fields);
if(g_listv) {
H5LD_clean_vector(g_listv);
HDfree(g_listv);
}
- if(g_dup_fields) HDfree(g_dup_fields);
+ if(g_dup_fields)
+ HDfree(g_dup_fields);
/* Close the file access property list */
if(fapl >= 0 && H5Pclose(fapl) < 0) {
@@ -960,12 +973,11 @@ main(int argc, const char *argv[])
}
/* Close the file */
- if(H5Fclose(fid) < 0) {
+ if(fid >= 0 && H5Fclose(fid) < 0) {
error_msg("unable to close file\n");
h5tools_setstatus(EXIT_FAILURE);
}
- H5Eset_auto2(H5E_DEFAULT, func, edata);
/* exit */
leave(h5tools_getstatus());
} /* main() */