vic/drivers/shared_all/src/forcing_utils.c
size_t
count_force_vars(FILE *gp)
{
    size_t        nvars;
    unsigned long start_position;
    char          cmdstr[MAXSTRING];
    char          optstr[MAXSTRING];

    // Figure out where we are in the input file
    fflush(gp);
    start_position = ftell(gp);

    // read the first line
    fgets(cmdstr, MAXSTRING, gp);

    // initalize nvars
    nvars = 0;

    // Loop through the lines
    while (!feof(gp)) {
        if (cmdstr[0] != '#' && cmdstr[0] != '\n' && cmdstr[0] != '\0') {
            // line is not blank or a comment
            sscanf(cmdstr, "%s", optstr);

            // if the line starts with FORCE_TYPE
            if (strcasecmp("FORCE_TYPE", optstr) == 0) {
                nvars++;
            }
            // else if we arive at another forcing file break out of loop
            else if (strcasecmp("FORCING1", optstr) == 0 ||
                     strcasecmp("FORCING2", optstr) == 0) {
                break;
            }
        }
        fgets(cmdstr, MAXSTRING, gp);
    }

    // put the position in the file back to where we started
    fseek(gp, start_position, SEEK_SET);

    return nvars;
}
/******************************************************************************
 * @brief    This routine determines the counts the number of forcing variables
             in each forcing file specified in the global parameter file.
 *****************************************************************************/
@brief    This routine determines the counts the number of forcing variables
in each forcing file specified in the global parameter file.
@brief This routine determines the counts the number of forcing variables in each forcing file specified in the global parameter file .
size_t
count_force_vars(FILE *gp)
{
    size_t        nvars;
    unsigned long start_position;
    char          cmdstr[MAXSTRING];
    char          optstr[MAXSTRING];
    fflush(gp);
    start_position = ftell(gp);
    fgets(cmdstr, MAXSTRING, gp);
    nvars = 0;
    while (!feof(gp)) {
        if (cmdstr[0] != '#' && cmdstr[0] != '\n' && cmdstr[0] != '\0') {
            sscanf(cmdstr, "%s", optstr);
            if (strcasecmp("FORCE_TYPE", optstr) == 0) {
                nvars++;
            }
            else if (strcasecmp("FORCING1", optstr) == 0 ||
                     strcasecmp("FORCING2", optstr) == 0) {
                break;
            }
        }
        fgets(cmdstr, MAXSTRING, gp);
    }
    fseek(gp, start_position, SEEK_SET);
    return nvars;
}
size_t count_force_vars ( FILE * gp ) { size_t nvars ; unsigned long start_position ; char cmdstr [ MAXSTRING ] ; char optstr [ MAXSTRING ] ; fflush ( gp ) ; start_position = ftell ( gp ) ; fgets ( cmdstr , MAXSTRING , gp ) ; nvars = 0 ; while ( ! feof ( gp ) ) { if ( cmdstr [ 0 ] != ' ' && cmdstr [ 0 ] != ' \n ' && cmdstr [ 0 ] != ' \0 ' ) { sscanf ( cmdstr , " " , optstr ) ; if ( strcasecmp ( " " , optstr ) == 0 ) { nvars ++ ; } else if ( strcasecmp ( " " , optstr ) == 0 || strcasecmp ( " " , optstr ) == 0 ) { break ; } } fgets ( cmdstr , MAXSTRING , gp ) ; } fseek ( gp , start_position , SEEK_SET ) ; return nvars ; }
@brief    This routine determines the counts the number of forcing variables
in each forcing file specified in the global parameter file.
@brief This routine determines the counts the number of forcing variables in each forcing file specified in the global parameter file .
// Figure out where we are in the input file // read the first line // initalize nvars // Loop through the lines // line is not blank or a comment // if the line starts with FORCE_TYPE // else if we arive at another forcing file break out of loop // put the position in the file back to where we started