Example #1
0
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);
	}
Example #2
0
void RGISAnalysePointSTNCharCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	DBDataset *dataset = UIDataset ();
	DBObjData *dbData = dataset->Data ();
	DBObjTable *pointTable = dbData->Table (DBrNItems);
	DBObjTableField *cellIDFLD			= pointTable->Field (RGlibCellID);
	DBObjTableField *basinFLD			= pointTable->Field (DBrNBasin);
	DBObjTableField *basinNameFLD		= pointTable->Field (RGlibBasinName);
	DBObjTableField *orderFLD			= pointTable->Field (DBrNOrder);
	DBObjTableField *colorFLD			= pointTable->Field (RGlibColor);
	DBObjTableField *basinCellsFLD	= pointTable->Field (RGlibCellNum);
	DBObjTableField *basinLengthFLD	= pointTable->Field (RGlibLength);
	DBObjTableField *basinAreaFLD		= pointTable->Field (RGlibArea);
	DBObjTableField *interAreaFLD		= pointTable->Field (RGlibInterStation);
	DBObjTableField *nextStationFLD	= pointTable->Field (RGlibNextStation);
	UITable *tableCLS = (UITable *) dbData->Display (UITableName (dbData,pointTable));

	UIPauseDialogOpen ((char *) "STN Characteristics");
	if ((RGlibPointSTNCharacteristics (dbData) == DBSuccess) && (tableCLS != (UITable *) NULL))
		{
		if (cellIDFLD      == (DBObjTableField *) NULL) tableCLS->AddField (pointTable->Field (RGlibCellID));
		if (basinFLD       == (DBObjTableField *) NULL) tableCLS->AddField (pointTable->Field (DBrNBasin));
		if (basinNameFLD   == (DBObjTableField *) NULL) tableCLS->AddField (pointTable->Field (RGlibBasinName));
		if (orderFLD       == (DBObjTableField *) NULL) tableCLS->AddField (pointTable->Field (DBrNOrder));
		if (colorFLD       == (DBObjTableField *) NULL) tableCLS->AddField (pointTable->Field (RGlibColor));
		if (basinCellsFLD  == (DBObjTableField *) NULL) tableCLS->AddField (pointTable->Field (RGlibCellNum));
		if (basinLengthFLD == (DBObjTableField *) NULL) tableCLS->AddField (pointTable->Field (RGlibLength));
		if (basinAreaFLD   == (DBObjTableField *) NULL) tableCLS->AddField (pointTable->Field (RGlibArea));
		if (interAreaFLD   == (DBObjTableField *) NULL) tableCLS->AddField (pointTable->Field (RGlibInterStation));
		if (nextStationFLD == (DBObjTableField *) NULL) tableCLS->AddField (pointTable->Field (RGlibNextStation));
		tableCLS->Draw ();
		}
	UIPauseDialogClose ();
	}
Example #3
0
void RGISAnNetworkToGridCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	char *selection;
	DBInt dataType;
	DBDataset *dataset = UIDataset ();
	DBObjData *netData = dataset->Data ();
	DBObjTable *cellTable = netData->Table (DBrNCells);
	DBObjTableField *field;
	DBObjData *grdData;
	static Widget select = NULL;

	if (select == NULL) select = UISelectionCreate ((char *) "Field Selection");
	selection = UISelectObject (select,(DBObjectLIST<DBObject> *) (cellTable->Fields ()),DBTableFieldIsSimple);
	if (selection == (char *) NULL) return;
	if ((field = cellTable->Field (selection)) == (DBObjTableField *) NULL)
		{ CMmsgPrint (CMmsgAppError,"Corrupt Network Dataset in: %s %d",__FILE__,__LINE__); return; }

	if (DBTableFieldIsCategory (field) && DBTableFieldIsNumeric (field))
		{
		DBObjData *tmpData;
		tmpData = new DBObjData ("",DBTypeGrid);
		tmpData->Document (DBDocGeoDomain,netData->Document (DBDocGeoDomain));
		tmpData->Document (DBDocSubject,field->Name ());
		if (UIDataHeaderForm (tmpData))
			{
			grdData = DBNetworkToGrid (netData,tmpData->Type ());
			grdData->Name (tmpData->Name ());
			grdData->Document (DBDocGeoDomain,tmpData->Document (DBDocGeoDomain));
			grdData->Document (DBDocSubject,tmpData->Document (DBDocSubject));
			grdData->Document (DBDocVersion,tmpData->Document (DBDocVersion));
			grdData->Document (DBDocCitationRef,tmpData->Document (DBDocCitationRef));
			grdData->Document (DBDocCitationInst,tmpData->Document (DBDocCitationInst));
			grdData->Document (DBDocSourceInst,tmpData->Document (DBDocSourceInst));
			grdData->Document (DBDocSourcePerson,tmpData->Document (DBDocSourcePerson));
			grdData->Document (DBDocOwnerPerson,tmpData->Document (DBDocOwnerPerson));
			grdData->Document (DBDocComment,tmpData->Document (DBDocComment));
			delete tmpData;
			}
		else { return; }
		}
	else
		{
		if (DBTableFieldIsCategory (field))		dataType = DBTypeGridDiscrete;
		else if (DBTableFieldIsNumeric (field))	dataType = DBTypeGridContinuous;
		else
			{
			CMmsgPrint (CMmsgAppError,"Invalid field type in: %s %d",__FILE__,__LINE__);
			return;
			}
		grdData = DBNetworkToGrid (netData,dataType);
		if (UIDataHeaderForm (grdData) == false) { delete grdData; return; }
		}

	UIPauseDialogOpen ((char *) "Converting Network to Grid");
	if (RGlibNetworkToGrid (netData,field,grdData) == DBSuccess) workspace->CurrentData (grdData);
	else delete grdData;
	UIPauseDialogClose ();
	}
Example #4
0
    DBInt Configure(DBObjTable *table, bool flat) {
        DBInt i;
        char *dataName;
        char *fieldName = (char *) NULL;
        DBObjData *data;

        dataName = TargetFLD->Name();

        if ((dataName = (char *) malloc(strlen(dataName) + 1)) == (char *) NULL) {
            CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__);
            return (CMfailed);
        }
        strcpy(dataName, TargetFLD->Name());

        for (i = 0; i < (DBInt) strlen(dataName); ++i)
            if (dataName[i] == ':') {
                fieldName = dataName + i + 1;
                dataName[i] = '\0';
                i = 0;
                break;
            }

        data = new DBObjData();
        if ((strcmp(dataName, "stdin") == 0 ? data->Read(stdin) : data->Read(dataName)) == DBFault) {
            CMmsgPrint(CMmsgUsrError, "%s", dataName);
            return (CMfailed);
        }

        if (data->Type() == DBTypeGridDiscrete) {
            DBObjTable *table = data->Table(DBrNItems);

            if (fieldName == (char *) NULL) fieldName = DBrNGridValue;
            if ((SourceFLD = table->Field(fieldName)) == (DBObjTableField *) NULL) {
                CMmsgPrint(CMmsgUsrError, "Invalid field [%s]!", fieldName);
                return (CMfailed);
            }
            strcpy(dataName, TargetFLD->Name());
            delete TargetFLD;
            TargetFLD = new DBObjTableField(*SourceFLD);
            TargetFLD->Name(dataName);
        }
        else {
            if (fieldName != (char *) NULL) {
                CMmsgPrint(CMmsgUsrError, "Continuous grid field is referenced!");
                free(dataName);
                return (CMfailed);
            }
        }
        table->AddField(TargetFLD);
        GridIF = new DBGridIF(data, flat);
        free(dataName);
        return (DBSuccess);
    }
Example #5
0
static void _RGISGridLayerListCBK (Widget widget,void *dummy, XmListCallbackStruct *callData)

	{
	int item = 0;
	DBObjData *data;
	DBObjTable *layerTable;
	DBObjRecord *record;

	XtVaGetValues (widget,XmNuserData, &data, NULL);
	layerTable = data->Table (DBrNLayers);
	for (record = layerTable->First ();record != (DBObjRecord *) NULL;record = layerTable->Next ())
		if (++item == callData->item_position)	layerTable->Item (record->RowID (),true);
	}
Example #6
0
void RGISEditGridStatsCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	DBDataset *dataset = UIDataset ();
	DBObjData *dbData = dataset->Data ();
	DBGridIF *gridIF = new DBGridIF (dbData);
	UITable *tableCLS = (UITable *) dbData->Display (UITableName (dbData,dbData->Table (DBrNItems)));

	if (dbData->Type () == DBTypeGridContinuous)
			gridIF->RecalcStats ();
	else	gridIF->DiscreteStats ();
	if (tableCLS != (UITable *) NULL) tableCLS->Draw ();
	}
Example #7
0
static void _RGISGrpPanelSaveCBK (Widget widget,RGISGrpPanel *grpPanel,XmAnyCallbackStruct *callData)

	{
	DBInt rowID;
	DBDataset  *dataset= UIDataset ();
	DBObjData  *dbData = dataset->Data ();
	DBObjTable *itemTable  = dbData->Table (DBrNItems);
	DBObjTable *groupTable = dbData->Table (DBrNGroups);
	DBObjTableField *group;
	DBObjRecord *itemRec, *groupRec;
	UITable *tableCLS;

	if (groupTable == (DBObjTable *) NULL) return;
	group = grpPanel->Current ();
	for (rowID = 0;rowID < groupTable->ItemNum ();++rowID)
		{
		groupRec = groupTable->Item (rowID);
		itemRec = itemTable->Item (rowID);
		group->Int (groupRec,(itemRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected ? true : false);
		}
	if ((tableCLS = (UITable *) dbData->Display (UITableName (dbData,groupTable))) != (UITable *) NULL)
		tableCLS->Draw ();
	}
Example #8
0
static void _RGISToolsImportASCIITableCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	static Widget fileSelect = (Widget) NULL;
	DBObjData *data = new DBObjData ("",DBTypeTable);

	widget = widget; callData = callData;
	if (fileSelect == NULL) fileSelect = UIFileSelectionCreate ((char *) "ASCII Import",NULL,(char *) "*.*",XmFILE_REGULAR);

	if (UIDataHeaderForm (data))
		{
		char *fileName;

		if ((fileName = UIFileSelection (fileSelect,true)) == NULL) { delete data; return; }

		if (DBImportASCIITable (data->Table (DBrNItems),fileName) == DBFault)
			{ UIMessage ((char *) "Import failed!"); delete data; return; }

		if (UITableRedefineFields (data->Table (DBrNItems)) != true)	{ delete data;  return; }

		workspace->CurrentData  (data);
		}
	else delete data;
	}
Example #9
0
static void _RGISGridGroupListCBK (Widget widget,RGISGrpPanel *grpPanel, XmListCallbackStruct *callData)

	{
	DBObjData *data;
	DBObjTable *groupTable;
	DBObjectLIST<DBObjTableField> *groups;
	DBObjTableField *group = (DBObjTableField *) NULL;

	XtVaGetValues (widget,XmNuserData, &data, NULL);
	if (data == (DBObjData *) NULL) return;
	if ((groupTable = data->Table (DBrNGroups)) != (DBObjTable *) NULL)
		{
		groups = groupTable->Fields ();
		if ((group = groups->Item (callData->item_position - 1)) != (DBObjTableField *) NULL)
			grpPanel->Current (group);
		}
	}
Example #10
0
void RGISAnalysePointSubbasinCenterCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	DBDataset *dataset = UIDataset ();
	DBObjData *pntData =dataset->Data ();
	DBObjTable *pointTable = pntData->Table (DBrNItems);
	DBObjTableField *massCoordXFLD = pointTable->Field (RGlibMassCoordX);
	DBObjTableField *massCoordYFLD = pointTable->Field (RGlibMassCoordY);
	DBObjData *netData = pntData->LinkedData ();
	UITable *tableCLS = (UITable *) pntData->Display (UITableName (pntData,pointTable));

	UIPauseDialogOpen ((char *) "Subbasin Centers");
	if ((RGlibPointSubbasinCenter (pntData, netData) == DBSuccess) && (tableCLS != (UITable *) NULL))
		{
		if (massCoordXFLD == NULL) tableCLS->AddField (pointTable->Field (RGlibMassCoordX));
		if (massCoordYFLD == NULL) tableCLS->AddField (pointTable->Field (RGlibMassCoordY));
		tableCLS->Draw ();
		}
	UIPauseDialogClose ();
	}
Example #11
0
void RGISEditNetAddBasinXYCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	DBInt basinID;
	DBDataset *dataset = UIDataset ();
	DBObjData *dbData =dataset->Data ();
	DBNetworkIF *netIF = new DBNetworkIF (dbData);
	DBObjTable *itemTable = dbData->Table (DBrNItems);
	DBObjTableField *xCoordFLD	= itemTable->Field (RGISNetMouthXCoord);
	DBObjTableField *yCoordFLD = itemTable->Field (RGISNetMouthYCoord);
	DBCoordinate coord;
	DBObjRecord *basinRec;
	UITable *tableCLS = (UITable *) dbData->Display (UITableName (dbData,itemTable));

	UIPauseDialogOpen ((char *) "Adding XY Coordinates");
	if (xCoordFLD == NULL)
		{
		xCoordFLD = new DBObjTableField (RGISNetMouthXCoord,DBTableFieldFloat,(char *) "%10.3f",sizeof (DBFloat4));
		itemTable->AddField (xCoordFLD);
		if (tableCLS != (UITable *) NULL) tableCLS->AddField (xCoordFLD);
		UIPause (40);
		}
	if (yCoordFLD == NULL)
		{
		yCoordFLD = new DBObjTableField (RGISNetMouthYCoord,DBTableFieldFloat,(char *) "%10.3f",sizeof (DBFloat4));
		itemTable->AddField (yCoordFLD);
		if (tableCLS != (UITable *) NULL) tableCLS->AddField (yCoordFLD);
		UIPause (80);
		}
	for (basinID = 0;basinID < netIF->BasinNum ();++basinID)
		{
		basinRec = netIF->Basin (basinID);
		if (UIPause (80 + basinID * 20 / netIF->BasinNum ())) goto Stop;
		coord = netIF->Center  (netIF->MouthCell (basinRec));
		xCoordFLD->Float (basinRec,coord.X);
		yCoordFLD->Float (basinRec,coord.Y);
		}
Stop:
	UIPauseDialogClose ();
	if (tableCLS != (UITable *) NULL) tableCLS->Draw ();
	}
Example #12
0
static void _RGISToolsExportASCIICBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	char *selection;
	DBDataset *dataset = UIDataset ();
	DBObjData *data = dataset->Data ();
	DBObjTable *table;
	static Widget fileSelect = NULL;
	static Widget tableSelect = (Widget) NULL;

	widget = widget; workspace = workspace; callData = callData;

	if (tableSelect == (Widget) NULL) tableSelect = UISelectionCreate ((char *) "Table Selection");
	if (fileSelect == NULL)	fileSelect = UIFileSelectionCreate ((char *) "ASCII Table",NULL,(char *) "*.txt",XmFILE_REGULAR);

	table = data->Table (UISelectObject (tableSelect,(DBObjectLIST<DBObject> *) data->Tables ()));
	if (table == (DBObjTable *) NULL) return;
	if ((selection = UIFileSelection (fileSelect,False)) == NULL) return;

	DBExportASCIITable (table, selection);
	}
Example #13
0
void RGISEditPointAddXYCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	DBDataset *dataset = UIDataset ();
	DBObjData *dbData =dataset->Data ();
	DBVPointIF *pntIF = new DBVPointIF (dbData);
	DBObjTable *pointTable = dbData->Table (DBrNItems);
	DBObjTableField *xCoordFLD	= pointTable->Field (RGISEditPointXCoord);
	DBObjTableField *yCoordFLD = pointTable->Field (RGISEditPointYCoord);
	DBCoordinate coord;
	DBObjRecord *pointRec;
	UITable *tableCLS = (UITable *) dbData->Display (UITableName (dbData,pointTable));

	widget = widget; workspace = workspace; callData = callData;
	UIPauseDialogOpen ((char *) "Adding XY Coordinates");
	if (xCoordFLD == NULL)
		{
		xCoordFLD = new DBObjTableField (RGISEditPointXCoord,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4));
		pointTable->AddField (xCoordFLD);
		if (tableCLS != (UITable *) NULL) tableCLS->AddField (xCoordFLD);
		UIPause (40);
		}
	if (yCoordFLD == NULL)
		{
		yCoordFLD = new DBObjTableField (RGISEditPointYCoord,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4));
		pointTable->AddField (yCoordFLD);
		if (tableCLS != (UITable *) NULL) tableCLS->AddField (yCoordFLD);
		UIPause (80);
		}
	for (pointRec = pntIF->FirstItem (); pointRec != (DBObjRecord *) NULL; pointRec = pntIF->NextItem ())
		{
		if (UIPause (80 + pointRec->RowID () * 20 / pntIF->ItemNum ())) goto Stop;
		coord = pntIF->Coordinate  (pointRec);
		xCoordFLD->Float (pointRec,coord.X);
		yCoordFLD->Float (pointRec,coord.Y);
		}
Stop:
	UIPauseDialogClose ();
	if (tableCLS != (UITable *) NULL) tableCLS->Draw ();
	}
Example #14
0
static void _RGISGrpPanelDeleteCBK (Widget widget,RGISGrpPanel *grpPanel,XmAnyCallbackStruct *callData)

	{
	DBDataset *dataset = UIDataset ();
	DBObjData *dbData  = dataset->Data ();
	DBObjTable *groupTable = dbData->Table (DBrNGroups);
	DBObjTableField *group = grpPanel->Current ();
	static Widget fieldSelect = (Widget) NULL;

	if (fieldSelect == (Widget) NULL) fieldSelect = UISelectionCreate ((char *) "Group Selection");

	if ((groupTable == (DBObjTable *) NULL) || (group == (DBObjTableField *) NULL)) return;
	if (groupTable->FieldNum () == 1) grpPanel->Groups ((DBObjectLIST<DBObjTableField> *) NULL);
	grpPanel->Remove (group);
	groupTable->DeleteField (group);
	if (groupTable->FieldNum () == 0)
		{
		DBObjectLIST<DBObjTable> *tables  = dbData->Tables ();
		tables->Remove (groupTable);
		delete groupTable;
		}
	}
Example #15
0
void RGISAnalysePointInterStationTSCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	char *selection;
	DBDataset *dataset = UIDataset ();
	DBObjMetaEntry *metaEntry;
	DBObjData *pntData = dataset->Data (), *tsData;
	DBObjTable *relateTBL = pntData->Table (DBrNRelations);
	DBObjRecord *relateRec;
	DBObjTableField *relDataFLD;
	DBObjTableField *relateFLD;
	DBObjTableField *joinFLD;
	static Widget selectWidget = (Widget) NULL;

	if (selectWidget == (Widget) NULL) selectWidget = UISelectionCreate ((char *) "Select Time Series");

	if ((selection = UISelectObject (selectWidget,(DBObjectLIST<DBObject> *) relateTBL)) == (char *) NULL) return;
	if ((relateRec = relateTBL->Item (selection)) == (DBObjRecord *) NULL)
		{ CMmsgPrint (CMmsgAppError, "Relate Record Error in: %s %d",__FILE__,__LINE__); return; }

	relDataFLD = relateTBL->Field (DBrNRelateData);
	relateFLD = relateTBL->Field (DBrNRelateField);
	joinFLD	= relateTBL->Field (DBrNRelateJoinField);

	if ((tsData = dataset->Data (relDataFLD->String (relateRec))) == (DBObjData *) NULL)
		{
		if ((metaEntry = dataset->Meta (relDataFLD->String (relateRec))) == (DBObjMetaEntry *) NULL)
			{ CMmsgPrint (CMmsgAppError, "Meta Enrty Finding Error in: %s %d",__FILE__,__LINE__); return; }
		tsData = new DBObjData ();
		if (tsData->Read (metaEntry->FileName ()) != DBSuccess) return;
		}
	workspace->CurrentData (tsData);

	UIPauseDialogOpen ((char *) "Calculating");
	RGlibPointInterStationTS (pntData,tsData,relateFLD->String (relateRec),joinFLD->String (relateRec));
	UIPauseDialogClose ();
	}
Example #16
0
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;
	}
Example #17
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    DBInt recID;
    DBObjData *data;
    char *tableName = (char *) NULL;
    char *fieldIDName = (char *) NULL;
    char *fieldXName = (char *) NULL;
    char *fieldYName = (char *) NULL;
    DBObjTable *table;
    DBObjTableField *fieldID, *fieldX, *fieldY;
    DBObjRecord *record;
    DBNetworkIF *netIF;
	DBCoordinate coord;

    for (argPos = 1; argPos < argNum;) {
        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], "-f", "--IDfield")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing field name!");
                return (CMfailed);
            }
            fieldIDName = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-x", "--Xfield")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing field name!");
                return (CMfailed);
            }
            fieldXName = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-y", "--Yfield")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing field name!");
                return (CMfailed);
            }
            fieldYName = 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   [ [DBCells] | DBItems ]");
            CMmsgPrint(CMmsgInfo, "     -f, --IDfield [ [CellID]  | BasinID ]");
            CMmsgPrint(CMmsgInfo, "     -x, --Xfield  [ [CellXCoord] | MouthXCoord ]");
            CMmsgPrint(CMmsgInfo, "     -y, --Yfield  [ [CellYCoord] | MouthYCoord ]");
            CMmsgPrint(CMmsgInfo, "     -V, --verbose");
            CMmsgPrint(CMmsgInfo, "     -h, --help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

    if (argNum > 3) {
        CMmsgPrint(CMmsgUsrError, "Extra arguments!");
        return (CMfailed);
    }
    if (verbose) RGlibPauseOpen(argv[0]);

    if (tableName == (char *) NULL)   tableName = (char *) "DBCells";
    if (fieldIDName == (char *) NULL) fieldIDName = (char *) "CellID";
    if (fieldXName == (char *) NULL)  fieldXName = (char *) "CellXCoord";
    if (fieldYName == (char *) NULL)  fieldYName = (char *) "CellYCoord";

    data = new DBObjData();
    if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) {
        delete data;
        return (CMfailed);
    }

    if ((table = data->Table(tableName)) == (DBObjTable *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Invalid table: %s!", tableName);
        delete data;
        return (CMfailed);
    }

    netIF = new DBNetworkIF(data);

    fieldID = new DBObjTableField(fieldIDName, DBTableFieldInt,   (char *) "%8d",    sizeof (DBInt));
    fieldX  = new DBObjTableField (fieldXName, DBTableFieldFloat, (char *) "%10.3f", sizeof (DBFloat4));
    fieldY  = new DBObjTableField (fieldYName, DBTableFieldFloat, (char *) "%10.3f", sizeof (DBFloat4));

    table->AddField(fieldID);
    table->AddField(fieldX);
    table->AddField(fieldY);

    if (strcmp(fieldIDName, "CellID") == 0) {
        for (recID = 0; recID < table->ItemNum(); ++recID) {
            record = netIF->Cell(recID);
            coord = netIF->Center(record);
            fieldID->Int(record, recID+1);
            fieldX->Float(record, coord.X);
            fieldY->Float(record, coord.Y);
        }
    } else if (strcmp(fieldIDName, "BasinID") == 0) {
        for (recID = 0; recID < netIF->BasinNum(); ++recID) {
            record = netIF->Basin(recID);
            coord = netIF->Center(netIF->MouthCell(record));
            fieldID->Int(record, recID+1);
            fieldX->Float(record,coord.X);
            fieldY->Float(record,coord.Y);
        }
    } else {
        CMmsgPrint(CMmsgUsrError, "Invalid field name: %s!", fieldIDName);
        delete data;
        return (CMfailed);
    }

    ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout);

    delete data;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Example #18
0
int main (int argc,char *argv [])

	{
	int argPos, argNum = argc, ret, verbose = false;
	DBInt recID;
	bool padding = false;
	char *tableName = (char *) NULL;
	char *fieldName = (char *) NULL;
	char *yearFieldName = (char *) NULL;
	char *monthFieldName = (char *) NULL;
	char *dayFieldName = (char *) NULL;
	char *hourFieldName = (char *) NULL;
	char *minFieldName = (char *) NULL;
	char *tmp = (char *) NULL;
	DBObjData *data;
	DBObjTable *table;
	DBObjTableField *srcField;
	DBObjTableField *yearField	= (DBObjTableField *) NULL;
	DBObjTableField *monthField= (DBObjTableField *) NULL;
	DBObjTableField *dayField	= (DBObjTableField *) NULL;
	DBObjTableField *hourField	= (DBObjTableField *) NULL;
	DBObjTableField *minField	= (DBObjTableField *) NULL;
	DBInt dbInputType = DBTableFieldInt;
	DBInt dbInputSize = sizeof(DBShort);
	DBDate date;
	DBObjRecord *record;

	for (argPos = 1;argPos < argNum; )
		{
		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],"-f","--field"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing field name!"); return (CMfailed); }
			fieldName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-y","--year"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing year field name!"); return (CMfailed); }
			yearFieldName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-m","--month"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing month field name!"); return (CMfailed); }
			monthFieldName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-d","--day"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing day field name!"); return (CMfailed); }
			dayFieldName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-o","--hour"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing hour field name!"); return (CMfailed); }
			hourFieldName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-i","--minute"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing minute field name!"); return (CMfailed); }
			minFieldName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-p","--padding"))
			{
			padding = true;
			dbInputType = DBTableFieldString;
			dbInputSize = sizeof(DBByte) * 3;
			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,"     -f,--field     [field name]");
			CMmsgPrint (CMmsgInfo,"     -y,--year      [year field]");
			CMmsgPrint (CMmsgInfo,"     -m,--month     [month field]");
			CMmsgPrint (CMmsgInfo,"     -d,--day       [day field]");
			CMmsgPrint (CMmsgInfo,"     -o,--hour      [hour field]");
			CMmsgPrint (CMmsgInfo,"     -i,--minute    [minute field]");
			CMmsgPrint (CMmsgInfo,"     -p,--padding");
			CMmsgPrint (CMmsgInfo,"     -V,--verbose");
			CMmsgPrint (CMmsgInfo,"     -h,--help");
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && ((int) strlen (argv [argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); }
		argPos++;
		}

	if (argNum > 3) { CMmsgPrint (CMmsgUsrError,"Extra arguments!"); 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)
		{ delete data; return (CMfailed); }

	if (tableName == (char *) NULL) tableName = DBrNItems;

	if ((table = data->Table (tableName)) == (DBObjTable *) NULL)
		{ CMmsgPrint (CMmsgUsrError,"Invalid table!"); delete data; return (CMfailed); }

	if (fieldName == (char *) NULL) fieldName = (char *) "Date";
	if ((srcField = table->Field (fieldName)) == (DBObjTableField *) NULL)
		{ CMmsgPrint (CMmsgUsrError,"Missing date field!"); delete data; return (CMfailed); }
	if ((srcField->Type () != DBTableFieldString) &&
		 (srcField->Type () != DBTableFieldDate))
		{ CMmsgPrint (CMmsgUsrError,"Invalid date field!"); delete data; return (CMfailed); }

	if (yearFieldName != (char *) NULL)
		{
		if ((yearField = table->Field (yearFieldName)) == (DBObjTableField *) NULL)
			{
			yearField = new DBObjTableField (yearFieldName,DBTableFieldInt,"%4d",sizeof(DBShort),false);
			table->AddField (yearField);
			}
		}

	if (monthFieldName != (char *) NULL)
		{
		if ((monthField = table->Field (monthFieldName)) == (DBObjTableField *) NULL)
			{
			monthField = new DBObjTableField (monthFieldName,dbInputType,"%2d",dbInputSize,false);
			table->AddField (monthField);
			}
		}

	if (dayFieldName != (char *) NULL)
		{
		if (monthField == (DBObjTableField *) NULL)
			{ CMmsgPrint (CMmsgUsrError,"Month field is not set!"); delete data; return (CMfailed); }
		if ((dayField = table->Field (dayFieldName)) == (DBObjTableField *) NULL)
			{
			dayField = new DBObjTableField (dayFieldName,dbInputType,"%2d",dbInputSize,false);
			table->AddField (dayField);
			}
		}

	if (hourFieldName != (char *) NULL)
		{
		if (dayField == (DBObjTableField *) NULL)
			{ CMmsgPrint (CMmsgUsrError,"Day field is not set!"); delete data; return (CMfailed); }
		if ((hourField = table->Field (hourFieldName)) == (DBObjTableField *) NULL)
			{
			hourField = new DBObjTableField (hourFieldName,dbInputType,"%2d",dbInputSize,false);
			table->AddField (hourField);
			}
		}

	if (minFieldName != (char *) NULL)
		{
		if (hourField == (DBObjTableField *) NULL)
			{ CMmsgPrint (CMmsgUsrError,"Hour field is not set!"); delete data; return (CMfailed); }
		if ((minField = table->Field (minFieldName)) == (DBObjTableField *) NULL)
			{
			minField = new DBObjTableField (minFieldName,dbInputType,"%2d",dbInputSize,false);
			table->AddField (minField);
			}
		}

	for (recID = 0;recID < table->ItemNum ();++recID)
		{
		record = table->Item (recID);
		if (srcField->Type () == DBTableFieldString)
				date.Set (srcField->String (record));
		else	date = srcField->Date (record);
		if (yearField  != (DBObjTableField *) NULL) yearField->Int(record,date.Year ());
		if(padding)
			{
			if (monthField != (DBObjTableField *) NULL)
				{
				if (date.Month() != DBDefaultMissingIntVal) monthField->String (record,tmp = _CMDpadit(date.Month() + 1,false));
				else monthField->String (record,tmp = _CMDpadit(date.Month(),false));
				free(tmp);
				}
			if (dayField   != (DBObjTableField *) NULL) { dayField->String (record,tmp = _CMDpadit(date.Day(),false)); free(tmp); }
			if (hourField  != (DBObjTableField *) NULL) { hourField->String (record,tmp = _CMDpadit(date.Hour(),false)); free(tmp); }
			if (minField   != (DBObjTableField *) NULL) { minField->String (record,tmp = _CMDpadit(date.Minute(),false)); free(tmp); }
			}
		else
			{
			if (monthField != (DBObjTableField *) NULL)
				{
				if (date.Month() != DBDefaultMissingIntVal) monthField->Int(record,date.Month () + 1);
				else monthField->Int (record,DBDefaultMissingIntVal);
				}
			if (dayField   != (DBObjTableField *) NULL) dayField->Int (record,date.Day ());
			if (hourField  != (DBObjTableField *) NULL) hourField->Int(record,date.Hour ());
			if (minField   != (DBObjTableField *) NULL) minField->Int (record,date.Minute ());
			}
		}
	ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? data->Write (argv [2]) : data->Write (stdout);

	delete data;
	if (verbose) RGlibPauseClose ();
	return (ret);
	}
Example #19
0
void RGISAnNetworkStreamLinesCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	char *selection;
	DBDataset *dataset = UIDataset ();
	DBObjData *netData = dataset->Data ();
	DBObjTable *cellTable = netData->Table (DBrNCells);
	DBObjData *arcData = new DBObjData ("",DBTypeVectorLine);
	DBNetworkIF *netIF = new DBNetworkIF (netData);
	static Widget fieldSelect = (Widget) NULL;

	widget = widget; callData = callData;

	if (fieldSelect == (Widget) NULL)	fieldSelect = UISelectionCreate ((char *) "Select Field");
	if ((selection = UISelectObject (fieldSelect,(DBObjectLIST<DBObject> *) cellTable->Fields (),DBTableFieldIsInteger)) == (char *) NULL)
		return;
	if ((_RGISAnNetOrderField = cellTable->Field (selection)) == (DBObjTableField *) NULL)
		{ CMmsgPrint (CMmsgAppError, "Field Selection Error in: %s %d",__FILE__,__LINE__); return; }
	arcData->Document (DBDocGeoDomain,netData->Document (DBDocGeoDomain));
	arcData->Document (DBDocSubject,"Stream Lines");
	if (UIDataHeaderForm (arcData))
		{
		DBInt cellID;
		char objName [DBStringLength];
		DBVLineIF *lineIF = new DBVLineIF (arcData);
		DBObjTable *cellTable 	= netData->Table (DBrNCells);
		DBObjTable *lineTable 	= arcData->Table (DBrNItems);
		DBObjTableField *basinFLD  = new DBObjTableField (DBrNBasin,DBTableFieldInt,"%8d",sizeof (DBInt));
		DBObjTableField *fieldFLD  = new DBObjTableField (_RGISAnNetOrderField->Name (),
		                                                  _RGISAnNetOrderField->Type (),
		                                                  _RGISAnNetOrderField->Format (),
		                                                  _RGISAnNetOrderField->Length ());
		DBObjTableField *lengthFLD = new DBObjTableField (RGISNetStreamLength,DBTableFieldFloat,"%10.1f",sizeof (DBFloat4));
		DBObjTableField *areaFLD   = new DBObjTableField (RGISNetStreamArea,DBTableFieldFloat,"%10.1f",sizeof (DBFloat4));
		DBObjTableField *basinAreaFLD = new DBObjTableField (RGISNetBasinArea,DBTableFieldFloat,"%10.1f",sizeof (DBFloat4));
		DBObjTableField *nextFLD  = new DBObjTableField (RGISNetStreamNext,DBTableFieldInt,"%6d",sizeof (DBInt));
		DBObjRecord *cellRec, *toCellRec, *lineRec;

		arcData->Projection (netData->Projection ());
		arcData->Precision  (netData->Precision ());
		arcData->MaxScale   (netData->MaxScale ());
		arcData->MinScale   (netData->MinScale ());

		lineTable->AddField (basinFLD);
		lineTable->AddField (fieldFLD);
		lineTable->AddField (lengthFLD);
		lineTable->AddField (areaFLD);
		lineTable->AddField (basinAreaFLD);
		lineTable->AddField (nextFLD);

		cellTable->AddField (_RGISAnNetStreamIDFLD = new DBObjTableField ("StreamID",DBTableFieldInt,"%8d",sizeof (DBInt)));

		_RGISAnNetStreamID = 0;
		UIPauseDialogOpen ((char *) "Creating Stream Lines");
		cellID = netIF->CellNum () - 1;
		cellRec = netIF->Cell (cellID);
		if (lineIF->NewSymbol ("Default Symbol") == (DBObjRecord *) NULL)
			{ CMmsgPrint (CMmsgAppError, "Symbol Creation Error in: %s %d",__FILE__,__LINE__); return; }

		for (;cellID >= 0;--cellID)
			{
			cellRec = netIF->Cell (cellID);
			if (((toCellRec = netIF->ToCell (cellRec)) == (DBObjRecord *) NULL) ||
			    (_RGISAnNetOrderField->Int (cellRec) != _RGISAnNetOrderField->Int (toCellRec)) ||
	 		    (netIF->CellOrder (cellRec)          != netIF->CellOrder (toCellRec)))
				{
				if (UIPause ((netIF->CellNum () - cellRec->RowID ()) * 100 / netIF->CellNum ())) goto Stop;
				sprintf (objName,"Line: %5d",_RGISAnNetStreamID + 1);
				if ((lineRec = lineIF->NewItem (objName)) == (DBObjRecord *) NULL)
					{ CMmsgPrint (CMmsgAppError, "Line Insertion Error in: %s %d",__FILE__,__LINE__); return; }
				nextFLD->Int (lineRec,toCellRec == (DBObjRecord *) NULL ? 0 : _RGISAnNetStreamIDFLD->Int (toCellRec) + 1);
				basinFLD->Int (lineRec,netIF->CellBasinID (cellRec));
				fieldFLD->Int (lineRec,_RGISAnNetOrderField->Int (cellRec));

				_RGISAnNetVertex = 0;
				netIF->UpStreamSearch (_RGISAnNetworkCellRec = cellRec,(DBNetworkACTION) _RGISAnNetworkUpStreamAction);
				lineIF->FromNode (lineRec,lineIF->Node (netIF->Center (_RGISAnNetworkCellRec),true));
				lineIF->ToNode (lineRec,lineIF->Node (netIF->Center (cellRec) + netIF->Delta (cellRec),true));

				_RGISAnNetArea = netIF->CellArea (_RGISAnNetworkCellRec);
				if (_RGISAnNetVertex > 1)
					{
					if (_RGISAnNetVertexNum < _RGISAnNetVertex - 1)
						{
						_RGISAnNetCoord = (DBCoordinate *) realloc (_RGISAnNetCoord,(_RGISAnNetVertex - 1) * sizeof (DBCoordinate));
						if (_RGISAnNetCoord == (DBCoordinate *) NULL)
							{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return; }
						}
					_RGISAnNetVertex = 0;
					netIF->DownStreamSearch (netIF->ToCell (_RGISAnNetworkCellRec),(DBNetworkACTION) _RGISAnNetworkDownStreamAction);
					}
				else	_RGISAnNetVertex = 0;
				lineIF->Vertexes (lineRec,_RGISAnNetCoord,_RGISAnNetVertex);
				lineIF->ItemSymbol (lineRec,lineIF->Symbol (0));
				lengthFLD->Float (lineRec,netIF->CellBasinLength (cellRec));
				areaFLD->Float (lineRec,_RGISAnNetArea);
				basinAreaFLD->Float (lineRec,netIF->CellBasinArea (cellRec));
				_RGISAnNetStreamID += 1;
				}
			}
Stop:	UIPauseDialogClose ();
		if (_RGISAnNetCoord != (DBCoordinate *) NULL) free (_RGISAnNetCoord);

		delete lineIF;
		if (cellID >= 0) delete arcData;
		else	workspace->CurrentData (arcData);
		}
	else delete arcData;
	delete netIF;
	}
Example #20
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, idleMode, verbose = false;
    char *tableName = (char *) NULL;
    DBInt recID;
    DBObjData *data;
    DBObjTable *table;
    DBObjRecord *record;

    for (argPos = 1; argPos < argNum;) {
        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], "-m", "--mode")) {
            int modeCodes[] = {true, false};
            const char *modes[] = {"set", "clear"};

            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing selection mode!");
                return (CMfailed);
            }
            if ((idleMode = CMoptLookup(modes, argv[argPos], true)) == DBFault) {
                CMmsgPrint(CMmsgUsrError, "Invalid selection mode!");
                return (CMfailed);
            }
            idleMode = modeCodes[idleMode];
            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, "     -m,--mode      [set|clear]");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

    if (argNum > 3) {
        CMmsgPrint(CMmsgUsrError, "Extra arguments!");
        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) {
        delete data;
        return (CMfailed);
    }

    if (tableName == (char *) NULL) tableName = DBrNItems;

    if ((table = data->Table(tableName)) == (DBObjTable *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Invalid table!");
        delete data;
        return (CMfailed);
    }

    if (idleMode)
        for (recID = 0; recID < table->ItemNum(); ++recID) {
            record = table->Item(recID);
            if ((record->Flags() & DBObjectFlagSelected) == DBObjectFlagSelected)
                record->Flags(DBObjectFlagIdle, DBSet);
            else
                record->Flags(DBObjectFlagIdle, DBClear);
        }
    else
        for (recID = 0; recID < table->ItemNum(); ++recID) {
            record = table->Item(recID);
            record->Flags(DBObjectFlagIdle, DBClear);
        }

    ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout);

    delete data;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Example #21
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    char *tableName = (char *) NULL;
    DBObjData *data;
    DBObjTable *table;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest (argv[argPos], "-a", "--table")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing table!");
                return (CMfailed);
            }
            tableName = 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] <rgis file> <ascii table>", CMfileName(argv[0]));
            CMmsgPrint(CMmsgInfo, "     -a,--table");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

    if (argNum > 3) {
        CMmsgPrint(CMmsgUsrError, "Extra arguments!");
        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) {
        delete data;
        return (CMfailed);
    }

    if (tableName == (char *) NULL) tableName = DBrNItems;
    if ((table = data->Table(tableName)) == (DBObjTable *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Invalid table!");
        delete data;
        return (CMfailed);
    }

    ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? DBExportASCIITable(table, argv[2]) :
          DBExportASCIITable(table, stdout);

    delete data;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Example #22
0
DBObjData *DBNetworkToGrid(DBObjData *netData, DBInt type) {
    DBPosition pos;
    DBObjData *grdData = new DBObjData("", type);
    DBObjRecord *layerRec, *dataRec;
    DBObjTable *layerTable = grdData->Table(DBrNLayers);
    DBObjTable *itemTable = grdData->Table(DBrNItems);
    DBObjTableField *rowNumFLD = layerTable->Field(DBrNRowNum);
    DBObjTableField *colNumFLD = layerTable->Field(DBrNColNum);
    DBObjTableField *cellWidthFLD = layerTable->Field(DBrNCellWidth);
    DBObjTableField *cellHeightFLD = layerTable->Field(DBrNCellHeight);
    DBObjTableField *valueTypeFLD = layerTable->Field(DBrNValueType);
    DBObjTableField *valueSizeFLD = layerTable->Field(DBrNValueSize);
    DBObjTableField *layerFLD = layerTable->Field(DBrNLayer);
    DBNetworkIF *netIF;
    DBGridIF *gridIF;

    grdData->Projection(netData->Projection());
    grdData->Precision(netData->Precision());
    grdData->MaxScale(netData->MaxScale());
    grdData->MinScale(netData->MinScale());
    grdData->Extent(netData->Extent());
    grdData->Document(DBDocGeoDomain, netData->Document(DBDocGeoDomain));

    netIF = new DBNetworkIF(netData);

    layerTable->Add("FirstLayer");
    if ((layerRec = layerTable->Item()) == (DBObjRecord *) NULL) {
        delete netIF;
        return ((DBObjData *) NULL);
    }
    rowNumFLD->Int(layerRec, netIF->RowNum());
    colNumFLD->Int(layerRec, netIF->ColNum());
    cellWidthFLD->Float(layerRec, netIF->CellWidth());
    cellHeightFLD->Float(layerRec, netIF->CellHeight());
    switch (type) {
        case DBTypeGridContinuous:
            valueTypeFLD->Int(layerRec, DBTableFieldFloat);
            valueSizeFLD->Int(layerRec, sizeof(DBFloat));
            break;
        case DBTypeGridDiscrete:
            valueTypeFLD->Int(layerRec, DBTableFieldInt);
            valueSizeFLD->Int(layerRec, sizeof(DBInt));
            break;
        default:
            CMmsgPrint(CMmsgAppError, "Invalid Data Type in: %s %d", __FILE__, __LINE__);
            delete grdData;
            delete netIF;
            return ((DBObjData *) NULL);
    }
    if ((dataRec = new DBObjRecord(layerRec->Name(),
                                   ((size_t) netIF->ColNum()) * netIF->RowNum() * valueSizeFLD->Int(layerRec),
                                   valueSizeFLD->Int(layerRec))) == (DBObjRecord *) NULL) {
        delete netIF;
        return ((DBObjData *) NULL);
    }
    (grdData->Arrays())->Add(dataRec);
    layerFLD->Record(layerRec, dataRec);

    gridIF = new DBGridIF(grdData);
    if (type == DBTypeGridContinuous) {
        itemTable->Add(layerRec->Name());
        DBObjTableField *missingValueFLD = itemTable->Field(DBrNMissingValue);
        missingValueFLD->Float(itemTable->Item(layerRec->Name()), DBDefaultMissingFloatVal);
        for (pos.Row = 0; pos.Row < netIF->RowNum(); pos.Row++)
            for (pos.Col = 0; pos.Col < netIF->ColNum(); pos.Col++)
                gridIF->Value(layerRec, pos, DBDefaultMissingFloatVal);
    }
    else {
        DBObjTable *symbolTable = grdData->Table(DBrNSymbols);
        DBObjTableField *foregroundFLD = symbolTable->Field(DBrNForeground);
        DBObjTableField *backgroundFLD = symbolTable->Field(DBrNBackground);
        DBObjTableField *styleFLD = symbolTable->Field(DBrNStyle);
        DBObjRecord *symbolRec = symbolTable->Add("Default Symbol");

        foregroundFLD->Int(symbolRec, 1);
        backgroundFLD->Int(symbolRec, 0);
        styleFLD->Int(symbolRec, 0);
        for (pos.Row = 0; pos.Row < netIF->RowNum(); pos.Row++)
            for (pos.Col = 0; pos.Col < netIF->ColNum(); pos.Col++)
                gridIF->Value(layerRec, pos, 0);
    }
    delete netIF;
    delete gridIF;
    return (grdData);
}
Example #23
0
int main (int argc,char *argv [])

	{
	int argPos, argNum = argc, ret, verbose = false;
	DBInt oper = DBMathOperatorAdd;
	char *tableName = (char *) NULL;
	char *srcFieldName = (char *) NULL;
	char *dstFieldName = (char *) NULL;
	char *nextFieldName = (char *) NULL;
	DBObjData *data;
	DBObjTable *table;

	for (argPos = 1;argPos < argNum; )
		{
		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],"-o","--operation"))
			{
			int operCodes [] = {	DBMathOperatorAdd, DBMathOperatorSub };
			const char *operations [] = {	"add", "subtract", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <=argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing operation!");   return (CMfailed); }
			if ((oper = CMoptLookup (operations,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid operation!");		return (CMfailed); }
			oper = operCodes [oper];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <=argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-n","--next"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <=argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing next field name!"); return (CMfailed); }
			nextFieldName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <=argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-s","--source"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <=argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing source field name!"); return (CMfailed); }
			srcFieldName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <=argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-t","--target"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <=argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing target field name!"); return (CMfailed); }
			dstFieldName = 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>",CMprgName(argv[0]));
			CMmsgPrint (CMmsgInfo,"     -a,--table     [table name]");
			CMmsgPrint (CMmsgInfo,"     -o,--operation [add|subtract]");
			CMmsgPrint (CMmsgInfo,"     -n,--next      [next fieldname]");
			CMmsgPrint (CMmsgInfo,"     -s,--source    [source fieldname]");
			CMmsgPrint (CMmsgInfo,"     -t,--target    [target fieldname]");
			CMmsgPrint (CMmsgInfo,"     -V,--verbose");
			CMmsgPrint (CMmsgInfo,"     -h,--help");
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && ((int) strlen (argv [argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); }
		argPos++;
		}

	if (srcFieldName == (char *) NULL)
		{ CMmsgPrint (CMmsgUsrError,"Missing source field!"); return (CMfailed); }
	if (dstFieldName == (char *) NULL)
		{ CMmsgPrint (CMmsgUsrError,"Missing target field!"); return (CMfailed); }
	if (nextFieldName == (char *) NULL) nextFieldName = RGlibNextStation;
	if (tableName == (char *) NULL) tableName = DBrNItems;

	if (argNum > 3) { CMmsgPrint (CMmsgUsrError,"Extra arguments!"); 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)
		{ delete data; if (argNum > 1) printf ("File error in: %s", argv[1]); return(DBFault); }

	if ((table = data->Table (tableName)) == (DBObjTable *) NULL)
		{ CMmsgPrint (CMmsgUsrError,"Invalid table!"); delete data; return (CMfailed); }

	switch (oper)
		{
		default:
		case DBMathOperatorAdd:
			ret = RGlibGenFuncTopoAccum (table,nextFieldName,srcFieldName,dstFieldName);
			break;
		case DBMathOperatorSub:
			ret = RGlibGenFuncTopoSubtract (table,nextFieldName,srcFieldName,dstFieldName);
			break;
		}
	if (ret == DBSuccess)
		ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? data->Write (argv [2]) : data->Write (stdout);

	delete data;
	if (verbose) RGlibPauseClose ();
	return (ret);
	}
Example #24
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    DBInt fromSelection = false, selectMode = true, recID;
    char *tableName = (char *) NULL;
    char *expr = (char *) NULL;
    DBMathOperand *operand;
    DBObjectLIST<DBObject> *variables = new DBObjectLIST<DBObject>("Variables");
    DBObjData *data;
    DBObjTable *table;
    DBObjRecord *record;

    for (argPos = 1; argPos < argNum;) {
        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], "-c", "--condition")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing expression!");
                return (CMfailed);
            }
            if (expr != (char *) NULL) {
                CMmsgPrint(CMmsgUsrError, "Expression is already set");
                return (CMfailed);
            }
            expr = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-f", "--from")) {
            int modeCodes[] = {false, true};
            const char *modes[] = {"all", "selection", (char *) NULL};

            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing selection mode!");
                return (CMfailed);
            }
            if ((fromSelection = CMoptLookup(modes, argv[argPos], true)) == DBFault) {
                CMmsgPrint(CMmsgUsrError, "Invalid selection mode!");
                return (CMfailed);
            }
            fromSelection = modeCodes[fromSelection];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-m", "--mode")) {
            int modeCodes[] = {true, false};
            const char *modes[] = {"select", "unselect", (char *) NULL};

            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing selection mode!");
                return (CMfailed);
            }
            if ((selectMode = CMoptLookup(modes, argv[argPos], true)) == DBFault) {
                CMmsgPrint(CMmsgUsrError, "Invalid selection mode!");
                return (CMfailed);
            }
            selectMode = modeCodes[selectMode];
            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, "     -c,--condition [ fieldname expression ]");
            CMmsgPrint(CMmsgInfo, "     -f,--from      [ [all] | selection ]");
            CMmsgPrint(CMmsgInfo, "     -m,--mode      [ [select] | unselect ]");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && ((int) strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

    if (argNum > 3) {
        CMmsgPrint(CMmsgUsrError, "Extra arguments!");
        return (CMfailed);
    }
    if (verbose) RGlibPauseOpen(argv[0]);

    if (expr != (char *) NULL) {
        operand = new DBMathOperand(expr);
        if (operand->Expand(variables) == DBFault) return (CMfailed);
    }

    data = new DBObjData();
    if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) {
        delete data;
        delete operand;
        return (CMfailed);
    }

    if (tableName == (char *) NULL) tableName = DBrNItems;

    if ((table = data->Table(tableName)) == (DBObjTable *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Invalid table!");
        delete data;
        delete operand;
        return (CMfailed);
    }

    if (expr != (char *) NULL) {
        if (operand->Configure(table->Fields()) == DBFault) {
            delete data;
            delete operand;
            return (CMfailed);
        }

        for (recID = 0; recID < table->ItemNum(); ++recID) {
            record = table->Item(recID);
            if (fromSelection && ((record->Flags() & DBObjectFlagSelected) != DBObjectFlagSelected))
                continue;
            if ((ret = operand->Int(record)) == true)
                record->Flags(DBObjectFlagSelected, selectMode ? DBSet : DBClear);
            else if (selectMode) record->Flags(DBObjectFlagSelected, DBClear);
        }
    }
    else {
        for (recID = 0; recID < table->ItemNum(); ++recID) {
            record = table->Item(recID);
            if (fromSelection && ((record->Flags() & DBObjectFlagSelected) != DBObjectFlagSelected))
                continue;
            record->Flags(DBObjectFlagSelected, selectMode ? DBSet : DBClear);
        }
    }

    ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout);

    if (expr != (char *) NULL) delete operand;
    delete data;
    delete variables;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Example #25
0
int main (int argc,char *argv [])

	{
	int argPos, argNum = argc, ret, verbose = false;
	DBInt fromSelection = false, recID;
	char *tableName = (char *) NULL;
	char *expr = (char *) NULL;
	DBMathOperand *operand;
	DBObjectLIST<DBObject> *variables = new DBObjectLIST<DBObject> ("Variables");
	DBObjData *data;
	DBObjTable *table, *saveTable, *groups = (DBObjTable *) NULL, *saveGroups;
	DBObjRecord *record;

	for (argPos = 1;argPos < argNum; )
		{
		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],"-c","--condition"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing expression!");   return (CMfailed); }
			if (expr != (char *) NULL) { CMmsgPrint (CMmsgUsrError,"Expression is already set"); return (CMfailed); }
			expr = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-s","--selection"))
			{
			fromSelection = true;
			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,"     -c,--condition [expression]");
			CMmsgPrint (CMmsgInfo,"     -s,--selection");
			CMmsgPrint (CMmsgInfo,"     -V,--verbose");
			CMmsgPrint (CMmsgInfo,"     -h,--help");
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && ((int) strlen (argv [argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); }
		argPos++;
		}

	if (argNum > 3) { CMmsgPrint (CMmsgUsrError,"Extra arguments!"); return (CMfailed); }
	if (verbose) RGlibPauseOpen (argv[0]);

	if (expr != (char *) NULL)
		{
		operand = new DBMathOperand (expr);
		if (operand->Expand (variables) == DBFault) return (CMfailed);
		}

	data = new DBObjData ();
	if (((argNum > 1) && (strcmp (argv [1],"-") != 0) ? data->Read (argv [1]) : data->Read (stdin)) == DBFault)
		{ delete data; delete operand; return (CMfailed); }

	if (tableName == (char *) NULL) tableName = DBrNItems;

	if ((table = data->Table (tableName)) == (DBObjTable *) NULL)
		{ CMmsgPrint (CMmsgUsrError,"Invalid table!"); delete data; delete operand; return (CMfailed); }

	saveTable = new DBObjTable (*table);
	table->DeleteAll ();
	if ((strcmp (tableName,DBrNItems) == 0) && ((groups = data->Table (DBrNGroups)) != (DBObjTable *) NULL))
		{
		saveGroups = new DBObjTable (*groups);
		groups->DeleteAll ();
		}

	if (expr != (char *) NULL)
		{
		if (operand->Configure (saveTable->Fields()) == DBFault)
			{ delete data; delete operand; return (CMfailed); }
	
		for (recID = 0;recID < saveTable->ItemNum ();++recID)
			{
			record = saveTable->Item (recID);
			if ((ret = operand->Int (record)) == true)
				{
				if (!fromSelection) continue;
				if ((record->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected) continue;
				}
			table->Add (new DBObjRecord (*record));
			if (groups != (DBObjTable *) NULL) groups->Add (new DBObjRecord (*(saveGroups->Item (recID))));
			}
		}
	else
		{
		if (fromSelection)
			{
			for (recID = 0;recID < saveTable->ItemNum ();++recID)
				{
				record = saveTable->Item (recID);
				if ((record->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected)
					{
					table->Add (new DBObjRecord (*record));
					if (groups != (DBObjTable *) NULL)
						groups->Add (new DBObjRecord (*(saveGroups->Item (recID))));
					}
				}
			}
		}

	if (expr != (char *) NULL) delete operand;
	delete variables;
	delete saveTable;
	if (groups != (DBObjTable *) NULL) delete saveGroups;

	ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? data->Write (argv [2]) : data->Write (stdout);

	delete data;
	if (verbose) RGlibPauseClose ();
	return (ret);
	}
Example #26
0
void RGISEditPointSTNCoordsCBK (Widget widget,void *data,XmAnyCallbackStruct *callData)

	{
	char *text;
	static DBInt cont;
	DBDataset *dataset;
	DBObjData *dbData;
	DBObjTable *table;
	DBObjTableField *field = (DBObjTableField *) NULL;
	static Widget dShell = NULL, mainForm, button, textF;

	widget = widget; data = data; callData = callData;

	if (dShell == (Widget) NULL)
		{
		XmString string;

		dShell = UIDialogForm ((char *) "Area Field",false);
		mainForm = UIDialogFormGetMainForm (dShell);

		string = XmStringCreate ((char *) "Select",UICharSetBold);
		button = XtVaCreateManagedWidget ("RGISEditPointSTNBestCoordsButton",xmPushButtonWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_FORM,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNmarginHeight,			5,
								XmNtraversalOn,			False,
								XmNlabelString,			string,
								XmNuserData,				DBTableFieldIsCategory,
								NULL);
		XmStringFree (string);
		textF = XtVaCreateManagedWidget ("RGISEditPointSTNBestCoordsTextF",xmTextFieldWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			button,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNmaxLength,				DBStringLength,
								XmNcolumns,					DBStringLength / 2,
								NULL);
		XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _RGISEditPointSTNCoordsSelectCBK,textF);
		string = XmStringCreate ((char *) "Area Field:",UICharSetBold);
		XtVaCreateManagedWidget ("RGISEditJoinTableNameLabel",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,				10,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			textF,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNlabelString,			string,
								NULL);
		XmStringFree (string);
		XtAddCallback (UIDialogFormGetOkButton (dShell),XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&cont);
		XtSetSensitive (UIDialogFormGetOkButton (dShell),true);
		}

	dataset = UIDataset ();
	dbData = dataset->Data ();
	table = dbData->Table (DBrNItems);
	XtVaSetValues (textF,XmNuserData,table->Fields (),NULL);
	UIDialogFormPopup (dShell);
	cont = false;
	while (UILoop ());
		{
		if (strlen (text = XmTextFieldGetString (textF)) > 0)
		field = table->Field (text);
/*		if ((strlen (text = XmTextFieldGetString (textF)) > 0) &&
			 ((field = table->Field (text)) != (DBObjTableField *) NULL))
				XtSetSensitive (UIDialogFormGetOkButton (dShell),True);
		else	XtSetSensitive (UIDialogFormGetOkButton (dShell),False);
*/		XtFree (text);
		}

	UIDialogFormPopdown (dShell);
	if (cont)
		{
		UIPauseDialogOpen ((char *) "Moving Points");
		RGlibPointSTNCoordinates (dbData,field);
		UIPauseDialogClose ();
		UI2DViewRedrawAll ();
		}
	}
Example #27
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    DBInt recID, i, deg, min, sec, strLen;
    DBFloat coord;
    char crdStr[DBStringLength];
    char *minStr, *secStr;
    char *tableName = (char *) NULL;
    char *srcFieldName = (char *) NULL;
    char *dstFieldName = (char *) NULL;
    DBObjData *data;
    DBObjTable *table;
    DBObjTableField *srcField;
    DBObjTableField *dstField;
    DBObjRecord *record;

    for (argPos = 1; argPos < argNum;) {
        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], "-f", "--field")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing field name!");
                return (CMfailed);
            }
            srcFieldName = 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 second field name!");
                return (CMfailed);
            }
            dstFieldName = 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, "     -f,--field     [coord field name]");
            CMmsgPrint(CMmsgInfo, "     -r,--rename    [output field]");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && ((int) strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

    if (argNum > 3) {
        CMmsgPrint(CMmsgUsrError, "Extra arguments!");
        return (CMfailed);
    }
    if (verbose) RGlibPauseOpen(argv[0]);

    if (srcFieldName == (char *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Coordinate field is not set!");
        return (CMfailed);
    }

    data = new DBObjData();
    if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) {
        delete data;
        return (CMfailed);
    }

    if (tableName == (char *) NULL) tableName = DBrNItems;

    if ((table = data->Table(tableName)) == (DBObjTable *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Invalid table!");
        delete data;
        return (CMfailed);
    }

    if ((srcField = table->Field(srcFieldName)) == (DBObjTableField *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Invalid coordinate field [%s]!", srcFieldName);
        delete data;
        return (CMfailed);
    }


    if (dstFieldName == (char *) NULL) dstFieldName = (char *) "DecimalCoord";
    {
        if ((dstField = table->Field(dstFieldName)) == (DBObjTableField *) NULL) {
            dstField = new DBObjTableField(dstFieldName, DBVariableFloat, "%10.3f", sizeof(DBFloat4), false);
            table->AddField(dstField);
        }
        else {
            if (dstField->Type() != DBVariableFloat) {
                CMmsgPrint(CMmsgUsrError, "Invalid coordinate field type!");
                delete data;
                return (CMfailed);
            }
        }
    }

    for (recID = 0; recID < table->ItemNum(); ++recID) {
        record = table->Item(recID);
        strncpy(crdStr, srcField->String(record), sizeof(crdStr) - 1);
        if ((strLen = strlen(crdStr)) > 0) {
            minStr = secStr = (char *) NULL;
            for (i = 0; i < strLen; ++i)
                if (crdStr[i] == ':') minStr = crdStr + i + 1;
                else if (crdStr[i] == '\'') secStr = crdStr + i + 1;
                else if (crdStr[i] == '\"') crdStr[i] = '\0';
            if (sscanf(crdStr, "%d", &deg) != 1) continue;
            coord = (float) deg;
            if ((minStr != (char *) NULL) && (sscanf(minStr, "%d", &min) == 1)) {
                coord = coord + (deg > 0 ? 1.0 : -1.0) * (DBFloat) min / 60.0;
                if ((secStr != (char *) NULL) && (sscanf(secStr, "%d", &sec) == 1))
                    coord = coord + (deg > 0 ? 1.0 : -1.0) * (DBFloat) sec / 3600.0;
            }
            dstField->Float(record, coord);
        }
    }

    ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout);

    delete data;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Example #28
0
void RGISAnalyseLineSSampleGridCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	char *fText;
	int allowOk;
	static int sample;
	DBDataset *dataset = UIDataset ();
	DBObjData *dbData  = dataset->Data (), *grdData = dbData->LinkedData ();
	DBObjTable *itemTable = dbData->Table (DBrNItems);
	static Widget dShell = (Widget) NULL, mainForm;
	static Widget fromNameTextF, toNameTextF;
	XmString string;

	widget = widget;	workspace = workspace; callData = callData;
	_RGISAnLineSampleGridFields = itemTable->Fields ();
	if (dShell == (Widget) NULL)
		{
		Widget button;

		dShell = UIDialogForm ((char *) "Single Layer Grid Sampling",false);
		mainForm = UIDialogFormGetMainForm (dShell);

		string = XmStringCreate ((char *) "Select",UICharSetBold);
		button = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameButton",xmPushButtonWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_FORM,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNmarginHeight,			5,
								XmNtraversalOn,			False,
								XmNlabelString,			string,
								XmNuserData,				grdData->Type () == DBTypeGridContinuous ? DBTableFieldIsNumeric : DBTableFieldIsCategory,
								NULL);
		XmStringFree (string);
		fromNameTextF = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameTextF",xmTextFieldWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			button,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNmaxLength,				DBStringLength,
								XmNcolumns,					DBStringLength / 2,
								NULL);
		XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _RGIAnalyseLineSSampleGridSSelectCBK,fromNameTextF);
		string = XmStringCreate ((char *) "From Field:",UICharSetBold);
		XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameLabel",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,				10,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			fromNameTextF,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNlabelString,			string,
								NULL);
		XmStringFree (string);

		string = XmStringCreate ((char *) "Select",UICharSetBold);
		button = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameButton",xmPushButtonWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_WIDGET,
								XmNtopWidget,				button,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_FORM,
								XmNbottomOffset,			10,
								XmNmarginHeight,			5,
								XmNtraversalOn,			False,
								XmNlabelString,			string,
								XmNuserData,				grdData->Type () == DBTypeGridContinuous ? DBTableFieldIsNumeric : DBTableFieldIsCategory,
								NULL);
		XmStringFree (string);
		toNameTextF = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameTextF",xmTextFieldWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			button,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNmaxLength,				DBStringLength,
								XmNcolumns,					DBStringLength / 2,
								NULL);
		XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _RGIAnalyseLineSSampleGridSSelectCBK,toNameTextF);
		string = XmStringCreate ((char *) "To Field:",UICharSetBold);
		XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameLabel",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,				10,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			toNameTextF,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNlabelString,			string,
								NULL);
		XmStringFree (string);
		XtAddCallback (UIDialogFormGetOkButton (dShell),XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&sample);
		}

	sample = false;
	UIDialogFormPopup (dShell);
	while (UILoop ())
		{
		allowOk = false;
		fText = XmTextFieldGetString (fromNameTextF);
		if (strlen (fText) > 0) allowOk = true;
		XtFree (fText);
		fText = XmTextFieldGetString (toNameTextF);
		if (strlen (fText) > 0) allowOk = true;
		XtFree (fText);
		XtSetSensitive (UIDialogFormGetOkButton (dShell),allowOk);
		}
	UIDialogFormPopdown (dShell);

	if (sample)
		{
		DBInt ret;
		DBFloat value;
		DBCoordinate coord;
		DBGridIF *gridIF = new DBGridIF (grdData);
		DBVLineIF *lineIF = new DBVLineIF (dbData);
		DBObjTableField *fromField;
		DBObjTableField *toField;
		DBObjRecord *record;

		fText = XmTextFieldGetString (fromNameTextF);
		if (strlen (fText) > 0)
			{
			if ((fromField = itemTable->Field (fText)) == (DBObjTableField *) NULL)
				itemTable->AddField (fromField = new DBObjTableField (fText,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)));
			}
		else	fromField = (DBObjTableField *) NULL;
		XtFree (fText);
		fText = XmTextFieldGetString (toNameTextF);
		if (strlen (fText) > 0)
			{
			if ((toField = itemTable->Field (fText)) == (DBObjTableField *) NULL)
				itemTable->AddField (toField = new DBObjTableField (fText,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)));
			}
		else	toField = (DBObjTableField *) NULL;
		XtFree (fText);

		UIPauseDialogOpen ((char *) "Sampling Grid");
		for (record = itemTable->First ();record != (DBObjRecord *) NULL;record = itemTable->Next ())
			{
			if (UIPause (record->RowID () * 100 / itemTable->ItemNum ())) goto Stop;
			if (fromField != (DBObjTableField *) NULL)
				{
				coord = lineIF->FromCoord (record);
				ret = gridIF->Value (coord,&value);
				if (fromField->Type () == DBTableFieldFloat)
					{
					if (ret)	fromField->Float (record,value);
					else		fromField->Float (record,fromField->FloatNoData ());
					}
				else
					{
					if (ret)	fromField->Int (record,(DBInt) value);
					else		fromField->Int (record,fromField->IntNoData ());
					}
				}
			if (toField != (DBObjTableField *) NULL)
				{
				coord = lineIF->ToCoord (record);
				ret = gridIF->Value (coord,&value);
				if (toField->Type () == DBTableFieldFloat)
					{
					if (ret)	toField->Float (record,value);
					else		toField->Float (record,toField->FloatNoData ());
					}
				else
					{
					if (ret)	toField->Int (record,(DBInt) value);
					else		toField->Int (record,toField->IntNoData ());
					}
				}
			}
Stop:
		UIPauseDialogClose ();
		delete lineIF;
		delete gridIF;
		}
	}
Example #29
0
int main (int argc,char *argv [])

	{
	int argPos, argNum = argc, ret, i, fieldNum = 0, verbose = false;
	DBObjData *data;
	char *tableName = (char *) NULL, **fieldNames;
	DBObjTable *table;
	DBObjTableField *field;

	for (argPos = 1;argPos < argNum; )
		{
		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],"-f","--field"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing field name!");   return (CMfailed); }
			fieldNames = fieldNum > 0 ? (char **) realloc (fieldNames,(fieldNum + 1) * sizeof (char *)) :
												 (char **) calloc (1,sizeof (char *));
			if (fieldNames == (char **) NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return (CMfailed); }
			fieldNames [fieldNum++] = 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>",CMprgName(argv[0]));
			CMmsgPrint (CMmsgInfo,"     -a,--table     [table name]");
			CMmsgPrint (CMmsgInfo,"     -f,--field     [field name]");
			CMmsgPrint (CMmsgInfo,"     -V,--verbose");
			CMmsgPrint (CMmsgInfo,"     -h,--help");
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); }
		argPos++;
		}

	if (argNum > 3) { CMmsgPrint (CMmsgUsrError,"Extra arguments!"); return (CMfailed); }
	if (verbose) RGlibPauseOpen (argv[0]);

	if (tableName == (char *) NULL) tableName = DBrNItems;
	if (fieldNum < 1) { CMmsgPrint (CMmsgUsrError,"Missing field name!"); return (CMfailed); }

	data = new DBObjData ();
	if (((argNum > 1) && (strcmp (argv [1],"-") != 0) ? data->Read (argv [1]) : data->Read (stdin)) == DBFault)
		{ delete data; return (CMfailed); }

	if ((table = data->Table (tableName)) == (DBObjTable *) NULL)
		{ CMmsgPrint (CMmsgUsrError,"Invalid table: %s!",tableName); delete data; return (CMfailed); }

	for (i = 0;i < fieldNum;++i)
		{
		if ((field = table->Field (fieldNames [i])) == (DBObjTableField *) NULL)
			{ CMmsgPrint (CMmsgUsrError,"Invalid field: %s!",fieldNames [i]); continue; }
		if (DBTableFieldIsOptional (field) != true)
			{ CMmsgPrint (CMmsgUsrError,"Required field!"); continue; }
		table->DeleteField (field); 
		}

	ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? data->Write (argv [2]) : data->Write (stdout);

	free (fieldNames);
	delete data;
	if (verbose) RGlibPauseClose ();
	return (ret);
	}
Example #30
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    DBInt expr, expNum = 0, tmpVar;
    char *tableName = (char *) NULL;
    char *fieldName = (char *) NULL;
    CMDExpression **expressions = (CMDExpression **) NULL;
    DBInt recID;
    DBObjectLIST<DBObject> *variables = new DBObjectLIST<DBObject>("Variables");
    DBObjData *data;
    DBObjTable *table;
    DBObjRecord *record;

    for (argPos = 1; argPos < argNum;) {
        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], "-f", "--field") || CMargTest (argv[argPos], "-t", "--tmpfield")) {
            tmpVar = CMargTest (argv[argPos], "-t", "--tmpfield") ? true : false;
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) < argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing field name!");
                return (CMfailed);
            }
            fieldName = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) < argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing expression!");
                return (CMfailed);
            }
            expressions = expNum < 1 ? (CMDExpression **) calloc(1, sizeof(CMDExpression *)) :
                          (CMDExpression **) realloc(expressions, (expNum + 1) * sizeof(CMDExpression *));
            if (expressions == (CMDExpression **) NULL) {
                CMmsgPrint(CMmsgSysError, "Memory Allocation error in: %s %d", __FILE__, __LINE__);
                return (CMfailed);
            }
            expressions[expNum] = new CMDExpression(fieldName, argv[argPos], tmpVar);
            if ((expressions[expNum])->Expand(variables) == DBFault) {
                CMmsgPrint(CMmsgUsrError, "Invalid Expression!");
                return (CMfailed);
            }
            expNum++;
            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, "     -f,--field     [fieldname] [expression]");
            CMmsgPrint(CMmsgInfo, "     -t,--tmpfield  [fieldname] [expression]");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && ((int) strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

    if (argNum > 3) {
        CMmsgPrint(CMmsgUsrError, "Extra arguments!");
        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) {
        delete data;
        if (argNum > 1) CMmsgPrint(CMmsgUsrError, "File error in: %s", argv[1]);
        return (DBFault);
    }

    if (tableName == (char *) NULL) tableName = DBrNItems;

    if ((table = data->Table(tableName)) == (DBObjTable *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Invalid table!");
        delete data;
        return (CMfailed);
    }

    for (expr = 0; expr < expNum; ++expr)
        if (expressions[expr]->Configure(table) == DBFault) {
            CMmsgPrint(CMmsgUsrError, "Invalid expression");
            return (CMfailed);
        }

    for (recID = 0; recID < table->ItemNum(); ++recID) {
        record = table->Item(recID);
        for (expr = 0; expr < expNum; ++expr) expressions[expr]->Evaluate(record);
    }
    for (expr = 0; expr < expNum; ++expr) delete expressions[expr];

    ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout);

    free(expressions);
    delete data;
    delete variables;
    if (verbose) RGlibPauseClose();
    return (ret);
}