NCEPLIBS-g2 4.0.0
Loading...
Searching...
No Matches
g2cf Module Reference

Module for the NCEPLIBS-g2 file-based GRIB2 API. More...

Functions/Subroutines

character(len=(len(string)+1)) function addcnullchar (string, nlen)
 Add a C_NULL_CHAR to a string to create a C compatible string.
 
integer function g2cf_close (g2id)
 Close a GRIB2 file.
 
integer function g2cf_inq (g2id, num_msg)
 Learn how many messages are in a GRIB2 file.
 
integer function g2cf_inq_dim (g2id, msg_num, prod_num, dim_num, dimlen, name, val)
 Learn about a dimension.
 
integer function g2cf_inq_msg (g2id, msg_num, discipline, num_fields, num_local, center, subcenter, master_version, local_version)
 Learn about a message are in a GRIB2 file.
 
integer function g2cf_inq_msg_time (g2id, msg_num, sig_ref_time, year, month, day, hour, minute, second)
 Learn about message date/time.
 
integer function g2cf_inq_prod (g2id, msg_num, prod_num, pds_template_len, pds_template, gds_template_len, gds_template, drs_template_len, drs_template)
 Learn about a product.
 
integer function g2cf_open (path, mode, g2id)
 Open a GRIB2 file.
 
integer function g2cf_open_index (data_file, index_file, mode, g2cid)
 Open a GRIB2 file using an exsiting index file (generated by the grb2index utility).
 
integer function g2cf_set_log_level (log_level)
 Turn internal logging on.
 
character(len=nlen) function stripcnullchar (cstring, nlen)
 Check cstring for a c null char, strip it off and return regular string.
 

Variables

integer, parameter g2_max_drs_template_len = 55
 Maximum number of entries in a DRS template.
 
integer, parameter g2_max_gds_template_len = 50
 Maximum number of entries in a GDS template.
 
integer, parameter g2_max_name = 1024
 Maximum name length.
 
integer, parameter g2_max_pds_template_len = 50
 Maximum number of entries in a PDS template.
 
integer, parameter g2_noerr = 0
 Return value from functions when there is no error.
 

Detailed Description

Module for the NCEPLIBS-g2 file-based GRIB2 API.

Author
Edward Hartnett
Date
2020-16-12

Function/Subroutine Documentation

◆ addcnullchar()

character(len = (len(string) + 1)) function g2cf::addcnullchar ( character(len=*), intent(in)  string,
integer, intent(inout)  nlen 
)

Add a C_NULL_CHAR to a string to create a C compatible string.

Assumes target variable will be of length LEN(string)+1. Trailing blanks will be stripped from string and length of trimmed string will be returned in nlen.

Parameters
stringThe string to trimmed and null-terminated
nlenThe length of the returned string, including null-terminator.
Returns
the trimmed, null-terminated string

This function was originally written by, Richard Weed, Ph.D., as part of netcdf-fortran.

Author
Edward Hartnett
Date
2024-06-12

Definition at line 42 of file g2cf.F90.

Referenced by g2cf_open(), and g2cf_open_index().

◆ g2cf_close()

integer function g2cf::g2cf_close ( integer, intent(in)  g2id)

Close a GRIB2 file.

Parameters
g2idThe ID of the open file
Returns
0 for success, error code otherwise.
Author
Edward Hartnett
Date
2024-06-12

Definition at line 466 of file g2cf.F90.

◆ g2cf_inq()

integer function g2cf::g2cf_inq ( integer, intent(in)  g2id,
integer, intent(out)  num_msg 
)

Learn how many messages are in a GRIB2 file.

Parameters
g2idThe ID of the open file
num_msgThe number of messages in the file.
Returns
0 for success, error code otherwise.
Author
Edward Hartnett
Date
2024-12-21

Definition at line 190 of file g2cf.F90.

◆ g2cf_inq_dim()

integer function g2cf::g2cf_inq_dim ( integer, intent(in)  g2id,
integer, intent(in)  msg_num,
integer, intent(in)  prod_num,
integer, intent(in)  dim_num,
integer(kind = 8), intent(out)  dimlen,
character, dimension(*), intent(out)  name,
real, dimension(*), intent(out), optional  val 
)

Learn about a dimension.

Parameters
[in]g2idThe ID of the open file
[in]msg_numThe message number in the file (first message is 1).
[in]prod_numThe product number in the message (first product is 1).
[in]dim_numThe dimension number in the product (first dimension is 1).
[out]dimlenLength of dimension.
[out]nameName of dimension.
[out]valArray of values along the dimension.
Returns
0 for success, error code otherwise.
Author
Edward Hartnett
Date
2024-12-22

Definition at line 392 of file g2cf.F90.

References g2_noerr, and stripcnullchar().

◆ g2cf_inq_msg()

integer function g2cf::g2cf_inq_msg ( integer, intent(in)  g2id,
integer, intent(in)  msg_num,
integer(kind = 1), intent(out)  discipline,
integer, intent(out)  num_fields,
integer, intent(out)  num_local,
integer(kind = 2), intent(out)  center,
integer(kind = 2), intent(out)  subcenter,
integer(kind = 1), intent(out)  master_version,
integer(kind = 1), intent(out)  local_version 
)

Learn about a message are in a GRIB2 file.

Parameters
[in]g2idThe ID of the open file
[in]msg_numThe number of message to learn about. The first message in the file is number 1.
[out]disciplineThe discipline of the message.
[out]num_fieldsNumber of fields in the message.
[out]num_localNumber of local sections in the message.
[out]centerOriginating center.
[out]subcenterOriginating sub-center.
[out]master_versionMaster version.
[out]local_versionLocal version.
Returns
0 for success, error code otherwise.
Author
Edward Hartnett
Date
2024-12-21

Definition at line 223 of file g2cf.F90.

◆ g2cf_inq_msg_time()

integer function g2cf::g2cf_inq_msg_time ( integer, intent(in)  g2id,
integer, intent(in)  msg_num,
integer(kind = 1), intent(out)  sig_ref_time,
integer(kind = 2), intent(out)  year,
integer(kind = 1), intent(out)  month,
integer(kind = 1), intent(out)  day,
integer(kind = 1), intent(out)  hour,
integer(kind = 1), intent(out)  minute,
integer(kind = 1), intent(out)  second 
)

Learn about message date/time.

Parameters
g2idThe ID of the open file
msg_numThe message number in the file (first message is 1).
sig_ref_timeThe significant reference time.
yearYear
monthMongh
dayDay
hourHour
minuteMinute
secondSecond
Returns
0 for success, error code otherwise.
Author
Edward Hartnett
Date
2024-12-22

Definition at line 272 of file g2cf.F90.

◆ g2cf_inq_prod()

integer function g2cf::g2cf_inq_prod ( integer, intent(in)  g2id,
integer, intent(in)  msg_num,
integer, intent(in)  prod_num,
integer, intent(out)  pds_template_len,
integer(kind = 8), dimension(*), intent(out)  pds_template,
integer, intent(out)  gds_template_len,
integer(kind = 8), dimension(*), intent(out)  gds_template,
integer, intent(out)  drs_template_len,
integer(kind = 8), dimension(*), intent(out)  drs_template 
)

Learn about a product.

Parameters
[in]g2idThe ID of the open file
[in]msg_numThe message number in the file (first message is 1).
[in]prod_numThe product number in the message (first product is 1).
[out]pds_template_lenLength of the PDS template.
[out]pds_templateThe PDS template values.
[out]gds_template_lenLength of the GDS template.
[out]gds_templateThe GDS template values.
[out]drs_template_lenLength of the DRS template.
[out]drs_templateThe DRS template values.
Returns
0 for success, error code otherwise.
Author
Edward Hartnett
Date
2024-12-22

Definition at line 322 of file g2cf.F90.

◆ g2cf_open()

integer function g2cf::g2cf_open ( character(len = *), intent(in)  path,
integer, intent(in)  mode,
integer, intent(inout)  g2id 
)

Open a GRIB2 file.

Parameters
pathThe path to the file
modeFlag with open mode information
g2idThe ID of the open file
Returns
0 for success, error code otherwise.
Author
Edward Hartnett
Date
2024-06-12

Definition at line 109 of file g2cf.F90.

References addcnullchar().

◆ g2cf_open_index()

integer function g2cf::g2cf_open_index ( character(len=*), intent(in)  data_file,
character(len=*), intent(in)  index_file,
integer, intent(in)  mode,
integer, intent(inout)  g2cid 
)

Open a GRIB2 file using an exsiting index file (generated by the grb2index utility).

Parameters
data_filePath to data file.
index_filePath to index file.
modeOpen mode, may be NC_CLOBBER (0) or NC_NOCLOBBER.
g2cidFile ID.
Returns
  • 0 No error
Author
Ed Hartnett
Date
2022-11-21

Definition at line 152 of file g2cf.F90.

References addcnullchar().

◆ g2cf_set_log_level()

integer function g2cf::g2cf_set_log_level ( integer, intent(in)  log_level)

Turn internal logging on.

Parameters
log_level0 for no logging, 5 for maximum logging.
Returns
0 for success, error code otherwise.
Author
Edward Hartnett
Date
2024-12-16

Definition at line 488 of file g2cf.F90.

◆ stripcnullchar()

character(len=nlen) function g2cf::stripcnullchar ( character(len=*), intent(in)  cstring,
integer, intent(in)  nlen 
)

Check cstring for a c null char, strip it off and return regular string.

Limit length of cstring loaded into string to nlen.

Parameters
[in]cstringString which may have null char.
[in]nlenLength of string.
Returns
String with NULL removed.

This function was originally written by, Richard Weed, Ph.D., as part of netcdf-fortran.

Author
Edward Hartnett
Date
2024-12-23

Definition at line 81 of file g2cf.F90.

Referenced by g2cf_inq_dim().

Variable Documentation

◆ g2_max_drs_template_len

integer, parameter g2cf::g2_max_drs_template_len = 55

Maximum number of entries in a DRS template.

Definition at line 24 of file g2cf.F90.

◆ g2_max_gds_template_len

integer, parameter g2cf::g2_max_gds_template_len = 50

Maximum number of entries in a GDS template.

Definition at line 21 of file g2cf.F90.

◆ g2_max_name

integer, parameter g2cf::g2_max_name = 1024

Maximum name length.

Definition at line 15 of file g2cf.F90.

◆ g2_max_pds_template_len

integer, parameter g2cf::g2_max_pds_template_len = 50

Maximum number of entries in a PDS template.

Definition at line 18 of file g2cf.F90.

◆ g2_noerr

integer, parameter g2cf::g2_noerr = 0

Return value from functions when there is no error.

Definition at line 12 of file g2cf.F90.

Referenced by g2cf_inq_dim().