HDF5 Extras
0.0.1
Convenience Functions for using HDF5 Better
|
Go to the source code of this file.
Data Structures | |
struct | IFILE |
Functions | |
IFILE * | IFileOpen (hid_t file_id, const char *ifilename, const char *access) |
IFileOpen is used to open an internal file in a GeoSci File. More... | |
int | IFileClearError (IFILE *ifilep) |
IFileClearError clears the error condition on an internal file. More... | |
int | IFileClose (IFILE *ifilep) |
IFileClose closes an internal file in a GeoSci File. More... | |
int | IFileEOF (IFILE *ifilep) |
IFileEOF returns the End-Of-File condition of the previous internal read. More... | |
int | IFileError (IFILE *ifilep) |
IFileError returns error condition on an internal file. More... | |
int | IFileFlush (IFILE *ifilep) |
IFileFlush flushes unwritten buffers to an internal file in a GeoSci File. More... | |
int | IFileGetc (IFILE *ifilep) |
IFileGetc reads a character from an internal file. More... | |
char * | IFileGets (IFILE *ifilep, char *str, int num) |
IFileGets reads characters from an internal file in a geosci file, and stores them as a string until the maximum number of characters have been read or either a newline or the end-of-file is reached, whichever happens first. More... | |
int | IFileSeek (IFILE *ifilep, long int offset, int origin) |
IFileSeek moves to a position in an internal file. More... | |
long int | IFileTell (IFILE *ifilep) |
IFileTell retrieves the current read/write position in an internal file. More... | |
int | IFileRewind (IFILE *ifilep) |
IFileRewind moves to the start of an internal file. More... | |
int | IFilePerror (IFILE *ifilep, const char *str) |
IFilePerror prints latest error for an internal file. More... | |
int | IFileReadAccess (IFILE *ifilep) |
IFileReadAccess reads access code of an internal file. More... | |
int | IFileReadAccessHDF (hid_t dataset_id) |
IFileReadAccessHDF reads access code of an internal file. More... | |
int | IFileWriteAccess (IFILE *ifilep, int code) |
IFileWriteAccess writes a new access code for an internal file. More... | |
int | IFileAllocate (IFILE *ifilep, long int offset, long int length) |
IFileAllocate is used to allocate more space to an internal file. More... | |
int | IFilePrintf (IFILE *ifilep, const char *format,...) |
IFilePrintf writes formatted data to an internal file. More... | |
int | IFilePutc (IFILE *ifilep, char character) |
IFilePutc writes a single character to an internal file. More... | |
int | IFilePuts (IFILE *ifilep, const char *string) |
IFilePuts writes a string to an internal file. More... | |
size_t | IFileRead (IFILE *ifilep, void *buf, int size, int count) |
IFileRead reads the requested number of bytes from an internal file in a geosci file. More... | |
int | IFileReadStatus (IFILE *ifilep, char **message) |
IFileReadStatus reads the status properties of an internal file. More... | |
int | IFileWriteStatus (IFILE *ifilep, int status, const char *message) |
IFileWriteStatus writes the status properties of an internal file. More... | |
int | IFileWriteStatusMessage (IFILE *ifilep, const char *message) |
IFileWriteStatusMessage writes the status message of an internal file. More... | |
int | IFileScanf (IFILE *ifilep, const char *format,...) |
IFileScanf reads formatted data from an internal file. More... | |
int | IFileSetEOF (IFILE *ifilep, int value) |
IFileSetEOF sets End-Of-File condition on an internal file. More... | |
int | IFileSetWriteability (hid_t file_id, const char *name, int property) |
IFileSetWriteability sets the read/write property of an internal file. More... | |
int | IFileGetWrite (IFILE *ifilep) |
IFileGetWrite gets the read/write property of an internal file. More... | |
int | IFileSetWrite (IFILE *ifilep, int property) |
IFileSetWrite sets the read/write property of an internal file. More... | |
int | IFileGetWriteDataset (hid_t dataset_id) |
IFileGetWriteDataset gets the read/write property of an internal file. More... | |
long int | IFileSize (IFILE *ifilep) |
IFileSize gets the #bytes in an internal file. More... | |
long int | IFileSizeHDF (IFILE *ifilep) |
IFileSizeHDF gets the #bytes in an internal file. More... | |
int | IFileTruncate (IFILE *ifilep, long int length) |
IFileTruncate changes the size of an internal file. More... | |
int | IFileWrite (IFILE *ifilep, const void *buf, int size, int count) |
IFileWrite writes bytes to an internal file. More... | |
int | IFileReadALine (IFILE *ifilep, char *str, int num) |
IFileReadALine reads a string from an internal file. More... | |
int IFileAllocate | ( | IFILE * | ifilep, |
long int | offset, | ||
long int | length | ||
) |
IFileAllocate is used to allocate more space to an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | offset | The offset, in bytes, from the start of the file where the newly-allocates bytes must start. Should be >= 0. |
[in] | length | The length, in bytes, of the region of the newly-allocated bytes. Should be >0. |
int IFileClearError | ( | IFILE * | ifilep | ) |
IFileClearError clears the error condition on an internal file.
[in] | ifilep | The struct of the open internal file. |
int IFileClose | ( | IFILE * | ifilep | ) |
IFileClose closes an internal file in a GeoSci File.
[in] | ifilep | The struct of the open internal file. |
int IFileEOF | ( | IFILE * | ifilep | ) |
IFileEOF returns the End-Of-File condition of the previous internal read.
[in] | ifilep | The struct of the open internal file. |
int IFileError | ( | IFILE * | ifilep | ) |
IFileError returns error condition on an internal file.
[in] | ifilep | The struct of the open internal file. |
int IFileFlush | ( | IFILE * | ifilep | ) |
IFileFlush flushes unwritten buffers to an internal file in a GeoSci File.
[in] | ifilep | The struct of the open internal file. |
int IFileGetc | ( | IFILE * | ifilep | ) |
IFileGetc reads a character from an internal file.
[in] | ifilep | The struct of the open internal file. |
char* IFileGets | ( | IFILE * | ifilep, |
char * | str, | ||
int | num | ||
) |
IFileGets reads characters from an internal file in a geosci file, and stores them as a string until the maximum number of characters have been read or either a newline or the end-of-file is reached, whichever happens first.
[in] | ifilep | The struct of the open internal file. |
[in,out] | str | Pointer to an array of chars where the string read is copied. |
[in] | num | Maximum number of characters to be copied into str (including the terminating null-character). |
On success, the function returns str
.
If the end-of-file is encountered while attempting to read a character, the eof indicator is set (IFileEOF). If this happens before any characters could be read, the pointer returned is a null pointer (and the contents of str
remain unchanged).
If a read error occurs, the error indicator (IFileError) is set and a null pointer is also returned (but the contents pointed-to by str
may have changed).
int IFileGetWrite | ( | IFILE * | ifilep | ) |
IFileGetWrite gets the read/write property of an internal file.
[in] | ifilep | The struct of the open internal file. |
TRUE is returned if the internal file is writeable, FALSE if not writeable.
ERROR is returned on any kind of error. The error_string variable is also set to a system-specific error code on failure.
int IFileGetWriteDataset | ( | hid_t | dataset_id | ) |
IFileGetWriteDataset gets the read/write property of an internal file.
[in] | id; | The handle of the open dataset. |
TRUE
is returned if the dataset is writeable, FALSE
if not writeable.
ERROR is returned on any kind of error. The error_string
variable is also set to a system-specific error code on failure.
IFILE* IFileOpen | ( | hid_t | file_id, |
const char * | ifilename, | ||
const char * | access | ||
) |
IFileOpen is used to open an internal file in a GeoSci File.
[in] | file_id | The handle of the open GeoSci file. |
[in] | ifilename | The name of the internal file in an existing GeoSci file to be opened. Use Unix filenaming conventions, giving the full pathname, starting with "/". All but the last component of this name must already exist. |
[in] | access | Access mode for the IFile, similar to that used for files:
The letter "x" can be appended to any "w" specifier (to form "wx" or "w+x"). This subspecifier forces the function to fail if the internal file exists, instead of overwriting it. |
This function is meant to emulate as close as possible the standard C fopen() function.
For internal files open for update (those which include a "+" sign), on which both input and output operations are allowed, the file should be flushed (IFileFlush) or repositioned (IFileSeek, IFileSetpos, IFileRewind) between either a writing operation followed by a reading operation or a reading operation which did not reach the end-of-file followed by a writing operation.
When appropriate, this routine creates a single-dimensional unsigned-8-bit dataset with the given name. The components of the pathname above the filename must already exist, and be HDF5 groups in order for this to work.
Note that even if you intend to only read from an IFile, you need to open the GeoSci file for reading AND writing ("r+"). This is because the state of the internal file is written to metadata in the GeoSci file, even if one is only reading from the IFile.
For developers, the details of the implementation are presented here.
The complete list of all 34 IFile-related functions is given below:
Some of these are named based on the standard C library functions that they emulate. Others are implementation-specific functions.
The overall idea of a IFile is that of a HDF5 dataset. This dataset is 1-dimensional, with a datatype of unsigned-8-bit. It is infinitely extendable. It has three string attributes:
The returned data structure is defined as:
int IFilePerror | ( | IFILE * | ifilep, |
const char * | str | ||
) |
IFilePerror prints latest error for an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | str | String containing a custom message to be printed before the error message itself. If it is a null pointer, no preceding custom message is printed, but the error message is still printed. By convention, the name of the application itself is generally used as parameter. |
TRUE is returned on success, FALSE otherwise.
This function should be called right after the error was produced, otherwise the error of interest can be overwritten by calls to other functions.
stdout
, optionally preceded by the custom message provided in str. This function is meant to emulate as close as possible the standard C perror() function. int IFilePrintf | ( | IFILE * | ifilep, |
const char * | format, | ||
... | |||
) |
IFilePrintf writes formatted data to an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | format | String that contains the text to be written to the internal file. It can optionally contain embedded format specifiers that are replaced by the values specified in subsequent additional arguments and formatted as requested. See docs for fscanf() in any C book for the complete details. |
[in] | ... | (additional arguments) Depending on the format string, the function may expect a sequence of additional arguments, each containing a pointer to allocated storage where the interpretation of the extracted characters is stored with the appropriate type. There should be at least as many of these arguments as the number of values stored by the format specifiers. Additional arguments are ignored by the function. |
On success, the function returns the number of characters successfully written.
If a reading error happens or the end-of-file is reached while reading, the proper indicator is set (IFileEOF() or IFileError()). And, if either happens before any data could be successfully written, ERROR is returned.
The error_string variable is also set to a system-specific error code on failure.
This function is meant to emulate as close as possible the standard C fprintf()
function.
Writes the string pointed by format to the internal file. If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.
After the format parameter, the function expects at least as many additional arguments as specified by format.
int IFilePutc | ( | IFILE * | ifilep, |
char | character | ||
) |
IFilePutc writes a single character to an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | character | The character to write. |
On success, TRUE is returned.
If some writing error happens, the function returns FALSE, and sets its error indicator (IFileError).
fputc()
function. int IFilePuts | ( | IFILE * | ifilep, |
const char * | string | ||
) |
IFilePuts writes a string to an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | string | The character string to write. |
fputs()
function. size_t IFileRead | ( | IFILE * | ifilep, |
void * | buf, | ||
int | size, | ||
int | count | ||
) |
IFileRead reads the requested number of bytes from an internal file in a geosci file.
[in] | ifilep | The struct of the open internal file. |
[in,out] | buf | Pointer to an array where the bytes read are copied to. This must have at least size*count bytes of storage. Using a void pointer here allows the user to pass a buf variable of any type. |
[in] | size | Size in bytes of each element to be read. |
[in] | count | Number of elements to read. Each element has a size of "size" bytes. |
The total number of elements successfully read is returned.
If this number differs from the count parameter, either a reading error occurred or the end-of-file was reached while reading. In both cases, the proper indicator is set, which can be checked with IFileError and IFileEOF, respectively.
If either size
or count
is less than or equal to zero, the function returns zero and both the internal-file state and the content pointed to by buf
remain unchanged.
This function is meant to emulate as close as possible the standard C fread()
function.
The types of size and count are purposely int
and not size_t
because if the user accidentally passes a negative value the value becomes a very big number when casted to an unsigned integer, which is what size_t
is. In order to detect this error, int
is used instead.
int IFileReadAccess | ( | IFILE * | ifilep | ) |
IFileReadAccess reads access code of an internal file.
[in] | ifilep | The struct of the open internal file. |
IFILE_CLOSED
0 IFILE_R
1 IFILE_W
2 IFILE_A
3 IFILE_RP
4 IFILE_WP
5 IFILE_AP
6 int IFileReadAccessHDF | ( | hid_t | dataset_id | ) |
IFileReadAccessHDF reads access code of an internal file.
[in] | datset_id | The hdf-id of the open internal file dataset-object. |
IFILE_CLOSED
0 IFILE_R
1 IFILE_W
2 IFILE_A
3 IFILE_RP
4 IFILE_WP
5 IFILE_AP
6 ERROR
is returned.int IFileReadALine | ( | IFILE * | ifilep, |
char * | str, | ||
int | num | ||
) |
IFileReadALine reads a string from an internal file.
IFileReadALine() reads characters from an internal file in a geosci file, and stores them as a string until the maximum number of characters have been read or either a newline or the end-of-file is reached, whichever happens first.
[in] | ifilep | The struct of the open internal file. |
[in,out] | str | Pointer to an array of chars where the string read is copied. |
[in] | num | Maximum number of characters to be copied into str (including the terminating null-character). |
This function uses IFileGets() to read the data, any errors encountered will cause this routine to return ERROR.
If the read succeeds, but the last character read is NOT a newline, then it returns FALSE.
If there are no read errors, and a complete line is read, then TRUE is returned.
int IFileReadStatus | ( | IFILE * | ifilep, |
char ** | message | ||
) |
IFileReadStatus reads the status properties of an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | message | Returned Message associated with the status. No need to GFree it when done. |
IFILE_SUCCESS
– the last IFile operation succeededIFILE_FAILURE
– the last IFile operation failedFALSE
is returned. The error_string
variable is also set to a system-specific error code on failure.int IFileRewind | ( | IFILE * | ifilep | ) |
IFileRewind moves to the start of an internal file.
[in] | ifilep | The struct of the open internal file. |
TRUE
is returned on success, FALSE
otherwise. The error_string
variable is also set to a system-specific error code on failure.rewind()
function. int IFileScanf | ( | IFILE * | ifilep, |
const char * | format, | ||
... | |||
) |
IFileScanf reads formatted data from an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | format | String that contains a sequence of characters that control how characters extracted from the stream are treated. See docs for fscanf() in any C book for the complete details. |
[in] | ... | (additional arguments) Depending on the format string, the function may expect a sequence of additional arguments, each containing a pointer to allocated storage where the interpretation of the extracted characters is stored with the appropriate type. There should be at least as many of these arguments as the number of values stored by the format specifiers. Additional arguments are ignored by the function. These arguments are expected to be pointers: to store the result of a IFileScanf operation on a regular variable, its name should be preceded by the reference operator (&) (see example). |
On success, the function returns the number of items of the argument list successfully filled. This count can match the expected number of items or be less (even zero) due to a matching failure, a reading error, or the reaching of the end-of-file.
If a reading error happens or the end-of-file is reached while reading, the proper indicator is set (IFileEOF() or IFileError()). And, if either happens before any data could be successfully read, ERROR
is returned.
The error_string
variable is also set to a system-specific error code on failure.
fscanf()
function. int IFileSeek | ( | IFILE * | ifilep, |
long int | offset, | ||
int | origin | ||
) |
IFileSeek moves to a position in an internal file.
[in] | ifilep | The struct of the open internal file. | ||||||||
[in] | offset | Offset, in bytes, from a reference position where the new file pointer is desired to go. [in] origin Position used as reference for the offset. Specify one of the following constants :
|
TRUE
is returned on success, FALSE
otherwise.
For situations where the new position would be before the first byte, the file pointer position is not changed, and FALSE
is returned.
For situations where the new position is beyond the last byte, this is allowed, but a subsequent read will fail. A subsequent write will "fill in" NULL
bytes to get to this point before writing.
The error_string variable is also set to a system-specific error code on failure.
fseek()
function. int IFileSetEOF | ( | IFILE * | ifilep, |
int | value | ||
) |
IFileSetEOF sets End-Of-File condition on an internal file.
[in] | filep | The struct of the open internal file. |
[in] | value | The value to set the EOF condition to, one of:TRUE (if there was an EOF ), or:FALSE (there was not an EOF ) |
TRUE
is returned when the condition is set successfully, FALSE
if not. The error_string
variable is also set to a system-specific error code on failure.EOF
on an internal file named "/somename" succeeded or not. int IFileSetWrite | ( | IFILE * | ifilep, |
int | property | ||
) |
IFileSetWrite sets the read/write property of an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | property | The value to set the read/write property to: GS_READ – internal file set to read-only mode GS_WRITE – internal file set to read and write mode |
TRUE
is returned on success, FALSE
otherwise. The error_string
variable is also set to a system-specific error code on failure. int IFileSetWriteability | ( | hid_t | file_id, |
const char * | name, | ||
int | property | ||
) |
IFileSetWriteability sets the read/write property of an internal file.
[in] | file_id | The handle of the open geosci file. |
[in] | name | Name of the internal file whose properties need to be altered. The internal file must not be open, otherwise this operation will fail. |
[in] | property | The value to set the read/write property to:GS_READ – internal file set to read-only modeGS_WRITE – internal file set to read and write mode |
TRUE
is returned on success, FALSE
otherwise. The error_string
variable is also set to a system-specific error code on failure.long int IFileSize | ( | IFILE * | ifilep | ) |
IFileSize gets the #bytes in an internal file.
[in] | ifilep | The struct of the open internal file. |
long int IFileSizeHDF | ( | IFILE * | ifilep | ) |
IFileSizeHDF gets the #bytes in an internal file.
[in] | ifilep | The struct of the open internal file. |
long int IFileTell | ( | IFILE * | ifilep | ) |
IFileTell retrieves the current read/write position in an internal file.
[in] | ifilep | The struct of the open internal file. |
error_string
variable is also set to a system-specific error code on failure. ftell()
function. int IFileTruncate | ( | IFILE * | ifilep, |
long int | length | ||
) |
IFileTruncate changes the size of an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | length | The desired length, in bytes, of the file. Must be >= 0. |
TRUE
is returned on success, FALSE
otherwise. The error_string
variable is also set to a system-specific error code on failure. length
, then the file is increased to this size. If the size of the file is greater than length
, then the file is decreased to this size. This function is meant to emulate as close as possible the standard C ftruncate()
function. int IFileWrite | ( | IFILE * | ifilep, |
const void * | buf, | ||
int | size, | ||
int | count | ||
) |
IFileWrite writes bytes to an internal file.
[in] | ifilep | The struct of the open internal file. |
[in,out] | buf | Pointer to an array where the bytes to write are read from. This must have at least size*count bytes of storage. Using a void pointer here allows the user to pass a buf variable of any type. |
[in] | size | Size in bytes of each element to be written. |
[in] | count | Number of elements to write. Each element has a size of "size" bytes. |
The total number of elements successfully written is returned.
If this number differs from the count parameter, a writing error prevented the function from completing. In this case, the error indicator (IFileError) will be set for the stream.
If either size or count is less than or equal to zero, the function returns zero and both the internal-file state and the content pointed to by buf
remain unchanged.
fwrite()
function. int IFileWriteAccess | ( | IFILE * | ifilep, |
int | code | ||
) |
IFileWriteAccess writes a new access code for an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | code | The access code one wishes to write to the file, one of:IFILE_CLOSED 0 IFILE_R 1 IFILE_W 2 IFILE_A 3 IFILE_RP 4 IFILE_WP 5 IFILE_AP 6 |
TRUE
is returned on success, FALSE
on failure. int IFileWriteStatus | ( | IFILE * | ifilep, |
int | status, | ||
const char * | message | ||
) |
IFileWriteStatus writes the status properties of an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | status | The value to set the status property to:IFILE_SUCCESS – the last IFile operation succeeded IFILE_FAILURE – the last IFile operation failed |
[in] | message | Message associated with the status. |
TRUE
is returned on success, FALSE
otherwise. The error_string
variable is also set to a system-specific error code on failure. int IFileWriteStatusMessage | ( | IFILE * | ifilep, |
const char * | message | ||
) |
IFileWriteStatusMessage writes the status message of an internal file.
[in] | ifilep | The struct of the open internal file. |
[in] | message | Message associated with the status. |
TRUE
is returned on success, FALSE
otherwise. The error_string
variable is also set to a system-specific error code on failure.