void Condition_Destroy( Condition *c ) { Lock_Destroy( c->m ); c->m = NULL; host_rtos_deinit_semaphore( c->s ); c->s = NULL; host_rtos_deinit_semaphore( c->x ); c->x = NULL; host_rtos_deinit_semaphore( c->h ); c->h = NULL; }
//--------------------------------------------------------- void CSG_Module_Grid::Lock_Create(void) { if( Get_System()->is_Valid() ) { if( m_pLock && Get_System()->is_Equal(m_pLock->Get_System()) ) { m_pLock->Assign(0.0); } else { Lock_Destroy(); m_pLock = new CSG_Grid( SG_DATATYPE_Char, Get_System()->Get_NX(), Get_System()->Get_NY(), Get_System()->Get_Cellsize(), Get_System()->Get_XMin(), Get_System()->Get_YMin() ); } } }
//--------------------------------------------------------- bool CChannelNetwork::On_Execute(void) { int x, y, ID, Trace_Method, Init_Method; long n; double Init_Threshold; CSG_Grid *Trace_pRoute, *Trace_pWeight, *Init_pGrid; //----------------------------------------------------- pDTM = Parameters("ELEVATION") ->asGrid(); pConvergence = Parameters("DIV_GRID") ->asGrid(); pChannels = Parameters("CHNLNTWRK") ->asGrid(); pChannelRoute = Parameters("CHNLROUTE") ->asGrid(); pShapes = Parameters("SHAPES") ->asShapes(); minLength = Parameters("MINLEN") ->asInt(); maxDivCells = Parameters("DIV_GRID")->asGrid() ? Parameters("DIV_CELLS")->asInt() : -1; //----------------------------------------------------- // 1. Flow Direction... Process_Set_Text(_TL("Channel Network: Pass 1")); pChannels->Assign(); Trace_pRoute = Parameters("SINKROUTE") ->asGrid(); Trace_pWeight = Parameters("TRACE_WEIGHT")->asGrid(); Trace_Method = Trace_pWeight ? 1 : 0; for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { if( Trace_pRoute && (ID = Trace_pRoute->asChar(x, y)) >= 1 && ID <= 8 ) { pChannels->Set_Value(x, y, ID); } else { switch( Trace_Method ) { default: Set_Route_Standard(x, y); break; case 1: Set_Route_Weighted(x, y, Trace_pWeight, 0.0); break; } } } } //----------------------------------------------------- // 2. Initiation... Process_Set_Text(_TL("Channel Network: Pass 2")); pStart = SG_Create_Grid(pDTM, SG_DATATYPE_Char); Init_pGrid = Parameters("INIT_GRID") ->asGrid(); Init_Method = Parameters("INIT_METHOD") ->asInt(); Init_Threshold = Parameters("INIT_VALUE") ->asDouble(); for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++) { switch( Init_Method ) { case 0: if( Init_pGrid->asDouble(n) <= Init_Threshold ) pStart->Set_Value(n, 1); break; case 1: if( Init_pGrid->asDouble(n) == Init_Threshold ) pStart->Set_Value(n, 1); break; case 2: if( Init_pGrid->asDouble(n) >= Init_Threshold ) pStart->Set_Value(n, 1); break; } } //----------------------------------------------------- // 3. Trace Channel Routes... Process_Set_Text(_TL("Channel Network: Pass 3")); pChannelRoute->Assign(); Direction = NULL; Direction_Buffer = 0; for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++) { if( pDTM->Get_Sorted(n,x,y) ) { Set_Channel_Route(x,y); } } if( Direction ) { SG_Free( Direction ); } pChannels->Assign(); delete(pStart); //----------------------------------------------------- Process_Set_Text(_TL("Channel Network: Pass 4")); for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { Set_Channel_Order(x,y); } } //----------------------------------------------------- Process_Set_Text(_TL("Channel Network: Pass 5")); for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { Set_Channel_Mouth(x,y); } } //----------------------------------------------------- if( pShapes ) { Process_Set_Text(_TL("Channel Network: Pass 6")); pShapes->Create(SHAPE_TYPE_Line, _TL("Channel Network")); pShapes->Add_Field("SegmentID" ,SG_DATATYPE_Int); pShapes->Add_Field("Order" ,SG_DATATYPE_Int); pShapes->Add_Field("Length" ,SG_DATATYPE_Double); Lock_Create(); for(y=0, ID=1; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { Set_Vector(x, y, ID++); } } Lock_Destroy(); } //----------------------------------------------------- for(n=0; n<Get_NCells(); n++) { if( pChannels->asInt(n) == 0 ) { pChannels->Set_NoData(n); pChannelRoute->Set_NoData(n); } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- CSG_Module_Grid::~CSG_Module_Grid(void) { Lock_Destroy(); }
//--------------------------------------------------------- bool CPit_Eliminator::On_Execute(void) { bool bResult, bKillRoute; int Method, nPits; CPit_Router Router; //----------------------------------------------------- bResult = true; pRoute = Parameters("SINKROUTE") ->asGrid(); Method = Parameters("METHOD") ->asInt(); pDTM = Parameters("DEM_PREPROC") ->asGrid(); if( pDTM == NULL ) { pDTM = Parameters("DEM")->asGrid(); } else if( pDTM != Parameters("DEM")->asGrid() ) { pDTM->Assign(Parameters("DEM")->asGrid()); } //----------------------------------------------------- bKillRoute = pRoute == NULL; if( bKillRoute ) { pRoute = SG_Create_Grid(pDTM); nPits = Router.Get_Routes(pDTM, pRoute, Parameters("THRESHOLD")->asBool() ? Parameters("THRSHEIGHT")->asDouble() : -1.0); } else { nPits = 1; } //----------------------------------------------------- if( nPits > 0 ) { Process_Set_Text(_TL("Initializing direction matrix...")); Create_goRoute(); //------------------------------------------------- switch( Method ) { case 0: Process_Set_Text(_TL("I'm diggin'...")); bResult = Dig_Channels(); break; case 1: Process_Set_Text(_TL("I'm fillin'...")); bResult = Fill_Sinks(); break; default: bResult = false; break; } delete( goRoute ); } //----------------------------------------------------- if( bKillRoute ) { delete(pRoute); } Lock_Destroy(); return( bResult ); }