static void _RGISGrpPanelNewCBK (Widget widget,RGISGrpPanel *grpPanel,XmAnyCallbackStruct *callData) { char *groupName; DBDataset *dataset = UIDataset (); DBObjData *dbData = dataset->Data (); DBObjTable *groupTable = dbData->Table (DBrNGroups); DBObjTableField *group; DBObjRecord *record; if ((groupName = UIGetString ((char *) "Group Name",16)) == (char *) NULL) return; if (groupTable == (DBObjTable *) NULL) { DBObjTable *items = dbData->Table (DBrNItems); DBObjectLIST<DBObjTable> *tables = dbData->Tables (); DBTableFieldDefinition fieldDefs [] = { DBTableFieldDefinition (groupName, DBTableFieldInt,(char *) "%1d",sizeof (DBByte)), DBTableFieldDefinition () }; tables->Add (groupTable = new DBObjTable (DBrNGroups,fieldDefs)); grpPanel->Groups (groupTable->Fields ()); group = groupTable->Field (groupName); for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) group->Int (groupTable->Add (record->Name ()),true); } else { groupTable->AddField (group = new DBObjTableField (groupName,DBTableFieldInt,"%1d",sizeof (DBByte))); for (record = groupTable->First ();record != (DBObjRecord *) NULL;record = groupTable->Next ()) group->Int (record,true); } grpPanel->Add (group); }
void DBVLineIF::Vertexes (DBObjRecord *lineRec,DBCoordinate *coord,DBInt vertexNum) { DBInt vertex; DBFloat length = 0; DBCoordinate *vertexes, prevCoord; DBObjRecord *dataRec = (DBObjRecord *) NULL; DBObjectLIST<DBObjRecord> *dataArrays = Data ()->Arrays (); DBRegion lineExtent, dataExtent = Data ()->Extent (); DBMathDistanceFunction distFunc = DBMathGetDistanceFunction (Data ()); prevCoord = NodeCoordFLD->Coordinate (FromNodeFLD->Record (lineRec)); lineExtent.Expand (prevCoord); if (vertexNum > 0) { if ((dataRec = dataArrays->Item (lineRec->RowID ())) == (DBObjRecord *) NULL) { if ((dataRec = new DBObjRecord (lineRec->Name (),((size_t) vertexNum) * sizeof (DBCoordinate),sizeof (DBFloat))) == (DBObjRecord *) NULL) return; dataArrays->Add (dataRec); } else dataRec->Realloc (vertexNum * sizeof (DBCoordinate)); if ((vertexes = (DBCoordinate *) dataRec->Data ()) == NULL) { CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return; } for (vertex = 0;vertex < vertexNum;vertex++) { lineExtent.Expand (vertexes [vertex] = coord [vertex]); length += DBMathCoordinateDistance (distFunc,prevCoord,coord [vertex]); prevCoord = coord [vertex]; } } VertexesFLD->Record (lineRec,dataRec); VertexNumFLD->Int (lineRec,vertexNum); length += DBMathCoordinateDistance (distFunc,prevCoord,NodeCoordFLD->Coordinate (ToNodeFLD->Record (lineRec))); PerimeterFLD->Float (lineRec,length); lineExtent.Expand (NodeCoordFLD->Coordinate (ToNodeFLD->Record (lineRec))); ExtentFLD->Region (lineRec,lineExtent); dataExtent.Expand (lineExtent); Data ()->Extent (dataExtent); }
void RGISAnalyseLineMSampleGridCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBInt layerID, layerNum; DBCoordinate coord; DBFloat realValue; DBDataset *dataset = UIDataset (); DBObjData *dbData = dataset->Data (); DBObjData *grdData = dbData->LinkedData (); DBObjData *tblData; DBObjTable *table, *itemTable = dbData->Table (DBrNItems); DBObjTableField *lineIDFLD; DBObjTableField *layerIDFLD; DBObjTableField *layerNameFLD; DBObjTableField *fromValueFLD = (DBObjTableField *) NULL; DBObjTableField *toValueFLD = (DBObjTableField *) NULL; DBVLineIF *lineIF = (DBVLineIF *) NULL; DBGridIF *gridIF; DBObjRecord *record, *layerRec, *tblRec; DBObjectLIST<DBObjTableField> *fields; widget = widget; callData = callData; gridIF = new DBGridIF (grdData); for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); if ((layerRec->Flags () & DBObjectFlagIdle) != DBObjectFlagIdle) ++layerNum; } if (layerNum < 1) { CMmsgPrint (CMmsgAppError, "No Layer to Process in: %s %d",__FILE__,__LINE__); delete gridIF; return; } tblData = new DBObjData ("",DBTypeTable); tblData->Document (DBDocGeoDomain,dbData->Document (DBDocGeoDomain)); tblData->Document (DBDocSubject,grdData->Document (DBDocSubject)); if (UIDataHeaderForm (tblData) == false) { delete gridIF; delete tblData; return; } table = tblData->Table (DBrNItems); lineIF = new DBVLineIF (dbData); table->AddField (lineIDFLD = new DBObjTableField ("GHAASPointID",DBTableFieldInt, "%8d",sizeof (DBInt))); table->AddField (layerIDFLD = new DBObjTableField ("LayerID", DBTableFieldInt, "%4d",sizeof (DBShort))); table->AddField (layerNameFLD = new DBObjTableField ("LayerName", DBTableFieldString,"%s",DBStringLength)); table->AddField (fromValueFLD = new DBObjTableField (RGISLineFromNodeValue,DBTableFieldFloat,gridIF->ValueFormat (),sizeof (DBFloat4))); table->AddField (toValueFLD = new DBObjTableField (RGISLineToNodeValue,DBTableFieldFloat,gridIF->ValueFormat (),sizeof (DBFloat4))); grdData->Flags (DBObjectFlagProcessed,DBSet); UIPauseDialogOpen ((char *) "Sampling Grid(s)"); for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); if ((layerRec->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue; for (record = itemTable->First ();record != (DBObjRecord *) NULL;record = itemTable->Next ()) { if (UIPause ((layerRec->RowID () * itemTable->ItemNum () + record->RowID ()) * 100 / (itemTable->ItemNum () * gridIF->LayerNum ()))) goto Stop; if ((record->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue; tblRec = table->Add (record->Name ()); lineIDFLD->Int (tblRec,record->RowID () + 1); layerIDFLD->Int (tblRec,layerRec->RowID ()); layerNameFLD->String (tblRec,layerRec->Name ()); coord = lineIF->FromCoord (record); if (gridIF->Value (layerRec,coord,&realValue)) fromValueFLD->Float (tblRec,realValue); coord = lineIF->ToCoord (record); if (gridIF->Value (layerRec,coord,&realValue)) toValueFLD->Float (tblRec,realValue); } } Stop: UIPauseDialogClose (); delete gridIF; delete lineIF; fields = new DBObjectLIST<DBObjTableField> ("Field List"); fields->Add (new DBObjTableField (*lineIDFLD)); fields->Add (new DBObjTableField (*layerIDFLD)); table->ListSort (fields); workspace->CurrentData (tblData); delete fields; }
int DBImportARCLine (DBObjData *vecData,const char *arcCov) { FILE *inFile; DBInt arcNum, vertex, swap = DBByteOrder (DBByteOrderLITTLE), floatCov; char fileName [DBDataFileNameLen], objName [DBStringLength]; short infoHeader [50]; DBARCRecord arcRecord; DBObjTable *lines; DBObjTable *nodes; DBObjectLIST<DBObjRecord> *data; DBObjRecord *lineRec, *nodeRec, *dataRec; DBRegion dataExtent = vecData->Extent (), itemExtent; DBObjTableField *fromNodeFLD; DBObjTableField *toNodeFLD; DBObjTableField *leftPolyFLD; DBObjTableField *rightPolyFLD; DBObjTableField *vertexesFLD; DBObjTableField *vertexNumFLD; DBObjTableField *extentFLD; DBObjTableField *coordFLD; DBObjTableField *linkNumFLD; DBCoordinate *vertexes, nodeCoord; DBFloat4 floatVAR [2]; switch (vecData->Type ()) { case DBTypeVectorLine: lines = vecData->Table (DBrNItems); break; case DBTypeVectorPolygon: lines = vecData->Table (DBrNContours); break; default: CMmsgPrint (CMmsgAppError, "Invalide Vector Data Type in: %s %d",__FILE__,__LINE__); return (DBFault); } fromNodeFLD = lines->Field (DBrNFromNode); toNodeFLD = lines->Field (DBrNToNode); leftPolyFLD = lines->Field (DBrNLeftPoly); rightPolyFLD= lines->Field (DBrNRightPoly); vertexesFLD = lines->Field (DBrNVertexes); vertexNumFLD= lines->Field (DBrNVertexNum); extentFLD = lines->Field (DBrNRegion); nodes = vecData->Table (DBrNNodes); coordFLD = nodes->Field (DBrNCoord); linkNumFLD = nodes->Field (DBrNLinkNum); data = vecData->Arrays (); sprintf (fileName,"%s/arc",arcCov); if (access (fileName,R_OK) == DBFault) sprintf (fileName,"%s/arc.adf",arcCov); if ((inFile = fopen (fileName,"r")) == NULL) { CMmsgPrint (CMmsgSysError, "File Opening Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (fread (infoHeader,sizeof (short),50,inFile) != 50) { CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } arcNum = 0; for (lineRec = lines->First ();arcRecord.Read (inFile,swap) != DBFault;lineRec = lines->Next ()) { if (lineRec == NULL) { sprintf (objName,"Line: %5d",arcRecord.ID () + 1); if ((lineRec = lines->Add (objName)) == (DBObjRecord *) NULL) return (DBFault); } else DBPause ((++arcNum * 100) / lines->ItemNum ()); floatCov = arcRecord.RecordLength () - 12 == arcRecord.NumOfPnts () * (DBInt) sizeof (float) ? true : false; while (arcRecord.FromNode () > nodes->ItemNum ()) { sprintf (objName,"Node: %5d",nodes->ItemNum () + 1); nodes->Add (objName); if ((nodeRec = nodes->Item ()) == NULL) return (DBFault); linkNumFLD->Int (nodeRec,0); } if ((nodeRec = nodes->Item (arcRecord.FromNode () - 1)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Node Not Found in: %s %d",__FILE__,__LINE__); return (DBFault); } if (floatCov) { if (fread (floatVAR,sizeof (floatVAR),1,inFile) != 1) { CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) { DBByteOrderSwapWord (floatVAR); DBByteOrderSwapWord (floatVAR + 1); } nodeCoord.X = (DBFloat) floatVAR [0]; nodeCoord.Y = (DBFloat) floatVAR [1]; } else { if (fread (&nodeCoord,sizeof (DBCoordinate),1,inFile) != 1) { CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) nodeCoord.Swap (); } coordFLD->Coordinate (nodeRec,nodeCoord); fromNodeFLD->Record (lineRec,nodeRec); if (leftPolyFLD != (DBObjTableField *) NULL) leftPolyFLD->Record (lineRec,arcRecord.LeftPoly ()); if (rightPolyFLD != (DBObjTableField *) NULL) rightPolyFLD->Record (lineRec,arcRecord.RightPoly ()); itemExtent.LowerLeft = nodeCoord; itemExtent.UpperRight = nodeCoord; linkNumFLD->Int (nodeRec,linkNumFLD->Int (nodeRec) + 1); if (arcRecord.NumOfPnts () > 2) { if ((dataRec = data->Item (lineRec->RowID ())) == (DBObjRecord *) NULL) { if ((dataRec = new DBObjRecord ("LineData",0,sizeof (DBFloat))) == (DBObjRecord *) NULL) return (DBFault); data->Add (dataRec); } dataRec->Realloc ((arcRecord.NumOfPnts () - 2) * sizeof (DBCoordinate)); if ((vertexes = (DBCoordinate *) dataRec->Data ()) == NULL) { CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (floatCov) for (vertex = 0;vertex < arcRecord.NumOfPnts () - 2;++vertex) { if (fread (floatVAR,sizeof (floatVAR),1,inFile) != 1) { CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) { DBByteOrderSwapWord (floatVAR); DBByteOrderSwapWord (floatVAR + 1); } vertexes [vertex].X = (DBFloat) floatVAR [0]; vertexes [vertex].Y = (DBFloat) floatVAR [1]; dataExtent.Expand (vertexes [vertex]); itemExtent.Expand (vertexes [vertex]); } else for (vertex = 0;vertex < arcRecord.NumOfPnts () - 2;++vertex) { if (fread (vertexes + vertex,sizeof (DBCoordinate),1,inFile) != 1) { CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) vertexes [vertex].Swap (); dataExtent.Expand (vertexes [vertex]); itemExtent.Expand (vertexes [vertex]); } vertexesFLD->Record (lineRec,dataRec); } else vertexesFLD->Record (lineRec,(DBObjRecord *) NULL); vertexNumFLD->Int (lineRec,arcRecord.NumOfPnts () - 2); while (arcRecord.ToNode () > nodes->ItemNum ()) { sprintf (objName,"Node: %5d",nodes->ItemNum () + 1); nodes->Add (objName); if ((nodeRec = nodes->Item ()) == NULL) return (DBFault); linkNumFLD->Int (nodeRec,0); } if ((nodeRec = nodes->Item (arcRecord.ToNode () - 1)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Node Not Found in: %s %d",__FILE__,__LINE__); return (DBFault); } if (floatCov) { if (fread (floatVAR,sizeof (floatVAR),1,inFile) != 1) { CMmsgPrint (CMmsgAppError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) { DBByteOrderSwapWord (floatVAR); DBByteOrderSwapWord (floatVAR + 1); } nodeCoord.X = (DBFloat) floatVAR [0]; nodeCoord.Y = (DBFloat) floatVAR [1]; } else { if (fread (&nodeCoord,sizeof (DBCoordinate),1,inFile) != 1) { CMmsgPrint (CMmsgAppError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) nodeCoord.Swap (); } itemExtent.Expand (nodeCoord); coordFLD->Coordinate (nodeRec,nodeCoord); linkNumFLD->Int (nodeRec,linkNumFLD->Int (nodeRec) + 1); toNodeFLD->Record (lineRec,nodeRec); extentFLD->Region (lineRec,itemExtent); } fclose (inFile); vertexesFLD->RecordProp ((DBInt) sizeof (DBFloat)); vecData->Extent (dataExtent); vecData->Projection (DBMathGuessProjection (dataExtent)); return (DBSuccess); }
UI2DView::UI2DView () : DBObject ("Noname 2DView",sizeof (UI2DView)) { char name [DBStringLength]; Widget menuBar, scrolledWindow, radioBox; Widget button; static Pixmap iconPixmap = (Pixmap) NULL, meshPixmap = (Pixmap) NULL; static Pixmap fullPixmap = (Pixmap) NULL, extentPixmap = (Pixmap) NULL; static Pixmap capturePixmap = (Pixmap) NULL, redrawPixmap = (Pixmap) NULL; static Pixmap zoomPixmap = (Pixmap) NULL, panePixmap = (Pixmap) NULL, userPixmap = (Pixmap) NULL; Pixel foreground, background; XWindowAttributes xwa; XSetWindowAttributes xswa; Atom deleteWindowAtom = XmInternAtom(XtDisplay(UITopLevel ()),(char *) "WM_DELETE_WINDOW",FALSE); _UI2DViewLIST.Add (this); sprintf (name,"2DView:%2d",RowID ()); Name (name); Image = (XImage *) NULL; DrawRegion = FullRegion = NULL; MaxVertexNumVAR = 0; PointARR = (XPoint *) NULL; RequiredEXT = (UIDataset ())->Extent (); DShell = XtVaCreatePopupShell ("UI2DView",xmDialogShellWidgetClass,UITopLevel (), XmNkeyboardFocusPolicy, XmPOINTER, XmNtitle, Name (), XmNtransient, false, XmNminWidth, 600, XmNminHeight, 450, NULL); XmAddWMProtocolCallback (DShell,deleteWindowAtom,(XtCallbackProc) _UI2DViewDeleteCBK,(XtPointer) this); MainFormW = XtVaCreateManagedWidget ("UI2DViewForm",xmFormWidgetClass,DShell, XmNdialogStyle, XmDIALOG_WORK_AREA, XmNshadowThickness, 0, XmNwidth, 600, XmNheight, 450, NULL); menuBar = XtVaCreateManagedWidget ("UI2DViewMenuBar",xmRowColumnWidgetClass,MainFormW, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 2, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 2, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 2, XmNorientation, XmHORIZONTAL, XmNrowColumnType, XmWORK_AREA, NULL); XtVaGetValues (MainFormW,XmNforeground, &foreground,XmNbackground, &background,NULL); iconPixmap = iconPixmap == (Pixmap) NULL ? XmGetPixmap(XtScreen (UITopLevel()),(char *) "GHAAS2Dview.bmp",foreground,background): iconPixmap; XtVaSetValues (DShell,XmNiconPixmap, iconPixmap,NULL); fullPixmap = fullPixmap == (Pixmap) NULL ? XmGetPixmap(XtScreen(UITopLevel()),(char *) "GHAASfull.bmp", foreground,background) : fullPixmap; extentPixmap = extentPixmap == (Pixmap) NULL ? XmGetPixmap(XtScreen(UITopLevel()),(char *) "GHAASextent.bmp",foreground,background) : extentPixmap; capturePixmap= capturePixmap == (Pixmap) NULL ? XmGetPixmap(XtScreen(UITopLevel()),(char *) "GHAAScapture.bmp",foreground,background):capturePixmap; redrawPixmap = redrawPixmap == (Pixmap) NULL ? XmGetPixmap(XtScreen(UITopLevel()),(char *) "GHAASredraw.bmp", foreground,background) : redrawPixmap; zoomPixmap = zoomPixmap == (Pixmap) NULL ? XmGetPixmap(XtScreen(UITopLevel()),(char *) "GHAASzoom.bmp", foreground,background) : zoomPixmap; panePixmap = panePixmap == (Pixmap) NULL ? XmGetPixmap(XtScreen(UITopLevel()),(char *) "GHAASpane.bmp", foreground,background) : panePixmap; userPixmap = userPixmap == (Pixmap) NULL ? XmGetPixmap(XtScreen(UITopLevel()),(char *) "GHAASuser.bmp", foreground,background) : userPixmap; meshPixmap = meshPixmap == (Pixmap) NULL ? XmGetPixmap(XtScreen(UITopLevel()),(char *) "GHAASmesh.bmp", foreground,background) : meshPixmap; button = XtVaCreateManagedWidget ("UI2DViewRedrawButton",xmPushButtonGadgetClass,menuBar, XmNlabelType, XmPIXMAP, XmNlabelPixmap, redrawPixmap, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _UI2DViewRedrawCBK,this); button = XtVaCreateManagedWidget ("UI2DViewFullButton",xmPushButtonGadgetClass,menuBar, XmNlabelType, XmPIXMAP, XmNlabelPixmap, fullPixmap, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _UI2DViewFullActivateCBK,this); button = XtVaCreateManagedWidget ("UI2DViewExtentButton",xmPushButtonGadgetClass,menuBar, XmNlabelType, XmPIXMAP, XmNlabelPixmap, extentPixmap, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _UI2DViewExtentActivateCBK,this); button = XtVaCreateManagedWidget ("UI2DViewCaptureButton",xmPushButtonGadgetClass,menuBar, XmNlabelType, XmPIXMAP, XmNlabelPixmap, capturePixmap, NULL); radioBox = XtVaCreateManagedWidget ("UI2DViewRadioBox",xmRowColumnWidgetClass,menuBar, XmNorientation, XmHORIZONTAL, XmNpacking, XmPACK_COLUMN, XmNisHomogeneous, true, XmNentryClass, xmToggleButtonGadgetClass, XmNradioBehavior, true, NULL); ZoomToggle = XtVaCreateManagedWidget ("UI2DViewZoomToggle",xmToggleButtonGadgetClass,radioBox, XmNlabelType, XmPIXMAP, XmNlabelPixmap, zoomPixmap, XmNshadowThickness, 0, XmNset, true, NULL); XtAddCallback (ZoomToggle,XmNvalueChangedCallback,(XtCallbackProc) _UI2DViewZoomToggleValueCBK,this); PaneToggle = XtVaCreateManagedWidget ("UI2DViewPaneToggle",xmToggleButtonGadgetClass,radioBox, XmNlabelType, XmPIXMAP, XmNlabelPixmap, panePixmap, XmNshadowThickness, 0, NULL); XtAddCallback (PaneToggle,XmNvalueChangedCallback,(XtCallbackProc) _UI2DViewPaneToggleValueCBK,this); UserToggle = XtVaCreateWidget ("UI2DViewUserToggle",xmToggleButtonGadgetClass,radioBox, XmNlabelType, XmPIXMAP, XmNlabelPixmap, userPixmap, XmNmappedWhenManaged, false, XmNshadowThickness, 0, NULL); XtAddCallback (UserToggle,XmNvalueChangedCallback,(XtCallbackProc) _UI2DViewUserToggleValueCBK,this); if (_UI2DViewUserFunction != (UI2DViewUserFunction) NULL) XtManageChild (UserToggle); MeshOptionW = XtVaCreateManagedWidget ("UI2DViewMeshOption",xmToggleButtonGadgetClass,menuBar, XmNlabelType, XmPIXMAP, XmNlabelPixmap, meshPixmap, XmNshadowThickness, 0, NULL); XtAddCallback (MeshOptionW,XmNvalueChangedCallback,(XtCallbackProc) _UI2DViewMeshOptionCBK,this); XtVaSetValues (menuBar, XmNmenuHelpWidget, MeshOptionW, NULL); ScaleW = XtVaCreateManagedWidget ("UI2DViewScale",xmScaleWidgetClass,MainFormW, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, menuBar, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 2, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 18, XmNorientation, XmVERTICAL, XmNwidth, 16, NULL); XtAddCallback (ScaleW,XmNvalueChangedCallback,(XtCallbackProc) _UI2DViewScaleValueChangedCBK,this); scrolledWindow = XtVaCreateManagedWidget ("UI2DViewScrolledWindow",xmScrolledWindowWidgetClass,MainFormW, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, menuBar, XmNtopOffset, 2, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, ScaleW, XmNleftOffset, 3, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 3, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 3, XmNspacing, 2, NULL); HorScrollBarW = XtVaCreateManagedWidget ("UI2DViewHorScrollBar", xmScrollBarWidgetClass, scrolledWindow, XmNsliderSize, 100, XmNorientation, XmHORIZONTAL, XmNheight, 16, NULL); XtAddCallback (HorScrollBarW,XmNvalueChangedCallback,(XtCallbackProc) _UI2DViewHorScrollBarValueChangedCBK,this); VerScrollBarW = XtVaCreateManagedWidget ("UI2DViewVerScrollBar", xmScrollBarWidgetClass, scrolledWindow, XmNsliderSize, 100, XmNorientation, XmVERTICAL, XmNwidth, 16, NULL); XtAddCallback (VerScrollBarW,XmNvalueChangedCallback,(XtCallbackProc) _UI2DViewVerScrollBarValueChangedCBK,this); DrawingAreaW = XtVaCreateManagedWidget ("UI2DViewDrawingArea", xmDrawingAreaWidgetClass, scrolledWindow, XmNuserData, this, XmNbackground, UIColor (UIColorStandard,0), NULL); XtAddCallback (DrawingAreaW,XmNresizeCallback,(XtCallbackProc) _UI2DViewResizeCBK,this); XtAddEventHandler (DrawingAreaW,EnterWindowMask|LeaveWindowMask|PointerMotionMask|ButtonPressMask|ButtonReleaseMask, false,(XtEventHandler) _UI2DViewPointerEHR,this); XmScrolledWindowSetAreas(scrolledWindow,HorScrollBarW,VerScrollBarW,DrawingAreaW); _UI2DViewViewCursor = _UI2DViewViewCursor != (Cursor) NULL ? _UI2DViewViewCursor : XCreateFontCursor (XtDisplay (DrawingAreaW),XC_top_left_arrow), _UI2DViewUserCursor = _UI2DViewUserCursor != (Cursor) NULL ? _UI2DViewUserCursor : XCreateFontCursor (XtDisplay (DrawingAreaW),XC_crosshair); RegenCursor = XCreateFontCursor (XtDisplay (DrawingAreaW),XC_watch); ActiveCursor = xswa.cursor = _UI2DViewViewCursor; XChangeWindowAttributes (XtDisplay (DrawingAreaW), XtWindow (DrawingAreaW), CWCursor, &xswa); XGetWindowAttributes (XtDisplay (DrawingAreaW),XtWindow (DrawingAreaW),&xwa); Background = xwa.backing_pixel; xswa.backing_store = Always; XChangeWindowAttributes (XtDisplay (DrawingAreaW), XtWindow (DrawingAreaW),CWBackingStore,&xswa); InputMode (ZOOM_MODE); Size (); Set (); }
int main(int argc, char *argv[]) { int argPos, argNum = argc, ret, fieldNum = 0, verbose = false; char *tableName = (char *) NULL; char *title = (char *) NULL, *subject = (char *) NULL; char *domain = (char *) NULL, *version = (char *) NULL; DBObjData *data; DBObjectLIST<DBObjTableField> *fieldList; DBObjTable *table; DBObjTableField *fieldPTR; CMDtblSortField *fields = (CMDtblSortField *) NULL; for (argPos = 1; argPos < argNum;) { if (CMargTest (argv[argPos], "-a", "--table")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing table name!"); if (fields != (CMDtblSortField *) NULL) free(fields); return (CMfailed); } tableName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-A", "--ascending")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing sort field!"); if (fields != (CMDtblSortField *) NULL) free(fields); return (CMfailed); } if ((fields = (CMDtblSortField *) realloc(fields, (fieldNum + 1) * sizeof(CMDtblSortField))) == (CMDtblSortField *) NULL) { CMmsgPrint(CMmsgSysError, "Memory reallocation error in: %s, %n", __FILE__, __LINE__); return (CMfailed); } fields[fieldNum].FieldName(argv[argPos]); fields[fieldNum].Ascending(true); fieldNum++; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-D", "--descending")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing selection mode!"); if (fields != (CMDtblSortField *) NULL) free(fields); return (CMfailed); } if ((fields = (CMDtblSortField *) realloc(fields, (fieldNum + 1) * sizeof(CMDtblSortField))) == (CMDtblSortField *) NULL) { CMmsgPrint(CMmsgSysError, "Memory reallocation error in: %s, %n", __FILE__, __LINE__); return (CMfailed); } fields[fieldNum].FieldName(argv[argPos]); fields[fieldNum].Ascending(false); fieldNum++; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-t", "--title")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing title!"); return (CMfailed); } title = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-u", "--subject")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing subject!"); return (CMfailed); } subject = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-d", "--domain")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing domain!"); return (CMfailed); } domain = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-v", "--version")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing version!"); return (CMfailed); } version = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-V", "--verbose")) { verbose = true; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-h", "--help")) { CMmsgPrint(CMmsgInfo, "%s [options] <input file> <output file>", CMfileName(argv[0])); CMmsgPrint(CMmsgInfo, " -a,--table [ table name ]"); CMmsgPrint(CMmsgInfo, " -A,--ascending [ fieldname ]"); CMmsgPrint(CMmsgInfo, " -D,--descending [ fieldname ]"); CMmsgPrint(CMmsgInfo, " -t,--title [dataset title]"); CMmsgPrint(CMmsgInfo, " -u,--subject [subject]"); CMmsgPrint(CMmsgInfo, " -d,--domain [domain]"); CMmsgPrint(CMmsgInfo, " -v,--version [version]"); CMmsgPrint(CMmsgInfo, " -V,--verbose"); CMmsgPrint(CMmsgInfo, " -h,--help"); if (fields != (CMDtblSortField *) NULL) free(fields); return (DBSuccess); } if ((argv[argPos][0] == '-') && ((int) strlen(argv[argPos]) > 1)) { CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]); if (fields != (CMDtblSortField *) NULL) free(fields); return (CMfailed); } argPos++; } if (argNum > 3) { CMmsgPrint(CMmsgUsrError, "Extra arguments!"); if (fields != (CMDtblSortField *) NULL) free(fields); return (CMfailed); } if (verbose) RGlibPauseOpen(argv[0]); data = new DBObjData(); if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) { if (fields != (CMDtblSortField *) NULL)free(fields); delete data; return (CMfailed); } if (title != (char *) NULL) data->Name(title); if (subject != (char *) NULL) data->Document(DBDocSubject, subject); if (domain != (char *) NULL) data->Document(DBDocGeoDomain, domain); if (version != (char *) NULL) data->Document(DBDocVersion, version); if (tableName == (char *) NULL) tableName = DBrNItems; if ((table = data->Table(tableName)) == (DBObjTable *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid table!"); if (fields != (CMDtblSortField *) NULL) free(fields); delete data; return (CMfailed); } if (fields != (CMDtblSortField *) NULL) { DBInt fieldID; fieldList = new DBObjectLIST<DBObjTableField>("Fields"); for (fieldID = 0; fieldID < fieldNum; ++fieldID) { if ((fieldPTR = table->Field(fields[fieldID].FieldName())) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid field: %s!", fields[fieldID].FieldName()); free(fields); return (CMfailed); } if (fields[fieldID].Ascending()) fieldPTR->Flags(DBObjectFlagSortReversed, DBClear); else fieldPTR->Flags(DBObjectFlagSortReversed, DBSet); fieldList->Add(new DBObjTableField(*fieldPTR)); } table->ListSort(fieldList); table->ItemSort(); delete fieldList; free(fields); } ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout); delete data; if (verbose) RGlibPauseClose(); return (ret); }
DBInt RGlibPointSubbasinHist(DBObjData *pntData, DBObjData *netData, DBObjData *grdData, DBObjData *tblData) { DBInt layerID, layerNum = 0, progress = 0, maxProgress; DBObjTable *itemTable = grdData->Table(DBrNItems); DBObjTable *table = tblData->Table(DBrNItems); DBObjTableField *pointIDFLD; DBObjTableField *layerIDFLD; DBObjTableField *layerNameFLD; DBObjTableField *categoryIDFLD; DBObjTableField *categoryFLD; DBObjTableField *percentFLD; DBObjTableField *areaFLD; DBObjTableField *cellNumFLD; DBVPointIF *pntIF; DBNetworkIF *netIF; DBObjRecord *pntRec, *itemRec, *tblRec; DBObjectLIST<DBObjTableField> *fields; _RGlibPointGrdIF = new DBGridIF(grdData); for (layerID = 0; layerID < _RGlibPointGrdIF->LayerNum(); ++layerID) { _RGlibPointGrdLayerRec = _RGlibPointGrdIF->Layer(layerID); if ((_RGlibPointGrdLayerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) ++layerNum; } if (layerNum < 1) { CMmsgPrint(CMmsgUsrError, "No Layer to Process!"); delete _RGlibPointGrdIF; return (DBFault); } pntIF = new DBVPointIF(pntData); netIF = new DBNetworkIF(netData); table->AddField(pointIDFLD = new DBObjTableField("GHAASPointID", DBTableFieldInt, "%8d", sizeof(DBInt))); table->AddField(layerIDFLD = new DBObjTableField("LayerID", DBTableFieldInt, "%4d", sizeof(DBShort))); table->AddField(layerNameFLD = new DBObjTableField("LayerName", DBTableFieldString, "%s", DBStringLength)); table->AddField(categoryIDFLD = new DBObjTableField(DBrNCategoryID, DBTableFieldInt, "%2d", sizeof(DBShort))); table->AddField(categoryFLD = new DBObjTableField(DBrNCategory, DBTableFieldString, _RGlibPointGrdIF->ValueFormat(), DBStringLength)); table->AddField(cellNumFLD = new DBObjTableField("CellNum", DBTableFieldInt, "%8d", sizeof(DBInt))); table->AddField(areaFLD = new DBObjTableField(DBrNArea, DBTableFieldFloat, "%10.1f", sizeof(DBFloat4))); table->AddField(percentFLD = new DBObjTableField(DBrNPercent, DBTableFieldFloat, "%6.2f", sizeof(DBFloat4))); _RGlibHistogram = (Histogram *) malloc(itemTable->ItemNum() * sizeof(Histogram)); if (_RGlibHistogram == (Histogram *) NULL) { CMmsgPrint(CMmsgAppError, "Memory Allocation Error in: %s %d", __FILE__, __LINE__); return (DBFault); } maxProgress = pntIF->ItemNum() * _RGlibPointGrdIF->LayerNum(); for (layerID = 0; layerID < _RGlibPointGrdIF->LayerNum(); ++layerID) { _RGlibPointGrdLayerRec = _RGlibPointGrdIF->Layer(layerID); if ((_RGlibPointGrdLayerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; for (pntRec = pntIF->FirstItem(); pntRec != (DBObjRecord *) NULL; pntRec = pntIF->NextItem()) { if (DBPause(progress * 100 / maxProgress)) goto Stop; progress++; if ((pntRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; for (itemRec = itemTable->First(); itemRec != (DBObjRecord *) NULL; itemRec = itemTable->Next()) _RGlibHistogram[itemRec->RowID()].Initialize(); netIF->UpStreamSearch(netIF->Cell(pntIF->Coordinate(pntRec)), (DBNetworkACTION) _RGlibSubbasinCategories); for (itemRec = itemTable->First(); itemRec != (DBObjRecord *) NULL; itemRec = itemTable->Next()) if (_RGlibHistogram[itemRec->RowID()].cellNum > 0) { tblRec = table->Add(pntRec->Name()); pointIDFLD->Int(tblRec, pntRec->RowID() + 1); layerIDFLD->Int(tblRec, _RGlibPointGrdLayerRec->RowID()); layerNameFLD->String(tblRec, _RGlibPointGrdLayerRec->Name()); categoryIDFLD->Int(tblRec, itemRec->RowID() + 1); categoryFLD->String(tblRec, itemRec->Name()); areaFLD->Float(tblRec, _RGlibHistogram[itemRec->RowID()].area); percentFLD->Float(tblRec, _RGlibHistogram[itemRec->RowID()].area / netIF->CellBasinArea(netIF->Cell(pntIF->Coordinate(pntRec))) * 100.0); cellNumFLD->Int(tblRec, _RGlibHistogram[itemRec->RowID()].cellNum); } } } Stop: delete _RGlibPointGrdIF; delete netIF; delete pntIF; free(_RGlibHistogram); if (progress == maxProgress) { fields = new DBObjectLIST<DBObjTableField>("Field List"); fields->Add(new DBObjTableField(*pointIDFLD)); fields->Add(new DBObjTableField(*layerIDFLD)); fields->Add(areaFLD = new DBObjTableField(*areaFLD)); areaFLD->Flags(DBObjectFlagSortReversed, DBSet); table->ListSort(fields); delete fields; return (DBSuccess); } return (DBFault); }
DBInt RGlibPointSubbasinStats(DBObjData *pntData, DBObjData *netData, DBObjData *grdData, DBObjData *tblData) { DBInt layerID, layerNum = 0, progress = 0, maxProgress; DBObjTable *table; DBObjTableField *pointIDFLD; DBObjTableField *layerIDFLD; DBObjTableField *layerNameFLD; DBObjTableField *minimumFLD; DBObjTableField *maximumFLD; DBObjTableField *averageFLD; DBObjTableField *stdDevFLD; DBObjTableField *areaFLD; DBVPointIF *pntIF; DBNetworkIF *netIF; DBObjRecord *pntRec, *tblRec; DBObjectLIST<DBObjTableField> *fields; _RGlibPointGrdIF = new DBGridIF(grdData); for (layerID = 0; layerID < _RGlibPointGrdIF->LayerNum(); ++layerID) { _RGlibPointGrdLayerRec = _RGlibPointGrdIF->Layer(layerID); if ((_RGlibPointGrdLayerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) ++layerNum; } if (layerNum < 1) { CMmsgPrint(CMmsgUsrError, "No Layer to Process!"); delete _RGlibPointGrdIF; return (DBFault); } table = tblData->Table(DBrNItems); pntIF = new DBVPointIF(pntData); netIF = new DBNetworkIF(netData); table->AddField(pointIDFLD = new DBObjTableField("GHAASPointID", DBTableFieldInt, "%8d", sizeof(DBInt))); table->AddField(layerIDFLD = new DBObjTableField("LayerID", DBTableFieldInt, "%4d", sizeof(DBShort))); table->AddField(layerNameFLD = new DBObjTableField("LayerName", DBTableFieldString, "%s", DBStringLength)); table->AddField(averageFLD = new DBObjTableField(RGlibPointMean, DBTableFieldFloat, _RGlibPointGrdIF->ValueFormat(), sizeof(DBFloat4))); table->AddField(minimumFLD = new DBObjTableField(RGlibPointMin, DBTableFieldFloat, _RGlibPointGrdIF->ValueFormat(), sizeof(DBFloat4))); table->AddField(maximumFLD = new DBObjTableField(RGlibPointMax, DBTableFieldFloat, _RGlibPointGrdIF->ValueFormat(), sizeof(DBFloat4))); table->AddField( stdDevFLD = new DBObjTableField(RGlibPointStdDev, DBTableFieldFloat, _RGlibPointGrdIF->ValueFormat(), sizeof(DBFloat4))); table->AddField(areaFLD = new DBObjTableField(RGlibPointArea, DBTableFieldFloat, _RGlibPointGrdIF->ValueFormat(), sizeof(DBFloat4))); grdData->Flags(DBObjectFlagProcessed, DBSet); maxProgress = pntIF->ItemNum() * _RGlibPointGrdIF->LayerNum(); for (layerID = 0; layerID < _RGlibPointGrdIF->LayerNum(); ++layerID) { _RGlibPointGrdLayerRec = _RGlibPointGrdIF->Layer(layerID); if ((_RGlibPointGrdLayerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; for (pntRec = pntIF->FirstItem(); pntRec != (DBObjRecord *) NULL; pntRec = pntIF->NextItem()) { if (DBPause(progress * 100 / maxProgress)) goto Stop; progress++; if ((pntRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; tblRec = table->Add(pntRec->Name()); pointIDFLD->Int(tblRec, pntRec->RowID() + 1); layerIDFLD->Int(tblRec, _RGlibPointGrdLayerRec->RowID()); layerNameFLD->String(tblRec, _RGlibPointGrdLayerRec->Name()); _RGlibSubbasinArea = 0.0; _RGlibSubbasinMin = DBHugeVal; _RGlibSubbasinMax = -DBHugeVal; _RGlibSubbasinMean = 0.0; _RGlibSubbasinStdDev = 0.0; netIF->UpStreamSearch(netIF->Cell(pntIF->Coordinate(pntRec)), (DBNetworkACTION) _RGlibSubbasinStatistics); _RGlibSubbasinMean = _RGlibSubbasinMean / _RGlibSubbasinArea; _RGlibSubbasinStdDev = _RGlibSubbasinStdDev / _RGlibSubbasinArea; _RGlibSubbasinStdDev = _RGlibSubbasinStdDev - _RGlibSubbasinMean * _RGlibSubbasinMean; _RGlibSubbasinStdDev = sqrt(_RGlibSubbasinStdDev); minimumFLD->Float(tblRec, _RGlibSubbasinMin); maximumFLD->Float(tblRec, _RGlibSubbasinMax); averageFLD->Float(tblRec, _RGlibSubbasinMean); stdDevFLD->Float(tblRec, _RGlibSubbasinStdDev); areaFLD->Float(tblRec, _RGlibSubbasinArea); } } Stop: delete _RGlibPointGrdIF; delete netIF; delete pntIF; if (progress == maxProgress) { fields = new DBObjectLIST<DBObjTableField>("Field List"); fields->Add(new DBObjTableField(*pointIDFLD)); fields->Add(new DBObjTableField(*layerIDFLD)); table->ListSort(fields); delete fields; return (DBSuccess); } return (DBFault); }
DBInt RGlibPointInterStationTS(DBObjData *pntData, DBObjData *tsData, char *relateFldName, char *joinFldName) { DBInt first = true, tsIndex, tsRowNum = 0; DBObjTable *pntTBL = pntData->Table(DBrNItems), *tsTBL; DBObjectLIST<DBObjTableField> *fields; DBObjTableField *pntNextFLD = pntTBL->Field(RGlibNextStation); DBObjTableField *pntAreaFLD = pntTBL->Field(RGlibArea); DBObjTableField *pntInterStnFLD = pntTBL->Field(RGlibInterStation); DBObjTableField *pntRelateFLD; DBObjTableField *pntNewNextFLD; DBObjTableField *pntNewInterStnFLD; DBObjTableField *tsTimeFLD; DBObjTableField *tsJoinFLD; DBObjTableField *tsNextStnFLD, *tsInterStnFLD; DBObjRecord *pntRec, *nextPntRec, *tsRec, *tsIndexRec; DBDate curDate, date; if (pntNextFLD == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Missing Next Station Field!"); return (DBFault); } if (pntAreaFLD == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Missing STN Area Field!"); return (DBFault); } if (pntInterStnFLD == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Missing Interfluvial Area Field!"); return (DBFault); } tsTBL = tsData->Table(DBrNItems); tsNextStnFLD = new DBObjTableField(RGlibNextStation, DBTableFieldInt, "%8d", sizeof(DBInt)); tsTBL->AddField(tsNextStnFLD); tsInterStnFLD = new DBObjTableField(RGlibInterStation, DBTableFieldFloat, "%9.1f", sizeof(DBFloat4)); tsTBL->AddField(tsInterStnFLD); fields = tsTBL->Fields(); for (tsTimeFLD = fields->First(); tsTimeFLD != (DBObjTableField *) NULL; tsTimeFLD = fields->Next()) if (tsTimeFLD->Type() == DBTableFieldDate) break; if (tsTimeFLD == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Missing Date Field!"); return (DBFault); } if ((tsJoinFLD = tsTBL->Field(joinFldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Missing Join Field!"); return (DBFault); } fields = new DBObjectLIST<DBObjTableField>("Field List"); fields->Add(new DBObjTableField(*tsTimeFLD)); fields->Add(new DBObjTableField(*tsJoinFLD)); tsTBL->ListSort(fields); delete fields; pntTBL = new DBObjTable(*pntTBL); pntNextFLD = pntTBL->Field(RGlibNextStation); pntAreaFLD = pntTBL->Field(RGlibArea); pntInterStnFLD = pntTBL->Field(RGlibInterStation); pntNewNextFLD = new DBObjTableField("NextStnTS", pntNextFLD->Type(), pntNextFLD->Format(), pntNextFLD->Length()); pntNewInterStnFLD = new DBObjTableField("InterFluTS", pntInterStnFLD->Type(), pntInterStnFLD->Format(), pntInterStnFLD->Length()); pntRelateFLD = pntTBL->Field(relateFldName); pntTBL->AddField(pntNewNextFLD); pntTBL->AddField(pntNewInterStnFLD); pntTBL->ListSort(pntRelateFLD); tsIndexRec = tsTBL->First(&tsIndex); for (tsRec = tsTBL->First(); tsRec != (DBObjRecord *) NULL; tsRec = tsTBL->Next()) { DBPause(tsRowNum++ * 100 / tsTBL->ItemNum()); date = tsTimeFLD->Date(tsRec); if (date != curDate) { if (first) first = false; else { for (pntRec = pntTBL->First(); pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next()) { if ((pntRec->Flags() & DBObjectFlagLocked) != DBObjectFlagLocked) continue; for (nextPntRec = pntTBL->Item(pntNextFLD->Int(pntRec) - 1); (nextPntRec != (DBObjRecord *) NULL) && ((nextPntRec->Flags() & DBObjectFlagLocked) != DBObjectFlagLocked); nextPntRec = pntTBL->Item(pntNextFLD->Int(nextPntRec) - 1)); if (nextPntRec != (DBObjRecord *) NULL) { pntNewNextFLD->Int(pntRec, nextPntRec->RowID() + 1); pntNewInterStnFLD->Float(nextPntRec, pntNewInterStnFLD->Float(nextPntRec) - pntAreaFLD->Float(pntRec)); } } pntRec = pntTBL->First(); for (; tsIndexRec != (DBObjRecord *) NULL; tsIndexRec = tsTBL->Next(&tsIndex)) { if (tsRec == tsIndexRec) break; for (; pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next()) if (pntRelateFLD->Int(pntRec) == tsJoinFLD->Int(tsIndexRec)) { tsNextStnFLD->Int(tsIndexRec, pntNewNextFLD->Int(pntRec)); tsInterStnFLD->Float(tsIndexRec, pntNewInterStnFLD->Float(pntRec)); break; } if (pntRec == (DBObjRecord *) NULL) pntRec = pntTBL->First(); } } for (pntRec = pntTBL->First(); pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next()) { pntNewNextFLD->Int(pntRec, 0); pntNewInterStnFLD->Float(pntRec, pntAreaFLD->Float(pntRec)); pntRec->Flags(DBObjectFlagLocked, DBClear); } curDate = date; pntRec = pntTBL->First(); } for (; pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next()) if (pntRelateFLD->Int(pntRec) == tsJoinFLD->Int(tsRec)) { pntRec->Flags(DBObjectFlagLocked, DBSet); break; } if (pntRec == (DBObjRecord *) NULL) pntRec = pntTBL->First(); } if (!first) { for (pntRec = pntTBL->First(); pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next()) { if ((pntRec->Flags() & DBObjectFlagLocked) != DBObjectFlagLocked) continue; for (nextPntRec = pntTBL->Item(pntNextFLD->Int(pntRec) - 1); (nextPntRec != (DBObjRecord *) NULL) && ((nextPntRec->Flags() & DBObjectFlagLocked) != DBObjectFlagLocked); nextPntRec = pntTBL->Item(pntNextFLD->Int(nextPntRec) - 1)); if (nextPntRec != (DBObjRecord *) NULL) { pntNewNextFLD->Int(pntRec, nextPntRec->RowID() + 1); pntNewInterStnFLD->Float(nextPntRec, pntNewInterStnFLD->Float(nextPntRec) - pntAreaFLD->Float(pntRec)); } } pntRec = pntTBL->First(); for (; tsIndexRec != (DBObjRecord *) NULL; tsIndexRec = tsTBL->Next(&tsIndex)) { if (tsRec == tsIndexRec) break; for (; pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next()) if (pntRelateFLD->Int(pntRec) == tsJoinFLD->Int(tsIndexRec)) { tsNextStnFLD->Int(tsIndexRec, pntNewNextFLD->Int(pntRec)); tsInterStnFLD->Float(tsIndexRec, pntNewInterStnFLD->Float(pntRec)); break; } if (pntRec == (DBObjRecord *) NULL) pntRec = pntTBL->First(); } } delete pntTBL; return (DBSuccess); }
int main (int argc,char *argv []) { int argPos, argNum = argc, numGrpNames = 0, i = 0; char **groupnames, *rename = (char *) NULL, *tableName = (char *) NULL; bool ascii = false; FieldOptions *head = (FieldOptions *) NULL, *p = (FieldOptions *) NULL, *temp = (FieldOptions *) NULL; Groups **groups = (Groups **) NULL; FILE *outFile = (FILE *) NULL; DBObjData *inData, *outData; DBObjTable *inTable, *outTable; DBObjTableField *field; DBObjRecord *inRecord, *outRecord; DBObjectLIST<DBObjTableField> *fields; if(argc <= 2) { doHelp(false,argv[0]); return(DBSuccess); } outData = new DBObjData("Untitled", DBTypeTable); outTable = outData->Table(DBrNItems); head = new FieldOptions(BAD,"","", (FieldOptions *) NULL); groupnames = (char **) malloc(sizeof(char *)); for (argPos = 1;argPos < argNum;) { if (CMargTest(argv[argPos],"-f","--field")) { if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing operation and field after -f!"); return (CMfailed); } if(!strcmp(argv[argPos],"pct")) { if (argNum <= argPos + 2) { CMmsgPrint (CMmsgUsrError,"Missing field and/or percentage after -f pct!"); return (CMfailed); } p = FOHierarchy(argv[argPos],argv[argPos+1],rename,atoi(argv[argPos+2]),head); argNum = CMargShiftLeft(argPos,argv,argNum); argNum = CMargShiftLeft(argPos,argv,argNum); } else if(!strcmp(argv[argPos],"num")) { char *num = new char[4]; strcpy(num,"Num"); p = FOHierarchy(argv[argPos],num,rename,-1,head); } else { if (argNum < argPos + 1) { CMmsgPrint (CMmsgUsrError,"Missing operation or field after -f %s!",argv[argPos]); return (CMfailed); } p = FOHierarchy(argv[argPos],argv[argPos+1],rename,-1,head); argNum = CMargShiftLeft(argPos,argv,argNum); } p->setPrint(true); rename = (char *) NULL; if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest(argv[argPos],"-g","--group")) { if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing groupname!"); return (CMfailed); } if((groupnames = (char **) realloc(groupnames,(numGrpNames + 1) * sizeof(char *))) == (char **) NULL) { CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return(DBFault); } groupnames[numGrpNames] = argv[argPos]; numGrpNames++; if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest(argv[argPos],"-h","--help")) { argNum = CMargShiftLeft (argPos,argv,argNum); if(CMargTest(argv[argPos],"e","extend")) { doHelp(true,argv[0]); argNum = CMargShiftLeft (argPos,argv,argNum); } else doHelp(false,argv[0]); } if (CMargTest(argv[argPos],"-c","--ascii")) { ascii = true; if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest(argv[argPos],"-a","--table")) { if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing table name!"); return (CMfailed); } tableName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest(argv[argPos],"-r","--rename")) { if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing field after -r!"); return (CMfailed); } rename = argv[argPos]; if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest(argv[argPos],"-o","--output")) { if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing output filename!"); return (CMfailed); } if((outFile = fopen(argv[argPos],"w")) == (FILE *) NULL) { CMmsgPrint (CMmsgUsrError,"Cannot open file %s",argv[argPos]); return (CMfailed); } if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest(argv[argPos],"-t","--title")) { if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing title!"); return (CMfailed); } outData->Name(argv[argPos]); if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest(argv[argPos],"-s","--subject")) { if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing subject!"); return (CMfailed); } outData->Document(DBDocSubject,argv[argPos]); if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest(argv[argPos],"-d","--domain")) { if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing domain!"); return (CMfailed); } outData->Document(DBDocGeoDomain,argv[argPos]); if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest(argv[argPos],"-v","--version")) { if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing version!"); return (CMfailed); } outData->Document(DBDocVersion,argv[argPos]); if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break; continue; } if ((argv[argPos][0] == '-') && (strlen (argv[argPos]) > 1)) { CMmsgPrint (CMmsgUsrError, "Unknown option: %s!",argv[argPos]); return (CMfailed); } argPos++; } if(outFile == (FILE *) NULL) outFile = stdout; if(head->next == (FieldOptions *) NULL) return(DBSuccess); inData = new DBObjData(); if ((argNum > 1) && (strcmp(argv[1],"-") != 0)) inData->Read(argv[1]); else inData->Read(stdin); if (outData->Name() == (char *) NULL) outData->Name("Untitled"); if (outData->Document(DBDocSubject) == (char *) NULL) outData->Document(DBDocSubject,inData->Document(DBDocSubject)); if (outData->Document(DBDocGeoDomain) == (char *) NULL) outData->Document(DBDocGeoDomain,inData->Document(DBDocGeoDomain)); if (outData->Document(DBDocVersion) == (char *) NULL) outData->Document(DBDocVersion,inData->Document(DBDocVersion)); if(tableName == (char *) NULL) tableName = DBrNItems; if((inTable = inData->Table(tableName)) == (DBObjTable *) NULL) { CMmsgPrint (CMmsgUsrError,"Invalid table!"); delete inData; return (CMfailed); } if((groups = (Groups **) malloc(numGrpNames * sizeof(Groups *))) == (Groups **) NULL) { CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return(DBFault); } for(i = 0; i < numGrpNames; i++) { if((field = inTable->Field(groupnames[i])) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError, "Invalid group name: %s",groupnames[i]); return (CMfailed); } if(DBTableFieldIsCategory(field)) { groups[i] = new Groups(); groups[i]->srcFLD = field; groups[i]->dstFLD = new DBObjTableField(*field); outTable->AddField(groups[i]->dstFLD); // CMmsgPrint (CMmsgUsrError, "Added Group: %s",groups[i]->dstFLD->Name()); } else CMmsgPrint (CMmsgUsrError, "Group %s is not Category!",groupnames[i]); } delete groupnames; p = head->next; temp = head; while(p->next) { FieldOptions *duplicate = (FieldOptions *) NULL, *prev = p; if(!p->getPrint() && FLDExists(p,p->getOldName(),p->getFunc(),&duplicate)) { temp->next = p->next; delete p; p = temp->next; continue; } while(FLDExists(prev,prev->getOldName(),prev->getFunc(),&prev,&duplicate) && !duplicate->getPrint()) { prev->next = duplicate->next; delete duplicate; } temp = p; p = p->next; } // p = head->next; // while(p) { CMmsgPrint (CMmsgUsrError, "Added: o:%s n:%s p:",p->getOldName(),p->getNewName()); if(p->getPrint()) CMmsgPrint (CMmsgUsrError, "true"); else CMmsgPrint (CMmsgUsrError, "false"); p = p->next; } fields = inTable->Fields(); p = head->next; while(p) { field = fields->Item (p->getOldName()); if (p->getFunc() == MIN || p->getFunc() == MAX) p->field = new DBObjTableField(p->getNewName(),field->Type(),field->Format(),field->Length()); else if(p->getFunc() == NUM || p->getFunc() == NONNULL) p->field = new DBObjTableField(p->getNewName(), DBTableFieldInt, DBHiddenField, sizeof (DBInt)); else p->field = new DBObjTableField(p->getNewName(), DBTableFieldFloat, DBHiddenField, sizeof(DBFloat)); if(p->getFunc() != NUM && p->getFunc() != NONNULL) { // if ((field = inTable->Field(p->getOldName())) == (DBObjTableField *) NULL) if (field == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError, "Invalid field name: %s",p->getOldName()); return(DBFault); } if (!DBTableFieldIsNumeric(field)) { CMmsgPrint (CMmsgUsrError, "Field is not Numeric: %s",p->getOldName()); return(DBFault); } } outTable->AddField(p->field); p = p->next; } // MAKE SURE TO TEST FOR SPEED BY DECLARING INTS OUTSIDE OF FOR LOOPS!!! for (int inRecID = 0;inRecID < inTable->ItemNum();++inRecID) { inRecord = inTable->Item(inRecID); if ((outRecord = FindMatch(inRecord, outTable,(const Groups**) groups, numGrpNames)) != (DBObjRecord *) NULL) { p = head->next; while(p) { field = fields->Item (p->getOldName()); switch(p->getFunc()) { default: break; case NUM: p->field->Int(outRecord,p->field->Int(outRecord) + 1); break; case NONNULL: if (p->isInt()) { if (field->Int(inRecord) != field->IntNoData()) p->field->Int(outRecord,p->field->Int(outRecord) + 1); } else { if (!CMmathEqualValues(field->Float(inRecord),field->FloatNoData())) p->field->Int(outRecord,p->field->Int(outRecord) + 1); } break; case MIN: if (p->isInt()) { if(field->Int(inRecord) != field->IntNoData()) { if (p->field->Int(outRecord) != p->field->IntNoData()) { if (field->Int(inRecord) < p->field->Int(outRecord)) p->field->Int(outRecord,field->Int(inRecord)); } else { p->field->Int(outRecord,field->Int(inRecord)); } } } else { if (!CMmathEqualValues(field->Float(inRecord),field->FloatNoData())) { if (!CMmathEqualValues(p->field->Float(inRecord),p->field->FloatNoData())) { if (field->Float(inRecord) < p->field->Float(outRecord)) p->field->Float(outRecord,field->Float(inRecord)); } else { p->field->Float(outRecord,field->Float(inRecord)); } } } break; case MAX: if (p->isInt()) { if(field->Int(inRecord) != field->IntNoData()) { if (p->field->Int(outRecord) != p->field->IntNoData()) { if (field->Int(inRecord) > p->field->Int(outRecord)) p->field->Int(outRecord,field->Int(inRecord)); } else { p->field->Int(outRecord,field->Int(inRecord)); } } } else { if (!CMmathEqualValues(field->Float(inRecord),field->FloatNoData())) { if (!CMmathEqualValues(p->field->Float(inRecord),p->field->FloatNoData())) { if (field->Float(inRecord) > p->field->Float(outRecord)) p->field->Float(outRecord,field->Float(inRecord)); } else { p->field->Float(outRecord,field->Float(inRecord)); } } } break; case SUM: if (p->isInt()) { if(field->Int(inRecord) != field->IntNoData()) p->field->Int(outRecord,p->field->Int(outRecord) + field->Int(inRecord)); } else { if (!CMmathEqualValues(field->Float(inRecord),field->FloatNoData())) p->field->Float(outRecord,p->field->Float(outRecord) + field->Float(inRecord)); } break; case DEV: case PCT: case MED: p->tailVal = p->tailVal->next = new Values(); p->tailVal->val = field->Float(inRecord); p->tailVal->next = 0; break; case MOD: Values *cur = p->getHead(); while(cur->next && !CMmathEqualValues(cur->val,field->Float(inRecord))) cur = cur->next; if(cur->next) cur->occur++; else { p->tailVal->val = field->Float(inRecord); p->tailVal->occur = 1; p->tailVal = p->tailVal->next = new Values(); } break; } p = p->next; } } else { outRecord = outTable->Add(); for(i = 0; i < numGrpNames; i++) { switch (groups[i]->srcFLD->Type()) { default: case DBTableFieldString: groups[i]->dstFLD->String(outRecord,groups[i]->srcFLD->String(inRecord)); break; case DBTableFieldInt: groups[i]->dstFLD->Int(outRecord,groups[i]->srcFLD->Int(inRecord)); break; } } p = head->next; while(p) { field = fields->Item (p->getOldName()); switch(p->getFunc()) { default: case BAD: break; case NUM: p->setInt(); p->field->Int(outRecord,1); break; case NONNULL: if (field->Type() == DBTableFieldInt) { p->setInt(); if (field->Int(inRecord) != field->IntNoData()) p->field->Int(outRecord,1); else p->field->Int(outRecord,0); } else { if (!CMmathEqualValues(field->Float(inRecord),field->FloatNoData())) p->field->Int(outRecord,1); else p->field->Int(outRecord,0); } break; case MIN: if (field->Type() == DBTableFieldInt) { p->setInt(); if (field->Int(inRecord) != field->IntNoData()) p->field->Int(outRecord,field->Int(inRecord)); } else { if(!CMmathEqualValues(field->Float(inRecord),field->FloatNoData())) p->field->Float(outRecord,field->Float(inRecord)); } break; case MAX: if (field->Type() == DBTableFieldInt) { p->setInt(); if (field->Int(inRecord) != field->IntNoData()) p->field->Int(outRecord,field->Int(inRecord)); } else { if(!CMmathEqualValues(field->Float(inRecord),field->FloatNoData())) p->field->Float(outRecord,field->Float(inRecord)); } break; case SUM: if (field->Type() == DBTableFieldInt) { p->setInt(); if (field->Int(inRecord) != field->IntNoData()) p->field->Int(outRecord,field->Int(inRecord)); else p->field->Int(outRecord,0); } else { if(!CMmathEqualValues(field->Float(inRecord),field->FloatNoData())) p->field->Float(outRecord,field->Float(inRecord)); else p->field->Float(outRecord,0.0); } break; case DEV: case PCT: case MED: p->tailVal = p->tailVal->next = new Values(); p->tailVal->val = field->Float(inRecord); p->tailVal->next = 0; break; case MOD: p->tailVal->val = field->Float(inRecord); p->tailVal->occur = 1; p->tailVal = p->tailVal->next = new Values(); break; } p = p->next; } } } for(int outRecID = 0; outRecID < outTable->ItemNum();++outRecID) { outRecord = outTable->Item(outRecID); p = head->next; FieldOptions *sum, *num; DBFloat mod; int occurrance; float i; bool mult; Values *cur; while(p) { field = fields->Item (p->getOldName()); switch(p->getFunc()) { case AVG: if((FLDExists(head,p->getOldName(),SUM,&sum)) && (FLDExists(head,p->getOldName(),NONNULL,&num))) p->field->Float(outRecord,sum->field->Float(outRecord) / (DBFloat) (num->field->Int(outRecord))); else CMmsgPrint (CMmsgUsrError, "Program Error! Could not find SUM or NONNULL in linked list! Please contact the GHAAS developers group!"); break; case NAVG: if((FLDExists(head,p->getOldName(),SUM,&sum)) && (FLDExists(head,"NUM",NUM,&num))) p->field->Float(outRecord,sum->field->Float(outRecord) / (DBFloat) (num->field->Int(outRecord))); else CMmsgPrint (CMmsgUsrError, "Program Error! Could not find SUM or NUM in linked list! Please contact the GHAAS developers group!"); break; case PCT: case MED: i = (float) (inTable->ItemNum() * p->getHead()->occur * 0.01) - 1; cur = p->getHead()->next; while(i > 0) { cur = cur->next; i--; } p->field->Float(outRecord,(cur->val + cur->next->val) / 2); break; case MOD: mod = 0.0; occurrance = 0; mult = false; cur = p->getHead(); while(cur) { if(cur->occur > occurrance) { mod = cur->val; occurrance = cur->occur; mult = false; } else if(cur->occur == occurrance) mult = true; cur = cur->next; } if(mult) CMmsgPrint (CMmsgUsrError, "** Warning, multiple answers for MOD, listing first found!"); p->field->Float(outRecord,mod); break; default: break; } p = p->next; } } p = head->next; while(p) { if(p->getFunc() == DEV) { FieldOptions *avg, *num; field = fields->Item (p->getOldName()); if((FLDExists(head,p->getOldName(),AVG,&avg)) && (FLDExists(head,"NUM",NUM,&num))) { for(int outRecID = 0; outRecID < outTable->ItemNum();++outRecID) { outRecord = outTable->Item(outRecID); DBFloat sum = 0.0; Values *cur = p->getHead()->next; while(cur) { // sum += (DBFloat) (pow((cur->val - avg->field->Float(outRecord)),2)); DBFloat add = (cur->val - avg->field->Float(outRecord)); sum += (DBFloat) (add * add); cur = cur->next; } sum = sqrt(sum /(DBFloat) num->field->Int(outRecord)); p->field->Float(outRecord,sum); } } else CMmsgPrint (CMmsgUsrError, "Program Error! Could not find AVG or NUM in linked list! Please contact the GHAAS developers group!"); } p = p->next; } // DELETE unnecessary fields which were for temp storage fields = outTable->Fields(); p = head->next; while(p) { if(!p->getPrint()) outTable->DeleteField(fields->Item(p->getNewName())); p = p->next; } p = head->next; while(p) { if ((strcmp(p->field->Format(),DBHiddenField) == 0) && p->getPrint()) { if(p->isInt()) { int maxval = 0; for(int outRecID = 0; outRecID < outTable->ItemNum();++outRecID) { int val = p->field->Int(outTable->Item(outRecID)); if (maxval < val) maxval = val; else if (maxval < -val) maxval = -val; } p->field->Format(DBMathIntAutoFormat(maxval)); } else { float maxval = 0.0; for(int outRecID = 0; outRecID < outTable->ItemNum();++outRecID) { float val = p->field->Float(outTable->Item(outRecID)); if (maxval < val) maxval = val; else if (maxval < -val) maxval = -val; } p->field->Format(DBMathFloatAutoFormat(maxval)); } } // CMmsgPrint (CMmsgUsrError, "Format(%s)%d,%d: '%s'",p->getFuncName(),p->isInt(),p->getPrint(),p->field->Format()); p = p->next; } DBObjectLIST<DBObjTableField> *list = new DBObjectLIST<DBObjTableField> ("Sorted Field List"); for(i = 0; i < numGrpNames; i++) list->Add(groups[i]->dstFLD); outTable->ListSort(list); if (ascii) DBExportASCIITable(outTable,outFile); else outData->Write(outFile); /* CLEANUP ************************************************/ if(outFile != stdout) fclose(outFile); for(i = 0; i < numGrpNames; i++) delete groups[i]->dstFLD; delete groups; p = head; while(p) { head = head->next; delete p; p = head; } return(DBSuccess); }