Exemple #1
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 ();
	}
Exemple #2
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);
}
Exemple #3
0
void _RGISUserFuncionNetwork (DBObjData *data,UI2DView *view,XEvent *event)

	{
	DBInt sX, sY, redraw = false;
	DBNetworkIF *netIF;
	DBCoordinate coord;
	DBObjRecord *cellRec, *basinRec;
	void _RGISUserFuncionQuery (DBObjData *,UI2DView *,XEvent *);

	if ((data->Flags () & DBDataFlagUserModeFlags) == DBDataFlagUserModeQuery)
		{ _RGISUserFuncionQuery (data,view,event);	return; }

	if (event->type != ButtonPress) return;
	if (DBTypeNetwork != data->Type ())
		{ CMmsgPrint (CMmsgAppError, "Invalid data Type in: %s %d",__FILE__,__LINE__); }

	sX = event->xbutton.x;
	sY = event->xbutton.y;
	view->Window2Map  (sX,sY, &coord.X, &coord.Y);

	netIF = new DBNetworkIF (data);
	switch (data->Flags () & DBDataFlagUserModeFlags)
		{
		case DBDataFlagUserModeSelect:
			{
			DBInt basinID, cellID;
			DBRegion extent;
			UITable *tableView;

			if ((cellRec = netIF->Cell (coord)) == (DBObjRecord *) NULL)
				{ UIMessage ((char *) "Cell Does not Exists!"); return; }
			for (basinID = 0;basinID < netIF->BasinNum ();++basinID)
				{
				basinRec = netIF->Basin (basinID);
				if ((basinRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected)
					{
					data->SelectObject (basinRec,DBClear);
					extent.Expand (data->Extent (basinRec));
					}
				}
			for (cellID = 0;cellID < netIF->CellNum ();++cellID)
				{
				cellRec = netIF->Cell (cellID);
				if ((cellRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected)
					{
					extent.Expand (netIF->Center (cellRec) + (netIF->CellSize () / 2.0));
					extent.Expand (netIF->Center (cellRec) - (netIF->CellSize () / 2.0));
					cellRec->Flags (DBObjectFlagSelected,DBClear);
					}
				}
			if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNItems)))) != (UITable *) NULL)
				tableView->Draw ();
			if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNCells)))) != (UITable *) NULL)
				tableView->Draw ();
			UI2DViewRedrawAll (extent);
			cellRec = netIF->Cell (coord);
			switch (data->Flags () & DBDataFlagSelectMode)
				{
				case DBDataFlagSelectMode:	netIF->DownStreamSearch	(cellRec, DBNetworkSelect);	break;
				default:							netIF->UpStreamSearch	(cellRec, DBNetworkSelect);	break;
				}
			extent.Initialize ();
			for (cellID = 0;cellID < netIF->CellNum ();++cellID)
				{
				cellRec = netIF->Cell (cellID);
				if ((cellRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected)
					{
					extent.Expand (netIF->Center (cellRec) + (netIF->CellSize () / 2.0));
					extent.Expand (netIF->Center (cellRec) - (netIF->CellSize () / 2.0));
					}
				}
			UI2DViewRedrawAll (extent);
			if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNCells)))) != (UITable *) NULL)
				tableView->Draw ();
			} break;
		case DBDataFlagUserModeAdd:
			if (netIF->CellAdd (coord) == (DBObjRecord *) NULL) UIMessage ((char *) "Cell Creation Error");
			else redraw = true;
			break;
		case DBDataFlagUserModeDelete:
			if (netIF->CellDelete (coord) == DBFault) UIMessage ((char *) "Cell Does not Exists!");
			else redraw = true;
			break;
		case DBDataFlagUserModeRotate:
			{
			DBObjRecord *cellRec = netIF->Cell (coord);

			if (cellRec != (DBObjRecord *) NULL)
				{
				switch (netIF->CellDirection (cellRec))
					{
					case DBNull:     netIF->CellDirection (cellRec,DBNetDirN); break;
					case DBNetDirNW: netIF->CellDirection (cellRec,DBNull);    break;
					default:         netIF->CellRotate    (cellRec,DBForward); break;
					}
				redraw = true;
				}
			} break;
		default: printf ("Unknown Mode %lX",data->Flags () & DBDataFlagUserModeFlags); break;
		}
	if (redraw)
		{
		DBPosition pos;

		if (netIF->Coord2Pos (coord,pos) == DBSuccess)
			{
			DBRegion extent;
			DBCoordinate delta (netIF->CellWidth () * 1.25, netIF->CellHeight () * 1.25);

			netIF->Pos2Coord (pos,coord); coord = coord + delta; extent.Expand (coord);
			netIF->Pos2Coord (pos,coord); coord = coord - delta; extent.Expand (coord);
			UI2DViewRedrawAll (extent);
			}
		}
	delete netIF;
	}
Exemple #4
0
static void _RGISToolsNetBasinMouthCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	DBDataset *dataset = UIDataset ();
	DBObjData *netData = dataset->Data (), *pntData;
	DBNetworkIF *netIF;

	widget = widget; callData = callData;

	if (netData == (DBObjData *) NULL)
		{ CMmsgPrint (CMmsgAppError, "Null Data in: %s %d",__FILE__,__LINE__); return; }
	netIF = new DBNetworkIF (netData);

	if (UIDataHeaderForm (pntData = new DBObjData ("",DBTypeVectorPoint)))
		{
		char symName [DBStringLength];
		DBInt basinID, order;
		DBCoordinate coord;
		DBObjTable *items 	= pntData->Table (DBrNItems);
		DBObjTable *symbols	= pntData->Table (DBrNSymbols);
		DBObjTableField *coordField = items->Field (DBrNCoord);
		DBObjTableField *symbolFLD	 = items->Field (DBrNSymbol);
		DBObjTableField *orderFLD 	= new DBObjTableField (DBrNOrder,DBTableFieldInt,"%3d",sizeof (DBByte));
		DBObjTableField *subbasinLengthFLD = new DBObjTableField (DBrNSubbasinLength,DBTableFieldFloat,"%10.1f",sizeof (float));
		DBObjTableField *subbasinAreaFLD = new DBObjTableField (DBrNSubbasinArea,DBTableFieldFloat,"%10.1f",sizeof (float));
		DBObjTableField *foregroundFLD = symbols->Field (DBrNForeground);
		DBObjTableField *backgroundFLD = symbols->Field (DBrNBackground);
		DBObjTableField *styleFLD = symbols->Field (DBrNStyle);
		DBObjRecord *pntRec, *symRec, *cellRec, *basinRec;
		DBRegion dataExtent;

		items->AddField (orderFLD);
		items->AddField (subbasinLengthFLD);
		items->AddField (subbasinAreaFLD);

		cellRec = netIF->Cell ((DBInt) 0);
		for (order = 0;order <= netIF->CellOrder (cellRec);++order)
			{
			sprintf (symName,"Strahler Order:%2d",order);
			symRec = symbols->Add (symName);
			styleFLD->Int (symRec,0);
			foregroundFLD->Int (symRec,1);
			backgroundFLD->Int (symRec,0);
			}

		UIPauseDialogOpen ((char *) "Creating Basin Mouth");
		for (basinID = 0;basinID < netIF->BasinNum ();++basinID)
			{
			basinRec = netIF->Basin (basinID);
			if (UIPause (basinID * 100 / netIF->BasinNum ())) goto Stop;

			symRec = symbols->Item (netIF->CellOrder (cellRec));
			cellRec = netIF->MouthCell (basinRec);
			pntRec = items->Add (basinRec->Name ());
			coord = netIF->Center (cellRec);
			coordField->Coordinate (pntRec,coord);
			symbolFLD->Record (pntRec,symRec);
			orderFLD->Int (pntRec,netIF->CellOrder (cellRec));
			subbasinLengthFLD->Float (pntRec,netIF->CellBasinLength (cellRec));
			subbasinAreaFLD->Float (pntRec,netIF->CellBasinArea (cellRec));
			dataExtent.Expand (coord);
			}
Stop:
		UIPauseDialogClose ();
		pntData->Extent (dataExtent);
		workspace->CurrentData  (pntData);
		}
	else	delete pntData;
	delete netIF;
	}
Exemple #5
0
static void _RGISToolsExportNetworkCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	char *selection;
	FILE *outFILE;
	DBInt cellID, fieldID, fieldNum = 0;
	DBCoordinate coord;
	DBObjRecord *cellRec,*toCellRec, *basinRec;
	DBDataset *dataset = UIDataset ();
	DBObjData *netData = dataset->Data ();
	DBNetworkIF *netIF = new DBNetworkIF (netData);
	DBObjTable *cellTable = netData->Table (DBrNCells);
	DBObjTableField *field, **fields = (DBObjTableField **) NULL;
	static Widget dirSelect = NULL;

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

	if (dirSelect == NULL)
		{ if ((dirSelect = UIFileSelectionCreate ((char *) "Network File",NULL,(char *) "*.txt",XmFILE_REGULAR)) == NULL) return; }
	if ((selection = UIFileSelection (dirSelect,False)) == NULL) return;

	if ((outFILE = fopen (selection,"w")) == (FILE *) NULL)
		{ CMmsgPrint (CMmsgSysError, "File Opening Error in: %s %d",__FILE__,__LINE__); return; }
	fprintf (outFILE,"\"CellID\"\t\"XCoord\"\t\"YCoord\"\t\"BasinID\"\t\"ToCell\"\t\"CellArea\"\t\"CellLength\"");
	for (fieldID = 0;fieldID < cellTable->FieldNum (); fieldID++)
		{
		if ((field = cellTable->Field (fieldID)) == (DBObjTableField *) NULL)
			{
			if (fields != (DBObjTableField **) NULL) free (fields);
			CMmsgPrint (CMmsgSysError, "Invalid field in: %s %d",__FILE__,__LINE__);
			return;
			}
		if (field->Required ()) continue;
		if ((fields = (DBObjTableField **) realloc (fields,(fieldNum + 1) * sizeof (DBObjTableField *))) == (DBObjTableField **) NULL)
			{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return; }
		fields [fieldNum] = field;
		fprintf (outFILE,"\t\"%s\"",field->Name ());
		fieldNum++;
		}
	fprintf (outFILE,"\n");

	for (cellID = 0;cellID < netIF->CellNum (); cellID++)
		{
		cellRec = netIF->Cell (cellID);
		coord = netIF->Center (cellRec);
		basinRec = netIF->Basin (cellRec);
		toCellRec = netIF->ToCell (cellRec);
		fprintf (outFILE,"%d\t%f\t%f\t%d\t%d\t%f\t%f",cellRec->RowID () + 1,
														  coord.X, coord.Y,
														  basinRec->RowID () + 1,
														  toCellRec == (DBObjRecord *) NULL ? DBFault : toCellRec->RowID () + 1,
														  netIF->CellArea (cellRec),
														  netIF->CellLength (cellRec));
		for (fieldID = 0;fieldID < fieldNum; fieldID++)
			switch	(fields [fieldID]->Type ())
				{
				default:
				case DBTableFieldString: fprintf (outFILE,"%c\"%s\"",DBASCIISeparator,fields [fieldID]->String (cellRec)); break;
				case DBTableFieldInt:
					if (fields [fieldID]->Int (cellRec) == fields [fieldID]->IntNoData ())
						fprintf (outFILE,"%c",DBASCIISeparator);
					else	fprintf (outFILE,"%c%d",DBASCIISeparator,fields [fieldID]->Int (cellRec));
					break;
				case DBTableFieldFloat:
					if (CMmathEqualValues (fields [fieldID]->Float (cellRec),fields [fieldID]->FloatNoData ()))
						fprintf (outFILE,"%c",DBASCIISeparator);
					else	fprintf (outFILE,"%c%f",DBASCIISeparator,fields [fieldID]->Float (cellRec));
					break;
				case DBTableFieldDate:   fprintf (outFILE,"%c\"%s\"",DBASCIISeparator,fields [fieldID]->String(cellRec)); break;
				}
		fprintf (outFILE,"\n");
		}
	fclose (outFILE);
	}
Exemple #6
0
DBInt RGlibPointSTNCharacteristics(DBObjData *dbData) {
    DBInt i, pointID, dPointID, cellID, mouthID, basinID, color, ret = DBFault, dir;
    DBVPointIF *pntIF;
    DBObjTable *pointTable, *cellTable;
    DBObjTableField *cellIDFLD;
    DBObjTableField *basinFLD;
    DBObjTableField *basinNameFLD;
    DBObjTableField *orderFLD;
    DBObjTableField *colorFLD;
    DBObjTableField *basinCellsFLD;
    DBObjTableField *basinLengthFLD;
    DBObjTableField *basinAreaFLD;
    DBObjTableField *interAreaFLD;
    DBObjTableField *nextStationFLD;
    DBObjData *netData;
    DBNetworkIF *netIF;
    DBObjRecord *pointRec, *dPointRec, *cellRec, *fromCell, *basinRec;

    if ((netData = dbData->LinkedData()) == (DBObjData *) NULL) return (DBFault);
    pointTable = dbData->Table(DBrNItems);
    pntIF = new DBVPointIF(dbData);
    netIF = new DBNetworkIF(netData);
    cellTable = netData->Table(DBrNCells);
    if ((cellIDFLD = pointTable->Field(RGlibCellID)) == NULL) {
        cellIDFLD = new DBObjTableField(RGlibCellID, DBTableFieldInt, "%8d", sizeof(DBInt));
        pointTable->AddField(cellIDFLD);
        DBPause(1);
    }
    if ((basinFLD = pointTable->Field(DBrNBasin)) == NULL) {
        basinFLD = new DBObjTableField(DBrNBasin, DBTableFieldInt, "%8d", sizeof(DBInt));
        pointTable->AddField(basinFLD);
        DBPause(2);
    }
    if ((basinNameFLD = pointTable->Field(RGlibBasinName)) == NULL) {
        basinNameFLD = new DBObjTableField(RGlibBasinName, DBTableFieldString, "%32s", DBStringLength);
        pointTable->AddField(basinNameFLD);
        DBPause(3);
    }
    if ((orderFLD = pointTable->Field(DBrNOrder)) == NULL) {
        orderFLD = new DBObjTableField(DBrNOrder, DBTableFieldInt, "%3d", sizeof(DBByte));
        pointTable->AddField(orderFLD);
        DBPause(4);
    }
    if ((colorFLD = pointTable->Field(RGlibColor)) == NULL) {
        colorFLD = new DBObjTableField(RGlibColor, DBTableFieldInt, "%2d", sizeof(DBShort));
        pointTable->AddField(colorFLD);
        DBPause(5);
    }
    if ((basinCellsFLD = pointTable->Field(RGlibCellNum)) == NULL) {
        basinCellsFLD = new DBObjTableField(RGlibCellNum, DBTableFieldInt, "%8d", sizeof(DBInt));
        pointTable->AddField(basinCellsFLD);
        DBPause(6);
    }
    if ((basinLengthFLD = pointTable->Field(RGlibLength)) == NULL) {
        basinLengthFLD = new DBObjTableField(RGlibLength, DBTableFieldFloat, "%10.1f", sizeof(DBFloat4));
        pointTable->AddField(basinLengthFLD);
        DBPause(7);
    }
    if ((basinAreaFLD = pointTable->Field(RGlibArea)) == NULL) {
        basinAreaFLD = new DBObjTableField(RGlibArea, DBTableFieldFloat, "%10.1f", sizeof(DBFloat4));
        pointTable->AddField(basinAreaFLD);
        DBPause(8);
    }
    if ((interAreaFLD = pointTable->Field(RGlibInterStation)) == NULL) {
        interAreaFLD = new DBObjTableField(RGlibInterStation, DBTableFieldFloat, "%10.1f", sizeof(DBFloat4));
        pointTable->AddField(interAreaFLD);
        DBPause(9);
    }
    if ((nextStationFLD = pointTable->Field(RGlibNextStation)) == NULL) {
        nextStationFLD = new DBObjTableField(RGlibNextStation, DBTableFieldInt, "%8d", sizeof(DBInt));
        pointTable->AddField(nextStationFLD);
        DBPause(10);
    }
    if ((_RGlibTEMPPointIDFLD = cellTable->Field(RGlibTEMPPointID)) == NULL) {
        _RGlibTEMPPointIDFLD = new DBObjTableField(RGlibTEMPPointID, DBTableFieldInt, "%8d", sizeof(DBInt));
        cellTable->AddField(_RGlibTEMPPointIDFLD);
    }
    for (pointID = 0; pointID < pointTable->ItemNum(); pointID++) {
        pointRec = pointTable->Item(pointID);
        if (DBPause(10 + pointID * 10 / pointTable->ItemNum())) goto Stop;
        if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) {
            cellIDFLD->Int(pointRec, cellIDFLD->IntNoData());
            basinFLD->Int(pointRec, basinFLD->IntNoData());
            basinNameFLD->String(pointRec, "");
            orderFLD->Int(pointRec, orderFLD->IntNoData());
            colorFLD->Int(pointRec, colorFLD->IntNoData());
            basinCellsFLD->Int(pointRec, basinCellsFLD->IntNoData());
            basinAreaFLD->Float(pointRec, basinAreaFLD->FloatNoData());
            interAreaFLD->Float(pointRec, interAreaFLD->FloatNoData());
            continue;
        }
        if ((cellRec = netIF->Cell(pntIF->Coordinate(pointRec))) == (DBObjRecord *) NULL) {
            cellIDFLD->Int(pointRec, 0);
            basinFLD->Int(pointRec, 0);
            basinNameFLD->String(pointRec, "Water");
            orderFLD->Int(pointRec, colorFLD->IntNoData());
            colorFLD->Int(pointRec, colorFLD->IntNoData());
            basinCellsFLD->Int(pointRec, 0);
            basinAreaFLD->Float(pointRec, 0.0);
            interAreaFLD->Float(pointRec, 0.0);
        }
        else {
            cellIDFLD->Int(pointRec, cellRec->RowID() + 1);
            basinRec = netIF->Basin(cellRec);
            basinFLD->Int(pointRec, basinRec->RowID() + 1);
            basinNameFLD->String(pointRec, basinRec->Name());
            orderFLD->Int(pointRec, netIF->CellOrder(cellRec));
            colorFLD->Int(pointRec, 0);
            basinCellsFLD->Int(pointRec, netIF->CellBasinCells(cellRec));
            basinLengthFLD->Float(pointRec, netIF->CellBasinLength(cellRec));
            basinAreaFLD->Float(pointRec, netIF->CellBasinArea(cellRec));
            interAreaFLD->Float(pointRec, netIF->CellBasinArea(cellRec));
        }
        nextStationFLD->Int(pointRec, 0);
    }
    for (cellID = 0; cellID < cellTable->ItemNum(); ++cellID) {
        if (DBPause(20 + cellID * 20 / cellTable->ItemNum())) goto Stop;
        cellRec = cellTable->Item(cellID);
        _RGlibTEMPPointIDFLD->Int(cellRec, DBFault);
    }
    pointTable->ListSort(basinAreaFLD);
    for (pointRec = pointTable->Last(); pointRec != (DBObjRecord *) NULL; pointRec = pointTable->Next(DBBackward)) {
        if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
        if (DBPause(40 + pointID * 20 / pointTable->ItemNum())) goto Stop;
        cellRec = netIF->Cell(pntIF->Coordinate(pointRec));
        netIF->UpStreamSearch(cellRec, (DBNetworkACTION) _RGlibSetPointID,
                              (void *) ((char *) NULL + pointRec->RowID()));
    }
    for (pointID = 0; pointID < pointTable->ItemNum(); pointID++) {
        pointRec = pointTable->Item(pointID);
        if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
        if (DBPause(60 + pointID * 20 / pointTable->ItemNum())) goto Stop;
        if ((cellRec = netIF->Cell(pntIF->Coordinate(pointRec))) != (DBObjRecord *) NULL) {
            if ((cellRec = netIF->ToCell(cellRec)) == (DBObjRecord *) NULL) continue;
            if ((dPointID = _RGlibTEMPPointIDFLD->Int(cellRec)) != DBFault) {
                dPointRec = pointTable->Item(dPointID);
                nextStationFLD->Int(pointRec, dPointRec->RowID() + 1);
                interAreaFLD->Float(dPointRec, interAreaFLD->Float(dPointRec) - basinAreaFLD->Float(pointRec));
            }
        }
    }
    pointTable->ListSort(interAreaFLD);

    i = 0;
    for (pointRec = pointTable->Last(); pointRec != (DBObjRecord *) NULL; pointRec = pointTable->Next(DBBackward)) {
        if (DBPause(80 + (i++) * 20 / pointTable->ItemNum())) goto Stop;
        pointID = pointRec->RowID();
        if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;

        if ((basinID = basinFLD->Int(pointRec)) == 0) continue;
        cellRec = netIF->Cell(pntIF->Coordinate(pointRec));
        mouthID = cellRec->RowID();
        color = 1;
        Start:
        for (cellID = mouthID; cellID < cellTable->ItemNum(); ++cellID) {
            cellRec = cellTable->Item(cellID);
            if (netIF->CellBasinID(cellRec) != basinID) break;
            if (_RGlibTEMPPointIDFLD->Int(cellRec) != pointID) continue;

            for (dir = 0; dir < 8; ++dir) {
                if ((fromCell = netIF->FromCell(cellRec, 0x01 << dir, false)) == (DBObjRecord *) NULL) continue;
                if ((dPointID = _RGlibTEMPPointIDFLD->Int(fromCell)) == pointID) continue;
                if (dPointID == DBFault) continue;

                dPointRec = pointTable->Item(dPointID);
                if (colorFLD->Int(dPointRec) == color) {
                    color++;
                    goto Start;
                }
            }
        }
        colorFLD->Int(pointRec, color);
    }
    ret = DBSuccess;
    Stop:
    pointTable->ListSort();
    cellTable->DeleteField(_RGlibTEMPPointIDFLD);
    delete pntIF;
    delete netIF;
    return (ret);
}