Commit 9a9ae195 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

fileSize: use stat() instead of fseek/ftell

parent ca86b00f
...@@ -179,7 +179,7 @@ void *CDIread(void *argument) ...@@ -179,7 +179,7 @@ void *CDIread(void *argument)
tw = timer_val(timer_read) - tw0; tw = timer_val(timer_read) - tw0;
twsum += tw; twsum += tw;
file_size = (double) filesize(cdoStreamName(0)->args); file_size = (double) fileSize(cdoStreamName(0)->args);
if ( nruns > 1 ) sprintf(sinfo, "(run %d)", irun+1); if ( nruns > 1 ) sprintf(sinfo, "(run %d)", irun+1);
......
...@@ -279,7 +279,7 @@ void *CDIwrite(void *argument) ...@@ -279,7 +279,7 @@ void *CDIwrite(void *argument)
tw = timer_val(timer_write) - tw0; tw = timer_val(timer_write) - tw0;
twsum += tw; twsum += tw;
file_size = (double ) filesize(cdoStreamName(0)->args); file_size = (double) fileSize(cdoStreamName(0)->args);
if ( nruns > 1 ) sprintf(sinfo, "(run %d)", irun+1); if ( nruns > 1 ) sprintf(sinfo, "(run %d)", irun+1);
......
...@@ -1013,7 +1013,7 @@ void *Gradsdes(void *argument) ...@@ -1013,7 +1013,7 @@ void *Gradsdes(void *argument)
} }
else else
{ {
if ( filesize(cdoStreamName(0)->args) > 2147483647L ) map_version = 4; if ( fileSize(cdoStreamName(0)->args) > 2147483647L ) map_version = 4;
} }
if ( cdoVerbose ) cdoPrint("GrADS GRIB map version: %d", map_version); if ( cdoVerbose ) cdoPrint("GrADS GRIB map version: %d", map_version);
......
...@@ -142,7 +142,7 @@ void job_submit(const char *expname, const char *jobfilename, const char *jobnam ...@@ -142,7 +142,7 @@ void job_submit(const char *expname, const char *jobfilename, const char *jobnam
void minmaxval(long nvals, double *array, int *imiss, double *minval, double *maxval); void minmaxval(long nvals, double *array, int *imiss, double *minval, double *maxval);
off_t filesize(const char *restrict filename); off_t fileSize(const char *restrict filename);
char *expand_filename(const char *string); char *expand_filename(const char *string);
......
...@@ -276,6 +276,8 @@ void *kvlParseFile(const char *filename) ...@@ -276,6 +276,8 @@ void *kvlParseFile(const char *filename)
assert(filename != NULL); assert(filename != NULL);
filesize = fileSize(filename);
fp = fopen(filename, "r"); fp = fopen(filename, "r");
if ( fp == NULL ) if ( fp == NULL )
{ {
...@@ -283,11 +285,6 @@ void *kvlParseFile(const char *filename) ...@@ -283,11 +285,6 @@ void *kvlParseFile(const char *filename)
return (kvl); return (kvl);
} }
/* file size */
fseek(fp, 0L, SEEK_END);
filesize = (size_t) ftell(fp);
fseek(fp, 0L, SEEK_SET);
buffer = (char*) malloc(filesize); buffer = (char*) malloc(filesize);
nitems = fread(buffer, 1, filesize, fp); nitems = fread(buffer, 1, filesize, fp);
......
...@@ -573,7 +573,7 @@ static modules_t Modules[] = ...@@ -573,7 +573,7 @@ static modules_t Modules[] =
{ Derivepar, DeriveparHelp, DeriveparOperators, CDI_REAL, 1, 1 }, { Derivepar, DeriveparHelp, DeriveparOperators, CDI_REAL, 1, 1 },
{ Detrend, DetrendHelp, DetrendOperators, CDI_REAL, 1, 1 }, { Detrend, DetrendHelp, DetrendOperators, CDI_REAL, 1, 1 },
{ Diff, DiffHelp, DiffOperators, CDI_REAL, 2, 0 }, { Diff, DiffHelp, DiffOperators, CDI_REAL, 2, 0 },
{ Distgrid, DistgridHelp, DistgridOperators, CDI_REAL, 1, 1 }, { Distgrid, DistgridHelp, DistgridOperators, CDI_REAL, 1, 1 },
{ Duplicate, DuplicateHelp, DuplicateOperators, CDI_REAL, 1, 1 }, { Duplicate, DuplicateHelp, DuplicateOperators, CDI_REAL, 1, 1 },
{ Echam5ini, NULL, Echam5iniOperators, CDI_REAL, 1, 1 }, { Echam5ini, NULL, Echam5iniOperators, CDI_REAL, 1, 1 },
{ Enlarge, EnlargeHelp, EnlargeOperators, CDI_REAL, 1, 1 }, { Enlarge, EnlargeHelp, EnlargeOperators, CDI_REAL, 1, 1 },
...@@ -584,7 +584,7 @@ static modules_t Modules[] = ...@@ -584,7 +584,7 @@ static modules_t Modules[] =
{ Eofcoeff, EofcoeffHelp, EofcoeffOperators, CDI_REAL, 2, -1 }, { Eofcoeff, EofcoeffHelp, EofcoeffOperators, CDI_REAL, 2, -1 },
{ Eofcoeff3d, EofcoeffHelp, Eofcoeff3dOperators, CDI_REAL, 2, -1 }, { Eofcoeff3d, EofcoeffHelp, Eofcoeff3dOperators, CDI_REAL, 2, -1 },
{ EOFs, EOFsHelp, EOFsOperators, CDI_REAL, 1, 2 }, { EOFs, EOFsHelp, EOFsOperators, CDI_REAL, 1, 2 },
{ EOF3d, NULL, EOF3dOperators, CDI_REAL, 1, 2 }, { EOF3d, EOFsHelp, EOF3dOperators, CDI_REAL, 1, 2 },
{ Expr, ExprHelp, ExprOperators, CDI_REAL, 1, 1 }, { Expr, ExprHelp, ExprOperators, CDI_REAL, 1, 1 },
{ FC, NULL, FCOperators, CDI_REAL, 1, 1 }, { FC, NULL, FCOperators, CDI_REAL, 1, 1 },
{ Filedes, FiledesHelp, FiledesOperators, CDI_BOTH, 1, 0 }, { Filedes, FiledesHelp, FiledesOperators, CDI_BOTH, 1, 0 },
......
...@@ -153,16 +153,13 @@ void write_remap_scrip(const char *interp_file, int map_type, int submap_type, i ...@@ -153,16 +153,13 @@ void write_remap_scrip(const char *interp_file, int map_type, int submap_type, i
cdoAbort("Number of remap links is 0, no remap weights found!"); cdoAbort("Number of remap links is 0, no remap weights found!");
{ {
size_t filesize; size_t nele1 = 4*8 + 4;
size_t nele1, nele2; size_t nele2 = 4*8 + 4;
nele1 = 4*8 + 4;
nele2 = 4*8 + 4;
if ( src_grid.lneed_cell_corners ) nele1 += src_grid.num_cell_corners*2*8; if ( src_grid.lneed_cell_corners ) nele1 += src_grid.num_cell_corners*2*8;
if ( tgt_grid.lneed_cell_corners ) nele2 += tgt_grid.num_cell_corners*2*8; if ( tgt_grid.lneed_cell_corners ) nele2 += tgt_grid.num_cell_corners*2*8;
filesize = src_grid.size*(nele1) + size_t filesize = src_grid.size*(nele1) +
tgt_grid.size*(nele2) + tgt_grid.size*(nele2) +
rv.num_links*(4 + 4 + rv.num_wts*8); rv.num_links*(4 + 4 + rv.num_wts*8);
if ( cdoVerbose ) if ( cdoVerbose )
cdoPrint("Filesize for remap weights: ~%lu", (unsigned long) filesize); cdoPrint("Filesize for remap weights: ~%lu", (unsigned long) filesize);
......
...@@ -622,29 +622,20 @@ int str2datatype(const char *datatypestr) ...@@ -622,29 +622,20 @@ int str2datatype(const char *datatypestr)
} }
off_t filesize(const char *restrict filename) off_t fileSize(const char *restrict filename)
{ {
off_t pos = 0; off_t filesize = 0;
if ( filename[0] == '(' && filename[1] == 'p' ) if ( filename[0] == '(' && filename[1] == 'p' )
{ {
} }
else else
{ {
FILE *fp = NULL; struct stat buf;
fp = fopen(filename, "r"); if ( stat(filename, &buf) == 0 ) filesize = buf.st_size;
if ( fp == NULL )
{
fprintf(stderr, "Open failed on %s\n", filename);
}
else
{
fseek(fp, 0L, SEEK_END);
pos = ftello(fp);
}
} }
return pos; return filesize;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment