Ejemplo n.º 1
0
int  createStorageExfil(int k, double x[])
//
//  Input:   k = index of storage unit node
//           x = array of Green-Ampt infiltration parameters
//  Output:  returns an error code.
//  Purpose: creates an exfiltration object for a storage node.
//
//  Note: the exfiltration object is freed in project.c.
//
{
    TExfil*   exfil;

    // --- create an exfiltration object for the storage node
    exfil = Storage[k].exfil;
    if ( exfil == NULL )
    {
        exfil = (TExfil *) malloc(sizeof(TExfil));
        if ( exfil == NULL ) return error_setInpError(ERR_MEMORY, "");
        Storage[k].exfil = exfil;

        // --- create Green-Ampt infiltration objects for the bottom & banks
        exfil->btmExfil = NULL;
        exfil->bankExfil = NULL;
        exfil->btmExfil = (TGrnAmpt *) malloc(sizeof(TGrnAmpt));
        if ( exfil->btmExfil == NULL ) return error_setInpError(ERR_MEMORY, "");
        exfil->bankExfil = (TGrnAmpt *) malloc(sizeof(TGrnAmpt));
        if ( exfil->bankExfil == NULL ) return error_setInpError(ERR_MEMORY, "");
    }

    // --- initialize the Green-Ampt parameters
    if ( !grnampt_setParams(exfil->btmExfil, x) )
        return error_setInpError(ERR_NUMBER, "");
    grnampt_setParams(exfil->bankExfil, x);
    return 0;
}
Ejemplo n.º 2
0
int infil_readParams(int m, char* tok[], int ntoks)
//
//  Input:   m = infiltration method code
//           tok[] = array of string tokens
//           ntoks = number of tokens
//  Output:  returns an error code
//  Purpose: sets infiltration parameters from a line of input data.
//
//  Format of data line is:
//     subcatch  p1  p2 ...
{
    int   i, j, n, status;
    double x[5];

    // --- check that subcatchment exists
    j = project_findObject(SUBCATCH, tok[0]);
    if ( j < 0 ) return error_setInpError(ERR_NAME, tok[0]);

    // --- number of input tokens depends on infiltration model m
    if      ( m == HORTON )       n = 5;
    else if ( m == MOD_HORTON )   n = 5;
    else if ( m == GREEN_AMPT )   n = 4;
    else if ( m == MOD_GREEN_AMPT )   n = 4;                                   //(5.1.010)
    else if ( m == CURVE_NUMBER ) n = 4;
    else return 0;
    if ( ntoks < n ) return error_setInpError(ERR_ITEMS, "");

    // --- parse numerical values from tokens
    for (i = 0; i < 5; i++) x[i] = 0.0;
    for (i = 1; i < n; i++)
    {
        if ( ! getDouble(tok[i], &x[i-1]) )
            return error_setInpError(ERR_NUMBER, tok[i]);
    }

    // --- special case for Horton infil. - last parameter is optional
    if ( (m == HORTON || m == MOD_HORTON) && ntoks > n )
    {
        if ( ! getDouble(tok[n], &x[n-1]) )
            return error_setInpError(ERR_NUMBER, tok[n]);
    }

    // --- assign parameter values to infil. object
    Subcatch[j].infil = j;
    switch (m)
    {
      case HORTON:
      case MOD_HORTON:   status = horton_setParams(&HortInfil[j], x);
                         break;
      case GREEN_AMPT:
      case MOD_GREEN_AMPT:                                                     //(5.1.010)
                         status = grnampt_setParams(&GAInfil[j], x);
                         break;
      case CURVE_NUMBER: status = curvenum_setParams(&CNInfil[j], x);
                         break;
      default:           status = TRUE;
    }
    if ( !status ) return error_setInpError(ERR_NUMBER, "");
    return 0;
}
Ejemplo n.º 3
0
int storage_readInfilParams(int j, char* tok[], int ntoks, int n)
{
    int       i, k;
    double    x[3];
    TGrnAmpt* infil;

    // --- read Grenn-Ampt infiltration parameters from input tokens
    if ( ntoks < n + 3 ) return error_setInpError(ERR_ITEMS, "");
    for (i = 0; i < 3; i++)
    {
        if ( ! getDouble(tok[n+i], &x[i]) )
            return error_setInpError(ERR_NUMBER, tok[n+i]);
    }

    // --- create a Green-Ampt infiltration object for the storage node
    k = Node[j].subIndex;
    infil = Storage[k].infil;
    if ( infil == NULL )
    {
        infil = (TGrnAmpt *) malloc(sizeof(TGrnAmpt));
        if ( infil == NULL ) return error_setInpError(ERR_MEMORY, "");
        Storage[k].infil = infil;
    }

    // --- add the infiltration parameters to the Green-Ampt object
    if ( !grnampt_setParams(infil, x) ) return error_setInpError(ERR_NUMBER, "");
    return 0;
}