diff options
Diffstat (limited to 'hl/tools')
-rw-r--r-- | hl/tools/gif2h5/decompress.c | 176 | ||||
-rw-r--r-- | hl/tools/gif2h5/gif.h | 81 | ||||
-rw-r--r-- | hl/tools/gif2h5/gif2hdf.c | 46 | ||||
-rw-r--r-- | hl/tools/gif2h5/gif2mem.c | 181 | ||||
-rw-r--r-- | hl/tools/gif2h5/gifread.c | 311 | ||||
-rw-r--r-- | hl/tools/gif2h5/h52gifgentst.c | 66 | ||||
-rw-r--r-- | hl/tools/gif2h5/hdf2gif.c | 229 | ||||
-rw-r--r-- | hl/tools/gif2h5/hdfgifwr.c | 217 | ||||
-rw-r--r-- | hl/tools/gif2h5/writehdf.c | 57 | ||||
-rw-r--r-- | hl/tools/h5watch/extend_dset.c | 292 | ||||
-rw-r--r-- | hl/tools/h5watch/h5watch.c | 556 | ||||
-rw-r--r-- | hl/tools/h5watch/h5watchgentest.c | 275 | ||||
-rw-r--r-- | hl/tools/h5watch/swmr_check_compat_vfd.c | 8 |
13 files changed, 1204 insertions, 1291 deletions
diff --git a/hl/tools/gif2h5/decompress.c b/hl/tools/gif2h5/decompress.c index 129fa60..710d29f 100644 --- a/hl/tools/gif2h5/decompress.c +++ b/hl/tools/gif2h5/decompress.c @@ -15,45 +15,43 @@ #include "gif.h" -GIFWORD iWIDE, iHIGH, eWIDE, eHIGH, expand, numcols, strip, nostrip; -unsigned long cols[256]; -char *cmd; +GIFWORD iWIDE, iHIGH, eWIDE, eHIGH, expand, numcols, strip, nostrip; +unsigned long cols[256]; +char * cmd; FILE *fp; -static GIFWORD - XC = 0, YC = 0, /* Output X and Y coords of current pixel */ - InitCodeSize, /* Starting code size, used during Clear */ - CodeSize, /* Code size, read from GIF header */ - BytesPerScanline, /* Bytes per scanline in output raster */ - IWidth, IHeight; /* image dimensions */ -static int - BitOffset = 0, /* Bit Offset of next code */ - Pass = 0, /* Used by output routine if GIFWORDerlaced pic */ - OutCount = 0, /* Decompressor output 'stack count' */ - Code, /* Value returned by ReadCode */ - MaxCode, /* limiting value for current code size */ - ClearCode, /* GIF clear code */ - EOFCode, /* GIF end-of-information code */ - CurCode, OldCode, InCode, /* Decompressor variables */ - FirstFree, /* First free code, generated per GIF spec */ - FreeCode, /* Decompressor, next free slot in hash table */ - FinChar, /* Decompressor variable */ - DataMask, /* AND mask for data size */ - ReadMask; /* Code AND mask for current code size */ +static GIFWORD XC = 0, YC = 0, /* Output X and Y coords of current pixel */ + InitCodeSize, /* Starting code size, used during Clear */ + CodeSize, /* Code size, read from GIF header */ + BytesPerScanline, /* Bytes per scanline in output raster */ + IWidth, IHeight; /* image dimensions */ +static int BitOffset = 0, /* Bit Offset of next code */ + Pass = 0, /* Used by output routine if GIFWORDerlaced pic */ + OutCount = 0, /* Decompressor output 'stack count' */ + Code, /* Value returned by ReadCode */ + MaxCode, /* limiting value for current code size */ + ClearCode, /* GIF clear code */ + EOFCode, /* GIF end-of-information code */ + CurCode, OldCode, InCode, /* Decompressor variables */ + FirstFree, /* First free code, generated per GIF spec */ + FreeCode, /* Decompressor, next free slot in hash table */ + FinChar, /* Decompressor variable */ + DataMask, /* AND mask for data size */ + ReadMask; /* Code AND mask for current code size */ /*MODIFICATIONS*/ -GIFBYTE tempbyte[10]; -GIFBYTE * tempGIFBYTEptr[10]; -GIFWORD tempint[10]; -GIFWORD ImageCount = 0; +GIFBYTE tempbyte[10]; +GIFBYTE *tempGIFBYTEptr[10]; +GIFWORD tempint[10]; +GIFWORD ImageCount = 0; /*END MODIFICATION*/ boolean Interlace, HasColormap; -GIFBYTE *Image; /* The result array */ -GIFBYTE *RawGIF; /* The heap array to hold it, raw */ -GIFBYTE *Raster; /* The raster data stream, unblocked */ +GIFBYTE *Image; /* The result array */ +GIFBYTE *RawGIF; /* The heap array to hold it, raw */ +GIFBYTE *Raster; /* The raster data stream, unblocked */ /* The hash table used by the decompressor */ @@ -66,7 +64,7 @@ int *OutCode; /* The color map, read from the GIF header */ -int numused; +int numused; /* * Fetch the next code from the raster data stream. The codes can be any @@ -82,7 +80,7 @@ ReadCode(void) int RawCode, ByteOffset; ByteOffset = BitOffset / 8; - RawCode = Raster[ByteOffset] + (0x100 * Raster[ByteOffset + 1]); + RawCode = Raster[ByteOffset] + (0x100 * Raster[ByteOffset + 1]); if (CodeSize >= 8) RawCode += (0x10000 * Raster[ByteOffset + 2]); @@ -95,10 +93,8 @@ ReadCode(void) static void AddToPixel(GIFBYTE Index) { - if (YC<IHeight) - *(Image + YC * BytesPerScanline + XC) = Index; - - + if (YC < IHeight) + *(Image + YC * BytesPerScanline + XC) = Index; /* Update the X-coordinate, and if it overflows, update the * Y-coordinate */ @@ -113,40 +109,41 @@ AddToPixel(GIFBYTE Index) if (!Interlace) { YC++; - } else { + } + else { switch (Pass) { - case 0: - YC += 8; - - if (YC >= IHeight) { - Pass++; - YC = 4; - } - - break; - case 1: - YC += 8; - - if (YC >= IHeight) { - Pass++; - YC = 2; - } - - break; - case 2: - YC += 4; - - if (YC >= IHeight) { - Pass++; - YC = 1; - } - - break; - case 3: - YC += 2; - break; - default: - break; + case 0: + YC += 8; + + if (YC >= IHeight) { + Pass++; + YC = 4; + } + + break; + case 1: + YC += 8; + + if (YC >= IHeight) { + Pass++; + YC = 2; + } + + break; + case 2: + YC += 4; + + if (YC >= IHeight) { + Pass++; + YC = 1; + } + + break; + case 3: + YC += 2; + break; + default: + break; } } } @@ -172,20 +169,20 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) exit(EXIT_FAILURE); } - XC = 0; - YC = 0; - Pass = 0; - OutCount = 0; + XC = 0; + YC = 0; + Pass = 0; + OutCount = 0; BitOffset = 0; - DataMask = (1 << ((GifHead->PackedField & 0x07) +1)) -1; - Raster = GifImageDesc->GIFImage; + DataMask = (1 << ((GifHead->PackedField & 0x07) + 1)) - 1; + Raster = GifImageDesc->GIFImage; /* Check for image seperator */ /* Now read in values from the image descriptor */ - IWidth = GifImageDesc->ImageWidth; - IHeight = GifImageDesc->ImageHeight; + IWidth = GifImageDesc->ImageWidth; + IHeight = GifImageDesc->ImageHeight; Interlace = (uint8_t)(GifImageDesc->PackedField & 0x40); /* @@ -200,9 +197,9 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) * compute decompressor constant values, based on this code size. */ - CodeSize = GifImageDesc->CodeSize; + CodeSize = GifImageDesc->CodeSize; ClearCode = (1 << CodeSize); - EOFCode = ClearCode + 1; + EOFCode = ClearCode + 1; FreeCode = FirstFree = ClearCode + 2; /* @@ -214,8 +211,8 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) CodeSize++; InitCodeSize = CodeSize; - MaxCode = (1 << CodeSize); - ReadMask = MaxCode - 1; + MaxCode = (1 << CodeSize); + ReadMask = MaxCode - 1; /* * Read the raster data. Here we just transpose it from the GIF array to @@ -225,7 +222,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) /* Allocate the Image */ - if (!(Image = (GIFBYTE *)malloc((size_t)IWidth*(size_t)IHeight))) { + if (!(Image = (GIFBYTE *)malloc((size_t)IWidth * (size_t)IHeight))) { printf("Out of memory"); exit(EXIT_FAILURE); } @@ -246,13 +243,14 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) */ if (Code == ClearCode) { CodeSize = InitCodeSize; - MaxCode = (1 << CodeSize); + MaxCode = (1 << CodeSize); ReadMask = MaxCode - 1; FreeCode = FirstFree; CurCode = OldCode = Code = ReadCode(); - FinChar = CurCode & DataMask; + FinChar = CurCode & DataMask; AddToPixel((GIFBYTE)FinChar); - } else { + } + else { /* * If not a clear code, then must be data: save same as CurCode * and InCode @@ -264,7 +262,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) * repeat the last character decoded */ if (CurCode >= FreeCode) { - CurCode = OldCode; + CurCode = OldCode; OutCode[OutCount++] = FinChar; } @@ -279,11 +277,11 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) } OutCode[OutCount++] = Suffix[CurCode]; - CurCode = Prefix[CurCode]; + CurCode = Prefix[CurCode]; } /* The last code in the chain is treated as raw data. */ - FinChar = CurCode & DataMask; + FinChar = CurCode & DataMask; OutCode[OutCount++] = FinChar; /* @@ -301,7 +299,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) */ Prefix[FreeCode] = OldCode; Suffix[FreeCode] = FinChar; - OldCode = InCode; + OldCode = InCode; /* * Point to the next slot in the table. If we exceed the current diff --git a/hl/tools/gif2h5/gif.h b/hl/tools/gif2h5/gif.h index 0c0f963..cb54b9b 100644 --- a/hl/tools/gif2h5/gif.h +++ b/hl/tools/gif2h5/gif.h @@ -16,7 +16,7 @@ * Purpose: GIF Header file */ #ifndef GIF_H_ -#define GIF_H_ 1 +#define GIF_H_ 1 #include <stdio.h> #include <stdlib.h> @@ -39,10 +39,10 @@ typedef unsigned char boolean; #endif #ifndef false -#define false 0 +#define false 0 #endif #ifndef true -#define true 1 +#define true 1 #endif /* Set the EndianOrder. @@ -50,7 +50,7 @@ typedef unsigned char boolean; ** Set EndianOrder = 0 if machine is little endian ** EndianOrder = 1 if machine is big endian. */ -extern int EndianOrder; +extern int EndianOrder; /* ** The GIF header format. @@ -59,31 +59,30 @@ extern int EndianOrder; ** descriptor, and the global color table for the GIF image. */ typedef struct _GifHeader { /* Offset Description */ - GIFBYTE PackedField; /* 0Ah Color Information */ + GIFBYTE PackedField; /* 0Ah Color Information */ GIFWORD TableSize; - GIFBYTE ImageCount; /* Keep a count of the number of images */ + GIFBYTE ImageCount; /* Keep a count of the number of images */ GIFBYTE CommentCount; GIFBYTE ApplicationCount; GIFBYTE PlainTextCount; GIFBYTE HDFPalette[256][3]; - GIFBYTE HeaderDump[6]; /* GIFBYTE array to dump header contents */ - GIFBYTE LSDDump[7]; /* Logical Screen Descriptor dump */ + GIFBYTE HeaderDump[6]; /* GIFBYTE array to dump header contents */ + GIFBYTE LSDDump[7]; /* Logical Screen Descriptor dump */ } GIFHEAD; - /* ** The GIF Image Descriptor. */ typedef struct _GifImageDescriptor { - GIFWORD ImageWidth; /* Width of the image in pixels */ - GIFWORD ImageHeight; /* Height of the image in pixels */ - GIFBYTE PackedField; /* Image and Color Table Data Information */ + GIFWORD ImageWidth; /* Width of the image in pixels */ + GIFWORD ImageHeight; /* Height of the image in pixels */ + GIFBYTE PackedField; /* Image and Color Table Data Information */ GIFWORD TableSize; - GIFWORD CodeSize; /* Minimum LZW CodeSize for image data */ + GIFWORD CodeSize; /* Minimum LZW CodeSize for image data */ GIFBYTE HDFPalette[256][3]; - GIFBYTE GIDDump[9]; /* GifImageDescriptor dump */ + GIFBYTE GIDDump[9]; /* GifImageDescriptor dump */ - GIFBYTE *Image; /* Decompressed Raster Image */ + GIFBYTE *Image; /* Decompressed Raster Image */ GIFBYTE *GIFImage; } GIFIMAGEDESC; @@ -91,36 +90,35 @@ typedef struct _GifImageDescriptor { ** GIF 89a Graphic Control Extension Block */ typedef struct _GifGraphicControlExtension { - GIFBYTE GCEDump[5]; /* Graphic Control Extension Dump */ + GIFBYTE GCEDump[5]; /* Graphic Control Extension Dump */ } GIFGRAPHICCONTROL; /* ** GIF 89a Plain Text Extension Block */ typedef struct _GifPlainTextExtension { - GIFBYTE PTEDump[15]; /* Plain Text Extension Dump */ - GIFBYTE *PlainTextData; /* Plain Text data sub-blocks */ - GIFWORD DataSize; + GIFBYTE PTEDump[15]; /* Plain Text Extension Dump */ + GIFBYTE *PlainTextData; /* Plain Text data sub-blocks */ + GIFWORD DataSize; } GIFPLAINTEXT; - /* ** GIF 89a Application Extension Block */ typedef struct _GifApplicationExtension { - GIFBYTE AEDump[14]; /* Application Extension Dump */ - GIFBYTE *ApplicationData; /* Application data sub-blocks */ - GIFWORD DataSize; + GIFBYTE AEDump[14]; /* Application Extension Dump */ + GIFBYTE *ApplicationData; /* Application data sub-blocks */ + GIFWORD DataSize; } GIFAPPLICATION; /* ** GIF 89a Comment Extension Block */ typedef struct _GifCommentExtension { - GIFBYTE CEDump[2]; /* Comment Extension Dump */ - GIFBYTE *CommentData; /* Comment data sub-blocks */ - GIFWORD DataSize; - GIFBYTE Terminator; /* Block Terminator (always 0) */ + GIFBYTE CEDump[2]; /* Comment Extension Dump */ + GIFBYTE *CommentData; /* Comment data sub-blocks */ + GIFWORD DataSize; + GIFBYTE Terminator; /* Block Terminator (always 0) */ } GIFCOMMENT; /* @@ -135,12 +133,12 @@ typedef struct _GifCommentExtension { ** extension. */ typedef struct _GifToMem { - GIFHEAD *GifHeader; - GIFIMAGEDESC **GifImageDesc; + GIFHEAD * GifHeader; + GIFIMAGEDESC ** GifImageDesc; GIFGRAPHICCONTROL **GifGraphicControlExtension; - GIFPLAINTEXT **GifPlainTextExtension; - GIFAPPLICATION **GifApplicationExtension; - GIFCOMMENT **GifCommentExtension; + GIFPLAINTEXT ** GifPlainTextExtension; + GIFAPPLICATION ** GifApplicationExtension; + GIFCOMMENT ** GifCommentExtension; } GIFTOMEM; /* @@ -159,12 +157,11 @@ int ReadGifApplication(GIFAPPLICATION *, GIFBYTE **); int ReadGifComment(GIFCOMMENT *, GIFBYTE **); /* HDFGIFWR.C */ -int hdfWriteGIF(FILE *fp, GIFBYTE *pic, int ptype, int w, int h, GIFBYTE *rmap, - GIFBYTE *gmap, GIFBYTE *bmap, GIFBYTE *pc2ncmap, int numcols, - int colorstyle, int BitsPerPixel); +int hdfWriteGIF(FILE *fp, GIFBYTE *pic, int ptype, int w, int h, GIFBYTE *rmap, GIFBYTE *gmap, GIFBYTE *bmap, + GIFBYTE *pc2ncmap, int numcols, int colorstyle, int BitsPerPixel); /* WRITEHDF.C */ -int WriteHDF(GIFTOMEM , GIFCHAR * ); +int WriteHDF(GIFTOMEM, GIFCHAR *); /* Function: ReadHDF ** Return: 0 on completion without error, -1 on error @@ -175,13 +172,13 @@ int WriteHDF(GIFTOMEM , GIFCHAR * ); ** GIFBYTE palette[256][3] - the corresponding palette ** hsize_t* image_size - the size of each dimension of the image */ -int ReadHDF(GIFBYTE** data, GIFBYTE palette[256][3], hsize_t *image_size, - GIFCHAR *h5_file, GIFCHAR *dset_name, GIFCHAR *pal_name); +int ReadHDF(GIFBYTE **data, GIFBYTE palette[256][3], hsize_t *image_size, GIFCHAR *h5_file, + GIFCHAR *dset_name, GIFCHAR *pal_name); GIFBYTE *Decompress(GIFIMAGEDESC *, GIFHEAD *); -GIFBYTE GetByte(GIFBYTE *); -GIFWORD GetWord(GIFBYTE *); +GIFBYTE GetByte(GIFBYTE *); +GIFWORD GetWord(GIFBYTE *); -void cleanup(GIFBYTE*); +void cleanup(GIFBYTE *); -#endif /* GIF_H_ */ +#endif /* GIF_H_ */ diff --git a/hl/tools/gif2h5/gif2hdf.c b/hl/tools/gif2h5/gif2hdf.c index 051ff56..939844c 100644 --- a/hl/tools/gif2h5/gif2hdf.c +++ b/hl/tools/gif2h5/gif2hdf.c @@ -18,11 +18,10 @@ #include "h5tools.h" #include "h5tools_utils.h" - int -main(int argv , char *argc[]) +main(int argv, char *argc[]) { - GIFTOMEM GifMemoryStruct; + GIFTOMEM GifMemoryStruct; GIFIMAGEDESC gifImageDesc; FILE *fpGif; @@ -51,11 +50,9 @@ main(int argv , char *argc[]) /* Initialize h5tools lib */ h5tools_init(); - if ( argc[1] && (strcmp("-V",argc[1])==0) ) - { + if (argc[1] && (strcmp("-V", argc[1]) == 0)) { print_version("gif2h5"); exit(EXIT_SUCCESS); - } if (argv < 3) { @@ -68,15 +65,15 @@ main(int argv , char *argc[]) GIFFileName = argc[1]; HDFFileName = argc[2]; - if (!(fpGif = fopen(GIFFileName,"rb"))) { + if (!(fpGif = fopen(GIFFileName, "rb"))) { printf("Unable to open GIF file for reading.\n"); exit(EXIT_FAILURE); } /* Get the whole file into memory. Mem's much faster than I/O */ - fseek(fpGif, 0L , 2); + fseek(fpGif, 0L, 2); filesize = ftell(fpGif); - fseek(fpGif, 0L , 0); + fseek(fpGif, 0L, 0); if (filesize == 0) printf("File Size Zero"); @@ -86,12 +83,12 @@ main(int argv , char *argc[]) exit(EXIT_FAILURE); } - if (fread(MemGif,(size_t)filesize,1,fpGif) != 1) { + if (fread(MemGif, (size_t)filesize, 1, fpGif) != 1) { printf("Corrupted Input File"); exit(EXIT_FAILURE); } - fseek(fpGif,0L,0); + fseek(fpGif, 0L, 0); /* * Call Gif2Mem and break the whole file into parts. Gif2Mem also calls @@ -100,8 +97,8 @@ main(int argv , char *argc[]) Gif2Mem(MemGif, &GifMemoryStruct); if (ferror(fpGif)) { - printf("File Stream Error\n\n"); - exit(EXIT_FAILURE); + printf("File Stream Error\n\n"); + exit(EXIT_FAILURE); } fclose(fpGif); @@ -110,54 +107,47 @@ main(int argv , char *argc[]) * Call WriteHDF from here. Go ahead and change WriteHDF to write whatever * format you want */ - if (WriteHDF(GifMemoryStruct , HDFFileName)) + if (WriteHDF(GifMemoryStruct, HDFFileName)) printf("HDF Write Error\n\n"); /* Free all buffers */ /* replacing int32 with long */ ImageCount = (long)((GifMemoryStruct.GifHeader)->ImageCount); - for(i = 0; i < ImageCount ; i++) { + for (i = 0; i < ImageCount; i++) { gifImageDesc = *(GifMemoryStruct.GifImageDesc[i]); if (gifImageDesc.Image != NULL) free(gifImageDesc.Image); - if (GifMemoryStruct.GifImageDesc[i] != NULL) - { + if (GifMemoryStruct.GifImageDesc[i] != NULL) { free(GifMemoryStruct.GifImageDesc[i]); GifMemoryStruct.GifImageDesc[i] = NULL; } - if (GifMemoryStruct.GifGraphicControlExtension[i] != NULL) - { + if (GifMemoryStruct.GifGraphicControlExtension[i] != NULL) { free(GifMemoryStruct.GifGraphicControlExtension[i]); GifMemoryStruct.GifGraphicControlExtension[i] = NULL; } } free(StartPos); - if (GifMemoryStruct.GifHeader != NULL) - { + if (GifMemoryStruct.GifHeader != NULL) { free(GifMemoryStruct.GifHeader); GifMemoryStruct.GifHeader = NULL; } - if (GifMemoryStruct.GifApplicationExtension != NULL) - { + if (GifMemoryStruct.GifApplicationExtension != NULL) { free(GifMemoryStruct.GifApplicationExtension); GifMemoryStruct.GifApplicationExtension = NULL; } - if (GifMemoryStruct.GifImageDesc != NULL) - { + if (GifMemoryStruct.GifImageDesc != NULL) { free(GifMemoryStruct.GifImageDesc); GifMemoryStruct.GifImageDesc = NULL; } - if (GifMemoryStruct.GifGraphicControlExtension != NULL) - { + if (GifMemoryStruct.GifGraphicControlExtension != NULL) { free(GifMemoryStruct.GifGraphicControlExtension); GifMemoryStruct.GifGraphicControlExtension = NULL; } - return EXIT_SUCCESS; } diff --git a/hl/tools/gif2h5/gif2mem.c b/hl/tools/gif2h5/gif2mem.c index ae0a113..b1ea718 100644 --- a/hl/tools/gif2h5/gif2mem.c +++ b/hl/tools/gif2h5/gif2mem.c @@ -42,29 +42,29 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct) * The gif structure outline for passing data to memory is given in gif.h. * These pointers are redunant, should take them out in ver. 2 */ - GIFHEAD *gifHead; /* GIF Header structure */ - GIFIMAGEDESC **gifImageDesc; /* Logical Image Descriptor struct */ - GIFPLAINTEXT **gifPlainText; /* Plain Text Extension structure */ - GIFAPPLICATION **gifApplication; /* Application Extension structure */ - GIFCOMMENT **gifComment; /* Comment Extension structure */ + GIFHEAD * gifHead; /* GIF Header structure */ + GIFIMAGEDESC ** gifImageDesc; /* Logical Image Descriptor struct */ + GIFPLAINTEXT ** gifPlainText; /* Plain Text Extension structure */ + GIFAPPLICATION ** gifApplication; /* Application Extension structure */ + GIFCOMMENT ** gifComment; /* Comment Extension structure */ GIFGRAPHICCONTROL **gifGraphicControl; /* Graphic Control Extension strct */ - register GIFWORD i; /* Loop counter */ - GIFBYTE Identifier; /* Extension block identifier holder */ - GIFBYTE Label; /* Extension block label holder */ - GIFBYTE ImageCount; /* Count of the number of images in the file */ - GIFBYTE ImageArray; /* Keep the size of the array to store Images */ - GIFBYTE CommentCount; - GIFBYTE CommentArray; - GIFBYTE ApplicationCount; - GIFBYTE ApplicationArray; - GIFBYTE PlainTextCount; - GIFBYTE PlainTextArray; - GIFBYTE GCEflag; - GIFBYTE aTemp; - GIFBYTE j; - GIFBYTE w; /* Two more variables needed only while testing */ - GIFBYTE *b; /* Endian Ordering */ + register GIFWORD i; /* Loop counter */ + GIFBYTE Identifier; /* Extension block identifier holder */ + GIFBYTE Label; /* Extension block label holder */ + GIFBYTE ImageCount; /* Count of the number of images in the file */ + GIFBYTE ImageArray; /* Keep the size of the array to store Images */ + GIFBYTE CommentCount; + GIFBYTE CommentArray; + GIFBYTE ApplicationCount; + GIFBYTE ApplicationArray; + GIFBYTE PlainTextCount; + GIFBYTE PlainTextArray; + GIFBYTE GCEflag; + GIFBYTE aTemp; + GIFBYTE j; + GIFBYTE w; /* Two more variables needed only while testing */ + GIFBYTE * b; /* Endian Ordering */ /* Allocate memory for the GIF structures */ /* Plug the structs into GifMemoryStruct at the end */ @@ -89,8 +89,8 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct) /******************************/ /* Carry out Endian Testing and set Endian Order */ - w = 0x0001; - b = (GIFBYTE *) &w; + w = 0x0001; + b = (GIFBYTE *)&w; EndianOrder = (b[0] ? 1 : 0); /* Read the GIF image file header information */ @@ -103,22 +103,22 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct) fputs("GIFHEAD: Error reading header information!\n", stderr); exit(EXIT_FAILURE); } -#endif /* 0 */ +#endif /* 0 */ /* * Identify, read, and display block information. */ - ImageCount = ImageArray = 0; - CommentCount = CommentArray = 0; + ImageCount = ImageArray = 0; + CommentCount = CommentArray = 0; ApplicationCount = ApplicationArray = 0; - PlainTextCount = PlainTextArray = 0; - GCEflag = 0; + PlainTextCount = PlainTextArray = 0; + GCEflag = 0; for (;;) { Identifier = *MemGif++; switch (Identifier) { - case 0x3B: /* Trailer */ + case 0x3B: /* Trailer */ /* * The counts are stored to make it easier while putting stuff * into the HDF file and then deallocating space. @@ -129,17 +129,17 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct) gifHead->PlainTextCount = PlainTextCount; /* putting stuff into the gif2mem structure */ - GifMemoryStruct->GifHeader = gifHead; - GifMemoryStruct->GifImageDesc = gifImageDesc; - GifMemoryStruct->GifPlainTextExtension = gifPlainText; - GifMemoryStruct->GifApplicationExtension = gifApplication; - GifMemoryStruct->GifCommentExtension = gifComment; + GifMemoryStruct->GifHeader = gifHead; + GifMemoryStruct->GifImageDesc = gifImageDesc; + GifMemoryStruct->GifPlainTextExtension = gifPlainText; + GifMemoryStruct->GifApplicationExtension = gifApplication; + GifMemoryStruct->GifCommentExtension = gifComment; GifMemoryStruct->GifGraphicControlExtension = gifGraphicControl; /* return the struct */ return 0; - case 0x2C: /* Image Descriptor */ + case 0x2C: /* Image Descriptor */ /* * If there was no image descriptor before this increase image * count. If an imagedescriptor was present, reset GCEflag @@ -150,40 +150,37 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct) GCEflag = 0; if (ImageCount > ImageArray) { - aTemp = ImageArray; + aTemp = ImageArray; ImageArray = (GIFBYTE)((ImageArray << 1) + 1); - if (!(gifImageDesc = (GIFIMAGEDESC **)realloc(gifImageDesc, - sizeof(GIFIMAGEDESC *) * ImageArray))) { + if (!(gifImageDesc = + (GIFIMAGEDESC **)realloc(gifImageDesc, sizeof(GIFIMAGEDESC *) * ImageArray))) { printf("Out of memory!"); exit(EXIT_FAILURE); } if (!(gifGraphicControl = (GIFGRAPHICCONTROL **)realloc( - gifGraphicControl, - sizeof(GIFGRAPHICCONTROL *) * ImageArray))) { + gifGraphicControl, sizeof(GIFGRAPHICCONTROL *) * ImageArray))) { printf("Out of memory!"); exit(EXIT_FAILURE); } - for (j = aTemp ; j < ImageArray ; j++) { + for (j = aTemp; j < ImageArray; j++) { gifGraphicControl[j] = NULL; - gifImageDesc[j] = NULL; + gifImageDesc[j] = NULL; } } - if(!(gifImageDesc[ImageCount-1] = (GIFIMAGEDESC*)malloc(sizeof(GIFIMAGEDESC)))) { + if (!(gifImageDesc[ImageCount - 1] = (GIFIMAGEDESC *)malloc(sizeof(GIFIMAGEDESC)))) { printf("Out of memory!"); exit(EXIT_FAILURE); } - - if (ReadGifImageDesc(gifImageDesc[ImageCount-1], &MemGif) == -1) + if (ReadGifImageDesc(gifImageDesc[ImageCount - 1], &MemGif) == -1) fputs("Error reading Image Descriptor information\n", stderr); /* Decompress the Image */ - gifImageDesc[ImageCount-1]->Image = Decompress(gifImageDesc[ImageCount-1], - gifHead); - free(gifImageDesc[ImageCount-1]->GIFImage); + gifImageDesc[ImageCount - 1]->Image = Decompress(gifImageDesc[ImageCount - 1], gifHead); + free(gifImageDesc[ImageCount - 1]->GIFImage); /* * Convert the local palette into an HDF compatible palette In @@ -191,150 +188,146 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct) * the HDFPalette If it is absent the global table is written * as the HDFPalette. */ - if (!((gifImageDesc[ImageCount-1]->PackedField) & 0x80)) { + if (!((gifImageDesc[ImageCount - 1]->PackedField) & 0x80)) { /* Check to see if the global color table exists.... */ if (gifHead->PackedField & 0x80) { - for (i=0 ; i<gifHead->TableSize ; i++) { - gifImageDesc[ImageCount-1]->HDFPalette[i][0] = - gifHead->HDFPalette[i][0]; - gifImageDesc[ImageCount-1]->HDFPalette[i][1] = - gifHead->HDFPalette[i][1]; - gifImageDesc[ImageCount-1]->HDFPalette[i][2] = - gifHead->HDFPalette[i][2]; + for (i = 0; i < gifHead->TableSize; i++) { + gifImageDesc[ImageCount - 1]->HDFPalette[i][0] = gifHead->HDFPalette[i][0]; + gifImageDesc[ImageCount - 1]->HDFPalette[i][1] = gifHead->HDFPalette[i][1]; + gifImageDesc[ImageCount - 1]->HDFPalette[i][2] = gifHead->HDFPalette[i][2]; } } - gifImageDesc[ImageCount-1]->TableSize = gifHead->TableSize; + gifImageDesc[ImageCount - 1]->TableSize = gifHead->TableSize; } break; - case 0x21: /* Extension Block */ - Label = *MemGif++; + case 0x21: /* Extension Block */ + Label = *MemGif++; - switch (Label) { - case 0x01: /* Plain Text Extension */ + switch (Label) { + case 0x01: /* Plain Text Extension */ puts("Plain Text Extension\n"); PlainTextCount++; if (PlainTextCount > PlainTextArray) PlainTextArray = (GIFBYTE)((PlainTextArray << 1) + 1); - if (!(gifPlainText = (GIFPLAINTEXT **)realloc(gifPlainText , sizeof(GIFPLAINTEXT *) * PlainTextArray))) { + if (!(gifPlainText = (GIFPLAINTEXT **)realloc(gifPlainText, sizeof(GIFPLAINTEXT *) * + PlainTextArray))) { printf("Out of memory!"); exit(EXIT_FAILURE); } - if(!(gifPlainText[PlainTextCount - 1] = (GIFPLAINTEXT*)malloc(sizeof(GIFPLAINTEXT)))) { + if (!(gifPlainText[PlainTextCount - 1] = + (GIFPLAINTEXT *)malloc(sizeof(GIFPLAINTEXT)))) { printf("Out of memory!"); exit(EXIT_FAILURE); } if (ReadGifPlainText(gifPlainText[PlainTextCount - 1], &MemGif)) - fprintf(stderr, - "Error reading Plain Text Extension information.\n"); + fprintf(stderr, "Error reading Plain Text Extension information.\n"); break; - case 0xFE: /* Comment Extension */ + case 0xFE: /* Comment Extension */ CommentCount++; if (CommentCount > CommentArray) CommentArray = (GIFBYTE)((CommentArray << 1) + 1); - if (!(gifComment = (GIFCOMMENT **)realloc(gifComment , sizeof(GIFCOMMENT *) * CommentArray))) { + if (!(gifComment = + (GIFCOMMENT **)realloc(gifComment, sizeof(GIFCOMMENT *) * CommentArray))) { printf("Out of memory!"); exit(EXIT_FAILURE); } - if(!(gifComment[CommentCount - 1] = (GIFCOMMENT *)malloc(sizeof(GIFCOMMENT)))) { + if (!(gifComment[CommentCount - 1] = (GIFCOMMENT *)malloc(sizeof(GIFCOMMENT)))) { printf("Out of memory!"); exit(EXIT_FAILURE); } - if (ReadGifComment(gifComment[CommentCount - 1], &MemGif)) - fprintf(stderr, - "Error reading Comment Extension information\n"); + fprintf(stderr, "Error reading Comment Extension information\n"); break; - case 0xF9: /* Graphic Control Extension */ - if (GCEflag == 0 ) + case 0xF9: /* Graphic Control Extension */ + if (GCEflag == 0) ImageCount++; GCEflag = 1; if (ImageCount > ImageArray) { - aTemp = ImageArray; + aTemp = ImageArray; ImageArray = (GIFBYTE)((ImageArray << 1) + 1); - if (!(gifGraphicControl = (GIFGRAPHICCONTROL **)realloc(gifGraphicControl , sizeof(GIFGRAPHICCONTROL *) * ImageArray))) { + if (!(gifGraphicControl = (GIFGRAPHICCONTROL **)realloc( + gifGraphicControl, sizeof(GIFGRAPHICCONTROL *) * ImageArray))) { printf("Out of memory!"); exit(EXIT_FAILURE); } - if (!(gifImageDesc = (GIFIMAGEDESC **)realloc(gifImageDesc , sizeof(GIFIMAGEDESC *) * ImageArray))) { + if (!(gifImageDesc = (GIFIMAGEDESC **)realloc( + gifImageDesc, sizeof(GIFIMAGEDESC *) * ImageArray))) { printf("Out of memory!"); exit(EXIT_FAILURE); } - for (j = aTemp ; j < ImageArray ; j++) { + for (j = aTemp; j < ImageArray; j++) { gifGraphicControl[j] = NULL; gifImageDesc[j] = NULL; } } - if(!(gifGraphicControl[ImageCount-1] = (GIFGRAPHICCONTROL*)malloc(sizeof(GIFGRAPHICCONTROL)))) { + if (!(gifGraphicControl[ImageCount - 1] = + (GIFGRAPHICCONTROL *)malloc(sizeof(GIFGRAPHICCONTROL)))) { printf("Out of memory!"); exit(EXIT_FAILURE); } - - if (ReadGifGraphicControl(gifGraphicControl[ImageCount-1], &MemGif)) - fprintf(stderr, - "Error reading Graphic Control Extension information\n"); + if (ReadGifGraphicControl(gifGraphicControl[ImageCount - 1], &MemGif)) + fprintf(stderr, "Error reading Graphic Control Extension information\n"); (*MemGif)++; if ((!*MemGif) == 0) - fprintf(stderr, - "Error reading Graphic Control Extension\n"); + fprintf(stderr, "Error reading Graphic Control Extension\n"); break; - case 0xFF: /* Application Extension */ + case 0xFF: /* Application Extension */ ApplicationCount++; if (ApplicationCount > ApplicationArray) ApplicationArray = (GIFBYTE)((ApplicationArray << 1) + 1); - if (!(gifApplication = (GIFAPPLICATION **)realloc(gifApplication , sizeof(GIFAPPLICATION *) * ApplicationArray))) { + if (!(gifApplication = (GIFAPPLICATION **)realloc( + gifApplication, sizeof(GIFAPPLICATION *) * ApplicationArray))) { printf("Out of memory!"); exit(EXIT_FAILURE); } - if(!(gifApplication[ApplicationCount - 1] = (GIFAPPLICATION *)malloc(sizeof(GIFAPPLICATION)))) { + if (!(gifApplication[ApplicationCount - 1] = + (GIFAPPLICATION *)malloc(sizeof(GIFAPPLICATION)))) { printf("Out of memory!"); exit(EXIT_FAILURE); } - if (ReadGifApplication(gifApplication[ApplicationCount - 1], &MemGif)) - fprintf(stderr, - "Error reading Application Extension information\n"); + fprintf(stderr, "Error reading Application Extension information\n"); break; default: printf("Unknown Extension Label: %#02x\n", Label); break; - } + } - break; + break; default: - fprintf(stderr, - "Unknown Block Separator Character: %#02x\n", Identifier); + fprintf(stderr, "Unknown Block Separator Character: %#02x\n", Identifier); } } } diff --git a/hl/tools/gif2h5/gifread.c b/hl/tools/gif2h5/gifread.c index 79671aa..705e6f3 100644 --- a/hl/tools/gif2h5/gifread.c +++ b/hl/tools/gif2h5/gifread.c @@ -26,21 +26,19 @@ GetWord(GIFBYTE *MemGif) if (EndianOrder == 1) { /* LittleEndian */ - w = (GIFWORD) (*MemGif++ & 0xFF); - w |= (GIFWORD) ((*MemGif++ & 0xFF) << 0x08); - } else { - w = (GIFWORD) (*MemGif++ & 0xFF); - w = ((GIFWORD) (*MemGif++ & 0xFF)) | (w << 0x08); + w = (GIFWORD)(*MemGif++ & 0xFF); + w |= (GIFWORD)((*MemGif++ & 0xFF) << 0x08); + } + else { + w = (GIFWORD)(*MemGif++ & 0xFF); + w = ((GIFWORD)(*MemGif++ & 0xFF)) | (w << 0x08); } return w; } GIFBYTE -GetByte(GIFBYTE *MemGif) -{ - return *MemGif; -} +GetByte(GIFBYTE *MemGif) { return *MemGif; } /* * Read a GIF image GIFBYTE Header. @@ -53,23 +51,23 @@ GetByte(GIFBYTE *MemGif) * otherwise 0 if no error occured. */ int -ReadGifHeader(GIFHEAD *GifHead, /* Pointer to GIF header structure */ - GIFBYTE **MemGif2) /* GIF image file input FILE stream */ +ReadGifHeader(GIFHEAD * GifHead, /* Pointer to GIF header structure */ + GIFBYTE **MemGif2) /* GIF image file input FILE stream */ { - GIFWORD i; /* Loop counter */ - GIFWORD tableSize; /* Number of entires in the Global Color Table */ + GIFWORD i; /* Loop counter */ + GIFWORD tableSize; /* Number of entires in the Global Color Table */ GifHead->TableSize = 0; - for (i = 0 ; i < 6 ; i++) { + for (i = 0; i < 6; i++) { GifHead->HeaderDump[i] = *(*MemGif2)++; } - if (strncmp((const char *)GifHead->HeaderDump , "GIF" , (size_t)3)) { + if (strncmp((const char *)GifHead->HeaderDump, "GIF", (size_t)3)) { printf("The file does not appear to be a valid GIF file.\n"); exit(EXIT_FAILURE); } - for (i = 0 ; i < 7 ; i++) { + for (i = 0; i < 7; i++) { GifHead->LSDDump[i] = *(*MemGif2)++; } @@ -78,7 +76,7 @@ ReadGifHeader(GIFHEAD *GifHead, /* Pointer to GIF header structure */ /* Check if a Global Color Table is present */ if (GifHead->PackedField & 0x80) { /* Read number of color table entries */ - tableSize = (GIFWORD) (1L << ((GifHead->PackedField & 0x07) + 1)); + tableSize = (GIFWORD)(1L << ((GifHead->PackedField & 0x07) + 1)); GifHead->TableSize = tableSize; /* Read the Global Color Table */ @@ -100,12 +98,11 @@ ReadGifHeader(GIFHEAD *GifHead, /* Pointer to GIF header structure */ #if 0 if (ferror(FpGif)) return -1; -#endif /* 0 */ +#endif /* 0 */ - return 0; /* No FILE stream error occured */ + return 0; /* No FILE stream error occured */ } - /* ** Read a GIF Local Image Descriptor. ** @@ -120,93 +117,85 @@ ReadGifHeader(GIFHEAD *GifHead, /* Pointer to GIF header structure */ ** otherwise 0 if no error occured. */ int -ReadGifImageDesc( - GIFIMAGEDESC *GifImageDesc, /* Pointer to GIF image descriptor structure */ - GIFBYTE **MemGif2 /* GIF image file input FILE stream */ - ) +ReadGifImageDesc(GIFIMAGEDESC *GifImageDesc, /* Pointer to GIF image descriptor structure */ + GIFBYTE ** MemGif2 /* GIF image file input FILE stream */ +) { - GIFWORD i; /* Loop counter */ - GIFWORD tableSize; /* Number of entries in the Local Color Table */ - /* GIFBYTE Interlace; */ /* PackedField & 0x20 gives information on interlacing */ - GIFBYTE *TempPtr; - int ch , ch1; - - GifImageDesc->TableSize = 0; - for (i = 0 ; i < 9 ; i++) { - GifImageDesc->GIDDump[i] = *(*MemGif2)++; - } - - /* - ** Get the relevant fields. I need ImageWidth and Height actively hence I have - ** taken information from those fields. I intend to keep the GifImageDesc data - ** structure as it is so that anyone needing the rest of the fields can do so - ** quickly. - */ - - if (EndianOrder == 1) /* LittleEndian */ - { - GifImageDesc->ImageWidth = (GIFWORD) (GifImageDesc->GIDDump[4] & 0xFF); - GifImageDesc->ImageWidth |= (GIFWORD) ((GifImageDesc->GIDDump[5] & 0xFF) << 0x08); - - GifImageDesc->ImageHeight = (GIFWORD) (GifImageDesc->GIDDump[6] & 0xFF); - GifImageDesc->ImageHeight |= (GIFWORD) ((GifImageDesc->GIDDump[7] & 0xFF) << 0x08); - - } - else - { - GifImageDesc->ImageWidth = (GIFWORD) (GifImageDesc->GIDDump[4] & 0xFF); - GifImageDesc->ImageWidth = ((GIFWORD) (GifImageDesc->GIDDump[5] & 0xFF)) | (GifImageDesc->ImageWidth << 0x08); + GIFWORD i; /* Loop counter */ + GIFWORD tableSize; /* Number of entries in the Local Color Table */ + /* GIFBYTE Interlace; */ /* PackedField & 0x20 gives information on interlacing */ + GIFBYTE *TempPtr; + int ch, ch1; + + GifImageDesc->TableSize = 0; + for (i = 0; i < 9; i++) { + GifImageDesc->GIDDump[i] = *(*MemGif2)++; + } - GifImageDesc->ImageHeight = (GIFWORD) (GifImageDesc->GIDDump[6] & 0xFF); - GifImageDesc->ImageHeight = ((GIFWORD) (GifImageDesc->GIDDump[7] & 0xFF)) | (GifImageDesc->ImageWidth << 0x08); + /* + ** Get the relevant fields. I need ImageWidth and Height actively hence I have + ** taken information from those fields. I intend to keep the GifImageDesc data + ** structure as it is so that anyone needing the rest of the fields can do so + ** quickly. + */ + if (EndianOrder == 1) /* LittleEndian */ + { + GifImageDesc->ImageWidth = (GIFWORD)(GifImageDesc->GIDDump[4] & 0xFF); + GifImageDesc->ImageWidth |= (GIFWORD)((GifImageDesc->GIDDump[5] & 0xFF) << 0x08); - } + GifImageDesc->ImageHeight = (GIFWORD)(GifImageDesc->GIDDump[6] & 0xFF); + GifImageDesc->ImageHeight |= (GIFWORD)((GifImageDesc->GIDDump[7] & 0xFF) << 0x08); + } + else { + GifImageDesc->ImageWidth = (GIFWORD)(GifImageDesc->GIDDump[4] & 0xFF); + GifImageDesc->ImageWidth = + ((GIFWORD)(GifImageDesc->GIDDump[5] & 0xFF)) | (GifImageDesc->ImageWidth << 0x08); + + GifImageDesc->ImageHeight = (GIFWORD)(GifImageDesc->GIDDump[6] & 0xFF); + GifImageDesc->ImageHeight = + ((GIFWORD)(GifImageDesc->GIDDump[7] & 0xFF)) | (GifImageDesc->ImageWidth << 0x08); + } - GifImageDesc->PackedField = GifImageDesc->GIDDump[8]; + GifImageDesc->PackedField = GifImageDesc->GIDDump[8]; - /* Interlace = GifImageDesc->PackedField & 0x20; */ + /* Interlace = GifImageDesc->PackedField & 0x20; */ /* Check if a Local Color Table is present */ - if (GifImageDesc->PackedField & 0x80) - { + if (GifImageDesc->PackedField & 0x80) { /* Read number of color table entries */ - tableSize = (GIFWORD) (1L << ((GifImageDesc->PackedField & 0x07) + 1)); - GifImageDesc->TableSize = tableSize; + tableSize = (GIFWORD)(1L << ((GifImageDesc->PackedField & 0x07) + 1)); + GifImageDesc->TableSize = tableSize; /* Read the Local Color Table */ - for (i = 0; i < tableSize; i++) - { + for (i = 0; i < tableSize; i++) { GifImageDesc->HDFPalette[i][0] = *(*MemGif2)++; GifImageDesc->HDFPalette[i][1] = *(*MemGif2)++; GifImageDesc->HDFPalette[i][2] = *(*MemGif2)++; } } - /* - ** Get LZW minimum Code Size - */ - GifImageDesc->CodeSize = (GIFWORD)*(*MemGif2)++; - - /*GifImageDesc->GIFImage = ReadDataSubBlocks(FpGif);*/ - if (!(GifImageDesc->GIFImage = (GIFBYTE *)malloc((GifImageDesc->ImageWidth) * (GifImageDesc->ImageHeight)))) { - printf("Out of memory"); - exit(EXIT_FAILURE); - } - - - TempPtr = GifImageDesc->GIFImage; - do - { - ch = ch1 = (int)*(*MemGif2)++; - while (ch--) *TempPtr++ = *(*MemGif2)++; - } - while (ch1); + /* + ** Get LZW minimum Code Size + */ + GifImageDesc->CodeSize = (GIFWORD) * (*MemGif2)++; + + /*GifImageDesc->GIFImage = ReadDataSubBlocks(FpGif);*/ + if (!(GifImageDesc->GIFImage = + (GIFBYTE *)malloc((GifImageDesc->ImageWidth) * (GifImageDesc->ImageHeight)))) { + printf("Out of memory"); + exit(EXIT_FAILURE); + } + TempPtr = GifImageDesc->GIFImage; + do { + ch = ch1 = (int)*(*MemGif2)++; + while (ch--) + *TempPtr++ = *(*MemGif2)++; + } while (ch1); - return(0); /* No FILE stream error occured */ + return (0); /* No FILE stream error occured */ } - /* ** Read a GIF Graphic Control Extension block. ** @@ -217,21 +206,19 @@ ReadGifImageDesc( ** otherwise 0 if no error occured. */ int -ReadGifGraphicControl( - GIFGRAPHICCONTROL *GifGraphicControl, /* Pointer to GC Extension structure */ - GIFBYTE **MemGif2 /* GIF image file input FILE stream */ - ) +ReadGifGraphicControl(GIFGRAPHICCONTROL *GifGraphicControl, /* Pointer to GC Extension structure */ + GIFBYTE ** MemGif2 /* GIF image file input FILE stream */ +) { int i; - for (i = 0 ; i < 5 ; i++) { - GifGraphicControl->GCEDump[i] = *(*MemGif2)++; + for (i = 0; i < 5; i++) { + GifGraphicControl->GCEDump[i] = *(*MemGif2)++; } - return(0); /* No FILE stream error occured */ + return (0); /* No FILE stream error occured */ } - /* ** Read a GIF Plain Text Extension block. ** @@ -242,35 +229,33 @@ ReadGifGraphicControl( ** otherwise 0 if no error occured. */ int -ReadGifPlainText( - GIFPLAINTEXT *GifPlainText, /* Pointer to Plain Text Extension structure */ - GIFBYTE **MemGif2 /* GIF image file input FILE stream */ - ) +ReadGifPlainText(GIFPLAINTEXT *GifPlainText, /* Pointer to Plain Text Extension structure */ + GIFBYTE ** MemGif2 /* GIF image file input FILE stream */ +) { int i; - for (i = 0 ; i < 13 ; i++) { - GifPlainText->PTEDump[i] = *(*MemGif2)++; - } + for (i = 0; i < 13; i++) { + GifPlainText->PTEDump[i] = *(*MemGif2)++; + } /* Read in the Plain Text data sub-blocks */ - if (!(GifPlainText->PlainTextData = ReadDataSubBlocks(MemGif2 , &(GifPlainText->DataSize)))) - return(1); + if (!(GifPlainText->PlainTextData = ReadDataSubBlocks(MemGif2, &(GifPlainText->DataSize)))) + return (1); /* GifPlainText->Terminator = 0; */ /* Check for a FILE stream error */ - /* - if (ferror(FpGif)) - return(-1); - */ + /* + if (ferror(FpGif)) + return(-1); + */ - return(0); /* No FILE stream error occured */ + return (0); /* No FILE stream error occured */ } - /* ** Read a GIF Application Extension block. ** @@ -281,34 +266,32 @@ ReadGifPlainText( ** otherwise 0 if no error occured. */ int -ReadGifApplication( - GIFAPPLICATION *GifApplication, /* Pointer to Application Extension structure */ - GIFBYTE **MemGif2 /* GIF image file input FILE stream */ - ) +ReadGifApplication(GIFAPPLICATION *GifApplication, /* Pointer to Application Extension structure */ + GIFBYTE ** MemGif2 /* GIF image file input FILE stream */ +) { int i; - for (i = 0 ; i < 12 ; i++) { - GifApplication->AEDump[i] = *(*MemGif2)++; - } + for (i = 0; i < 12; i++) { + GifApplication->AEDump[i] = *(*MemGif2)++; + } /* Read in the Plain Text data sub-blocks */ - if (!(GifApplication->ApplicationData = ReadDataSubBlocks(MemGif2 , &(GifApplication->DataSize)))) - return(1); - /* - GifApplication->Terminator = 0; - */ + if (!(GifApplication->ApplicationData = ReadDataSubBlocks(MemGif2, &(GifApplication->DataSize)))) + return (1); + /* + GifApplication->Terminator = 0; + */ - /* Check for a FILE stream error */ - /* - if (ferror(FpGif)) - return(-1); - */ + /* Check for a FILE stream error */ + /* + if (ferror(FpGif)) + return(-1); + */ - return(0); /* No FILE stream error occured */ + return (0); /* No FILE stream error occured */ } - /* ** Read a GIF Comment Extension block. ** @@ -319,22 +302,20 @@ ReadGifApplication( ** otherwise 0 if no error occured. */ int -ReadGifComment( - GIFCOMMENT *GifComment, /* Pointer to GIF Comment Extension structure */ - GIFBYTE **MemGif2 /* GIF image file input FILE stream */ - ) +ReadGifComment(GIFCOMMENT *GifComment, /* Pointer to GIF Comment Extension structure */ + GIFBYTE ** MemGif2 /* GIF image file input FILE stream */ +) { /* Read in the Plain Text data sub-blocks */ - if (!(GifComment->CommentData = ReadDataSubBlocks(MemGif2 , &(GifComment->DataSize)))) - return(1); + if (!(GifComment->CommentData = ReadDataSubBlocks(MemGif2, &(GifComment->DataSize)))) + return (1); GifComment->Terminator = 0; - return(0); /* No FILE stream error occured */ + return (0); /* No FILE stream error occured */ } - /* ** Read one or more GIF data sub-blocks and write the information ** to a buffer. @@ -347,55 +328,47 @@ ReadGifComment( */ static GIFBYTE * ReadDataSubBlocks(GIFBYTE **MemGif2, /* GIF image file input FILE stream */ - GIFWORD *DSize) + GIFWORD * DSize) { GIFBYTE *ptr1; /* Pointer used to "walk the heap" */ GIFBYTE *ptr2; /* Pointer used to mark the top of the heap */ - GIFBYTE dataSize; /* Size of the current data sub-block being read */ - GIFWORD bufSize; /* Total size of the Plain Text data buffer */ - int tempcount = 0; + GIFBYTE dataSize; /* Size of the current data sub-block being read */ + GIFWORD bufSize; /* Total size of the Plain Text data buffer */ + int tempcount = 0; - bufSize = 0; /* The output buffer is empty */ + bufSize = 0; /* The output buffer is empty */ - dataSize = *(*MemGif2)++; /* Get the size of the first sub-block */ + dataSize = *(*MemGif2)++; /* Get the size of the first sub-block */ /* Allocate initial data buffer */ - if (!(ptr1 = ptr2 = (GIFBYTE *) malloc((size_t)dataSize + 1))) { - printf("Out of memory. Allocation of memory for data sub-blocks for\neither Comment, Plain Text or Application Extensions failed"); - return((GIFBYTE *) NULL); - } - for (;;) - { - tempcount++; - bufSize += (dataSize); /* Running total of the buffer size */ - *DSize = bufSize; + if (!(ptr1 = ptr2 = (GIFBYTE *)malloc((size_t)dataSize + 1))) { + printf("Out of memory. Allocation of memory for data sub-blocks for\neither Comment, Plain Text or " + "Application Extensions failed"); + return ((GIFBYTE *)NULL); + } + for (;;) { + tempcount++; + bufSize += (dataSize); /* Running total of the buffer size */ + *DSize = bufSize; #ifdef COMMENTED_OUT - *ptr1++ = dataSize; /* Write the data count */ -#endif /* COMMENTED_OUT */ - while (dataSize--) /* Read/write the Plain Text data */ - *ptr1++ = *(*MemGif2)++; + *ptr1++ = dataSize; /* Write the data count */ +#endif /* COMMENTED_OUT */ + while (dataSize--) /* Read/write the Plain Text data */ + *ptr1++ = *(*MemGif2)++; /* Check if there is another data sub-block */ if ((dataSize = *(*MemGif2)++) == 0) - break; /* Block Terminator encountered */ + break; /* Block Terminator encountered */ /* Increase the buffer size to accomodate the next sub-block */ - if (!(ptr1 = ptr2 = (GIFBYTE *) realloc(ptr2, bufSize + dataSize + 1))) - return((GIFBYTE *) NULL); - - - ptr1 += bufSize; /* Move pointer to the end of the data */ - + if (!(ptr1 = ptr2 = (GIFBYTE *)realloc(ptr2, bufSize + dataSize + 1))) + return ((GIFBYTE *)NULL); + ptr1 += bufSize; /* Move pointer to the end of the data */ } *ptr1++ = '\0'; - return(ptr2); /* Return a pointer to the sub-block data */ + return (ptr2); /* Return a pointer to the sub-block data */ } - - - - - diff --git a/hl/tools/gif2h5/h52gifgentst.c b/hl/tools/gif2h5/h52gifgentst.c index c0ad151..020fe26 100644 --- a/hl/tools/gif2h5/h52gifgentst.c +++ b/hl/tools/gif2h5/h52gifgentst.c @@ -30,11 +30,11 @@ */ #define FILENAME "h52giftst.h5" -#define WIDTH 400 -#define HEIGHT 200 -#define PAL_ENTRIES 256 -#define IMAGE1_NAME "image" -#define PAL_NAME "palette" +#define WIDTH 400 +#define HEIGHT 200 +#define PAL_ENTRIES 256 +#define IMAGE1_NAME "image" +#define PAL_NAME "palette" /*------------------------------------------------------------------------- * Function: main @@ -44,65 +44,61 @@ *------------------------------------------------------------------------- */ -int main(void) +int +main(void) { - hid_t fid; - int i, j, n, space; + hid_t fid; + int i, j, n, space; unsigned char *buf; - unsigned char pal[ PAL_ENTRIES * 3 ]; /* palette array */ - hsize_t pal_dims[2] = {PAL_ENTRIES,3}; /* palette dimensions */ - hsize_t width = WIDTH; - hsize_t height = HEIGHT; + unsigned char pal[PAL_ENTRIES * 3]; /* palette array */ + hsize_t pal_dims[2] = {PAL_ENTRIES, 3}; /* palette dimensions */ + hsize_t width = WIDTH; + hsize_t height = HEIGHT; /* Allocate buffer */ - if(NULL == (buf = (unsigned char *)malloc(WIDTH * HEIGHT))) + if (NULL == (buf = (unsigned char *)malloc(WIDTH * HEIGHT))) return EXIT_FAILURE; /* create a file */ - if ((fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) + if ((fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) return EXIT_FAILURE; /* create an image */ - space = WIDTH*HEIGHT / PAL_ENTRIES; - for (i=0, j=0, n=0; i < WIDTH*HEIGHT; i++, j++ ) - { + space = WIDTH * HEIGHT / PAL_ENTRIES; + for (i = 0, j = 0, n = 0; i < WIDTH * HEIGHT; i++, j++) { buf[i] = (unsigned char)n; - if ( j > space ) - { + if (j > space) { n++; - j=0; + j = 0; } - } /* make the image */ - if (H5IMmake_image_8bit( fid, IMAGE1_NAME, width, height, buf )<0) + if (H5IMmake_image_8bit(fid, IMAGE1_NAME, width, height, buf) < 0) return EXIT_FAILURE; - /*------------------------------------------------------------------------- - * define a palette, blue to red tones - *------------------------------------------------------------------------- - */ - for ( i=0, n=0; i<PAL_ENTRIES*3; i+=3, n++) - { - pal[i] = (unsigned char)n; /* red */ - pal[i+1] = (unsigned char)0; /* green */ - pal[i+2] = (unsigned char)(255-n); /* blue */ + /*------------------------------------------------------------------------- + * define a palette, blue to red tones + *------------------------------------------------------------------------- + */ + for (i = 0, n = 0; i < PAL_ENTRIES * 3; i += 3, n++) { + pal[i] = (unsigned char)n; /* red */ + pal[i + 1] = (unsigned char)0; /* green */ + pal[i + 2] = (unsigned char)(255 - n); /* blue */ } /* make a palette */ - if (H5IMmake_palette( fid, PAL_NAME, pal_dims, pal )<0) + if (H5IMmake_palette(fid, PAL_NAME, pal_dims, pal) < 0) return EXIT_FAILURE; /* attach the palette to the image */ - if (H5IMlink_palette( fid, IMAGE1_NAME, PAL_NAME )<0) + if (H5IMlink_palette(fid, IMAGE1_NAME, PAL_NAME) < 0) return EXIT_FAILURE; - if(H5Fclose(fid)<0) + if (H5Fclose(fid) < 0) return EXIT_FAILURE; free(buf); return EXIT_SUCCESS; } - diff --git a/hl/tools/gif2h5/hdf2gif.c b/hl/tools/gif2h5/hdf2gif.c index 1833c92..936fd21 100644 --- a/hl/tools/gif2h5/hdf2gif.c +++ b/hl/tools/gif2h5/hdf2gif.c @@ -21,9 +21,8 @@ /* Name of tool */ #define PROGRAMNAME "hdf2gif" -#define IMAGE_WIDTH_MAX 65535 /* unsigned 16bits integer */ -#define IMAGE_HEIGHT_MAX 65535 /* unsigned 16bits integer */ - +#define IMAGE_WIDTH_MAX 65535 /* unsigned 16bits integer */ +#define IMAGE_HEIGHT_MAX 65535 /* unsigned 16bits integer */ int EndianOrder; @@ -31,8 +30,8 @@ static void putword(int w, FILE *fp) { /* writes a 16-bit integer in GIF order (LSB first) */ - fputc(w &0xff, fp); - fputc((w>>8)&0xff,fp); + fputc(w & 0xff, fp); + fputc((w >> 8) & 0xff, fp); } static void @@ -42,18 +41,18 @@ usage(void) fprintf(stdout, " h52gif -V \n"); fprintf(stdout, " Print HDF5 library version and exit\n"); printf("h52gif expects *at least* one h5_image.\n"); - } static void leave(int ret) { - h5tools_close(); - HDexit(ret); + h5tools_close(); + HDexit(ret); } FILE *fpGif = NULL; -int main(int argc , char **argv) +int +main(int argc, char **argv) { GIFBYTE *Image; @@ -61,25 +60,25 @@ int main(int argc , char **argv) GIFCHAR *HDFName = NULL; GIFCHAR *GIFName = NULL; - GIFBYTE* b; + GIFBYTE *b; - GIFBYTE GlobalPalette[256][3]; - GIFBYTE Red[256]; - GIFBYTE Green[256]; - GIFBYTE Blue[256]; + GIFBYTE GlobalPalette[256][3]; + GIFBYTE Red[256]; + GIFBYTE Green[256]; + GIFBYTE Blue[256]; - int RWidth, RHeight; - int ColorMapSize, InitCodeSize, Background, BitsPerPixel; - int j,nc; - int i; - int numcols = 0; + int RWidth, RHeight; + int ColorMapSize, InitCodeSize, Background, BitsPerPixel; + int j, nc; + int i; + int numcols = 0; - GIFBYTE pc2nc[256] , r1[256] , g1[256] , b1[256]; + GIFBYTE pc2nc[256], r1[256], g1[256], b1[256]; - int arg_index = 2; - int bool_is_image = 0; /* 0 = false , 1 = true */ - char *image_name = NULL; - int idx; + int arg_index = 2; + int bool_is_image = 0; /* 0 = false , 1 = true */ + char *image_name = NULL; + int idx; h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); @@ -87,15 +86,12 @@ int main(int argc , char **argv) /* Initialize h5tools lib */ h5tools_init(); - if ( argv[1] && (strcmp("-V",argv[1])==0) ) - { + if (argv[1] && (strcmp("-V", argv[1]) == 0)) { print_version("gif2h5"); h5tools_setstatus(EXIT_SUCCESS); } - - if (argc < 4) - { + if (argc < 4) { /* they didn't supply at least one image -- bail */ usage(); h5tools_setstatus(EXIT_FAILURE); @@ -105,19 +101,17 @@ int main(int argc , char **argv) GIFName = argv[2]; /* get the options */ - while (arg_index++ < argc - 1) - { - if (!strcmp(argv[arg_index] , "-i")) { + while (arg_index++ < argc - 1) { + if (!strcmp(argv[arg_index], "-i")) { bool_is_image = 1; continue; } - if (bool_is_image) - { + if (bool_is_image) { /* allocate space to store the image name */ size_t len = strlen(argv[arg_index]); - image_name = (GIFCHAR*) malloc( len + 1); - strcpy(image_name , argv[arg_index]); + image_name = (GIFCHAR *)malloc(len + 1); + strcpy(image_name, argv[arg_index]); bool_is_image = 0; continue; @@ -129,80 +123,72 @@ int main(int argc , char **argv) goto out; } - /* Do Endian Order testing and set Endian Order */ - idx = 0x0001; - b = (GIFBYTE *) &idx; - EndianOrder = (b[0] ? 1:0); + /* Do Endian Order testing and set Endian Order */ + idx = 0x0001; + b = (GIFBYTE *)&idx; + EndianOrder = (b[0] ? 1 : 0); - if (!(fpGif = fopen(GIFName , "wb"))) - { + if (!(fpGif = fopen(GIFName, "wb"))) { printf("Error opening gif file for output. Aborting.\n"); goto out; } Background = 0; { - hsize_t width, height, planes; - hid_t fid; - char interlace[20]; - hssize_t npals; - hsize_t pal_dims[2]; + hsize_t width, height, planes; + hid_t fid; + char interlace[20]; + hssize_t npals; + hsize_t pal_dims[2]; unsigned char *pal; - if ((fid = H5Fopen(HDFName , H5F_ACC_RDONLY , H5P_DEFAULT)) < 0) - { - fprintf(stderr , "Unable to open HDF file for input. Aborting.\n"); + if ((fid = H5Fopen(HDFName, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) { + fprintf(stderr, "Unable to open HDF file for input. Aborting.\n"); goto out; } /* 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"); + 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); + 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) - { + if (planes > 1) { fprintf(stderr, "Cannot handle multiple planes image\n"); goto out; } - Image = (GIFBYTE*) malloc( (size_t) width * (size_t) height ); + 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"); + 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"); + 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] ); + pal = (GIFBYTE *)malloc((size_t)pal_dims[0] * (size_t)pal_dims[1]); - if ( H5IMget_palette( fid, image_name, 0, pal ) < 0 ) + if (H5IMget_palette(fid, image_name, 0, pal) < 0) goto out; - numcols = (int) pal_dims[0]; + numcols = (int)pal_dims[0]; - for (i = 0, j = 0 ; i < numcols ; j+=3, i++) - { + for (i = 0, j = 0; i < numcols; j += 3, i++) { GlobalPalette[i][0] = pal[j]; - GlobalPalette[i][1] = pal[j+1]; - GlobalPalette[i][2] = pal[j+2]; + GlobalPalette[i][1] = pal[j + 1]; + GlobalPalette[i][2] = pal[j + 2]; } free(pal); @@ -213,7 +199,6 @@ int main(int argc , char **argv) RWidth = (int)width; RHeight = (int)height; - /* * If the first image does not have a palette, I make my own global * color table Obviously this is not the best thing to do, better @@ -223,62 +208,52 @@ int main(int argc , char **argv) * palette * 2. Check for palettes in any of the other images. */ - if (!npals) - { + if (!npals) { numcols = 256; - for (i = 0 ; i < numcols ; i++) - { - Red[i] = (GIFBYTE)(255 - i); + for (i = 0; i < numcols; i++) { + Red[i] = (GIFBYTE)(255 - i); Green[i] = (GIFBYTE)(255 - i); - Blue[i] = (GIFBYTE)(255 - i); + Blue[i] = (GIFBYTE)(255 - i); } } - else - { - for (i = 0 ; i < numcols ; i++) - { - Red[i] = GlobalPalette[i][0]; + else { + for (i = 0; i < numcols; i++) { + Red[i] = GlobalPalette[i][0]; Green[i] = GlobalPalette[i][1]; - Blue[i] = GlobalPalette[i][2]; + Blue[i] = GlobalPalette[i][2]; } } - for (i = 0; i < numcols; i++) - { + for (i = 0; i < numcols; i++) { pc2nc[i] = r1[i] = g1[i] = b1[i] = 0; } /* compute number of unique colors */ nc = 0; - for (i = 0; i < numcols; i++) - { + for (i = 0; i < numcols; i++) { /* see if color #i is already used */ - for (j = 0; j < i; j++) - { + for (j = 0; j < i; j++) { if (Red[i] == Red[j] && Green[i] == Green[j] && Blue[i] == Blue[j]) break; } - if (j==i) - { + if (j == i) { /* wasn't found */ pc2nc[i] = (GIFBYTE)nc; - r1[nc] = Red[i]; - g1[nc] = Green[i]; - b1[nc] = Blue[i]; + r1[nc] = Red[i]; + g1[nc] = Green[i]; + b1[nc] = Blue[i]; nc++; } - else - { + else { pc2nc[i] = pc2nc[j]; } } /* figure out 'BitsPerPixel' */ - for (i = 1; i < 8; i++) - { - if ((1<<i) >= nc) + for (i = 1; i < 8; i++) { + if ((1 << i) >= nc) break; } @@ -290,59 +265,54 @@ int main(int argc , char **argv) else InitCodeSize = BitsPerPixel; - if (!fpGif) - { - fprintf(stderr, "WriteGIF: file not open for writing\n" ); + if (!fpGif) { + fprintf(stderr, "WriteGIF: file not open for writing\n"); goto out; } + fwrite("GIF87a", sizeof(char), 6, fpGif); /* the GIF magic number */ - fwrite("GIF87a", sizeof( char ), 6, fpGif); /* the GIF magic number */ - - putword(RWidth, fpGif); /* screen descriptor */ + putword(RWidth, fpGif); /* screen descriptor */ putword(RHeight, fpGif); - i = 0x00; /* No, there is no color map */ - i |= (8-1)<<4; /* OR in the color resolution (hardwired 8) */ - i |= (BitsPerPixel - 1); /* OR in the # of bits per pixel */ - fputc(i,fpGif); - - fputc(Background,fpGif); /* background color */ - fputc(0, fpGif); /* future expansion byte */ + i = 0x00; /* No, there is no color map */ + i |= (8 - 1) << 4; /* OR in the color resolution (hardwired 8) */ + i |= (BitsPerPixel - 1); /* OR in the # of bits per pixel */ + fputc(i, fpGif); + fputc(Background, fpGif); /* background color */ + fputc(0, fpGif); /* future expansion byte */ /* * Put Image Descriptor * Hardwiring Left Offset and Top Offset to 0x00 */ - fputc(0x2c , fpGif); - putword(0x00 , fpGif); - putword(0x00 , fpGif); - putword(RWidth , fpGif); - putword(RHeight , fpGif); + fputc(0x2c, fpGif); + putword(0x00, fpGif); + putword(0x00, fpGif); + putword(RWidth, fpGif); + putword(RHeight, fpGif); /* since we always have a local color palette ... */ - fputc((0x80 | (BitsPerPixel - 1)) , fpGif); + fputc((0x80 | (BitsPerPixel - 1)), fpGif); - for (i = 0; i < ColorMapSize; i++) - { + for (i = 0; i < ColorMapSize; i++) { /* write out Global colormap */ fputc(r1[i], fpGif); fputc(g1[i], fpGif); fputc(b1[i], fpGif); } - fputc(InitCodeSize , fpGif); + fputc(InitCodeSize, fpGif); - i = hdfWriteGIF(fpGif , Image , 0 , RHeight , RWidth , r1, g1 , b1 , pc2nc , 256 , 8 , BitsPerPixel); + i = hdfWriteGIF(fpGif, Image, 0, RHeight, RWidth, r1, g1, b1, pc2nc, 256, 8, BitsPerPixel); fputc(0x00, fpGif); free(Image); } - if (fputc(';',fpGif) == EOF) - { + if (fputc(';', fpGif) == EOF) { /* Write GIF file terminator */ - fprintf(stderr , "Error!"); + fprintf(stderr, "Error!"); goto out; } @@ -353,7 +323,6 @@ int main(int argc , char **argv) leave(h5tools_getstatus()); - out: if (fpGif != NULL) diff --git a/hl/tools/gif2h5/hdfgifwr.c b/hl/tools/gif2h5/hdfgifwr.c index d44ff7a..7be68dc 100644 --- a/hl/tools/gif2h5/hdfgifwr.c +++ b/hl/tools/gif2h5/hdfgifwr.c @@ -44,7 +44,6 @@ * Joe Orost (decvax!vax135!petsd!joe) *****************************************************************/ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -65,32 +64,32 @@ static void flush_char(void); #else static void compress(), output(), cl_block(), cl_hash(); static void char_init(), char_out(), flush_char(); -#endif /* __STDC__ */ +#endif /* __STDC__ */ static byte pc2nc[256]; /***********************************************************************/ static unsigned long cur_accum = 0; -static int cur_bits = 0; +static int cur_bits = 0; -#define MAXCODE(n_bits) ( (1 << (n_bits)) - 1) -#define XV_BITS 12 /* BITS was already defined on some systems */ -#define HSIZE 5003 /* 80% occupancy */ +#define MAXCODE(n_bits) ((1 << (n_bits)) - 1) +#define XV_BITS 12 /* BITS was already defined on some systems */ +#define HSIZE 5003 /* 80% occupancy */ -typedef unsigned char char_type; +typedef unsigned char char_type; static int n_bits; /* number of bits/code */ 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; -static unsigned short *codetab; +static count_int * htab; +static unsigned short *codetab; -#define HashTabOf(i) htab[i] -#define CodeTabOf(i) codetab[i] +#define HashTabOf(i) htab[i] +#define CodeTabOf(i) codetab[i] -static int hsize = HSIZE; /* for dynamic table sizing */ +static int hsize = HSIZE; /* for dynamic table sizing */ /* * To save much memory, we overlay the table used by compress() with those @@ -101,7 +100,7 @@ static int hsize = HSIZE; /* for dynamic table sizing */ * used to be 8000 characters). */ -static int free_ent = 0; /* first unused entry */ +static int free_ent = 0; /* first unused entry */ /* * block compression parameters -- after all codes are used up, @@ -109,8 +108,8 @@ static int free_ent = 0; /* first unused entry */ */ static int clear_flg = 0; -static long int in_count = 1; /* length of input */ -static long int out_count = 0; /* # of codes output (for debugging) */ +static long int in_count = 1; /* length of input */ +static long int out_count = 0; /* # of codes output (for debugging) */ /* * compress stdin to stdout @@ -128,19 +127,19 @@ static long int out_count = 0; /* # of codes output (for debugging) */ * about this implementation to ames!jaw. */ -static int g_init_bits; +static int g_init_bits; 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 +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; + int InitCodeSize; + int i; byte *pic8 = pic; if (!(htab = calloc(HSIZE, sizeof(count_int)))) { @@ -153,15 +152,15 @@ int hdfWriteGIF(FILE *fp, byte *pic, int ptype, int w, int h, byte *rmap, } /* Shut compiler up... */ - ptype=ptype; - rmap=rmap; - gmap=gmap; - bmap=bmap; - numcols=numcols; - colorstyle=colorstyle; + ptype = ptype; + rmap = rmap; + gmap = gmap; + bmap = bmap; + numcols = numcols; + colorstyle = colorstyle; for (i = 0; i < 256; i++) { - pc2nc[i] = pc2ncmap[i]; + pc2nc[i] = pc2ncmap[i]; } if (BitsPerPixel <= 1) @@ -170,11 +169,11 @@ int hdfWriteGIF(FILE *fp, byte *pic, int ptype, int w, int h, byte *rmap, InitCodeSize = BitsPerPixel; if (!fp) { - fprintf(stderr, "WriteGIF: file not open for writing\n"); + fprintf(stderr, "WriteGIF: file not open for writing\n"); return 1; } - compress(InitCodeSize+1, fp, pic8, w*h); + compress(InitCodeSize + 1, fp, pic8, w * h); free(htab); free(codetab); @@ -182,19 +181,20 @@ int hdfWriteGIF(FILE *fp, byte *pic, int ptype, int w, int h, byte *rmap, if (ferror(fp)) return -1; - return 0 ; + return 0; } /********************************************************/ -static void compress(int init_bits, FILE *outfile, byte *data, int len) +static void +compress(int init_bits, FILE *outfile, byte *data, int len) { register long fcode; - register int i = 0; - register int c; - register int ent; - register int disp; - register int hsize_reg; - register int hshift; + register int i = 0; + register int c; + register int ent; + register int disp; + register int hsize_reg; + register int hshift; /* * Set up the globals: g_init_bits - initial number of bits g_outfile - @@ -204,38 +204,38 @@ static void compress(int init_bits, FILE *outfile, byte *data, int len) g_outfile = outfile; /* initialize 'compress' globals */ - maxbits = XV_BITS; - maxmaxcode = 1<<XV_BITS; - hsize = HSIZE; - free_ent = 0; - clear_flg = 0; - in_count = 1; - out_count = 0; - cur_accum = 0; - cur_bits = 0; + maxbits = XV_BITS; + maxmaxcode = 1 << XV_BITS; + hsize = HSIZE; + free_ent = 0; + clear_flg = 0; + in_count = 1; + out_count = 0; + cur_accum = 0; + cur_bits = 0; /* Set up the necessary values */ out_count = 0; clear_flg = 0; - in_count = 1; - maxcode = MAXCODE(n_bits = g_init_bits); + in_count = 1; + maxcode = MAXCODE(n_bits = g_init_bits); ClearCode = (1 << (init_bits - 1)); - EOFCode = ClearCode + 1; - free_ent = ClearCode + 2; + EOFCode = ClearCode + 1; + free_ent = ClearCode + 2; char_init(); ent = pc2nc[*data++]; len--; hshift = 0; - for (fcode = (long)hsize; fcode < 65536L; fcode *= 2L ) + for (fcode = (long)hsize; fcode < 65536L; fcode *= 2L) hshift++; hshift = 8 - hshift; /* set hash code range bound */ hsize_reg = hsize; - cl_hash( (count_int) hsize_reg); /* clear hash table */ + cl_hash((count_int)hsize_reg); /* clear hash table */ output(ClearCode); @@ -244,32 +244,33 @@ static void compress(int init_bits, FILE *outfile, byte *data, int len) len--; in_count++; - fcode = (long)(((long) c << maxbits) + ent); - i = (((int) c << hshift) ^ ent); /* xor hashing */ + fcode = (long)(((long)c << maxbits) + ent); + i = (((int)c << hshift) ^ ent); /* xor hashing */ - if ( HashTabOf (i) == fcode ) { - ent = CodeTabOf (i); + if (HashTabOf(i) == fcode) { + ent = CodeTabOf(i); continue; - } else if ( (long)HashTabOf (i) < 0) { + } + else if ((long)HashTabOf(i) < 0) { /* empty slot */ goto nomatch; } - disp = hsize_reg - i; /* secondary hash (after G. Knott) */ + disp = hsize_reg - i; /* secondary hash (after G. Knott) */ - if ( i == 0 ) + if (i == 0) disp = 1; probe: if ((i -= disp) < 0) i += hsize_reg; - if (HashTabOf (i) == fcode) { - ent = CodeTabOf (i); + if (HashTabOf(i) == fcode) { + ent = CodeTabOf(i); continue; } - if ((long)HashTabOf (i) >= 0) + if ((long)HashTabOf(i) >= 0) goto probe; nomatch: @@ -278,9 +279,10 @@ nomatch: ent = c; if (free_ent < maxmaxcode) { - CodeTabOf (i) = (unsigned short)free_ent++; /* code -> hashtable */ - HashTabOf (i) = fcode; - } else { + CodeTabOf(i) = (unsigned short)free_ent++; /* code -> hashtable */ + HashTabOf(i) = fcode; + } + else { cl_block(); } } @@ -291,7 +293,6 @@ nomatch: output(EOFCode); } - /***************************************************************** * TAG( output ) * @@ -309,11 +310,8 @@ nomatch: * code in turn. When the buffer fills up empty it and start over. */ -static -unsigned long masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, - 0x001F, 0x003F, 0x007F, 0x00FF, - 0x01FF, 0x03FF, 0x07FF, 0x0FFF, - 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }; +static unsigned long masks[] = {0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, + 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF}; static void output(int code) @@ -327,8 +325,8 @@ output(int code) cur_bits += n_bits; - while( cur_bits >= 8 ) { - char_out( (int)((unsigned int) cur_accum & 0xff) ); + while (cur_bits >= 8) { + char_out((int)((unsigned int)cur_accum & 0xff)); cur_accum >>= 8; cur_bits -= 8; } @@ -339,12 +337,13 @@ output(int code) */ if (free_ent > maxcode || clear_flg) { if (clear_flg) { - maxcode = MAXCODE (n_bits = g_init_bits); + maxcode = MAXCODE(n_bits = g_init_bits); clear_flg = 0; - } else { + } + else { n_bits++; - if ( n_bits == maxbits ) + if (n_bits == maxbits) maxcode = maxmaxcode; else maxcode = MAXCODE(n_bits); @@ -353,17 +352,17 @@ output(int code) if (code == EOFCode) { /* At EOF, write the rest of the buffer */ - while( cur_bits > 0 ) { - char_out( (int)((unsigned int)cur_accum & 0xff) ); + while (cur_bits > 0) { + char_out((int)((unsigned int)cur_accum & 0xff)); cur_accum >>= 8; cur_bits -= 8; } flush_char(); - fflush( g_outfile ); + fflush(g_outfile); #ifdef FOO - if(ferror( g_outfile)) + if (ferror(g_outfile)) FatalError("unable to write GIF file"); #endif } @@ -371,45 +370,45 @@ output(int code) /********************************/ static void -cl_block(void) /* table clear for block compress */ +cl_block(void) /* table clear for block compress */ { /* Clear out the hash table */ - cl_hash((count_int) hsize); - free_ent = ClearCode + 2; + cl_hash((count_int)hsize); + free_ent = ClearCode + 2; clear_flg = 1; output(ClearCode); } /********************************/ static void -cl_hash(count_int hashsize) /* reset code table */ +cl_hash(count_int hashsize) /* reset code table */ { - count_int *htab_p = htab+hashsize; - long i, m1 = -1; + count_int *htab_p = htab + hashsize; + long i, m1 = -1; i = hashsize - 16; - do { /* might use Sys V memset(3) here */ - *(htab_p-16) = m1; - *(htab_p-15) = m1; - *(htab_p-14) = m1; - *(htab_p-13) = m1; - *(htab_p-12) = m1; - *(htab_p-11) = m1; - *(htab_p-10) = m1; - *(htab_p-9) = m1; - *(htab_p-8) = m1; - *(htab_p-7) = m1; - *(htab_p-6) = m1; - *(htab_p-5) = m1; - *(htab_p-4) = m1; - *(htab_p-3) = m1; - *(htab_p-2) = m1; - *(htab_p-1) = m1; + do { /* might use Sys V memset(3) here */ + *(htab_p - 16) = m1; + *(htab_p - 15) = m1; + *(htab_p - 14) = m1; + *(htab_p - 13) = m1; + *(htab_p - 12) = m1; + *(htab_p - 11) = m1; + *(htab_p - 10) = m1; + *(htab_p - 9) = m1; + *(htab_p - 8) = m1; + *(htab_p - 7) = m1; + *(htab_p - 6) = m1; + *(htab_p - 5) = m1; + *(htab_p - 4) = m1; + *(htab_p - 3) = m1; + *(htab_p - 2) = m1; + *(htab_p - 1) = m1; htab_p -= 16; } while ((i -= 16) >= 0); - for ( i += 16; i > 0; i-- ) + for (i += 16; i > 0; i--) *--htab_p = m1; } @@ -436,7 +435,7 @@ char_init(void) /* * Define the storage for the packet accumulator */ -static char accum[ 256 ]; +static char accum[256]; /* * Add a character to the end of the current packet, and if it is 254 @@ -445,7 +444,7 @@ static char accum[ 256 ]; static void char_out(int c) { - accum[ a_count++ ] = (char)c; + accum[a_count++] = (char)c; if (a_count >= 254) flush_char(); @@ -458,8 +457,8 @@ static void flush_char(void) { if (a_count > 0) { - fputc( a_count, g_outfile ); - fwrite( accum, (size_t)1, (size_t)a_count, g_outfile); + fputc(a_count, g_outfile); + fwrite(accum, (size_t)1, (size_t)a_count, g_outfile); a_count = 0; } } diff --git a/hl/tools/gif2h5/writehdf.c b/hl/tools/gif2h5/writehdf.c index c2933c5..0cf3926 100644 --- a/hl/tools/gif2h5/writehdf.c +++ b/hl/tools/gif2h5/writehdf.c @@ -37,21 +37,21 @@ int WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName) { - GIFHEAD gifHead; /* GIF Header structure */ - GIFIMAGEDESC *gifImageDesc; /* Logical Image Descriptor struct */ - int has_pal=0; + GIFHEAD gifHead; /* GIF Header structure */ + GIFIMAGEDESC *gifImageDesc; /* Logical Image Descriptor struct */ + int has_pal = 0; - long ImageCount; /* number of images */ + long ImageCount; /* number of images */ #ifdef UNUSED - long CommentCount, /* number of comments */ - ApplicationCount, /* number of application extensions */ - PlainTextCount; /* number of plain text extensions */ -#endif /* UNUSED */ + long CommentCount, /* number of comments */ + ApplicationCount, /* number of application extensions */ + PlainTextCount; /* number of plain text extensions */ +#endif /* UNUSED */ - char ImageName[256]; /* Image name for the Image */ + char ImageName[256]; /* Image name for the Image */ /* H5 variables */ - hid_t file_id; /* H5 file id */ + hid_t file_id; /* H5 file id */ /* temp counter */ int i; @@ -62,35 +62,36 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName) /* get some data from gifHead */ ImageCount = gifHead.ImageCount; #ifdef UNUSED - CommentCount = (GIFWORD)gifHead.CommentCount; + CommentCount = (GIFWORD)gifHead.CommentCount; ApplicationCount = (GIFWORD)gifHead.ApplicationCount; - PlainTextCount = (GIFWORD)gifHead.PlainTextCount; + PlainTextCount = (GIFWORD)gifHead.PlainTextCount; #endif /* UNUSED */ - if ((file_id = H5Fcreate(HDFName , H5F_ACC_TRUNC , H5P_DEFAULT , H5P_DEFAULT)) < 0) { + if ((file_id = H5Fcreate(HDFName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) { /* error occured opening the HDF File for write */ - fprintf(stderr , "HDF file could not be opened for writing\n"); - fprintf(stderr , "NOTE: GIF file must be present in the same directory as the binary on UNIX systems.\n"); + fprintf(stderr, "HDF file could not be opened for writing\n"); + fprintf(stderr, + "NOTE: GIF file must be present in the same directory as the binary on UNIX systems.\n"); exit(1); } /* first create the global palette if there is one */ if (gifHead.PackedField & 0x80) { /* global palette exists */ - hsize_t dims[2]; /* specify the dimensions of the palette */ + hsize_t dims[2]; /* specify the dimensions of the palette */ /* size of the palette is tablesize (rows) X 3 (columns) */ dims[0] = gifHead.TableSize; dims[1] = 3; /* make a palette */ - if (H5IMmake_palette(file_id,PAL_NAME,dims,(unsigned char *)gifHead.HDFPalette)<0) - return -1; + if (H5IMmake_palette(file_id, PAL_NAME, dims, (unsigned char *)gifHead.HDFPalette) < 0) + return -1; - has_pal=1; + has_pal = 1; } - for(i = 0; i < ImageCount; i++) { - hsize_t dims[2]; /* dimensions for the dataset */ + for (i = 0; i < ImageCount; i++) { + hsize_t dims[2]; /* dimensions for the dataset */ /* get the gifImageDesc */ gifImageDesc = GifMemoryStruct.GifImageDesc[i]; @@ -99,26 +100,24 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName) dims[1] = gifImageDesc->ImageWidth; /* create the image name */ - sprintf(ImageName , "Image%d" , i); + sprintf(ImageName, "Image%d", i); /* write image */ - if (H5IMmake_image_8bit(file_id,ImageName,dims[1],dims[0],(gifImageDesc->Image))<0) - return -1; + if (H5IMmake_image_8bit(file_id, ImageName, dims[1], dims[0], (gifImageDesc->Image)) < 0) + return -1; /* attach the palette to the image dataset */ - if (has_pal) - { - if (H5IMlink_palette(file_id,ImageName,PAL_NAME)<0) + if (has_pal) { + if (H5IMlink_palette(file_id, ImageName, PAL_NAME) < 0) return -1; } } /* close the H5 file */ if (H5Fclose(file_id) < 0) { - fprintf(stderr , "Could not close HDF5 file. Aborting...\n"); + fprintf(stderr, "Could not close HDF5 file. Aborting...\n"); return -1; } return 0; } - diff --git a/hl/tools/h5watch/extend_dset.c b/hl/tools/h5watch/extend_dset.c index 6b59ea1..8677601 100644 --- a/hl/tools/h5watch/extend_dset.c +++ b/hl/tools/h5watch/extend_dset.c @@ -16,18 +16,18 @@ /* * Extending datasets in WATCH.h5 generated by h5watchgentest.c */ -#define DSET_ONE "DSET_ONE" -#define DSET_TWO "DSET_TWO" -#define DSET_CMPD "DSET_CMPD" -#define DSET_CMPD_ESC "DSET_CMPD_ESC" -#define DSET_CMPD_TWO "DSET_CMPD_TWO" -#define DSET_ALLOC_LATE "DSET_ALLOC_LATE" +#define DSET_ONE "DSET_ONE" +#define DSET_TWO "DSET_TWO" +#define DSET_CMPD "DSET_CMPD" +#define DSET_CMPD_ESC "DSET_CMPD_ESC" +#define DSET_CMPD_TWO "DSET_CMPD_TWO" +#define DSET_ALLOC_LATE "DSET_ALLOC_LATE" #define DSET_ALLOC_EARLY "DSET_ALLOC_EARLY" /* The message sent by this process (extend_dset) to the test script to start "h5watch" */ -#define WRITER_MESSAGE "writer_message" +#define WRITER_MESSAGE "writer_message" /* The message received from the test script to start extending dataset */ -#define READER_MESSAGE "reader_message" +#define READER_MESSAGE "reader_message" /* Size of data buffer */ #define TEST_BUF_SIZE 100 @@ -35,7 +35,6 @@ static herr_t extend_dset_two(const char *file, char *dname, int action1, int action2); static herr_t extend_dset_one(const char *file, char *dname, int action); - /* Data structures for datasets with compound data type */ typedef struct sub22_t { int a; @@ -44,9 +43,9 @@ typedef struct sub22_t { } sub22_t; typedef struct sub2_t { - int a; + int a; sub22_t b; - int c; + int c; } sub2_t; typedef struct sub4_t { @@ -55,7 +54,7 @@ typedef struct sub4_t { } sub4_t; typedef struct set_t { - int field1; + int field1; sub2_t field2; double field3; sub4_t field4; @@ -72,67 +71,67 @@ typedef struct set_t { static herr_t extend_dset_two(const char *file, char *dname, int action1, int action2) { - hid_t fid = -1; /* file id */ - hid_t fapl = -1; /* file access property list id */ - hid_t did = -1; /* dataset id */ - hid_t sid = -1; /* dataspace id */ - hid_t dtid = -1; /* dataset's datatype id */ - int ndims; /* # of dimension sizes */ - unsigned i; /* local index variable */ - hsize_t ext_dims[2]; /* new dimension sizes after extension */ - hsize_t cur_dims[2]; /* current dimension sizes */ - size_t dtype_size; /* size of the dataset's datatype */ - unsigned num_elmts; /* number of elements in the dataset */ - int *ibuf = NULL; /* buffer for storing retrieved elements (integer) */ - set_t *cbuf = NULL; /* buffer for storing retrieved elemnets (compound) */ + hid_t fid = -1; /* file id */ + hid_t fapl = -1; /* file access property list id */ + hid_t did = -1; /* dataset id */ + hid_t sid = -1; /* dataspace id */ + hid_t dtid = -1; /* dataset's datatype id */ + int ndims; /* # of dimension sizes */ + unsigned i; /* local index variable */ + hsize_t ext_dims[2]; /* new dimension sizes after extension */ + hsize_t cur_dims[2]; /* current dimension sizes */ + size_t dtype_size; /* size of the dataset's datatype */ + unsigned num_elmts; /* number of elements in the dataset */ + int * ibuf = NULL; /* buffer for storing retrieved elements (integer) */ + set_t * cbuf = NULL; /* buffer for storing retrieved elemnets (compound) */ /* Allocate memory */ - if(NULL == (ibuf = (int *)HDcalloc(TEST_BUF_SIZE, sizeof(int)))) + if (NULL == (ibuf = (int *)HDcalloc(TEST_BUF_SIZE, sizeof(int)))) goto error; - if(NULL == (cbuf = (set_t *)HDcalloc(TEST_BUF_SIZE, sizeof(set_t)))) + if (NULL == (cbuf = (set_t *)HDcalloc(TEST_BUF_SIZE, sizeof(set_t)))) goto error; /* Create a copy of file access property list */ - if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) + if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) goto error; /* Set to use the latest library format */ - if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) + if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) goto error; /* Open the file and dataset with SWMR write */ - if((fid = H5Fopen(file, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0) + if ((fid = H5Fopen(file, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0) goto error; - if((did = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) + if ((did = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) goto error; /* Send message to the test script to start "h5watch" */ h5_send_message(WRITER_MESSAGE, NULL, NULL); - if((sid = H5Dget_space(did)) < 0) + if ((sid = H5Dget_space(did)) < 0) goto error; - if((ndims = H5Sget_simple_extent_ndims(sid)) < 0) + if ((ndims = H5Sget_simple_extent_ndims(sid)) < 0) goto error; /* Get the size of the dataset's datatype */ - if((dtype_size = H5LDget_dset_type_size(did, NULL)) == 0) + if ((dtype_size = H5LDget_dset_type_size(did, NULL)) == 0) goto error; /* Get the dataset's data type */ - if((dtid = H5Tget_native_type(H5Dget_type(did), H5T_DIR_DEFAULT)) < 0) + if ((dtid = H5Tget_native_type(H5Dget_type(did), H5T_DIR_DEFAULT)) < 0) goto error; /* Wait for message from the test script to start extending dataset */ - if(h5_wait_message(READER_MESSAGE) < 0) + if (h5_wait_message(READER_MESSAGE) < 0) goto error; /* sleep to emulate about 2 seconds of application operation */ HDsleep(2); /* Get current dimension sizes */ - if(H5LDget_dset_dims(did, cur_dims) < 0) + if (H5LDget_dset_dims(did, cur_dims) < 0) goto error; /* Set up the new extended dimension sizes */ @@ -140,68 +139,74 @@ extend_dset_two(const char *file, char *dname, int action1, int action2) ext_dims[1] = cur_dims[1] + (hsize_t)action2; /* Extend the dataset */ - if(H5Dset_extent(did, ext_dims) < 0) + if (H5Dset_extent(did, ext_dims) < 0) goto error; num_elmts = 1; - for(i = 0; i < (unsigned)ndims; i++) + for (i = 0; i < (unsigned)ndims; i++) num_elmts *= (unsigned)ext_dims[i]; /* Compound type */ - if(!HDstrcmp(dname, DSET_CMPD_TWO)) { + if (!HDstrcmp(dname, DSET_CMPD_TWO)) { HDmemset(cbuf, 0, TEST_BUF_SIZE * sizeof(set_t)); - for(i = 0; i < num_elmts; i++) { - cbuf[i].field1 = action1; - cbuf[i].field2.a = action1; - cbuf[i].field2.c = action1; + for (i = 0; i < num_elmts; i++) { + cbuf[i].field1 = action1; + cbuf[i].field2.a = action1; + cbuf[i].field2.c = action1; cbuf[i].field2.b.a = action1; cbuf[i].field2.b.b = action1; cbuf[i].field2.b.c = action1; - cbuf[i].field3 = action1; - cbuf[i].field4.a = action1; - cbuf[i].field4.b = action1; + cbuf[i].field3 = action1; + cbuf[i].field4.a = action1; + cbuf[i].field4.b = action1; } /* end for */ - /* Write to the dataset */ - if(H5Dwrite(did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, cbuf) < 0) + /* Write to the dataset */ + if (H5Dwrite(did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, cbuf) < 0) goto error; - - } else { /* Integer type */ + } + else { /* Integer type */ HDmemset(ibuf, 0, TEST_BUF_SIZE * sizeof(int)); - for(i = 0; i < num_elmts; i++) + for (i = 0; i < num_elmts; i++) ibuf[i] = action1; /* Write to the dataset */ - if(H5Dwrite(did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, ibuf) < 0) + if (H5Dwrite(did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, ibuf) < 0) goto error; } /* end if-else */ - if(H5Dflush(did) < 0) + if (H5Dflush(did) < 0) goto error; /* Closing */ - if(H5Tclose(dtid) < 0) goto error; - if(H5Dclose(did) < 0) goto error; - if(H5Pclose(fapl) < 0) goto error; - if(H5Fclose(fid) < 0) goto error; + if (H5Tclose(dtid) < 0) + goto error; + if (H5Dclose(did) < 0) + goto error; + if (H5Pclose(fapl) < 0) + goto error; + if (H5Fclose(fid) < 0) + goto error; - if(ibuf) HDfree(ibuf); - if(cbuf) HDfree(cbuf); + if (ibuf) + HDfree(ibuf); + if (cbuf) + HDfree(cbuf); return SUCCEED; error: H5E_BEGIN_TRY - H5Tclose(dtid); - H5Dclose(did); - H5Pclose(fapl); - H5Fclose(fid); + H5Tclose(dtid); + H5Dclose(did); + H5Pclose(fapl); + H5Fclose(fid); H5E_END_TRY - if(ibuf) + if (ibuf) HDfree(ibuf); - if(cbuf) + if (cbuf) HDfree(cbuf); return FAIL; @@ -219,98 +224,98 @@ error: static herr_t extend_dset_one(const char *file, char *dname, int action) { - hid_t fid = -1; /* file id */ - hid_t fapl = -1; /* file access property list id */ - hid_t did = -1; /* dataset id */ - hid_t dtid = -1; /* dataset's datatype id */ - hid_t sid = -1; /* dataspace id */ - hid_t mid = -1; /* memory space id */ - int i; /* local index variable */ - hsize_t cur_dims[1]; /* current dimension sizes */ - hsize_t ext_dims[1]; /* new dimension sizes after extension */ - hsize_t offset[1]; /* starting offsets of appended data */ - hsize_t count[1]; /* dimension sizes of appended data */ - size_t dtype_size; /* size of the dataset's datatype */ - int *ibuf = NULL; /* buffer for storing retrieved elements (integer) */ - set_t *cbuf = NULL; /* buffer for storing retrieved elemnets (compound) */ + hid_t fid = -1; /* file id */ + hid_t fapl = -1; /* file access property list id */ + hid_t did = -1; /* dataset id */ + hid_t dtid = -1; /* dataset's datatype id */ + hid_t sid = -1; /* dataspace id */ + hid_t mid = -1; /* memory space id */ + int i; /* local index variable */ + hsize_t cur_dims[1]; /* current dimension sizes */ + hsize_t ext_dims[1]; /* new dimension sizes after extension */ + hsize_t offset[1]; /* starting offsets of appended data */ + hsize_t count[1]; /* dimension sizes of appended data */ + size_t dtype_size; /* size of the dataset's datatype */ + int * ibuf = NULL; /* buffer for storing retrieved elements (integer) */ + set_t * cbuf = NULL; /* buffer for storing retrieved elemnets (compound) */ /* Allocate memory */ - if(NULL == (ibuf = (int *)HDcalloc(TEST_BUF_SIZE, sizeof(int)))) + if (NULL == (ibuf = (int *)HDcalloc(TEST_BUF_SIZE, sizeof(int)))) goto error; - if(NULL == (cbuf = (set_t *)HDcalloc(TEST_BUF_SIZE, sizeof(set_t)))) + if (NULL == (cbuf = (set_t *)HDcalloc(TEST_BUF_SIZE, sizeof(set_t)))) goto error; /* Create a copy of file access property list */ - if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) + if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) goto error; /* Set to use the latest library format */ - if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) + if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) goto error; /* Open the file and dataset with SWMR write */ - if((fid = H5Fopen(file, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0) + if ((fid = H5Fopen(file, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0) goto error; /* Send message to the test script to start "h5watch" */ h5_send_message(WRITER_MESSAGE, NULL, NULL); - if((did = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) + if ((did = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) goto error; /* Get size of the dataset's datatype */ - if((dtype_size = H5LDget_dset_type_size(did, NULL)) == 0) + if ((dtype_size = H5LDget_dset_type_size(did, NULL)) == 0) goto error; /* Get dataset's datatype */ - if((dtid = H5Tget_native_type(H5Dget_type(did), H5T_DIR_DEFAULT)) < 0) + if ((dtid = H5Tget_native_type(H5Dget_type(did), H5T_DIR_DEFAULT)) < 0) goto error; /* Wait for message from the test script to start extending dataset */ - if(h5_wait_message(READER_MESSAGE) < 0) + if (h5_wait_message(READER_MESSAGE) < 0) goto error; /* sleep to emulate about 2 seconds of application operation */ HDsleep(2); /* Get current dimension sizes */ - if(H5LDget_dset_dims(did, cur_dims) < 0) + if (H5LDget_dset_dims(did, cur_dims) < 0) goto error; /* Set up the new extended dimension sizes */ ext_dims[0] = cur_dims[0] + (hsize_t)action; /* Extend the dataset */ - if(H5Dset_extent(did, ext_dims) < 0) + if (H5Dset_extent(did, ext_dims) < 0) goto error; /* Write to the new appended region of the dataset */ - if(action > 0) { + if (action > 0) { /* Select the extended region */ offset[0] = cur_dims[0]; - count[0] = (hsize_t)action; - if((sid = H5Dget_space(did)) < 0) + count[0] = (hsize_t)action; + if ((sid = H5Dget_space(did)) < 0) goto error; - if(H5Sselect_hyperslab(sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) + if (H5Sselect_hyperslab(sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto error; /* Set up memory space and get dataset's datatype */ - if((mid = H5Screate_simple(1, count, NULL)) < 0) + if ((mid = H5Screate_simple(1, count, NULL)) < 0) goto error; /* Initialize data for the extended region of the dataset */ /* Compound type */ - if(!HDstrcmp(dname, DSET_CMPD) || !HDstrcmp(dname, DSET_CMPD_ESC)) { + if (!HDstrcmp(dname, DSET_CMPD) || !HDstrcmp(dname, DSET_CMPD_ESC)) { HDmemset(cbuf, 0, TEST_BUF_SIZE * sizeof(set_t)); - for(i = 0; i < action; i++) { - cbuf[i].field1 = i + 1; - cbuf[i].field2.a = i + 2; + for (i = 0; i < action; i++) { + cbuf[i].field1 = i + 1; + cbuf[i].field2.a = i + 2; cbuf[i].field2.b.a = i + 2; cbuf[i].field2.b.b = i + 2; cbuf[i].field2.b.c = i + 2; - cbuf[i].field2.c = i + 2; + cbuf[i].field2.c = i + 2; cbuf[i].field3 = i + 3; @@ -319,57 +324,65 @@ extend_dset_one(const char *file, char *dname, int action) } /* end for */ /* Write to the extended region of the dataset */ - if(H5Dwrite(did, dtid, mid, sid, H5P_DEFAULT, cbuf) < 0) + if (H5Dwrite(did, dtid, mid, sid, H5P_DEFAULT, cbuf) < 0) goto error; - } else { /* Integer type */ + } + else { /* Integer type */ HDmemset(ibuf, 0, TEST_BUF_SIZE * sizeof(int)); - for(i = 0; i < action; i++) + for (i = 0; i < action; i++) ibuf[i] = (int)i; /* Write to the extended region of the dataset */ - if(H5Dwrite(did, dtid, mid, sid, H5P_DEFAULT, ibuf) < 0) + if (H5Dwrite(did, dtid, mid, sid, H5P_DEFAULT, ibuf) < 0) goto error; } /* end if-else */ /* Closing */ - if(H5Sclose(sid) < 0) goto error; - if(H5Sclose(mid) < 0) goto error; + if (H5Sclose(sid) < 0) + goto error; + if (H5Sclose(mid) < 0) + goto error; } /* end if */ - if(H5Dflush(did) < 0) + if (H5Dflush(did) < 0) goto error; /* Closing */ - if(H5Tclose(dtid) < 0) goto error; - if(H5Dclose(did) < 0) goto error; - if(H5Pclose(fapl) < 0) goto error; - if(H5Fclose(fid) < 0) goto error; + if (H5Tclose(dtid) < 0) + goto error; + if (H5Dclose(did) < 0) + goto error; + if (H5Pclose(fapl) < 0) + goto error; + if (H5Fclose(fid) < 0) + goto error; - if(ibuf) HDfree(ibuf); - if(cbuf) HDfree(cbuf); + if (ibuf) + HDfree(ibuf); + if (cbuf) + HDfree(cbuf); return SUCCEED; error: H5E_BEGIN_TRY - H5Sclose(sid); - H5Sclose(mid); - H5Tclose(dtid); - H5Dclose(did); - H5Pclose(fapl); - H5Fclose(fid); + H5Sclose(sid); + H5Sclose(mid); + H5Tclose(dtid); + H5Dclose(did); + H5Pclose(fapl); + H5Fclose(fid); H5E_END_TRY - if(ibuf) + if (ibuf) HDfree(ibuf); - if(cbuf) + if (cbuf) HDfree(cbuf); return FAIL; } /* end extend_dset_one() */ - /* *********************************************************************** * @@ -383,32 +396,33 @@ main(int argc, const char *argv[]) { char *dname = NULL; char *fname = NULL; - int action1, action2; + int action1, action2; - if(argc != 5) { + if (argc != 5) { HDfprintf(stderr, "Should have file name, dataset name, and the extended amount...\n"); goto error; } /* end if */ /* Get the dataset name to be extended */ - fname = HDstrdup(argv[1]); - dname = HDstrdup(argv[2]); + fname = HDstrdup(argv[1]); + dname = HDstrdup(argv[2]); action1 = HDatoi(argv[3]); action2 = HDatoi(argv[4]); - if(!HDstrcmp(dname, DSET_CMPD) || !HDstrcmp(dname, DSET_CMPD_ESC)) { - if(extend_dset_one(fname, dname, action1) < 0) + if (!HDstrcmp(dname, DSET_CMPD) || !HDstrcmp(dname, DSET_CMPD_ESC)) { + if (extend_dset_one(fname, dname, action1) < 0) goto error; - } else if(!HDstrcmp(dname, DSET_ONE) || - !HDstrcmp(dname, DSET_ALLOC_LATE) || - !HDstrcmp(dname, DSET_ALLOC_EARLY)) { - if(extend_dset_one(fname, dname, action1) < 0) + } + else if (!HDstrcmp(dname, DSET_ONE) || !HDstrcmp(dname, DSET_ALLOC_LATE) || + !HDstrcmp(dname, DSET_ALLOC_EARLY)) { + if (extend_dset_one(fname, dname, action1) < 0) goto error; - } else if(!HDstrcmp(dname, DSET_TWO) || - !HDstrcmp(dname, DSET_CMPD_TWO)) { - if(extend_dset_two(fname, dname, action1, action2) < 0) + } + else if (!HDstrcmp(dname, DSET_TWO) || !HDstrcmp(dname, DSET_CMPD_TWO)) { + if (extend_dset_two(fname, dname, action1, action2) < 0) goto error; - } else { + } + else { HDfprintf(stdout, "Dataset cannot be extended...\n"); goto error; } /* end if-else */ @@ -416,9 +430,9 @@ main(int argc, const char *argv[]) HDexit(EXIT_SUCCESS); error: - if(dname) + if (dname) HDfree(dname); - if(fname) + if (fname) HDfree(fname); HDexit(EXIT_FAILURE); } /* end main() */ diff --git a/hl/tools/h5watch/h5watch.c b/hl/tools/h5watch/h5watch.c index 56f9b63..0190545 100644 --- a/hl/tools/h5watch/h5watch.c +++ b/hl/tools/h5watch/h5watch.c @@ -18,10 +18,9 @@ /* * Note: This tool used private routine */ -#define PROGRAMNAME "h5watch" /* Name of tool */ -#define FIELD_SEP "," /* nested field separator */ -#define DEFAULT_RETRY 50 /* number of times to try opening the file */ - +#define PROGRAMNAME "h5watch" /* Name of tool */ +#define FIELD_SEP "," /* nested field separator */ +#define DEFAULT_RETRY 50 /* number of times to try opening the file */ /* * Note:(see comments in hl/src/H5LDprivate.h) @@ -29,80 +28,57 @@ * This tool uses H5LD_memb_t data structure declared in H5LDprivate.h */ -const char *progname = "h5watch"; /* tool name */ -static char *g_list_of_fields = NULL; /* command line input for "list_of_fields" */ -static char *g_dup_fields = NULL; /* copy of "list_of_fields" */ -static H5LD_memb_t **g_listv = NULL; /* vector info for "list_of_fields" */ +const char * progname = "h5watch"; /* tool name */ +static char * g_list_of_fields = NULL; /* command line input for "list_of_fields" */ +static char * g_dup_fields = NULL; /* copy of "list_of_fields" */ +static H5LD_memb_t **g_listv = NULL; /* vector info for "list_of_fields" */ -static hbool_t g_monitor_size_only = FALSE; /* monitor changes in dataset dimension sizes */ -static unsigned g_polling_interval = 1; /* polling interval to check appended data */ +static hbool_t g_monitor_size_only = FALSE; /* monitor changes in dataset dimension sizes */ +static unsigned g_polling_interval = 1; /* polling interval to check appended data */ -static hbool_t g_label = FALSE; /* label compound values */ -static int g_display_width = 80; /* output width in characters */ -static hbool_t g_simple_output = FALSE; /* make output more machine-readable */ -static unsigned g_retry = DEFAULT_RETRY; /* # of times to try opening the file if somehow file is unstable */ -static hbool_t g_display_hex = FALSE; /* display data in hexadecimal format : LATER */ -static hbool_t g_user_interrupt = FALSE; /* Flag to indicate that user interrupted execution */ +static hbool_t g_label = FALSE; /* label compound values */ +static int g_display_width = 80; /* output width in characters */ +static hbool_t g_simple_output = FALSE; /* make output more machine-readable */ +static unsigned g_retry = DEFAULT_RETRY; /* # of times to try opening the file if somehow file is unstable */ +static hbool_t g_display_hex = FALSE; /* display data in hexadecimal format : LATER */ +static hbool_t g_user_interrupt = FALSE; /* Flag to indicate that user interrupted execution */ static herr_t doprint(hid_t did, hsize_t *start, hsize_t *block, int rank); -static herr_t slicendump(hid_t did, hsize_t *prev_dims, hsize_t *cur_dims, - hsize_t *start, hsize_t *block, int rank, int subrank); +static herr_t slicendump(hid_t did, hsize_t *prev_dims, hsize_t *cur_dims, hsize_t *start, hsize_t *block, + int rank, int subrank); static herr_t monitor_dataset(hid_t fid, char *dsetname); static herr_t process_cmpd_fields(hid_t fid, char *dsetname); static herr_t check_dataset(hid_t fid, char *dsetname); -static void leave(int ret); -static void usage(const char *prog); -static void parse_command_line(int argc, const char *argv[]); - +static void leave(int ret); +static void usage(const char *prog); +static void parse_command_line(int argc, const char *argv[]); /* * Command-line options: The user can only specify long-named parameters. * The long-named ones can be partially spelled. When * adding more, make sure that they don't clash with each other. */ -static const char *s_opts ="?"; -static struct long_options l_opts[] = { - { "help", no_arg, 'h' }, - { "hel", no_arg, 'h' }, - { "dim", no_arg, 'd' }, - { "di", no_arg, 'd' }, - { "label", no_arg, 'l' }, - { "labe", no_arg, 'l' }, - { "lab", no_arg, 'l' }, - { "la", no_arg, 'l' }, - { "simple", no_arg, 'S' }, - { "simpl", no_arg, 'S' }, - { "simp", no_arg, 'S' }, - { "sim", no_arg, 'S' }, - { "si", no_arg, 'S' }, - { "hexdump", no_arg, 'x' }, - { "hexdum", no_arg, 'x' }, - { "hexdu", no_arg, 'x' }, - { "hexd", no_arg, 'x' }, - { "hex", no_arg, 'x' }, - { "width", require_arg, 'w' }, - { "widt", require_arg, 'w' }, - { "wid", require_arg, 'w' }, - { "wi", require_arg, 'w' }, - { "polling", require_arg, 'p' }, - { "pollin", require_arg, 'p' }, - { "polli", require_arg, 'p' }, - { "poll", require_arg, 'p' }, - { "pol", require_arg, 'p' }, - { "po", require_arg, 'p' }, - { "fields", require_arg, 'f' }, - { "field", require_arg, 'f' }, - { "fiel", require_arg, 'f' }, - { "fie", require_arg, 'f' }, - { "fi", require_arg, 'f' }, - { "version", no_arg, 'V' }, - { "versio", no_arg, 'V' }, - { "versi", no_arg, 'V' }, - { "vers", no_arg, 'V' }, - { "ver", no_arg, 'V' }, - { "ve", no_arg, 'V' }, - { NULL, 0, '\0' } -}; +static const char * s_opts = "?"; +static struct long_options l_opts[] = {{"help", no_arg, 'h'}, {"hel", no_arg, 'h'}, + {"dim", no_arg, 'd'}, {"di", no_arg, 'd'}, + {"label", no_arg, 'l'}, {"labe", no_arg, 'l'}, + {"lab", no_arg, 'l'}, {"la", no_arg, 'l'}, + {"simple", no_arg, 'S'}, {"simpl", no_arg, 'S'}, + {"simp", no_arg, 'S'}, {"sim", no_arg, 'S'}, + {"si", no_arg, 'S'}, {"hexdump", no_arg, 'x'}, + {"hexdum", no_arg, 'x'}, {"hexdu", no_arg, 'x'}, + {"hexd", no_arg, 'x'}, {"hex", no_arg, 'x'}, + {"width", require_arg, 'w'}, {"widt", require_arg, 'w'}, + {"wid", require_arg, 'w'}, {"wi", require_arg, 'w'}, + {"polling", require_arg, 'p'}, {"pollin", require_arg, 'p'}, + {"polli", require_arg, 'p'}, {"poll", require_arg, 'p'}, + {"pol", require_arg, 'p'}, {"po", require_arg, 'p'}, + {"fields", require_arg, 'f'}, {"field", require_arg, 'f'}, + {"fiel", require_arg, 'f'}, {"fie", require_arg, 'f'}, + {"fi", require_arg, 'f'}, {"version", no_arg, 'V'}, + {"versio", no_arg, 'V'}, {"versi", no_arg, 'V'}, + {"vers", no_arg, 'V'}, {"ver", no_arg, 'V'}, + {"ve", no_arg, 'V'}, {NULL, 0, '\0'}}; /*------------------------------------------------------------------------- * Function: doprint() @@ -121,29 +97,29 @@ static struct long_options l_opts[] = { static herr_t doprint(hid_t did, hsize_t *start, hsize_t *block, int rank) { - h5tools_context_t ctx; /* print context */ - h5tool_format_t info; /* Format info for the tools library */ - static char fmt_double[16], fmt_float[16]; /* Format info */ - struct subset_t subset; /* Subsetting info */ - hsize_t ss_start[H5S_MAX_RANK]; /* Info for hyperslab */ - hsize_t ss_stride[H5S_MAX_RANK]; /* Info for hyperslab */ - hsize_t ss_block[H5S_MAX_RANK]; /* Info for hyperslab */ - hsize_t ss_count[H5S_MAX_RANK]; /* Info for hyperslab */ - int i; /* Local index variable */ - herr_t ret_value = SUCCEED; /* Return value */ + h5tools_context_t ctx; /* print context */ + h5tool_format_t info; /* Format info for the tools library */ + static char fmt_double[16], fmt_float[16]; /* Format info */ + struct subset_t subset; /* Subsetting info */ + hsize_t ss_start[H5S_MAX_RANK]; /* Info for hyperslab */ + hsize_t ss_stride[H5S_MAX_RANK]; /* Info for hyperslab */ + hsize_t ss_block[H5S_MAX_RANK]; /* Info for hyperslab */ + hsize_t ss_count[H5S_MAX_RANK]; /* Info for hyperslab */ + int i; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ /* Subsetting information for the tools library printing routines */ - subset.start.data = ss_start; + subset.start.data = ss_start; subset.stride.data = ss_stride; - subset.block.data = ss_block; - subset.count.data = ss_count; + subset.block.data = ss_block; + subset.count.data = ss_count; /* Initialize subsetting information */ - for(i = 0; i < rank; i++) { + for (i = 0; i < rank; i++) { subset.stride.data[i] = 1; - subset.count.data[i] = 1; - subset.start.data[i] = start[i]; - subset.block.data[i] = block[i]; + subset.count.data[i] = 1; + subset.start.data[i] = start[i]; + subset.block.data[i] = block[i]; } /* end for */ HDmemset(&ctx, 0, sizeof(ctx)); @@ -152,13 +128,13 @@ doprint(hid_t did, hsize_t *start, hsize_t *block, int rank) /* Set to all default values and then override */ HDmemset(&info, 0, sizeof info); - if(g_simple_output) { - info.idx_fmt = ""; - info.line_ncols = 65535; /*something big*/ - info.line_per_line = 1; + if (g_simple_output) { + info.idx_fmt = ""; + info.line_ncols = 65535; /*something big*/ + info.line_per_line = 1; info.line_multi_new = 0; - info.line_pre = " "; - info.line_cont = " "; + info.line_pre = " "; + info.line_cont = " "; info.arr_pre = ""; info.arr_suf = ""; @@ -169,18 +145,18 @@ doprint(hid_t did, hsize_t *start, hsize_t *block, int rank) info.cmpd_sep = " "; /* The "fields" selected by the user */ - info.cmpd_listv = (const struct H5LD_memb_t * const *)g_listv; + info.cmpd_listv = (const struct H5LD_memb_t *const *)g_listv; - if(g_label) + if (g_label) info.cmpd_name = "%s="; - info.elmt_suf1 = " "; + info.elmt_suf1 = " "; info.str_locale = ESCAPE_HTML; - - } else { + } + else { info.idx_fmt = "(%s)"; - if(!g_display_width) { - info.line_ncols = 65535; + if (!g_display_width) { + info.line_ncols = 65535; info.line_per_line = 1; } /* end if */ else @@ -189,11 +165,11 @@ doprint(hid_t did, hsize_t *start, hsize_t *block, int rank) info.line_multi_new = 1; /* The "fields" selected by the user */ - info.cmpd_listv = (const struct H5LD_memb_t * const *)g_listv; - if(g_label) + info.cmpd_listv = (const struct H5LD_memb_t *const *)g_listv; + if (g_label) info.cmpd_name = "%s="; - info.line_pre = " %s "; - info.line_cont = " %s "; + info.line_pre = " %s "; + info.line_cont = " %s "; info.str_repeat = 8; } /* end else */ @@ -203,25 +179,25 @@ doprint(hid_t did, hsize_t *start, hsize_t *block, int rank) sprintf(fmt_double, "%%1.%dg", DBL_DIG); info.fmt_double = fmt_double; - info.dset_format = "DSET-%s "; + info.dset_format = "DSET-%s "; info.dset_hidefileno = 0; - info.obj_format = "-%lu:%" PRIuHADDR; + info.obj_format = "-%lu:%" PRIuHADDR; info.obj_hidefileno = 0; info.dset_blockformat_pre = "%sBlk%lu: "; - info.dset_ptformat_pre = "%sPt%lu: "; + info.dset_ptformat_pre = "%sPt%lu: "; info.line_indent = ""; - if(g_display_hex) { + if (g_display_hex) { /* Print all data in hexadecimal format if the `-x' or `--hexdump' * command line switch was given. */ info.raw = TRUE; } /* end if */ /* Print the values. */ - if((ret_value = h5tools_dump_dset(stdout, &info, &ctx, did)) < 0) + if ((ret_value = h5tools_dump_dset(stdout, &info, &ctx, did)) < 0) error_msg("unable to print data\n"); HDfprintf(stdout, "\n"); @@ -251,25 +227,26 @@ doprint(hid_t did, hsize_t *start, hsize_t *block, int rank) *------------------------------------------------------------------------- */ static herr_t -slicendump(hid_t did, hsize_t *prev_dims, hsize_t *cur_dims, hsize_t *start, hsize_t *block, int rank, int subrank) +slicendump(hid_t did, hsize_t *prev_dims, hsize_t *cur_dims, hsize_t *start, hsize_t *block, int rank, + int subrank) { - int i; /* Local index variable */ - int ind; /* Index for the current rank */ + int i; /* Local index variable */ + int ind; /* Index for the current rank */ herr_t ret_value = SUCCEED; /* Return value */ ind = rank - subrank; - if((subrank - 1) > 0) { + if ((subrank - 1) > 0) { /* continue onto the next dimension */ - for (i = 0; i < (hssize_t)MIN(prev_dims[ind], cur_dims[ind]); i++){ + for (i = 0; i < (hssize_t)MIN(prev_dims[ind], cur_dims[ind]); i++) { start[ind] = (hsize_t)i; - if((ret_value = slicendump(did, prev_dims, cur_dims, start, block, rank, subrank-1)) < 0) + if ((ret_value = slicendump(did, prev_dims, cur_dims, start, block, rank, subrank - 1)) < 0) goto done; } /* end for */ - } /* end if */ + } /* end if */ /* this dimension remains the same or shrinking */ - if(cur_dims[ind] <= prev_dims[ind]) + if (cur_dims[ind] <= prev_dims[ind]) goto done; /* select first the slice for the faster changing dimension */ @@ -277,7 +254,7 @@ slicendump(hid_t did, hsize_t *prev_dims, hsize_t *cur_dims, hsize_t *start, hsi start[ind] = prev_dims[ind]; block[ind] = cur_dims[ind] - prev_dims[ind]; - for(i = ind + 1; i < rank; i++){ + for (i = ind + 1; i < rank; i++) { start[i] = 0; block[i] = cur_dims[i]; } /* end for */ @@ -289,7 +266,6 @@ done: return ret_value; } /* end slicendump() */ - /*------------------------------------------------------------------------- * Function: monitor_dataset * @@ -309,30 +285,30 @@ done: static herr_t monitor_dataset(hid_t fid, char *dsetname) { - hid_t did; /* dataset id */ - hid_t sid; /* dataspace id */ - int ndims; /* # of dimensions in the dataspace */ - int i, u; /* local index variable */ - hsize_t prev_dims[H5S_MAX_RANK]; /* current dataspace dimensions */ - hsize_t cur_dims[H5S_MAX_RANK]; /* previous dataspace dimensions */ - herr_t ret_value = SUCCEED; /* return value */ + hid_t did; /* dataset id */ + hid_t sid; /* dataspace id */ + int ndims; /* # of dimensions in the dataspace */ + int i, u; /* local index variable */ + hsize_t prev_dims[H5S_MAX_RANK]; /* current dataspace dimensions */ + hsize_t cur_dims[H5S_MAX_RANK]; /* previous dataspace dimensions */ + herr_t ret_value = SUCCEED; /* return value */ HDfprintf(stdout, "Monitoring dataset %s...\n", dsetname); /* Open the dataset for minitoring */ - if((did = H5Dopen2(fid, dsetname, H5P_DEFAULT)) < 0) { + if ((did = H5Dopen2(fid, dsetname, H5P_DEFAULT)) < 0) { error_msg("error in opening dataset \"%s\"\n", dsetname); ret_value = FAIL; goto done; } - if((sid = H5Dget_space(did)) < 0) { + if ((sid = H5Dget_space(did)) < 0) { error_msg("error in getting dataspace id for dataset \"%s\"\n", dsetname); ret_value = FAIL; goto done; } /* Get the dataset's dimension sizes */ - if((ndims = H5Sget_simple_extent_dims(sid, prev_dims, NULL)) < 0) { + if ((ndims = H5Sget_simple_extent_dims(sid, prev_dims, NULL)) < 0) { error_msg("unable to get dimensions sizes for \"%s\"\n", dsetname); ret_value = FAIL; goto done; @@ -340,58 +316,60 @@ monitor_dataset(hid_t fid, char *dsetname) HDfflush(stdout); /* Loop until an error occurs or the user interrupts execution */ - while(!g_user_interrupt) { + while (!g_user_interrupt) { /* Refreshes the dataset */ - if(H5Drefresh(did) < 0) { + if (H5Drefresh(did) < 0) { ret_value = FAIL; goto done; } /* Get the dataset's current dimension sizes */ - if(H5LDget_dset_dims(did, cur_dims) < 0) { + if (H5LDget_dset_dims(did, cur_dims) < 0) { error_msg("unable to get dimension sizes for \"%s\"\n", dsetname); ret_value = FAIL; goto done; } /* Check the dimension sizes */ - for(i = 0; i < ndims; i++) - if(cur_dims[i] != prev_dims[i]) + for (i = 0; i < ndims; i++) + if (cur_dims[i] != prev_dims[i]) break; /* at least one dimension has changed */ - if(i != ndims) { + if (i != ndims) { /* Printing changes in dimension sizes */ - for(u = 0; u < ndims; u++) { - HDfprintf(stdout, "dimension %d: %" PRIuHSIZE "->%" PRIuHSIZE "", u, prev_dims[u], cur_dims[u]); - if(cur_dims[u] > prev_dims[u]) + for (u = 0; u < ndims; u++) { + HDfprintf(stdout, "dimension %d: %" PRIuHSIZE "->%" PRIuHSIZE "", u, prev_dims[u], + cur_dims[u]); + if (cur_dims[u] > prev_dims[u]) HDfprintf(stdout, " (increases)\n"); - else if(cur_dims[u] < prev_dims[u]) + else if (cur_dims[u] < prev_dims[u]) HDfprintf(stdout, " (decreases)\n"); else HDfprintf(stdout, " (unchanged)\n"); } /* Printing elements appended to the dataset if there is */ - if(!g_monitor_size_only) { + if (!g_monitor_size_only) { /* See if at least one dimension size has increased */ - for(u = 0; u < ndims; u++) { - int j; + for (u = 0; u < ndims; u++) { + int j; hsize_t start[H5S_MAX_RANK]; hsize_t block[H5S_MAX_RANK]; /* Print the new appended data to the dataset */ - if(cur_dims[u] > prev_dims[u]) { + if (cur_dims[u] > prev_dims[u]) { HDfprintf(stdout, " Data:\n"); - for(j = 0; j < ndims; j++) { + for (j = 0; j < ndims; j++) { start[j] = 0; block[j] = 1; } - if((ret_value = slicendump(did, prev_dims, cur_dims, start, block, ndims, ndims)) < 0) + if ((ret_value = slicendump(did, prev_dims, cur_dims, start, block, ndims, ndims)) < + 0) goto done; break; } @@ -412,10 +390,10 @@ monitor_dataset(hid_t fid, char *dsetname) done: /* Closing */ H5E_BEGIN_TRY - H5Dclose(did); + H5Dclose(did); H5E_END_TRY - return(ret_value); + return (ret_value); } /* monitor_dataset() */ /*------------------------------------------------------------------------- @@ -433,53 +411,53 @@ done: static herr_t process_cmpd_fields(hid_t fid, char *dsetname) { - hid_t did=-1; /* dataset id */ - hid_t dtid=-1, tid=-1; /* dataset's data type id */ + hid_t did = -1; /* dataset id */ + hid_t dtid = -1, tid = -1; /* dataset's data type id */ size_t len; /* number of comma-separated fields in "g_list_of_fields" */ herr_t ret_value = SUCCEED; /* Return value */ HDassert(g_list_of_fields && *g_list_of_fields); /* Open the dataset */ - if((did = H5Dopen2(fid, dsetname, H5P_DEFAULT)) < 0) { + if ((did = H5Dopen2(fid, dsetname, H5P_DEFAULT)) < 0) { error_msg("error in opening dataset \"%s\"\n", dsetname); ret_value = FAIL; goto done; } /* Get the dataset's datatype */ - if(((dtid = H5Dget_type(did)) < 0) || (tid = H5Tget_native_type(dtid, H5T_DIR_DEFAULT)) < 0) { + if (((dtid = H5Dget_type(did)) < 0) || (tid = H5Tget_native_type(dtid, H5T_DIR_DEFAULT)) < 0) { error_msg("error in getting dataset's datatype\n"); ret_value = FAIL; goto done; } /* Check to make sure that the dataset's datatype is compound type */ - if(H5Tget_class(dtid) != H5T_COMPOUND) { + if (H5Tget_class(dtid) != H5T_COMPOUND) { error_msg("dataset should be compound type for <list_of_fields>\n"); ret_value = FAIL; goto done; } /* Make a copy of "g_list_of_fields" */ - if((g_dup_fields = HDstrdup(g_list_of_fields)) == NULL) { + if ((g_dup_fields = HDstrdup(g_list_of_fields)) == NULL) { error_msg("error in duplicating g_list_of_fields\n"); ret_value = FAIL; goto done; } /* Estimate the number of comma-separated fields in "g_list of_fields" */ - len = HDstrlen(g_list_of_fields)/2 + 2; + len = HDstrlen(g_list_of_fields) / 2 + 2; /* Allocate memory for a list vector of H5LD_memb_t structures to store "g_list_of_fields" info */ - if((g_listv = (H5LD_memb_t **)HDcalloc(len, sizeof(H5LD_memb_t *))) == NULL) { + if ((g_listv = (H5LD_memb_t **)HDcalloc(len, sizeof(H5LD_memb_t *))) == NULL) { error_msg("error in allocating memory for H5LD_memb_t\n"); ret_value = FAIL; goto done; } /* Process and store info for "g_listv" */ - if(H5LD_construct_vector(g_dup_fields, g_listv, tid) < 0) { + if (H5LD_construct_vector(g_dup_fields, g_listv, tid) < 0) { error_msg("error in processing <list_of_fields>\n"); ret_value = FAIL; goto done; @@ -489,14 +467,13 @@ process_cmpd_fields(hid_t fid, char *dsetname) done: /* Closing */ H5E_BEGIN_TRY - H5Tclose(dtid); - H5Tclose(tid); - H5Dclose(did); + H5Tclose(dtid); + H5Tclose(tid); + H5Dclose(did); H5E_END_TRY - return(ret_value); + return (ret_value); } /* process_cmpd_fields() */ - /*------------------------------------------------------------------------- * Function: check_dataset * @@ -513,44 +490,44 @@ done: static herr_t check_dataset(hid_t fid, char *dsetname) { - hid_t did=-1; /* Dataset id */ - hid_t dcp=-1; /* Dataset creation property */ - hid_t sid=-1; /* Dataset's dataspace id */ - int ndims; /* # of dimensions in the dataspace */ - unsigned u; /* Local index variable */ - hsize_t cur_dims[H5S_MAX_RANK]; /* size of dataspace dimensions */ - hsize_t max_dims[H5S_MAX_RANK]; /* maximum size of dataspace dimensions */ - hbool_t unlim_max_dims = FALSE; /* whether dataset has unlimited or max. dimension setting */ - void *edata; - H5E_auto2_t func; - H5D_layout_t layout; - herr_t ret_value = SUCCEED; /* Return value */ + hid_t did = -1; /* Dataset id */ + hid_t dcp = -1; /* Dataset creation property */ + hid_t sid = -1; /* Dataset's dataspace id */ + int ndims; /* # of dimensions in the dataspace */ + unsigned u; /* Local index variable */ + hsize_t cur_dims[H5S_MAX_RANK]; /* size of dataspace dimensions */ + hsize_t max_dims[H5S_MAX_RANK]; /* maximum size of dataspace dimensions */ + hbool_t unlim_max_dims = FALSE; /* whether dataset has unlimited or max. dimension setting */ + void * edata; + H5E_auto2_t func; + H5D_layout_t layout; + herr_t ret_value = SUCCEED; /* Return value */ /* Disable error reporting */ H5Eget_auto2(H5E_DEFAULT, &func, &edata); H5Eset_auto2(H5E_DEFAULT, NULL, NULL); /* Open the dataset */ - if((did = H5Dopen2(fid, dsetname, H5P_DEFAULT)) < 0) { + if ((did = H5Dopen2(fid, dsetname, H5P_DEFAULT)) < 0) { error_msg("unable to open dataset \"%s\"\n", dsetname); ret_value = FAIL; goto done; } /* Get dataset's creation property list */ - if((dcp = H5Dget_create_plist(did)) < 0) { + if ((dcp = H5Dget_create_plist(did)) < 0) { error_msg("unable to get dataset's creation property list \"%s\"\n", dsetname); ret_value = FAIL; goto done; } /* Query dataset's layout; the layout should be chunked or virtual */ - if((layout = H5Pget_layout(dcp)) < 0) { + if ((layout = H5Pget_layout(dcp)) < 0) { error_msg("unable to get dataset layout \"%s\"\n", dsetname); ret_value = FAIL; goto done; } - if(layout != H5D_CHUNKED && layout != H5D_VIRTUAL) { + if (layout != H5D_CHUNKED && layout != H5D_VIRTUAL) { error_msg("\"%s\" should be a chunked or virtual dataset\n", dsetname); ret_value = FAIL; goto done; @@ -560,27 +537,27 @@ check_dataset(hid_t fid, char *dsetname) HDmemset(max_dims, 0, sizeof max_dims); /* Get dataset's dataspace */ - if((sid = H5Dget_space(did)) < 0) { + if ((sid = H5Dget_space(did)) < 0) { error_msg("can't get dataset's dataspace\"%s\"\n", dsetname); ret_value = FAIL; goto done; } /* Get dimension size of dataset's dataspace */ - if((ndims = H5Sget_simple_extent_dims(sid, cur_dims, max_dims)) < 0) { + if ((ndims = H5Sget_simple_extent_dims(sid, cur_dims, max_dims)) < 0) { error_msg("can't get dataspace dimensions for dataset \"%s\"\n", dsetname); ret_value = FAIL; goto done; } /* Check whether dataset has unlimited dimension or max. dimension setting */ - for(u = 0; u < (unsigned)ndims; u++) - if(max_dims[u] == H5S_UNLIMITED || cur_dims[u] != max_dims[u]) { - unlim_max_dims = TRUE; - break; - } + for (u = 0; u < (unsigned)ndims; u++) + if (max_dims[u] == H5S_UNLIMITED || cur_dims[u] != max_dims[u]) { + unlim_max_dims = TRUE; + break; + } - if(!unlim_max_dims) { + if (!unlim_max_dims) { error_msg("\"%s\" should have unlimited or max. dimension setting\n", dsetname); ret_value = FAIL; } @@ -590,15 +567,14 @@ done: /* Closing */ H5E_BEGIN_TRY - H5Sclose(sid); - H5Pclose(dcp); - H5Dclose(did); + H5Sclose(sid); + H5Pclose(dcp); + H5Dclose(did); H5E_END_TRY - return(ret_value); + return (ret_value); } /* check_dataset() */ - /*------------------------------------------------------------------------- * Function: leave * @@ -619,7 +595,6 @@ leave(int ret) exit(ret); } - /*------------------------------------------------------------------------- * Function: usage * @@ -647,10 +622,12 @@ usage(const char *prog) HDfprintf(stdout, " A value of 0 sets the number of columns to the\n"); HDfprintf(stdout, " maximum (65535). The default width is 80 columns.\n"); HDfprintf(stdout, " --polling=N Set the polling interval to N (in seconds) when the\n"); - HDfprintf(stdout, " dataset will be checked for appended data. The default\n"); + HDfprintf(stdout, + " dataset will be checked for appended data. The default\n"); HDfprintf(stdout, " polling interval is 1.\n"); HDfprintf(stdout, " --fields=<list_of_fields>\n"); - HDfprintf(stdout, " Display data for the fields specified in <list_of_fields>\n"); + HDfprintf(stdout, + " Display data for the fields specified in <list_of_fields>\n"); HDfprintf(stdout, " for a compound data type. <list_of_fields> can be\n"); HDfprintf(stdout, " specified as follows:\n"); HDfprintf(stdout, " 1) A comma-separated list of field names in a\n"); @@ -660,7 +637,8 @@ usage(const char *prog) HDfprintf(stdout, " 2) A single field name in a compound data type.\n"); HDfprintf(stdout, " Can use this option multiple times.\n"); HDfprintf(stdout, " Note that backslash is the escape character to avoid\n"); - HDfprintf(stdout, " characters in field names that conflict with the tool's\n"); + HDfprintf(stdout, + " characters in field names that conflict with the tool's\n"); HDfprintf(stdout, " separators.\n"); HDfprintf(stdout, "\n"); HDfprintf(stdout, " OBJECT is specified as [<filename>/<path_to_dataset>/<dsetname>]\n"); @@ -669,11 +647,11 @@ usage(const char *prog) HDfprintf(stdout, " <path_to_dataset> Path separated by slashes to the specified dataset\n"); HDfprintf(stdout, " <dsetname> Name of the dataset\n"); HDfprintf(stdout, "\n"); - HDfprintf(stdout, " User can end the h5watch process by ctrl-C (SIGINT) or kill the process (SIGTERM).\n"); + HDfprintf(stdout, + " User can end the h5watch process by ctrl-C (SIGINT) or kill the process (SIGTERM).\n"); } /* usage() */ - /*------------------------------------------------------------------------- * Function: parse_command_line * @@ -689,10 +667,10 @@ usage(const char *prog) static void parse_command_line(int argc, const char *argv[]) { - int opt; /* Command line option */ + int opt; /* Command line option */ int tmp; - /* no arguments */ + /* no arguments */ if (argc == 1) { usage(h5tools_getprogname()); leave(EXIT_FAILURE); @@ -701,80 +679,77 @@ parse_command_line(int argc, const char *argv[]) /* parse command line options */ while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { switch ((char)opt) { - case '?': - case 'h': /* --help */ - usage(h5tools_getprogname()); - leave(EXIT_SUCCESS); - break; - - case 'V': /* --version */ - print_version(progname); - leave(EXIT_SUCCESS); - break; - - case 'w': /* --width=N */ - g_display_width = (int)HDstrtol(opt_arg, NULL, 0); - if(g_display_width < 0) { + case '?': + case 'h': /* --help */ usage(h5tools_getprogname()); - leave(EXIT_FAILURE); - } - break; + leave(EXIT_SUCCESS); + break; - case 'd': /* --dim */ - g_monitor_size_only = TRUE; - break; + case 'V': /* --version */ + print_version(progname); + leave(EXIT_SUCCESS); + break; - case 'S': /* --simple */ - g_simple_output = TRUE; - break; + case 'w': /* --width=N */ + g_display_width = (int)HDstrtol(opt_arg, NULL, 0); + if (g_display_width < 0) { + usage(h5tools_getprogname()); + leave(EXIT_FAILURE); + } + break; - case 'l': /* --label */ - g_label = TRUE; - break; + case 'd': /* --dim */ + g_monitor_size_only = TRUE; + break; - case 'p': /* --polling=N */ - /* g_polling_interval = HDstrtod(opt_arg, NULL); */ - if((tmp = (int)HDstrtol(opt_arg, NULL, 10)) <= 0) { - usage(h5tools_getprogname()); - leave(EXIT_FAILURE); - } - g_polling_interval = (unsigned)tmp; - break; + case 'S': /* --simple */ + g_simple_output = TRUE; + break; + + case 'l': /* --label */ + g_label = TRUE; + break; - case 'f': /* --fields=<list_of_fields> */ - if(g_list_of_fields == NULL) { - if((g_list_of_fields = HDstrdup(opt_arg)) == NULL) { - error_msg("memory allocation failed (file %s:line %d)\n", - __FILE__, __LINE__); + case 'p': /* --polling=N */ + /* g_polling_interval = HDstrtod(opt_arg, NULL); */ + if ((tmp = (int)HDstrtol(opt_arg, NULL, 10)) <= 0) { + usage(h5tools_getprogname()); leave(EXIT_FAILURE); } - } else { - char *str; + g_polling_interval = (unsigned)tmp; + break; - if((str = HDstrdup(opt_arg)) == NULL) { - error_msg("memory allocation failed (file %s:line %d)\n", - __FILE__, __LINE__); - leave(EXIT_FAILURE); + case 'f': /* --fields=<list_of_fields> */ + if (g_list_of_fields == NULL) { + if ((g_list_of_fields = HDstrdup(opt_arg)) == NULL) { + error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__); + leave(EXIT_FAILURE); + } } - if((g_list_of_fields = (char *)HDrealloc(g_list_of_fields, HDstrlen(g_list_of_fields) + HDstrlen(str) + 2)) == NULL) { - error_msg("memory allocation failed (file %s:line %d)\n", - __FILE__, __LINE__); - leave(EXIT_FAILURE); + else { + char *str; + if ((str = HDstrdup(opt_arg)) == NULL) { + error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__); + leave(EXIT_FAILURE); + } + if ((g_list_of_fields = (char *)HDrealloc( + g_list_of_fields, HDstrlen(g_list_of_fields) + HDstrlen(str) + 2)) == NULL) { + error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__); + leave(EXIT_FAILURE); + } + HDstrcat(g_list_of_fields, FIELD_SEP); + HDstrcat(g_list_of_fields, str); } - HDstrcat(g_list_of_fields, FIELD_SEP); - HDstrcat(g_list_of_fields, str); - } - break; + break; - default: - usage(h5tools_getprogname()); - leave(EXIT_FAILURE); + default: + usage(h5tools_getprogname()); + leave(EXIT_FAILURE); } } - /* check for object to be processed */ if (argc <= opt_ind) { error_msg("missing dataset name\n"); @@ -783,7 +758,6 @@ parse_command_line(int argc, const char *argv[]) } } /* parse_command_line() */ - /*------------------------------------------------------------------------- * Function: catch_signal * @@ -796,13 +770,13 @@ parse_command_line(int argc, const char *argv[]) * *------------------------------------------------------------------------- */ -static void catch_signal(int H5_ATTR_UNUSED signo) +static void +catch_signal(int H5_ATTR_UNUSED signo) { /* Set the flag to get out of the main loop */ g_user_interrupt = TRUE; } /* catch_signal() */ - /*------------------------------------------------------------------------- * Function: main * @@ -818,12 +792,12 @@ static void catch_signal(int H5_ATTR_UNUSED signo) int main(int argc, const char *argv[]) { - char drivername[50]; /* VFD name */ - char *fname = NULL; /* File name */ - char *dname = NULL; /* Dataset name */ - char *x; /* Temporary string pointer */ - hid_t fid = -1; /* File ID */ - hid_t fapl = -1; /* File access property list */ + char drivername[50]; /* VFD name */ + char *fname = NULL; /* File name */ + char *dname = NULL; /* Dataset name */ + char *x; /* Temporary string pointer */ + hid_t fid = -1; /* File ID */ + hid_t fapl = -1; /* File access property list */ /* Set up tool name and exit status */ h5tools_setprogname(PROGRAMNAME); @@ -833,13 +807,13 @@ main(int argc, const char *argv[]) h5tools_init(); /* To exit from h5watch for SIGTERM signal */ - if(HDsignal(SIGTERM, catch_signal) == SIG_ERR) { + if (HDsignal(SIGTERM, catch_signal) == SIG_ERR) { error_msg("An error occurred while setting a signal handler.\n"); leave(EXIT_FAILURE); } /* To exit from h5watch for SIGINT signal */ - if(HDsignal(SIGINT, catch_signal) == SIG_ERR) { + if (HDsignal(SIGINT, catch_signal) == SIG_ERR) { error_msg("An error occurred while setting a signal handler.\n"); leave(EXIT_FAILURE); } @@ -847,7 +821,7 @@ main(int argc, const char *argv[]) /* parse command line options */ parse_command_line(argc, argv); - if(argc <= opt_ind) { + if (argc <= opt_ind) { error_msg("missing dataset name\n"); usage(h5tools_getprogname()); leave(EXIT_FAILURE); @@ -871,60 +845,61 @@ main(int argc, const char *argv[]) * then there must have been something wrong with the file (perhaps it * doesn't exist). */ - if((fname = HDstrdup(argv[opt_ind])) == NULL) { + if ((fname = HDstrdup(argv[opt_ind])) == NULL) { 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) { + 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) { + 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, FALSE, drivername, sizeof drivername); + while (fname && *fname) { + fid = h5tools_fopen(fname, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl, FALSE, drivername, + sizeof drivername); - if(fid >= 0) { + if (fid >= 0) { HDfprintf(stdout, "Opened \"%s\" with %s driver.\n", fname, drivername); break; /*success*/ - } /* end if */ + } /* end if */ /* Shorten the file name; lengthen the object name */ - x = dname; + x = dname; dname = HDstrrchr(fname, '/'); - if(x) + if (x) *x = '/'; - if(!dname) + if (!dname) break; *dname = '\0'; } /* end while */ - /* Try opening the file again if somehow unstable */ - } while(g_retry-- > 0 && fid == FAIL); + /* Try opening the file again if somehow unstable */ + } while (g_retry-- > 0 && fid == FAIL); - if(fid < 0) { + if (fid < 0) { error_msg("unable to open file \"%s\"\n", fname); h5tools_setstatus(EXIT_FAILURE); goto done; } - if(!dname) { + if (!dname) { error_msg("no dataset specified\n"); h5tools_setstatus(EXIT_FAILURE); goto done; } else { *dname = '/'; - x = dname; - if((dname = HDstrdup(dname)) == NULL) { + x = dname; + if ((dname = HDstrdup(dname)) == NULL) { error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__); h5tools_setstatus(EXIT_FAILURE); goto done; @@ -932,13 +907,13 @@ main(int argc, const char *argv[]) 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; } @@ -947,33 +922,33 @@ main(int argc, const char *argv[]) } /* If everything is fine, start monitoring the datset */ - if(h5tools_getstatus() != EXIT_FAILURE) - if(monitor_dataset(fid, dname) < 0) + if (h5tools_getstatus() != EXIT_FAILURE) + if (monitor_dataset(fid, dname) < 0) h5tools_setstatus(EXIT_FAILURE); done: /* Free spaces */ - if(fname) + if (fname) HDfree(fname); - if(dname) + if (dname) HDfree(dname); - if(g_list_of_fields) + if (g_list_of_fields) HDfree(g_list_of_fields); - if(g_listv) { + if (g_listv) { H5LD_clean_vector(g_listv); HDfree(g_listv); } - if(g_dup_fields) + if (g_dup_fields) HDfree(g_dup_fields); /* Close the file access property list */ - if(fapl >= 0 && H5Pclose(fapl) < 0) { + if (fapl >= 0 && H5Pclose(fapl) < 0) { error_msg("unable to close file access property list\n"); h5tools_setstatus(EXIT_FAILURE); } /* Close the file */ - if(fid >= 0 && H5Fclose(fid) < 0) { + if (fid >= 0 && H5Fclose(fid) < 0) { error_msg("unable to close file\n"); h5tools_setstatus(EXIT_FAILURE); } @@ -981,4 +956,3 @@ done: /* exit */ leave(h5tools_getstatus()); } /* main() */ - diff --git a/hl/tools/h5watch/h5watchgentest.c b/hl/tools/h5watch/h5watchgentest.c index 19c9876..255ad41 100644 --- a/hl/tools/h5watch/h5watchgentest.c +++ b/hl/tools/h5watch/h5watchgentest.c @@ -33,26 +33,26 @@ * DSET_NONE: fixed dimension setting, contiguous, H5D_ALLOC_TIME_LATE * DSET_NOMAX: fixed dimension setting, chunked, H5D_ALLOC_TIME_INCR */ -#define ONE_DIMS0 10 -#define MAX_ONE_DIMS0 100 +#define ONE_DIMS0 10 +#define MAX_ONE_DIMS0 100 -#define DSET_ONE "DSET_ONE" -#define DSET_NONE "DSET_NONE" -#define DSET_NOMAX "DSET_NOMAX" -#define DSET_ALLOC_LATE "DSET_ALLOC_LATE" +#define DSET_ONE "DSET_ONE" +#define DSET_NONE "DSET_NONE" +#define DSET_NOMAX "DSET_NOMAX" +#define DSET_ALLOC_LATE "DSET_ALLOC_LATE" #define DSET_ALLOC_EARLY "DSET_ALLOC_EARLY" -#define DSET_CMPD "DSET_CMPD" -#define DSET_CMPD_ESC "DSET_CMPD_ESC" +#define DSET_CMPD "DSET_CMPD" +#define DSET_CMPD_ESC "DSET_CMPD_ESC" -#define TWO_DIMS0 4 -#define TWO_DIMS1 10 -#define MAX_TWO_DIMS0 60 -#define MAX_TWO_DIMS1 100 +#define TWO_DIMS0 4 +#define TWO_DIMS1 10 +#define MAX_TWO_DIMS0 60 +#define MAX_TWO_DIMS1 100 -#define DSET_TWO "DSET_TWO" -#define DSET_CMPD_TWO "DSET_CMPD_TWO" +#define DSET_TWO "DSET_TWO" +#define DSET_CMPD_TWO "DSET_CMPD_TWO" -#define CHUNK_SIZE 2 +#define CHUNK_SIZE 2 #define FILE "WATCH.h5" @@ -64,9 +64,9 @@ typedef struct sub22_t { } sub22_t; typedef struct sub2_t { - int a; + int a; sub22_t b; - int c; + int c; } sub2_t; typedef struct sub4_t { @@ -75,7 +75,7 @@ typedef struct sub4_t { } sub4_t; typedef struct set_t { - int field1; + int field1; sub2_t field2; double field3; sub4_t field4; @@ -90,58 +90,63 @@ typedef struct set_t { ************************************************************************************** */ static herr_t -generate_dset(hid_t fid, const char *dname, int ndims, hsize_t *dims, hsize_t *maxdims, hid_t dtid, void *data) +generate_dset(hid_t fid, const char *dname, int ndims, hsize_t *dims, hsize_t *maxdims, hid_t dtid, + void *data) { - hid_t dcpl=-1; /* Dataset creation property */ - hid_t did=-1; /* Dataset id */ - hid_t sid=-1; /* Dataspace id */ - int i; /* Local index variable */ - hsize_t chunk_dims[H5S_MAX_RANK]; /* Dimension sizes for chunks */ + hid_t dcpl = -1; /* Dataset creation property */ + hid_t did = -1; /* Dataset id */ + hid_t sid = -1; /* Dataspace id */ + int i; /* Local index variable */ + hsize_t chunk_dims[H5S_MAX_RANK]; /* Dimension sizes for chunks */ /* Create the dataspace */ - if((sid = H5Screate_simple(ndims, dims, maxdims)) < 0) + if ((sid = H5Screate_simple(ndims, dims, maxdims)) < 0) goto done; /* Set up dataset's creation properties */ - if(!HDstrcmp(dname, DSET_NONE)) + if (!HDstrcmp(dname, DSET_NONE)) dcpl = H5P_DEFAULT; else { - if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) + if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto done; - for(i = 0; i < ndims; i++) + for (i = 0; i < ndims; i++) chunk_dims[i] = CHUNK_SIZE; - if(H5Pset_chunk(dcpl, ndims, chunk_dims) < 0) + if (H5Pset_chunk(dcpl, ndims, chunk_dims) < 0) goto done; } /* end else */ - if(!HDstrcmp(dname, DSET_ALLOC_LATE)) { - if(H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_LATE) < 0) + if (!HDstrcmp(dname, DSET_ALLOC_LATE)) { + if (H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_LATE) < 0) goto done; - } else if(!HDstrcmp(dname, DSET_ALLOC_EARLY)) { - if(H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) + } + else if (!HDstrcmp(dname, DSET_ALLOC_EARLY)) { + if (H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) goto done; } /* end if-else */ /* Create the dataset */ - if((did = H5Dcreate2(fid, dname, dtid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + if ((did = H5Dcreate2(fid, dname, dtid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto done; /* Write to the dataset */ - if(H5Dwrite(did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0) + if (H5Dwrite(did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0) goto done; /* Closing */ - if(H5Pclose(dcpl) < 0) goto done; - if(H5Sclose(sid) < 0) goto done; - if(H5Dclose(did) < 0) goto done; + if (H5Pclose(dcpl) < 0) + goto done; + if (H5Sclose(sid) < 0) + goto done; + if (H5Dclose(did) < 0) + goto done; return SUCCEED; done: H5E_BEGIN_TRY - H5Sclose(sid); - H5Pclose(dcpl); - H5Dclose(did); + H5Sclose(sid); + H5Pclose(dcpl); + H5Dclose(did); H5E_END_TRY return FAIL; @@ -150,49 +155,49 @@ done: int main(void) { - hid_t fid=-1; /* File id */ - hid_t fapl=-1; /* File access property list id */ - hsize_t cur_dims[1]; /* Dimension sizes */ - hsize_t max_dims[1]; /* Maximum dimension sizes */ - hsize_t cur2_dims[2]; /* Current dimension sizes */ - hsize_t max2_dims[2]; /* Maximum dimension sizes */ - hid_t set_tid=-1, esc_set_tid=-1; /* Compound type id */ - hid_t sub22_tid=-1; /* Compound type id */ - hid_t sub2_tid=-1, esc_sub2_tid=-1; /* Compound type id */ - hid_t sub4_tid=-1, esc_sub4_tid=-1; /* Compound type id */ - int one_data[ONE_DIMS0]; /* Buffer for data */ - int two_data[TWO_DIMS0*TWO_DIMS1]; /* Buffer for data */ - set_t one_cbuf[ONE_DIMS0]; /* Buffer for data with compound type */ - set_t two_cbuf[TWO_DIMS0*TWO_DIMS1]; /* Buffer for data with compound type */ - int i; /* Local index variable */ + hid_t fid = -1; /* File id */ + hid_t fapl = -1; /* File access property list id */ + hsize_t cur_dims[1]; /* Dimension sizes */ + hsize_t max_dims[1]; /* Maximum dimension sizes */ + hsize_t cur2_dims[2]; /* Current dimension sizes */ + hsize_t max2_dims[2]; /* Maximum dimension sizes */ + hid_t set_tid = -1, esc_set_tid = -1; /* Compound type id */ + hid_t sub22_tid = -1; /* Compound type id */ + hid_t sub2_tid = -1, esc_sub2_tid = -1; /* Compound type id */ + hid_t sub4_tid = -1, esc_sub4_tid = -1; /* Compound type id */ + int one_data[ONE_DIMS0]; /* Buffer for data */ + int two_data[TWO_DIMS0 * TWO_DIMS1]; /* Buffer for data */ + set_t one_cbuf[ONE_DIMS0]; /* Buffer for data with compound type */ + set_t two_cbuf[TWO_DIMS0 * TWO_DIMS1]; /* Buffer for data with compound type */ + int i; /* Local index variable */ /* Create a copy of file access property list */ - if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) + if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) HDexit(EXIT_FAILURE); /* Set to use the latest library format */ - if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) + if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) HDexit(EXIT_FAILURE); /* Create a file with the latest format */ - if((fid = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) + if ((fid = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) HDexit(EXIT_FAILURE); /* Initialization for one-dimensional dataset */ cur_dims[0] = ONE_DIMS0; max_dims[0] = MAX_ONE_DIMS0; - for(i = 0; i < ONE_DIMS0; i++) + for (i = 0; i < ONE_DIMS0; i++) one_data[i] = i; /* Generate DSET_ONE, DSET_NONE, DSET_NOMAX, DSET_ALLOC_LATE, DSET_EARLY */ - if(generate_dset(fid, DSET_ONE, 1, cur_dims, max_dims, H5T_NATIVE_INT, one_data) < 0) + if (generate_dset(fid, DSET_ONE, 1, cur_dims, max_dims, H5T_NATIVE_INT, one_data) < 0) goto done; - if(generate_dset(fid, DSET_NONE, 1, cur_dims, NULL, H5T_NATIVE_INT, one_data) < 0) + if (generate_dset(fid, DSET_NONE, 1, cur_dims, NULL, H5T_NATIVE_INT, one_data) < 0) goto done; - if(generate_dset(fid, DSET_NOMAX, 1, cur_dims, NULL, H5T_NATIVE_INT, one_data) < 0) + if (generate_dset(fid, DSET_NOMAX, 1, cur_dims, NULL, H5T_NATIVE_INT, one_data) < 0) goto done; - if(generate_dset(fid, DSET_ALLOC_LATE, 1, cur_dims, max_dims, H5T_NATIVE_INT, one_data) < 0) + if (generate_dset(fid, DSET_ALLOC_LATE, 1, cur_dims, max_dims, H5T_NATIVE_INT, one_data) < 0) goto done; - if(generate_dset(fid, DSET_ALLOC_EARLY, 1, cur_dims, max_dims, H5T_NATIVE_INT, one_data) < 0) + if (generate_dset(fid, DSET_ALLOC_EARLY, 1, cur_dims, max_dims, H5T_NATIVE_INT, one_data) < 0) goto done; /* Initialization for two-dimensional dataset */ @@ -201,98 +206,98 @@ main(void) max2_dims[0] = MAX_TWO_DIMS0; max2_dims[1] = MAX_TWO_DIMS1; - for(i = 0; i < (TWO_DIMS0 * TWO_DIMS1); i++) + for (i = 0; i < (TWO_DIMS0 * TWO_DIMS1); i++) two_data[i] = i; /* Generate DSET_TWO */ - if(generate_dset(fid, DSET_TWO, 2, cur2_dims, max2_dims, H5T_NATIVE_INT, two_data) < 0) + if (generate_dset(fid, DSET_TWO, 2, cur2_dims, max2_dims, H5T_NATIVE_INT, two_data) < 0) goto done; /* Initialization for one-dimensional compound typed dataset */ cur_dims[0] = ONE_DIMS0; max_dims[0] = MAX_ONE_DIMS0; - for(i = 0; i < ONE_DIMS0; i++) { - one_cbuf[i].field1 = 1; - one_cbuf[i].field2.a = 2; - one_cbuf[i].field2.c = 4; + for (i = 0; i < ONE_DIMS0; i++) { + one_cbuf[i].field1 = 1; + one_cbuf[i].field2.a = 2; + one_cbuf[i].field2.c = 4; one_cbuf[i].field2.b.a = 20; one_cbuf[i].field2.b.b = 40; one_cbuf[i].field2.b.c = 80; - one_cbuf[i].field3 = 3.0F; - one_cbuf[i].field4.a = 4; - one_cbuf[i].field4.b = 8; + one_cbuf[i].field3 = 3.0F; + one_cbuf[i].field4.a = 4; + one_cbuf[i].field4.b = 8; } /* end for */ /* Create the compound type */ - if((sub22_tid = H5Tcreate(H5T_COMPOUND, sizeof(sub22_t))) < 0) + if ((sub22_tid = H5Tcreate(H5T_COMPOUND, sizeof(sub22_t))) < 0) goto done; - if(H5Tinsert(sub22_tid, "a", HOFFSET(sub22_t, a), H5T_NATIVE_INT) < 0) + if (H5Tinsert(sub22_tid, "a", HOFFSET(sub22_t, a), H5T_NATIVE_INT) < 0) goto done; - if(H5Tinsert(sub22_tid, "b", HOFFSET(sub22_t, b), H5T_NATIVE_INT) < 0) + if (H5Tinsert(sub22_tid, "b", HOFFSET(sub22_t, b), H5T_NATIVE_INT) < 0) goto done; - if(H5Tinsert(sub22_tid, "c", HOFFSET(sub22_t, c), H5T_NATIVE_INT) < 0) + if (H5Tinsert(sub22_tid, "c", HOFFSET(sub22_t, c), H5T_NATIVE_INT) < 0) goto done; - if((sub2_tid = H5Tcreate(H5T_COMPOUND, sizeof(sub2_t))) < 0) + if ((sub2_tid = H5Tcreate(H5T_COMPOUND, sizeof(sub2_t))) < 0) goto done; - if(H5Tinsert(sub2_tid, "a", HOFFSET(sub2_t, a), H5T_NATIVE_INT) < 0) + if (H5Tinsert(sub2_tid, "a", HOFFSET(sub2_t, a), H5T_NATIVE_INT) < 0) goto done; - if(H5Tinsert(sub2_tid, "b", HOFFSET(sub2_t, b), sub22_tid) < 0) + if (H5Tinsert(sub2_tid, "b", HOFFSET(sub2_t, b), sub22_tid) < 0) goto done; - if(H5Tinsert(sub2_tid, "c", HOFFSET(sub2_t, c), H5T_NATIVE_INT) < 0) + if (H5Tinsert(sub2_tid, "c", HOFFSET(sub2_t, c), H5T_NATIVE_INT) < 0) goto done; - if((sub4_tid = H5Tcreate(H5T_COMPOUND, sizeof(sub4_t))) < 0) + if ((sub4_tid = H5Tcreate(H5T_COMPOUND, sizeof(sub4_t))) < 0) goto done; - if(H5Tinsert(sub4_tid, "a", HOFFSET(sub4_t, a), H5T_NATIVE_INT) < 0) + if (H5Tinsert(sub4_tid, "a", HOFFSET(sub4_t, a), H5T_NATIVE_INT) < 0) goto done; - if(H5Tinsert(sub4_tid, "b", HOFFSET(sub4_t, b), H5T_NATIVE_INT) < 0) + if (H5Tinsert(sub4_tid, "b", HOFFSET(sub4_t, b), H5T_NATIVE_INT) < 0) goto done; - if((set_tid = H5Tcreate(H5T_COMPOUND, sizeof(set_t))) < 0) + if ((set_tid = H5Tcreate(H5T_COMPOUND, sizeof(set_t))) < 0) goto done; - if(H5Tinsert(set_tid, "field1", HOFFSET(set_t, field1), H5T_NATIVE_INT) < 0) + if (H5Tinsert(set_tid, "field1", HOFFSET(set_t, field1), H5T_NATIVE_INT) < 0) goto done; - if(H5Tinsert(set_tid, "field2", HOFFSET(set_t, field2), sub2_tid) < 0) + if (H5Tinsert(set_tid, "field2", HOFFSET(set_t, field2), sub2_tid) < 0) goto done; - if(H5Tinsert(set_tid, "field3", HOFFSET(set_t, field3), H5T_NATIVE_DOUBLE) < 0) + if (H5Tinsert(set_tid, "field3", HOFFSET(set_t, field3), H5T_NATIVE_DOUBLE) < 0) goto done; - if(H5Tinsert(set_tid, "field4", HOFFSET(set_t, field4), sub4_tid) < 0) + if (H5Tinsert(set_tid, "field4", HOFFSET(set_t, field4), sub4_tid) < 0) goto done; /* Create the compound type with escape/separator characters */ - if((esc_sub2_tid = H5Tcreate(H5T_COMPOUND, sizeof(sub2_t))) < 0) + if ((esc_sub2_tid = H5Tcreate(H5T_COMPOUND, sizeof(sub2_t))) < 0) goto done; - if(H5Tinsert(esc_sub2_tid, ".a", HOFFSET(sub2_t, a), H5T_NATIVE_INT) < 0) + if (H5Tinsert(esc_sub2_tid, ".a", HOFFSET(sub2_t, a), H5T_NATIVE_INT) < 0) goto done; - if(H5Tinsert(esc_sub2_tid, ",b", HOFFSET(sub2_t, b), sub22_tid) < 0) + if (H5Tinsert(esc_sub2_tid, ",b", HOFFSET(sub2_t, b), sub22_tid) < 0) goto done; - if(H5Tinsert(esc_sub2_tid, "\\K", HOFFSET(sub2_t, c), H5T_NATIVE_INT) < 0) + if (H5Tinsert(esc_sub2_tid, "\\K", HOFFSET(sub2_t, c), H5T_NATIVE_INT) < 0) goto done; - if((esc_sub4_tid = H5Tcreate(H5T_COMPOUND, sizeof(sub4_t))) < 0) + if ((esc_sub4_tid = H5Tcreate(H5T_COMPOUND, sizeof(sub4_t))) < 0) goto done; - if(H5Tinsert(esc_sub4_tid, "a.", HOFFSET(sub4_t, a), H5T_NATIVE_INT) < 0) + if (H5Tinsert(esc_sub4_tid, "a.", HOFFSET(sub4_t, a), H5T_NATIVE_INT) < 0) goto done; - if(H5Tinsert(esc_sub4_tid, "b,", HOFFSET(sub4_t, b), H5T_NATIVE_INT) < 0) + if (H5Tinsert(esc_sub4_tid, "b,", HOFFSET(sub4_t, b), H5T_NATIVE_INT) < 0) goto done; - if((esc_set_tid = H5Tcreate(H5T_COMPOUND, sizeof(set_t))) < 0) + if ((esc_set_tid = H5Tcreate(H5T_COMPOUND, sizeof(set_t))) < 0) goto done; - if(H5Tinsert(esc_set_tid, "field,1", HOFFSET(set_t, field1), H5T_NATIVE_INT) < 0) + if (H5Tinsert(esc_set_tid, "field,1", HOFFSET(set_t, field1), H5T_NATIVE_INT) < 0) goto done; - if(H5Tinsert(esc_set_tid, "field2.", HOFFSET(set_t, field2), esc_sub2_tid) < 0) + if (H5Tinsert(esc_set_tid, "field2.", HOFFSET(set_t, field2), esc_sub2_tid) < 0) goto done; - if(H5Tinsert(esc_set_tid, "field\\3", HOFFSET(set_t, field3), H5T_NATIVE_DOUBLE) < 0) + if (H5Tinsert(esc_set_tid, "field\\3", HOFFSET(set_t, field3), H5T_NATIVE_DOUBLE) < 0) goto done; - if(H5Tinsert(esc_set_tid, "field4,", HOFFSET(set_t, field4), esc_sub4_tid) < 0) + if (H5Tinsert(esc_set_tid, "field4,", HOFFSET(set_t, field4), esc_sub4_tid) < 0) goto done; /* Generate DSET_CMPD, DSET_CMPD_ESC */ - if(generate_dset(fid, DSET_CMPD, 1, cur_dims, max_dims, set_tid, one_cbuf) < 0) + if (generate_dset(fid, DSET_CMPD, 1, cur_dims, max_dims, set_tid, one_cbuf) < 0) goto done; - if(generate_dset(fid, DSET_CMPD_ESC, 1, cur_dims, max_dims, esc_set_tid, one_cbuf) < 0) + if (generate_dset(fid, DSET_CMPD_ESC, 1, cur_dims, max_dims, esc_set_tid, one_cbuf) < 0) goto done; /* Initialization for two-dimensional compound typed dataset */ @@ -301,48 +306,56 @@ main(void) max2_dims[0] = MAX_TWO_DIMS0; max2_dims[0] = MAX_TWO_DIMS1; - for(i = 0; i < (TWO_DIMS0 * TWO_DIMS1); i++) { - two_cbuf[i].field1 = 1; - two_cbuf[i].field2.a = 2; - two_cbuf[i].field2.c = 4; + for (i = 0; i < (TWO_DIMS0 * TWO_DIMS1); i++) { + two_cbuf[i].field1 = 1; + two_cbuf[i].field2.a = 2; + two_cbuf[i].field2.c = 4; two_cbuf[i].field2.b.a = 20; two_cbuf[i].field2.b.b = 40; two_cbuf[i].field2.b.c = 80; - two_cbuf[i].field3 = 3.0F; - two_cbuf[i].field4.a = 4; - two_cbuf[i].field4.b = 8; + two_cbuf[i].field3 = 3.0F; + two_cbuf[i].field4.a = 4; + two_cbuf[i].field4.b = 8; } /* end for */ /* Generate DSET_CMPD_TWO */ - if(generate_dset(fid, DSET_CMPD_TWO, 2, cur2_dims, max2_dims, set_tid, two_cbuf) < 0) + if (generate_dset(fid, DSET_CMPD_TWO, 2, cur2_dims, max2_dims, set_tid, two_cbuf) < 0) goto done; /* Closing */ - if(H5Tclose(sub22_tid) < 0) goto done; - if(H5Tclose(sub2_tid) < 0) goto done; - if(H5Tclose(sub4_tid) < 0) goto done; - if(H5Tclose(set_tid) < 0) goto done; - if(H5Tclose(esc_sub2_tid) < 0) goto done; - if(H5Tclose(esc_sub4_tid) < 0) goto done; - if(H5Tclose(esc_set_tid) < 0) goto done; - if(H5Pclose(fapl) < 0) goto done; - if(H5Fclose(fid) < 0) goto done; + if (H5Tclose(sub22_tid) < 0) + goto done; + if (H5Tclose(sub2_tid) < 0) + goto done; + if (H5Tclose(sub4_tid) < 0) + goto done; + if (H5Tclose(set_tid) < 0) + goto done; + if (H5Tclose(esc_sub2_tid) < 0) + goto done; + if (H5Tclose(esc_sub4_tid) < 0) + goto done; + if (H5Tclose(esc_set_tid) < 0) + goto done; + if (H5Pclose(fapl) < 0) + goto done; + if (H5Fclose(fid) < 0) + goto done; HDexit(EXIT_SUCCESS); done: H5E_BEGIN_TRY - H5Tclose(sub22_tid); - H5Tclose(sub2_tid); - H5Tclose(sub4_tid); - H5Tclose(set_tid); - H5Tclose(esc_sub2_tid); - H5Tclose(esc_sub4_tid); - H5Tclose(esc_set_tid); - H5Pclose(fapl); - H5Fclose(fid); + H5Tclose(sub22_tid); + H5Tclose(sub2_tid); + H5Tclose(sub4_tid); + H5Tclose(set_tid); + H5Tclose(esc_sub2_tid); + H5Tclose(esc_sub4_tid); + H5Tclose(esc_set_tid); + H5Pclose(fapl); + H5Fclose(fid); H5E_END_TRY HDexit(EXIT_FAILURE); } /* end main() */ - diff --git a/hl/tools/h5watch/swmr_check_compat_vfd.c b/hl/tools/h5watch/swmr_check_compat_vfd.c index 608f4a8..fb1c903 100644 --- a/hl/tools/h5watch/swmr_check_compat_vfd.c +++ b/hl/tools/h5watch/swmr_check_compat_vfd.c @@ -22,11 +22,10 @@ #include "H5private.h" /* This file needs to access the file driver testing code */ -#define H5FD_FRIEND /*suppress error about including H5FDpkg */ +#define H5FD_FRIEND /*suppress error about including H5FDpkg */ #define H5FD_TESTING -#include "H5FDpkg.h" /* File drivers */ +#include "H5FDpkg.h" /* File drivers */ - /*------------------------------------------------------------------------- * Function: main * @@ -48,10 +47,9 @@ main(void) driver = HDgetenv("HDF5_DRIVER"); - if(H5FD__supports_swmr_test(driver)) + if (H5FD__supports_swmr_test(driver)) return EXIT_SUCCESS; else return EXIT_FAILURE; } /* end main() */ - |