NCEPLIBS-g2tmpl  1.12.0
process_4dot2.c File Reference

4dot2 More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

Go to the source code of this file.

Macros

#define MXFNLEN   120
 Max fn length. More...
 
#define MXFNLEN   120
 Max fn length. More...
 
#define MXG2MNEM   16
 Define the maximum length of a mnemonic in GRIB2 Code Table 4.2. More...
 
#define MXG2MNEMP4   ( MXG2MNEM + 4)
 Define the maximum length of a mnemonic in GRIB2 Code Table 4.2. More...
 
#define NUMALLOC   2500
 Allocate internal memory for table entries in chunks of 25000. More...
 

Typedefs

typedef int f77int
 On certain operating systems, the FORTRAN compiler appends an underscore to subprogram names in its object namespace. More...
 

Functions

void close_4dot2 (f77int *iret)
 This subroutine should be called one time at the end of the application program in order to free all allocated memory. More...
 
int compar (const struct TableEntry *pte1, const struct TableEntry *pte2)
 Define the internal comparison function for use with qsort and bsearch. More...
 
void open_and_read_4dot2 (char *filename, f77int *iret)
 Opens and reads the GRIB2 Code Table 4.2 into an internal memory structure. More...
 
void search_for_4dot2_entry (char nemo[MXG2MNEM], f77int *locflg, f77int *disc, f77int *catg, f77int *parm, f77int *iret)
 Searches for a specified mnemonic within the previously-opened GRIB2 Code Table 4.2 and returns the corresponding product discipline, parameter category and parameter number. More...
 
void sort_and_write_4dot2 (char *filename, f77int *iret)
 Sorts the contents of GRIB2 Code Table 4.2 within the internal memory structure and writes the output to the file specified by filename. More...
 

Variables

size_t nentry = 0
 Number of entries. More...
 
struct TableEntry * pe0 = NULL
 Table entry. More...
 

Detailed Description

4dot2

Author
Jeff Ator
Date
Feb 2010

Definition in file process_4dot2.c.

Macro Definition Documentation

◆ MXFNLEN [1/2]

#define MXFNLEN   120

Max fn length.

Definition at line 23 of file process_4dot2.c.

◆ MXFNLEN [2/2]

#define MXFNLEN   120

Max fn length.

Definition at line 23 of file process_4dot2.c.

◆ MXG2MNEM

#define MXG2MNEM   16

Define the maximum length of a mnemonic in GRIB2 Code Table 4.2.

Definition at line 13 of file process_4dot2.c.

◆ MXG2MNEMP4

#define MXG2MNEMP4   ( MXG2MNEM + 4)

Define the maximum length of a mnemonic in GRIB2 Code Table 4.2.

Definition at line 17 of file process_4dot2.c.

◆ NUMALLOC

#define NUMALLOC   2500

Allocate internal memory for table entries in chunks of 25000.

Definition at line 20 of file process_4dot2.c.

Typedef Documentation

◆ f77int

typedef int f77int

On certain operating systems, the FORTRAN compiler appends an underscore to subprogram names in its object namespace.

Therefore, on such systems, a matching underscore must be appended to any C language references to the same subprogram names so that the linker can correctly resolve such references across the C <-> FORTRAN interface at link time. In order to ensure that the C <-> FORTRAN interface works properly (and portably!), the default size of an "INTEGER" declared in FORTRAN must be identical to that of an "int" declared in C. If this is not the case (e.g. some FORTRAN compilers, most notably AIX via the -qintsize= option, allow the sizes of INTEGERs to be definitively prescribed outside of the source code itself!), then the following conditional directive (or a variant of it) can be used to ensure that the size of an "int" in C remains identical to that of an "INTEGER" in FORTRAN.

Definition at line 50 of file process_4dot2.c.

Function Documentation

◆ close_4dot2()

void close_4dot2 ( f77int iret)

This subroutine should be called one time at the end of the application program in order to free all allocated memory.

Parameters
iretReturn code: 0 = normal return.

Definition at line 342 of file process_4dot2.c.

References pe0.

◆ compar()

int compar ( const struct TableEntry *  pte1,
const struct TableEntry *  pte2 
)

Define the internal comparison function for use with qsort and bsearch.

Parameters
pte1TableEntry1
pte2TableEntry2
Returns
0 if they are the same.

Definition at line 84 of file process_4dot2.c.

Referenced by search_for_4dot2_entry(), and sort_and_write_4dot2().

◆ open_and_read_4dot2()

void open_and_read_4dot2 ( char *  filename,
f77int iret 
)

Opens and reads the GRIB2 Code Table 4.2 into an internal memory structure.

In order for the search_for_4dot2_entry() function to be used, the table must be in sorted order with respect to the mnemonic and according to the criteria of the compar() function. If this has not already been done, it can be done by calling the sort_and_write_4dot2() function prior to calling the search_for_4dot2_entry() function.

Parameters
filenameLocation of table file on filesystem; directory prefixes or other local filesystem notation is allowed up to 120 total characters.
iretReturn code:
  • 0 normal return
  • -1 input filename was more than 120 characters
  • -2 table file could not be opened
  • -3 memory allocation error

Definition at line 113 of file process_4dot2.c.

References MXFNLEN, nentry, NUMALLOC, and pe0.

Referenced by sort_params_grib2_tbl().

◆ search_for_4dot2_entry()

void search_for_4dot2_entry ( char  nemo[MXG2MNEM],
f77int locflg,
f77int disc,
f77int catg,
f77int parm,
f77int iret 
)

Searches for a specified mnemonic within the previously-opened GRIB2 Code Table 4.2 and returns the corresponding product discipline, parameter category and parameter number.

A binary search algorithm is used.

In order for this function to be used, the table must already be in sorted order with respect to the mnemonic and according to the criteria of the compar() function. If this has not already been done, it can be done by calling the sort_and_write_4dot2() function prior to calling this function.

Parameters
nemoMnemonic (of up to 16 characters in length) to search for within table.
locflgVersion of mnemonic to be returned, in case of duplication within table:
  • 0 international version (default)
  • 1 local version
discProduct discipline
catgParameter category
parmParameter number
iretReturn code:
  • 0 normal return
  • -1 nemo not found within table for specified locflg version

Definition at line 284 of file process_4dot2.c.

References compar(), MXG2MNEM, nentry, and pe0.

◆ sort_and_write_4dot2()

void sort_and_write_4dot2 ( char *  filename,
f77int iret 
)

Sorts the contents of GRIB2 Code Table 4.2 within the internal memory structure and writes the output to the file specified by filename.

The output file will be in a format suitable for subsequent reading via the open_and_read_4dot2() function, so that this function does not need to be called again prior to calling search_for_4dot2_entry().

Parameters
filenameFilename to which to write the sorted output. Directory prefixes or other local filesystem notation is allowed up to 120 total characters.
iretReturn code:
  • 0 normal return
  • -1 filename was more than 120 characters
  • -2 filename could not be opened

Definition at line 199 of file process_4dot2.c.

References compar(), MXFNLEN, MXG2MNEMP4, nentry, and pe0.

Referenced by sort_params_grib2_tbl().

Variable Documentation

◆ nentry

size_t nentry = 0

Number of entries.

Definition at line 65 of file process_4dot2.c.

Referenced by open_and_read_4dot2(), search_for_4dot2_entry(), and sort_and_write_4dot2().

◆ pe0

struct TableEntry* pe0 = NULL

Table entry.

Definition at line 62 of file process_4dot2.c.

Referenced by close_4dot2(), open_and_read_4dot2(), search_for_4dot2_entry(), and sort_and_write_4dot2().