Testing: Cleanup

This commit is contained in:
shahramn 2024-03-04 18:52:22 +00:00
parent 6f10faac1c
commit 0514d24a72
4 changed files with 14 additions and 64 deletions

View File

@ -25,12 +25,6 @@ static double compare_double_absolute(double a, double b, double tolerance)
return ret; return ret;
} }
static void usage(const char* prog)
{
fprintf(stderr, "usage: %s input\n", prog);
exit(1);
}
static int check_error_code(int err) static int check_error_code(int err)
{ {
if (err == GRIB_INVALID_BPV || err == GRIB_DECODING_ERROR) if (err == GRIB_INVALID_BPV || err == GRIB_DECODING_ERROR)
@ -49,7 +43,7 @@ int main(int argc, char** argv)
grib_handle* h; grib_handle* h;
char* filename; char* filename;
if (argc < 2) usage(argv[0]); Assert(argc == 2);
filename = argv[1]; filename = argv[1];
for (i = 0; i < 255; i++) { for (i = 0; i < 255; i++) {

View File

@ -26,21 +26,14 @@ int main(int argc, char** argv)
double dmin, dmax, dval; double dmin, dmax, dval;
float fval; float fval;
FILE* in = NULL; Assert(argc == 2);
const char* filename = 0; const char* filename = argv[1];
codes_handle* h = NULL;
if (argc != 2) {
fprintf(stderr, "usage: %s file\n", argv[0]);
return 1;
}
filename = argv[1];
printf("Opening %s\n", filename); printf("Opening %s\n", filename);
in = fopen(filename, "rb"); FILE* in = fopen(filename, "rb");
Assert(in); Assert(in);
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); codes_handle* h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
Assert(h); Assert(h);
CODES_CHECK(codes_get_float(h, "referenceValue", &fval), 0); CODES_CHECK(codes_get_float(h, "referenceValue", &fval), 0);

View File

@ -9,18 +9,11 @@
*/ */
/* /*
* Description: Reads a GRIB message from file, measures read time. * Description: Reads a GRIB message from file, measures time taken
*
*/ */
#include <stdio.h> #include <stdio.h>
#include "grib_api_internal.h" #include "grib_api_internal.h"
static void usage(const char* prog)
{
printf("usage: %s filename\n", prog);
exit(1);
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
grib_timer* tes = grib_get_timer(0, "decoding", 0, 0); grib_timer* tes = grib_get_timer(0, "decoding", 0, 0);
@ -33,21 +26,15 @@ int main(int argc, char** argv)
const double duration_max = 3.6; /* seconds */ const double duration_max = 3.6; /* seconds */
const int num_repetitions = 100; const int num_repetitions = 100;
if (argc < 2) usage(argv[0]); if (argc < 2) return 1;
in = fopen(argv[1], "rb"); in = fopen(argv[1], "rb");
if (!in) { Assert(in);
printf("ERROR: unable to open file %s\n", argv[1]);
return 1;
}
/* create new handle */ /* create new handle */
err = 0; err = 0;
h = grib_handle_new_from_file(0, in, &err); h = grib_handle_new_from_file(0, in, &err);
if (h == NULL) { Assert(h);
printf("Error: unable to create handle from file.\n");
return 1;
}
/* get the size of the values array*/ /* get the size of the values array*/
GRIB_CHECK(grib_get_size(h, "values", &values_len), 0); GRIB_CHECK(grib_get_size(h, "values", &values_len), 0);
@ -72,9 +59,3 @@ int main(int argc, char** argv)
fclose(in); fclose(in);
return 0; return 0;
} }
// int main(int argc, char** argv)
// {
// return 0;
// }
// #endif

View File

@ -8,25 +8,14 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/ */
/* /* Test: reading GRIB2 multi fields messages from memory */
* test: reading GRIB2 multi fields messages from memory
*/
#include "grib_api_internal.h" #include "grib_api_internal.h"
static void usage(const char* prog)
{
fprintf(stderr, "usage: %s [-m] file.grib\n", prog);
exit(1);
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
struct stat finfo; struct stat finfo;
char shortName[20] = { char shortName[20] = {0,};
0,
};
size_t len; size_t len;
grib_handle* h = NULL; grib_handle* h = NULL;
size_t fsize; size_t fsize;
@ -49,25 +38,18 @@ int main(int argc, char* argv[])
else if (argc == 2) else if (argc == 2)
filename = argv[1]; filename = argv[1];
else else
usage(argv[0]); return 1;
Assert(filename); Assert(filename);
f = fopen(filename, "rb"); f = fopen(filename, "rb");
if (!f) { Assert(f);
perror(filename);
exit(1);
}
stat(filename, &finfo); stat(filename, &finfo);
fsize = finfo.st_size; fsize = finfo.st_size;
data = (unsigned char*)malloc(fsize); data = (unsigned char*)malloc(fsize);
p = data; p = data;
Assert(data);
if (!data) {
fprintf(stderr, "unable to allocate %ld bytes\n", (long)fsize);
exit(1);
}
if (fread(data, 1, fsize, f) != fsize) { if (fread(data, 1, fsize, f) != fsize) {
perror(filename); perror(filename);