NCEPLIBS-g2
3.5.0
|
Subroutines for dealing with indexes. More...
Go to the source code of this file.
Functions/Subroutines | |
subroutine | g2_create_index (lugb, lugi, idxver, filename, iret) |
Create a version 1 or 2 index file for a GRIB2 file. More... | |
subroutine | g2_write_index_headers (lugi, nlen, nnum, idxver, filename) |
Write index headers. More... | |
subroutine | getg2i (lugi, cbuf, nlen, nnum, iret) |
Read a version 1 index file and return its contents. More... | |
subroutine | getg2i2 (lugi, cbuf, idxver, nlen, nnum, iret) |
Read a version 1 or 2 index file and return its contents. More... | |
subroutine | getg2i2r (lugb, msk1, msk2, mnum, idxver, cbuf, nlen, nnum, nmess, iret) |
Generate a version 1 or 2 index record for each message in a GRIB2 file. More... | |
subroutine | getg2ir (lugb, msk1, msk2, mnum, cbuf, nlen, nnum, nmess, iret) |
Generate a version 1 index record for each message in a GRIB2 file. More... | |
subroutine | getgb2s (cbuf, nlen, nnum, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, k, gfld, lpos, iret) |
Find information about a GRIB field from the index and fill a grib_mod::gribfield. More... | |
subroutine | getgb2s2 (cbuf, idxver, nlen, nnum, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, k, gfld, lpos, iret) |
Find information about a GRIB field from the index and fill a grib_mod::gribfield. More... | |
subroutine | getidx (lugb, lugi, cindex, nlen, nnum, iret) |
Find, read or generate a version 1 GRIB2 index for a GRIB2 file (which must be < 2 GB). More... | |
subroutine | getidx2 (lugb, lugi, idxver, cindex, nlen, nnum, iret) |
Find, read or generate a version 1 or 2 GRIB2 index for a GRIB2 file (which may be > 2 GB). More... | |
subroutine | gf_finalize (iret) |
Free all memory associated with the library. More... | |
subroutine | ix2gb2 (lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret) |
Generate a version 1 or 2 index record for each field in a GRIB2 message. More... | |
subroutine | ixgb2 (lugb, lskip, lgrib, cbuf, numfld, mlen, iret) |
Generate a version 1 index record for each field in a GRIB2 message. More... | |
subroutine g2_create_index | ( | integer, intent(in) | lugb, |
integer, intent(in) | lugi, | ||
integer, intent(in) | idxver, | ||
character*(*) | filename, | ||
integer, intent(out) | iret | ||
) |
Create a version 1 or 2 index file for a GRIB2 file.
[in] | lugb | Logical unit of opened GRIB2 file. |
[in] | lugi | Logical unit file opened to write index to. |
[in] | idxver | Index version. |
[in] | filename | Name of GRIB2 file. This file must already be open, with logical unit passed to the lugb parameter. The filename is also encoded in one of the index header records. |
[out] | iret | Return code:
|
Definition at line 20 of file g2index.F90.
References g2_write_index_headers(), and getg2i2r().
subroutine g2_write_index_headers | ( | integer, intent(in) | lugi, |
integer, intent(in) | nlen, | ||
integer, intent(in) | nnum, | ||
integer, intent(in) | idxver, | ||
character, dimension(*), intent(in) | filename | ||
) |
Write index headers.
[in] | lugi | integer logical unit of output index file |
[in] | nlen | integer total length of index records |
[in] | nnum | integer number of index records |
[in] | idxver | Index version, 1 for legacy, 2 for files that may be > 2 GB. |
[in] | filename | character name of GRIB file |
Definition at line 102 of file g2index.F90.
Referenced by g2_create_index().
subroutine getg2i | ( | integer, intent(in) | lugi, |
character(len=1), dimension(:), pointer | cbuf, | ||
integer, intent(out) | nlen, | ||
integer, intent(out) | nnum, | ||
integer, intent(out) | iret | ||
) |
Read a version 1 index file and return its contents.
The index file may be generated by the grb2index utility of the NCEPLIBS-grib_util project.
For the contents of the index file, see getgi2().
This subroutine is maintained for backward compatibility, and may only be used with version 1 of the index files. To handle both version 1 and 2 index files, use getg2i2().
[in] | lugi | Integer unit of the GRIB index file. Must be opened by baopen() or baopenr(). |
[out] | cbuf | Pointer to a buffer that will get the index records. Memory will be allocated within this function, so callers must free the memory that cbuf points to, using deallocate(cbuf) when cbuf is no longer needed. |
[out] | nlen | Total length of all index records. |
[out] | nnum | Number of index records. |
[out] | iret | Return code.
|
Definition at line 429 of file g2index.F90.
References getg2i2().
subroutine getg2i2 | ( | integer, intent(in) | lugi, |
character(len=1), dimension(:), pointer | cbuf, | ||
integer, intent(out) | idxver, | ||
integer, intent(out) | nlen, | ||
integer, intent(out) | nnum, | ||
integer, intent(out) | iret | ||
) |
Read a version 1 or 2 index file and return its contents.
The index file may be generated by the grb2index utility of the NCEPLIBS-grib_util project.
The index file has two header records:
Each record in the index table contains the following fields. All integers are in big-endian format in the file. The only difference between index version 1 and index version 2 is the size of the field containing the number of bytes to skip in file before message. To accomodate files > 2 GB, this must be a 64-bit int.
Index Version 1 | Index Version 2 | Contents |
---|---|---|
001 - 004 | 001 - 004 | length of index record (4 bytes) |
005 - 008 | 005 - 012 | bytes to skip in data file before grib message (4/8 bytes) |
009 - 012 | 013 - 020 | bytes to skip in message before lus (local use) set = 0, if no local section. (4/8 bytes) |
013 - 016 | 021 - 028 | bytes to skip in message before gds (4/8 bytes) |
017 - 020 | 029 - 036 | bytes to skip in message before pds (4/8 bytes) |
021 - 024 | 037 - 044 | bytes to skip in message before drs (4/8 bytes) |
025 - 028 | 045 - 052 | bytes to skip in message before bms (4/8 bytes) |
029 - 032 | 053 - 060 | bytes to skip in message before data section (4/8 bytes) |
033 - 040 | 061 - 068 | bytes total in the message (8 bytes) |
041 - 041 | 069 - 069 | grib version number (always 2) (1 byte) |
042 - 042 | 070 - 070 | message discipline (1 byte) |
043 - 044 | 071 - 072 | field number within grib2 message (2 bytes) |
045 - ii | 073 - ii | identification section (ids) (character) |
ii+1- jj | ii+1- jj | grid definition section (gds) (character) |
jj+1- kk | jj+1- kk | product definition section (pds) (character) |
kk+1- ll | kk+1- ll | the data representation section (drs) (character) |
ll+1-ll+6 | ll+1-ll+6 | first 6 bytes of the bit map section (bms) (character) |
[in] | lugi | Integer unit of the unblocked GRIB index file. Must be opened by baopen() or baopenr(). |
[out] | cbuf | Pointer to a buffer that will get the index records. Memory will be allocated within this function, so callers must free the memory that cbuf points to, using deallocate(cbuf) when cbuf is no longer needed. |
[out] | idxver | Index version of this index, will be 1 or 2. |
[out] | nlen | Total length of all index records. |
[out] | nnum | Number of index records. |
[out] | iret | Return code.
|
Definition at line 511 of file g2index.F90.
References g2logging::g2_log(), and g2logging::g2_log_msg.
Referenced by getg2i(), getgb2p2(), and getidx2().
subroutine getg2i2r | ( | integer, intent(in) | lugb, |
integer (kind = 8), intent(in) | msk1, | ||
integer (kind = 8), intent(in) | msk2, | ||
integer, intent(in) | mnum, | ||
integer, intent(in) | idxver, | ||
character(len = 1), dimension(:), pointer | cbuf, | ||
integer, intent(out) | nlen, | ||
integer, intent(out) | nnum, | ||
integer, intent(out) | nmess, | ||
integer, intent(out) | iret | ||
) |
Generate a version 1 or 2 index record for each message in a GRIB2 file.
The index record contains byte offsets to the message, it's length, and byte offsets within the message to each section. The index file record format is documented in subroutine ixgb2().
[in] | lugb | Unit of the GRIB file. Must be opened by baopen() or baopenr(). |
[in] | msk1 | Number of bytes to search for first message. |
[in] | msk2 | Number of bytes to search for other messages. |
[in] | mnum | Number of GRIB messages to skip (usually 0). |
[in] | idxver | Index version number. Use 1 for legacy, 2 for files > 2 GB. |
[out] | cbuf | Pointer to a buffer that will get the index records. If any memory is associated with cbuf when this subroutine is called, cbuf will be nullified in the subroutine. Initially cbuf will get an allocation of 5000 bytes. realloc() will be used to increase the size if necessary. Users must free memory that cbuf points to when cbuf is no longer needed. |
[out] | nlen | Total length of index record buffer in bytes. |
[out] | nnum | Number of index records, zero if no GRIB messages are found. |
[out] | nmess | Last GRIB message in file successfully processed |
[out] | iret | Return code.
|
Definition at line 648 of file g2index.F90.
References g2logging::g2_log(), g2logging::g2_log_msg, ix2gb2(), and skgb8().
Referenced by g2_create_index(), getg2ir(), getgb2p2(), and getidx2().
subroutine getg2ir | ( | integer, intent(in) | lugb, |
integer, intent(in) | msk1, | ||
integer, intent(in) | msk2, | ||
integer, intent(in) | mnum, | ||
character(len = 1), dimension(:), pointer | cbuf, | ||
integer, intent(out) | nlen, | ||
integer, intent(out) | nnum, | ||
integer, intent(out) | nmess, | ||
integer, intent(out) | iret | ||
) |
Generate a version 1 index record for each message in a GRIB2 file.
The index record contains byte offsets to the message, it's length, and byte offsets within the message to each section. The index file record format is documented in subroutine ixgb2().
[in] | lugb | Unit of the unblocked GRIB file. Must be opened by baopen() or baopenr(). |
[in] | msk1 | Number of bytes to search for first message. |
[in] | msk2 | Number of bytes to search for other messages. |
[in] | mnum | Number of GRIB messages to skip (usually 0). |
[out] | cbuf | Pointer to a buffer that will get the index records. If any memory is associated with cbuf when this subroutine is called, cbuf will be nullified in the subroutine. Initially cbuf will get an allocation of 5000 bytes. realloc() will be used to increase the size if necessary. Users must free memory that cbuf points to when cbuf is no longer needed. |
[out] | nlen | Total length of index record buffer in bytes. |
[out] | nnum | Number of index records, zero if no GRIB messages are found. |
[out] | nmess | Last GRIB message in file successfully processed |
[out] | iret | Return code.
|
Definition at line 587 of file g2index.F90.
References getg2i2r().
subroutine getgb2s | ( | character(len = 1), dimension(nlen), intent(in) | cbuf, |
integer, intent(in) | nlen, | ||
integer, intent(in) | nnum, | ||
integer, intent(in) | j, | ||
integer, intent(in) | jdisc, | ||
integer, dimension(*) | jids, | ||
integer, intent(in) | jpdtn, | ||
integer, dimension(*) | jpdt, | ||
integer, intent(in) | jgdtn, | ||
integer, dimension(*) | jgdt, | ||
integer, intent(out) | k, | ||
type(gribfield), intent(out) | gfld, | ||
integer, intent(out) | lpos, | ||
integer, intent(out) | iret | ||
) |
Find information about a GRIB field from the index and fill a grib_mod::gribfield.
For a description of the index record see getg2i2().
Users of this routine will need to include the line "use grib_mod" in their calling routine.
The unpacked bitmap and bitmap data field are the only components of the grib_mod::gribfield type not set by this routine.
[in] | cbuf | Buffer (of size nlen bytes) containing index data. |
[in] | nlen | Total length of all index records. |
[in] | nnum | Number of index records. |
[in] | j | Number of fields to skip (0 to search from beginning). |
[in] | jdisc | GRIB2 discipline number of requested field. See GRIB2 - TABLE 0.0 - DISCIPLINE. Use -1 to accept any discipline. |
[in] | jids | Array of values in the identification section. (Set to -9999 for wildcard.)
|
[in] | jpdtn | Product Definition Template (PDT) number (n) (if = -1, don't bother matching PDT - accept any). |
[in] | jpdt | Array of values defining the Product Definition Template of the field for which to search (=-9999 for wildcard). |
[in] | jgdtn | Grid Definition Template (GDT) number (if = -1, don't bother matching GDT - accept any). |
[in] | jgdt | array of values defining the Grid Definition Template of the field for which to search (=-9999 for wildcard). |
[out] | k | Field number unpacked. |
[out] | gfld | Derived type grib_mod::gribfield. |
[out] | lpos | Starting position of the found index record within the complete index buffer, CBUF. = 0, if request not found. |
[out] | iret | integer return code:
|
Definition at line 814 of file g2index.F90.
References getgb2s2().
subroutine getgb2s2 | ( | character(len = 1), dimension(nlen), intent(in) | cbuf, |
integer, intent(in) | idxver, | ||
integer, intent(in) | nlen, | ||
integer, intent(in) | nnum, | ||
integer, intent(in) | j, | ||
integer, intent(in) | jdisc, | ||
integer, dimension(*) | jids, | ||
integer, intent(in) | jpdtn, | ||
integer, dimension(*) | jpdt, | ||
integer, intent(in) | jgdtn, | ||
integer, dimension(*) | jgdt, | ||
integer, intent(out) | k, | ||
type(gribfield), intent(out) | gfld, | ||
integer, intent(out) | lpos, | ||
integer, intent(out) | iret | ||
) |
Find information about a GRIB field from the index and fill a grib_mod::gribfield.
For a description of the index record see getg2i2().
Users of this routine will need to include the line "use grib_mod" in their calling routine.
The unpacked bitmap and bitmap data field are the only components of the grib_mod::gribfield type not set by this routine.
[in] | cbuf | Buffer (of size nlen bytes) containing index data. |
[in] | idxver | Index version, 1 for legacy, 2 if files may be > 2 GB. |
[in] | nlen | Total length of all index records. |
[in] | nnum | Number of index records. |
[in] | j | Number of fields to skip (0 to search from beginning). |
[in] | jdisc | GRIB2 discipline number of requested field. See GRIB2 - TABLE 0.0 - DISCIPLINE. Use -1 to accept any discipline. |
[in] | jids | Array of values in the identification section. (Set to -9999 for wildcard.)
|
[in] | jpdtn | Product Definition Template (PDT) number (n) (if = -1, don't bother matching PDT - accept any). |
[in] | jpdt | Array of values defining the Product Definition Template of the field for which to search (=-9999 for wildcard). |
[in] | jgdtn | Grid Definition Template (GDT) number (if = -1, don't bother matching GDT - accept any). |
[in] | jgdt | array of values defining the Grid Definition Template of the field for which to search (=-9999 for wildcard). |
[out] | k | Field number unpacked. |
[out] | gfld | Derived type grib_mod::gribfield. |
[out] | lpos | Starting position of the found index record within the complete index buffer, CBUF. = 0, if request not found. |
[out] | iret | integer return code:
|
Definition at line 927 of file g2index.F90.
References g2_gbytec1(), g2logging::g2_log(), g2logging::g2_log_msg, gf_unpack1(), gf_unpack3(), gf_unpack4(), and gf_unpack5().
Referenced by getgb2i2(), getgb2p2(), and getgb2s().
subroutine getidx | ( | integer, intent(in) | lugb, |
integer, intent(in) | lugi, | ||
character(len = 1), dimension(:), pointer | cindex, | ||
integer, intent(out) | nlen, | ||
integer, intent(out) | nnum, | ||
integer, intent(out) | iret | ||
) |
Find, read or generate a version 1 GRIB2 index for a GRIB2 file (which must be < 2 GB).
If the index already exists in library memory, it is returned, otherwise, the index is read from an existing index file associated with unit lugi or generated from the GRIB2 file lugb.
Users can force a regeneration of an index: if lugi equals lugb, the index will be regenerated from the data in file lugb. If lugi is less than zero, then the index is re-read from index file abs(lugi).
This subroutine allocates memory and stores the resulting pointers in an array that is a Fortran "save" variable. The result is that the memory will not be freed by the library and cannot be reached by the caller. To free this memory call gf_finalize() after all library operations are complete.
[in] | lugb | integer unit of the GRIB2 data file. File must have been opened with baopen() or baopenr() before calling this routine. If 0, then all saved memory will be released (necessary for g2_finalize()). |
[in] | lugi | integer unit of the GRIB2 index file. If nonzero, file must have been opened with baopen() or baopenr() before calling this routine. Set to 0 to get index information from the GRIB2 file. |
[in,out] | cindex | character*1 Pointer to a buffer that will get index records. |
[out] | nlen | integer Total length of all index records. |
[out] | nnum | integer Number of index records. |
[out] | iret | integer Return code:
|
Definition at line 197 of file g2index.F90.
References getidx2().
Referenced by gf_finalize().
subroutine getidx2 | ( | integer, intent(in) | lugb, |
integer, intent(in) | lugi, | ||
integer, intent(inout) | idxver, | ||
character(len = 1), dimension(:), pointer | cindex, | ||
integer, intent(out) | nlen, | ||
integer, intent(out) | nnum, | ||
integer, intent(out) | iret | ||
) |
Find, read or generate a version 1 or 2 GRIB2 index for a GRIB2 file (which may be > 2 GB).
If the index already exists in library memory, it is returned, otherwise, the index is read from an existing index file associated with unit lugi or generated from the GRIB2 file lugb.
Users can force a regeneration of an index: if lugi equals lugb, the index will be regenerated from the data in file lugb. If lugi is less than zero, then the index is re-read from index file abs(lugi).
This subroutine allocates memory and stores the resulting pointers in an array that is a Fortran "save" variable. The result is that the memory will not be freed by the library and cannot be reached by the caller. To free this memory call gf_finalize() after all library operations are complete.
[in] | lugb | integer unit of the GRIB2 data file. File must have been opened with baopen() or baopenr() before calling this routine. If 0, then all saved memory will be released (necessary for g2_finalize()). |
[in] | lugi | integer unit of the GRIB2 index file. If nonzero, file must have been opened with baopen() or baopenr() before calling this routine. Set to 0 to get index information from the GRIB2 file. |
[in] | idxver | Index version, 1 for legacy, 2 if files may be > 2 GB. index records. |
[in,out] | cindex | character*1 Pointer to a buffer that will get index records. |
[out] | nlen | integer Total length of all index records. |
[out] | nnum | integer Number of index records. |
[out] | iret | integer Return code:
|
Definition at line 265 of file g2index.F90.
References g2logging::g2_log(), g2logging::g2_log_msg, getg2i2(), and getg2i2r().
Referenced by getgb2i2(), and getidx().
subroutine gf_finalize | ( | integer, intent(out) | iret | ) |
Free all memory associated with the library.
[out] | iret | integer Return code:
|
Definition at line 1664 of file g2index.F90.
References getidx().
subroutine ix2gb2 | ( | integer, intent(in) | lugb, |
integer (kind = 8), intent(in) | lskip8, | ||
integer, intent(in) | idxver, | ||
integer (kind = 8), intent(in) | lgrib8, | ||
character(len = 1), dimension(:), intent(inout), pointer | cbuf, | ||
integer, intent(out) | numfld, | ||
integer, intent(out) | mlen, | ||
integer, intent(out) | iret | ||
) |
Generate a version 1 or 2 index record for each field in a GRIB2 message.
The index records are written to index buffer pointed to by cbuf. All integers in the index are in big-endian format.
This subroutine is called by getg2ir(), which packages the index records into an index file.
See getg2i2() for thr format of the index buffer records.
[in] | lugb | Unit of the unblocked GRIB file. Must be opened by baopen() or baopenr(). |
[in] | lskip8 | Number of bytes to skip before GRIB message. |
[in] | idxver | Index version, use 1 for legacy, 2 for GRIB2 files > 2 GB. |
lgrib8 | Number of bytes in GRIB message. When subroutine is called, if this is < 5000, it will be used as the number of bytes initially read from the file. So for GRIB2 messages of < 5000 in size, this should be set to the size of the GRIB2 message. | |
[in,out] | cbuf | Pointer to a buffer that will get the index records. If any memory is associated with cbuf when this subroutine is called, cbuf will be nullified in the subroutine. Initially cbuf will get an allocation of 5000 bytes. realloc() will be used to increase the size if necessary. Users must free memory that cbuf points to when cbuf is no longer needed. |
[out] | numfld | Number of index records created. |
[out] | mlen | Total length of all index records. |
[out] | iret | Return code
|
Definition at line 1255 of file g2index.F90.
References g2_gbytec1(), g2logging::g2_log(), g2logging::g2_log_msg, g2_sbytec1(), and g2_sbytec81().
Referenced by getg2i2r(), and ixgb2().
subroutine ixgb2 | ( | integer | lugb, |
integer | lskip, | ||
integer | lgrib, | ||
character(len = 1), dimension(:), pointer | cbuf, | ||
integer | numfld, | ||
integer | mlen, | ||
integer | iret | ||
) |
Generate a version 1 index record for each field in a GRIB2 message.
The index records are written to index buffer pointed to by cbuf. All integers in the index are in big-endian format.
This subroutine is called by getg2ir(), which packages the index records into an index file.
See getg2i2() for thr format of the index buffer records.
lugb | Unit of the unblocked GRIB file. Must be opened by baopen() or baopenr(). |
lskip | Number of bytes to skip before GRIB message. |
lgrib | Number of bytes in GRIB message. When subroutine is called, this must be set to the size of the cbuf buffer. |
cbuf | Pointer to a buffer that will get the index records. If any memory is associated with cbuf when this subroutine is called, cbuf will be nullified in the subroutine. Initially cbuf will get an allocation of 5000 bytes. realloc() will be used to increase the size if necessary. Users must free memory that cbuf points to when cbuf is no longer needed. |
numfld | Number of index records created. |
mlen | Total length of all index records. |
iret | Return code
|
Definition at line 1191 of file g2index.F90.
References ix2gb2().