Пример #1
0
int rdii_readUnitHydParams(char* tok[], int ntoks)
//
//  Input:   tok[] = array of string tokens
//           ntoks = number of tokens
//  Output:  returns an error code
//  Purpose: reads parameters of an RDII unit hydrograph from a line of input.
//
{
    int i, j, m, g;
    float x[9];

    // --- check that RDII UH object exists in database
    j = project_findObject(UNITHYD, tok[0]);
    if ( j < 0 ) return error_setInpError(ERR_NAME, tok[0]);
   
    // --- assign UH ID to name in hash table
    if ( UnitHyd[j].ID == NULL )
        UnitHyd[j].ID = project_findID(UNITHYD, tok[0]);

    // --- line has 2 tokens; assign rain gage to UH object
    if ( ntoks == 2 )
    {
        g = project_findObject(GAGE, tok[1]);
        if ( g < 0 ) return error_setInpError(ERR_NAME, tok[1]);
        UnitHyd[j].rainGage = g;
        return 0;
    }

    // --- line has 11 tokens; retrieve & save UH params.
    if ( ntoks == 11 )
    {
        // --- find which month UH params apply to
        m = datetime_findMonth(tok[1]);
        if ( m == 0 )
        {
            if ( !match(tok[1], w_ALL) )
                return error_setInpError(ERR_KEYWORD, tok[1]);
        }

        // --- read 3 sets of r-t-k values
        for ( i = 0; i < 9; i++ )
        {
            if ( ! getFloat(tok[i+2], &x[i]) )
                return error_setInpError(ERR_NUMBER, tok[i+2]);
        }

        // --- save UH params
        setUnitHydParams(j, m, x);
        return 0;
    }
    else return error_setInpError(ERR_ITEMS, "");
}
Пример #2
0
int datetime_strToDate(char* s, DateTime* d)

//  Input:   s = date as string
//  Output:  d = encoded date;
//           returns 1 if conversion successful, 0 if not
//  Purpose: converts string date s to DateTime value.
//
{
    int  yr = 0, mon = 0, day = 0, n;
    char month[4];
    char sep1, sep2;
    *d = -DateDelta;
    if (strchr(s, '-') || strchr(s, '/'))
    {
        switch (DateFormat)
        {
          case Y_M_D:
            n = sscanf(s, "%d%c%d%c%d", &yr, &sep1, &mon, &sep2, &day);
            if ( n < 3 )
            {
                mon = 0;
                n = sscanf(s, "%d%c%3s%c%d", &yr, &sep1, month, &sep2, &day);
                if ( n < 3 ) return 0;
            }
            break;

          case D_M_Y:
            n = sscanf(s, "%d%c%d%c%d", &day, &sep1, &mon, &sep2, &yr);
            if ( n < 3 )
            {
                mon = 0;
                n = sscanf(s, "%d%c%3s%c%d", &day, &sep1, month, &sep2, &yr);
                if ( n < 3 ) return 0;
            }
            break;

          default: // M_D_Y
            n = sscanf(s, "%d%c%d%c%d", &mon, &sep1, &day, &sep2, &yr);
            if ( n < 3 )
            {
                mon = 0;
                n = sscanf(s, "%3s%c%d%c%d", month, &sep1, &day, &sep2, &yr);
                if ( n < 3 ) return 0;
            }
        }
        if (mon == 0) mon = datetime_findMonth(month);
        *d = datetime_encodeDate(yr, mon, day);
    }
    if (*d == -DateDelta) return 0;
    else return 1;
}