Windows test failures: use binary mode for opening GRIBs

This commit is contained in:
Shahram Najm 2019-12-10 16:27:44 +00:00
parent 13ead71c10
commit 7403ae68fa
18 changed files with 42 additions and 42 deletions

View File

@ -44,14 +44,14 @@ 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;
}
/* create new handle from a message in a file*/
while((h = codes_handle_new_from_file(0,f,&err)) != NULL) {
while((h = codes_handle_new_from_file(0,in,&err)) != NULL) {
/* get the size of the values array*/
CODES_CHECK(codes_get_size(h,"values",&values_len),0);

View File

@ -27,10 +27,10 @@ static int encode_file(char *template_file, char *output_file)
long numSubsets = 0;
assert(template_file);
in = fopen(template_file,"r"); assert(in);
in = fopen(template_file,"rb"); assert(in);
if (opt_write) {
assert(output_file);
out = fopen(output_file,"w"); assert(out);
out = fopen(output_file,"wb"); assert(out);
}
/* loop over the messages in the source BUFR and clone them */

View File

@ -21,7 +21,7 @@ size_t grib_handle_write(grib_handle* h,char* filename) {
FILE* of=NULL;
const void *buffer; size_t size;
of = fopen(filename,"w");
of = fopen(filename,"wb");
if(!of) {
perror(filename);
exit(1);
@ -99,13 +99,13 @@ int main(int argc, char* argv[]) {
repeatsimple=atoi(argv[iarg++]);
bitsPerValue=atoi(argv[iarg++]);
fin = fopen(finname,"r");
fin = fopen(finname,"rb");
if(!fin) {perror(finname);exit(1);}
if (append)
fout = fopen(ofilename,"a");
fout = fopen(ofilename,"ab");
else
fout = fopen(ofilename,"w");
fout = fopen(ofilename,"wb");
if(!fout) {perror(ofilename);exit(1);}

View File

@ -25,9 +25,9 @@ static int encode_file(char *template_file, char *output_file)
int err = 0;
double *values;
in = fopen(template_file,"r"); assert(in);
in = fopen(template_file,"rb"); assert(in);
if (opt_write) {
out = fopen(output_file,"w"); assert(out);
out = fopen(output_file,"wb"); assert(out);
}
/* loop over the messages in the source GRIB and clone them */

View File

@ -56,8 +56,8 @@ static int encode_file(char *input_file, char *output_file)
const void *buffer = NULL;
int err = 0;
FILE* in = fopen(input_file,"r");
FILE* out = fopen(output_file,"w");
FILE* in = fopen(input_file,"rb");
FILE* out = fopen(output_file,"wb");
assert(in);
assert(out);

View File

@ -768,7 +768,7 @@ int main (int argc, char *argv[])
size_t size;
const void *buffer = NULL;
sprintf (f, "lam_bf_%s_%s.grib", grids[igrid], trunc[itrunc].name);
fp = fopen (f, "w");
fp = fopen (f, "wb");
GRIB_CHECK (grib_get_message (h, &buffer, &size), 0);
if (fwrite (buffer, 1, size, fp) != size) {
perror (f);
@ -793,7 +793,7 @@ int main (int argc, char *argv[])
sprintf (f, "lam_bf_%s_%s.grib", grids[igrid], trunc[itrunc].name);
fp = fopen (f, "r");
fp = fopen (f, "rb");
h = grib_handle_new_from_file (0, fp, &err);
vals = (double *) malloc (sizeof (double) * trunc[itrunc].len);
values_len = trunc[itrunc].len;

View File

@ -917,7 +917,7 @@ int main (int argc, char *argv[])
size_t size;
const void *buffer = NULL;
sprintf (f, "lam_gp_%s.grib", grids[igrid]);
fp = fopen (f, "w");
fp = fopen (f, "wb");
GRIB_CHECK (grib_get_message (h, &buffer, &size), 0);
if (fwrite (buffer, 1, size, fp) != size)
{
@ -941,7 +941,7 @@ int main (int argc, char *argv[])
char geometry[128];
sprintf (f, "lam_gp_%s.grib", grids[igrid]);
fp = fopen (f, "r");
fp = fopen (f, "rb");
h = grib_handle_new_from_file (0, fp, &err);
vals = (double *) malloc (sizeof (double) * 4096);
values_len = 4096;

View File

@ -49,7 +49,7 @@ int main(int argc,char* argv[]) {
else usage(argv[0]);
assert(filename);
f=fopen(filename,"r");
f=fopen(filename,"rb");
if (!f) {perror(filename);exit(1);}
fstat(fileno((FILE*)f),&finfo);

View File

@ -215,7 +215,7 @@ size_t grib_handle_write(grib_handle* h,char* filename) {
FILE* of=NULL;
const void *buffer; size_t size;
of = fopen(filename,"w");
of = fopen(filename,"wb");
if(!of) {
perror(filename);
exit(1);
@ -303,7 +303,7 @@ int main(int argc, char* argv[]) {
repeatsimple=atoi(argv[iarg++]);
bitsPerValue=atoi(argv[iarg++]);
fin = fopen(finname,"r");
fin = fopen(finname,"rb");
if(!fin) {perror(finname);exit(1);}
c=grib_context_get_default();
@ -313,9 +313,9 @@ int main(int argc, char* argv[]) {
if (append)
fout = fopen(ofilename,"a");
fout = fopen(ofilename,"ab");
else
fout = fopen(ofilename,"w");
fout = fopen(ofilename,"wb");
if(!fout) {perror(ofilename);exit(1);}

View File

@ -21,7 +21,7 @@ size_t grib_handle_write(grib_handle* h,char* filename) {
FILE* of=NULL;
const void *buffer; size_t size;
of = fopen(filename,"w");
of = fopen(filename,"wb");
if(!of) {
perror(filename);
exit(1);
@ -99,13 +99,13 @@ int main(int argc, char* argv[]) {
repeatsimple=atoi(argv[iarg++]);
bitsPerValue=atoi(argv[iarg++]);
fin = fopen(finname,"r");
fin = fopen(finname,"rb");
if(!fin) {perror(finname);exit(1);}
if (append)
fout = fopen(ofilename,"a");
fout = fopen(ofilename,"ab");
else
fout = fopen(ofilename,"w");
fout = fopen(ofilename,"wb");
if(!fout) {perror(ofilename);exit(1);}

View File

@ -230,7 +230,7 @@ int main(int argc, char* argv[]) {
char finname[]="sh.grib";
fin = fopen(finname,"r");
fin = fopen(finname,"rb");
if(!fin) {perror(finname);exit(1);}
c=grib_context_get_default();
@ -268,7 +268,7 @@ int main(int argc, char* argv[]) {
ksec4,gvalues,nvalues, buf,&gribex_msg_len,"C"));
fout=fopen("out_gribex.grib","w");
fout=fopen("out_gribex.grib","wb");
if (!fout) {perror("out_gribex.grib");exit(1);}
if (fwrite(buf,1,gribex_msg_len,fout)!=gribex_msg_len) {
perror("out_gribex.grib"); exit(1);

View File

@ -229,7 +229,7 @@ int main(int argc, char* argv[]) {
if (argc != 2) usage(argv[0]);
finname=argv[1];
fin = fopen(finname,"r");
fin = fopen(finname,"rb");
if(!fin) {perror(finname);exit(1);}
c=grib_context_get_default();

View File

@ -407,7 +407,7 @@ int main(int argc, char* argv[]) {
err_threshold=atof(argv[++argi]);
finname=argv[++argi];
fin = fopen(finname,"r");
fin = fopen(finname,"rb");
if(!fin) {perror(finname);exit(1);}
c=grib_context_get_default();
@ -483,7 +483,7 @@ int main(int argc, char* argv[]) {
/* writing the output grib files if required */
if (write_grib == 1) {
if (!foutgribex) {
foutgribex=fopen(foutnamegribex,"w");
foutgribex=fopen(foutnamegribex,"wb");
if (!foutgribex) {
perror(foutnamegribex);
exit(1);
@ -502,7 +502,7 @@ int main(int argc, char* argv[]) {
if (write_grib == 2) {
GRIB_CHECK(grib_get_message(h,&msg,&msg_len),0);
if (!foutgrib) {
foutgrib=fopen(foutnamegrib,"w");
foutgrib=fopen(foutnamegrib,"wb");
if (!foutgrib) {
perror(foutnamegrib);
exit(1);

View File

@ -235,7 +235,7 @@ int main(int argc, char* argv[]) {
if (argc != 2 ) usage(argv[0]);
finname=argv[1];
fin = fopen(finname,"r");
fin = fopen(finname,"rb");
if(!fin) {perror(finname);exit(1);}
c=grib_context_get_default();

View File

@ -21,7 +21,7 @@ size_t grib_handle_write(grib_handle* h,char* filename) {
FILE* of=NULL;
const void *buffer; size_t size;
of = fopen(filename,"w");
of = fopen(filename,"wb");
if(!of) {
perror(filename);
exit(1);
@ -99,13 +99,13 @@ int main(int argc, char* argv[]) {
repeatsimple=atoi(argv[iarg++]);
bitsPerValue=atoi(argv[iarg++]);
fin = fopen(finname,"r");
fin = fopen(finname,"rb");
if(!fin) {perror(finname);exit(1);}
if (append)
fout = fopen(ofilename,"a");
fout = fopen(ofilename,"ab");
else
fout = fopen(ofilename,"w");
fout = fopen(ofilename,"wb");
if(!fout) {perror(ofilename);exit(1);}

View File

@ -215,7 +215,7 @@ size_t grib_handle_write(grib_handle* h,char* filename) {
FILE* of=NULL;
const void *buffer; size_t size;
of = fopen(filename,"w");
of = fopen(filename,"wb");
if(!of) {
perror(filename);
exit(1);
@ -312,7 +312,7 @@ int main(int argc, char* argv[]) {
repeatsimple=atoi(argv[iarg++]);
bitsPerValue=atoi(argv[iarg++]);
fin = fopen(finname,"r");
fin = fopen(finname,"rb");
if(!fin) {perror(finname);exit(1);}
c=grib_context_get_default();
@ -322,9 +322,9 @@ int main(int argc, char* argv[]) {
if (append)
fout = fopen(ofilename,"a");
fout = fopen(ofilename,"ab");
else
fout = fopen(ofilename,"w");
fout = fopen(ofilename,"wb");
if(!fout) {perror(ofilename);exit(1);}

View File

@ -238,7 +238,7 @@ int main(int argc, char* argv[]) {
if (argc != 2) usage(argv[0]);
finname=argv[1];
fin = fopen(finname,"r");
fin = fopen(finname,"rb");
if(!fin) {perror(finname);exit(1);}
c=grib_context_get_default();

View File

@ -34,7 +34,7 @@ int main(int argc, char** argv) {
if(argc > 1)
in = fopen(argv[1],"r");
in = fopen(argv[1],"rb");
else{
printf("usage : gribvals filename [format]\n");
exit(1);