Volcano Monitoring
by Steve Jordi


Listing One

// variables to be used

float vbat, ta, ut, tf0, e1, po2, coef, incl ;
long vbatPtr, taPtr, utPtr, tf0Ptr, e1Ptr, po2Ptr, coefPtr, inclPtr ;

// variables holding the formulas
String vbatF, taF, utF, tf0F, e1F, po2F, coefF, inclF ;
long vbatFPtr, taFPtr, utFPtr, tf0FPtr, e1FPtr, po2FPtr, coefFPtr, inclFPtr ;

// Get the formulas from the dialog box
vbatF = VBatFormula->Text ;
taF   = TaFormula->Text   ;
utF   = UtFormula->Text   ;
tf0F  = Tf0Formula->Text  ;
e1F   = E1Formula->Text   ;
po2F  = Po2Formula->Text  ;
coefF = CoefFormula->Text ;
inclF = InclFormula->Text ;

// Define the variables
vbatPtr  = ucDefineVariable( "vbat" ) ;
taPtr    = ucDefineVariable( "ta"   ) ;
utPtr    = ucDefineVariable( "ut"   ) ;
tf0Ptr   = ucDefineVariable( "tf0"  ) ;
e1Ptr    = ucDefineVariable( "e1"   ) ;
po2Ptr   = ucDefineVariable( "po2"  ) ;
coefPtr  = ucDefineVariable( "coef" ) ;
inclPtr  = ucDefineVariable( "incl" ) ;

// Prepare the parser for each formula
vbatFPtr = ucParse( vbatF.c_str() ) ;
taFPtr   = ucParse( taF.c_str()   ) ;
utFPtr   = ucParse( utF.c_str()   ) ;
tf0FPtr  = ucParse( tf0F.c_str()  ) ;
e1FPtr   = ucParse( e1F.c_str()   ) ;
po2FPtr  = ucParse( po2F.c_str()  ) ;
coefFPtr = ucParse( coefF.c_str() ) ;
inclFPtr = ucParse( inclF.c_str() ) ;

// Now just loop into the file "inputFile" and read all points. Most of them 
// are then sent to the appropriate chart by chartNNN->AddPoint(time,value); 
long timeVar = 0 ;
float dataVBat, dataTa, dataUt, dataTf0, dataE1, dataPo2, dataCoef, dataIncl ;

while( !inputFile->eof() ) {
   // read from file
   fscanf( inputFile, "%f %f %f %f %f %f %f %f", &dataVBat,  &dataTa,
      &dataUt, &dataTf0, &dataE1, &dataPo2, &dataCoef, &dataIncl      ) ;

   // set the variables values
   ucSetVariableValue( vbatPtr, dataVBat ) ;
   ucSetVariableValue( taPtr,   dataTa   ) ;
   ucSetVariableValue( utPtr,   dataUt   ) ;
   ucSetVariableValue( tf0Ptr,  dataTf0  ) ;
   ucSetVariableValue( e1Ptr,   dataE1   ) ;
   ucSetVariableValue( po2Ptr,  dataPo2  ) ;
   ucSetVariableValue( coefPtr, dataCoef ) ;

   ucSetVariableValue( inclPtr, dataIncl ) ;

   // calculate everything and pass the values to the charts
   chartVBat->AddPoint( timeVar, ucEvaluate( vbatFPtr ) ;
   chartTa->AddPoint(   timeVar, ucEvaluate( taFPtr ) ;
   ut = ucEvaluate( utFPtr ) ;
   chartTf0->AddPoint(  timeVar, ucEvaluate( tf0FPtr ) ;
   e1 = ucEvaluate( e1FPtr ) ;
   chartCoef->AddPoint( timeVar, ucEvaluate( coefFPtr ) ;
   chartIncl->AddPoint( timeVar, ucEvaluate( inclFPtr ) ;
   timeVar += deltaTime ;
}
// Now we are done with all the calculation
inputFile.close() ;

ucReleaseExpr() ;





2

