Commit 6c404cc9 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

expand gridfile name parameter

parent fe569b34
......@@ -3,6 +3,10 @@
* using CDI library version 1.6.5
* Version 1.6.5 released
2014-09-19 Uwe Schulzweida
* expand gridfile name parameter [Bug #5196]
2014-09-18 Uwe Schulzweida
* gradsdes: added support for option 365_day_calendar
......
CDO NEWS
--------
Version 1.7.0 (01 October 2014):
Version 1.6.5 (01 October 2014):
New features:
Changed operators:
* remaplaf: changed weight calculation from SCRIP to YAC
* remaplaf: changed calculation of weights from SCRIP to YAC
Fixed bugs:
* gridarea: added support for concave grid cells
* gradsdes: added support for option 365_day_calendar
* import_binary: option 365_day_calendar does not work
* select: wrong result when select only one timestep
......
......@@ -193,5 +193,7 @@ void minmaxval(long nvals, double *array, int *imiss, double *minval, double *ma
off_t filesize(const char *filename);
char *expand_filename(const char *string);
#endif /* _CDO_INT_H */
......@@ -1771,8 +1771,16 @@ int cdoDefineGrid(const char *gridfile)
struct stat filestat;
int fileno;
int isreg = FALSE;
int lalloc = FALSE;
char *filename;
fileno = open(gridfile, O_RDONLY);
filename = expand_filename(gridfile);
if ( filename )
lalloc = TRUE;
else
filename = (char *) gridfile;
fileno = open(filename, O_RDONLY);
if ( fileno >= 0 )
{
if ( fstat(fileno, &filestat) == 0 )
......@@ -1790,14 +1798,14 @@ int cdoDefineGrid(const char *gridfile)
else
{
if ( read(fileno, buffer, 4) != 4 )
SysError("Read grid from %s failed!", gridfile);
SysError("Read grid from %s failed!", filename);
close(fileno);
if ( cmpstr(buffer, "CDF", len) == 0 )
{
if ( cdoDebug ) cdoPrint("Grid from netCDF file");
gridID = gridFromNCfile(gridfile);
gridID = gridFromNCfile(filename);
}
if ( gridID == -1 )
......@@ -1805,7 +1813,7 @@ int cdoDefineGrid(const char *gridfile)
if ( cmpstr(buffer+1, "HDF", len) == 0 )
{
if ( cdoDebug ) cdoPrint("Grid from HDF5 file");
gridID = gridFromH5file(gridfile);
gridID = gridFromH5file(filename);
}
}
......@@ -1814,7 +1822,7 @@ int cdoDefineGrid(const char *gridfile)
if ( cmpstr(buffer+1, "HDF", len) == 0 )
{
if ( cdoDebug ) cdoPrint("Grid from netCDF4 file");
gridID = gridFromNCfile(gridfile);
gridID = gridFromNCfile(filename);
}
}
......@@ -1823,7 +1831,7 @@ int cdoDefineGrid(const char *gridfile)
int streamID;
if ( cdoDebug ) cdoPrint("Grid from CDI file");
openLock();
streamID = streamOpenRead(gridfile);
streamID = streamOpenRead(filename);
openUnlock();
if ( streamID >= 0 )
{
......@@ -1837,11 +1845,11 @@ int cdoDefineGrid(const char *gridfile)
if ( gridID == -1 )
{
if ( cdoDebug ) cdoPrint("grid from ASCII file");
gfp = fopen(gridfile, "r");
gfp = fopen(filename, "r");
//size_t buffersize = 20*1024*1024;
//char *buffer = (char*) malloc(buffersize);
//setvbuf(gfp, buffer, _IOFBF, buffersize);
gridID = gridFromFile(gfp, gridfile);
gridID = gridFromFile(gfp, filename);
fclose(gfp);
//free(buffer);
}
......@@ -1849,14 +1857,16 @@ int cdoDefineGrid(const char *gridfile)
if ( gridID == -1 )
{
if ( cdoDebug ) cdoPrint("grid from PINGO file");
gfp = fopen(gridfile, "r");
gridID = gridFromPingo(gfp, gridfile);
gfp = fopen(filename, "r");
gridID = gridFromPingo(gfp, filename);
fclose(gfp);
}
if ( gridID == -1 ) cdoAbort("Invalid grid description file %s!", gridfile);
if ( gridID == -1 ) cdoAbort("Invalid grid description file %s!", filename);
}
if ( lalloc ) free(filename);
return (gridID);
}
......
......@@ -327,11 +327,12 @@ const char *processInqPrompt(void)
argument_t *glob_pattern(const char *restrict wildcard)
{
size_t cnt, length = 0;
int glob_flags = GLOB_NOCHECK | GLOB_TILDE;
glob_t glob_results;
char **p;
argument_t *argument = NULL;
glob(wildcard, GLOB_NOCHECK, 0, &glob_results);
glob(wildcard, glob_flags, 0, &glob_results);
/* How much space do we need? */
for ( p = glob_results.gl_pathv, cnt = glob_results.gl_pathc; cnt; p++, cnt-- )
......@@ -536,21 +537,64 @@ void setStreamNames(int argc, char *argv[])
}
}
static
int find_wildcard(const char *string, size_t len)
{
int status = 0;
if ( len > 0 )
{
if ( string[0] == '~' ) status = 1;
if ( status == 0 )
{
for ( size_t i = 0; i < len; ++i )
if ( string[i] == '?' || string[i] == '*' || string[i] == '[' )
{
status = 1;
break;
}
}
}
return status;
}
char *expand_filename(const char *string)
{
char *filename = NULL;
if ( find_wildcard(string, strlen(string)) )
{
#if defined(HAVE_GLOB_H)
int glob_flags = GLOB_NOCHECK | GLOB_TILDE;
glob_t glob_results;
glob(string, glob_flags, 0, &glob_results);
if ( glob_results.gl_pathc == 1 ) filename = strdupx(glob_results.gl_pathv[0]);
globfree(&glob_results);
#endif
}
return filename;
}
static
int expand_wildcards(int processID, int streamCnt)
{
int i;
const char *streamname0 = Process[processID].streamNames[0].args;
int len = strlen(streamname0);
for ( i = 0; i < len; ++i ) if ( streamname0[i] == '?' || streamname0[i] == '*' || streamname0[i] == '[' ) break;
if ( i < len )
if ( find_wildcard(streamname0, strlen(streamname0)) )
{
#if defined(HAVE_GLOB_H)
argument_t *glob_arg = glob_pattern(streamname0);
if ( strcmp(streamname0, glob_arg->args) != 0 )
{
int i;
streamCnt = streamCnt - 1 + glob_arg->argc;
free(Process[processID].streamNames[0].argv);
......
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