int runoff_open() // // Input: none // Output: returns the global error code // Purpose: opens the runoff analyzer. // { IsRaining = FALSE; HasRunoff = FALSE; HasSnow = FALSE; Nsteps = 0; // --- open the Ordinary Differential Equation solver // to solve up to 3 ode's. if ( !odesolve_open(3) ) report_writeErrorMsg(ERR_ODE_SOLVER, ""); // --- allocate memory for pollutant washoff loads WashoffQual = NULL; WashoffLoad = NULL; if ( Nobjects[POLLUT] > 0 ) { WashoffQual = (double *) calloc(Nobjects[POLLUT], sizeof(double)); if ( !WashoffQual ) report_writeErrorMsg(ERR_MEMORY, ""); WashoffLoad = (double *) calloc(Nobjects[POLLUT], sizeof(double)); if ( !WashoffLoad ) report_writeErrorMsg(ERR_MEMORY, ""); } // --- see if a runoff interface file should be opened switch ( Frunoff.mode ) { case USE_FILE: if ( (Frunoff.file = fopen(Frunoff.name, "r+b")) == NULL) report_writeErrorMsg(ERR_RUNOFF_FILE_OPEN, Frunoff.name); else runoff_initFile(); break; case SAVE_FILE: if ( (Frunoff.file = fopen(Frunoff.name, "w+b")) == NULL) report_writeErrorMsg(ERR_RUNOFF_FILE_OPEN, Frunoff.name); else runoff_initFile(); break; } // --- see if a climate file should be opened if ( Frunoff.mode != USE_FILE && Fclimate.mode == USE_FILE ) { climate_openFile(); } return ErrorCode; }
void climate_validate() // // Input: none // Output: none // Purpose: validates climatological variables // { int i; //(5.1.007) double a, z, pa; // --- check if climate data comes from external data file //(5.1.007) if ( Wind.type == FILE_WIND || Evap.type == FILE_EVAP || Evap.type == TEMPERATURE_EVAP ) { if ( Fclimate.mode == NO_FILE ) { report_writeErrorMsg(ERR_NO_CLIMATE_FILE, ""); } } // --- open the climate data file //(5.1.007) if ( Fclimate.mode == USE_FILE ) climate_openFile(); //(5.1.007) // --- snow melt parameters tipm & rnm must be fractions if ( Snow.tipm < 0.0 || Snow.tipm > 1.0 || Snow.rnm < 0.0 || Snow.rnm > 1.0 ) report_writeErrorMsg(ERR_SNOWMELT_PARAMS, ""); // --- latitude should be between -90 & 90 degrees a = Temp.anglat; if ( a <= -89.99 || a >= 89.99 ) report_writeErrorMsg(ERR_SNOWMELT_PARAMS, ""); else Temp.tanAnglat = tan(a * PI / 180.0); // --- compute psychrometric constant z = Temp.elev / 1000.0; if ( z <= 0.0 ) pa = 29.9; else pa = 29.9 - 1.02*z + 0.0032*pow(z, 2.4); // atmos. pressure Temp.gamma = 0.000359 * pa; // --- convert units of monthly temperature & evap adjustments //(5.1.007) for (i = 0; i < 12; i++) { if (UnitSystem == SI) Adjust.temp[i] *= 9.0/5.0; Adjust.evap[i] /= UCF(EVAPRATE); } }