/******************************************************************************* Function name: InitMM5() Purpose : Read the MM5 information the options file. This information is in the [METEOROLOGY] section Required : LISTPTR Input - Linked list with input options int NSoilLayers - Number of soil layers TIMESTRUCT *Time - Time information INPUTFILES *InFiles - Filenames for various input files Returns : void Modifies : Members of Time and InFiles Comments : *****************************************************************************/ void InitMM5(LISTPTR Input, int NSoilLayers, TIMESTRUCT * Time, INPUTFILES * InFiles, OPTIONSTRUCT * Options, MAPSIZE * MM5Map, MAPSIZE * Map) { DATE Start; char *Routine = "InitMM5"; char KeyName[BUFSIZE + 1]; char VarStr[BUFSIZE + 1]; int i; STRINIENTRY StrEnv[] = { {"METEOROLOGY", "MM5 START", "", ""}, {"METEOROLOGY", "MM5 TEMPERATURE FILE", "", ""}, {"METEOROLOGY", "MM5 HUMIDITY FILE", "", ""}, {"METEOROLOGY", "MM5 WIND SPEED FILE", "", ""}, {"METEOROLOGY", "MM5 SHORTWAVE FILE", "", ""}, {"METEOROLOGY", "MM5 LONGWAVE FILE", "", ""}, {"METEOROLOGY", "MM5 PRECIPITATION FILE", "", ""}, {"METEOROLOGY", "MM5 TERRAIN FILE", "", ""}, {"METEOROLOGY", "MM5 TEMP LAPSE FILE", "", ""}, {"METEOROLOGY", "MM5 ROWS", "", ""}, {"METEOROLOGY", "MM5 COLS", "", ""}, {"METEOROLOGY", "MM5 EXTREME NORTH", "", ""}, {"METEOROLOGY", "MM5 EXTREME WEST", "", ""}, {"METEOROLOGY", "MM5 DY", "", ""}, {NULL, NULL, "", NULL}, }; /* Read the key-entry pairs from the input file */ for (i = 0; StrEnv[i].SectionName; i++) GetInitString(StrEnv[i].SectionName, StrEnv[i].KeyName, StrEnv[i].Default, StrEnv[i].VarStr, (unsigned long) BUFSIZE, Input); /* Assign the entries to the variables */ if (!SScanDate(StrEnv[MM5_start].VarStr, &Start)) ReportError(StrEnv[MM5_start].KeyName, 51); InitTime(Time, NULL, NULL, NULL, &Start, Time->Dt); if (IsEmptyStr(StrEnv[MM5_temperature].VarStr)) ReportError(StrEnv[MM5_temperature].KeyName, 51); strcpy(InFiles->MM5Temp, StrEnv[MM5_temperature].VarStr); if (IsEmptyStr(StrEnv[MM5_terrain].VarStr)) ReportError(StrEnv[MM5_terrain].KeyName, 51); strcpy(InFiles->MM5Terrain, StrEnv[MM5_terrain].VarStr); if (IsEmptyStr(StrEnv[MM5_lapse].VarStr)) ReportError(StrEnv[MM5_lapse].KeyName, 51); strcpy(InFiles->MM5Lapse, StrEnv[MM5_lapse].VarStr); if (IsEmptyStr(StrEnv[MM5_humidity].VarStr)) ReportError(StrEnv[MM5_humidity].KeyName, 51); strcpy(InFiles->MM5Humidity, StrEnv[MM5_humidity].VarStr); if (IsEmptyStr(StrEnv[MM5_wind].VarStr)) ReportError(StrEnv[MM5_wind].KeyName, 51); strcpy(InFiles->MM5Wind, StrEnv[MM5_wind].VarStr); if (IsEmptyStr(StrEnv[MM5_shortwave].VarStr)) ReportError(StrEnv[MM5_shortwave].KeyName, 51); strcpy(InFiles->MM5ShortWave, StrEnv[MM5_shortwave].VarStr); if (IsEmptyStr(StrEnv[MM5_longwave].VarStr)) ReportError(StrEnv[MM5_longwave].KeyName, 51); strcpy(InFiles->MM5LongWave, StrEnv[MM5_longwave].VarStr); if (IsEmptyStr(StrEnv[MM5_precip].VarStr)) ReportError(StrEnv[MM5_precip].KeyName, 51); strcpy(InFiles->MM5Precipitation, StrEnv[MM5_precip].VarStr); if (Options->HeatFlux == TRUE) { if (!(InFiles->MM5SoilTemp = (char **) calloc(sizeof(char *), NSoilLayers))) ReportError(Routine, 1); for (i = 0; i < NSoilLayers; i++) { if (! (InFiles->MM5SoilTemp[i] = (char *) calloc(sizeof(char), BUFSIZE + 1))) ReportError(Routine, 1); sprintf(KeyName, "MM5 SOIL TEMPERATURE FILE %d", i); GetInitString("METEOROLOGY", KeyName, "", VarStr, (unsigned long) BUFSIZE, Input); if (IsEmptyStr(VarStr)) ReportError(KeyName, 51); strcpy(InFiles->MM5SoilTemp[i], VarStr); } } if (!CopyDouble(&(MM5Map->Yorig), StrEnv[MM5_ext_north].VarStr, 1)) ReportError(StrEnv[MM5_ext_north].KeyName, 51); if (!CopyDouble(&(MM5Map->Xorig), StrEnv[MM5_ext_west].VarStr, 1)) ReportError(StrEnv[MM5_ext_west].KeyName, 51); if (!CopyInt(&(MM5Map->NY), StrEnv[MM5_rows].VarStr, 1)) ReportError(StrEnv[MM5_rows].KeyName, 51); if (!CopyInt(&(MM5Map->NX), StrEnv[MM5_cols].VarStr, 1)) ReportError(StrEnv[MM5_cols].KeyName, 51); if (!CopyFloat(&(MM5Map->DY), StrEnv[MM5_dy].VarStr, 1)) ReportError(StrEnv[MM5_dy].KeyName, 51); MM5Map->OffsetX = Round(((float) (MM5Map->Xorig - Map->Xorig)) / ((float) Map->DX)); MM5Map->OffsetY = Round(((float) (MM5Map->Yorig - Map->Yorig)) / ((float) Map->DY)); if (MM5Map->OffsetX > 0 || MM5Map->OffsetY < 0) ReportError("Input Options File", 31); printf("MM5 extreme north / south is %f %f \n", MM5Map->Yorig, MM5Map->Yorig - MM5Map->NY * MM5Map->DY); printf("MM5 extreme west / east is %f %f\n", MM5Map->Xorig, MM5Map->Xorig + MM5Map->NX * MM5Map->DY); printf("MM5 rows is %d \n", MM5Map->NY); printf("MM5 cols is %d \n", MM5Map->NX); printf("MM5 dy is %f \n", MM5Map->DY); printf("Temperature Map is %s\n", InFiles->MM5Temp); printf("Precip Map is %s\n", InFiles->MM5Precipitation); printf("wind Map is %s\n", InFiles->MM5Wind); printf("shortwave Map is %s\n", InFiles->MM5ShortWave); printf("humidity Map is %s\n", InFiles->MM5Humidity); printf("lapse Map is %s\n", InFiles->MM5Lapse); printf("terrain Map is %s\n", InFiles->MM5Terrain); printf("MM5 offset x is %d \n", MM5Map->OffsetX); printf("MM5 offset y is %d \n", MM5Map->OffsetY); printf("dhsvm extreme north / south is %f %f \n", Map->Yorig, Map->Yorig - Map->NY * Map->DY); printf("dhsvm extreme west / east is %f %f \n", Map->Xorig, Map->Xorig + Map->NX * Map->DY); printf("fail if %d > %d\n", (int) ((Map->NY + MM5Map->OffsetY) * Map->DY / MM5Map->DY), MM5Map->NY); printf("fail if %d > %d\n", (int) ((Map->NX - MM5Map->OffsetX) * Map->DX / MM5Map->DY), MM5Map->NX); if ((int) ((Map->NY + MM5Map->OffsetY) * Map->DY / MM5Map->DY) > MM5Map->NY || (int) ((Map->NX - MM5Map->OffsetX) * Map->DX / MM5Map->DY) > MM5Map->NX) ReportError("Input Options File", 31); }
void CCellView::ResizeCol(BPoint where, int colNr) { float x, minX, maxRow; BPoint newP, lastP; BRect bounds(Bounds()), r, b; ulong buttons, cnt; bool multi; int mCol = colNr; CRunArray backup(fCellWidths); StPenState save(this); ClearAnts(); cnt = fSelection.right - fSelection.left + 1; while (fCellWidths[colNr + 1] == fCellWidths[colNr]) colNr++; multi = fSelection.left != fSelection.right && colNr >= fSelection.left && colNr <= fSelection.right; if (colNr <= fFrozen.h) { x = fBorderWidth + fCellWidths[colNr]; minX = fBorderWidth + fCellWidths[multi?fSelection.left - 1 : colNr - 1]; } else { x = fBorderWidth + fCellWidths[colNr] + fCellWidths[fFrozen.h] - fCellWidths[fPosition.h - 1]; minX = fBorderWidth + fCellWidths[fFrozen.h] - fCellWidths[fPosition.h - 1] + fCellWidths[multi?fSelection.left - 1 : colNr - 1]; } r.top = 1; r.bottom = fBorderHeight - 1; r.left = minX + 1; if (multi) r.right = minX + fCellWidths[fSelection.right] - fCellWidths[fSelection.left - 1] - 1; else r.right = minX + fCellWidths[colNr] - fCellWidths[colNr - 1] - 1; b = bounds; b.left = r.right; maxRow = fPosition.v; while (fCellHeights[++maxRow] - fCellHeights[fPosition.v] < bounds.bottom - fBorderHeight) ; lastP = where; newP = where; do { if (newP.x != lastP.x) { float dx; int k = colNr; dx = newP.x - lastP.x; if (lastP.x + dx < bounds.left + fBorderWidth) dx = std::min(lastP.x - bounds.left - fBorderWidth, (float)0); if (lastP.x + dx > bounds.right) dx = std::max(bounds.right - lastP.x, (float)0); if (multi && x + dx < minX) dx = minX - x; if (multi) { float w, t; w = x + dx - minX; if (w > 0) w = Round(w / (colNr - fSelection.left + 1)); t = fCellWidths[fSelection.right]; fCellWidths.SetValue(fSelection.left, fSelection.right, w); dx = fCellWidths[fSelection.right] - t; } else if (x + dx < minX) { int t = k; fCellWidths.SetValue(colNr, 0); while (k > 1 && backup[k - 1] + fBorderWidth >= x + dx) k--; ASSERT(k<colNr); if (k <= mCol) while (mCol > k) fCellWidths.SetValue(mCol--, 0); else { t = mCol; for (;mCol<k;mCol++) fCellWidths.SetValue(mCol, backup[mCol] - backup[mCol - 1]); } float kw = x + dx - fBorderWidth; kw -= backup[k - 1]; fCellWidths.SetValue(k, std::max(kw, (float)0)); mCol = k; k = t; } else { k = mCol; for (; mCol < colNr; mCol++) fCellWidths.SetValue(mCol, backup[mCol] - backup[mCol - 1]); fCellWidths.SetValue(colNr, x + dx - minX); } if (dx != 0) { x += dx; lastP.x += dx; if (dx < 0) b.left += dx; StPenState save(this); StClipCells clip(this); ScrollRect(b, dx, 0); Window()->UpdateIfNeeded(); if (dx > 0) b.left += dx; if (multi) { int h = fSelection.left, v; do { for (v = 1; v < fFrozen.v; v++) DrawCell(cell(h, v)); for (v = fPosition.v; v < maxRow; v++) DrawCell(cell(h, v)); DrawBorderCell(h++, true); } while (h <= fSelection.right && bounds.left + fCellWidths[h] + fBorderWidth < bounds.right); } else { int v; for (v = 1; v < fFrozen.v; v++) DrawCell(cell(mCol, v)); for (v = fPosition.v; v < maxRow; v++) DrawCell(cell(mCol, v)); DrawBorderCell(mCol, true); } for (; k < colNr; k++) { int v; for (v = 1; v < fFrozen.v; v++) DrawCell(cell(k, v)); for (v = fPosition.v; v < maxRow; v++) DrawCell(cell(k, v)); DrawBorderCell(k, true); } } if (dx < 0) { float X; int h; X = bounds.right + dx - fBorderWidth; h = fSelection.right; do h++; while (fCellWidths[h] < X); while (h <= kColCount && bounds.left + fCellWidths[h] + fBorderWidth < bounds.right) { int v; for (v = 1; v < fFrozen.v; v++) DrawCell(cell(h, v)); for (v = fPosition.v; v < maxRow; v++) DrawCell(cell(h, v)); DrawBorderCell(h++, true); } } if (dx && fFirstGraphic) fFirstGraphic->HandleUpdate(bounds); } GetMouse(&newP, &buttons); } while (buttons); if (!(backup == fCellWidths)) { CRunArray temp(fCellWidths); fCellWidths = backup; ((CCellWindow*)Window())->RegisterCommand(new CResizeCommand(this, temp, false)); ((CCellWindow*)Window())->SetDirty(true); } } /* ResizeCol */
void UIWidgetFrame::InitializeFromDefinition( const SimpleString& DefinitionName ) { UIWidget::InitializeFromDefinition( DefinitionName ); MAKEHASH( DefinitionName ); MAKEHASH( m_Archetype ); STATICHASH( DisplayWidth ); const float DisplayWidth = ConfigManager::GetFloat( sDisplayWidth ); const float ParentWidth = m_OriginParent ? m_OriginParent->GetWidth() : DisplayWidth; const float ParentX = m_OriginParent ? Ceiling( m_OriginParent->GetX() ) : 0.0f; STATICHASH( DisplayHeight ); const float DisplayHeight = ConfigManager::GetFloat( sDisplayHeight ); const float ParentHeight = m_OriginParent ? m_OriginParent->GetHeight() : DisplayHeight; const float ParentY = m_OriginParent ? Ceiling( m_OriginParent->GetY() ) : 0.0f; // "Screen" values are now relative to parent, which may or may not be screen dimensions. STATICHASH( PixelX ); STATICHASH( ScreenX ); float X = Pick( ConfigManager::GetArchetypeFloat( sPixelX, sm_Archetype, 0.0f, sDefinitionName ), ParentWidth * ConfigManager::GetArchetypeFloat( sScreenX, sm_Archetype, 0.0f, sDefinitionName ) ); STATICHASH( PixelY ); STATICHASH( ScreenY ); float Y = Pick( ConfigManager::GetArchetypeFloat( sPixelY, sm_Archetype, 0.0f, sDefinitionName ), ParentHeight * ConfigManager::GetArchetypeFloat( sScreenY, sm_Archetype, 0.0f, sDefinitionName ) ); STATICHASH( PixelWidth ); STATICHASH( ScreenWidth ); float Width = Pick( ConfigManager::GetArchetypeFloat( sPixelWidth, sm_Archetype, 0.0f, sDefinitionName ), ParentWidth * ConfigManager::GetArchetypeFloat( sScreenWidth, sm_Archetype, 0.0f, sDefinitionName ) ); STATICHASH( PixelHeight ); STATICHASH( ScreenHeight ); float Height = Pick( ConfigManager::GetArchetypeFloat( sPixelHeight, sm_Archetype, 0.0f, sDefinitionName ), ParentHeight * ConfigManager::GetArchetypeFloat( sScreenHeight, sm_Archetype, 0.0f, sDefinitionName ) ); STATICHASH( PixelBorder ); m_Border = ConfigManager::GetArchetypeFloat( sPixelBorder, sm_Archetype, 0.0f, sDefinitionName ); // Adjust for desired aspect ratio if one dimension is not given // (This is used to size images using ScreenWidth or ScreenHeight // properly regardless of screen aspect ratio. STATICHASH( AspectRatio ); const float AspectRatio = ConfigManager::GetArchetypeFloat( sAspectRatio, sm_Archetype, 1.0f, sDefinitionName ); if( Width == 0.0f ) { Width = Height * AspectRatio; } else if( Height == 0.0f ) { Height = Width / AspectRatio; } AdjustDimensionsToParent( X, Y, Width, Height, ParentX, ParentY, ParentWidth, ParentHeight ); GetPositionFromOrigin( X, Y, Width, Height ); ASSERT( Width > m_Border * 2.0f ); ASSERT( Height > m_Border * 2.0f ); STATICHASH( ClampToPixelGrid ); if( ConfigManager::GetArchetypeBool( sClampToPixelGrid, sm_Archetype, true, sDefinitionName ) ) { m_TopLeft.x = Round( m_TopLeft.x ); m_TopLeft.y = Round( m_TopLeft.y ); } // Offset to properly align on pixel grid. const float PixelGridOffset = GetPixelGridOffset(); m_TopLeft.x -= PixelGridOffset; m_TopLeft.y -= PixelGridOffset; STATICHASH( Image ); const char* const Filename = ConfigManager::GetArchetypeString( sImage, sm_Archetype, DEFAULT_TEXTURE, sDefinitionName ); m_Texture = m_UIManager->GetRenderer()->GetTextureManager()->GetTexture( Filename, TextureManager::ETL_Permanent ); m_Dimensions = Vector2( Width, Height ); STATICHASH( MaterialOverride ); const SimpleString DefaultMaterial( "Material_HUD" ); m_Material = ConfigManager::GetArchetypeString( sMaterialOverride, sm_Archetype, DefaultMaterial.CStr(), sDefinitionName ); UpdateRender(); }
void PrintPath(HDesign& design, HCriticalPath path, int pathNumber) { //columns numbers int sigDirections = design.cfg.ValueOf("Timing.SignalDirectionsUsed", 2); int ColAAT = 0; int ColRAT = ColAAT + 1; int ColGate = ColRAT + 1; int ColRC = ColGate + 1; int ColPhase = sigDirections == 2 ? ColRC + 1 : -1; int ColCap = ColRC + sigDirections; int ColFanout = ColCap + 1; int ColArcName = ColFanout + 1; int ColCellName = ColArcName + 1; int ColSep1 = ColCellName + 1; int ColNetName = ColSep1 + 1; int NCols = ColNetName + 1; //create header TableFormatter tf(NCols); //columns tf.SetColumnAlign(ColArcName, TableFormatter::Align_Left); tf.SetColumnAlign(ColCellName, TableFormatter::Align_Left); tf.SetColumnAlign(ColSep1, TableFormatter::Align_Fill); tf.SetColumnAlign(ColNetName, TableFormatter::Align_Left); //first header row tf.NewHeaderRow(); tf.SetCell(ColGate, "Delay[ps]", 2, TableFormatter::Align_Left); tf.SetCell(ColCap, "Cap", TableFormatter::Align_Left); tf.SetCell(ColFanout, "Fan-", TableFormatter::Align_Left); //second header row tf.NewHeaderRow(); tf.SetCell(ColAAT, "AAT", TableFormatter::Align_Left); tf.SetCell(ColRAT, "RAT", TableFormatter::Align_Left); tf.SetCell(ColGate, "Gate", TableFormatter::Align_Left); tf.SetCell(ColRC, "RC", TableFormatter::Align_Left); tf.SetCell(ColCap, "(fF)", TableFormatter::Align_Left); tf.SetCell(ColFanout, "out", TableFormatter::Align_Left); tf.SetCell(ColArcName, "Info", TableFormatter::Align_Left, 1000); //separator tf.NewBorderRow(); tf.SetCell(ColAAT, "-", TableFormatter::Align_Fill); tf.SetCell(ColRAT, "-", TableFormatter::Align_Fill); tf.SetCell(ColGate, "-", TableFormatter::Align_Fill); tf.SetCell(ColRC, "-", TableFormatter::Align_Fill); tf.SetCell(ColCap, "-", TableFormatter::Align_Fill); tf.SetCell(ColFanout, "-", TableFormatter::Align_Fill); tf.SetCell(ColPhase, "-", TableFormatter::Align_Fill); tf.SetCell(ColArcName, "-", TableFormatter::Align_Fill); //print arc (cell + net pairs) HCriticalPath::PointsEnumeratorW cpoint = (path,design).GetEnumeratorW(); HCriticalPathPointWrapper previousSink = design.CriticalPathPoints.NullW(); while (cpoint.MoveNext()) { HCriticalPathPointWrapper driver = cpoint; if (!cpoint.MoveNext()) break;//wtf? HPinWrapper driverPin = design[(driver.TimingPoint(),design).Pin()]; HSteinerPointWrapper stPointDriver = design[design.SteinerPoints[driverPin]]; HSteinerPointWrapper stPointSink = design[design.SteinerPoints[(cpoint.TimingPoint(),design).Pin()]]; HNetWrapper net = design[driverPin.Net()]; tf.NewRow(); tf.SetCell(ColFanout, net.SinksCount()); tf.SetCell(ColSep1, '-'); tf.SetCell(ColNetName, net.Name()); tf.SetCell(ColCellName, driverPin.IsPrimaryInput() ? driverPin.Name() : (driverPin.Cell(),design).Name()); if (driver.SignalDirection() == SignalDirection_Rise) { tf.SetCell(ColAAT, PikoSec(design[cpoint.TimingPoint()].RiseArrivalTime())); tf.SetCell(ColRAT, PikoSec(design[cpoint.TimingPoint()].RiseRequiredTime())); tf.SetCell(ColPhase, 'R'); tf.SetCell(ColRC, PikoSec(stPointSink.RisePathDelay())); tf.SetCell(ColCap, Round(1000.0 * stPointDriver.RiseObservedC())); } else if (driver.SignalDirection() == SignalDirection_Fall) { tf.SetCell(ColAAT, PikoSec(design[cpoint.TimingPoint()].FallArrivalTime())); tf.SetCell(ColRAT, PikoSec(design[cpoint.TimingPoint()].FallRequiredTime())); tf.SetCell(ColPhase, 'F'); tf.SetCell(ColRC, PikoSec(stPointSink.FallPathDelay())); tf.SetCell(ColCap, Round(1000.0 * stPointDriver.FallObservedC())); } else if (driver.SignalDirection() == SignalDirection_None) { tf.SetCell(ColAAT, PikoSec(design[cpoint.TimingPoint()].ArrivalTime())); tf.SetCell(ColRAT, PikoSec(design[cpoint.TimingPoint()].RequiredTime())); tf.SetCell(ColRC, PikoSec(stPointSink.PathDelay())); tf.SetCell(ColCap, Round(1000.0 * stPointDriver.ObservedC())); } else { LOGERROR("Unsupported signal direction."); } double arcTime; bool inversed; HTimingArcType arc = design.TimingArcTypes.Null(); if(design[path].ExtractionType() == PathExtractionType_Arrival || ::IsNull(previousSink)) arc = FindArrivalArc(design, driver.TimingPoint(), driver.SignalDirection(), arcTime, inversed); else if(design[path].ExtractionType() == PathExtractionType_Required) arc = FindRequiredArc(design, previousSink.TimingPoint(), previousSink.SignalDirection(), arcTime, inversed); tf.SetCell(ColGate, PikoSec(arcTime)); tf.SetCell(ColArcName, FormatArcName(design, driverPin, arc)); previousSink = cpoint; } //check for setup arc HPin finalPin = design.Get<HTimingPoint::Pin, HPin>(previousSink.TimingPoint()); for (HPinType::ArcsEnumeratorW arc = design.Get<HPinType::ArcTypesEnumerator, HPinType::ArcsEnumeratorW>( design.Get<HPin::Type, HPinType>(finalPin)); arc.MoveNext(); ) { if (arc.TimingType() == TimingType_SetupRising || arc.TimingType() == TimingType_SetupFalling) { tf.NewRow(); if (previousSink.SignalDirection() == SignalDirection_Fall) tf.SetCell(ColGate, PikoSec(arc.TIntrinsicFall())); else if (previousSink.SignalDirection() == SignalDirection_Rise || previousSink.SignalDirection() == SignalDirection_None) tf.SetCell(ColGate, PikoSec(arc.TIntrinsicRise())); else { LOGERROR("Unsupported signal direction."); } tf.SetCell(ColArcName, FormatArcName(design, finalPin, arc)); tf.SetCell(ColCellName, design[design[finalPin].Cell()].Name()); break; } } //separator tf.NewRow(); tf.SetCell(ColAAT, "-", TableFormatter::Align_Fill); tf.SetCell(ColRAT, "-", TableFormatter::Align_Fill); tf.SetCell(ColGate, "-", TableFormatter::Align_Fill); tf.SetCell(ColArcName, "-", TableFormatter::Align_Fill); //slack tf.NewRow(); tf.SetCell(ColAAT, PikoSec(design[path].Criticality())); tf.SetCell(ColArcName, "(slack)", 10); //printing Logger::Global.WriteIgnoringHTML("================================================================================"); WRITELINE(""); HPinWrapper firstPin = design[design[design[design[path].StartPoint()].TimingPoint()].Pin()]; HPinWrapper lastPin = design[design[design[design[path].EndPoint()].TimingPoint()].Pin()]; HCellWrapper firstCell = design[firstPin.Cell()]; HCellWrapper lastCell = design[lastPin.Cell()]; tf.Caption = Aux::Format("Path #%d %10s %s %s %8s %s %s", pathNumber, "From ", firstPin.IsPrimary() ? "PIN" : firstCell.Name().c_str(), firstPin.Name().c_str(), "To ", lastPin.IsPrimary() ? "PIN" : lastCell.Name().c_str(), lastPin.Name().c_str()); WRITELINE(""); tf.Print(); WRITELINE(""); WRITELINE(""); }
unsigned short CDlgCreateVacuumPatch::GetTurnDiameter() { return (unsigned short)Round(m_edtTurnDiameter * cTPI); }
void CDlgCreateVacuumPatch::DrawVacuumPatch() { if (m_VacuumPath != NULL) { CDC* pDC = GetDC(); CBrush ArrowBrush(COLORREF(0)); // CBrush BorderBrush(COLORREF(0x0)); /*Draw stuff*/ RECT OuterRect; robPOINT RobotPoint; POINT point; CRect ProbGridBmpUpdateRect; m_staVacuumPatchBounds.GetWindowRect(&ProbGridBmpUpdateRect); ScreenToClient(&ProbGridBmpUpdateRect); // CPoint SurfaceOffset = ProbGridBmpUpdateRect.TopLeft(); CRect SurfaceOffset = ProbGridBmpUpdateRect; RobotPoint.x = m_Bounds.left, RobotPoint.y = m_Bounds.top; point = RobotToDDSurface(RobotPoint, SurfaceOffset); OuterRect.left = point.x; OuterRect.top = point.y; RobotPoint.x = m_Bounds.right, RobotPoint.y = m_Bounds.bottom; point = RobotToDDSurface(RobotPoint, SurfaceOffset); OuterRect.right = point.x; OuterRect.bottom = point.y; // pDC->FrameRect(&OuterRect, &BorderBrush); unsigned short i = 0; double HeadForward = m_HeadForward; while (i < m_NumberPaths) { short CosFor = (short)Round(cos(HeadForward)); short SinFor = (short)Round(sin(HeadForward)); short CosNext = (short)Round(cos(m_HeadNext)); short SinNext = (short)Round(sin(m_HeadNext)); /*Draw line*/ POINT BmpPoint[4]; if (i != 0) { BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i - 1].Arc2e, SurfaceOffset); } else { BmpPoint[0] = RobotToDDSurface(m_EntryPoint, SurfaceOffset); } pDC->MoveTo(BmpPoint[0]); BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i].Arc1s, SurfaceOffset); pDC->LineTo(BmpPoint[0]); /*Draw arrow head*/ double x1, y1, x2, y2; x1 = m_VacuumPath[i].Arc1s.x - 30 * CosFor; y1 = m_VacuumPath[i].Arc1s.y - 30 * SinFor; RobotPoint.x = x1, RobotPoint.y = y1; BmpPoint[0] = RobotToDDSurface(RobotPoint, SurfaceOffset); x2 = x1 - CosFor * 30 - CosNext * 30; y2 = y1 - SinFor * 30 - SinNext * 30; RobotPoint.x = x2, RobotPoint.y = y2; BmpPoint[1] = RobotToDDSurface(RobotPoint, SurfaceOffset); x2 = x1 - CosFor * 30 + CosNext * 30; y2 = y1 - SinFor * 30 + SinNext * 30; RobotPoint.x = x2, RobotPoint.y = y2; BmpPoint[2] = RobotToDDSurface(RobotPoint, SurfaceOffset); BmpPoint[3] = BmpPoint[0]; CRgn ArrowRegion; ArrowRegion.CreatePolygonRgn(BmpPoint, 4, ALTERNATE); pDC->FillRgn(&ArrowRegion, &ArrowBrush); /*If next vacuum path inside the patch, draw an arc to it*/ if (i < m_NumberPaths - 1) { /*Draw 2 arcs*/ /*Arc 1*/ CRect ArcRect; short TurnDiameter = ABS(m_VacuumPath[i].TurnDiameter); x1 = m_VacuumPath[i].Arc1s.x + CosFor * TurnDiameter / 2; y1 = m_VacuumPath[i].Arc1s.y + SinFor * TurnDiameter / 2; x2 = m_VacuumPath[i].Arc1s.x - CosFor * TurnDiameter / 2 + CosNext * TurnDiameter; y2 = m_VacuumPath[i].Arc1s.y - SinFor * TurnDiameter / 2 + SinNext * TurnDiameter; RobotPoint.x = x1, RobotPoint.y = y1; point = RobotToDDSurface(RobotPoint, SurfaceOffset); ArcRect.left = point.x, ArcRect.top = point.y; RobotPoint.x = x2, RobotPoint.y = y2; point = RobotToDDSurface(RobotPoint, SurfaceOffset); ArcRect.right = point.x, ArcRect.bottom = point.y; ArcRect.NormalizeRect(); if ((SinFor * CosNext == 1) || (CosFor * SinNext == -1)) { BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i].Arc1e, SurfaceOffset); BmpPoint[1] = RobotToDDSurface(m_VacuumPath[i].Arc1s, SurfaceOffset); } else { BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i].Arc1s, SurfaceOffset); BmpPoint[1] = RobotToDDSurface(m_VacuumPath[i].Arc1e, SurfaceOffset); } pDC->Arc(ArcRect, BmpPoint[0], BmpPoint[1]); /*Arc 2*/ x1 = m_VacuumPath[i].Arc2c.x + m_VacuumPath[i].Arc2r; y1 = m_VacuumPath[i].Arc2c.y + m_VacuumPath[i].Arc2r; RobotPoint.x = x1, RobotPoint.y = y1; point = RobotToDDSurface(RobotPoint, SurfaceOffset); ArcRect.left = point.x, ArcRect.top = point.y; x1 = m_VacuumPath[i].Arc2c.x - m_VacuumPath[i].Arc2r; y1 = m_VacuumPath[i].Arc2c.y - m_VacuumPath[i].Arc2r; RobotPoint.x = x1, RobotPoint.y = y1; point = RobotToDDSurface(RobotPoint, SurfaceOffset); ArcRect.right = point.x, ArcRect.bottom = point.y; ArcRect.NormalizeRect(); if ((SinFor * CosNext == 1) || (CosFor * SinNext == -1)) { BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i].Arc2s, SurfaceOffset); BmpPoint[1] = RobotToDDSurface(m_VacuumPath[i].Arc2e, SurfaceOffset); } else { BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i].Arc2e, SurfaceOffset); BmpPoint[1] = RobotToDDSurface(m_VacuumPath[i].Arc2s, SurfaceOffset); } pDC->Arc(ArcRect, BmpPoint[0], BmpPoint[1]); } /*Onto next patch*/ HeadForward += pi; i++; } // BorderBrush.DeleteObject(); // ArrowBrush.DeleteObject(); } }
static void Round4(unsigned int *a, unsigned int b, unsigned int c, unsigned int d, unsigned int k, unsigned int s, unsigned int i) { *a = Round(*a, b, I(b, c, d), k, s, i); }
static block_t * DoWork( filter_t * p_filter, block_t * p_in_buf ) { int i_samples = p_in_buf->i_nb_samples; int i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio ); float *pf_buf = (float*)p_in_buf->p_buffer; /* Current parameters */ filter_sys_t *p_sys = p_filter->p_sys; /* Fetch the configurable parameters */ vlc_mutex_lock( &p_sys->lock ); float f_rms_peak = p_sys->f_rms_peak; /* RMS/peak */ float f_attack = p_sys->f_attack; /* Attack time (ms) */ float f_release = p_sys->f_release; /* Release time (ms) */ float f_threshold = p_sys->f_threshold; /* Threshold level (dB) */ float f_ratio = p_sys->f_ratio; /* Ratio (n:1) */ float f_knee = p_sys->f_knee; /* Knee radius (dB) */ float f_makeup_gain = p_sys->f_makeup_gain; /* Makeup gain (dB) */ vlc_mutex_unlock( &p_sys->lock ); /* Fetch the internal parameters */ float f_amp = p_sys->f_amp; float *pf_as = p_sys->pf_as; float f_env = p_sys->f_env; float f_env_peak = p_sys->f_env_peak; float f_env_rms = p_sys->f_env_rms; float f_gain = p_sys->f_gain; float f_gain_out = p_sys->f_gain_out; rms_env *p_rms = &p_sys->rms; float f_sum = p_sys->f_sum; lookahead *p_la = &p_sys->la; /* Prepare other compressor parameters */ float f_ga = f_attack < 2.0f ? 0.0f : pf_as[Round( f_attack * 0.001f * ( A_TBL - 1 ) )]; float f_gr = pf_as[Round( f_release * 0.001f * ( A_TBL - 1 ) )]; float f_rs = ( f_ratio - 1.0f ) / f_ratio; float f_mug = Db2Lin( f_makeup_gain, p_sys ); float f_knee_min = Db2Lin( f_threshold - f_knee, p_sys ); float f_knee_max = Db2Lin( f_threshold + f_knee, p_sys ); float f_ef_a = f_ga * 0.25f; float f_ef_ai = 1.0f - f_ef_a; /* Process the current buffer */ for( int i = 0; i < i_samples; i++ ) { float f_lev_in_old, f_lev_in_new; /* Now, compress the pre-equalized audio (ported from sc4_1882 * plugin with a few modifications) */ /* Fetch the old delayed buffer value */ f_lev_in_old = p_la->p_buf[p_la->i_pos].f_lev_in; /* Find the peak value of current sample. This becomes the new delayed * buffer value that replaces the old one in the lookahead array */ f_lev_in_new = fabs( pf_buf[0] ); for( int i_chan = 1; i_chan < i_channels; i_chan++ ) { f_lev_in_new = Max( f_lev_in_new, fabs( pf_buf[i_chan] ) ); } p_la->p_buf[p_la->i_pos].f_lev_in = f_lev_in_new; /* Add the square of the peak value to a running sum */ f_sum += f_lev_in_new * f_lev_in_new; /* Update the RMS envelope */ if( f_amp > f_env_rms ) { f_env_rms = f_env_rms * f_ga + f_amp * ( 1.0f - f_ga ); } else { f_env_rms = f_env_rms * f_gr + f_amp * ( 1.0f - f_gr ); } RoundToZero( &f_env_rms ); /* Update the peak envelope */ if( f_lev_in_old > f_env_peak ) { f_env_peak = f_env_peak * f_ga + f_lev_in_old * ( 1.0f - f_ga ); } else { f_env_peak = f_env_peak * f_gr + f_lev_in_old * ( 1.0f - f_gr ); } RoundToZero( &f_env_peak ); /* Process the RMS value and update the output gain every 4 samples */ if( ( p_sys->i_count++ & 3 ) == 3 ) { /* Process the RMS value by placing in the mean square value, and * reset the running sum */ f_amp = RmsEnvProcess( p_rms, f_sum * 0.25f ); f_sum = 0.0f; if( cover_isnan( f_env_rms ) ) // sunqueen modify { /* This can happen sometimes, but I don't know why. */ f_env_rms = 0.0f; } /* Find the superposition of the RMS and peak envelopes */ f_env = LIN_INTERP( f_rms_peak, f_env_rms, f_env_peak ); /* Update the output gain */ if( f_env <= f_knee_min ) { /* Gain below the knee (and below the threshold) */ f_gain_out = 1.0f; } else if( f_env < f_knee_max ) { /* Gain within the knee */ const float f_x = -( f_threshold - f_knee - Lin2Db( f_env, p_sys ) ) / f_knee; f_gain_out = Db2Lin( -f_knee * f_rs * f_x * f_x * 0.25f, p_sys ); } else { /* Gain above the knee (and above the threshold) */ f_gain_out = Db2Lin( ( f_threshold - Lin2Db( f_env, p_sys ) ) * f_rs, p_sys ); } } /* Find the total gain */ f_gain = f_gain * f_ef_a + f_gain_out * f_ef_ai; /* Write the resulting buffer to the output */ BufferProcess( pf_buf, i_channels, f_gain, f_mug, p_la ); pf_buf += i_channels; } /* Update the internal parameters */ p_sys->f_sum = f_sum; p_sys->f_amp = f_amp; p_sys->f_gain = f_gain; p_sys->f_gain_out = f_gain_out; p_sys->f_env = f_env; p_sys->f_env_rms = f_env_rms; p_sys->f_env_peak = f_env_peak; return p_in_buf; }
void IntControl::Update_Signals (void) { int method, min_phase; double pocket_factor, shared_factor, turn_factor, permit_factor; int p, p1, p2, phase, nphase, dir, tot, low, high, sum, cycle, count, time; int bar, nbarrier, barrier_extra, barrier_critical; int extra, ring, nring, ring_extra, ring_critical, min_cap, max_cap; int split [MAX_PHASE_NUM], demand [MAX_PHASE_NUM], critical [MAX_PHASE_NUM]; double rate, share, bucket, factor, lanes [MAX_PHASE_NUM]; String buffer; bool adjust, first; Int_Map_Itr map_itr; Int_Set_Itr set_itr; Signal_Data *signal_ptr; Signal_Itr signal_itr; Signal_Time_Itr time_itr; Phasing_Itr phasing_itr; Movement_Itr move_itr; Flow_Time_Array *array_ptr; Flow_Time_Data *flow_ptr; Connect_Data *connect_ptr; Dir_Data *dir_ptr; Timing_Itr timing_itr; Timing_Phase_Itr phase_itr; Group_Map_Itr group_itr; Signal_Group *group_ptr; typedef struct { int dir_index; int left_rate; int thru_rate; int right_rate; double left_lanes; double thru_lanes; double right_lanes; char left_low; char left_high; char thru_low; char thru_high; char right_low; char right_high; char protect; char flag; } Approach; Approach total [MAX_DIR_TOT], approach [MAX_PHASE_NUM] [MAX_DIR_NUM], *app_ptr, *tot_ptr; min_cap = max_cap = 0; if (regen_flag) { for (signal_itr = signal_array.begin (); signal_itr != signal_array.end (); signal_itr++) { update_signal.insert (signal_itr->Signal ()); } } //---- initialize the report header ---- if (update_report) { Header_Number (TIMING_UPDATE); if (!Break_Check ((int) update_signal.size () * 6)) { Print (1); Update_Header (); } } first = true; //---- process each signal marked for updating ---- Show_Message ("Updating Signal Timing Plans -- Record"); Set_Progress (); for (set_itr = update_signal.begin (); set_itr != update_signal.end (); set_itr++) { Show_Progress (); map_itr = signal_map.find (*set_itr); if (map_itr == signal_map.end ()) continue; signal_ptr = &signal_array [map_itr->second]; //---- find the signal group ---- group_itr = group_map.find (signal_ptr->Group ()); if (group_itr == group_map.end ()) { if (signal_ptr->Group () != 0) { Warning (String ("Control Keys for Signal Group %d were Not Provided") % signal_ptr->Group ()); } group_itr = group_map.begin (); if (group_itr == group_map.end ()) continue; } group_ptr = &group_itr->second; //---- process each time period in range ---- for (time_itr = signal_ptr->begin (); time_itr != signal_ptr->end (); time_itr++) { if (!sum_periods.Period_Range (time_itr->Start (), time_itr->End (), p1, p2)) continue; p = group_ptr->time_breaks.Period ((time_itr->Start () + time_itr->End ()) / 2); if (p++ < 0) continue; pocket_factor = group_ptr->pocket_factor.Best (p); shared_factor = group_ptr->shared_factor.Best (p); turn_factor = group_ptr->turn_factor.Best (p); permit_factor = group_ptr->permit_factor.Best (p); min_phase = group_ptr->min_phase.Best (p); method = group_ptr->method.Best (p); if (method == CAPACITY_SPLITS) { min_cap = group_ptr->min_cap.Best (p); max_cap = group_ptr->max_cap.Best (p); } //---- gather the phase and flow data ---- nphase = 0; memset (approach, '\0', sizeof (approach)); memset (total, '\0', sizeof (total)); tot_ptr = total; for (tot=0; tot < MAX_DIR_TOT; tot++, tot_ptr++) { tot_ptr->dir_index = -1; } for (phasing_itr = signal_ptr->phasing_plan.begin (); phasing_itr != signal_ptr->phasing_plan.end (); phasing_itr++) { if (phasing_itr->Phasing () != time_itr->Phasing ()) continue; phase = phasing_itr->Phase (); if (phase >= MAX_PHASE_NUM) continue; if (phase > nphase) nphase = phase; app_ptr = approach [phase]; for (dir=0; dir < MAX_DIR_NUM; dir++, app_ptr++) { app_ptr->dir_index = -1; } //---- process each turning movement ---- for (move_itr = phasing_itr->begin (); move_itr != phasing_itr->end (); move_itr++) { if (move_itr->Protection () == STOP_PERMIT) continue; connect_ptr = &connect_array [move_itr->Connection ()]; low = connect_ptr->Low_Lane () + 1; high = connect_ptr->High_Lane () + 1; //---- sum the time period rates ---- rate = 0; if (method == VOLUME_SPLITS || method == UPDATE_SPLITS) { for (p=p1; p <= p2; p++) { array_ptr = &turn_delay_array [p]; flow_ptr = &array_ptr->at (move_itr->Connection ()); rate += flow_ptr->Flow (); } } else if (method == CAPACITY_SPLITS) { dir_ptr = &dir_array [connect_ptr->Dir_Index ()]; rate = (double) dir_ptr->Capacity () / dir_ptr->Lanes (); if (rate < min_cap) { rate = min_cap; } else if (rate > max_cap) { rate = max_cap; } rate *= dir_ptr->Lanes (); } //if (rate < 1.0) rate = 1.0; //---- store the movement type data ---- app_ptr = approach [phase]; for (dir=0; dir < MAX_DIR_NUM; dir++, app_ptr++) { if (app_ptr->dir_index < 0 || app_ptr->dir_index == connect_ptr->Dir_Index ()) { app_ptr->dir_index = connect_ptr->Dir_Index (); if (connect_ptr->Type () == RIGHT) { app_ptr->right_rate += Round (rate); if (app_ptr->right_low == 0 || app_ptr->right_low > low) { app_ptr->right_low = (char) low; } if (app_ptr->right_high == 0 || app_ptr->right_high < high) { app_ptr->right_high = (char) high; } } else if (connect_ptr->Type () == LEFT || connect_ptr->Type () == UTURN) { app_ptr->left_rate += Round (rate); if (app_ptr->left_low == 0 || app_ptr->left_low > low) { app_ptr->left_low = (char) low; } if (app_ptr->left_high == 0 || app_ptr->left_high < high) { app_ptr->left_high = (char) high; } if (move_itr->Protection () == PROTECTED) { app_ptr->protect = 1; } } else { app_ptr->thru_rate += Round (rate); if (app_ptr->thru_low == 0 || app_ptr->thru_low > low) { app_ptr->thru_low = (char) low; } if (app_ptr->thru_high == 0 || app_ptr->thru_high < high) { app_ptr->thru_high = (char) high; } } break; } } } //---- calculate the lane weights for each movement ---- app_ptr = approach [phase]; for (dir=0; dir < MAX_DIR_NUM; dir++, app_ptr++) { if (app_ptr->dir_index < 0) break; dir_ptr = &dir_array [app_ptr->dir_index]; if (app_ptr->left_rate > 0) { //---- check for shared lanes ---- if (app_ptr->thru_rate > 0 && app_ptr->left_high < app_ptr->thru_low) { //---- shared thru-left lanes ---- share = shared_factor * (app_ptr->left_high - app_ptr->thru_low + 1); app_ptr->thru_lanes = share; app_ptr->left_lanes = share + (app_ptr->thru_low - app_ptr->left_low) * pocket_factor; //---- check for pocket lanes ---- } else if (dir_ptr->Left () > 0 && app_ptr->left_low <= dir_ptr->Left ()) { share = app_ptr->left_high - dir_ptr->Left (); app_ptr->left_lanes = share + (dir_ptr->Left () - app_ptr->left_low + 1) * pocket_factor; } else { app_ptr->left_lanes = app_ptr->left_high - app_ptr->left_low + 1; } //---- turn slow down impact ---- app_ptr->left_lanes *= turn_factor; //---- non-protected left adjustment ---- if (app_ptr->protect == 0) { app_ptr->left_lanes *= permit_factor; } } if (app_ptr->right_rate > 0) { //---- check for shared lanes ---- if (app_ptr->thru_rate > 0 && app_ptr->right_low < app_ptr->thru_high) { share = shared_factor * (app_ptr->thru_high - app_ptr->right_low + 1); app_ptr->thru_lanes += share; app_ptr->right_lanes = share + (app_ptr->right_high - app_ptr->thru_high) + pocket_factor; //---- check for pocket lanes ---- } else if (dir_ptr->Right () > 0 && app_ptr->right_high > (dir_ptr->Left () + dir_ptr->Lanes ())) { share = dir_ptr->Left () + dir_ptr->Lanes () - app_ptr->left_low + 1; app_ptr->right_lanes = share + (app_ptr->right_high - (dir_ptr->Left () + dir_ptr->Lanes ())) * pocket_factor; } else { app_ptr->right_lanes = app_ptr->right_high - app_ptr->right_low + 1; } //---- turn slow down impact ---- app_ptr->right_lanes *= turn_factor; } if (app_ptr->thru_rate > 0) { //---- exclude shared lanes ---- low = MAX (app_ptr->left_high, app_ptr->thru_low); if (app_ptr->right_low > 0) { high = MIN (app_ptr->right_low, app_ptr->thru_high); } else { high = app_ptr->thru_high; } app_ptr->thru_lanes += high - low + 1; } //---- add to the intersection totals ---- tot_ptr = total; for (tot=0; tot < MAX_DIR_TOT; tot++, tot_ptr++) { if (tot_ptr->dir_index < 0 || tot_ptr->dir_index == app_ptr->dir_index) { tot_ptr->dir_index = app_ptr->dir_index; if (tot_ptr->left_rate == 0) { tot_ptr->left_rate = app_ptr->left_rate; tot_ptr->left_low = app_ptr->left_low; tot_ptr->left_high = app_ptr->left_high; } if (tot_ptr->right_rate == 0) { tot_ptr->right_rate = app_ptr->right_rate; tot_ptr->right_low = app_ptr->right_low; tot_ptr->right_high = app_ptr->right_high; } if (tot_ptr->thru_rate == 0) { tot_ptr->thru_rate = app_ptr->thru_rate; tot_ptr->thru_low = app_ptr->thru_low; tot_ptr->thru_high = app_ptr->thru_high; } tot_ptr->left_lanes += app_ptr->left_lanes; tot_ptr->right_lanes += app_ptr->right_lanes; tot_ptr->thru_lanes += app_ptr->thru_lanes; break; } } } } //---- adjust the phase rates ---- sum = 0; memset (lanes, '\0', sizeof (lanes)); memset (demand, '\0', sizeof (demand)); memset (split, '\0', sizeof (split)); memset (critical, '\0', sizeof (critical)); for (phase=1; phase <= nphase; phase++) { app_ptr = approach [phase]; if (app_ptr->dir_index < 0) continue; high = 0; for (dir=0; dir < MAX_DIR_NUM; dir++, app_ptr++) { if (app_ptr->dir_index < 0) break; tot_ptr = total; for (tot=0; tot < MAX_DIR_TOT; tot++, tot_ptr++) { if (tot_ptr->dir_index == app_ptr->dir_index) break; } if (tot == MAX_DIR_TOT) continue; if (app_ptr->thru_lanes > 0.0) { lanes [phase] += app_ptr->thru_lanes; rate = tot_ptr->thru_rate * app_ptr->thru_lanes / tot_ptr->thru_lanes; demand [phase] += DTOI (rate); app_ptr->thru_rate = DTOI (rate / tot_ptr->thru_lanes); if (app_ptr->thru_rate > high) high = app_ptr->thru_rate; } if (app_ptr->left_lanes > 0.0) { lanes [phase] += app_ptr->left_lanes; rate = tot_ptr->left_rate * app_ptr->left_lanes / tot_ptr->left_lanes; demand [phase] += DTOI (rate); app_ptr->left_rate = DTOI (rate / tot_ptr->left_lanes); if (app_ptr->left_rate > high) high = app_ptr->left_rate; } if (app_ptr->right_lanes > 0.0) { lanes [phase] += app_ptr->right_lanes; rate = tot_ptr->right_rate * app_ptr->right_lanes / tot_ptr->right_lanes; demand [phase] += DTOI (rate); app_ptr->right_rate = DTOI (rate / tot_ptr->right_lanes); if (app_ptr->right_rate > high) high = app_ptr->right_rate; } } critical [phase] = split [phase] = high; sum += high; } if (sum == 0) continue; //---- process the timing plan ---- for (timing_itr = signal_ptr->timing_plan.begin (); timing_itr != signal_ptr->timing_plan.end (); timing_itr++) { if (timing_itr->Timing () != time_itr->Timing ()) continue; //---- scan for multiple rings ---- nbarrier = nring = 0; for (phase_itr = timing_itr->begin (); phase_itr != timing_itr->end (); phase_itr++) { if (phase_itr->Barrier () > nbarrier) nbarrier = phase_itr->Barrier (); if (phase_itr->Ring () > nring) nring = phase_itr->Ring (); } //---- multiple ring processing ---- if (nbarrier > 1 || nring > 1) { sum = extra = 0; for (bar = 1; bar <= nbarrier; bar++) { barrier_extra = barrier_critical = 0; for (ring = 1; ring <= nring; ring++) { ring_extra = ring_critical = 0; for (phase_itr = timing_itr->begin (); phase_itr != timing_itr->end (); phase_itr++) { if (phase_itr->Barrier () != bar || phase_itr->Ring () != ring) continue; ring_critical += critical [phase_itr->Phase ()]; ring_extra += phase_itr->Yellow () + phase_itr->All_Red (); } if (ring_critical > barrier_critical) { barrier_critical = ring_critical; barrier_extra = ring_extra; } } sum += barrier_critical; extra += barrier_extra; } //---- adjust phasing by demand ---- for (count=0; count < 5; count++) { cycle = timing_itr->Cycle () - extra; if (sum > 0) { factor = (double) cycle / sum; sum = 0; } else { factor = 1.0; } bucket = 0.45; adjust = false; sum = extra = 0; for (bar = 1; bar <= nbarrier; bar++) { barrier_extra = barrier_critical = 0; for (ring = 1; ring <= nring; ring++) { ring_extra = ring_critical = 0; for (phase_itr = timing_itr->begin (); phase_itr != timing_itr->end (); phase_itr++) { if (phase_itr->Barrier () != bar || phase_itr->Ring () != ring) continue; phase = phase_itr->Phase (); share = factor * split [phase] + bucket; high = (int) share; bucket = share - (double) high; if (high < min_phase) { high = min_phase; adjust = true; } split [phase] = high; ring_critical += high; ring_extra += phase_itr->Yellow () + phase_itr->All_Red (); } if (ring_critical > barrier_critical) { barrier_critical = ring_critical; barrier_extra = ring_extra; } } sum += barrier_critical; extra += barrier_extra; //---- normalize the rings in each barrier ---- for (ring = 1; ring <= nring; ring++) { ring_extra = ring_critical = 0; for (phase_itr = timing_itr->begin (); phase_itr != timing_itr->end (); phase_itr++) { if (phase_itr->Barrier () != bar || phase_itr->Ring () != ring) continue; ring_critical += split [phase_itr->Phase ()]; ring_extra += phase_itr->Yellow () + phase_itr->All_Red (); } if (ring_critical >= barrier_critical || ring_critical == 0) continue; share = (double) (barrier_critical + barrier_extra - ring_extra) / ring_critical; for (phase_itr = timing_itr->begin (); phase_itr != timing_itr->end (); phase_itr++) { if (phase_itr->Barrier () != bar || phase_itr->Ring () != ring) continue; phase = phase_itr->Phase (); split [phase] = DTOI (split [phase] * share); } } } if (!adjust) break; } } else { //---- single ring ---- //---- calculate the green cycle length ---- cycle = timing_itr->Cycle (); for (phase = 1; phase <= nphase; phase++) { for (phase_itr = timing_itr->begin (); phase_itr != timing_itr->end (); phase_itr++) { if (phase_itr->Phase () == phase) break; } if (phase_itr == timing_itr->end ()) continue; cycle -= (phase_itr->Yellow () + phase_itr->All_Red ()); } //---- adjust phasing by demand ---- for (count=0; count < 5; count++) { if (sum > 0) { factor = (double) cycle / sum; sum = 0; } else { factor = 1.0; } bucket = 0.45; adjust = false; for (phase = 1; phase <= nphase; phase++) { share = factor * split [phase] + bucket; high = (int) share; bucket = share - (double) high; if (high < min_phase) { high = min_phase; adjust = true; } split [phase] = high; sum += high; } if (!adjust) break; } } //---- update the green times ---- for (phase = 1; phase <= nphase; phase++) { for (phase_itr = timing_itr->begin (); phase_itr != timing_itr->end (); phase_itr++) { if (phase_itr->Phase () == phase) break; } if (phase_itr == timing_itr->end ()) continue; if (update_report) { if (phase == 1) { if (!Break_Check (nphase + 1)) { if (first) { first = false; } else { Print (1); } } buffer = time_itr->Start ().Time_String () + "-" + time_itr->End ().Time_String (); Print (1, String ("%10d %-11.11s %6d") % signal_ptr->Signal () % buffer % time_itr->Timing ()); } else { Print (1, String ("%30c") % BLANK); } Print (0, String (" %3d %7d %4.1lf %5d %3d %3d %3d") % phase % Resolve (demand [phase]) % lanes [phase] % Resolve (critical [phase]) % phase_itr->Min_Green () % phase_itr->Max_Green () % phase_itr->Extension ()); } time = MAX (phase_itr->Min_Green (), phase_itr->Max_Green ()); if (time > 0) { factor = split [phase] / (double) time; } else { factor = 1.0; } time = DTOI (phase_itr->Min_Green () * factor); if (time < min_phase) time = min_phase; phase_itr->Min_Green (time); time = DTOI (phase_itr->Max_Green () * factor); phase_itr->Max_Green (time); time = DTOI (phase_itr->Extension () * factor); phase_itr->Extension (time); if (update_report) { Print (0, String (" %3d %3d %3d") % phase_itr->Min_Green () % phase_itr->Max_Green () % phase_itr->Extension ()); } } ntiming++; } } } End_Progress (); Header_Number (0); }
// // Draw wireframe rectangle // void CClientColRectangle::DebugRender ( const CVector& vecPosition, float fDrawRadius ) { CVector vecBase ( m_vecPosition.fX, m_vecPosition.fY, vecPosition.fZ - fDrawRadius ); CVector vecOrigin ( m_vecPosition.fX + m_vecSize.fX * 0.5f, m_vecPosition.fY + m_vecSize.fY * 0.5f, vecPosition.fZ ); CVector vecSize ( m_vecSize.fX, m_vecSize.fY, fDrawRadius * 2.f ); SColorARGB color ( 128, 255, 0, 255 ); float fLineWidth = 4.f + pow ( std::max ( m_vecSize.fX, m_vecSize.fY ) * 0.5f, 0.5f ); CGraphicsInterface* pGraphics = g_pCore->GetGraphics (); // Don't draw a few end slices to show it goes on for ever int iSkipEndSlicesZ = 4; // Calc required detail level uint uiNumSlicesX = std::max ( 2, Round ( sqrt ( vecSize.fX ) * 1.5f ) ); uint uiNumSlicesY = std::max ( 2, Round ( sqrt ( vecSize.fY ) * 1.5f ) ); uint uiNumSlicesZ = std::max ( 2 + iSkipEndSlicesZ * 2, Round ( sqrt ( vecSize.fZ ) * 2.0f ) ); // Draw Slices Z { static const CVector cornerPoints[] = { CVector( 0, 0, 1 ), CVector( 1, 0, 1 ), CVector( 1, 1, 1 ), CVector( 0, 1, 1 ) }; CVector vecMult = vecSize; CVector vecAdd = vecBase + CVector ( 0, 0, 4 ); // Extra bit so a slice is on the same Z coord as the camera for ( uint s = iSkipEndSlicesZ ; s < uiNumSlicesZ - iSkipEndSlicesZ ; s++ ) { vecMult.fZ = vecSize.fZ * ( s / (float)( uiNumSlicesZ - 1 ) ); for ( uint i = 0 ; i < NUMELMS( cornerPoints ) ; i++ ) { const CVector& vecBegin = cornerPoints [ i ] * vecMult + vecAdd; const CVector& vecEnd = cornerPoints [ ( i + 1 ) % 4 ] * vecMult + vecAdd; pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } } } // Draw Slices Y { static const CVector cornerPoints[] = { CVector( 0, 1, 0 ), CVector( 1, 1, 0 ), CVector( 1, 1, 1 ), CVector( 0, 1, 1 ) }; CVector vecMult = vecSize; CVector vecAdd = vecBase; for ( uint s = 0 ; s < uiNumSlicesY ; s++ ) { vecMult.fY = vecSize.fY * ( s / (float)( uiNumSlicesY - 1 ) ); for ( uint i = 0 ; i < NUMELMS( cornerPoints ) ; i++ ) { if ( !(i & 1) ) continue; // No end cap const CVector& vecBegin = cornerPoints [ i ] * vecMult + vecAdd; const CVector& vecEnd = cornerPoints [ ( i + 1 ) % 4 ] * vecMult + vecAdd; pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } } } // Draw Slices X { static const CVector cornerPoints[] = { CVector( 1, 0, 0 ), CVector( 1, 1, 0 ), CVector( 1, 1, 1 ), CVector( 1, 0, 1 ) }; CVector vecMult = vecSize; CVector vecAdd = vecBase; for ( uint s = 0 ; s < uiNumSlicesX ; s++ ) { vecMult.fX = vecSize.fX * ( s / (float)( uiNumSlicesX - 1 ) ); for ( uint i = 0 ; i < NUMELMS( cornerPoints ) ; i++ ) { if ( !(i & 1) ) continue; // No end cap const CVector& vecBegin = cornerPoints [ i ] * vecMult + vecAdd; const CVector& vecEnd = cornerPoints [ ( i + 1 ) % 4 ] * vecMult + vecAdd; pGraphics->DrawLine3DQueued ( vecBegin, vecEnd, fLineWidth, color, false ); } } } }
double roundTo(double num, int decimals) { double shift = pow(10, decimals); return Round(num * shift) / shift; };
SubareaPlans::SubareaPlans (void) : Demand_Service () { Program ("SubareaPlans"); Version ("4.0.33"); Title ("Subarea Plan and Vehicle Files"); Network_File required_network [] = { NODE, LINK, ACTIVITY_LOCATION, PARKING, PROCESS_LINK, END_NETWORK }; Network_File optional_network [] = { DIRECTORY, LANE_CONNECTIVITY, NEW_DIRECTORY, NEW_ACTIVITY_LOCATION, NEW_PARKING, NEW_PROCESS_LINK, TRANSIT_STOP, TRANSIT_ROUTE, TRANSIT_SCHEDULE, TRANSIT_DRIVER, NEW_TRANSIT_STOP, NEW_TRANSIT_ROUTE, NEW_TRANSIT_SCHEDULE, NEW_TRANSIT_DRIVER, END_NETWORK }; Demand_File required_demand [] = { VEHICLE, NEW_VEHICLE, END_DEMAND }; Demand_File optional_demand [] = { LINK_DELAY, NEW_BOUNDARY_SPEED, END_DEMAND }; char *keys [] = { PLAN_FILE, PLAN_FORMAT, NODE_LIST_PATHS, SUBAREA_BOUNDARY_POLYGON, EXTERNAL_OFFSET_LENGTH, NEW_PLAN_FILE, NEW_PLAN_FORMAT, NEW_HOUSEHOLD_LIST, RETIME_EARLY_ARRIVALS, ZONE_EQUIVALENCE_FILE, TIME_PERIOD_EQUIVALENCE, SELECT_TIME_PERIODS, NULL }; char *reports [] = { "TRIP_SUMMARY_REPORT", "PRINT_ZONE_EQUIVALENCIES", "TIME_PERIOD_EQUIVALENCE", NULL }; Required_Network_Files (required_network); Optional_Network_Files (optional_network); Required_Demand_Files (required_demand); Optional_Demand_Files (optional_demand); Key_List (keys); Report_List (reports); Enable_Partitions (true); AB_Key_Flag (true); trips = NULL; type_flag = true; transit_flag = output_flag = range_flag = false; delay_flag = location_flag = parking_flag = access_flag = extend_flag = early_flag = false; trip_flag = zone_flag = time_flag = turn_flag = hhlist_flag = boundary_flag = false; nlink = nshort = nlocation = nparking = naccess = num_adjust = total_adjust = 0; max_location = max_parking = max_access = max_vehicle = max_zone = 0; num_in_in = num_out_in = num_in_out = num_out_out = 0; leg_in_in = leg_out_in = leg_in_out = leg_out_out = 0; max_stop = max_route = 0; new_stop = new_route = 0; nstop = nroute = nschedule = ndriver = 0; current_traveler = current_trip = current_leg = boarding_stop = last_location = last_time = 0; external_offset = Round (15); //---- 15 meters ---- boundary.Data_Size (sizeof (Boundary)); Compress_Vehicles (false); }
int PikoSec(double delay_ns) { return Round(1000.0 * delay_ns); }
void CCellView::ResizeRow(BPoint where, int rowNr) { float y, minY; BPoint newP, lastP; BRect bounds(Bounds()), r, b; BRegion rgn; ulong buttons, cnt; bool multi; int mRow = rowNr; CRunArray backup(fCellHeights); StPenState save(this); ClearAnts(); rgn.Include(bounds); cnt = fSelection.bottom-fSelection.top+1; while (where.y > fCellHeights[rowNr+1]+2) rowNr++; multi = fSelection.top != fSelection.bottom && rowNr >= fSelection.top && rowNr <= fSelection.bottom; if (rowNr <= fFrozen.v) { y = fBorderHeight+fCellHeights[rowNr]; minY = fBorderHeight+fCellHeights[multi?fSelection.top-1:rowNr-1]; } else { y = fBorderHeight+fCellHeights[rowNr]+fCellHeights[fFrozen.v]- fCellHeights[fPosition.v-1]; minY = fBorderHeight+fCellHeights[fFrozen.v]-fCellHeights[fPosition.v-1]+ fCellHeights[multi?fSelection.top-1:rowNr-1]; } r.left = 0; r.right = fBorderWidth-1; r.top = minY+1; if (multi) r.bottom = minY+fCellHeights[fSelection.bottom]- fCellHeights[fSelection.top-1]-1; else r.bottom = minY+fCellHeights[rowNr]-fCellHeights[rowNr-1]-1; b = bounds; b.top = r.bottom; lastP = where; newP = where; do { if (newP.y != lastP.y) { float dy; int k = rowNr; dy = newP.y - lastP.y; if (lastP.y + dy < bounds.top + fBorderHeight) dy = std::min(lastP.y - bounds.top - fBorderHeight, (float)0); if (lastP.y + dy > bounds.bottom) dy = std::max(bounds.bottom - lastP.y, (float)0); if (multi && y + dy < minY) dy = minY - y; if (multi) { float h, t; h = y + dy - minY; if (h > 0) h = Round(h/(rowNr-fSelection.top+1)); t = fCellHeights[fSelection.bottom]; fCellHeights.SetValue(fSelection.top, fSelection.bottom, h); dy = fCellHeights[fSelection.bottom] - t; } else if (y + dy < minY) { int t = k; fCellHeights.SetValue(rowNr, 0); while (k > 1 && backup[k - 1] + fBorderHeight >= y + dy) k--; ASSERT(k<rowNr); if (k <= mRow) while (mRow > k) fCellHeights.SetValue(mRow--, 0); else { t = mRow; for (; mRow < k; mRow++) fCellHeights.SetValue(mRow, backup[mRow] - backup[mRow - 1]); } float kh = y + dy - fBorderHeight; kh -= backup[k - 1]; fCellHeights.SetValue(k, std::max(kh, (float)0)); mRow = k; k = t; } else { k = mRow; for (; mRow < rowNr; mRow++) fCellHeights.SetValue(mRow, backup[mRow] - backup[mRow - 1]); fCellHeights.SetValue(rowNr, y + dy - minY); } if (dy != 0) { y += dy; lastP.y += dy; if (dy < 0) b.top += dy; StPenState save(this); StClipCells clip(this); ScrollRect(b, 0, dy); Window()->UpdateIfNeeded(); if (dy > 0) b.top += dy; if (multi) { int v = fSelection.top; do { TouchLine(v); DrawBorderCell(v++, false); } while (v <= fSelection.bottom && bounds.top + fCellHeights[v] + fBorderHeight < bounds.bottom); } else { TouchLine(mRow); DrawBorderCell(mRow, false); } for (; k < rowNr; k++) { TouchLine(k); DrawBorderCell(k, false); } } if (dy < 0) { float Y; int v; Y = bounds.bottom + dy - fBorderHeight; v = fSelection.bottom; do v++; while (fCellHeights[v] < Y) ; StPenState save(this); while (v <= kRowCount && bounds.top + fCellHeights[v] + fBorderHeight < bounds.bottom) { TouchLine(v); DrawBorderCell(v++, false); } } if (dy) { DrawAllLines(); if (fFirstGraphic) fFirstGraphic->HandleUpdate(bounds); } } GetMouse(&newP, &buttons); } while (buttons); if (!(backup == fCellHeights)) { CRunArray temp(fCellHeights); fCellHeights = backup; ((CCellWindow*)Window())->RegisterCommand(new CResizeCommand(this, temp, true)); ((CCellWindow*)Window())->SetDirty(true); } } /* ResizeRow */
void LineSum::Performance_Report (int number) { double veh_miles, veh_hours, pass_miles, pass_hours; int board, alight, vehicles, passengers; double tot_veh_miles, tot_veh_hours, tot_pass_miles, tot_pass_hours; int tot_board, tot_alight, tot_vehicles, tot_passengers; int stop, stops, run, runs, period, per, num, time, on, off, ride, /*percent,*/ distance; bool last_stop_flag, stop_flag; Rider_Data *rider_ptr; Offset_Data *offset_ptr; //Route_Legs *legs_ptr; Show_Message ("Creating a Transit Performance Report -- Record"); Set_Progress (100); //---- initialize the selection sets ---- set_ptr = select_set [number]; if (set_ptr == NULL) return; Header_Number (PERF_REPORT); //---- initialize the report data ---- num = set_ptr->Num_Periods (); if (!Break_Check (num + 6)) { Print (1); Performance_Header (); } tot_veh_miles = tot_veh_hours = tot_pass_miles = tot_pass_hours = 0.0; tot_board = tot_alight = tot_vehicles = tot_passengers = 0; //---- process each time period ---- for (per=1; per <= num; per++) { veh_miles = veh_hours = pass_miles = pass_hours = 0.0; board = alight = vehicles = passengers = 0; //---- process each route ---- for (rider_ptr = rider_data.First_Key (); rider_ptr; rider_ptr = rider_data.Next_Key ()) { Show_Progress (); //---- check the selection criteria ---- if (!set_ptr->Select_Modes (rider_ptr->Mode ())) continue; if (!set_ptr->Select_Routes (rider_ptr->Route ())) continue; stops = rider_ptr->Stops (); runs = rider_ptr->Runs (); //---- check for routes in the subarea ---- //legs_ptr = set_ptr->Route_Legs (rider_data.Record_Index ()); //if (legs_ptr == NULL) continue; //if (!legs_ptr->Subarea_Flag ()) continue; //---- process each run ---- for (run=1; run <= runs; run++) { switch (set_ptr->Time_Method ()) { case RUN_START: time = rider_ptr->Time (run, 1); break; case RUN_END: time = rider_ptr->Time (run, stops); break; case RUN_MID: time = (rider_ptr->Time (run, 1) + rider_ptr->Time (run, stops)) / 2; break; case SCHED_START: time = rider_ptr->Schedule (run, 1); break; case SCHED_END: time = rider_ptr->Schedule (run, stops); break; case SCHED_MID: time = (rider_ptr->Schedule (run, 1) + rider_ptr->Schedule (run, stops)) / 2; break; } period = set_ptr->Time_Period (Resolve (time)); if (period < per) continue; if (period > per) break; //---- sum the line ridership ---- ride = 0; last_stop_flag = stop_flag = true; for (stop=1; stop <= stops; stop++) { on = rider_ptr->Board (run, stop); off = rider_ptr->Alight (run, stop); time = rider_ptr->Time (run, stop); distance = rider_ptr->Distance (stop); //percent = legs_ptr->Percent (stop); //distance = legs_ptr->Distance (stop); if (offset_flag && set_ptr->Subarea_Flag ()) { offset_ptr = stop_offset.Get (rider_ptr->Stop (stop)); if (offset_ptr == NULL) continue; stop_flag = set_ptr->In_Subarea (offset_ptr->X (), offset_ptr->Y ()); if (stop_flag && !last_stop_flag) { passengers += ride; } last_stop_flag = stop_flag; } ride += on - off; if (stop_flag) { passengers += on; board += on; alight += off; if (stop < stops) { time = rider_ptr->Time (run, stop+1) - time; distance = rider_ptr->Distance (stop+1) - distance; pass_hours += ride * time; veh_hours += time; pass_miles += ride * distance; veh_miles += distance; } } } vehicles++; } } veh_miles /= Round (MILETOMETER); pass_miles /= Round (MILETOMETER); veh_hours /= 3600.0; pass_hours /= 3600.0; Print (1, "%-12.12s%10.1lf%10.1lf%8d%8d%10.1lf%10.1lf", set_ptr->Time_Format (per), veh_miles, veh_hours, board, alight, pass_miles, pass_hours); tot_veh_miles += veh_miles; tot_veh_hours += veh_hours; tot_pass_miles += pass_miles; tot_pass_hours += pass_hours; tot_board += board; tot_alight += alight; tot_vehicles += vehicles; tot_passengers += passengers; if (veh_miles <= 0.0) veh_miles = 1.0; if (veh_hours <= 0.0) veh_hours = 1.0; if (vehicles <= 0) vehicles = 1; Print (0, " %7.1lf%7.1lf%7.1lf", passengers / veh_miles, passengers / veh_hours, (double) passengers / vehicles); } End_Progress (); if (num > 1) { Print (2, "Total %10.1lf%10.1lf%8d%8d%10.1lf%10.1lf", tot_veh_miles, tot_veh_hours, tot_board, tot_alight, tot_pass_miles, tot_pass_hours); if (tot_veh_miles <= 0.0) tot_veh_miles = 1.0; if (tot_veh_hours <= 0.0) tot_veh_hours = 1.0; if (tot_vehicles <= 0) tot_vehicles = 1; Print (0, " %7.1lf%7.1lf%7.1lf", tot_passengers / tot_veh_miles, tot_passengers / tot_veh_hours, (double) tot_passengers / tot_vehicles); } Header_Number (0); }
int RoundInt(float x) { return (int)Round(x); }
ConvolutionFilterCodeDialog::ConvolutionFilterCodeDialog( String mode, const Filter& _filter ) : Dialog(), filter( _filter ) { // ### TextBox FilterCode_TextBox.SetScaledMinSize( 700, 300 ); FilterCode_TextBox.OnCaretPositionUpdated( (TextBox::caret_event_handler)&ConvolutionFilterCodeDialog::__TextBox_CaretPosition, *this ); if ( mode == "Edit" ) { FilterCode_TextBox.SetReadWrite(); FilterCode_TextBox.SetText( filter.ToSource() ); } tableRow = 0; String s; String html( "<html style=\"white-space:pre;text-align:right;\">" "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" ); StringList cols; UpdateTableColors(); if ( mode == "View" ) { FilterCode_TextBox.SetReadOnly(); if ( filter.IsSeparable() ) { SeparableFilter fs( filter.Separable() ); float element; // Rows for ( int i = 0; i < fs.Size(); ++i ) { // Cols for ( int j = 0; j < fs.Size(); ++j ) { // Calculus of each coefficient of the separable filter element = Round( fs.ColFilter()[i] * fs.RowFilter()[j], 6 ); cols.Add( String().Format( "%10.6f", element ) ); } html += TR( cols ); cols.Clear(); } } else { KernelFilter k( filter.Kernel() ); for ( int i = 0; i < k.Size(); ++i ) { for ( int j = 0; j < k.Size(); ++j ) { float element = Round( k.Coefficients()[i][j], 6 ); // The elements of the KernelFilter can be accessed directly God thanks and the [] operator. cols.Add( String().Format( "%10.6f", element ) ); } html += TR( cols ); cols.Clear(); } } html += "</table></html>"; // We got it!! we set the TextBox text by passing the composed String s. FilterCode_TextBox.SetText( html ); UpdateTableColors(); } if ( mode == "View" ) LineCol_Label.Hide(); else LineCol_Label.Show(); LineCol_Sizer.SetSpacing( 4 ); LineCol_Sizer.Add( LineCol_Label ); LineCol_Sizer.AddStretch(); // ### Save PushButton Save_PushButton.SetText( "Save" ); Save_PushButton.SetCursor( StdCursor::Checkmark ); Save_PushButton.OnClick( (Button::click_event_handler)&ConvolutionFilterCodeDialog::__Button_Click, *this ); if ( mode == "View" ) Save_PushButton.Hide(); else Save_PushButton.SetDefault(); if ( mode == "View" ) { Cancel_PushButton.SetText( "Close" ); Cancel_PushButton.SetCursor( StdCursor::Checkmark ); Cancel_PushButton.SetDefault(); } else { Cancel_PushButton.SetText( "Cancel" ); Cancel_PushButton.SetCursor( StdCursor::Crossmark ); } Cancel_PushButton.OnClick( (Button::click_event_handler)&ConvolutionFilterCodeDialog::__Button_Click, *this ); DialogButtons_Sizer.SetSpacing( 8 ); DialogButtons_Sizer.AddStretch(); DialogButtons_Sizer.Add( Save_PushButton ); DialogButtons_Sizer.Add( Cancel_PushButton ); DialogButtons_Sizer.AddStretch(); Global_Sizer.SetMargin( 4 ); Global_Sizer.SetSpacing( 4 ); Global_Sizer.Add( FilterCode_TextBox ); Global_Sizer.Add( LineCol_Sizer ); Global_Sizer.Add( DialogButtons_Sizer ); SetSizer( Global_Sizer ); EnableUserResizing(); AdjustToContents(); BringToFront(); //SetFixedSize(); if ( mode == "View" ) SetWindowTitle( '\"' + filter.Name() + '\"' + " filter elements" ); else if ( mode == "Edit" ) SetWindowTitle( '\"' + filter.Name() + '\"' + " edit" ); else if ( mode == "New" ) SetWindowTitle( "New filter" ); else throw Error( "Internal error: Invalid dialog operation mode in ConvolutionFilterCodeDialog" ); }
void TransimsNet::Program_Control (void) { int i, num, lvalue; double dvalue; char *str_ptr, buffer [FIELD_BUFFER]; Area_Type *type_ptr; //---- open network files ---- Network_Service::Program_Control (); //---- set the file flags ---- shape_flag = Network_File_Flag (NEW_SHAPE); zone_flag = Network_File_Flag (ZONE); zout_flag = Network_File_Flag (NEW_ZONE); name_flag = (((Link_File *) Network_Db_Base (LINK))->Name_Flag () && ((Link_File *) Network_Db_Base (NEW_LINK))->Name_Flag ()); turn_flag = Network_File_Flag (TURN_PROHIBITION); //---- set the zone fields ---- if (zout_flag) { if (!zone_flag) { Print (2, "Zone Centroids Copied from Node File"); } else { Zone_File *file = (Zone_File *) Network_Db_File (ZONE); Zone_File *new_file = (Zone_File *) Network_Db_File (NEW_ZONE); new_file->Clear_Fields (); new_file->Replicate_Fields (file); new_file->Write_Header (); } } //---- keep node list ---- str_ptr = Get_Control_String (KEEP_NODE_LIST); if (str_ptr != NULL) { Print (1); keep_nodes.File_Type ("Keep Node List File"); keep_nodes.Open (Network_Filename (str_ptr)); } //---- link node equivalance ---- str_ptr = Get_Control_String (LINK_NODE_EQUIVALENCE); if (str_ptr != NULL) { Print (1); node_string.File_Type ("Link Node Equivalence File"); node_string.Create (New_Filename (str_ptr)); } //---- get the pocket lane lengths ---- Print (1); num = Highest_Control_Group (POCKET_LENGTHS_FOR_FACILITY_x, 0); if (num >= EXTERNAL) num = EXTERNAL - 1; for (i=1; i <= num; i++) { str_ptr = Get_Control_String (POCKET_LENGTHS_FOR_FACILITY_x, i); if (str_ptr != NULL) { Print (1, "Pocket Lengths for Facility Type %d = %s meters", i, str_ptr); while (str_ptr != NULL) { str_ptr = Get_Double (str_ptr, &dvalue); if (dvalue < 0.0 || dvalue > 2000.0) { Error ("Pocket Length %.1lf for Facility %d is Out of Range (0..2000)", dvalue, i); } if (!pocket_len [i].Add (Round (dvalue))) { Error ("Adding Pocket Lane Length"); } } } } //---- get the pocket to facility ---- str_ptr = Get_Control_String (POCKET_TO_FACILITY_BY_AREA_TYPE); if (str_ptr != NULL) { pocket_to_flag = true; Print (1, "Pocket To Facility Types by Area Type = %s", str_ptr); while (str_ptr != NULL) { str_ptr = Get_Integer (str_ptr, &lvalue); if (lvalue < 0 || lvalue > EXTERNAL) { Error ("Pocket To Facility %d is Out of Range (0..%d)", lvalue, EXTERNAL); } if (!pocket_to.Add (lvalue)) { Error ("Adding Pocket To Facility"); } } } //---- get the signal warrants ---- Print (1); num = Highest_Control_Group (SIGNAL_WARRANT_FOR_AREA_TYPE_x, 0); for (i=1; i <= num; i++) { str_ptr = Get_Control_String (SIGNAL_WARRANT_FOR_AREA_TYPE_x, i); if (str_ptr != NULL) { Area_Type type_rec (i); Print (1, "Signal Warrant for Area Type %d = %s", i, str_ptr); str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer)); type_rec.Primary (Facility_Code (buffer)); str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer)); type_rec.Secondary (Facility_Code (buffer)); str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer)); if (*buffer == '\0') { str_cpy (buffer, sizeof (buffer), "ACTUATED"); } type_rec.Signal_Type (Signal_Code (buffer)); str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer)); if (*buffer == '\0') { str_cpy (buffer, sizeof (buffer), "SINGLE_RING"); } type_rec.Ring_Type (Ring_Code (buffer)); if (!area_type.Add (&type_rec)) goto type_error; } } //---- get the sign warrants ---- Print (1); num = Highest_Control_Group (STOP_WARRANT_FOR_AREA_TYPE_x, 0); for (i=1; i <= num; i++) { str_ptr = Get_Control_String (STOP_WARRANT_FOR_AREA_TYPE_x, i); if (str_ptr != NULL) { type_ptr = area_type.Get (i); lvalue = Facility_Code (str_ptr); if (type_ptr == NULL) { Area_Type type_rec (i); type_rec.All_Stop (lvalue); if (!area_type.Add (&type_rec)) goto type_error; } else { type_ptr->All_Stop (lvalue); } Print (1, "Stop Warrant for Area Type %d = %s", i, str_ptr); } } //---- activity location side offset ---- str_ptr = Get_Control_String (ACTIVITY_LOCATION_SIDE_OFFSET); if (str_ptr != NULL) { Get_Double (str_ptr, &location_side); if (location_side < 0.0 || location_side > 100.0) { Error ("Activity Location Side Offset %.2lf is Out of Range (0..100)", location_side); } } Print (2, "Activity Location Side Offset = %.2lf meters", location_side); //---- get the facility type access flags ---- str_ptr = Get_Control_String (FACILITY_TYPE_ACCESS_FLAGS); if (str_ptr != NULL) { for (i=1; str_ptr != NULL; i++) { str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer)); if (*buffer == '\0') break; access_flag [i] = (*buffer == '1' || *buffer == 't' || *buffer == 'T' || *buffer == 'y' || *buffer == 'Y'); } } Print (2, "Facility Type Access Flags = "); for (i=1; i <= EXTERNAL; i++) { if (i > 1) { Print (0, ", %d", access_flag [i]); } else { Print (0, "%d", access_flag [i]); } } //---- get the number of access points ---- str_ptr = Get_Control_String (MAXIMUM_ACCESS_POINTS); if (str_ptr == NULL) goto control_error; Get_Integer (str_ptr, &max_splits); if (max_splits < 1 || max_splits > 20) { Error ("Maximum Number of Access Points %d is Out of Range", max_splits); } Print (2, "Maximum Number of Access Points Per Link = %d", max_splits); //---- get the min split length ---- str_ptr = Get_Control_String (MINIMUM_SPLIT_LENGTHS); if (str_ptr == NULL) goto control_error; Print (2, "Minimum Split Lengths = %s meters", str_ptr); for (i=1; str_ptr != NULL; i++) { str_ptr = Get_Integer (str_ptr, &lvalue); if (lvalue == 0) continue; if (lvalue < 40 || lvalue > 4000) { Error ("Minimum Split Length %d is Out of Range (40-4000)", lvalue); } lvalue = Round (lvalue); type_ptr = area_type.Get (i); if (type_ptr == NULL) { Area_Type type_rec (i); type_rec.Split_Len (lvalue); if (!area_type.Add (&type_rec)) goto type_error; } else { type_ptr->Split_Len (lvalue); } } //---- get the cell size ---- str_ptr = Get_Control_String (CELL_SIZE); if (str_ptr != NULL) { Get_Double (str_ptr, &cell_size); if (cell_size < 4.0 || cell_size > 9.0) { Error ("Cell Size %.2lf is Out of Range (4..9)", cell_size); } } Print (2, "Cell Size = %.2lf meters", cell_size); //---- get the minimum link length ---- str_ptr = Get_Control_String (MINIMUM_LINK_LENGTH); if (str_ptr != NULL) { Get_Double (str_ptr, &dvalue); if (dvalue < cell_size || dvalue > 100.0) { Error ("Minimum Link Length %.1lf is Out of Range (%.1lf..100.0)", dvalue, cell_size); } } else { dvalue = cell_size * 5.0; } min_length = Round (dvalue); Print (2, "Minimum Link Length = %.1lf meters", UnRound (min_length)); //---- get the maximum length factor ---- str_ptr = Get_Control_String (MAXIMUM_LENGTH_TO_XY_RATIO); if (str_ptr != NULL) { Get_Double (str_ptr, &max_length_factor); if (max_length_factor < 1.0 || max_length_factor > 2.0) { Error ("Maximum Length to XY Ratio %.1lf is Out of Range (1.0..2.0)", max_length_factor); } } Print (2, "Maximum Length to XY Ratio = %.2lf", max_length_factor); //---- get the maximum connection angle ---- str_ptr = Get_Control_String (MAXIMUM_CONNECTION_ANGLE); if (str_ptr != NULL) { Get_Integer (str_ptr, &lvalue); if (lvalue < 90 || lvalue > 180) { Error ("Maximum Connection Angle %d is Out of Range (90..180)", lvalue); } max_angle = compass.Num_Points () * lvalue / 360; } Print (2, "Maximum Connection Angle = %d degrees", max_angle * 360 / compass.Num_Points ()); //---- uturn flag ---- uturn_flag = Get_Control_Flag (ADD_UTURN_TO_DEADEND_LINKS); if (uturn_flag) { Print (1, "U-Turns will be added to Dead-End Links"); } else { Print (1, "U-Turns will not be added to Dead-End Links"); } //---- get the setback distance ---- str_ptr = Get_Control_String (INTERSECTION_SETBACK_DISTANCE); if (str_ptr != NULL) { Get_Double (str_ptr, &dvalue); if (dvalue < 0.0 || dvalue > 20.0) { Error ("Intersection Setback Distance %.1lf is Out of Range (0.0..20.0)", dvalue); } } else { dvalue = 0.0; } setback = Round (dvalue); Print (2, "Intersection Setback Distance = %.1lf meters", UnRound (setback)); //---- get the external zone number ---- str_ptr = Get_Control_String (FIRST_EXTERNAL_ZONE_NUMBER); if (str_ptr != NULL) { Get_Integer (str_ptr, &ext_zone); if (ext_zone < 0 || ext_zone > 10000) { Error ("External Zone Number %d is Out of Range (0..10000)", ext_zone); } } else { ext_zone = 0; } Print (2, "First External Zone Number = %d", ext_zone); //---- get the zone connector flag ---- str_ptr = Get_Control_String (KEEP_ZONE_CONNECTORS_AS_LOCALS); if (str_ptr != NULL) { Print (1, "Keep Zone Connectors as Locals = %s", str_ptr); connect_flag = Get_Control_Flag (KEEP_ZONE_CONNECTORS_AS_LOCALS); } //---- get the replicate MPO network ---- str_ptr = Get_Control_String (REPLICATE_MPO_NETWORK); if (str_ptr != NULL) { Print (1, "Replication MPO Network = %s", str_ptr); replicate_flag = Get_Control_Flag (REPLICATE_MPO_NETWORK); } //---- collapse nodes flag ---- if (Get_Control_String (COLLAPSE_NODES_FLAG) != NULL) { collapse_flag = Get_Control_Flag (COLLAPSE_NODES_FLAG); } if (collapse_flag) { Print (2, "Extra Nodes will be Removed from the Network"); } else { Print (2, "All Nodes in the Network will be Kept"); } //---- update node range ---- str_ptr = Get_Control_String (UPDATE_NODE_RANGE); if (str_ptr != NULL) { update_flag = true; Print (2, "Update Node Range = %s", str_ptr); if (!update_nodes.Add_Ranges (str_ptr)) { Error ("Adding Update Nodes"); } } //---- update node file ---- str_ptr = Get_Control_String (UPDATE_NODE_FILE); if (str_ptr != NULL) { update_flag = update_node_flag = true; Print (1); update_node_file.File_Type ("Update Node File"); if (!update_node_file.Open (Project_Filename (str_ptr))) { Error ("Opening %s", update_node_file.File_Type ()); } } //---- update link range ---- str_ptr = Get_Control_String (UPDATE_LINK_RANGE); if (str_ptr != NULL) { update_flag = true; Print (2, "Update Link Range = %s", str_ptr); if (!update_links.Add_Ranges (str_ptr)) { Error ("Adding Update Links"); } } //---- update link file ---- str_ptr = Get_Control_String (UPDATE_LINK_FILE); if (str_ptr != NULL) { update_flag = update_link_flag = true; Print (1); update_link_file.File_Type ("Update Link File"); if (!update_link_file.Open (Project_Filename (str_ptr))) { Error ("Opening %s", update_link_file.File_Type ()); } } //---- delete node range ---- str_ptr = Get_Control_String (DELETE_NODE_RANGE); if (str_ptr != NULL) { delete_flag = true; Print (2, "Delete Node Range = %s", str_ptr); if (!delete_nodes.Add_Ranges (str_ptr)) { Error ("Adding Delete Nodes"); } } //---- delete node file ---- str_ptr = Get_Control_String (DELETE_NODE_FILE); if (str_ptr != NULL) { delete_flag = delete_node_flag = true; Print (1); delete_node_file.File_Type ("Delete Node File"); if (!delete_node_file.Open (Project_Filename (str_ptr))) { Error ("Opening %s", delete_node_file.File_Type ()); } } //---- delete link range ---- str_ptr = Get_Control_String (DELETE_LINK_RANGE); if (str_ptr != NULL) { delete_flag = true; Print (2, "Delete Link Range = %s", str_ptr); if (!delete_links.Add_Ranges (str_ptr)) { Error ("Adding Delete Links"); } } //---- delete link file ---- str_ptr = Get_Control_String (DELETE_LINK_FILE); if (str_ptr != NULL) { delete_flag = delete_link_flag = true; Print (1); delete_link_file.File_Type ("Delete Link File"); if (!delete_link_file.Open (Project_Filename (str_ptr))) { Error ("Opening %s", delete_link_file.File_Type ()); } } //---- link detail file ---- str_ptr = Get_Control_String (LINK_DETAIL_FILE); if (str_ptr != NULL) { Print (1); detail_flag = true; if (!detail_file.Open (Project_Filename (str_ptr))) { Error ("Opening %s", detail_file.File_Type ()); } lane_use_flag = Network_File_Flag (NEW_LANE_USE); } //---- get the projection data ---- projection.Read_Control (); coord.Set_Projection (projection.Input_Projection (), projection.Output_Projection ()); Set_Projection (&coord); return; //---- error message ---- control_error: Error ("Missing Control Key = %s", Current_Key ()); type_error: Error ("Adding Area Type Record"); }
int CDispOptsFontsPage::LogicalSizeToPoints(int nLogSize) { CWindowDC dc(this); int nPoints = Round((Abs(nLogSize) / (float)::GetDeviceCaps(dc, LOGPIXELSY)) * 72); return nPoints; }
unsigned short CDlgCreateVacuumPatch::GetPathWidth() { return (unsigned short)Round(m_edtPathWidth * cTPI); }
void Text::UpdateCharLocations() { // Remember the font face to see if it's still valid when it's time to render FontFace* face = font_ ? font_->GetFace(fontSize_) : nullptr; if (!face) return; fontFace_ = face; auto rowHeight = RoundToInt(rowSpacing_ * rowHeight_); // Store position & size of each character, and locations per texture page unsigned numChars = unicodeText_.Size(); charLocations_.Resize(numChars + 1); pageGlyphLocations_.Resize(face->GetTextures().Size()); for (unsigned i = 0; i < pageGlyphLocations_.Size(); ++i) pageGlyphLocations_[i].Clear(); IntVector2 offset = font_->GetTotalGlyphOffset(fontSize_); unsigned rowIndex = 0; unsigned lastFilled = 0; float x = Round(GetRowStartPosition(rowIndex) + offset.x_); float y = Round(offset.y_); for (unsigned i = 0; i < printText_.Size(); ++i) { CharLocation loc; loc.position_ = Vector2(x, y); unsigned c = printText_[i]; if (c != '\n') { const FontGlyph* glyph = face->GetGlyph(c); loc.size_ = Vector2(glyph ? glyph->advanceX_ : 0, rowHeight_); if (glyph) { // Store glyph's location for rendering. Verify that glyph page is valid if (glyph->page_ < pageGlyphLocations_.Size()) pageGlyphLocations_[glyph->page_].Push(GlyphLocation(x, y, glyph)); x += glyph->advanceX_; if (i < printText_.Size() - 1) x += face->GetKerning(c, printText_[i + 1]); } } else { loc.size_ = Vector2::ZERO; x = GetRowStartPosition(++rowIndex); y += rowHeight; } if (lastFilled > printToText_[i]) lastFilled = printToText_[i]; // Fill gaps in case characters were skipped from printing for (unsigned j = lastFilled; j <= printToText_[i]; ++j) charLocations_[j] = loc; lastFilled = printToText_[i] + 1; } // Store the ending position charLocations_[numChars].position_ = Vector2(x, y); charLocations_[numChars].size_ = Vector2::ZERO; charLocationsDirty_ = false; }
/***************************************************************************** Function name: InitConstants() Purpose : Initialize constants and settings for DHSVM run Processes the following sections in InFile: [OPTIONS] [AREA] [TIME] [CONSTANTS} Required : LISTPTR Input - Linked list with input strings OPTIONSTRUCT *Options - Structure with different program options MAPSIZE *Map - Coverage and resolution of model area SOLARGEOMETRY *SolarGeo - Solar geometry information TIMESTRUCT *Time - Begin and end times, model timestep Returns : void Modifies : (see list of required above) Comments : *****************************************************************************/ void InitConstants(LISTPTR Input, OPTIONSTRUCT * Options, MAPSIZE * Map, SOLARGEOMETRY * SolarGeo, TIMESTRUCT * Time) { int i; /* counter */ double PointModelX; /* X-coordinate for POINT model mode */ double PointModelY; /* Y-coordinate for POINT model mode */ float TimeStep; /* Timestep in hours */ DATE End; /* End of run */ DATE Start; /* Start of run */ STRINIENTRY StrEnv[] = { {"OPTIONS", "FORMAT", "", ""}, {"OPTIONS", "EXTENT", "", ""}, {"OPTIONS", "GRADIENT", "", ""}, {"OPTIONS", "FLOW ROUTING", "", ""}, {"OPTIONS", "SENSIBLE HEAT FLUX", "", ""}, {"OPTIONS", "SEDIMENT", "", ""}, {"OPTIONS", "SEDIMENT INPUT FILE", "", ""}, {"OPTIONS", "OVERLAND ROUTING", "", ""}, {"OPTIONS", "INFILTRATION", "", ""}, {"OPTIONS", "INTERPOLATION", "", ""}, {"OPTIONS", "MM5", "", ""}, {"OPTIONS", "QPF", "", ""}, {"OPTIONS", "PRISM", "", ""}, {"OPTIONS", "CANOPY RADIATION ATTENUATION MODE", "", ""}, {"OPTIONS", "SHADING", "", ""}, {"OPTIONS", "SNOTEL", "", ""}, {"OPTIONS", "OUTSIDE", "", ""}, {"OPTIONS", "RHOVERRIDE", "", ""}, {"OPTIONS", "PRECIPITATION SOURCE", "", ""}, {"OPTIONS", "WIND SOURCE", "", ""}, {"OPTIONS", "TEMPERATURE LAPSE RATE", "", ""}, {"OPTIONS", "PRECIPITATION LAPSE RATE", "", ""}, {"OPTIONS", "CRESSMAN RADIUS", "", ""}, {"OPTIONS", "CRESSMAN STATIONS", "", ""}, {"OPTIONS", "PRISM DATA PATH", "", ""}, {"OPTIONS", "PRISM DATA EXTENSION", "", ""}, {"OPTIONS", "SHADING DATA PATH", "", ""}, {"OPTIONS", "SHADING DATA EXTENSION", "", ""}, {"OPTIONS", "SKYVIEW DATA PATH", "", ""}, {"OPTIONS", "STREAM TEMPERATURE", "", ""}, {"OPTIONS", "CANOPY SHADING", "", ""}, {"AREA", "COORDINATE SYSTEM", "", ""}, {"AREA", "EXTREME NORTH", "", ""}, {"AREA", "EXTREME WEST", "", ""}, {"AREA", "CENTER LATITUDE", "", ""}, {"AREA", "CENTER LONGITUDE", "", ""}, {"AREA", "TIME ZONE MERIDIAN", "", ""}, {"AREA", "NUMBER OF ROWS", "", ""}, {"AREA", "NUMBER OF COLUMNS", "", ""}, {"AREA", "GRID SPACING", "", ""}, {"AREA", "POINT NORTH", "", ""}, {"AREA", "POINT EAST", "", ""}, {"TIME", "TIME STEP", "", ""}, {"TIME", "MODEL START", "", ""}, {"TIME", "MODEL END", "", ""}, {"CONSTANTS", "GROUND ROUGHNESS", "", ""}, {"CONSTANTS", "SNOW ROUGHNESS", "", ""}, {"CONSTANTS", "RAIN THRESHOLD", "", ""}, {"CONSTANTS", "SNOW THRESHOLD", "", ""}, {"CONSTANTS", "SNOW WATER CAPACITY", "", ""}, {"CONSTANTS", "REFERENCE HEIGHT", "", ""}, {"CONSTANTS", "RAIN LAI MULTIPLIER", "", ""}, {"CONSTANTS", "SNOW LAI MULTIPLIER", "", ""}, {"CONSTANTS", "MIN INTERCEPTED SNOW", "", ""}, {"CONSTANTS", "OUTSIDE BASIN VALUE", "", ""}, {"CONSTANTS", "TEMPERATURE LAPSE RATE", "", ""}, {"CONSTANTS", "PRECIPITATION LAPSE RATE", "", ""}, {"CONSTANTS", "PRECIPITATION MULTIPLIER", "", ""}, {NULL, NULL, "", NULL} }; /* Read the key-entry pairs from the input file */ for (i = 0; StrEnv[i].SectionName; i++) GetInitString(StrEnv[i].SectionName, StrEnv[i].KeyName, StrEnv[i].Default, StrEnv[i].VarStr, (unsigned long) BUFSIZE, Input); /**************** Determine model options ****************/ /* Determine file format to be used */ if (strncmp(StrEnv[format].VarStr, "BIN", 3) == 0) Options->FileFormat = BIN; else if (strncmp(StrEnv[format].VarStr, "NETCDF", 3) == 0) Options->FileFormat = NETCDF; else if (strncmp(StrEnv[format].VarStr, "BYTESWAP", 3) == 0) Options->FileFormat = BYTESWAP; else ReportError(StrEnv[format].KeyName, 51); /* Determine whether the model should be run in POINT mode or in BASIN mode. If in POINT mode also read which pixel to model */ if (strncmp(StrEnv[extent].VarStr, "POINT", 5) == 0) { Options->Extent = POINT; Options->HasNetwork = FALSE; } else if (strncmp(StrEnv[extent].VarStr, "BASIN", 5) == 0) { Options->Extent = BASIN; } else ReportError(StrEnv[extent].KeyName, 51); /* Determine how the flow gradient should be calculated */ if (Options->Extent != POINT) { if (strncmp(StrEnv[gradient].VarStr, "TOPO", 4) == 0) Options->FlowGradient = TOPOGRAPHY; else if (strncmp(StrEnv[gradient].VarStr, "WATER", 5) == 0) Options->FlowGradient = WATERTABLE; else ReportError(StrEnv[gradient].KeyName, 51); } else Options->FlowGradient = NOT_APPLICABLE; /* Determine what meterological interpolation to use */ if (strncmp(StrEnv[interpolation].VarStr, "INVDIST", 7) == 0) Options->Interpolation = INVDIST; else if (strncmp(StrEnv[interpolation].VarStr, "NEAREST", 7) == 0) Options->Interpolation = NEAREST; else if (strncmp(StrEnv[interpolation].VarStr, "VARCRESS", 8) == 0) Options->Interpolation = VARCRESS; else ReportError(StrEnv[interpolation].KeyName, 51); /* if VARIABLE CRESTMAN interpolation then get parameters */ if (Options->Interpolation == VARCRESS) { if (!CopyInt(&(Options->CressRadius), StrEnv[cressman_radius].VarStr, 1)) ReportError(StrEnv[cressman_radius].KeyName, 51); if (!CopyInt (&(Options->CressStations), StrEnv[cressman_stations].VarStr, 1)) ReportError(StrEnv[cressman_stations].KeyName, 51); } /* Determine whether a road/network is imposed on the model area */ if (Options->Extent != POINT) { if (strncmp(StrEnv[flow_routing].VarStr, "NETWORK", 7) == 0) Options->HasNetwork = TRUE; else if (strncmp(StrEnv[flow_routing].VarStr, "UNIT", 4) == 0) Options->HasNetwork = FALSE; else ReportError(StrEnv[flow_routing].KeyName, 51); } else Options->HasNetwork = FALSE; /* Determine whether a sensible heat flux should be calculated */ if (strncmp(StrEnv[sensible_heat_flux].VarStr, "TRUE", 4) == 0) Options->HeatFlux = TRUE; else if (strncmp(StrEnv[sensible_heat_flux].VarStr, "FALSE", 5) == 0) Options->HeatFlux = FALSE; else ReportError(StrEnv[sensible_heat_flux].KeyName, 51); /* Determine whether sediment model should be run */ if (strncmp(StrEnv[sediment].VarStr, "TRUE", 4) == 0) Options->Sediment = TRUE; else if (strncmp(StrEnv[sediment].VarStr, "FALSE", 5) == 0){ printf("WARNING: Sediment option has not been chosen. All erosion\n"); printf("options are being turned off.\n\n"); Options->Sediment = FALSE; Options->MassWaste = FALSE; Options->SurfaceErosion = FALSE; Options->ErosionPeriod = FALSE; } else ReportError(StrEnv[sediment].KeyName, 51); if(Options->Sediment == TRUE) { if (IsEmptyStr(StrEnv[sed_input_file].VarStr)) ReportError(StrEnv[sed_input_file].KeyName, 51); strcpy(Options->SedFile, StrEnv[sed_input_file].VarStr); } /* Determine overland flow routing method to use */ if (strncmp(StrEnv[routing].VarStr, "KINEMATIC", 9) == 0) Options->Routing = TRUE; else if (strncmp(StrEnv[routing].VarStr, "CONVENTIONAL", 12) == 0) Options->Routing = FALSE; else ReportError(StrEnv[routing].KeyName, 51); /* Determine if the maximum infiltration rate is static or dynamic */ if (strncmp(StrEnv[infiltration].VarStr, "STATIC", 6) == 0) { Options->Infiltration = STATIC; } else if (strncmp(StrEnv[infiltration].VarStr, "DYNAMIC", 7) == 0) { Options->Infiltration = DYNAMIC ; printf("WARNING: Dynamic maximum infiltration capacity has\n"); printf("not been fully tested. It is a work in progress.\n\n"); } else ReportError(StrEnv[infiltration].KeyName, 51); /* Determine whether the mm5 interface should be used */ if (strncmp(StrEnv[mm5].VarStr, "TRUE", 4) == 0) Options->MM5 = TRUE; else if (strncmp(StrEnv[mm5].VarStr, "FALSE", 5) == 0) Options->MM5 = FALSE; else ReportError(StrEnv[mm5].KeyName, 51); /* Determine whether the QPF override should be used on the MM5 fields */ if (strncmp(StrEnv[qpf].VarStr, "TRUE", 4) == 0) Options->QPF = TRUE; else if (strncmp(StrEnv[qpf].VarStr, "FALSE", 5) == 0) Options->QPF = FALSE; else ReportError(StrEnv[qpf].KeyName, 51); /* Determine if PRISM maps will be used to interpolate precip fields */ if (strncmp(StrEnv[prism].VarStr, "TRUE", 4) == 0) Options->Prism = TRUE; else if (strncmp(StrEnv[prism].VarStr, "FALSE", 5) == 0) Options->Prism = FALSE; else ReportError(StrEnv[prism].KeyName, 51); /* Determine the kind of canopy radiation attenuation to be used */ if (strncmp(StrEnv[canopy_radatt].VarStr, "FIXED", 3) == 0) Options->CanopyRadAtt = FIXED; else if (strncmp(StrEnv[canopy_radatt].VarStr, "VARIABLE", 3) == 0) Options->CanopyRadAtt = VARIABLE; else ReportError(StrEnv[canopy_radatt].KeyName, 51); /* Determine if solar shading maps will be used */ if (strncmp(StrEnv[shading].VarStr, "TRUE", 4) == 0) Options->Shading = TRUE; else if (strncmp(StrEnv[shading].VarStr, "FALSE", 5) == 0) Options->Shading = FALSE; else ReportError(StrEnv[shading].KeyName, 51); if (Options->MM5 == TRUE && Options->Prism == TRUE && Options->QPF == FALSE) ReportError(StrEnv[prism].KeyName, 51); /* Determine if Snotel test is called for */ if (strncmp(StrEnv[snotel].VarStr, "TRUE", 4) == 0) Options->Snotel = TRUE; else if (strncmp(StrEnv[snotel].VarStr, "FALSE", 5) == 0) Options->Snotel = FALSE; else ReportError(StrEnv[snotel].KeyName, 51); /* Determine if STREAM TEMP is called for */ if (strncmp(StrEnv[stream_temp].VarStr, "TRUE", 4) == 0) Options->StreamTemp = TRUE; else if (strncmp(StrEnv[stream_temp].VarStr, "FALSE", 5) == 0) Options->StreamTemp = FALSE; else ReportError(StrEnv[stream_temp].KeyName, 51); /* Determine if CANOPY SHADING is called for */ if (strncmp(StrEnv[canopy_shading].VarStr, "TRUE", 4) == 0) { Options->CanopyShading = TRUE; if (Options->StreamTemp == FALSE) { printf("Stream temp module must be turned on to allow canopy shading options\n"); exit(-1); } } else if (strncmp(StrEnv[canopy_shading].VarStr, "FALSE", 5) == 0) Options->CanopyShading = FALSE; else ReportError(StrEnv[canopy_shading].KeyName, 51); /* Determine if listed met stations outside bounding box are used */ if (strncmp(StrEnv[outside].VarStr, "TRUE", 4) == 0) Options->Outside = TRUE; else if (strncmp(StrEnv[outside].VarStr, "FALSE", 5) == 0) Options->Outside = FALSE; else ReportError(StrEnv[outside].KeyName, 51); if (Options->Prism == TRUE) { if (IsEmptyStr(StrEnv[prism_data_path].VarStr)) ReportError(StrEnv[prism_data_path].KeyName, 51); strcpy(Options->PrismDataPath, StrEnv[prism_data_path].VarStr); if (IsEmptyStr(StrEnv[prism_data_ext].VarStr)) ReportError(StrEnv[prism_data_ext].KeyName, 51); strcpy(Options->PrismDataExt, StrEnv[prism_data_ext].VarStr); } if (Options->Shading == TRUE) { if (IsEmptyStr(StrEnv[shading_data_path].VarStr)) ReportError(StrEnv[shading_data_path].KeyName, 51); strcpy(Options->ShadingDataPath, StrEnv[shading_data_path].VarStr); if (IsEmptyStr(StrEnv[shading_data_ext].VarStr)) ReportError(StrEnv[shading_data_ext].KeyName, 51); strcpy(Options->ShadingDataExt, StrEnv[shading_data_ext].VarStr); if (IsEmptyStr(StrEnv[skyview_data_path].VarStr)) ReportError(StrEnv[skyview_data_path].KeyName, 51); strcpy(Options->SkyViewDataPath, StrEnv[skyview_data_path].VarStr); } /* Determine if rh override is used */ if (strncmp(StrEnv[rhoverride].VarStr, "TRUE", 4) == 0) Options->Rhoverride = TRUE; else if (strncmp(StrEnv[rhoverride].VarStr, "FALSE", 5) == 0) Options->Rhoverride = FALSE; else ReportError(StrEnv[rhoverride].KeyName, 51); /* The other met options are only of importance if MM5 is FALSE */ if (Options->MM5 == TRUE) { Options->PrecipType = NOT_APPLICABLE; Options->WindSource = NOT_APPLICABLE; Options->PrecipLapse = NOT_APPLICABLE; Options->TempLapse = NOT_APPLICABLE; if (Options->QPF == TRUE) Options->PrecipType = STATION; if (Options->QPF == TRUE && Options->Prism == FALSE) Options->PrecipLapse = CONSTANT; } else { /* Determine the type of precipitation data that the model will use */ if (strncmp(StrEnv[precipitation_source].VarStr, "RADAR", 5) == 0) Options->PrecipType = RADAR; else if (strncmp(StrEnv[precipitation_source].VarStr, "STATION", 7) == 0) Options->PrecipType = STATION; else ReportError(StrEnv[precipitation_source].KeyName, 51); /* Determine the type of wind data that the model will use */ if (strncmp(StrEnv[wind_source].VarStr, "MODEL", 5) == 0) Options->WindSource = MODEL; else if (strncmp(StrEnv[wind_source].VarStr, "STATION", 7) == 0) Options->WindSource = STATION; else ReportError(StrEnv[wind_source].KeyName, 51); /* Determine the type of temperature lapse rate */ if (strncmp(StrEnv[temp_lapse].VarStr, "CONSTANT", 8) == 0) Options->TempLapse = CONSTANT; else if (strncmp(StrEnv[temp_lapse].VarStr, "VARIABLE", 8) == 0) Options->TempLapse = VARIABLE; else ReportError(StrEnv[temp_lapse].KeyName, 51); /* Determine the type of precipitation lapse rate */ if (strncmp(StrEnv[precip_lapse].VarStr, "CONSTANT", 8) == 0) Options->PrecipLapse = CONSTANT; else if (strncmp(StrEnv[precip_lapse].VarStr, "MAP", 3) == 0) Options->PrecipLapse = MAP; else if (strncmp(StrEnv[precip_lapse].VarStr, "VARIABLE", 8) == 0) Options->PrecipLapse = VARIABLE; else ReportError(StrEnv[precip_lapse].KeyName, 51); } /**************** Determine areal extent ****************/ if (IsEmptyStr(StrEnv[coordinate_system].VarStr)) ReportError(StrEnv[coordinate_system].KeyName, 51); strcpy(Map->System, StrEnv[coordinate_system].VarStr); if (!CopyDouble(&(Map->Yorig), StrEnv[extreme_north].VarStr, 1)) ReportError(StrEnv[extreme_north].KeyName, 51); if (!CopyDouble(&(Map->Xorig), StrEnv[extreme_west].VarStr, 1)) ReportError(StrEnv[extreme_west].KeyName, 51); if (!CopyFloat(&(SolarGeo->Latitude), StrEnv[center_latitude].VarStr, 1)) ReportError(StrEnv[center_latitude].KeyName, 51); SolarGeo->Latitude *= (float) RADPDEG; if (!CopyFloat(&(SolarGeo->Longitude), StrEnv[center_longitude].VarStr, 1)) ReportError(StrEnv[center_longitude].KeyName, 51); SolarGeo->Longitude *= (float) RADPDEG; if (!CopyFloat(&(SolarGeo->StandardMeridian), StrEnv[time_zone_meridian].VarStr, 1)) ReportError(StrEnv[time_zone_meridian].KeyName, 51); SolarGeo->StandardMeridian *= (float) RADPDEG; if (!CopyInt(&(Map->NY), StrEnv[number_of_rows].VarStr, 1)) ReportError(StrEnv[number_of_rows].KeyName, 51); if (!CopyInt(&(Map->NX), StrEnv[number_of_columns].VarStr, 1)) ReportError(StrEnv[number_of_columns].KeyName, 51); if (!CopyFloat(&(Map->DY), StrEnv[grid_spacing].VarStr, 1)) ReportError(StrEnv[grid_spacing].KeyName, 51); Map->DX = Map->DY; Map->DXY = (float) sqrt(Map->DX * Map->DX + Map->DY * Map->DY); Map->X = 0; Map->Y = 0; Map->OffsetX = 0; Map->OffsetY = 0; Map->NumCells = 0; if (Options->Extent == POINT) { if (!CopyDouble(&PointModelY, StrEnv[point_north].VarStr, 1)) ReportError(StrEnv[point_north].KeyName, 51); if (!CopyDouble(&PointModelX, StrEnv[point_east].VarStr, 1)) ReportError(StrEnv[point_east].KeyName, 51); Options->PointY = Round(((Map->Yorig - 0.5 * Map->DY) - PointModelY) / Map->DY); Options->PointX = Round((PointModelX - (Map->Xorig + 0.5 * Map->DX)) / Map->DX); } else { Options->PointY = 0; Options->PointX = 0; } /**************** Determine model period ****************/ if (!CopyFloat(&(TimeStep), StrEnv[time_step].VarStr, 1)) ReportError(StrEnv[time_step].KeyName, 51); TimeStep *= SECPHOUR; if (!SScanDate(StrEnv[model_start].VarStr, &(Start))) ReportError(StrEnv[model_start].KeyName, 51); if (!SScanDate(StrEnv[model_end].VarStr, &(End))) ReportError(StrEnv[model_end].KeyName, 51); InitTime(Time, &Start, &End, NULL, NULL, (int) TimeStep); /**************** Determine model constants ****************/ if (!CopyFloat(&Z0_GROUND, StrEnv[ground_roughness].VarStr, 1)) ReportError(StrEnv[ground_roughness].KeyName, 51); if (!CopyFloat(&Z0_SNOW, StrEnv[snow_roughness].VarStr, 1)) ReportError(StrEnv[snow_roughness].KeyName, 51); if (!CopyFloat(&MIN_RAIN_TEMP, StrEnv[rain_threshold].VarStr, 1)) ReportError(StrEnv[rain_threshold].KeyName, 51); if (!CopyFloat(&MAX_SNOW_TEMP, StrEnv[snow_threshold].VarStr, 1)) ReportError(StrEnv[snow_threshold].KeyName, 51); if (!CopyFloat(&LIQUID_WATER_CAPACITY, StrEnv[snow_water_capacity].VarStr, 1)) ReportError(StrEnv[snow_water_capacity].KeyName, 51); if (!CopyFloat(&Zref, StrEnv[reference_height].VarStr, 1)) ReportError(StrEnv[reference_height].KeyName, 51); if (!CopyFloat(&LAI_WATER_MULTIPLIER, StrEnv[rain_lai_multiplier].VarStr, 1)) ReportError(StrEnv[rain_lai_multiplier].KeyName, 51); if (!CopyFloat(&LAI_SNOW_MULTIPLIER, StrEnv[snow_lai_multiplier].VarStr, 1)) ReportError(StrEnv[snow_lai_multiplier].KeyName, 51); if (!CopyFloat(&MIN_INTERCEPTION_STORAGE, StrEnv[min_intercepted_snow].VarStr, 1)) ReportError(StrEnv[min_intercepted_snow].KeyName, 51); if (!CopyUChar(&OUTSIDEBASIN, StrEnv[outside_basin].VarStr, 1)) ReportError(StrEnv[outside_basin].KeyName, 51); if (Options->TempLapse == CONSTANT) { if (!CopyFloat(&TEMPLAPSE, StrEnv[temp_lapse_rate].VarStr, 1)) ReportError(StrEnv[temp_lapse_rate].KeyName, 51); } else TEMPLAPSE = NOT_APPLICABLE; if (Options->PrecipLapse == CONSTANT) { if (!CopyFloat(&PRECIPLAPSE, StrEnv[precip_lapse_rate].VarStr, 1)) ReportError(StrEnv[precip_lapse_rate].KeyName, 51); } else PRECIPLAPSE = NOT_APPLICABLE; if (!CopyFloat(&PRECIPMULTIPLIER, StrEnv[precip_multiplier].VarStr, 1)) ReportError(StrEnv[precip_multiplier].KeyName, 51); }
/******************************************************************************* Function name: InitStations() Purpose : Read the station information from the options file. This information is in the [METEOROLOGY] section Required : LISTPTR Input - Linked list with input strings MAPSIZE *Map - Information about the basin area int NDaysSteps - Number of time steps in a day int *NStats - Number of met stations METLOCATION **Stat - Information about each met station Returns : void Modifies : NStats, Stat and members of Stat Comments : *****************************************************************************/ void InitStations(LISTPTR Input, MAPSIZE * Map, int NDaySteps, OPTIONSTRUCT * Options, int *NStats, METLOCATION ** Stat) { int i; int j; int k; char tempfilename[BUFSIZE + 1]; char KeyName[station_file + 1][BUFSIZE + 1]; char *KeyStr[] = { "STATION NAME", "NORTH COORDINATE", "EAST COORDINATE", "ELEVATION", "STATION FILE" }; char *SectionName = "METEOROLOGY"; char VarStr[station_file + 1][BUFSIZE + 1]; float East; float North; FILE *PrismStatFile; /* Get the number of different stations */ GetInitString(SectionName, "NUMBER OF STATIONS", "", VarStr[0], (unsigned long) BUFSIZE, Input); if (!CopyInt(NStats, VarStr[0], 1)) ReportError("NUMBER OF STATIONS", 51); if (*NStats <= 0) ReportError("Input Options File", 6); printf("\nEvaluating %d Met stations for inclusion\n", *NStats); /* Allocate memory for the stations */ if (!(*Stat = (METLOCATION *) calloc(*NStats, sizeof(METLOCATION)))) ReportError("Input Options File", 1); /* Read key-entry pairs for each station from the input file */ /* for each potential station, up to NStats, read in the data and */ /* determine if it is in the current model bounding box */ /* If it is then put it into memory, otherwise, forget about it */ /* unless Outside option is TRUE, then include it anyway */ /* use temp counter k to track number of valid stations */ k = 0; for (i = 0; i < *NStats; i++) { for (j = 0; j <= station_file; j++) { sprintf(KeyName[j], "%s %d", KeyStr[j], i + 1); GetInitString(SectionName, KeyName[j], "", VarStr[j], (unsigned long) BUFSIZE, Input); } /* Assign the entries to the variables */ if (IsEmptyStr(VarStr[station_name])) ReportError(KeyName[number_of_maps], 51); strcpy((*Stat)[k].Name, VarStr[station_name]); if (!CopyFloat(&North, VarStr[station_north], 1)) ReportError(KeyName[station_north], 51); if (!CopyFloat(&East, VarStr[station_east], 1)) ReportError(KeyName[station_east], 51); (*Stat)[k].Loc.N = Round(((Map->Yorig - 0.5 * Map->DY) - North) / Map->DY); (*Stat)[k].Loc.E = Round((East - (Map->Xorig + 0.5 * Map->DX)) / Map->DX); if (!CopyFloat(&((*Stat)[k].Elev), VarStr[station_elev], 1)) ReportError(KeyName[station_elev], 51); if (IsEmptyStr(VarStr[station_file])) ReportError(KeyName[station_file], 51); strcpy((*Stat)[k].MetFile.FileName, VarStr[station_file]); OpenFile(&((*Stat)[k].MetFile.FilePtr), (*Stat)[k].MetFile.FileName, "r", FALSE); /* check to see if the stations are inside the bounding box */ if (((*Stat)[k].Loc.N > Map->NY || (*Stat)[k].Loc.N < 0 || (*Stat)[k].Loc.E > Map->NX || (*Stat)[k].Loc.E < 0) && Options->Outside == FALSE) /* ReportError((*Stat)[i].Name,10); */ printf("Station %d outside bounding box: %s ignored\n", i + 1, (*Stat)[k].Name); else k = k + 1; } if (Options->Outside == FALSE) printf("Final number of stations in bounding box is %d \n\n", k); else printf("Forced to include all %d stations \n", k); *NStats = k; if (Options->Outside == TRUE && Options->Prism == TRUE) { for (i = 0; i < *NStats; i++) { sprintf(tempfilename, "%s.prism", (*Stat)[i].MetFile.FileName); /* Options->PrismDataExt); */ OpenFile(&PrismStatFile, tempfilename, "rt", FALSE); for (k = 0; k < 12; k++) { fscanf(PrismStatFile, "%f ", &(*Stat)[i].PrismPrecip[k]); } fclose(PrismStatFile); } } }
void Network_Service::Read_Schedule (void) { int i, route, time, stop, last_route, first_stop, nrun, nstop, index, npoints, tim; int num_runs, max_runs, num; bool stop_flag; Line_Data *line_ptr = NULL; Schedule_File *file = (Schedule_File *) Network_Db_File (TRANSIT_SCHEDULE); if (!Network_Data_Flag (TRANSIT_ROUTE)) { Error (file_error, "Transit Route", file->File_ID ()); } stop_flag = Network_Data_Flag (TRANSIT_STOP); if (Check_Data () || Renumber ()) { if (!Network_File_Flag (TRANSIT_STOP) && Network_Option_Flag (TRANSIT_STOP)) { Error (file_error, "Transit Stop", file->File_ID ()); } } Show_Message ("Reading %s -- Record", file->File_Type ()); //---- scan for number of runs per route ---- last_route = first_stop = nrun = nstop = npoints = num_runs = max_runs = 0; while (file->Read ()) { route = file->Route (); if (route == 0) continue; //---- check the stop data ---- stop = file->Stop (); if (stop_flag) { index = stop_data.Get_Index (stop); if (index == 0) { Check_Message ("Stop %d on Route %d was Not Found in the Stop File", stop, route); continue; } if (Renumber ()) stop = index; } if (route != last_route) { if (last_route > 0) { if (!line_ptr->Runs (nrun)) goto mem_error; if (nrun > max_runs) max_runs = nrun; num_runs += nrun; } first_stop = stop; last_route = route; nrun = 1; nstop = 1; line_ptr = line_data.Get (route); if (line_ptr == NULL) { Check_Message ("Transit Route %d was Not Found in the Route File", route); continue; } stop = line_ptr->Stop (1); if (first_stop != stop) { if (Renumber ()) stop = stop_data [stop]->ID (); Check_Message ("Transit Route %d First Stop %d Schedule was Not Found", route, stop); continue; } } else { for (nstop++; nstop <= line_ptr->Stops (); nstop++) { if (stop == line_ptr->Stop (nstop)) break; } if (nstop > line_ptr->Stops ()) { nstop = 1; if (stop == first_stop) { nrun++; } else { Check_Message ("Stop %d was Not Found on Route %d", file->Stop (), route); continue; } nstop = i = 1; } } } if (last_route > 0) { if (!line_ptr->Runs (nrun)) goto mem_error; if (nrun > max_runs) max_runs = nrun; num_runs += nrun; } file->Rewind (); line_data.Num_Runs (num_runs); line_data.Max_Runs (max_runs); //---- store the transit schedule data ---- Set_Progress (); last_route = first_stop = num = 0; nrun = nstop = 1; while (file->Read ()) { Show_Progress (); route = file->Route (); if (route == 0) continue; //---- check the stop id ---- stop = file->Stop (); if (Renumber ()) { stop = stop_data.Get_Index (stop); } time = Round (file->Time ()); //---- check for a new route ---- if (route != last_route) { first_stop = stop; last_route = route; nrun = nstop = i = 1; line_ptr = line_data.Get (route); } else { //---- find the stop id on the route ---- for (i=nstop; i <= line_ptr->Stops (); i++) { if (line_ptr->Stop (i) == stop) break; } if (i > line_ptr->Stops ()) { if (stop == first_stop) nrun++; nstop = i = 1; } } //---- add the time point ---- line_ptr->Schedule (nrun, i, time); num++; //---- interpolate time points ---- if (i > nstop) { if (nstop == 1) { Check_Message ("Stop %d is Not the First Stop for Route %d", file->Stop (), route); continue; } index = i; tim = line_ptr->Schedule (nrun, nstop-1); time = (time - tim) / (index - nstop + 1); for (i=nstop; i < index; i++) { tim += time; line_ptr->Schedule (nrun, i, tim); npoints++; } nstop = index; } nstop++; } End_Progress (); file->Close (); line_data.Schedule_Records (Progress_Count ()); Print (2, "Number of %s Records = %d", file->File_Type (), Progress_Count ()); if (num && num != Progress_Count ()) { Print (1, "Number of Transit Schedule Data Records = %d", num); } if (npoints > 0) { Print (1, "Number of Interpolated Time Points = %d", npoints); } if (num > 0) Network_Data_True (TRANSIT_SCHEDULE); return; mem_error: Error ("Insufficient Memory for %d Runs on Route %d", nrun, last_route); }
void CRMLandScape::Sprinkle(CCMPatch *patch, CCGHeightDetails *hd, int level) { int i, count, px, py; float density; vec3_t origin, scale, angles, bounds[2]; refEntity_t refEnt; CRandomModel *rm; CArea area; // int areaTypes[] = { AT_BSP, AT_OBJECTIVE }; TCGMiscEnt *data = (TCGMiscEnt *)cl.mSharedMemory; TCGTrace *td = (TCGTrace *)cl.mSharedMemory; // memset(&refEnt, 0, sizeof(refEntity_t)); px = patch->GetHeightMapX() / common->GetTerxels(); py = patch->GetHeightMapY() / common->GetTerxels(); // Get a number -5.3f to 5.3f density = (mDensityMap[px + (common->GetBlockWidth() * py)] - 128) / 24.0f; // ..and multiply that into the count count = Round(common->GetPatchScalarSize() * hd->GetAverageFrequency() * powf(2.0f, density) * 0.001); for(i = 0; i < count; i++) { if(!common->irand(0, 10)) { vec3_t temp; float average; rm = hd->GetRandomModel(common); refEnt.hModel = re.RegisterModel(rm->GetModelName()); refEnt.frame = 0; re.ModelBoundsRef(&refEnt, bounds[0], bounds[1]); // Calculate the scale using some magic to help ensure that the // scales are never too different from eachother. Otherwise you // could get an entity that is really small on one axis but huge // on another. temp[0] = common->flrand(rm->GetMinScale(), rm->GetMaxScale()); temp[1] = common->flrand(rm->GetMinScale(), rm->GetMaxScale()); temp[2] = common->flrand(rm->GetMinScale(), rm->GetMaxScale()); // Average of the three random numbers and divide that by two average = ( ( temp[0] + temp[1] + temp[2] ) / 3) / 2; // Add in half of the other two numbers and then subtract half the average to prevent. // any number from going beyond the range. If all three numbers were the same then // they would remain unchanged after this calculation. scale[0] = temp[0] + (temp[1]+temp[2]) / 2 - average; scale[1] = temp[1] + (temp[0]+temp[2]) / 2 - average; scale[2] = temp[2] + (temp[0]+temp[1]) / 2 - average; angles[0] = 0.0f; angles[1] = common->flrand(-M_PI, M_PI); angles[2] = 0.0f; VectorCopy(patch->GetMins(), origin); origin[0] += common->flrand(0.0f, common->GetPatchWidth()); origin[1] += common->flrand(0.0f, common->GetPatchHeight()); // Get above world height float slope = common->GetWorldHeight(origin, bounds, true); if (slope > 1.33) { // spot has too steep of a slope continue; } if(origin[2] < common->GetWaterHeight()) { continue; } // very that we aren't dropped too low if (origin[2] < common->CalcWorldHeight(level)) { continue; } // Hack-ariffic, don't allow them to drop below the big player clip brush. if (origin[2] < 1280 ) { continue; } // FIXME: shouldn't be using a hard-coded 1280 number, only allow to spawn if inside player clip brush? // if( !(CONTENTS_PLAYERCLIP & VM_Call( cgvm, CG_POINT_CONTENTS )) ) // { // continue; // } // Simple radius check for buildings /* area.Init(origin, VectorLength(bounds[0])); if(common->AreaCollision(&area, areaTypes, sizeof(areaTypes) / sizeof(int))) { continue; }*/ // Make sure there is no architecture around - doesn't work for ents though =( memset(td, sizeof(*td), 0); VectorCopy(origin, td->mStart); VectorCopy(bounds[0], td->mMins); VectorCopy(bounds[1], td->mMaxs); VectorCopy(origin, td->mEnd); td->mSkipNumber = -1; td->mMask = MASK_PLAYERSOLID; VM_Call( cgvm, CG_TRACE ); if(td->mResult.surfaceFlags & SURF_NOMISCENTS) { continue; } if(td->mResult.startsolid) { // continue; } // Get minimum height of area common->GetWorldHeight(origin, bounds, false); // Account for relative origin origin[2] -= bounds[0][2] * scale[2]; origin[2] -= common->flrand(2.0, (bounds[1][2] - bounds[0][2]) / 4); // Spawn the client model strcpy(data->mModel, rm->GetModelName()); VectorCopy(origin, data->mOrigin); VectorCopy(angles, data->mAngles); VectorCopy(scale, data->mScale); VM_Call( cgvm, CG_MISC_ENT); mModelCount++; } } }