An illustrative code example in C++ using the input parsing API is shown below (and is also available in the examples directory from a top-level install). This C++ example is configured to parse the example pecos-input.txt file shown here and uses many of the available parsing routines including a demonstration of default value registration.
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace GRVY;
using namespace std;
int main(int argc, char **argv)
{
GRVY_Input_Class iparse;
double reyn, mach, temp;
float aoa,A[3];
int iter_max,turbulent, ikoomie;
bool restart;
std::string GridFile, RestartFile;
std::string Key1, Key2;
if(! iparse.Open("./pecos-input.txt"))
exit(1);
if( iparse.Read_Var("reyn",&reyn,0.) )
printf("--> %-11s = %f\n","reyn",reyn);
if( iparse.Read_Var("mach",&mach) )
printf("--> %-11s = %f\n","mach",mach);
if ( iparse.Read_Var("temp",&temp,1200.) )
printf("--> %-11s = %f\n","temp",temp);
if( iparse.Read_Var("aoa",&aoa,0.0f) )
printf("--> %-11s = %f\n","aoa",aoa);
if( iparse.Read_Var("iter_max",&iter_max,100) )
printf("--> %-11s = %i\n","iter_max",iter_max);
if( iparse.Read_Var("gridfile",&GridFile) )
cout << "--> gridfile = " << GridFile << endl;
std::string restart_flag("restart");
if( iparse.Read_Var(restart_flag,&restart,false) )
cout << "--> restart = " << restart << endl;
if(restart)
{
cout << endl << "Restart enabled - parsing desired restart file" << endl;
if( iparse.Read_Var("restartfile",&RestartFile,"sol.h5") )
cout << "--> restartfile = " << RestartFile << endl;
}
if( iparse.Read_Var("solver/turbulence",&turbulent))
printf("--> %-10s = %i\n","turbulent",turbulent);
if( iparse.Read_Var_iVec("solver/keywords",&Key1,0))
cout << "--> solver/keyword (#1) = " << Key1 << endl;
if( iparse.Read_Var_iVec("solver/keywords",&Key2,1))
cout << "--> solver/keyword (#2) = " << Key2 << endl;
if( iparse.Read_Var_Vec("turbulence/A",A,3))
printf("--> %-10s = %f %f %f\n","turbulence/A",A[0],A[1],A[2]);
if( iparse.Read_Var("koomie",&ikoomie) )
printf("--> %-11s = %i\n","koomie",ikoomie);
grvy_printf(GRVY_INFO,
"Switching to silent message mode...\n");
if( iparse.Read_Var("koomie",&ikoomie))
printf("--> %-11s = %i\n","koomie",ikoomie);
grvy_printf(GRVY_INFO,
"Switching back to standard INFO mode...\n");
printf("\n ------ Full Dump ------\n\n");
iparse.Fdump();
printf(" ---- End Full Dump ----\n\n");
printf("\n ------ Full Dump (delimited) ------\n\n");
iparse.Fdump("# ");
printf(" ---- End Full Dump ----\n\n");
printf("\n ------ Full Dump to test.out ------\n\n");
iparse.Fdump("% ","test.out");
printf(" ------- End Full Dump -------\n\n");
iparse.Close();
return 0;
}