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)
tw = timer_val(timer_read) - tw0;
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);
......
......@@ -279,7 +279,7 @@ void *CDIwrite(void *argument)
tw = timer_val(timer_write) - tw0;
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);
......
......@@ -1013,7 +1013,7 @@ void *Gradsdes(void *argument)
}
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);
......
......@@ -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);
off_t filesize(const char *restrict filename);
off_t fileSize(const char *restrict filename);
char *expand_filename(const char *string);
......
......@@ -276,6 +276,8 @@ void *kvlParseFile(const char *filename)
assert(filename != NULL);
filesize = fileSize(filename);
fp = fopen(filename, "r");
if ( fp == NULL )
{
......@@ -283,11 +285,6 @@ void *kvlParseFile(const char *filename)
return (kvl);
}
/* file size */
fseek(fp, 0L, SEEK_END);
filesize = (size_t) ftell(fp);
fseek(fp, 0L, SEEK_SET);
buffer = (char*) malloc(filesize);
nitems = fread(buffer, 1, filesize, fp);
......
......@@ -584,7 +584,7 @@ static modules_t Modules[] =
{ Eofcoeff, EofcoeffHelp, EofcoeffOperators, CDI_REAL, 2, -1 },
{ Eofcoeff3d, EofcoeffHelp, Eofcoeff3dOperators, CDI_REAL, 2, -1 },
{ 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 },
{ FC, NULL, FCOperators, CDI_REAL, 1, 1 },
{ Filedes, FiledesHelp, FiledesOperators, CDI_BOTH, 1, 0 },
......
......@@ -153,14 +153,11 @@ 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!");
{
size_t filesize;
size_t nele1, nele2;
nele1 = 4*8 + 4;
nele2 = 4*8 + 4;
size_t nele1 = 4*8 + 4;
size_t nele2 = 4*8 + 4;
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;
filesize = src_grid.size*(nele1) +
size_t filesize = src_grid.size*(nele1) +
tgt_grid.size*(nele2) +
rv.num_links*(4 + 4 + rv.num_wts*8);
......
......@@ -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' )
{
}
else
{
FILE *fp = NULL;
fp = fopen(filename, "r");
if ( fp == NULL )
{
fprintf(stderr, "Open failed on %s\n", filename);
}
else
{
fseek(fp, 0L, SEEK_END);
pos = ftello(fp);
}
struct stat buf;
if ( stat(filename, &buf) == 0 ) filesize = buf.st_size;
}
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