Skip to content

Commit

Permalink
more progress
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett committed Feb 3, 2024
1 parent 00608a8 commit 9c8023d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/g2cindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ g2c_start_index_record(FILE *f, int rw_flag, int *reclen, int *msg, int *local,
|| !msglen || !version || !discipline || !fieldnum)
return G2C_EINVAL;

LOG((4, "g2c_start_index_record rw_flag %d", rw_flag));

/* When writing, set the fieldnum1 to be a 1-based index, just
* like in Fortran. */
if (rw_flag)
Expand Down Expand Up @@ -152,6 +154,8 @@ g2c_start_index_record_lf(FILE *f, int rw_flag, int *reclen, size_t *msg, int *l
short fieldnum1; /* This is for the 1-based fieldnum in the index file. */
int ret;

LOG((4, "g2c_start_index_record_lf rw_flag %d", rw_flag));

/* All pointers must be provided. */
if (!f || !reclen || !msg || !local || !gds || !pds || !drs || !bms || !data
|| !msglen || !version || !discipline || !fieldnum)
Expand Down
2 changes: 1 addition & 1 deletion tests/run_large_index_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ echo ""
echo "*** Running g2c_index large file test"

# Create an index for a GRIB2 file.
../utils/g2c_index -v data/fv3lam.t00z.prslev.f000.grib2 fv3lam.t00z.prslev.f000.grib2.idx
../utils/g2c_index -o fv3lam.t00z.prslev.f000.grib2.idx -l -v data/fv3lam.t00z.prslev.f000.grib2

# Summarize the index data.
../utils/g2c_degrib2 -v -o fv3lam.t00z.prslev.f000.grib2.idx.degrib2 data/fv3lam.t00z.prslev.f000.grib2 fv3lam.t00z.prslev.f000.grib2.idx
Expand Down
2 changes: 1 addition & 1 deletion utils/g2c_degrib2.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ main(int argc, char **argv)
/* Turn on logging for verbose output. This only has effect if the
* library was built with LOGGING=ON. */
if (verbose)
g2c_set_log_level(3);
g2c_set_log_level(4);

/* If we got one input file, open it. If we got two input files,
* the second is an index file for the first. */
Expand Down
37 changes: 21 additions & 16 deletions utils/g2c_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
int
main(int argc, char **argv)
{
char *path[2] = {NULL, NULL};
char *filein = NULL;
char *fileout = NULL;
int verbose = 0;
int large_file_index = 0;
int index;
Expand All @@ -38,7 +39,7 @@ main(int argc, char **argv)
opterr = 0;

/* Parse command line arguments. */
while ((c = getopt(argc, argv, "v")) != -1)
while ((c = getopt(argc, argv, "vlo:")) != -1)
{
switch (c)
{
Expand All @@ -48,6 +49,11 @@ main(int argc, char **argv)
case 'l':
large_file_index = 1;
break;
case 'o':
if (!(fileout = malloc(sizeof(char) * strlen(optarg) + 1)))
return G2C_ENOMEM;
strcpy(fileout, optarg);
break;
case '?':
if (isprint(optopt))
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand All @@ -59,41 +65,40 @@ main(int argc, char **argv)
}
}

/* Get names of input and output files. */
/* Get names of input file. */
for (index = optind; index < argc; index++)
{
if (!(path[p] = malloc(sizeof(char) * strlen(argv[index]) + 1)))
return G2C_ENOMEM;
strcpy(path[p], argv[index]);
if (++p == 2)
if (!(filein = malloc(sizeof(char) * strlen(argv[index]) + 1)))
return G2C_ENOMEM;
strcpy(filein, argv[index]);
if (++p == 1)
break;
}

/* Yammer on and on. */
if (verbose)
printf("g2c_index %s reading index file %s summarizing into %s.\n", G2C_VERSION, path[0], path[1]);
printf("g2c_index %s reading index file %s summarizing into %s.\n",
G2C_VERSION, filein, fileout);

/* Open the GRIB2 file. */
if ((ret = g2c_open(path[0], G2C_NOWRITE, &g2cid)))
if ((ret = g2c_open(filein, G2C_NOWRITE, &g2cid)))
return ret;

/* Write the index file. */
if (large_file_index)
write_index_flag &= G2C_LARGE_FILE_INDEX;
if ((ret = g2c_write_index(g2cid, write_index_flag, path[1])))
if ((ret = g2c_write_index(g2cid, write_index_flag, fileout)))
return ret;

/* Close the file. */
if ((ret = g2c_close(g2cid)))
return ret;

/* Free memory. */
if (path[0])
free(path[0]);
if (path[1])
free(path[1]);

printf("returning 0\n");
if (filein)
free(filein);
if (fileout)
free(fileout);

return 0;
}

0 comments on commit 9c8023d

Please sign in to comment.