void iface_saveOutletResults(DateTime reportDate, FILE* file)
//
//  Input:   reportDate = reporting date/time
//           file = ptr. to interface file
//  Output:  none
//  Purpose: saves system outflows to routing interface file.
//
{
    int i, p, yr, mon, day, hr, min, sec;
    //char theDate[25];                                                        //(5.0.010 - RD)
    datetime_decodeDate(reportDate, &yr, &mon, &day);
    datetime_decodeTime(reportDate, &hr, &min, &sec);
    //sprintf(theDate, " %04d %02d  %02d  %02d  %02d  %02d ",                  //(5.0.010 - RD)
    //        yr, mon, day, hr, min, sec);                                     //(5.0.010 - RD)
    for (i=0; i<Nobjects[NODE]; i++)
    {
        // --- check that node is an outlet node
        if ( !isOutletNode(i) ) continue;

        // --- write node ID, date, flow, and quality to file
        fprintf(file, "\n%-16s", Node[i].ID);
        //fprintf(file, "%s", theDate);                                       //(5.0.010 - RD) 
        fprintf(file, " %04d %02d  %02d  %02d  %02d  %02d ",                  //(5.0.010 - RD)
            yr, mon, day, hr, min, sec);                                      //(5.0.010 - RD)
        fprintf(file, " %-10f", Node[i].inflow * UCF(FLOW));
        for ( p = 0; p < Nobjects[POLLUT]; p++ )
        {
            fprintf(file, " %-10f", Node[i].newQual[p]);
        }
    }
}
示例#2
0
文件: datetime.c 项目: ezhangle/swmm
void datetime_dateToStr(DateTime date, char* s)

//  Input:   date = encoded date/time value
//  Output:  s = formatted date string
//  Purpose: represents DateTime date value as a formatted string.

{
    int  y, m, d;
    char dateStr[DATE_STR_SIZE];
    datetime_decodeDate(date, &y, &m, &d);
    switch (DateFormat)
    {
      case Y_M_D:
        sprintf(dateStr, "%4d-%3s-%02d", y, MonthTxt[m-1], d);
        break;

      case M_D_Y:
        sprintf(dateStr, "%3s-%02d-%4d", MonthTxt[m-1], d, y);
        break;

      default:
        sprintf(dateStr, "%02d-%3s-%4d", d, MonthTxt[m-1], y);
    }
    strcpy(s, dateStr);
}
示例#3
0
void setNextEvapDate(DateTime theDate)
//
//  Input:   theDate = current simulation date
//  Output:  sets a new value for NextEvapDate
//  Purpose: finds date for next change in evaporation after the current date.
//
{
    int    yr, mon, day, k;
    double d, e;

    // --- do nothing if current date hasn't reached the current next date
    if ( NextEvapDate > theDate ) return;

    switch ( Evap.type )
    {
      // --- for constant evaporation, use a next date far in the future
      case CONSTANT_EVAP:
         NextEvapDate = theDate + 365.;
         break;

      // --- for monthly evaporation, use the start of the next month
      case MONTHLY_EVAP:
        datetime_decodeDate(theDate, &yr, &mon, &day);
        if ( mon == 12 )
        {
            mon = 1;
            yr++;
        }
        else mon++;
        NextEvapDate = datetime_encodeDate(yr, mon, 1);
        break;

      // --- for time series evaporation, find the next entry in the
      //     series on or after the current date
      case TIMESERIES_EVAP:
        k = Evap.tSeries;
        if ( k >= 0 )
        {
            NextEvapDate = theDate + 365.;
            while ( table_getNextEntry(&Tseries[k], &d, &e) &&
                    d <= EndDateTime )
            {
                if ( d >= theDate )
                {
                    NextEvapDate = d;
                    NextEvapRate = e;
                    break;
                }
            }
        }
        break;

      // --- for climate file daily evaporation, use the next day
      case FILE_EVAP:
        NextEvapDate = floor(theDate) + 1.0;
        break;

      default: NextEvapDate = theDate + 365.;
    }
}
示例#4
0
文件: climate.c 项目: boinst/liquids
void setEvap(DateTime theDate)
//
//  Input:   theDate = simulation date
//  Output:  none
//  Purpose: sets evaporation rate (ft/sec) for a specified date.
//
{
    int yr, mon, day, k;

    switch ( Evap.type )
    {
      case CONSTANT_EVAP:
        Evap.rate = Evap.monthlyEvap[0] / UCF(EVAPRATE);
        break;

      case MONTHLY_EVAP:
        datetime_decodeDate(theDate, &yr, &mon, &day);
        Evap.rate = Evap.monthlyEvap[mon-1] / UCF(EVAPRATE);
        break;

      case TIMESERIES_EVAP:
        if ( theDate >= NextEvapDate )
            Evap.rate = NextEvapRate / UCF(EVAPRATE);
        break;

      case FILE_EVAP:
        Evap.rate = FileValue[EVAP] / UCF(EVAPRATE);
        datetime_decodeDate(theDate, &yr, &mon, &day);
        Evap.rate *= Evap.panCoeff[mon-1];
        break;

      case TEMPERATURE_EVAP:
        Evap.rate = FileValue[EVAP] / UCF(EVAPRATE);
        break;

      default: Evap.rate = 0.0;
    }

    // --- set soil recovery factor
    Evap.recoveryFactor = 1.0;
    k = Evap.recoveryPattern;
    if ( k >= 0 && Pattern[k].type == MONTHLY_PATTERN )
    {
        mon = datetime_monthOfYear(theDate) - 1;
        Evap.recoveryFactor = Pattern[k].factor[mon];
    }
}
示例#5
0
文件: datetime.c 项目: ezhangle/swmm
int  datetime_monthOfYear(DateTime date)

//  Input:   date = an encoded date/time value
//  Output:  returns index of month of year (1..12)
//  Purpose: finds month of year (Jan = 1 ...) for a given date.

{
    int year, month, day;
    datetime_decodeDate(date, &year, &month, &day);
    return month;
}
示例#6
0
文件: climate.c 项目: boinst/liquids
DateTime climate_getNextEvap(DateTime days)
//
//  Input:   days = current simulation date                                    //(5.0.019 - LR)
//  Output:  returns date (in whole days) when evaporation rate next changes
//  Purpose: finds date for next change in evaporation.
//
{
    int    yr, mon, day, k;
    double d, e;

    days = floor(days);                                                        //(5.0.019 - LR)
    switch ( Evap.type )
    {
      case CONSTANT_EVAP:
        return days + 365.;

      case MONTHLY_EVAP:
        datetime_decodeDate(days, &yr, &mon, &day);
        if ( mon == 12 )
        {
            mon = 1;
            yr++;
        }
        else mon++;
        return datetime_encodeDate(yr, mon, 1);

      case TIMESERIES_EVAP:

////  Following section modified for release 5.0.019  ////                     //(5.0.019 - LR)
        if ( NextEvapDate > days ) return NextEvapDate;
        k = Evap.tSeries;
        if ( k >= 0 )
        {    
            while ( table_getNextEntry(&Tseries[k], &d, &e) &&
                    d <= EndDateTime )
            {
                if ( d > days )
                {
                    NextEvapDate = d;
                    NextEvapRate = e;
                    return d;
                }
            }
        }
//////////////////////////////////////////////////////////
        return days + 365.;

      case FILE_EVAP:
        return days + 1.0;

      default: return days + 365.;
    }
}
示例#7
0
文件: datetime.c 项目: ezhangle/swmm
int  datetime_dayOfYear(DateTime date)

//  Input:   date = an encoded date/time value
//  Output:  returns day of year (1..365)
//  Purpose: finds day of year (Jan 1 = 1) for a given date.

{
    int year, month, day;
    DateTime startOfYear;
    datetime_decodeDate(date, &year, &month, &day);
    startOfYear = datetime_encodeDate(year, 1, 1);
    return (int)(floor(date - startOfYear)) + 1;
}
示例#8
0
void setEvap(DateTime theDate)
//
//  Input:   theDate = simulation date
//  Output:  none
//  Purpose: sets evaporation rate (ft/sec) for a specified date.
//
{
    int yr, mon, day, k;

    switch ( Evap.type )
    {
      case CONSTANT_EVAP:
        Evap.rate = Evap.monthlyEvap[0];
        break;

      case MONTHLY_EVAP:
        datetime_decodeDate(theDate, &yr, &mon, &day);
        Evap.rate = Evap.monthlyEvap[mon-1];
        break;

      case TIMESERIES_EVAP:
        k = Evap.tSeries;
        Evap.rate = table_tseriesLookup(&Tseries[k], theDate, TRUE);
        break;

      case FILE_EVAP:
        Evap.rate = FileValue[EVAP];
        datetime_decodeDate(theDate, &yr, &mon, &day);
        Evap.rate *= Evap.panCoeff[mon-1];
        break;

      default: Evap.rate = 0.0;
    }

    // --- convert rate from in/day (mm/day) to ft/sec
    Evap.rate /= UCF(EVAPRATE);
}
示例#9
0
DateTime climate_getNextEvap(DateTime days)
//
//  Input:   days = current simulation date (in whole days)
//  Output:  returns date (in whole days) when evaporation rate next changes
//  Purpose: finds date for next change in evaporation.
//
{
    int    yr, mon, day, k;
    double d, e;

    switch ( Evap.type )
    {
      case CONSTANT_EVAP:
        return days + 365.;

      case MONTHLY_EVAP:
        datetime_decodeDate(days, &yr, &mon, &day);
        if ( mon == 12 )
        {
            mon = 1;
            yr++;
        }
        else mon++;
        return datetime_encodeDate(yr, mon, 1);

      case TIMESERIES_EVAP:
        k = Evap.tSeries;
        while ( table_getNextEntry(&Tseries[k], &d, &e) )
        {
            if ( d > days ) return d;
        }
        return days + 365.;

      case FILE_EVAP:
        return days + 1.0;

      default: return days + 365.;
    }
}
示例#10
0
void setWind(DateTime theDate)
//
//  Input:   theDate = simulation date
//  Output:  none
//  Purpose: sets wind speed (mph) for a specified date.
//
{
    int yr, mon, day;

    switch ( Wind.type )
    {
      case MONTHLY_WIND:
        datetime_decodeDate(theDate, &yr, &mon, &day);
        Wind.ws = Wind.aws[mon-1] / UCF(WINDSPEED);
        break;

      case FILE_WIND:
        Wind.ws = FileValue[WIND];
        break;

      default: Wind.ws = 0.0;
    }
}
示例#11
0
void saveRdiiFlows(DateTime currentDate)
//
//  Input:   currentDate = current calendar date/time
//  Output:  none
//  Purpose: saves current set of RDII inflows in current flow units to file.
//
{
    int i, j, yr, mon, day, hr, min, sec;
    char theDate[25];

    // --- write year, month, day, hour, minute of current date to string
    datetime_decodeDate(currentDate, &yr, &mon, &day);
    datetime_decodeTime(currentDate, &hr, &min, &sec);
    sprintf(theDate, " %04d %02d  %02d  %02d  %02d  %02d ",
            yr, mon, day, hr, min, sec);
    
    // --- write RDII inflow at each RDII node to file
    for (i=0; i<NumRdiiNodes; i++)
    {
        j = RdiiNodeIndex[i];
        fprintf(Frdii.file, "\n%-16s %s %-10f", Node[j].ID, theDate,
            RdiiNodeFlow[i]*Qcf[FlowUnits]);
    }
}
示例#12
0
void climate_openFile()
//
//  Input:   none
//  Output:  none
//  Purpose: opens a climate file and reads in first set of values.
//
{
    int i, m, y;

    // --- open the file
    if ( (Fclimate.file = fopen(Fclimate.name, "rt")) == NULL )
    {
        report_writeErrorMsg(ERR_CLIMATE_FILE_OPEN, Fclimate.name);
        return;
    }

    // --- initialize values of file's climate variables
    //     (Temp.ta was previously initialized in project.c)
    FileValue[TMIN] = Temp.ta;
    FileValue[TMAX] = Temp.ta;
    FileValue[EVAP] = 0.0;
    FileValue[WIND] = 0.0;

    // --- find climate file's format
    FileFormat = getFileFormat();
    if ( FileFormat == UNKNOWN_FORMAT )
    {
        report_writeErrorMsg(ERR_CLIMATE_FILE_READ, Fclimate.name);
        return;
    }

    // --- position file to begin reading climate file at either user-specified
    //     month/year or at start of simulation period.
    rewind(Fclimate.file);
    strcpy(FileLine, "");
    if ( Temp.fileStartDate == NO_DATE )
        datetime_decodeDate(StartDate, &FileYear, &FileMonth, &FileDay); 
    else
        datetime_decodeDate(Temp.fileStartDate, &FileYear, &FileMonth, &FileDay);
    while ( !feof(Fclimate.file) )
    {
        strcpy(FileLine, "");
        readFileLine(&y, &m);
        if ( y == FileYear && m == FileMonth ) break;
    }
    if ( feof(Fclimate.file) )
    {
        report_writeErrorMsg(ERR_CLIMATE_END_OF_FILE, Fclimate.name);
        return;
    }
    
    // --- initialize file dates and current climate variable values 
    if ( !ErrorCode )
    {
        FileElapsedDays = 0;
        FileLastDay = datetime_daysPerMonth(FileYear, FileMonth);
        readFileValues();
        for (i=TMIN; i<=WIND; i++)
        {
            if ( FileData[i][FileDay] == MISSING ) continue;
            FileValue[i] = FileData[i][FileDay];
        }
    }
}
示例#13
0
int LandSimulation(int landfg,char* strInputFilePath,CProgressWnd* pwndProgress)
{
	CString ReportFilePath(strInputFilePath);
	ReportFilePath.TrimRight("inp");
	CString OutputFilePath = ReportFilePath;
	ReportFilePath += "rpt";
	OutputFilePath += "out";
	char* strReportFilePath = ReportFilePath.GetBuffer(ReportFilePath.GetLength());
	char* strOutputFilePath = OutputFilePath.GetBuffer(OutputFilePath.GetLength());
	
	// initialize progress bar
	pwndProgress->SetRange(0, 100);			 
	pwndProgress->SetText("");
	CString strMsg, strForDdg, strE;

	COleDateTime time_i;		// time at the beginning of the simulation
	COleDateTime time_f;		// time at the end of the simulation
	COleDateTimeSpan time_dif;	// simulation run time
	SYSTEMTIME tm;				// system time
	GetLocalTime(&tm);
	time_i = COleDateTime(tm);

	long newHour, oldHour = 0;
	DateTime elapsedTime = 0.0;

	// --- open the files & read input data
	ErrorCode = 0;
	swmm_open(strInputFilePath,strReportFilePath,strOutputFilePath);

	// --- run the simulation if input data OK
	if ( !ErrorCode )
	{
		// --- initialize values
		swmm_start(TRUE);

		// --- execute each time step until elapsed time is re-set to 0
		if ( !ErrorCode )
		{
			int y, m, d;
			datetime_decodeDate(StartDateTime, &y, &m, &d);
			COleDateTime tStart(y,m,d,0,0,0);
			datetime_decodeDate(EndDateTime, &y, &m, &d);
			COleDateTime tEnd(y,m,d,0,0,0);
			COleDateTimeSpan span0 = tEnd - tStart;

			do
			{
				swmm_step(&elapsedTime);
				newHour = elapsedTime * 24.0;

				COleDateTimeSpan span = COleDateTimeSpan(0,newHour,0,0);
				COleDateTime tCurrent = tStart + span;

				int nSYear = tCurrent.GetYear();
				int nSMonth = tCurrent.GetMonth();
				int nSDay = tCurrent.GetDay();
				int nSHour = tCurrent.GetHour();

				GetLocalTime(&tm);
				time_f = COleDateTime(tm);
				time_dif = time_f - time_i;

				int dd_elap = int(time_dif.GetDays());
				int hh_elap = int(time_dif.GetHours());
				int mm_elap = int(time_dif.GetMinutes());
				int ss_elap = int(time_dif.GetSeconds());

				if ( newHour > oldHour )
				{
					oldHour = newHour;

					if (landfg == 0)
						strMsg.Format("Land Simulation:\t Pre-Development Scenario\n");
					else
						strMsg.Format("Land Simulation:\t Post-Development Scenario\n");
					strForDdg = strMsg;

					strMsg.Format("Calculating:\t %02d-%02d-%04d\n", nSMonth, nSDay, nSYear);
					strForDdg += strMsg;
					
					strE.Format("\nTime Elapsed:\t %02d:%02d:%02d:%02d\n", dd_elap, hh_elap, mm_elap, ss_elap);
					strForDdg += strE;

					double lfPart = span.GetTotalSeconds();
					double lfAll  = span0.GetTotalSeconds();
					double lfPerc = lfPart/lfAll;

					if(pwndProgress->GetSafeHwnd() != NULL && nSHour == 0)
					{
						pwndProgress->SetText(strForDdg);
						pwndProgress->SetPos((int)(lfPerc*100));
						pwndProgress->PeekAndPump();
					}

					if (pwndProgress->Cancelled())
					{
						pwndProgress->DestroyWindow();
						AfxMessageBox("BMP simulation is cancelled");
						break;
					}
				}
			} while ( elapsedTime > 0.0 && !ErrorCode );
		}

		// --- clean up
		swmm_end();
	}

	// --- report results
	swmm_report();

	// --- close the system
	swmm_close();

	//return ErrorCode;
	return ErrorCode;
}