Ejemplo n.º 1
0
void DBGridOperationAbs(DBObjData *grdData) {
    DBInt layerID;
    DBFloat value;
    DBPosition pos;
    DBObjRecord *layerRec;
    DBGridIF *gridIF = new DBGridIF(grdData);

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) break;
    }
    if (layerID == gridIF->LayerNum()) {
        CMmsgPrint(CMmsgAppError, "No Layer to Process in %s %d", __FILE__, __LINE__);
        return;
    }

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;

        for (pos.Row = 0; pos.Row < gridIF->RowNum(); pos.Row++) {
            if (DBPause((layerID * gridIF->RowNum() + pos.Row) * 100 / (gridIF->LayerNum() * gridIF->RowNum())))
                goto Stop;
            for (pos.Col = 0; pos.Col < gridIF->ColNum(); pos.Col++)
                if (gridIF->Value(layerRec, pos, &value)) gridIF->Value(layerRec, pos, fabs(value));
        }
        gridIF->RecalcStats(layerRec);
    }
    Stop:
    return;
}
Ejemplo n.º 2
0
void DBGridOperation(DBObjData *grdData, DBFloat constant, DBInt oper) {
    DBInt layerID;
    DBFloat value;
    DBPosition pos;
    DBObjRecord *layerRec;
    DBGridIF *gridIF = new DBGridIF(grdData);

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) break;
    }
    if (layerID == gridIF->LayerNum()) {
        CMmsgPrint(CMmsgAppError, "No Layer to Process in %s %d", __FILE__, __LINE__);
        return;
    }

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;

        for (pos.Row = 0; pos.Row < gridIF->RowNum(); pos.Row++) {
            if (DBPause((layerID * gridIF->RowNum() + pos.Row) * 100 / (gridIF->LayerNum() * gridIF->RowNum())))
                goto Stop;
            for (pos.Col = 0; pos.Col < gridIF->ColNum(); pos.Col++) {
                if (gridIF->Value(layerRec, pos, &value))
                    switch (oper) {
                        case DBMathOperatorAdd:
                            gridIF->Value(layerRec, pos, value + constant);
                            break;
                        case DBMathOperatorSub:
                            gridIF->Value(layerRec, pos, value - constant);
                            break;
                        case DBMathOperatorMul:
                            gridIF->Value(layerRec, pos, value * constant);
                            break;
                        case DBMathOperatorDiv:
                            gridIF->Value(layerRec, pos, value / constant);
                            break;
                    }
            }
        }
        gridIF->RecalcStats(layerRec);
    }
    Stop:
    return;
}
Ejemplo n.º 3
0
DBInt RGlibGenFuncFieldCompare(DBObjTable *table, char *f0Text, char *f1Text, char *rText, DBInt diffMethod) {
    DBInt intVal, ret, i, rowID;
    DBFloat val[2];
    DBObjTableField *field[2];
    DBObjTableField *result;
    DBObjRecord *record;

    field[0] = table->Field(f0Text);
    field[1] = table->Field(f1Text);
    result = table->Field(rText);
    if ((field[0] == (DBObjTableField *) NULL) || (field[1] == (DBObjTableField *) NULL)) {
        CMmsgPrint(CMmsgAppError, "Invalid Compare Fields in: %s %d", __FILE__, __LINE__);
        return (DBFault);
    }
    if (result == (DBObjTableField *) NULL)
        table->AddField(result = new DBObjTableField(rText, DBTableFieldFloat, "%10.3f", sizeof(DBFloat4)));
    if (diffMethod > 0) result->Format("%6.2f");
    for (rowID = 0; rowID < table->ItemNum(); ++rowID) {
        record = table->Item(rowID);
        if ((record->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle)
            result->Float(record, result->FloatNoData());
        else {
            for (i = 0; i < 2; ++i)
                if (field[i]->Type() == DBTableFieldInt) {
                    intVal = field[i]->Int(record);
                    ret = intVal == field[i]->IntNoData();
                    val[i] = (DBFloat) intVal;
                }
                else {
                    val[i] = field[i]->Float(record);
                    ret = CMmathEqualValues(val[i], field[i]->FloatNoData());
                }
            if (ret) result->Float(record, result->FloatNoData());
            else
                switch (diffMethod) {
                    default:
                        result->Float(record, val[0] - val[1]);
                        break;
                    case 1:
                        result->Float(record, (val[0] - val[1]) * 100.0 / val[0]);
                        break;
                    case 2:
                        result->Float(record, (val[0] - val[1]) * 100.0 / (val[0] > val[1] ? val[0] : val[1]));
                        break;
                }
        }
    }
    return (DBSuccess);
}
Ejemplo n.º 4
0
DBInt DBObjData::SelectObject(DBObjRecord *record, DBInt select) {
    DBObjTable *items = TablesPTR->Item(DBrNItems);

    if (record == (DBObjRecord *) NULL) return (false);
    if (items->Item(record->RowID()) != record) return (false);

    record->Flags(DBObjectFlagSelected, select);
    if (Type() == DBTypeNetwork) {
        DBInt cellID;
        DBObjRecord *cellRec;
        DBNetworkIF *netIF = new DBNetworkIF(this);

        for (cellID = 0; cellID < netIF->CellNum(); ++cellID) {
            cellRec = netIF->Cell(cellID);
            if (netIF->CellBasinID(cellRec) == record->RowID() + 1)
                cellRec->Flags(DBObjectFlagSelected, select);
        }
        delete netIF;
    }
    return (DBSuccess);
}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
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);
	}
Ejemplo n.º 7
0
DBInt RGlibGenFuncFieldCalculate (DBObjTable *table,char *f0Text,char *f1Text,char *rText,DBInt oper)

	{
	DBInt intVal, ret = false, i, rowID;
	DBFloat val [2];
	DBObjTableField *field [2];
	DBObjTableField *result;
	DBObjRecord *record;
		
	field [0] = table->Field (f0Text);
	field [1] = table->Field (f1Text);
	result = table->Field (rText);

	if ((field [0] == (DBObjTableField *) NULL) && (sscanf (f0Text,"%lf",val) != 1)) 		return (DBFault);
	if ((field [1] == (DBObjTableField *) NULL) && (sscanf (f1Text,"%lf",val + 1) != 1))	return (DBFault);
	 
	if (result == (DBObjTableField *) NULL)
		table->AddField (result = new DBObjTableField (rText,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)));
	if (field [0] != (DBObjTableField *) NULL)
		result->Format (field [0]->Format ());
	else if (field [1] != (DBObjTableField *) NULL)
		result->Format (field [1]->Format ());

	for (rowID = 0;rowID < table->ItemNum ();++rowID)
		{
		record = table->Item (rowID);
		if ((record->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle)
			result->Float (record,result->FloatNoData ());
		else
			{
			for (i = 0;i < 2;++i)
				if (field [i] != (DBObjTableField *) NULL)
					{
					ret = false;
					if (field [i]->Type () == DBTableFieldInt) 
						{
						intVal = field [i]->Int (record);
						val [i] = (DBFloat) intVal;
						ret = intVal == field [i]->IntNoData ();
						}
					else
						{
						val [i] = field [i]->Float (record);
						ret = CMmathEqualValues (val [i],field [i]->FloatNoData ());
						}
					if (ret)
						{
						result->Float (record,result->FloatNoData ());
						goto Continue;
						}
					}
			if ((oper == DBMathOperatorDiv) && (val [1] == 0))
				result->Float (record,result->FloatNoData ());
			else
				switch (oper)
					{
					case DBMathOperatorAdd:	result->Float (record, val [0] + val [1]);	break;
					case DBMathOperatorSub:	result->Float (record, val [0] - val [1]);	break;
					case DBMathOperatorMul:	result->Float (record, val [0] * val [1]);	break;
					case DBMathOperatorDiv:	result->Float (record, val [0] / val [1]);	break;
					default:	CMmsgPrint (CMmsgAppError, "Invalid Operand in: %s %d",__FILE__,__LINE__);	break;
					}
Continue:
			continue;
			}
		}
	return (DBSuccess);
	}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
0
void RGISAnGNUXYPlotCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	FILE *file;
	char command [DBDataFileNameLen * 2 + DBStringLength];
	const char *ghaasDir;
	char *f0Text, *f1Text, fileName [12];
	int allowOk, fd;
	static int plot = false, logScale = false;
	DBDataset *dataset = UIDataset ();
	DBObjData *dbData  = dataset->Data ();
	DBObjTable *itemTable = dbData->Table (DBrNItems);
	static Widget dShell = (Widget) NULL, mainForm;
	static Widget field0TextF, field1TextF;
	Widget toggle;
	XmString string;

	if (dShell == (Widget) NULL)
		{
		Widget button;

		dShell = UIDialogForm ((char *) "Compare Fields",false);
		mainForm = UIDialogFormGetMainForm (dShell);

		string = XmStringCreate ((char *) "Select",UICharSetBold);
		button = XtVaCreateManagedWidget ("RGISEdiCompFieldsButton",xmPushButtonWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_FORM,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNmarginHeight,			5,
								XmNtraversalOn,			False,
								XmNlabelString,			string,
								XmNuserData,				DBTableFieldIsNumeric,
								NULL);
		XmStringFree (string);
		field0TextF = XtVaCreateManagedWidget ("RGISEditCompField0TextF",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) UIAuxObjectSelectCBK,field0TextF);
		string = XmStringCreate ((char *) "X Field:",UICharSetBold);
		XtVaCreateManagedWidget ("RGISEditCompFieldNameLabel",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,				10,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			field0TextF,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNlabelString,			string,
								NULL);
		XmStringFree (string);

		string = XmStringCreate ((char *) "Select",UICharSetBold);
		button = XtVaCreateManagedWidget ("RGISEditCompField0Button",xmPushButtonWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_WIDGET,
								XmNtopWidget,				button,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNmarginHeight,			5,
								XmNtraversalOn,			False,
								XmNlabelString,			string,
								XmNuserData,				DBTableFieldIsNumeric,
								NULL);
		XmStringFree (string);
		field1TextF = XtVaCreateManagedWidget ("RGISEditCompField1TextF",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) UIAuxObjectSelectCBK,field1TextF);
		string = XmStringCreate ((char *) "Y Field:",UICharSetBold);
		XtVaCreateManagedWidget ("RGISEditCompField1Label",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,				10,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			field1TextF,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNlabelString,			string,
								NULL);
		XmStringFree (string);
		string = XmStringCreate ((char *) "Logarithmic Scale",UICharSetBold);
		toggle = XtVaCreateManagedWidget ("RGISEditCompLogScaleToggle",xmToggleButtonWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_WIDGET,
								XmNtopWidget,				button,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_FORM,
								XmNbottomOffset,			10,
								XmNlabelString,			string,
								XmNhighlightThickness,	0,
								XmNshadowThickness,		0,
								XmNmarginWidth,			5,
								XmNset,						False,
								NULL);
 		XmStringFree (string);
 		XtAddCallback (toggle,XmNvalueChangedCallback,(XtCallbackProc) UIAuxSetToggleCBK, (XtPointer) &logScale);

		XtAddCallback (UIDialogFormGetOkButton (dShell),XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&plot);
		}
	plot = false;
	XtVaSetValues (field0TextF,XmNuserData, itemTable->Fields (), NULL);
	XtVaSetValues (field1TextF,XmNuserData, itemTable->Fields (), NULL);
	UIDialogFormPopup (dShell);
	while (UILoop ())
		{
		f0Text = XmTextFieldGetString (field0TextF);
		f1Text = XmTextFieldGetString (field1TextF);
		allowOk = (strlen (f0Text) > 0) && (strlen (f1Text) > 0);
		XtFree (f0Text);	XtFree (f1Text);
		XtSetSensitive (UIDialogFormGetOkButton (dShell),allowOk);
		}
	UIDialogFormPopdown (dShell);

	if (plot)
		{
		char buffer [256];
		DBInt intVal, rowID;
		DBFloat val;
		DBObjTableField *field0 = itemTable->Field (f0Text = XmTextFieldGetString (field0TextF));
		DBObjTableField *field1 = itemTable->Field (f1Text = XmTextFieldGetString (field1TextF));
		DBObjRecord *record;

		XtFree (f0Text);	XtFree (f1Text);
		if ((field0 == (DBObjTableField *) NULL) || (field1 == (DBObjTableField *) NULL))
			{ CMmsgPrint (CMmsgAppError, "Invalid Compare Fields in: %s %d",__FILE__,__LINE__);	return; }

		strcpy (fileName,"ghaasXXXXXX");
		if ((fd = mkstemp (fileName)) == DBFault)
			{ CMmsgPrint (CMmsgSysError, "File Opening Error in: %s %d",__FILE__,__LINE__); return; }

		if ((file = fdopen (fd,"w")) == (FILE *) NULL)
			{ CMmsgPrint (CMmsgSysError, "File Opening Error in: %s %d",__FILE__,__LINE__); return; }

		fprintf (file,"\"GHAASId\"\t\"RecordName\"\t\"Selected\"\t\"%s\"\t\"%s\"\n",field0->Name (),field1->Name ());
		for (rowID = 0;rowID < itemTable->ItemNum ();++rowID)
			{
			record = itemTable->Item (rowID);
			if ((record->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
			sprintf (buffer,"%d\t\"%s\"\t%d",record->RowID () + 1,record->Name (),
						(record->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected ? true : false);
			if (field0->Type () == DBTableFieldInt)
				{
				intVal = field0->Int (record);
				if (intVal == field0->IntNoData ()) continue;
				sprintf (buffer + strlen (buffer),"\t%d",intVal);
				}
			else
				{
				val = field0->Float (record);
				if (CMmathEqualValues (val,field0->FloatNoData ())) continue;
				sprintf (buffer + strlen (buffer),"\t%f",val);
				}
			if (field1->Type () == DBTableFieldInt)
				{
				intVal = field1->Int (record);
				if (intVal == field1->IntNoData ()) continue;
				sprintf (buffer + strlen (buffer),"\t%d",intVal);
				}
			else
				{
				val = field1->Float (record);
				if (CMmathEqualValues (val,field1->FloatNoData ())) continue;
				sprintf (buffer + strlen (buffer),"\t%f",val);
				}
			fprintf (file,"%s\n",buffer);
			}
		fclose (file);
		ghaasDir = getenv ("GHAAS_DIR");
		sprintf (command,"%s/Scripts/xy-plot.sh %s %s",ghaasDir != (const char *) NULL ? ghaasDir : ".",fileName,logScale ? "log" : "normal");
		system (command);
		unlink (fileName);
		}
	}
Ejemplo n.º 10
0
void RGISAnalysePointSTNPointsCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	char *srcText;
	static DBInt cont, diffMethod;
	DBDataset *dataset;
	DBObjData *dbData;
	DBObjTable *table;
	DBObjTableField *field = (DBObjTableField *) NULL;
	static Widget dShell = NULL, mainForm, button;
	static Widget srcTextF, dstTextF, cmpTextF, errTextF;
	static Widget menu, mButton;

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

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

		string = XmStringCreate ((char *) "Select",UICharSetBold);
		button = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsSrcButton",xmPushButtonWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_FORM,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNmarginHeight,			5,
								XmNtraversalOn,			False,
								XmNlabelString,			string,
								XmNuserData,				DBTableFieldIsNumeric,
								NULL);
		XmStringFree (string);
		srcTextF = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsSrcTextF",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) UIAuxObjectSelectCBK,srcTextF);
		string = XmStringCreate ((char *) "Area Field:",UICharSetBold);
		XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsSrcLabel",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,				10,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			srcTextF,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNlabelString,			string,
								NULL);
		XmStringFree (string);
		string = XmStringCreate ((char *) "Select",UICharSetBold);
		button = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsSrcButton",xmPushButtonWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_WIDGET,
								XmNtopWidget,				srcTextF,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNmarginHeight,			5,
								XmNtraversalOn,			False,
								XmNlabelString,			string,
								XmNuserData,				DBTableFieldIsNumeric,
								NULL);
		XmStringFree (string);
		dstTextF = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsDstTextF",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) UIAuxObjectSelectCBK,dstTextF);
		string = XmStringCreate ((char *) "Target Field:",UICharSetBold);
		XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsDstLabel",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,				10,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			dstTextF,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNlabelString,			string,
								NULL);
		XmStringFree (string);

		string = XmStringCreate ((char *) "Select",UICharSetBold);
		button = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsErrorButton",xmPushButtonWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_WIDGET,
								XmNtopWidget,				dstTextF,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNmarginHeight,			5,
								XmNtraversalOn,			False,
								XmNlabelString,			string,
								XmNuserData,				DBTableFieldIsNumeric,
								NULL);
		XmStringFree (string);
		cmpTextF = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsCompTextF",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) UIAuxObjectSelectCBK,cmpTextF);

		string = XmStringCreate ((char *) "Compare Field:",UICharSetBold);
		XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsDstLabel",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,				10,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			cmpTextF,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNlabelString,			string,
								NULL);
		XmStringFree (string);

		string = XmStringCreate ((char *) "Select",UICharSetBold);
		button = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsErrorButton",xmPushButtonWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_WIDGET,
								XmNtopWidget,				cmpTextF,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNmarginHeight,			5,
								XmNtraversalOn,			False,
								XmNlabelString,			string,
								XmNuserData,				DBTableFieldIsNumeric,
								NULL);
		XmStringFree (string);
		errTextF = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsErrorTextF",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) UIAuxObjectSelectCBK,errTextF);
		string = XmStringCreate ((char *) "Error Field:",UICharSetBold);
		XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsDstLabel",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,				10,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			errTextF,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNlabelString,			string,
								NULL);
		XmStringFree (string);

		menu = XmCreatePulldownMenu (mainForm,(char *) "RGISAnalysePointSTNPointsMenu",NULL,0);
		string = XmStringCreate ((char *) "Plain",UICharSetNormal);
		mButton = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsMenuButton",xmPushButtonWidgetClass,menu,
								XmNlabelString,			string,
								XmNuserData,				&diffMethod,
								NULL);
		XmStringFree (string);
		XtAddCallback (mButton,XmNactivateCallback,(XtCallbackProc) UIAuxSetIntegerCBK,(XtPointer) 0);
		string = XmStringCreate ((char *) "Simple %",UICharSetNormal);
		mButton = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsMenuButton",xmPushButtonWidgetClass,menu,
								XmNlabelString,			string,
								XmNuserData,				&diffMethod,
								NULL);
		XmStringFree (string);
		XtAddCallback (mButton,XmNactivateCallback,(XtCallbackProc) UIAuxSetIntegerCBK,(XtPointer) 1);
		string = XmStringCreate ((char *) "Symmetric %",UICharSetNormal);
		mButton = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsMenuButton",xmPushButtonWidgetClass,menu,
								XmNlabelString,			string,
								XmNuserData,				&diffMethod,
								NULL);
		XmStringFree (string);
		XtAddCallback (mButton,XmNactivateCallback,(XtCallbackProc) UIAuxSetIntegerCBK,(XtPointer) 2);
		string = XmStringCreate ((char *) "Difference Method:",UICharSetBold);
		menu = XtVaCreateManagedWidget ("RGISAnalysePointSTNPointsMenu",xmRowColumnWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_WIDGET,
								XmNtopWidget,				button,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_FORM,
								XmNbottomOffset,			10,
								XmNrowColumnType,			XmMENU_OPTION,
								XmNlabelString,			string,
								XmNsubMenuId,				menu,
								NULL);
		XmStringFree (string);
		XtAddCallback (UIDialogFormGetOkButton (dShell),XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&cont);
		XtSetSensitive (UIDialogFormGetOkButton (dShell),true);
		}

	dataset = UIDataset ();
	dbData = dataset->Data ();
	table = dbData->Table (DBrNItems);
	XtVaSetValues (srcTextF,XmNuserData,table->Fields (),NULL);
	XtVaSetValues (dstTextF,XmNuserData,table->Fields (),NULL);
	XtVaSetValues (cmpTextF,XmNuserData,table->Fields (),NULL);
	XtVaSetValues (errTextF,XmNuserData,table->Fields (),NULL);
	UIDialogFormPopup (dShell);
	cont = false;
	while (UILoop ())
		{
		if ((strlen (srcText = XmTextFieldGetString (srcTextF)) > 0) &&
			 ((field = table->Field (srcText)) != (DBObjTableField *) NULL))
				XtSetSensitive (UIDialogFormGetOkButton (dShell),True);
		else	XtSetSensitive (UIDialogFormGetOkButton (dShell),False);
		XtFree (srcText);
		if ((strlen (srcText = XmTextFieldGetString (cmpTextF)) > 0) &&
			 ((field = table->Field (srcText)) != (DBObjTableField *) NULL))
			{
			XtSetSensitive (button,True);
			XtSetSensitive (errTextF,True);
			XtSetSensitive (menu,True);
			}
		else
			{
			XmTextFieldSetString (errTextF,(char *) "");
			XtSetSensitive (button,False);
			XtSetSensitive (errTextF,False);
			XtSetSensitive (menu,False);
			}
		XtFree (srcText);
		}
	UIDialogFormPopdown (dShell);
	if (cont)
		{
		char dataName [DBDataNameLen + 5];
		DBObjData *netData = dbData->LinkedData ();

		sprintf (dataName,"%s STN",dbData->Name ());
		dbData = new DBObjData (*dbData);
		dbData->Name (dataName);
		if (UIDataHeaderForm (dbData))
			{
			char *dstText;
			DBObjTable *groups;
			DBObjRecord *pointRec;

			srcText = XmTextFieldGetString (srcTextF);
			dbData->LinkedData (netData);
			table = dbData->Table (DBrNItems);
			groups = dbData->Table (DBrNGroups);
			for (pointRec = table->First ();pointRec != (DBObjRecord *) NULL;pointRec = table->Next ())
				if ((pointRec->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle)
					{
					if (groups != (DBObjTable *) NULL)
						groups->Delete (groups->Item (pointRec->RowID ()));
					table->Delete (pointRec);
					pointRec = table->Next (DBBackward);
					}

			field = table->Field (srcText);
			XtFree (srcText);
			RGlibPointSTNCoordinates (dbData,field);
			UIPauseDialogOpen ((char *) "Moving Points");
			RGlibPointSTNCharacteristics (dbData);
			UIPauseDialogClose ();
			srcText = XmTextFieldGetString (srcTextF);
			if (strlen (dstText = XmTextFieldGetString (dstTextF)) > 0)
				{
				srcText = XmTextFieldGetString (srcTextF);
				RGlibGenFuncTopoSubtract (table,RGlibNextStation,srcText,dstText);
				XtFree (dstText);
				}
			if (strlen (dstText = XmTextFieldGetString (errTextF)) > 0)
				{
				char *cmpText;
				srcText = XmTextFieldGetString (srcTextF);
				cmpText = XmTextFieldGetString (cmpTextF);
				RGlibGenFuncFieldCompare (table,srcText,cmpText,dstText,diffMethod);
				XtFree (dstText);
				XtFree (cmpText);
				}
			XtFree (srcText);
			UI2DViewRedrawAll ();
			workspace->CurrentData (dbData);
			}
		else delete dbData;
		}
	}