void ComputeTask(DBObjRecord *record, size_t taskId) { size_t i; DBPosition pos; DBCoordinate coord; pos.Row = taskId / GridIF->ColNum(); pos.Col = taskId % GridIF->ColNum(); GridIF->Pos2Coord(pos, coord); for (i = 0; i < VarNum; ++i) GrdVar[i]->GetVariable(record, coord); for (i = 0; i < ExpNum; ++i) Expressions[i]->Evaluate(record); GridIF->Value(LayerRec, pos, Operand->Float(record)); }
DBObjData *Compute(char *title, CMthreadUserExecFunc userFunc) { DBInt i, layerID, dataLayerID; size_t threadId; DBPosition pos; DBCoordinate coord; char *layerName; DBObjData *data; DBObjRecord *record; size_t threadsNum = CMthreadProcessorNum(); CMthreadTeam_t team; CMthreadJob_p job = (CMthreadJob_p) NULL; if (CMthreadTeamInitialize(&team, threadsNum) == (CMthreadTeam_p) NULL) { CMmsgPrint (CMmsgUsrError,"Team initialization error %s, %d",__FILE__,__LINE__); return ((DBObjData *) NULL); } if ((data = DBGridCreate(title, Extent, CellSize)) == (DBObjData *) NULL) return ((DBObjData *) NULL); data->Projection(GrdVar[0]->Projection()); // Taking projection from first grid variable GridIF = new DBGridIF(data); if (team.ThreadNum > 0) { if ((job = CMthreadJobCreate(GridIF->RowNum() * GridIF->ColNum(), userFunc, (void *) this)) == (CMthreadJob_p) NULL) { CMmsgPrint(CMmsgAppError, "Job creation error in %s:%d", __FILE__, __LINE__); CMthreadTeamDestroy(&team); return ((DBObjData *) NULL); } for (threadId = 0; threadId < team.ThreadNum; ++threadId) if (Table->Add("TEMPRecord") == (DBObjRecord *) NULL) { CMthreadTeamDestroy(&team); return ((DBObjData *) NULL); } } else { if ((record = Table->Add("TEMPRecord")) == (DBObjRecord *) NULL) return ((DBObjData *) NULL); } for (layerID = 0; layerID < LayerNum; ++layerID) { layerName = GrdVar[MasterVar]->CurrentLayer(layerID); for (i = 0; i < (DBInt) VarNum; ++i) { if ((dataLayerID = GrdVar[i]->FindLayer(layerName)) != DBFault) GrdVar[i]->CurrentLayer(dataLayerID); else { if (GrdVar[i]->LayerIsDated(0)) continue; GrdVar[i]->CurrentLayer(dataLayerID); } } if (layerID > 0) GridIF->AddLayer((char *) "New Layer"); LayerRec = GridIF->Layer(layerID); GridIF->RenameLayer(LayerRec, layerName); if (job != (CMthreadJob_p) NULL) CMthreadJobExecute(&team, job); else for (pos.Row = 0; pos.Row < GridIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < GridIF->ColNum(); ++pos.Col) { GridIF->Pos2Coord(pos, coord); for (i = 0; i < (DBInt) VarNum; ++i) GrdVar[i]->GetVariable(record, coord); for (i = 0; i < (DBInt) ExpNum; ++i) Expressions[i]->Evaluate(record); GridIF->Value(LayerRec, pos, Operand->Float(record)); } GridIF->RecalcStats(LayerRec); } delete GridIF; CMthreadTeamDestroy(&team); return (data); }