diff --git a/tests/bufr_ecc-517.c b/tests/bufr_ecc-517.c index 54ca05e79..d6515232a 100644 --- a/tests/bufr_ecc-517.c +++ b/tests/bufr_ecc-517.c @@ -90,7 +90,7 @@ int main(int argc, char** argv) /* Encode the keys back in the data section */ CODES_CHECK(codes_set_long(h, "pack", 1), 0); - fout = fopen(outfilename, "w"); + fout = fopen(outfilename, "wb"); if (!fout) { fprintf(stderr, "Failed to open (create) output file.\n"); return 1; diff --git a/tests/bufr_get_element.c b/tests/bufr_get_element.c index 1de3588a3..ca44af265 100644 --- a/tests/bufr_get_element.c +++ b/tests/bufr_get_element.c @@ -29,7 +29,7 @@ int main(int argc,char* argv[]) const char* key_name = "#5#brightnessTemperature"; const double tolerance = 1e-6; - in=fopen(infile,"r"); + in=fopen(infile,"rb"); assert(in); while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) diff --git a/tests/bufr_keys_iter.c b/tests/bufr_keys_iter.c index ce7df3b77..eb38feb73 100644 --- a/tests/bufr_keys_iter.c +++ b/tests/bufr_keys_iter.c @@ -46,7 +46,7 @@ int main(int argc,char* argv[]) } assert(input_filename); - f = fopen(input_filename, "r"); + f = fopen(input_filename, "rb"); assert(f); h = codes_handle_new_from_file(NULL, f, PRODUCT_BUFR, &err); assert(h); diff --git a/tests/gauss_sub.c b/tests/gauss_sub.c index 6941d74c9..a9e8ee5a8 100644 --- a/tests/gauss_sub.c +++ b/tests/gauss_sub.c @@ -38,13 +38,13 @@ int main(int argc, char* argv[]) { infile1=argv[1]; infile2=argv[2]; - f1=fopen(infile1,"r"); + f1=fopen(infile1,"rb"); if (!f1) { perror(infile1); exit(1); } - f2=fopen(infile2,"r"); + f2=fopen(infile2,"rb"); if (!f2) { perror(infile2); exit(1); diff --git a/tests/grib_double_cmp.c b/tests/grib_double_cmp.c index bbec47ca5..bbd0b02d9 100644 --- a/tests/grib_double_cmp.c +++ b/tests/grib_double_cmp.c @@ -36,7 +36,7 @@ int main(int argc, char** argv) if (argc<2) usage(argv[0]); filename=argv[1]; - in = fopen(filename,"r"); + in = fopen(filename,"rb"); if(!in) { printf("ERROR: unable to open file %s\n",filename); return 1; diff --git a/tests/grib_ecc-386.c b/tests/grib_ecc-386.c index 5883b2e57..a51cd1f07 100644 --- a/tests/grib_ecc-386.c +++ b/tests/grib_ecc-386.c @@ -36,13 +36,13 @@ int main(int argc, char** argv) if (argc<2) usage(argv[0]); - in = fopen(argv[1],"r"); + in = fopen(argv[1],"rb"); if(!in) { printf("ERROR: unable to open file %s\n",argv[1]); return 1; } - /* create new handle from a message in a file*/ + /* create new handle */ err = 0; h = grib_handle_new_from_file(0,in,&err); if (h == NULL) { diff --git a/tests/grib_util_set_spec.c b/tests/grib_util_set_spec.c index c736a65e0..beed53378 100644 --- a/tests/grib_util_set_spec.c +++ b/tests/grib_util_set_spec.c @@ -51,7 +51,7 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi grib_util_packing_spec packing_spec={0,}; assert(input_filename); - in = fopen(input_filename,"r"); assert(in); + in = fopen(input_filename,"rb"); assert(in); handle = grib_handle_new_from_file(0,in,&err); assert(handle); CODES_CHECK(grib_get_string(handle, "gridType", gridType, &slen),0); @@ -60,7 +60,7 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi return; } assert(output_filename); - out = fopen(output_filename,"w"); assert(out); + out = fopen(output_filename,"wb"); assert(out); CODES_CHECK(grib_get_size(handle,"values",&inlen), 0); values = (double*)malloc(sizeof(double)*inlen); @@ -155,7 +155,7 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi grib_util_packing_spec packing_spec={0,}; assert(input_filename); - in = fopen(input_filename,"r"); assert(in); + in = fopen(input_filename,"rb"); assert(in); handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); assert(handle); CODES_CHECK(codes_get_long(handle, "edition", &input_edition), 0); @@ -166,7 +166,7 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi return; } assert(output_filename); - out = fopen(output_filename,"w"); assert(out); + out = fopen(output_filename,"wb"); assert(out); CODES_CHECK(codes_get_size(handle,"values",&inlen), 0); values = (double*)malloc(sizeof(double)*inlen); @@ -255,7 +255,7 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi grib_util_grid_spec spec={0,}; grib_util_packing_spec packing_spec={0,}; - in = fopen(input_filename,"r"); assert(in); + in = fopen(input_filename,"rb"); assert(in); handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); assert(handle); CODES_CHECK(grib_get_string(handle, "packingType", gridType, &slen),0); @@ -263,7 +263,7 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi grib_handle_delete(handle); return; } - out = fopen(output_filename,"w"); assert(out); + out = fopen(output_filename,"wb"); assert(out); CODES_CHECK(codes_get_size(handle,"values",&inlen), 0); values = (double*)malloc(sizeof(double)*inlen); diff --git a/tests/read_any.c b/tests/read_any.c index 6b8a81f99..e292b01fc 100644 --- a/tests/read_any.c +++ b/tests/read_any.c @@ -9,71 +9,74 @@ */ #include "grib_api_internal.h" -static void usage(const char* prog) { - printf("usage: %s infile\n",prog); - exit(1); +static void usage (const char *prog) +{ + printf ("usage: %s infile\n", prog); + exit (1); } static unsigned char buffer[50000000]; -int main(int argc,char* argv[]) { +int main (int argc, char *argv[]) +{ + char *filename; + FILE *f; + grib_handle *h = NULL; + grib_context *c; + size_t size = 0; + int ret = 0; + size_t bufsize = sizeof (buffer); + long count, step, edition, totalLength; + char gridType[50], levelType[50], level[50], shortName[50]; + size_t gridTypelen = sizeof (gridType); + size_t levelTypelen = sizeof (levelType); + size_t levellen = sizeof (level); + size_t shortNamelen = sizeof (shortName); + size_t len; - char* filename; - FILE* f; - grib_handle* h=NULL; - grib_context* c; - size_t size=0; - int ret=0; - size_t bufsize=sizeof(buffer); - long count,step,edition,totalLength; - char gridType[50],levelType[50],level[50],shortName[50]; - size_t gridTypelen=sizeof(gridType); - size_t levelTypelen=sizeof(levelType); - size_t levellen=sizeof(level); - size_t shortNamelen=sizeof(shortName); - size_t len; + if (argc != 2) + usage (argv[0]); + filename = argv[1]; - if (argc!=2) usage(argv[0]); - filename=argv[1]; + f = fopen (filename, "rb"); + if (!f) { + perror (filename); + exit (1); + } + c = grib_context_get_default (); - f=fopen(filename,"r"); - if (!f) { - perror(filename); - exit(1); - } - c=grib_context_get_default(); - - size=bufsize; - count=1; - while ((ret=grib_read_any_from_file(c,f,buffer,&size))==GRIB_SUCCESS) { - if ((1)) { - h=grib_handle_new_from_message_copy(c,buffer,size); - if (!h) { - printf("unable to new from message\n"); - exit(1); - } else { - grib_get_long(h,"edition",&edition); - grib_get_long(h,"step",&step); - grib_get_long(h,"totalLength",&totalLength); - len=gridTypelen; - grib_get_string(h,"gridType",gridType,&len); - len=levelTypelen; - GRIB_CHECK(grib_get_string(h,"levelType",levelType,&len),0); - len=levellen; - grib_get_string(h,"level",level,&len); - len=shortNamelen; - grib_get_string(h,"shortName",shortName,&len); - printf("- %3ld -\t ed=%ld\t size=%8ld totalLength=%8ld \t %s\t %s\t %s\t level=%s\t step=%ld\n", - count, edition, (long)size, totalLength, shortName, gridType, levelType, level, step); - grib_handle_delete(h); - } - } else { - printf("MESSAGE #%ld\n",count); - } - size=bufsize; - count++; - } - - return 0; + size = bufsize; + count = 1; + while ((ret = grib_read_any_from_file (c, f, buffer, &size)) == GRIB_SUCCESS) { + if ((1)) { + h = grib_handle_new_from_message_copy (c, buffer, size); + if (!h) { + printf ("unable to new from message\n"); + exit (1); + } + else { + grib_get_long (h, "edition", &edition); + grib_get_long (h, "step", &step); + grib_get_long (h, "totalLength", &totalLength); + len = gridTypelen; + grib_get_string (h, "gridType", gridType, &len); + len = levelTypelen; + GRIB_CHECK (grib_get_string (h, "levelType", levelType, &len), 0); + len = levellen; + grib_get_string (h, "level", level, &len); + len = shortNamelen; + grib_get_string (h, "shortName", shortName, &len); + printf ("- %3ld -\t ed=%ld\t size=%8ld totalLength=%8ld \t %s\t %s\t %s\t level=%s\t step=%ld\n", + count, edition, (long) size, totalLength, shortName, gridType, levelType, level, step); + grib_handle_delete (h); + } + } + else { + printf ("MESSAGE #%ld\n", count); + } + size = bufsize; + count++; + } + return 0; }