Loading...
Searching...
No Matches
g2cutil.c
Go to the documentation of this file.
#include "grib2_int.h"
#include <stdarg.h>
extern G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES + 1];
extern G2C_CODE_TABLE_T *g2c_table;
const char *
g2c_strerror(int g2cerr)
{
switch (g2cerr)
{
case G2C_NOERROR:
return "No error";
case G2C_ENOTGRIB:
return "GRIB2 header not found";
case G2C_EMSGCOMPLETE:
return "GRIB message is already complete.";
case G2C_ENAMETOOLONG:
return "Name too long";
case G2C_EINVAL:
return "Invalid input";
case G2C_EFILE:
return "Error reading file";
case G2C_EBADID:
return "Bad ID";
case G2C_ETOOMANYFILES:
return "Too many files open";
case G2C_ENOMEM:
return "Out of memory";
case G2C_EMSG:
return "Error decoding message";
case G2C_ENOMSG:
return "No GRIB message found";
case G2C_EXML:
return "Error parsing XML";
case G2C_ENOTFOUND:
return "Table or entry not found";
case G2C_ENOTGRIB2:
return "Not GRIB 2";
case G2C_ENOSECTION:
return "Cannot find section";
case G2C_ENOEND:
return "Cannot find end of GRIB message";
case G2C_EBADEND:
return "End of message in wrong place";
case G2C_EBADSECTION:
return "Invalid section number";
case G2C_EJPEG:
return "Error encoding/decoding JPEG data";
case G2C_EPNG:
return "Error encoding/decoding PNG data";
case G2C_ENOTEMPLATE:
return "Template not found";
case G2C_EBADTEMPLATE:
return "Template problem";
case G2C_ENOPARAM:
return "Parameter not found";
case G2C_ENOPRODUCT:
return "Product not found";
case G2C_EBADTYPE:
return "Bad type";
default:
return "Unknown Error";
}
}
int
g2c_log_section1(G2C_MESSAGE_INFO_T *msg)
{
#ifdef LOGGING
char desc[G2C_MAX_GRIB_DESC_LEN + 1];
int ret;
/* Read in the CSV GRIB2 code definitions. */
if ((ret = g2c_csv_init()))
return ret;
/* Section 0 discipline flag. */
if ((ret = g2c_find_desc("Code table 0.0", msg->discipline, desc)))
return ret;
LOG((4, "Discipline: %s", desc));
/* Section 1 flags. */
LOG((4, "Identification of originating/generating center: %d", msg->center));
LOG((4, "Identification of originating/generating subcenter: %d", msg->subcenter));
if ((ret = g2c_find_desc("Code table 1.0", msg->master_version, desc)))
return ret;
LOG((4, "GRIB master tables version number: %s", desc));
if ((ret = g2c_find_desc("Code table 1.1", msg->local_version, desc)))
return ret;
LOG((4, "Version number of GRIB local tables used to augment Master Tables: %s", desc));
if ((ret = g2c_find_desc("Code table 1.2", msg->sig_ref_time, desc)))
return ret;
LOG((4, "Significance of reference time: %s", desc));
LOG((4, "Reference time: %d/%d/%d %d:%d:%d", msg->year, msg->month, msg->day,
msg->hour, msg->minute, msg->second));
if ((ret = g2c_find_desc("Code table 1.3", msg->status, desc)))
return ret;
LOG((4, "Production Status of Processed data in the GRIB message: %s", desc));
if ((ret = g2c_find_desc("Code table 1.4", msg->type, desc)))
return ret;
LOG((4, "Type of processed data in this GRIB message: %s", desc));
#endif
return G2C_NOERROR;
}
int
g2c_log_section(G2C_SECTION_INFO_T *sec)
{
#ifdef LOGGING
int ret;
LOG((3, "sec_id %d sec_len %d byte_to_sec %ld sec_num %d", sec->sec_id,
sec->sec_len, sec->bytes_to_sec, sec->sec_num));
if (sec->sec_num == 4)
{
char abbrev[G2C_MAX_NOAA_ABBREV_LEN + 1];
/* Look up the parameter abbreviation with the discipline,
* category, and product number. */
if ((ret = g2c_param_abbrev(sec->msg->discipline, sec->template[0],
sec->template[1], abbrev)))
return ret;
LOG((4, "%s", abbrev));
}
#endif
return G2C_NOERROR;
}
int
g2c_log_file(int g2cid)
{
#ifdef LOGGING
G2C_MESSAGE_INFO_T *msg;
int ret;
/* Read in the CSV GRIB2 code definitions. */
if ((ret = g2c_csv_init()))
return ret;
/* Find the open file struct. */
if (g2c_file[g2cid].g2cid != g2cid)
return G2C_EBADID;
LOG((1, "path %s", g2c_file[g2cid].path));
LOG((1, "num_messages %ld", g2c_file[g2cid].num_messages));
for (msg = g2c_file[g2cid].msg; msg; msg = msg->next)
{
G2C_SECTION_INFO_T *sec;
LOG((1, "message %ld bytes_to_msg %ld bytes_in_msg %ld num_fields %d num_local %d",
msg->msg_num, msg->bytes_to_msg, msg->bytes_in_msg, msg->num_fields, msg->num_local));
LOG((1, "sec1_len %d center %d subcenter %d master_version %d local_version %d",
msg->sec1_len, msg->center, msg->subcenter, msg->master_version, msg->local_version));
LOG((1, "sig_ref_time %d %d %d %d %d:%d:%d status %d type %d", msg->sig_ref_time, msg->year,
msg->month, msg->day, msg->hour, msg->minute, msg->second, msg->status, msg->type));
/* If we've loaded CSV tables, decode some flags. */
if (g2c_table)
if ((ret = g2c_log_section1(msg)))
return ret;
/* Section info. */
for (sec = msg->sec; sec; sec = sec->next)
if ((ret = g2c_log_section(sec)))
return ret;
}
/* Free CSV code memory. */
g2c_free_tables();
#endif /* LOGGING */
return G2C_NOERROR;
}
g2c_find_desc
int g2c_find_desc(char *title, int code, char *desc)
Given a table title and an integer code, find a description.
Definition g2ccsv.c:131
g2c_csv_init
int g2c_csv_init()
Initialize tables from "CodeFlag.txt".
Definition g2ccsv.c:215
g2c_free_tables
void g2c_free_tables()
Free table memory.
Definition g2ccsv.c:42
g2c_param_abbrev
int g2c_param_abbrev(int g2disc, int g2cat, int g2num, char *abbrev)
Get NOAA abbreviation for a GRIB2 parameter.
Definition g2cparams.c:1091
g2c_strerror
const char * g2c_strerror(int g2cerr)
Given an error code, return an error message.
Definition g2cutil.c:29
g2c_log_section1
int g2c_log_section1(G2C_MESSAGE_INFO_T *msg)
Log section 0 information.
Definition g2cutil.c:101
g2c_log_section
int g2c_log_section(G2C_SECTION_INFO_T *sec)
Log info about a section.
Definition g2cutil.c:152
g2c_file
G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES+1]
Global file information.
Definition g2cfile.c:10
g2c_log_file
int g2c_log_file(int g2cid)
Print a summary of the contents of an open GRIB2 file.
Definition g2cutil.c:189
g2c_table
G2C_CODE_TABLE_T * g2c_table
Pointer to the list of code tables.
Definition g2ccsv.c:16
G2C_EMSG
#define G2C_EMSG
Error decoding GRIB message.
Definition grib2.h:494
G2C_MAX_FILES
#define G2C_MAX_FILES
Maximum number of open files.
Definition grib2.h:273
G2C_MAX_GRIB_DESC_LEN
#define G2C_MAX_GRIB_DESC_LEN
Maximum length of code description.
Definition grib2.h:415
G2C_ENOEND
#define G2C_ENOEND
Cannot find end of GRIB message.
Definition grib2.h:500
G2C_ENOMSG
#define G2C_ENOMSG
No GRIB message found.
Definition grib2.h:495
G2C_EBADEND
#define G2C_EBADEND
End of message in wrong place.
Definition grib2.h:501
G2C_ENAMETOOLONG
#define G2C_ENAMETOOLONG
Name too long.
Definition grib2.h:488
G2C_ENOTGRIB2
#define G2C_ENOTGRIB2
Not GRIB 2.
Definition grib2.h:498
G2C_ENOSECTION
#define G2C_ENOSECTION
Cannot find section.
Definition grib2.h:499
G2C_EFILE
#define G2C_EFILE
File I/O error.
Definition grib2.h:490
G2C_ENOPARAM
#define G2C_ENOPARAM
Parameter not found.
Definition grib2.h:507
G2C_ENOTEMPLATE
#define G2C_ENOTEMPLATE
Template not found.
Definition grib2.h:505
G2C_ENOMEM
#define G2C_ENOMEM
Out of memory.
Definition grib2.h:493
G2C_EPNG
#define G2C_EPNG
Error encoding/decoding PNG data.
Definition grib2.h:504
G2C_ENOTFOUND
#define G2C_ENOTFOUND
Table or entry not found.
Definition grib2.h:497
G2C_ENOPRODUCT
#define G2C_ENOPRODUCT
Product not found.
Definition grib2.h:508
G2C_EINVAL
#define G2C_EINVAL
Invalid input.
Definition grib2.h:489
G2C_ENOTGRIB
#define G2C_ENOTGRIB
GRIB header not found.
Definition grib2.h:486
G2C_ETOOMANYFILES
#define G2C_ETOOMANYFILES
Trying to open too many files.
Definition grib2.h:492
G2C_EBADSECTION
#define G2C_EBADSECTION
Invalid section number.
Definition grib2.h:502
G2C_EMSGCOMPLETE
#define G2C_EMSGCOMPLETE
GRIB message already complete.
Definition grib2.h:487
G2C_EBADTEMPLATE
#define G2C_EBADTEMPLATE
Template problem.
Definition grib2.h:506
G2C_EXML
#define G2C_EXML
XML error.
Definition grib2.h:496
G2C_EJPEG
#define G2C_EJPEG
Error encoding/decoding JPEG data.
Definition grib2.h:503
G2C_EBADID
#define G2C_EBADID
Bad ID.
Definition grib2.h:491
G2C_MAX_NOAA_ABBREV_LEN
#define G2C_MAX_NOAA_ABBREV_LEN
Maximum length of a NOAA abbreviation of a parameter.
Definition grib2.h:423
G2C_NOERROR
#define G2C_NOERROR
No error.
Definition grib2.h:484
G2C_EBADTYPE
#define G2C_EBADTYPE
Type not found.
Definition grib2.h:509
grib2_int.h
Header file with internal function prototypes NCEPLIBS-g2c library.
g2c_section_info::next
struct g2c_section_info * next
Pointer to next in list.
Definition grib2_int.h:178
g2c_message_info::sec
struct g2c_section_info * sec
List of section metadata.
Definition grib2_int.h:164
g2c_message_info::subcenter
short subcenter
Originating subcenter.
Definition grib2_int.h:152
g2c_section_info::sec_id
int sec_id
ID of the section (0-based).
Definition grib2_int.h:172
g2c_message_info::master_version
unsigned char master_version
GRIB master tables version number.
Definition grib2_int.h:153
g2c_message_info::type
unsigned char type
Type of processed data in this GRIB message.
Definition grib2_int.h:163
g2c_message_info::hour
unsigned char hour
Hour.
Definition grib2_int.h:159
g2c_message_info::minute
unsigned char minute
Minute.
Definition grib2_int.h:160
g2c_message_info::num_local
int num_local
Number of local sections in the message.
Definition grib2_int.h:143
g2c_message_info::sig_ref_time
unsigned char sig_ref_time
Significance of reference time.
Definition grib2_int.h:155
g2c_message_info::discipline
unsigned char discipline
Discipline from section 0.
Definition grib2_int.h:140
g2c_message_info::bytes_in_msg
size_t bytes_in_msg
Number of bytes in this message.
Definition grib2_int.h:139
g2c_message_info::num_fields
int num_fields
Number of fields in the message.
Definition grib2_int.h:142
g2c_section_info::sec_num
unsigned char sec_num
Section number.
Definition grib2_int.h:175
g2c_section_info::sec_len
unsigned int sec_len
Length of the section (in bytes).
Definition grib2_int.h:173
g2c_message_info::year
short year
Year.
Definition grib2_int.h:156
g2c_section_info::bytes_to_sec
size_t bytes_to_sec
Number of bytes from start of message to this section.
Definition grib2_int.h:174
g2c_message_info::status
unsigned char status
Production Status of Processed data in the GRIB message.
Definition grib2_int.h:162
LOG
#define LOG(e)
Ignore logging to stdout.
Definition grib2_int.h:428
g2c_message_info::second
unsigned char second
Second.
Definition grib2_int.h:161
g2c_message_info::day
unsigned char day
Day.
Definition grib2_int.h:158
g2c_message_info::local_version
unsigned char local_version
Version number of GRIB local tables used to augment Master Tables.
Definition grib2_int.h:154
g2c_message_info::month
unsigned char month
Month.
Definition grib2_int.h:157
g2c_message_info::msg_num
size_t msg_num
Number of message in file (0-based).
Definition grib2_int.h:137
g2c_message_info::bytes_to_msg
size_t bytes_to_msg
Number of bytes to skip in the file, to get to this message.
Definition grib2_int.h:138
g2c_section_info::template
long long int * template
Grid, product, or data template.
Definition grib2_int.h:180
g2c_message_info::sec1_len
int sec1_len
Length of section 1.
Definition grib2_int.h:150
g2c_message_info::next
struct g2c_message_info * next
Pointer to next in list.
Definition grib2_int.h:166
g2c_section_info::msg
G2C_MESSAGE_INFO_T * msg
Pointer to contianing message.
Definition grib2_int.h:176
g2c_message_info::center
short center
Originating center.
Definition grib2_int.h:151
g2c_code_table
A GRIB2 code table.
Definition grib2_int.h:257
g2c_file_info
This is the information about each open file.
Definition grib2_int.h:238
g2c_message_info
This is the information about each message.
Definition grib2_int.h:136
g2c_section_info
Information about a section 3 through 7 in a GRIB2 message.
Definition grib2_int.h:171