NCEPLIBS-g2c 1.9.0
Loading...
Searching...
No Matches
g2cutil.c
Go to the documentation of this file.
1
9#include "grib2_int.h"
10#include <stdarg.h>
11
14
17
28const char *
29g2c_strerror(int g2cerr)
30{
31 switch(g2cerr)
32 {
33 case G2C_NOERROR:
34 return "No error";
35 case G2C_ENOTGRIB:
36 return "GRIB2 header not found";
38 return "GRIB message is already complete.";
40 return "Name too long";
41 case G2C_EINVAL:
42 return "Invalid input";
43 case G2C_EFILE:
44 return "Error reading file";
45 case G2C_EBADID:
46 return "Bad ID";
48 return "Too many files open";
49 case G2C_ENOMEM:
50 return "Out of memory";
51 case G2C_EMSG:
52 return "Error decoding message";
53 case G2C_ENOMSG:
54 return "No GRIB message found";
55 case G2C_EXML:
56 return "Error parsing XML";
57 case G2C_ENOTFOUND:
58 return "Table or entry not found";
59 case G2C_ENOTGRIB2:
60 return "Not GRIB 2";
61 case G2C_ENOSECTION:
62 return "Cannot find section";
63 case G2C_ENOEND:
64 return "Cannot find end of GRIB message";
65 case G2C_EBADEND:
66 return "End of message in wrong place";
67 case G2C_EBADSECTION:
68 return "Invalid section number";
69 case G2C_EJPEG:
70 return "Error encoding/decoding JPEG data";
71 case G2C_EPNG:
72 return "Error encoding/decoding PNG data";
73 case G2C_ENOTEMPLATE:
74 return "Template not found";
76 return "Template problem";
77 case G2C_ENOPARAM:
78 return "Parameter not found";
79 case G2C_ENOPRODUCT:
80 return "Product not found";
81 case G2C_EBADTYPE:
82 return "Bad type";
83
84 default:
85 return "Unknown Error";
86 }
87}
88
100int
102{
103#ifdef LOGGING
104 char desc[G2C_MAX_GRIB_DESC_LEN + 1];
105 int ret;
106
107 /* Read in the XML GRIB2 code definitions. */
108 if ((ret = g2c_xml_init()))
109 return ret;
110
111 /* Section 0 discipline flag. */
112 if ((ret = g2c_find_desc("Code table 0.0", msg->discipline, desc)))
113 return ret;
114 LOG((4, "Discipline: %s", desc));
115
116 /* Section 1 flags. */
117 LOG((4, "Identification of originating/generating center: %d", msg->center));
118 LOG((4, "Identification of originating/generating subcenter: %d", msg->subcenter));
119 if ((ret = g2c_find_desc("Code table 1.0", msg->master_version, desc)))
120 return ret;
121 LOG((4, "GRIB master tables version number: %s", desc));
122 if ((ret = g2c_find_desc("Code table 1.1", msg->local_version, desc)))
123 return ret;
124 LOG((4, "Version number of GRIB local tables used to augment Master Tables: %s", desc));
125 if ((ret = g2c_find_desc("Code table 1.2", msg->sig_ref_time, desc)))
126 return ret;
127 LOG((4, "Significance of reference time: %s", desc));
128 LOG((4, "Reference time: %d/%d/%d %d:%d:%d", msg->year, msg->month, msg->day,
129 msg->hour, msg->minute, msg->second));
130 if ((ret = g2c_find_desc("Code table 1.3", msg->status, desc)))
131 return ret;
132 LOG((4, "Production Status of Processed data in the GRIB message: %s", desc));
133 if ((ret = g2c_find_desc("Code table 1.4", msg->type, desc)))
134 return ret;
135 LOG((4, "Type of processed data in this GRIB message: %s", desc));
136
137#endif
138 return G2C_NOERROR;
139}
140
151int
153{
154#ifdef LOGGING
155 int ret;
156
157 LOG((3, "sec_id %d sec_len %d byte_to_sec %ld sec_num %d", sec->sec_id, sec->sec_len,
158 sec->bytes_to_sec, sec->sec_num));
159 if (sec->sec_num == 4)
160 {
161 char abbrev[G2C_MAX_NOAA_ABBREV_LEN + 1];
162
163 /* Look up the parameter abbreviation with the discipline,
164 * category, and product number. */
165 if ((ret = g2c_param_abbrev(sec->msg->discipline, sec->template[0], sec->template[1], abbrev)))
166 return ret;
167 LOG((4, "%s", abbrev));
168 }
169
170#endif
171 return G2C_NOERROR;
172}
173
187int
188g2c_log_file(int g2cid)
189{
190#ifdef LOGGING
192 int ret;
193
194 /* Read in the XML GRIB2 code definitions. */
195 if ((ret = g2c_xml_init()))
196 return ret;
197
198 /* Find the open file struct. */
199 if (g2c_file[g2cid].g2cid != g2cid)
200 return G2C_EBADID;
201
202 LOG((1, "path %s", g2c_file[g2cid].path));
203 LOG((1, "num_messages %ld", g2c_file[g2cid].num_messages));
204 for (msg = g2c_file[g2cid].msg; msg; msg = msg->next)
205 {
207
208 LOG((1, "message %ld bytes_to_msg %ld bytes_in_msg %ld num_fields %d num_local %d",
209 msg->msg_num, msg->bytes_to_msg, msg->bytes_in_msg, msg->num_fields, msg->num_local));
210 LOG((1, "sec1_len %d center %d subcenter %d master_version %d local_version %d",
211 msg->sec1_len, msg->center, msg->subcenter, msg->master_version, msg->local_version));
212 LOG((1, "sig_ref_time %d %d %d %d %d:%d:%d status %d type %d", msg->sig_ref_time, msg->year,
213 msg->month, msg->day, msg->hour, msg->minute, msg->second, msg->status, msg->type));
214
215 /* If we've loaded XML tables, decode some flags. */
216 if (g2c_table)
217 if ((ret = g2c_log_section1(msg)))
218 return ret;
219
220 /* Section info. */
221 for (sec = msg->sec; sec; sec = sec->next)
222 if ((ret = g2c_log_section(sec)))
223 return ret;
224 }
225
226 /* Free XML code memory. */
228
229#endif /* LOGGING */
230 return G2C_NOERROR;
231}
int g2c_param_abbrev(int g2disc, int g2cat, int g2num, char *abbrev)
Get NOAA abbreviation for a GRIB2 parameter.
Definition g2cparams.c:1091
const char * g2c_strerror(int g2cerr)
Given an error code, return an error message.
Definition g2cutil.c:29
int g2c_log_section1(G2C_MESSAGE_INFO_T *msg)
Log section 0 information.
Definition g2cutil.c:101
int g2c_log_section(G2C_SECTION_INFO_T *sec)
Log info about a section.
Definition g2cutil.c:152
G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES+1]
Global file information.
Definition g2cfile.c:10
int g2c_log_file(int g2cid)
Print a summary of the contents of an open GRIB2 file.
Definition g2cutil.c:188
G2C_CODE_TABLE_T * g2c_table
Pointer to the list of code tables.
Definition g2cxml.c:15
int g2c_find_desc(char *title, int code, char *desc)
Given a table title and an integer code, find a description.
Definition g2cxml.c:132
int g2c_xml_init()
Init.
Definition g2cxml.c:190
void g2c_free_tables()
Free table memory.
Definition g2cxml.c:42
#define G2C_EMSG
Error decoding GRIB message.
Definition grib2.h:501
#define G2C_MAX_FILES
Maximum number of open files.
Definition grib2.h:288
#define G2C_MAX_GRIB_DESC_LEN
Maximum length of code description.
Definition grib2.h:424
#define G2C_ENOEND
Cannot find end of GRIB message.
Definition grib2.h:507
#define G2C_ENOMSG
No GRIB message found.
Definition grib2.h:502
#define G2C_EBADEND
End of message in wrong place.
Definition grib2.h:508
#define G2C_ENAMETOOLONG
Name too long.
Definition grib2.h:495
#define G2C_ENOTGRIB2
Not GRIB 2.
Definition grib2.h:505
#define G2C_ENOSECTION
Cannot find section.
Definition grib2.h:506
#define G2C_EFILE
File I/O error.
Definition grib2.h:497
#define G2C_ENOPARAM
Parameter not found.
Definition grib2.h:514
#define G2C_ENOTEMPLATE
Template not found.
Definition grib2.h:512
#define G2C_ENOMEM
Out of memory.
Definition grib2.h:500
#define G2C_EPNG
Error encoding/decoding PNG data.
Definition grib2.h:511
#define G2C_ENOTFOUND
Table or entry not found.
Definition grib2.h:504
#define G2C_ENOPRODUCT
Product not found.
Definition grib2.h:515
#define G2C_EINVAL
Invalid input.
Definition grib2.h:496
#define G2C_ENOTGRIB
GRIB header not found.
Definition grib2.h:493
#define G2C_ETOOMANYFILES
Trying to open too many files.
Definition grib2.h:499
#define G2C_EBADSECTION
Invalid section number.
Definition grib2.h:509
#define G2C_EMSGCOMPLETE
GRIB message already complete.
Definition grib2.h:494
#define G2C_EBADTEMPLATE
Template problem.
Definition grib2.h:513
#define G2C_EXML
XML error.
Definition grib2.h:503
#define G2C_EJPEG
Error encoding/decoding JPEG data.
Definition grib2.h:510
#define G2C_EBADID
Bad ID.
Definition grib2.h:498
#define G2C_MAX_NOAA_ABBREV_LEN
Maximum length of a NOAA abbreviation of a parameter.
Definition grib2.h:432
#define G2C_NOERROR
No error.
Definition grib2.h:491
#define G2C_EBADTYPE
Type not found.
Definition grib2.h:516
Header file with internal function prototypes NCEPLIBS-g2c library.
struct g2c_section_info * next
Pointer to next in list.
Definition grib2_int.h:176
struct g2c_section_info * sec
List of section metadata.
Definition grib2_int.h:162
short subcenter
Originating subcenter.
Definition grib2_int.h:150
int sec_id
ID of the section (0-based).
Definition grib2_int.h:170
unsigned char master_version
GRIB master tables version number.
Definition grib2_int.h:151
unsigned char type
Type of processed data in this GRIB message.
Definition grib2_int.h:161
unsigned char hour
Hour.
Definition grib2_int.h:157
unsigned char minute
Minute.
Definition grib2_int.h:158
int num_local
Number of local sections in the message.
Definition grib2_int.h:141
unsigned char sig_ref_time
Significance of reference time.
Definition grib2_int.h:153
unsigned char discipline
Discipline from section 0.
Definition grib2_int.h:138
size_t bytes_in_msg
Number of bytes in this message.
Definition grib2_int.h:137
int num_fields
Number of fields in the message.
Definition grib2_int.h:140
unsigned char sec_num
Section number.
Definition grib2_int.h:173
unsigned int sec_len
Length of the section (in bytes).
Definition grib2_int.h:171
short year
Year.
Definition grib2_int.h:154
size_t bytes_to_sec
Number of bytes from start of message to this section.
Definition grib2_int.h:172
unsigned char status
Production Status of Processed data in the GRIB message.
Definition grib2_int.h:160
#define LOG(e)
Ignore logging to stdout.
Definition grib2_int.h:426
unsigned char second
Second.
Definition grib2_int.h:159
unsigned char day
Day.
Definition grib2_int.h:156
unsigned char local_version
Version number of GRIB local tables used to augment Master Tables.
Definition grib2_int.h:152
unsigned char month
Month.
Definition grib2_int.h:155
size_t msg_num
Number of message in file (0-based).
Definition grib2_int.h:135
size_t bytes_to_msg
Number of bytes to skip in the file, to get to this message.
Definition grib2_int.h:136
long long int * template
Grid, product, or data template.
Definition grib2_int.h:178
int sec1_len
Length of section 1.
Definition grib2_int.h:148
struct g2c_message_info * next
Pointer to next in list.
Definition grib2_int.h:164
G2C_MESSAGE_INFO_T * msg
Pointer to contianing message.
Definition grib2_int.h:174
short center
Originating center.
Definition grib2_int.h:149
A GRIB2 code table.
Definition grib2_int.h:255
This is the information about each open file.
Definition grib2_int.h:236
This is the information about each message.
Definition grib2_int.h:134
Information about a section 3 through 7 in a GRIB2 message.
Definition grib2_int.h:169