NCEPLIBS-g2c 2.0.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 CSV GRIB2 code definitions. */
108 if ((ret = g2c_csv_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,
158 sec->sec_len, 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],
166 sec->template[1], abbrev)))
167 return ret;
168 LOG((4, "%s", abbrev));
169 }
170
171#endif
172 return G2C_NOERROR;
173}
174
188int
189g2c_log_file(int g2cid)
190{
191#ifdef LOGGING
193 int ret;
194
195 /* Read in the CSV GRIB2 code definitions. */
196 if ((ret = g2c_csv_init()))
197 return ret;
198
199 /* Find the open file struct. */
200 if (g2c_file[g2cid].g2cid != g2cid)
201 return G2C_EBADID;
202
203 LOG((1, "path %s", g2c_file[g2cid].path));
204 LOG((1, "num_messages %ld", g2c_file[g2cid].num_messages));
205 for (msg = g2c_file[g2cid].msg; msg; msg = msg->next)
206 {
208
209 LOG((1, "message %ld bytes_to_msg %ld bytes_in_msg %ld num_fields %d num_local %d",
210 msg->msg_num, msg->bytes_to_msg, msg->bytes_in_msg, msg->num_fields, msg->num_local));
211 LOG((1, "sec1_len %d center %d subcenter %d master_version %d local_version %d",
212 msg->sec1_len, msg->center, msg->subcenter, msg->master_version, msg->local_version));
213 LOG((1, "sig_ref_time %d %d %d %d %d:%d:%d status %d type %d", msg->sig_ref_time, msg->year,
214 msg->month, msg->day, msg->hour, msg->minute, msg->second, msg->status, msg->type));
215
216 /* If we've loaded CSV tables, decode some flags. */
217 if (g2c_table)
218 if ((ret = g2c_log_section1(msg)))
219 return ret;
220
221 /* Section info. */
222 for (sec = msg->sec; sec; sec = sec->next)
223 if ((ret = g2c_log_section(sec)))
224 return ret;
225 }
226
227 /* Free CSV code memory. */
229
230#endif /* LOGGING */
231 return G2C_NOERROR;
232}
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
int g2c_csv_init()
Initialize tables from "CodeFlag.txt".
Definition g2ccsv.c:189
void g2c_free_tables()
Free table memory.
Definition g2ccsv.c:42
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:189
G2C_CODE_TABLE_T * g2c_table
Pointer to the list of code tables.
Definition g2ccsv.c:16
#define G2C_EMSG
Error decoding GRIB message.
Definition grib2.h:486
#define G2C_MAX_FILES
Maximum number of open files.
Definition grib2.h:273
#define G2C_MAX_GRIB_DESC_LEN
Maximum length of code description.
Definition grib2.h:409
#define G2C_ENOEND
Cannot find end of GRIB message.
Definition grib2.h:492
#define G2C_ENOMSG
No GRIB message found.
Definition grib2.h:487
#define G2C_EBADEND
End of message in wrong place.
Definition grib2.h:493
#define G2C_ENAMETOOLONG
Name too long.
Definition grib2.h:480
#define G2C_ENOTGRIB2
Not GRIB 2.
Definition grib2.h:490
#define G2C_ENOSECTION
Cannot find section.
Definition grib2.h:491
#define G2C_EFILE
File I/O error.
Definition grib2.h:482
#define G2C_ENOPARAM
Parameter not found.
Definition grib2.h:499
#define G2C_ENOTEMPLATE
Template not found.
Definition grib2.h:497
#define G2C_ENOMEM
Out of memory.
Definition grib2.h:485
#define G2C_EPNG
Error encoding/decoding PNG data.
Definition grib2.h:496
#define G2C_ENOTFOUND
Table or entry not found.
Definition grib2.h:489
#define G2C_ENOPRODUCT
Product not found.
Definition grib2.h:500
#define G2C_EINVAL
Invalid input.
Definition grib2.h:481
#define G2C_ENOTGRIB
GRIB header not found.
Definition grib2.h:478
#define G2C_ETOOMANYFILES
Trying to open too many files.
Definition grib2.h:484
#define G2C_EBADSECTION
Invalid section number.
Definition grib2.h:494
#define G2C_EMSGCOMPLETE
GRIB message already complete.
Definition grib2.h:479
#define G2C_EBADTEMPLATE
Template problem.
Definition grib2.h:498
#define G2C_EXML
XML error.
Definition grib2.h:488
#define G2C_EJPEG
Error encoding/decoding JPEG data.
Definition grib2.h:495
#define G2C_EBADID
Bad ID.
Definition grib2.h:483
#define G2C_MAX_NOAA_ABBREV_LEN
Maximum length of a NOAA abbreviation of a parameter.
Definition grib2.h:417
#define G2C_NOERROR
No error.
Definition grib2.h:476
#define G2C_EBADTYPE
Type not found.
Definition grib2.h:501
Header file with internal function prototypes NCEPLIBS-g2c library.
struct g2c_section_info * next
Pointer to next in list.
Definition grib2_int.h:178
struct g2c_section_info * sec
List of section metadata.
Definition grib2_int.h:164
short subcenter
Originating subcenter.
Definition grib2_int.h:152
int sec_id
ID of the section (0-based).
Definition grib2_int.h:172
unsigned char master_version
GRIB master tables version number.
Definition grib2_int.h:153
unsigned char type
Type of processed data in this GRIB message.
Definition grib2_int.h:163
unsigned char hour
Hour.
Definition grib2_int.h:159
unsigned char minute
Minute.
Definition grib2_int.h:160
int num_local
Number of local sections in the message.
Definition grib2_int.h:143
unsigned char sig_ref_time
Significance of reference time.
Definition grib2_int.h:155
unsigned char discipline
Discipline from section 0.
Definition grib2_int.h:140
size_t bytes_in_msg
Number of bytes in this message.
Definition grib2_int.h:139
int num_fields
Number of fields in the message.
Definition grib2_int.h:142
unsigned char sec_num
Section number.
Definition grib2_int.h:175
unsigned int sec_len
Length of the section (in bytes).
Definition grib2_int.h:173
short year
Year.
Definition grib2_int.h:156
size_t bytes_to_sec
Number of bytes from start of message to this section.
Definition grib2_int.h:174
unsigned char status
Production Status of Processed data in the GRIB message.
Definition grib2_int.h:162
#define LOG(e)
Ignore logging to stdout.
Definition grib2_int.h:428
unsigned char second
Second.
Definition grib2_int.h:161
unsigned char day
Day.
Definition grib2_int.h:158
unsigned char local_version
Version number of GRIB local tables used to augment Master Tables.
Definition grib2_int.h:154
unsigned char month
Month.
Definition grib2_int.h:157
size_t msg_num
Number of message in file (0-based).
Definition grib2_int.h:137
size_t bytes_to_msg
Number of bytes to skip in the file, to get to this message.
Definition grib2_int.h:138
long long int * template
Grid, product, or data template.
Definition grib2_int.h:180
int sec1_len
Length of section 1.
Definition grib2_int.h:150
struct g2c_message_info * next
Pointer to next in list.
Definition grib2_int.h:166
G2C_MESSAGE_INFO_T * msg
Pointer to contianing message.
Definition grib2_int.h:176
short center
Originating center.
Definition grib2_int.h:151
A GRIB2 code table.
Definition grib2_int.h:257
This is the information about each open file.
Definition grib2_int.h:238
This is the information about each message.
Definition grib2_int.h:136
Information about a section 3 through 7 in a GRIB2 message.
Definition grib2_int.h:171