Commit c0f3d4ec authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

expr: added support for function clon(), clat() and clev()

parent 77bbc311
......@@ -37,7 +37,7 @@ static const char *tmpvnm = "_tmp_";
int pointID = -1;
int surfaceID = -1;
enum {FT_STD, FT_CONST, FT_FLD, FT_VERT, FT_GRID};
enum {FT_STD, FT_CONST, FT_FLD, FT_VERT, FT_COORD};
#define COMPLT(x,y) ((x) < (y) ? 1 : 0)
#define COMPGT(x,y) ((x) > (y) ? 1 : 0)
......@@ -128,7 +128,10 @@ static func_t fun_sym_tbl[] =
{FT_VERT, 1, "vertvar", (void (*)()) fldvar},
{FT_VERT, 1, "vertvar1", (void (*)()) fldvar1},
// {FT_GRID, 1, "x", (void (*)()) xcoord},
{FT_COORD, 0, "clon", NULL},
{FT_COORD, 0, "clat", NULL},
{FT_COORD, 0, "clev", NULL},
{FT_COORD, 0, "gridarea", NULL},
};
static int NumFunc = sizeof(fun_sym_tbl) / sizeof(fun_sym_tbl[0]);
......@@ -747,12 +750,15 @@ nodeType *ex_fun_con(int funcID, nodeType *p1)
double (*exprfunc)(double) = (double (*)(double)) fun_sym_tbl[funcID].func;
p->u.con.value = exprfunc(p1->u.con.value);
if ( p1->ltmpobj ) node_delete(p1);
return p;
}
static
nodeType *ex_fun_var(int init, int funcID, nodeType *p1)
{
//const char *funcname = fun_sym_tbl[funcID].name;
int functype = fun_sym_tbl[funcID].type;
int funcflag = fun_sym_tbl[funcID].flag;
......@@ -846,6 +852,10 @@ nodeType *ex_fun_var(int init, int funcID, nodeType *p1)
if ( array ) Free(array);
if ( weights ) Free(weights);
}
else if ( functype == FT_COORD )
{
for ( size_t i = 0; i < ngp*nlev; i++ ) pdata[i] = p1data[i];
}
nmiss = 0;
for ( size_t i = 0; i < p->param.ngp*p->param.nlev; i++ )
......@@ -1294,8 +1304,36 @@ nodeType *expr_run(nodeType *p, parse_param_t *parse_arg)
case typeFun:
{
int funcID = get_funcID(p->u.fun.name);
int functype = fun_sym_tbl[funcID].type;
nodeType *fnode = expr_run(p->u.fun.op, parse_arg);
if ( functype == FT_COORD )
{
const char *funcname = fun_sym_tbl[funcID].name;
if ( fnode->type != typeVar ) cdoAbort("Parameter of function %s needs to be a variable!", funcname);
size_t len = 3 + strlen(fnode->u.var.nm);
char *cname = (char*) Calloc(len, 1);
strcpy(cname, fnode->u.var.nm);
if ( strcmp(funcname, "clon") == 0 ) strcat(cname, ".x");
else if ( strcmp(funcname, "clat") == 0 ) strcat(cname, ".y");
else if ( strcmp(funcname, "clev") == 0 ) strcat(cname, ".z");
else if ( strcmp(funcname, "gridarea") == 0 ) strcat(cname, ".a");
else cdoAbort("Implementation missing for function %s!", funcname);
Free(fnode->u.var.nm);
fnode->u.var.nm = cname;
nodeType *tmpnode = fnode;
fnode = expr_run(tmpnode, parse_arg);
if ( tmpnode->ltmpobj ) node_delete(tmpnode);
}
rnode = ex_fun(init, funcID, expr_run(p->u.fun.op, parse_arg));
rnode = ex_fun(init, funcID, fnode);
// if ( fnode->ltmpobj ) node_delete(fnode);
// Free(fnode);
break;
}
......
......@@ -8,8 +8,8 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
#define YY_FLEX_SUBMINOR_VERSION 0
#define YY_FLEX_MINOR_VERSION 5
#define YY_FLEX_SUBMINOR_VERSION 37
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
......@@ -159,15 +159,7 @@ typedef void* yyscan_t;
/* Size of default input buffer. */
#ifndef YY_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k.
* Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
* Ditto for the __ia64__ case accordingly.
*/
#define YY_BUF_SIZE 32768
#else
#define YY_BUF_SIZE 16384
#endif /* __ia64__ */
#endif
/* The state buf must be large enough to hold one state per character in the main buffer.
......@@ -189,7 +181,6 @@ typedef size_t yy_size_t;
#define EOB_ACT_LAST_MATCH 2
#define YY_LESS_LINENO(n)
#define YY_LINENO_REWIND_TO(ptr)
/* Return all but the first "n" matched characters back to the input stream. */
#define yyless(n) \
......@@ -335,7 +326,7 @@ void yyfree (void * ,yyscan_t yyscanner );
/* Begin user sect3 */
#define yywrap(yyscanner) (/*CONSTCOND*/1)
#define yywrap(yyscanner) 1
#define YY_SKIP_YYWRAP
typedef unsigned char YY_CHAR;
......@@ -347,9 +338,6 @@ typedef int yy_state_type;
static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
static int yy_get_next_buffer (yyscan_t yyscanner );
#if defined(__GNUC__) && __GNUC__ >= 3
__attribute__((__noreturn__))
#endif
static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
/* Done after the current pattern has been matched and before the
......@@ -397,7 +385,7 @@ static yyconst flex_int16_t yy_accept[61] =
93, 95, 97, 98, 101, 103, 105, 107, 109, 109
} ;
static yyconst YY_CHAR yy_ec[256] =
static yyconst flex_int32_t yy_ec[256] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
......@@ -429,14 +417,14 @@ static yyconst YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1
} ;
static yyconst YY_CHAR yy_meta[29] =
static yyconst flex_int32_t yy_meta[29] =
{ 0,
1, 1, 2, 3, 1, 1, 1, 3, 1, 1,
3, 3, 1, 1, 1, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 1
} ;
static yyconst flex_uint16_t yy_base[63] =
static yyconst flex_int16_t yy_base[63] =
{ 0,
0, 0, 122, 133, 27, 30, 107, 0, 112, 133,
23, 36, 104, 102, 80, 34, 47, 56, 27, 40,
......@@ -458,7 +446,7 @@ static yyconst flex_int16_t yy_def[63] =
59, 59
} ;
static yyconst flex_uint16_t yy_nxt[162] =
static yyconst flex_int16_t yy_nxt[162] =
{ 0,
4, 5, 6, 5, 7, 8, 9, 10, 10, 10,
11, 12, 13, 14, 15, 16, 17, 18, 16, 19,
......@@ -543,7 +531,7 @@ goto find_rule; \
LPH [A-Za-z_] Alphabetic character
LPHDGT [A-Za-z0-9_] Alphanumeric character
XPN [eE][+-]?[0-9]+ Real number Exponent */
#line 547 "expr_lex.c"
#line 535 "expr_lex.c"
#define INITIAL 0
......@@ -631,11 +619,11 @@ void yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
FILE *yyget_in (yyscan_t yyscanner );
void yyset_in (FILE * _in_str ,yyscan_t yyscanner );
void yyset_in (FILE * in_str ,yyscan_t yyscanner );
FILE *yyget_out (yyscan_t yyscanner );
void yyset_out (FILE * _out_str ,yyscan_t yyscanner );
void yyset_out (FILE * out_str ,yyscan_t yyscanner );
yy_size_t yyget_leng (yyscan_t yyscanner );
......@@ -643,11 +631,11 @@ char *yyget_text (yyscan_t yyscanner );
int yyget_lineno (yyscan_t yyscanner );
void yyset_lineno (int _line_number ,yyscan_t yyscanner );
void yyset_lineno (int line_number ,yyscan_t yyscanner );
int yyget_column (yyscan_t yyscanner );
void yyset_column (int _column_no ,yyscan_t yyscanner );
void yyset_column (int column_no ,yyscan_t yyscanner );
YYSTYPE * yyget_lval (yyscan_t yyscanner );
......@@ -665,10 +653,6 @@ extern int yywrap (yyscan_t yyscanner );
#endif
#endif
#ifndef YY_NO_UNPUT
#endif
#ifndef yytext_ptr
static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
#endif
......@@ -689,12 +673,7 @@ static int input (yyscan_t yyscanner );
/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k */
#define YY_READ_BUF_SIZE 16384
#else
#define YY_READ_BUF_SIZE 8192
#endif /* __ia64__ */
#endif
/* Copy whatever the last rule matched to the standard output. */
......@@ -783,7 +762,7 @@ extern int yylex \
/* Code executed at the end of each rule. */
#ifndef YY_BREAK
#define YY_BREAK /*LINTED*/break;
#define YY_BREAK break;
#endif
#define YY_RULE_SETUP \
......@@ -793,11 +772,16 @@ extern int yylex \
*/
YY_DECL
{
yy_state_type yy_current_state;
char *yy_cp, *yy_bp;
int yy_act;
register yy_state_type yy_current_state;
register char *yy_cp, *yy_bp;
register int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
#line 36 "expr_lex.l"
#line 784 "expr_lex.c"
yylval = yylval_param;
if ( !yyg->yy_init )
......@@ -832,13 +816,7 @@ YY_DECL
yy_load_buffer_state(yyscanner );
}
{
#line 36 "expr_lex.l"
#line 840 "expr_lex.c"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
while ( 1 ) /* loops until end-of-file is reached */
{
yy_cp = yyg->yy_c_buf_p;
......@@ -858,7 +836,7 @@ YY_DECL
yy_match:
do
{
YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
......@@ -1047,7 +1025,7 @@ YY_RULE_SETUP
#line 95 "expr_lex.l"
ECHO;
YY_BREAK
#line 1051 "expr_lex.c"
#line 1029 "expr_lex.c"
case YY_STATE_EOF(INITIAL):
yyterminate();
......@@ -1178,7 +1156,6 @@ ECHO;
"fatal flex scanner internal error--no action found" );
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of yylex */
/* yy_get_next_buffer - try to read in a new buffer
......@@ -1191,9 +1168,9 @@ ECHO;
static int yy_get_next_buffer (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
char *source = yyg->yytext_ptr;
yy_size_t number_to_move, i;
register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
register char *source = yyg->yytext_ptr;
register int number_to_move, i;
int ret_val;
if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
......@@ -1222,7 +1199,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
/* Try to read more data. */
/* First move last chars to start of buffer. */
number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++);
......@@ -1296,8 +1273,8 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
{
yy_state_type yy_current_state;
char *yy_cp;
register yy_state_type yy_current_state;
register char *yy_cp;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yy_current_state = yyg->yy_start;
......@@ -1307,7 +1284,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
{
YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
......@@ -1328,10 +1305,10 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
*/
static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
{
int yy_is_jam;
register int yy_is_jam;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
YY_CHAR yy_c = 1;
register YY_CHAR yy_c = 1;
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
......@@ -1347,10 +1324,6 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
return yy_is_jam ? 0 : yy_current_state;
}
#ifndef YY_NO_UNPUT
#endif
#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput (yyscan_t yyscanner)
......@@ -1504,7 +1477,7 @@ static void yy_load_buffer_state (yyscan_t yyscanner)
if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
b->yy_buf_size = (yy_size_t)size;
b->yy_buf_size = size;
/* yy_ch_buf has to be 2 characters longer than the size given because
* we need to put in 2 end-of-buffer characters.
......@@ -1665,7 +1638,7 @@ static void yyensure_buffer_stack (yyscan_t yyscanner)
* scanner will even need a stack. We use 2 instead of 1 to avoid an
* immediate realloc on the next call.
*/
num_to_alloc = 1; // After all that talk, this was set to 1 anyways...
num_to_alloc = 1;
yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
(num_to_alloc * sizeof(struct yy_buffer_state*)
, yyscanner);
......@@ -1682,7 +1655,7 @@ static void yyensure_buffer_stack (yyscan_t yyscanner)
if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
/* Increase the buffer to prepare for a possible push. */
yy_size_t grow_size = 8 /* arbitrary grow size */;
int grow_size = 8 /* arbitrary grow size */;
num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc
......@@ -1759,7 +1732,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
yy_size_t i;
int i;
/* Get memory for full buffer, including space for trailing EOB's. */
n = _yybytes_len + 2;
......@@ -1790,9 +1763,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len
static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
(void) fprintf( stderr, "%s\n", msg );
(void) fprintf( stderr, "%s\n", msg );
exit( YY_EXIT_FAILURE );
}
......@@ -1898,10 +1869,10 @@ void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
}
/** Set the current line number.
* @param _line_number line number
* @param line_number
* @param yyscanner The scanner object.
*/
void yyset_lineno (int _line_number , yyscan_t yyscanner)
void yyset_lineno (int line_number , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
......@@ -1909,14 +1880,14 @@ void yyset_lineno (int _line_number , yyscan_t yyscanner)
if (! YY_CURRENT_BUFFER )
YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
yylineno = _line_number;
yylineno = line_number;
}
/** Set the current column.
* @param _column_no column number
* @param line_number
* @param yyscanner The scanner object.
*/
void yyset_column (int _column_no , yyscan_t yyscanner)
void yyset_column (int column_no , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
......@@ -1924,25 +1895,25 @@ void yyset_column (int _column_no , yyscan_t yyscanner)
if (! YY_CURRENT_BUFFER )
YY_FATAL_ERROR( "yyset_column called with no buffer" );
yycolumn = _column_no;
yycolumn = column_no;
}
/** Set the input stream. This does not discard the current
* input buffer.
* @param _in_str A readable stream.
* @param in_str A readable stream.
* @param yyscanner The scanner object.
* @see yy_switch_to_buffer
*/
void yyset_in (FILE * _in_str , yyscan_t yyscanner)
void yyset_in (FILE * in_str , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyin = _in_str ;
yyin = in_str ;
}
void yyset_out (FILE * _out_str , yyscan_t yyscanner)
void yyset_out (FILE * out_str , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyout = _out_str ;
yyout = out_str ;
}
int yyget_debug (yyscan_t yyscanner)
......@@ -1951,10 +1922,10 @@ int yyget_debug (yyscan_t yyscanner)
return yy_flex_debug;
}
void yyset_debug (int _bdebug , yyscan_t yyscanner)
void yyset_debug (int bdebug , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yy_flex_debug = _bdebug ;
yy_flex_debug = bdebug ;
}
/* Accessor methods for yylval and yylloc */
......@@ -2113,10 +2084,7 @@ int yylex_destroy (yyscan_t yyscanner)
#ifndef yytext_ptr
static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
int i;
register int i;
for ( i = 0; i < n; ++i )
s1[i] = s2[i];
}
......@@ -2125,7 +2093,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yysca
#ifdef YY_NEED_STRLEN
static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
{
int n;
register int n;
for ( n = 0; s[n]; ++n )
;
......@@ -2135,16 +2103,11 @@ static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
void *yyalloc (yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
return (void *) malloc( size );
}
void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
/* The cast to (char *) in the following accommodates both
* implementations that use char* generic pointers, and those
* that use void* generic pointers. It works with the latter
......@@ -2157,8 +2120,6 @@ void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
void yyfree (void * ptr , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
}
......
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