Loading...
Searching...
No Matches
g2ccompare.c
Go to the documentation of this file.
#include "grib2_int.h"
#include <math.h>
#include <stdarg.h>
extern G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES + 1];
int
g2c_compare(int g2cid1, int g2cid2)
{
G2C_MESSAGE_INFO_T *msg1, *msg2;
int m;
/* int total_fields = 0; */
/* int i; */
/* int ret; */
/* Check inputs. */
if (g2cid1 < 0 || g2cid1 > G2C_MAX_FILES || g2c_file[g2cid1].g2cid != g2cid1)
return G2C_EBADID;
if (g2cid2 < 0 || g2cid2 > G2C_MAX_FILES || g2c_file[g2cid2].g2cid != g2cid2)
return G2C_EBADID;
LOG((2, "g2c_metadata_cmp g2cid1 %d g2cid2 %d", g2cid1, g2cid2));
/* Same number of messages? */
if (g2c_file[g2cid1].num_messages != g2c_file[g2cid2].num_messages)
return G2C_ERROR;
/* Check metadata of each message. */
msg1 = g2c_file[g2cid1].msg;
msg2 = g2c_file[g2cid2].msg;
for (m = 0; m < g2c_file[g2cid1].num_messages; m++)
{
int fld;
if (msg1->discipline != msg2->discipline)
return G2C_ERROR;
if (msg1->center != msg2->center || msg1->subcenter != msg2->subcenter ||
msg1->master_version != msg2->master_version || msg1->local_version != msg2->local_version ||
msg1->sig_ref_time != msg2->sig_ref_time || msg1->year != msg2->year ||
msg1->month != msg2->month || msg1->day != msg2->day || msg1->hour != msg2->hour ||
msg1->minute != msg2->minute || msg1->second != msg2->second || msg1->status != msg2->status ||
msg1->type != msg2->type)
return G2C_ERROR;
if (msg1->num_local != msg2->num_local || msg1->num_fields != msg2->num_fields)
return G2C_ERROR;
/* For each field, print info. */
for (fld = 0; fld < msg1->num_fields; fld++)
{
G2C_SECTION_INFO_T *sec_1, *sec_2;
G2C_SECTION_INFO_T *sec3_1, *sec3_2;
G2C_SECTION_INFO_T *sec5_1, *sec5_2;
G2C_SECTION3_INFO_T *sec3_info_1, *sec3_info_2;
G2C_SECTION4_INFO_T *sec4_info_1, *sec4_info_2;
G2C_SECTION5_INFO_T *sec5_info_1, *sec5_info_2;
int t;
/* Find this field (a.k.a. product, a.k.a. section 4). */
for (sec_1 = msg1->sec; sec_1; sec_1 = sec_1->next)
{
sec4_info_1 = (G2C_SECTION4_INFO_T *)sec_1->sec_info;
if (sec_1->sec_num == 4 && sec4_info_1->field_num == fld)
break;
}
if (!sec_1)
return G2C_ENOSECTION;
for (sec_2 = msg2->sec; sec_2; sec_2 = sec_2->next)
{
sec4_info_2 = (G2C_SECTION4_INFO_T *)sec_2->sec_info;
if (sec_2->sec_num == 4 && sec4_info_2->field_num == fld)
break;
}
if (!sec_2)
return G2C_ENOSECTION;
if (sec4_info_1->num_coord != sec4_info_2->num_coord ||
sec4_info_1->prod_def != sec4_info_2->prod_def)
return G2C_ERROR;
if (sec_1->template_len != sec_2->template_len)
return G2C_ERROR;
for (t = 0; t < sec_1->template_len; t++)
if (sec_1->template[t] != sec_2->template[t])
return G2C_ERROR;
/* Find the sec3 that applies to this field. */
for (sec3_1 = sec_1; sec3_1; sec3_1 = sec3_1->prev)
if (sec3_1->sec_num == 3)
break;
if (!sec3_1)
return G2C_ENOSECTION;
sec3_info_1 = (G2C_SECTION3_INFO_T *)sec3_1->sec_info;
for (sec3_2 = sec_2; sec3_2; sec3_2 = sec3_2->prev)
if (sec3_2->sec_num == 3)
break;
if (!sec3_2)
return G2C_ENOSECTION;
sec3_info_2 = (G2C_SECTION3_INFO_T *)sec3_2->sec_info;
if (sec3_info_1->source_grid_def != sec3_info_2->source_grid_def ||
sec3_info_1->num_data_points != sec3_info_2->num_data_points ||
sec3_info_1->num_opt != sec3_info_2->num_opt ||
sec3_info_1->interp_list != sec3_info_2->interp_list ||
sec3_info_1->grid_def != sec3_info_2->grid_def)
return G2C_ERROR;
if (sec3_1->template_len != sec3_2->template_len)
return G2C_ERROR;
for (t = 0; t < sec3_1->template_len; t++)
if (sec3_1->template[t] != sec3_2->template[t])
return G2C_ERROR;
/* Find the sec5 that applies to this field. */
for (sec5_1 = sec_1; sec5_1; sec5_1 = sec5_1->next)
if (sec5_1->sec_num == 5)
break;
if (!sec5_1)
return G2C_ENOSECTION;
sec5_info_1 = (G2C_SECTION5_INFO_T *)sec5_1->sec_info;
for (sec5_2 = sec_2; sec5_2; sec5_2 = sec5_2->next)
if (sec5_2->sec_num == 5)
break;
if (!sec5_2)
return G2C_ENOSECTION;
sec5_info_2 = (G2C_SECTION5_INFO_T *)sec5_2->sec_info;
if (sec5_info_1->num_data_points != sec5_info_2->num_data_points ||
sec5_info_1->data_def != sec5_info_2->data_def)
return G2C_ERROR;
if (sec5_1->template_len != sec5_2->template_len)
return G2C_ERROR;
for (t = 0; t < sec5_1->template_len; t++)
if (sec5_1->template[t] != sec5_2->template[t])
return G2C_ERROR;
}
msg1 = msg1->next;
msg2 = msg2->next;
}
/* fprintf(f, " \n Total Number of Fields Found = %d\n", total_fields); */
return G2C_NOERROR;
}
g2c_file
G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES+1]
Global file information.
Definition g2cfile.c:30
g2c_compare
int g2c_compare(int g2cid1, int g2cid2)
Compare the metadata of two open GRIB2 files.
Definition g2ccompare.c:28
G2C_MAX_FILES
#define G2C_MAX_FILES
Maximum number of open files.
Definition grib2.h:273
G2C_ENOSECTION
#define G2C_ENOSECTION
Cannot find section.
Definition grib2.h:505
G2C_ERROR
#define G2C_ERROR
General error code, returned for some test errors.
Definition grib2.h:491
G2C_EBADID
#define G2C_EBADID
Bad ID.
Definition grib2.h:497
G2C_NOERROR
#define G2C_NOERROR
No error.
Definition grib2.h:490
grib2_int.h
Header file with internal function prototypes NCEPLIBS-g2c library.
G2C_SECTION3_INFO_T
struct g2c_section3_info G2C_SECTION3_INFO_T
Information about Section 3 GRID DEFINITION SECTION.
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_message_info::master_version
unsigned char master_version
GRIB master tables version number.
Definition grib2_int.h:153
G2C_FILE_INFO_T
struct g2c_file_info G2C_FILE_INFO_T
This is the information about each open file.
g2c_message_info::type
unsigned char type
Type of processed data in this GRIB message.
Definition grib2_int.h:163
g2c_section3_info::grid_def
unsigned short grid_def
Grid definition template number (= N) (See Table 3.1).
Definition grib2_int.h:201
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_section3_info::num_data_points
unsigned int num_data_points
Number of data points.
Definition grib2_int.h:198
g2c_section4_info::num_coord
unsigned short num_coord
Number of coordinate values after template.
Definition grib2_int.h:211
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_SECTION_INFO_T
struct g2c_section_info G2C_SECTION_INFO_T
Information about a section 3 through 7 in a GRIB2 message.
g2c_section3_info::num_opt
unsigned char num_opt
Number of octets for optional list of numbers defining number of points.
Definition grib2_int.h:199
g2c_message_info::discipline
unsigned char discipline
Discipline from section 0.
Definition grib2_int.h:140
g2c_section3_info::interp_list
unsigned char interp_list
Interpetation of list of numbers defining number of points (See Table 3.11).
Definition grib2_int.h:200
G2C_SECTION5_INFO_T
struct g2c_section5_info G2C_SECTION5_INFO_T
Information about Section 5 DATA REPRESENTATION SECTION.
g2c_section_info::prev
struct g2c_section_info * prev
Pointer to previous in list.
Definition grib2_int.h:179
g2c_message_info::num_fields
int num_fields
Number of fields in the message.
Definition grib2_int.h:142
G2C_SECTION4_INFO_T
struct g2c_section4_info G2C_SECTION4_INFO_T
Information about Section 4 PRODUCT DEFINITION SECTION.
g2c_section_info::sec_num
unsigned char sec_num
Section number.
Definition grib2_int.h:175
g2c_section5_info::num_data_points
unsigned int num_data_points
Number of data points where one or more values are specified in Section 7 when a bit map is present,...
Definition grib2_int.h:223
g2c_section_info::sec_info
void * sec_info
Pointer to struct specific for section 3, 4, 5, 6, or 7.
Definition grib2_int.h:177
G2C_MESSAGE_INFO_T
struct g2c_message_info G2C_MESSAGE_INFO_T
This is the information about each message.
g2c_message_info::year
short year
Year.
Definition grib2_int.h:156
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_section3_info::source_grid_def
unsigned char source_grid_def
Source of grid definition (See Table 3.0).
Definition grib2_int.h:197
g2c_section_info::template_len
int template_len
Number of entries in template.
Definition grib2_int.h:181
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_section5_info::data_def
unsigned short data_def
Data representation template number (See Table 5.0).
Definition grib2_int.h:224
g2c_section_info::template
long long int * template
Grid, product, or data template.
Definition grib2_int.h:180
g2c_message_info::next
struct g2c_message_info * next
Pointer to next in list.
Definition grib2_int.h:166
g2c_message_info::center
short center
Originating center.
Definition grib2_int.h:151
g2c_section4_info::prod_def
unsigned short prod_def
Product definition template number (See Table 4.0).
Definition grib2_int.h:212