intg2c_file_io(FILE*f,intwrite,intg2ctype,void*var)
Read or write a big-endian integer type to an open file, with conversion between native and big-endian
format. GRIB2 handles negative numbers in a special way. Instead of storing two-compliments, like every
other programmer and computing organization in the world, GRIB2 flips the first bit, then stores the rest
of the int as an unsigned number in the remaining 31 bits. How exciting!
This function takes the excitement out of GRIB2 negative numbers.
Parametersf Pointer to the open FILE.
write Non-zero if function should write, otherwise function will read.
g2ctype The type to be read or written.
var Pointer to the int to be written, or pointer to the storage that gets the int read.
Returns
• :: G2C_NOERROR No error.
• :: G2C_EINVAL Invalid input.
• :: G2C_EFILE Error reading/writing file.
Author
Ed Hartnett
Date
11/7/22
Definition at line 41 of file g2cio.c.
References BITSHIFT_15, BITSHIFT_31, BITSHIFT_63, BITSHIFT_7, EIGHT_BYTES, FOUR_BYTES, G2C_BYTE,
G2C_EBADTYPE, G2C_EFILE, G2C_EINVAL, G2C_INT, G2C_INT64, G2C_NOERROR, G2C_SHORT, G2C_UBYTE, G2C_UINT,
G2C_UINT64, G2C_USHORT, hton64, ntoh64, ONE_BYTE, and TWO_BYTES.
Referenced by g2c_file_io_byte(), g2c_file_io_int(), g2c_file_io_longlong(), g2c_file_io_short(),
g2c_file_io_ubyte(), g2c_file_io_uint(), g2c_file_io_ulonglong(), and g2c_file_io_ushort().
intg2c_file_io_byte(FILE*f,intwrite,char*var)
Read or write a big-endian signed byte to an open GRIB2 file, with conversion between native and big-
endian format, and special GRIB2 handling of negative numbers.
Parametersf Pointer to the open GRIB2 FILE.
write Non-zero to write, zero to read.
var Pointer to the byte.
Returns
• :: G2C_NOERROR No error.
• :: G2C_EINVAL Invalid input.
• :: G2C_EFILE Error reading/writing file.
Author
Ed Hartnett 11/13/22
Definition at line 316 of file g2cio.c.
References G2C_BYTE, and g2c_file_io().
Referenced by g2c_file_io_template().
intg2c_file_io_int(FILE*f,intwrite,int*var)
Read or write a big-endian 4-byte signed int to an open GRIB2 file, with conversion between native and
big-endian format, and special GRIB2 handling of negative numbers.
Parametersf Pointer to the open GRIB2 FILE.
write Non-zero to write, zero to read.
var Pointer to the int.
Returns
• :: G2C_NOERROR No error.
• :: G2C_EINVAL Invalid input.
• :: G2C_EFILE Error reading/writing file.
Author
Ed Hartnett 11/7/22
Definition at line 230 of file g2cio.c.
References g2c_file_io(), and G2C_INT.
Referenced by g2c_file_io_template().
intg2c_file_io_longlong(FILE*f,intwrite,longlong*var)
Read or write a big-endian signed long long to an open GRIB2 file, with conversion between native and
big-endian format, and special GRIB2 handling of negative numbers.
Parametersf Pointer to the open GRIB2 FILE.
write Non-zero to write, zero to read.
var Pointer to the long long.
Returns
• :: G2C_NOERROR No error.
• :: G2C_EINVAL Invalid input.
• :: G2C_EFILE Error reading/writing file.
Author
Ed Hartnett 11/13/22
Definition at line 359 of file g2cio.c.
References g2c_file_io(), and G2C_INT64.
intg2c_file_io_short(FILE*f,intwrite,short*var)
Read or write a big-endian signed short to an open GRIB2 file, with conversion between native and big-
endian format, and special GRIB2 handling of negative numbers.
Parametersf Pointer to the open GRIB2 FILE.
write Non-zero to write, zero to read.
var Pointer to the short.
Returns
• :: G2C_NOERROR No error.
• :: G2C_EINVAL Invalid input.
• :: G2C_EFILE Error reading/writing file.
Author
Ed Hartnett 11/13/22
Definition at line 273 of file g2cio.c.
References g2c_file_io(), and G2C_SHORT.
Referenced by g2c_file_io_template(), g2c_rw_section1_metadata(), g2c_start_index_record(), and
g2c_start_index_record_lf().
intg2c_file_io_template(FILE*f,intrw_flag,intmap,longlongint*template_value)
Read or write a big-endian 4-byte int or unsigned int from or to an open file, with conversion between
native and big-endian format, and handling of GRIB negative numbers. This is for template values.
With template values, if the map value is negative, then the template value may be negative.
Parametersf Pointer to the open FILE.
rw_flag Non-zero if function should write, otherwise function will read.
map The map value for this template item.
template_value Pointer to the template value to be written, or pointer to the storage that gets the
templage value read.
Returns
• :: G2C_NOERROR No error.
• :: G2C_EINVAL Invalid input.
• :: G2C_EFILE Error reading/writing file.
Author
Ed Hartnett 11/7/22
Definition at line 408 of file g2cio.c.
References FOUR_BYTES, G2C_EBADTEMPLATE, g2c_file_io_byte(), g2c_file_io_int(), g2c_file_io_short(),
g2c_file_io_ubyte(), g2c_file_io_uint(), g2c_file_io_ushort(), G2C_NOERROR, ONE_BYTE, and TWO_BYTES.
Referenced by g2c_rw_section3_metadata(), g2c_rw_section4_metadata(), and g2c_rw_section5_metadata().
intg2c_file_io_ubyte(FILE*f,intwrite,unsignedchar*var)
Read or write a big-endian unsigned byte to an open GRIB2 file, with conversion between native and big-
endian format.
Parametersf Pointer to the open GRIB2 FILE.
write Non-zero to write, zero to read.
var Pointer to the unsigned byte.
Returns
• :: G2C_NOERROR No error.
• :: G2C_EINVAL Invalid input.
• :: G2C_EFILE Error reading/writing file.
Author
Ed Hartnett 11/13/22
Definition at line 337 of file g2cio.c.
References g2c_file_io(), and G2C_UBYTE.
Referenced by g2c_file_io_template(), g2c_open_index(), g2c_rw_section1_metadata(),
g2c_rw_section3_metadata(), g2c_rw_section6_metadata(), g2c_start_index1_record(),
g2c_start_index_record(), g2c_start_index_record_lf(), g2c_write_index(), and read_msg_metadata().
intg2c_file_io_uint(FILE*f,intwrite,unsignedint*var)
Read or write a big-endian 4-byte unsigned int to an open GRIB2 file, with conversion between native and
big-endian format.
Parametersf Pointer to the open GRIB2 FILE.
write Non-zero to write, zero to read.
var Pointer to the unsigned int.
Returns
• :: G2C_NOERROR No error.
• :: G2C_EINVAL Invalid input.
• :: G2C_EFILE Error reading/writing file.
Author
Ed Hartnett 11/7/22
Definition at line 251 of file g2cio.c.
References g2c_file_io(), and G2C_UINT.
Referenced by g2c_file_io_template(), g2c_open_index(), g2c_rw_section1_metadata(),
g2c_rw_section3_metadata(), g2c_rw_section5_metadata(), g2c_start_index1_record(),
g2c_start_index_record(), g2c_start_index_record_lf(), g2c_write_index(), and read_msg_metadata().
intg2c_file_io_ulonglong(FILE*f,intwrite,unsignedlonglong*var)
Read or write a big-endian unsigned long long to an open GRIB2 file, with conversion between native and
big-endian format.
Parametersf Pointer to the open GRIB2 FILE.
write Non-zero to write, zero to read.
var Pointer to the unsigned long long.
Returns
• :: G2C_NOERROR No error.
• :: G2C_EINVAL Invalid input.
• :: G2C_EFILE Error reading/writing file.
Author
Ed Hartnett 11/13/22
Definition at line 380 of file g2cio.c.
References g2c_file_io(), and G2C_UINT64.
Referenced by g2c_start_index_record(), and g2c_start_index_record_lf().
intg2c_file_io_ushort(FILE*f,intwrite,unsignedshort*var)
Read or write a big-endian unsigned short to an open GRIB2 file, with conversion between native and big-
endian format.
Parametersf Pointer to the open GRIB2 FILE.
write Non-zero to write, zero to read.
var Pointer to the unsigned short.
Returns
• :: G2C_NOERROR No error.
• :: G2C_EINVAL Invalid input.
• :: G2C_EFILE Error reading/writing file.
Author
Ed Hartnett 11/13/22
Definition at line 294 of file g2cio.c.
References g2c_file_io(), and G2C_USHORT.
Referenced by g2c_file_io_template(), g2c_rw_section3_metadata(), g2c_rw_section4_metadata(), and
g2c_rw_section5_metadata().