void gwater_deleteFlowExpression(Project* project, int j) // // Input: j = subcatchment index // Output: none // Purpose: deletes a subcatchment's custom groundwater flow expressions. //(5.1.007) // { mathexpr_delete(project->Subcatch[j].gwLatFlowExpr); mathexpr_delete(project->Subcatch[j].gwDeepFlowExpr); }
int gwater_readFlowExpression(Project* project, char* tok[], int ntoks) // // Input: tok[] = array of string tokens // ntoks = number of tokens // Output: returns error code // Purpose: reads mathematical expression for lateral or deep groundwater // flow for a subcatchment from a line of input data. // // Format is: subcatch LATERAL/DEEP <expr> // where subcatch is the ID of the subcatchment, LATERAL is for lateral // project->GW flow, DEEP is for deep project->GW flow and <expr> is any well-formed math // expression. // { int i, j, k; char exprStr[MAXLINE+1]; MathExpr* expr; // --- return if too few tokens if ( ntoks < 3 ) return error_setInpError(ERR_ITEMS, ""); // --- check that subcatchment exists j = project_findObject(project, SUBCATCH, tok[0]); if ( j < 0 ) return error_setInpError(ERR_NAME, tok[0]); // --- check if expression is for lateral or deep project->GW flow k = 1; if ( match(tok[1], "LAT") ) k = 1; else if ( match(tok[1], "DEEP") ) k = 2; else return error_setInpError(ERR_KEYWORD, tok[1]); // --- concatenate remaining tokens into a single string strcpy(exprStr, tok[2]); for ( i = 3; i < ntoks; i++) { strcat(exprStr, " "); strcat(exprStr, tok[i]); } // --- delete any previous flow eqn. if ( k == 1 ) mathexpr_delete(project->Subcatch[j].gwLatFlowExpr); else mathexpr_delete(project->Subcatch[j].gwDeepFlowExpr); // --- create a parsed expression tree from the string expr // (getVariableIndex is the function that converts a project->GW // variable's name into an index number) expr = mathexpr_create(project,exprStr, getVariableIndex); if ( expr == NULL ) return error_setInpError(ERR_TREATMENT_EXPR, ""); // --- save expression tree with the subcatchment if ( k == 1 ) project->Subcatch[j].gwLatFlowExpr = expr; else project->Subcatch[j].gwDeepFlowExpr = expr; return 0; }
void treatmnt_delete(int j) // // Input: j = node index // Output: none // Purpose: deletes the treatment objects for each pollutant at a node. // { int p; if ( Node[j].treatment ) { for (p=0; p<Nobjects[POLLUT]; p++) mathexpr_delete(Node[j].treatment[p].equation); free(Node[j].treatment); } Node[j].treatment = NULL; }
void mathexpr_delete(MathExpr *expr) { if (expr) mathexpr_delete(expr->next); free(expr); }