17 #define MXG2MNEMP4 ( MXG2MNEM + 4)
32 #define open_and_read_4dot2 open_and_read_4dot2_
33 #define sort_and_write_4dot2 sort_and_write_4dot2_
34 #define search_for_4dot2_entry search_for_4dot2_entry_
35 #define close_4dot2 close_4dot2_
62 struct TableEntry *
pe0 = NULL;
71 int compar(
const struct TableEntry *,
const struct TableEntry *);
84 compar(
const struct TableEntry *pte1,
const struct TableEntry *pte2)
86 return strcmp(pte1->mnemonic, pte2->mnemonic);
116 struct TableEntry *pra;
118 char lfn[
MXFNLEN+1], str[81], cflag, cub =
'_';
130 for (i = 0; (! isspace(filename[i]) && ! iscntrl(filename[i])); i++) {
135 lfn[i] = filename[i];
142 if ((pfn = fopen(lfn,
"r")) == NULL) {
144 printf(
"Can't open input file %s\n",lfn);
152 while (fgets(str, 80, pfn) != NULL) {
158 pra = realloc(
pe0, (
NUMALLOC *
sizeof(
struct TableEntry)));
165 sscanf(str,
"%d%d%d%*3c%c%*c%s",
170 strncat(
pe0[
nentry].mnemonic, &cflag, 1);
215 for (i = 0; (! isspace(filename[i]) && ! iscntrl(filename[i])); i++) {
220 lfn[i] = filename[i];
227 if ((pfn = fopen(lfn,
"w")) == NULL) {
229 printf(
"Can't open output file %s\n",lfn);
236 qsort(
pe0,
nentry,
sizeof(
struct TableEntry),
237 (
int (*) (
const void *,
const void *))
compar);
242 for (i = 0; i <
nentry; i++) {
243 strcpy(str,
pe0[i].mnemonic);
244 cflag = str[strlen(str)-1];
245 str[strlen(str)-2] =
'\0';
246 fprintf(pfn,
"%4d%4d%6d %c %s\n",
247 pe0[i].discipline,
pe0[i].category,
248 pe0[i].parameter, cflag, str);
288 unsigned short n = 0, n2 = 0;
292 struct TableEntry key, *pbs;
301 ((isalnum((
int) nemo[n]) ||
302 (nemo[n] ==
'_') || (nemo[n] ==
'-'))) ) {
303 key.mnemonic[n2++] = nemo[n++];
310 key.mnemonic[n2++] =
'_';
311 llf = (long) *locflg;
312 if (llf != 1) llf = 0;
314 sprintf(&key.mnemonic[n2],
"%ld", llf);
320 pbs = bsearch(&key,
pe0,
nentry,
sizeof(
struct TableEntry),
321 (
int (*) (
const void *,
const void *))
compar);
struct TableEntry * pe0
Table 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....
int f77int
On certain operating systems, the FORTRAN compiler appends an underscore to subprogram names in its o...
#define NUMALLOC
Allocate internal memory for table entries in chunks of 25000.
size_t nentry
Number of entries.
#define MXG2MNEM
Define the maximum length of a mnemonic in GRIB2 Code Table 4.2.
int compar(const struct TableEntry *, const struct TableEntry *)
Define the internal comparison function for use with qsort and bsearch.
#define MXFNLEN
Max fn length.
void open_and_read_4dot2(char *, f77int *)
Opens and reads the GRIB2 Code Table 4.2 into an internal memory structure.
void sort_and_write_4dot2(char *, f77int *)
Sorts the contents of GRIB2 Code Table 4.2 within the internal memory structure and writes the output...
#define MXG2MNEMP4
Define the maximum length of a mnemonic in GRIB2 Code Table 4.2.
void close_4dot2(f77int *)
This subroutine should be called one time at the end of the application program in order to free all ...