Пример #1
0
//-----------------------------------------------------------------------------
int RunSwmmDll(char* inpFile, char* rptFile, char* outFile)
//-----------------------------------------------------------------------------
{
  int err;
  double elapsedTime;

  // --- open a SWMM project
  err = swmm_open(inpFile, rptFile, outFile);
  if (!err)
  {
    // --- initialize all processing systems
    err = swmm_start(1);
    if (err == 0)
    {
      // --- step through the simulation
      do
      {
        // --- allow Windows to process any pending events
        ProcessMessages();

        // --- extend the simulation by one routing time step
        err = swmm_step(&elapsedTime);

        /////////////////////////////////////////////
        // --- call progress reporting function here,
        //     using elapsedTime as an argument
        /////////////////////////////////////////////

      } while (elapsedTime > 0.0 && err == 0);

      // --- close all processing systems
      swmm_end();
    }
  }

  // --- close the project
  swmm_close();
  return err;
}
Пример #2
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;
}