[prog] Converting definitions into 'on the fly' code...
Conor Daly
c.daly at met.ie
Tue May 4 11:19:58 EST 2004
This is an interesting one for me but comes with a few caveats. Well, one
really; "Large amounts of complexity are to be avoided".
We're working on writing a major, integrated, future proof quality control
(QC) system.
The setup:
Large database of weather data in many tables.
The same datatype (eg. dry bulb 2m temperature) may exist in different tables
with different column names depending on source and date.
The question:
Is there an easy way to translate a test (defined somewhere) into the code
to run that test while the program is running?
More detail:
I want to conduct a test such as: "Is the difference between air pressure
now (ppp[t]) and three hours ago (ppp[t-3]) equal to the supplied change
(a[t])?". This translates to the equation: a[t] = ppp[t-3] - ppp[t]
If I can read and parse that to generate a tree like:
=
/ \
/ \
a[t] -
/ \
/ \
ppp[-] ppp[t]
/ \
t 3
and use eval(tree); to evaluate it where eval() (lifted mostly from "The
Practice of Programming", Kernigan and Pike, ISBN 0-201-61586) looks
something like:
struct Symbol {
int value;
char *name;
}
struct Tree {
int op; /* Operation code */
int value; /* value if number */
Symbol *symbol; /* Symbol entry if variable */
Tree *left;
Tree *right;
};
int eval(Tree *t)
{
int left, right;
switch(t->op) {
case NUMBER:
return t->value;
case VARIABLE:
return t->symbol->value;
case ADD:
return eval(t->left) + eval(t->right);
/* ... */
}
}
Am I going to get snarled up in levels of program complexity that make it
impossible to see exactly what is happening? Are there ways to do this that
will give me the ability to see what is being compared with what?
Conor
--
Conor Daly, Please avoid sending me
Met Eireann, Glasnevin Hill, Word or PowerPoint attachments.
Dublin 9, Ireland http://www.fsf.org/philosophy/no-word-attachments.html
Ph +3531 8064276 Fax +3531 8064247
**********************************************************************
This e-mail and any files transmitted with it are confidential
and intended solely for the addressee. If you have received
this email in error please notify the sender.
This e-mail message has also been scanned for the
presence of computer viruses.
**********************************************************************
More information about the Programming
mailing list