Пример #1
0
void DBObjData::RecalcExtent() {
    DBRegion extent;

    switch (Type()) {
        case DBTypeVectorPoint:
        case DBTypeVectorLine:
        case DBTypeVectorPolygon: {
            DBVectorIF *vectorIF = new DBVectorIF(this);
            DBInt recordID;
            for (recordID = 0; recordID < vectorIF->ItemNum(); ++recordID)
                extent.Expand(Extent(vectorIF->Item(recordID)));
            delete vectorIF;
        }
            break;
        case DBTypeGridDiscrete:
        case DBTypeGridContinuous: {
            DBGridIF *gridIF = new DBGridIF(this);
            extent.LowerLeft = Extent().LowerLeft;
            extent.UpperRight.X = extent.LowerLeft.X + gridIF->ColNum() * gridIF->CellWidth();
            extent.UpperRight.Y = extent.LowerLeft.Y + gridIF->RowNum() * gridIF->CellHeight();
            delete gridIF;
        }
            break;
        case DBTypeNetwork: {
            DBNetworkIF *netIF = new DBNetworkIF(this);
            extent.LowerLeft = Extent().LowerLeft;
            extent.UpperRight.X = extent.LowerLeft.X + netIF->ColNum() * netIF->CellWidth();
            extent.UpperRight.Y = extent.LowerLeft.Y + netIF->RowNum() * netIF->CellHeight();
            delete netIF;
        }
            break;
        case DBTypeTable:
        default:
            return;
    }
    Extent(extent);
}
Пример #2
0
DBInt RGPDrawGridContinuous (DBInt mode, DBInt *entryNum, DBObjData *grdData)

	{
	DBInt r, g, b;
	DBInt ret, shadeNum, colorNum, scaleMode = 0;
	DBPosition pos;
	char charBuffer [RGPBufferSIZE], errorMsg [RGPBufferSIZE];
	const char *colorMaps [] = { "default", "grey", "blue", "red", "blue-red", "elevation", "custom", NULL };
	char colorMap;
	const char *scaleModes [] = { "linear", "logarithmic", "square-root", NULL };
	RGPColorMapEntry *customColors;
	DBFloat value;
	float *array, translation [6], min, max, unit = 1.0;
	DBRegion extent = grdData->Extent ();
	DBObjRecord *layerRec;
	DBGridIF *gridIF = new DBGridIF (grdData);

	do {
		RGPPrintMessage (mode,entryNum,"Grid Layer:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';
		if ((layerRec = gridIF->Layer (charBuffer)) != NULL) break;
		sprintf (errorMsg,"Invalid grid layer [%s]",charBuffer);
		if (RGPPrintError (mode,*entryNum,errorMsg)) { ret = DBFault; goto Stop;}
 		} while (true);

	do	{
		RGPPrintMessage (mode,entryNum,"Colormap [default|grey|blue|red-blue|elevation|custom]:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';
		if ((colorMap = CMoptLookup (colorMaps,charBuffer,true)) != DBFault) break;
		sprintf (errorMsg,"Invalid colormap [%s]",charBuffer);
		if (RGPPrintError (mode,*entryNum,errorMsg)) { ret = DBFault; goto Stop; }
		} while (true);
	switch (colorMap)
		{
		default:
		case 0:
			switch (grdData->Flags () & DBDataFlagDispModeFlags)
				{
				case DBDataFlagDispModeContStandard:
				case DBDataFlagDispModeContGreyScale:
					shadeNum = RGPSetColorMap (_RGPGreyColors,		RGPColorNum (_RGPGreyColors));		break;
				case DBDataFlagDispModeContBlueScale:
					shadeNum = RGPSetColorMap	(_RGPBlueColors,		RGPColorNum (_RGPBlueColors));		break;
				case DBDataFlagDispModeContBlueRed:
					shadeNum = RGPSetColorMap (_RGPBlueRedColors,	RGPColorNum (_RGPBlueRedColors));	break;
				case DBDataFlagDispModeContElevation:
					shadeNum = RGPSetColorMap (_RGPElevationColors,	RGPColorNum (_RGPElevationColors));	break;
				}
			break;
		case 1:	shadeNum = RGPSetColorMap (_RGPGreyColors,		RGPColorNum (_RGPGreyColors));		break;
		case 2:	shadeNum = RGPSetColorMap (_RGPBlueColors,		RGPColorNum (_RGPBlueColors));		break;
		case 3:	shadeNum = RGPSetColorMap (_RGPRedColors,			RGPColorNum (_RGPRedColors));			break;
		case 4:	shadeNum = RGPSetColorMap (_RGPBlueRedColors,	RGPColorNum (_RGPBlueRedColors));	break;
		case 5:	shadeNum = RGPSetColorMap (_RGPElevationColors,	RGPColorNum (_RGPElevationColors));	break;
		case 6:
			colorNum = 0;
			if ((customColors = (RGPColorMapEntry *) calloc (1,sizeof (RGPColorMapEntry))) == (RGPColorMapEntry *) NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); delete gridIF; return (DBFault); }
			do	{
				RGPPrintMessage (mode,entryNum,"Background Shade [red,green,blue]:");
				if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
				if (sscanf (charBuffer,"%d,%d,%d",&r,&g,&b) == 3)
					{
					customColors [colorNum].Red = r;
					customColors [colorNum].Green = g;
					customColors [colorNum].Blue = b;
					colorNum++;
					break;
					}
				else	if (RGPPrintError (mode,*entryNum,"Background Color Entry Error")) { ret = DBFault; goto Stop; }
				} while (true);
			do	{
				RGPPrintMessage (mode,entryNum,"Color Shade [red,green,blue]:");
				if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
				if (sscanf (charBuffer,"%d,%d,%d",&r,&g,&b) == 3)
					{
					if ((customColors = (RGPColorMapEntry *) realloc (customColors,(colorNum + 1) * sizeof (RGPColorMapEntry))) == (RGPColorMapEntry *) NULL)
						{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); delete gridIF; return (DBFault); }
					customColors [colorNum].Red = r;
					customColors [colorNum].Green = g;
					customColors [colorNum].Blue = b;
					colorNum++;
					}
				else
					{
					if (colorNum < 3)
						{ if (RGPPrintError (mode,*entryNum,"Color Shade Entry Error")) { ret = DBFault; goto Stop; }}
					else	break;
					}
				} while (true);
			shadeNum = RGPSetColorMap (customColors,colorNum);
			free (customColors);
			break;
		}
	if (shadeNum == DBFault)	{ RGPPrintError (mode,*entryNum,"Colormap Initialization Error") ; ret = DBFault; goto Stop; }
	do	{
		RGPPrintMessage (mode,entryNum,"Scale mode [linear|logarithmic]:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';
		if ((scaleMode = CMoptLookup (scaleModes,charBuffer,true)) != DBFault) break;
		sprintf (errorMsg,"Invalid scale mode [%s]",charBuffer);
		if (RGPPrintError (mode,*entryNum,errorMsg)) { ret = DBFault; goto Stop; }
		} while (true);
	do	{
		RGPPrintMessage (mode,entryNum,"Value range [minimum,maximum]:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if (sscanf (charBuffer,"%f,%f",&min,&max) == 2)	break;
		else	if (RGPPrintError (mode,*entryNum,"Value range input error")) { ret = DBFault; goto Stop; }
		} while (true);
	if ((array = (float *) calloc (gridIF->RowNum () * gridIF->ColNum (),sizeof (float))) == (float *) NULL)
		{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); ret = DBFault; goto Stop; }
	for (pos.Row = 0;pos.Row < gridIF->RowNum ();++pos.Row)
		for (pos.Col = 0;pos.Col < gridIF->ColNum ();++pos.Col)
			if (gridIF->Value (layerRec,pos,&value))
					{
					value = value > min ? value : min;
					value = value < max ? value : max;
					switch (scaleMode)
						{
						default:
						case 0:	array [pos.Row * gridIF->ColNum () + pos.Col] = value; break;
						case 1:	array [pos.Row * gridIF->ColNum () + pos.Col] = log10 (value); break;
						case 2:	array [pos.Row * gridIF->ColNum () + pos.Col] = sqrt (value); break;
						}
					}
			else 	array [pos.Row * gridIF->ColNum () + pos.Col] = min - (max - min) / (float) shadeNum;

	translation [0] = extent.LowerLeft.X - gridIF->CellWidth () / 2.0;
	translation [1] = gridIF->CellWidth ();
	translation [2] = 0.0;
	translation [3] = extent.LowerLeft.Y - gridIF->CellHeight () / 2.0;
	translation [4] = 0.0;
	translation [5] = gridIF->CellHeight ();
	RGPPrintMessage (mode,entryNum,"Unit:");
	if ((fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) || (sscanf (charBuffer,"%f",&unit) != 1))
		{ RGPPrintError (mode,*entryNum,"Unit input error"), ret = DBFault; goto Stop; }

	RGPPrintMessage (mode,entryNum,"Unit label:");
	if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL)
		{ RGPPrintError (mode,*entryNum,"Unit label input error"); ret = DBFault; goto Stop; }
	if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';

/*	cpgsitf (scaleMode); */
	switch (scaleMode)
		{
		default:
		case 0:
			min = min - (max - min) / (float) shadeNum;
			max = max + (max - min) / (float) shadeNum;
			cpgwedg ("BI",0.0,5.0,min * unit,max * unit,charBuffer);
			cpgimag (array,pos.Col,pos.Row,1,pos.Col,1,pos.Row,min,max,translation);
			break;
		case 1:
			cpgwedg ("BI",0.0,5.0,log10 (min * unit),log10 (max * unit),charBuffer);
			cpgimag (array,pos.Col,pos.Row,1,pos.Col,1,pos.Row,log10 (min),log10 (max),translation);
			break;
		case 2:
			cpgwedg ("BI",0.0,5.0,sqrt (min * unit),sqrt (max * unit),charBuffer);
			cpgimag (array,pos.Col,pos.Row,1,pos.Col,1,pos.Row,sqrt (min),sqrt (max),translation);
			break;
		}

Stop:
	delete gridIF;
	return (ret);
	}
Пример #3
0
 DBFloat CellHeight() const { return (GridIF->CellWidth()); }
Пример #4
0
		DBInt Write (FILE *file,DBObjData *data)
			{
			char *dmRecord;
			DBInt layerID, docLen, dbType, intVal;
			DBFloat floatVal;
			DBPosition pos;
			DBObjRecord *layerRec;
			DBGridIF *gridIF = new DBGridIF (data);
			DMLayerHeader dmLayerHeader;

			dbType = gridIF->ValueType ();
			switch (dbType)
				{
				case DBTableFieldFloat: DataType (DMFloat);	break;
				case DBTableFieldInt:
					DataType (gridIF->ValueSize () > 1 ? DMInt : DMByte); 	break;
				}
			CellWidth (gridIF->CellWidth ());
			CellHeight (gridIF->CellHeight ());
			Extent (data->Extent ());
			LayerNum (gridIF->LayerNum ());
			RowNum (gridIF->RowNum ());
			ColNum (gridIF->ColNum ());
			dmRecord = (char *) calloc (RowNum () * ColNum (),DataType () != DMByte ? sizeof (int) : sizeof (char));
			if (dmRecord == (char *) NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return (DBFault); }

			DMFileHeader::Write (file);
			for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
				{
				layerRec = gridIF->Layer (layerID);
				dmLayerHeader.Description (layerRec->Name ());
				dmLayerHeader.Write (file);
				}
			docLen = strlen (data->Document (DBDocComment));
			if (fwrite (&docLen,sizeof (int),1,file) != 1)
				{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
			if (docLen > 0)
				{
				if (fwrite (data->Document (DBDocComment),docLen,1,file) != 1)
					{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
				}
			for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
				{
				layerRec = gridIF->Layer (layerID);
				switch (data->Type ())
					{
					case DBTypeGridContinuous:
						layerRec = gridIF->Layer (layerID);
						if (dbType == DBTableFieldFloat)
							{
							for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
								for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
									if (gridIF->Value (layerRec,pos,&floatVal))
										((float *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (float) floatVal;
									else
										((float *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = MissingValue ();
							}
						else
							{
							for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
								for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
									if (gridIF->Value (layerRec,pos,&intVal))
										{
										if (DataType () == DMInt)
											((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (int) intVal;
										else
											dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = intVal;
										}
									else
										{
										if (DataType () == DMInt)
											((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (int) MissingValue ();
										else
											dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = -99;
										}

							}
						break;
					case DBTypeGridDiscrete:
						for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
							for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
								{
								intVal = gridIF->GridValue (layerRec,pos);
								if (DataType () == DMInt)
									((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = intVal;
								else
									dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = -99;

								}
						break;
					default:
						CMmsgPrint (CMmsgAppError, "Invalid Data Type in: %s %d",__FILE__,__LINE__);
						free (dmRecord);
						delete gridIF;
						return (DBFault);
					}
				if ((DBInt) fwrite (dmRecord,DataType () == DMByte ? sizeof (char) : sizeof (int),DataPointNum (),file) != DataPointNum ())
					{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
				}
			free (dmRecord);
			delete gridIF;
			return (DBSuccess);
			}
Пример #5
0
DBInt DBGridCont2Network (DBObjData *gridData,DBObjData *netData, bool downhill)

	{
	DBInt basinID, layerID, zLayerID, zLayerNum, dir, maxDir, projection = gridData->Projection (), *zones;
	DBFloat elev0, elev1, delta, maxDelta, distance;
	DBCoordinate coord0, coord1;
	DBInt row, col;
	DBPosition pos, auxPos;
	char nameSTR [DBStringLength];
	DBObjTable *basinTable = netData->Table (DBrNItems);
	DBObjTable *cellTable  = netData->Table (DBrNCells);
	DBObjTable *layerTable = netData->Table (DBrNLayers);
	DBObjRecord *layerRec, *dataRec, *cellRec, *basinRec;

	DBObjTableField *mouthPosFLD = basinTable->Field (DBrNMouthPos);
	DBObjTableField *colorFLD		= basinTable->Field (DBrNColor);

	DBObjTableField *positionFLD	= cellTable->Field (DBrNPosition);
	DBObjTableField *toCellFLD		= cellTable->Field (DBrNToCell);
	DBObjTableField *fromCellFLD	= cellTable->Field (DBrNFromCell);
	DBObjTableField *orderFLD		= cellTable->Field (DBrNOrder);
	DBObjTableField *basinFLD		= cellTable->Field (DBrNBasin);
	DBObjTableField *basinCellsFLD= cellTable->Field (DBrNBasinCells);
	DBObjTableField *travelFLD		= cellTable->Field (DBrNTravel);
	DBObjTableField *upCellPosFLD	= cellTable->Field (DBrNUpCellPos);
	DBObjTableField *cellAreaFLD	= cellTable->Field (DBrNCellArea);
	DBObjTableField *subbasinLengthFLD = cellTable->Field (DBrNSubbasinLength);
	DBObjTableField *subbasinAreaFLD = cellTable->Field (DBrNSubbasinArea);

	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);
	DBObjData *zGridData = gridData->LinkedData ();
	DBGridIF *gridIF = new DBGridIF (gridData), *zGridIF;
	DBNetworkIF *netIF;

	if ((zGridData != (DBObjData *) NULL) && ((zGridData->Type () == DBTypeGridDiscrete) || (zGridData->Type () == DBTypeGridContinuous)))
		{
		zGridIF = new DBGridIF (zGridData);
		zLayerNum = zGridIF->LayerNum () + 1;
		}
	else { zGridIF = (DBGridIF *) NULL; zLayerNum = 1; }

	if ((zones = (DBInt *) calloc (9 * zLayerNum,sizeof (DBInt))) == (DBInt *) NULL)
		{
		CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__);
		if (zGridIF != (DBGridIF *) NULL) delete zGridIF;
		delete gridIF;
		return (DBFault);
		}
	layerTable->Add (DBrNLookupGrid);
	if ((layerRec = layerTable->Item (DBrNLookupGrid)) == (DBObjRecord *) NULL)
		{
		free (zones);
		if (zGridIF != (DBGridIF *) NULL) delete zGridIF;
		delete gridIF;
		return (DBFault);
		}

	netData->Projection (projection);
	netData->Extent (gridData->Extent ());
	cellWidthFLD->Float  (layerRec,gridIF->CellWidth ());
	cellHeightFLD->Float (layerRec,gridIF->CellHeight ());
	valueTypeFLD->Int (layerRec,DBTableFieldInt);
	valueSizeFLD->Int (layerRec,sizeof (DBInt));
	rowNumFLD->Int (layerRec,gridIF->RowNum ());
	colNumFLD->Int (layerRec,gridIF->ColNum ());

	dataRec = new DBObjRecord ("NetLookupGridRecord",((size_t) gridIF->RowNum ()) * gridIF->ColNum () * sizeof (DBInt),sizeof (DBInt));
	if (dataRec == (DBObjRecord *) NULL)
		{
		if (zGridIF != (DBGridIF *) NULL) delete zGridIF;
		return (DBFault);
		}
	layerFLD->Record (layerRec,dataRec);
	(netData->Arrays ())->Add (dataRec);
	for (pos.Row = 0;pos.Row < gridIF->RowNum ();pos.Row++)
		for (pos.Col = 0;pos.Col < gridIF->ColNum ();pos.Col++)
			((DBInt *) dataRec->Data ()) [pos.Row * gridIF->ColNum () + pos.Col] = DBFault;

	for (pos.Row = 0;pos.Row < gridIF->RowNum ();pos.Row++)
		{
		if (DBPause (10 * pos.Row / gridIF->RowNum ())) goto PauseStop;
		for (pos.Col = 0;pos.Col < gridIF->ColNum ();pos.Col++)
			{
			gridIF->Pos2Coord (pos,coord0);
			zLayerID = 0;
			if (zGridIF != (DBGridIF *) NULL)
				for ( ; zLayerID < zGridIF->LayerNum (); zLayerID++)
					{
					layerRec = zGridIF->Layer (zLayerID);
					if ((layerRec->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
					for (dir = 0;dir < 8;++dir)
						{
						row = pos.Row;
						col = pos.Col;
						if (((0x01 << dir) == DBNetDirNW) || ((0x01 << dir) == DBNetDirN) || ((0x01 << dir) == DBNetDirNE)) row++;
						if (((0x01 << dir) == DBNetDirSE) || ((0x01 << dir) == DBNetDirS) || ((0x01 << dir) == DBNetDirSW)) row--;
						if (((0x01 << dir) == DBNetDirNE) || ((0x01 << dir) == DBNetDirE) || ((0x01 << dir) == DBNetDirSE)) col++;
						if (((0x01 << dir) == DBNetDirNW) || ((0x01 << dir) == DBNetDirW) || ((0x01 << dir) == DBNetDirSW)) col--;
						if (row < 0) continue;
						if (col < 0) continue;
						if (row >= gridIF->RowNum ()) continue;
						if (col >= gridIF->ColNum ()) continue;
						auxPos.Row = row;
						auxPos.Col = col;
						gridIF->Pos2Coord (auxPos,coord1);
						switch (zGridData->Type ())
							{
							case DBTypeGridDiscrete:	basinID = zGridIF->GridValue (layerRec,coord1);	break;
							case DBTypeGridContinuous:	zGridIF->Value (layerRec,coord1,&basinID);		break;
							}
						zones [zLayerID * 9 + dir] = basinID;
						}
					switch (zGridData->Type ())
						{
						case DBTypeGridDiscrete:	basinID = zGridIF->GridValue (layerRec,coord0);	break;
						case DBTypeGridContinuous: zGridIF->Value (layerRec,coord0,&basinID);		break;
						}
					zones [zLayerID * 9 + 8] = basinID;
					}
			for (dir = 0;dir < 9;++dir) zones [zLayerID * 9 + dir] = 0;

			maxDir = DBFault;
			for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
				{
				layerRec = gridIF->Layer (layerID);
				if ((layerRec->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
				if (gridIF->Value (layerRec,pos,&elev0))
					{
					maxDelta = (DBFloat) 0.0;
					maxDir   = 0;

					for (zLayerID = 0;zLayerID < zLayerNum;++zLayerID)
						{
						for (dir = 0;dir < 8;++dir)
							{
							row = pos.Row;
							col = pos.Col;
							if (((0x01 << dir) == DBNetDirNW) || ((0x01 << dir) == DBNetDirN) || ((0x01 << dir) == DBNetDirNE)) row++;
							if (((0x01 << dir) == DBNetDirSE) || ((0x01 << dir) == DBNetDirS) || ((0x01 << dir) == DBNetDirSW)) row--;
							if (((0x01 << dir) == DBNetDirNE) || ((0x01 << dir) == DBNetDirE) || ((0x01 << dir) == DBNetDirSE)) col++;
							if (((0x01 << dir) == DBNetDirNW) || ((0x01 << dir) == DBNetDirW) || ((0x01 << dir) == DBNetDirSW)) col--;
							if (col < 0) continue;
							if (row < 0) continue;
							if (col >= gridIF->ColNum ()) continue;
							if (row >= gridIF->RowNum ()) continue;
							auxPos.Row = row;
							auxPos.Col = col;
							gridIF->Pos2Coord (auxPos,coord1);
							distance = DBMathCoordinateDistance (projection,coord0,coord1);
							if ((zones [zLayerID * 9 + dir] == zones [zLayerID * 9 + 8]) && (gridIF->Value (layerRec,auxPos,&elev1)))
								{
								delta = (downhill ? (elev1 - elev0) : (elev0 - elev1)) / distance;
								if (maxDelta > delta) { maxDelta = delta; maxDir = (0x01 << dir); }
								}
							}
						if (maxDir != 0) goto SlopeStop;
						}
					}
				}
SlopeStop:
			if (maxDir != DBFault)
				{
				sprintf (nameSTR,"GHAASCell:%d",cellTable->ItemNum ());
				cellRec = cellTable->Add (nameSTR);
				positionFLD->Position(cellRec,pos);
				toCellFLD->Int			(cellRec,(DBInt) maxDir);
				fromCellFLD->Int		(cellRec,(DBInt) 0);
				orderFLD->Int			(cellRec,(DBInt) 0);
				basinFLD->Int			(cellRec,(DBInt) 0);
				basinCellsFLD->Int	(cellRec,(DBInt) 0);
				travelFLD->Int			(cellRec,(DBInt) 0);
				upCellPosFLD->Position	(cellRec,pos);
				cellAreaFLD->Float	(cellRec,(DBFloat) 0.0);
				subbasinLengthFLD->Float(cellRec,(DBFloat) 0.0);
				subbasinAreaFLD->Float	(cellRec,(DBFloat) 0.0);
				((DBInt *) dataRec->Data ()) [pos.Row * gridIF->ColNum () + pos.Col] = cellRec->RowID ();
				}
			}
		}
PauseStop:
	if (pos.Row < gridIF->RowNum ())	return (DBFault);
	sprintf (nameSTR,"GHAASBasin%d",(DBInt) 0);
	basinRec = basinTable->Add (nameSTR);
	mouthPosFLD->Position	(basinRec,positionFLD->Position (cellTable->Item (0)));
	colorFLD->Int				(basinRec,0);

	free (zones);
	delete gridIF;
	if (zGridIF != (DBGridIF *) NULL) delete zGridIF;

	netData->Precision (DBMathMin (gridIF->CellWidth (),gridIF->CellHeight ()) / 25.0);
	netIF = new DBNetworkIF (netData);
	netIF->Build ();
	delete netIF;
	return (DBSuccess);
	}