コード例 #1
0
ファイル: RGlibGenFuncs.C プロジェクト: bandi13/RGIS
int RGlibGenFuncSymbolField (DBObjData *data, const char *fieldName)
	{
	DBInt recID;
	char symbolName [DBStringLength + 1];
	DBObjTable *table = data->Table (DBrNItems);
	DBObjTable *symbols = data->Table (DBrNSymbols);
	DBObjRecord *record, *symbolRec;
	DBObjTableField *field;
	DBObjTableField *symbolFLD;
	DBObjTableField *symbolIDFLD;
	DBObjTableField *foregroundFLD;
	DBObjTableField *backgroundFLD;
	DBObjTableField *styleFLD;

	if (table == (DBObjTable *) NULL) return (DBFault);
	if ((field = table->Field (fieldName)) == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Invalid field name in: %s %d",__FILE__,__LINE__);       return (DBFault); }
	if ((symbolFLD = table->Field (DBrNSymbol)) == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing symbol field in: %s %d",__FILE__,__LINE__);     return (DBFault); }
	if (symbols == (DBObjTable *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing symbol table in: %s %d",__FILE__,__LINE__);     return (DBFault); }
	if ((symbolIDFLD   = symbols->Field (DBrNSymbolID))   == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing symbolID field in: %s %d",__FILE__,__LINE__);   return (DBFault); }
	if ((foregroundFLD = symbols->Field (DBrNForeground)) == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing foreground field in: %s %d",__FILE__,__LINE__); return (DBFault); }
	if ((backgroundFLD = symbols->Field (DBrNBackground)) == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing background field in: %s %d",__FILE__,__LINE__); return (DBFault); }
	if ((styleFLD      = symbols->Field (DBrNStyle))      == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing style field in: %s %d",__FILE__,__LINE__);      return (DBFault); }

	symbols->DeleteAll ();
	for (recID = 0;recID < table->ItemNum (); ++recID)
		{
		record = table->Item (recID);
		DBPause (record->RowID () * 100 / table->ItemNum ());
		
		if (field->Type () == DBTableFieldString) sprintf (symbolName,"%s",field->String (record));
		else	sprintf (symbolName,"Symbol:%03d",field->Int (record));
		if ((symbolRec = (DBObjRecord *) symbols->Item (symbolName)) == (DBObjRecord *) NULL)
			{
			if ((symbolRec = symbols->Add (symbolName)) == NULL)
				{ CMmsgPrint (CMmsgAppError, "Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
			symbolIDFLD->Int (symbolRec,field->Type () == DBTableFieldString ? symbolRec->RowID () : field->Int (record));
			foregroundFLD->Int (symbolRec,1);
			backgroundFLD->Int (symbolRec,0);
			styleFLD->Int (symbolRec,0);
			}
		symbolFLD->Record (record,symbolRec);
		}
	return (DBSuccess);
	}
コード例 #2
0
ファイル: DBObjData.C プロジェクト: bmfekete/RGIS
DBObjData::DBObjData(DBObjData &data) : DBObject(data), DBDataHeader(data._Header()) {
    DBObjTable *table;
    DBObjRecord *record, *obj;
    DBObjTableField *field;
    DBObjectLIST<DBObjTableField> *fields;
    strcpy(FileNameSTR, "");
    TablesPTR = new DBObjectLIST<DBObjTable>(*data.TablesPTR);
    DocsPTR = new DBObjectLIST<DBObjRecord>(*data.DocsPTR);
    ArraysPTR = new DBObjectLIST<DBObjRecord>(*data.ArraysPTR);
    DispPTR = new DBObjectLIST<DBObject>("Data Display");
    LinkedDataPTR = (DBObjData *) NULL;
    for (table = TablesPTR->First(); table != (DBObjTable *) NULL; table = TablesPTR->Next()) {
        fields = table->Fields();
        for (record = table->First(); record != (DBObjRecord *) NULL; record = table->Next()) {
            for (field = fields->First(); field != (DBObjTableField *) NULL; field = fields->Next())
                switch (field->Type()) {
                    case DBTableFieldTableRec:
                    case DBTableFieldDataRec:
                        if ((obj = field->Record(record)) != NULL)
                            field->Record(record, (DBObjRecord *) ((char *) NULL + obj->RowID()));
                        else field->Record(record, (DBObjRecord *) DBFault);
                        break;
                }
        }
    }
    BuildFields();
}
コード例 #3
0
int DBObjTable::Write(FILE *file) {
    DBInt id;
    DBObjRecord *obj;
    DBObjRecord *record;
    DBObjTableField *field;

    if (DBObjectLIST<DBObjRecord>::Write(file) != DBSuccess) return (DBFault);
    if (FieldPTR->Write(file) != DBSuccess) return (DBFault);
    for (id = 0; id < FieldPTR->ItemNum(); ++id)
        if (FieldPTR->WriteItem(file, id) == DBFault) return (DBFault);

    for (id = 0; id < ItemNum(); ++id) {
        record = Item(id);
        for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next())
            switch (field->Type()) {
                case DBTableFieldTableRec:
                case DBTableFieldDataRec:
                    if ((obj = field->Record(record)) != (DBObjRecord *) NULL)
                        field->Record(record, (DBObjRecord *) ((char *) NULL + obj->RowID()));
                    else field->Record(record, (DBObjRecord *) DBFault);
                    break;
            }
        if (WriteItem(file, id) == DBFault) return (DBFault);
    }
    if (MethodPTR->Write(file) != DBSuccess) return (DBFault);
    for (id = 0; id < MethodPTR->ItemNum(); ++id) if (MethodPTR->WriteItem(file, id) == DBFault) return (DBFault);
    return (DBSuccess);
}
コード例 #4
0
int DBObjData::BuildFields() {
    DBInt ret = DBSuccess;
    DBObjTable *table, *refTable;
    DBObjRecord *tableRec;
    DBObjTableField *field;
    DBObjectLIST<DBObjTableField> *tableFLDs;

    for (table = TablesPTR->First(); table != (DBObjTable *) NULL; table = TablesPTR->Next()) {
        tableFLDs = table->Fields();
        for (field = tableFLDs->First(); field != (DBObjTableField *) NULL; field = tableFLDs->Next())
            switch (field->Type()) {
                case DBTableFieldTableRec:
                    if ((refTable = TablesPTR->Item(field->RecordProp())) == (DBObjTable *) NULL) {
                        CMmsgPrint(CMmsgAppError, "Corrupt Dataset in: %s %d", __FILE__, __LINE__);
                        ret = DBFault;
                        continue;
                    }
                    for (tableRec = table->First(); tableRec != (DBObjRecord *) NULL; tableRec = table->Next())
                        if ((DBInt) (field->Record(tableRec) - (DBObjRecord *) NULL) != DBFault)
                            field->Record(tableRec,
                                          refTable->Item((DBInt) ((char *) (field->Record(tableRec)) - (char *) NULL)));
                        else field->Record(tableRec, (DBObjRecord *) NULL);
                    break;
                case DBTableFieldDataRec:
                    for (tableRec = table->First(); tableRec != (DBObjRecord *) NULL; tableRec = table->Next())
                        if ((DBInt) (field->Record(tableRec) - (DBObjRecord *) NULL) != DBFault)
                            field->Record(tableRec, ArraysPTR->Item(
                                    (DBInt) ((char *) (field->Record(tableRec)) - (char *) NULL)));
                        else field->Record(tableRec, (DBObjRecord *) NULL);
                    break;
            }
    }
    return (ret);
}
コード例 #5
0
 void GetVariable(DBObjRecord *record, DBCoordinate coord) {
     switch ((GridIF->Data())->Type()) {
         case DBTypeGridContinuous: {
             DBFloat value;
             if (GridIF->Value(LayerRec, coord, &value))
                 TargetFLD->Float(record, value);
             else TargetFLD->Float(record, TargetFLD->FloatNoData());
         }
             break;
         case DBTypeGridDiscrete: {
             DBObjRecord *grdRec;
             if ((grdRec = GridIF->GridItem(LayerRec, coord)) != (DBObjRecord *) NULL)
                 switch (SourceFLD->Type()) {
                     case DBVariableString:
                         TargetFLD->String(record, SourceFLD->String(grdRec));
                         break;
                     case DBVariableInt:
                         TargetFLD->Int(record, SourceFLD->Int(grdRec));
                         break;
                     case DBVariableFloat:
                         TargetFLD->Float(record, SourceFLD->Float(grdRec));
                         break;
                     default:
                         break;
                 }
             else
                 switch (SourceFLD->Type()) {
                     case DBVariableString:
                         TargetFLD->String(record, "");
                         break;
                     case DBVariableInt:
                         TargetFLD->Int(record, SourceFLD->IntNoData());
                         break;
                     case DBVariableFloat:
                         TargetFLD->Float(record, SourceFLD->FloatNoData());
                         break;
                     default:
                         break;
                 }
         }
             break;
         default:
             CMmsgPrint(CMmsgUsrError, "Invalid grid type in: CMDgrdVariable:GetVariable ()");
             break;
     }
 }
コード例 #6
0
ファイル: DBObjTables.C プロジェクト: ztessler/RGIS
DBInt DBTableFieldIsOptional(const DBObject *obj) {
    DBObjTableField *tableField = (DBObjTableField *) obj;
    switch (tableField->Type()) {
        case DBTableFieldString:
        case DBTableFieldInt:
        case DBTableFieldFloat:
        case DBTableFieldDate:
            return (tableField->Required() ? false : true);
        default:
            return (false);
    }
}
コード例 #7
0
ファイル: DBObjTables.C プロジェクト: ztessler/RGIS
DBInt DBTableFieldIsVisible(const DBObject *obj) {
    DBObjTableField *tableField = (DBObjTableField *) obj;
    switch (tableField->Type()) {
        case DBTableFieldString:
        case DBTableFieldInt:
        case DBTableFieldFloat:
        case DBTableFieldDate:
            return (strlen(tableField->Format()) > 0 ? true : false);
        default:
            return (false);
    }
}
コード例 #8
0
ファイル: DBObjTables.C プロジェクト: ztessler/RGIS
static int _DBObjTableListSort(const DBObjRecord **obj0, const DBObjRecord **obj1) {
    DBInt ret = 0;
    DBObjTableField *field;
    DBDate date0, date1;

    for (field = _DBObjTableSortFields->First();
         field != (DBObjTableField *) NULL;
         field = _DBObjTableSortFields->Next()) {
        switch (field->Type()) {
            case DBTableFieldString:
                ret = strcmp(field->String(*obj0), field->String(*obj1));
                break;
            case DBTableFieldInt:
                ret = field->Int(*obj0) - field->Int(*obj1);
                break;
            case DBTableFieldFloat:
                if (field->Float(*obj0) - field->Float(*obj1) > 0.0) ret = 1;
                else if (field->Float(*obj0) - field->Float(*obj1) < 0.0) ret = -1;
                else ret = 0;
                break;
            case DBTableFieldDate:
                date0 = field->Date(*obj0);
                date1 = field->Date(*obj1);
                if (date0 > date1) ret = 1;
                else if (date0 < date1) ret = -1;
                else ret = 0;
                break;
            case DBTableFieldTableRec:
                ret = strcmp((*obj0)->Name(), (*obj1)->Name());
                break;
            case DBTableFieldDataRec:
                ret = (*obj0)->RowID() - (*obj1)->RowID();
                break;
        }
        if ((field->Flags() & DBObjectFlagSortReversed) == DBObjectFlagSortReversed) ret *= -1;
        if (ret != 0) return (ret);
    }
    if (ret == 0) ret = (*obj0)->ListPos() - (*obj1)->ListPos();
    return (ret);
}
コード例 #9
0
int DBObjTable::Read(FILE *file, int swap) {
    DBInt id;
    DBDate date;
    DBCoordinate coord;
    DBRegion region;
    DBPosition pos;
    DBUShort row, col;
    DBObjRecord *record;
    DBObjTableField *field;

    if (DBObjectLIST<DBObjRecord>::Read(file, swap) != DBSuccess) return (DBFault);
    if (FieldPTR->Read(file, swap) != DBSuccess) return (DBFault);
    for (id = 0; id < FieldPTR->ItemNum(); ++id)
        if (FieldPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);

    RecordLengthVAR = 0;
    for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next())
        RecordLengthVAR = RecordLengthVAR > field->StartByte() + field->Length() ?
                          RecordLengthVAR : field->StartByte() + field->Length();

    for (id = 0; id < ItemNum(); ++id) {
        if (ReadItem(file, id, swap) == DBFault) return (DBFault);
        record = Item(id);
        if (swap == false) continue;
        for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next())
            switch (field->Type()) {
                case DBTableFieldInt:
                case DBTableFieldFloat:
                case DBTableFieldTableRec:
                case DBTableFieldDataRec:
                    switch (field->Length()) {
                        case 2:
                            DBByteOrderSwapHalfWord((char *) record->Data() + field->StartByte());
                            break;
                        case 4:
                            DBByteOrderSwapWord((char *) record->Data() + field->StartByte());
                            break;
                        case 8:
                            DBByteOrderSwapLongWord((char *) record->Data() + field->StartByte());
                            break;
                    }
                    break;
                case DBTableFieldDate:
                    date = field->Date(record);
                    date.Swap();
                    field->Date(record, date);
                    break;
                case DBTableFieldCoord:
                    coord = field->Coordinate(record);
                    coord.Swap();
                    field->Coordinate(record, coord);
                    break;
                case DBTableFieldRegion:
                    region = field->Region(record);
                    region.Swap();
                    field->Region(record, region);
                    break;
                case DBTableFieldPosition:
                    pos = field->Position(record);
                    switch (field->Length()) {
                        case sizeof(DBPosition):
                            pos.Swap();
                            break;
                        default:
                            row = pos.Row;
                            col = pos.Col;
                            DBByteOrderSwapHalfWord(&row);
                            DBByteOrderSwapHalfWord(&col);
                            pos.Row = row;
                            pos.Col = col;
                            break;
                    }
                    field->Position(record, pos);
                    break;
                default:
                    break;
            }
    }
    if (MethodPTR->Read(file, swap) != DBSuccess) return (DBFault);
    for (id = 0; id < MethodPTR->ItemNum(); ++id) if (MethodPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
    return (DBSuccess);
}
コード例 #10
0
ファイル: RGISAnLine.C プロジェクト: amiara/RGIS
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;
		}
	}
コード例 #11
0
ファイル: CMDtblSplitDate.C プロジェクト: bandi13/RGIS
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);
	}
コード例 #12
0
DBInt DBPointToGrid(DBObjData *pntData, DBObjData *netData, DBObjData *grdData) {
    DBInt i;
    DBPosition pos;
    DBObjTable *pntTable = pntData->Table(DBrNItems);
    DBObjTable *grdTable = grdData->Table(DBrNItems);
    DBObjTable *symTable = grdData->Table(DBrNSymbols);
    DBObjectLIST<DBObjTableField> *pntFields = pntTable->Fields();
    DBObjTableField *pntFLD;
    DBObjTableField *grdAttribFLD;
    DBObjTableField *grdFLD = grdTable->Field(DBrNGridValue);
    DBObjTableField *symFLD = grdTable->Field(DBrNSymbol);
    DBObjRecord *cellRec, *toCell, *pntRec, *itemRec;
    DBObjRecord *symRec = symTable->First();
    DBVPointIF *pntIF;
    DBNetworkIF *netIF;
    DBGridIF *grdIF;

    pntIF = new DBVPointIF(pntData);
    netIF = new DBNetworkIF(netData);
    grdIF = new DBGridIF(grdData);

    grdIF->RenameLayer(grdIF->Layer((DBInt) 0), (char *) "Subbasins");

    for (pos.Row = 0; pos.Row < grdIF->RowNum(); ++pos.Row)
        for (pos.Col = 0; pos.Col < grdIF->ColNum(); ++pos.Col) grdIF->Value(pos, DBFault);

    for (pntFLD = pntFields->First(); pntFLD != (DBObjTableField *) NULL; pntFLD = pntFields->Next())
        if (DBTableFieldIsVisible(pntFLD)) grdTable->AddField(new DBObjTableField(*pntFLD));

    for (i = 0; i < pntIF->ItemNum(); ++i) {
        DBPause(i * 100 / pntIF->ItemNum());
        pntRec = pntIF->Item(i);
        if ((pntRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
        if ((cellRec = netIF->Cell(pntIF->Coordinate(pntRec))) == (DBObjRecord *) NULL) continue;

        itemRec = grdTable->Add(pntRec->Name());
        grdFLD->Int(itemRec, pntRec->RowID() + 1);
        symFLD->Record(itemRec, symRec);

        for (pntFLD = pntFields->First(); pntFLD != (DBObjTableField *) NULL; pntFLD = pntFields->Next())
            if ((grdAttribFLD = grdTable->Field(pntFLD->Name())) != (DBObjTableField *) NULL)
                switch (pntFLD->Type()) {
                    case DBTableFieldString:
                        grdAttribFLD->String(itemRec, pntFLD->String(pntRec));
                        break;
                    case DBTableFieldInt:
                        grdAttribFLD->Int(itemRec, pntFLD->Int(pntRec));
                        break;
                    case DBTableFieldFloat:
                        grdAttribFLD->Float(itemRec, pntFLD->Float(pntRec));
                        break;
                    case DBTableFieldDate:
                        grdAttribFLD->Date(itemRec, pntFLD->Date(pntRec));
                        break;
                }
        grdIF->Value(netIF->CellPosition(cellRec), itemRec->RowID());
    }

    for (i = 0; i < netIF->CellNum(); ++i) {
        if ((cellRec = netIF->Cell(i)) == (DBObjRecord *) NULL) continue;
        if ((itemRec = grdIF->GridItem(netIF->CellPosition(cellRec))) != (DBObjRecord *) NULL) continue;
        if ((toCell = netIF->ToCell(cellRec)) == (DBObjRecord *) NULL) continue;
        if ((itemRec = grdIF->GridItem(netIF->CellPosition(toCell))) != (DBObjRecord *) NULL)
            grdIF->Value(netIF->CellPosition(cellRec), itemRec->RowID());
    }
    grdIF->DiscreteStats();
    delete pntIF;
    delete netIF;
    delete grdIF;
    return (DBSuccess);
}
コード例 #13
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    DBInt recID, mode = DBTimeStepYear;
    char *tableName = (char *) NULL;
    char *srcName = (char *) NULL;
    char *dstName = (char *) NULL;
    DBObjData *data;
    DBObjTable *table;
    DBObjTableField *srcField;
    DBObjTableField *dstField = (DBObjTableField *) NULL;
    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);
            }
            srcName = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-o", "--outfield")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing output field name!");
                return (CMfailed);
            }
            dstName = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-m", "--mode")) {
            int optCodes[] = {DBTimeStepYear, DBTimeStepMonth};
            const char *optStrs[] = {"year", "month", (char *) NULL};

            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing mode!");
                return (CMfailed);
            }
            if ((mode = CMoptLookup(optStrs, argv[argPos], true)) == DBFault) {
                CMmsgPrint(CMmsgUsrError, "Invalid decimal date method!");
                return (CMfailed);
            }
            mode = optCodes[mode];
            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, "     -o,--outfield  [output field]");
            CMmsgPrint(CMmsgInfo, "     -m,--mode      [year|month]");
            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 (srcName == (char *) NULL) srcName = (char *) "Date";
    if ((srcField = table->Field(srcName)) == (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 (dstName == (char *) NULL)
        switch (mode) {
            case DBTimeStepYear:
                dstName = (char *) "Decimal Year";
                break;
            case DBTimeStepMonth:
                dstName = (char *) "Decimal Month";
                break;
        }

    if ((dstField = table->Field(dstName)) == (DBObjTableField *) NULL) {
        dstField = new DBObjTableField(dstName, DBTableFieldFloat, (char *) "%8.2f", sizeof(DBFloat4), false);
        table->AddField(dstField);
    }

    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);
        switch (mode) {
            case DBTimeStepYear:
                dstField->Float(record, date.DecimalYear());
                break;
            case DBTimeStepMonth:
                dstField->Float(record, date.DecimalMonth());
                break;
        }
    }
    ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout);

    delete data;
    if (verbose) RGlibPauseClose();
    return (ret);
}
コード例 #14
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);
}
コード例 #15
0
ファイル: DBObjTables.C プロジェクト: ztessler/RGIS
DBInt DBTableFieldIsSimple(const DBObject *obj) {
    DBObjTableField *tableField = (DBObjTableField *) obj;
    return ((tableField->Type() == DBTableFieldInt) ||
            (tableField->Type() == DBTableFieldString) ||
            (tableField->Type() == DBTableFieldFloat) ? true : false);
}
コード例 #16
0
DBInt RGlibRGIS2DataStream(DBObjData *grdData, DBObjData *tmplData, char *fieldName, FILE *outFile) {
    DBInt layerID, ret = DBSuccess, itemSize, itemID;
    DBInt intValue;
    DBFloat floatValue;
    void *data;
    MFVarHeader_t varHeader;
    DBObjRecord *layerRec, *gridRec;
    DBObjTableField *fieldPTR = (DBObjTableField *) NULL;
    DBGridIF *gridIF;
    DBVPointIF *tmplPntIF = (DBVPointIF *) NULL;
    DBGridIF *tmplGrdIF = (DBGridIF *) NULL;
    DBNetworkIF *tmplNetIF = (DBNetworkIF *) NULL;

    gridIF = new DBGridIF(grdData);

    varHeader.Swap = 1;
    if (grdData->Type() == DBTypeGridDiscrete) {
        DBObjTable *itemTable = grdData->Table(DBrNItems);

        if (fieldName == (char *) NULL) fieldName = DBrNGridValue;
        if ((fieldPTR = itemTable->Field(fieldName)) == (DBObjTableField *) NULL) {
            CMmsgPrint(CMmsgAppError, "Error: Invalid field [%s] in: %s %d", fieldName, __FILE__, __LINE__);
            return (DBFault);
        }
        itemSize = fieldPTR->Length();
        switch (fieldPTR->Type()) {
            case DBTableFieldInt:
                switch (itemSize) {
                    default:
                    case sizeof(DBByte):
                        varHeader.DataType = MFByte;
                        break;
                    case sizeof(DBShort):
                        varHeader.DataType = MFShort;
                        break;
                    case sizeof(DBInt):
                        varHeader.DataType = MFInt;
                        break;
                }
                varHeader.Missing.Int = fieldPTR->IntNoData();
                break;
            case DBTableFieldFloat:
                switch (itemSize) {
                    default:
                    case sizeof(DBFloat4):
                        varHeader.DataType = MFFloat;
                        break;
                    case sizeof(DBFloat):
                        varHeader.DataType = MFDouble;
                        break;
                }
                varHeader.Missing.Float = fieldPTR->FloatNoData();
                break;
        }
    }
    else {
        if (fieldName != (char *) NULL) CMmsgPrint(CMmsgUsrError, "Warning: Fieldname ignored for continuous grid!");
        itemSize = gridIF->ValueSize();
        switch (gridIF->ValueType()) {
            case DBVariableInt:
                switch (itemSize) {
                    case 1:
                        varHeader.DataType = MFByte;
                        break;
                    case 2:
                        varHeader.DataType = MFShort;
                        break;
                    case 4:
                        varHeader.DataType = MFInt;
                        break;
                }
                varHeader.Missing.Int = (int) gridIF->MissingValue();
                break;
            case DBVariableFloat:
                switch (itemSize) {
                    case 4:
                        varHeader.DataType = MFFloat;
                        break;
                    case 8:
                        varHeader.DataType = MFDouble;
                        break;
                }
                varHeader.Missing.Float = gridIF->MissingValue();
                break;
        }
    }

    if (tmplData == (DBObjData *) NULL) {
        tmplGrdIF = gridIF;
        varHeader.ItemNum = gridIF->RowNum() * gridIF->ColNum();
    }
    else {
        switch (tmplData->Type()) {
            case DBTypeVectorPoint:
                tmplPntIF = new DBVPointIF(tmplData);
                varHeader.ItemNum = tmplPntIF->ItemNum();
                break;
            case DBTypeGridContinuous:
            case DBTypeGridDiscrete:
                tmplGrdIF = new DBGridIF(tmplData);
                varHeader.ItemNum = gridIF->RowNum() * gridIF->ColNum();
                break;
            case DBTypeNetwork:
                tmplNetIF = new DBNetworkIF(tmplData);
                varHeader.ItemNum = tmplNetIF->CellNum();
                break;
            default:
                delete gridIF;
                return (DBFault);
        }
    }
    if ((data = (void *) calloc(varHeader.ItemNum, itemSize)) == (void *) NULL) {
        CMmsgPrint(CMmsgSysError, "Error! Allocating %d items of %d size in: %s %d", varHeader.ItemNum, itemSize,
                   __FILE__, __LINE__);
        return (DBFault);
    }

/**************************************************************
*                                                             *
* Point template                                              *
*                                                             *
**************************************************************/

    if (tmplPntIF != (DBVPointIF *) NULL) {
        DBObjRecord *pntRec;

        if (fieldPTR == (DBObjTableField *) NULL) {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) {
                    pntRec = tmplPntIF->Item(itemID);
                    if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) ||
                        (varHeader.DataType == MFInt)) {
                        if (gridIF->Value(layerRec, tmplPntIF->Coordinate(pntRec), &intValue) == false)
                            intValue = varHeader.Missing.Int;
                        switch (varHeader.DataType) {
                            case MFByte:
                                ((char *) data)[itemID] = (char) intValue;
                                break;
                            case MFShort:
                                ((short *) data)[itemID] = (short) intValue;
                                break;
                            case MFInt:
                                ((int *) data)[itemID] = (short) intValue;
                                break;
                        }
                    }
                    else {
                        if (gridIF->Value(layerRec, tmplPntIF->Coordinate(pntRec), &floatValue) == false)
                            floatValue = varHeader.Missing.Float;
                        switch (varHeader.DataType) {
                            case MFFloat:
                                ((float *) data)[itemID] = (float) floatValue;
                                break;
                            case MFDouble:
                                ((double *) data)[itemID] = (double) floatValue;
                                break;
                        }
                    }
                }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        else {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) {
                    pntRec = tmplPntIF->Item(itemID);
                    gridRec = gridIF->GridItem(layerRec, tmplPntIF->Coordinate(pntRec));
                    switch (varHeader.DataType) {
                        case MFByte:
                            ((char *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFShort:
                            ((short *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFInt:
                            ((int *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFFloat:
                            ((float *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData();
                            break;
                        case MFDouble:
                            ((double *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData();
                            break;
                    }
                }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        delete tmplPntIF;
    }

/**************************************************************
*                                                             *
* Grid Template (default when no template coverage is given.  *
*                                                             *
**************************************************************/
    else if (tmplGrdIF != (DBGridIF *) NULL) {
        DBPosition pos;
        DBCoordinate coord;

        if (fieldPTR == (DBObjTableField *) NULL) {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (pos.Row = 0; pos.Row < tmplGrdIF->RowNum(); ++pos.Row)
                    for (pos.Col = 0; pos.Col < tmplGrdIF->ColNum(); ++pos.Col) {
                        itemID = pos.Row * tmplGrdIF->ColNum() + pos.Col;
                        if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) ||
                            (varHeader.DataType == MFInt)) {
                            if (tmplGrdIF != gridIF) {
                                tmplGrdIF->Pos2Coord(pos, coord);
                                if (gridIF->Value(layerRec, coord, &intValue) == false)
                                    intValue = varHeader.Missing.Int;
                            }
                            else {
                                if (gridIF->Value(layerRec, pos, &intValue) == false) intValue = varHeader.Missing.Int;
                            }
                            switch (varHeader.DataType) {
                                case MFByte:
                                    ((char *) data)[itemID] = (char) intValue;
                                    break;
                                case MFShort:
                                    ((short *) data)[itemID] = (short) intValue;
                                    break;
                                case MFInt:
                                    ((int *) data)[itemID] = (short) intValue;
                                    break;
                            }
                        }
                        else {
                            if (tmplGrdIF != gridIF) {
                                tmplGrdIF->Pos2Coord(pos, coord);
                                if (gridIF->Value(layerRec, coord, &floatValue) == false)
                                    floatValue = varHeader.Missing.Float;
                            }
                            else {
                                if (gridIF->Value(layerRec, pos, &floatValue) == false)
                                    floatValue = varHeader.Missing.Float;
                            }
                            switch (varHeader.DataType) {
                                case MFFloat:
                                    ((float *) data)[itemID] = (float) floatValue;
                                    break;
                                case MFDouble:
                                    ((double *) data)[itemID] = (double) floatValue;
                                    break;
                            }
                        }
                    }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        else {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (pos.Row = 0; pos.Row < tmplGrdIF->RowNum(); ++pos.Row)
                    for (pos.Col = 0; pos.Col < tmplGrdIF->ColNum(); ++pos.Col) {
                        itemID = pos.Row * tmplGrdIF->ColNum() + pos.Col;
                        if (tmplGrdIF != gridIF) {
                            tmplGrdIF->Pos2Coord(pos, coord);
                            gridRec = gridIF->GridItem(layerRec, coord);
                        }
                        else gridRec = gridIF->GridItem(layerRec, pos);
                        switch (varHeader.DataType) {
                            case MFByte:
                                ((char *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec)
                                                                                          : fieldPTR->IntNoData();
                                break;
                            case MFShort:
                                ((short *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec)
                                                                                           : fieldPTR->IntNoData();
                                break;
                            case MFInt:
                                ((int *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec)
                                                                                         : fieldPTR->IntNoData();
                                break;
                            case MFFloat:
                                ((float *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec)
                                                                                           : fieldPTR->FloatNoData();
                                break;
                            case MFDouble:
                                ((double *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec)
                                                                                            : fieldPTR->FloatNoData();
                                break;
                        }
                    }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        if (tmplGrdIF != gridIF) delete tmplGrdIF;
    }

/**************************************************************
*                                                             *
* Network Template                                            *
*                                                             *
**************************************************************/
    else if (tmplNetIF != (DBNetworkIF *) NULL) {
        DBObjRecord *cellRec;

        if (fieldPTR == (DBObjTableField *) NULL) {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) {
                    cellRec = tmplNetIF->Cell(itemID);
                    if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) ||
                        (varHeader.DataType == MFInt)) {
                        if (gridIF->Value(layerRec, tmplNetIF->Center(cellRec), &intValue) == false)
                            intValue = varHeader.Missing.Int;
                        switch (varHeader.DataType) {
                            case MFByte:
                                ((char *) data)[itemID] = (char) intValue;
                                break;
                            case MFShort:
                                ((short *) data)[itemID] = (short) intValue;
                                break;
                            case MFInt:
                                ((int *) data)[itemID] = (short) intValue;
                                break;
                        }
                    }
                    else {
                        if (gridIF->Value(layerRec, tmplNetIF->Center(cellRec), &floatValue) == false)
                            floatValue = varHeader.Missing.Float;
                        switch (varHeader.DataType) {
                            case MFFloat:
                                ((float *) data)[itemID] = (float) floatValue;
                                break;
                            case MFDouble:
                                ((double *) data)[itemID] = (double) floatValue;
                                break;
                        }
                    }
                }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        else {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) {
                    cellRec = tmplNetIF->Cell(itemID);
                    gridRec = gridIF->GridItem(layerRec, tmplNetIF->Center(cellRec));
                    switch (varHeader.DataType) {
                        case MFByte:
                            ((char *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFShort:
                            ((short *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFInt:
                            ((int *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFFloat:
                            ((float *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Float(gridRec)
                                                                                       : fieldPTR->FloatNoData();
                            break;
                        case MFDouble:
                            ((double *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Float(gridRec)
                                                                                        : fieldPTR->FloatNoData();
                            break;
                    }
                }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        delete tmplNetIF;
    }

    free(data);
    delete gridIF;
    return (ret);
}
コード例 #17
0
ファイル: DBObjTables.C プロジェクト: ztessler/RGIS
DBInt DBTableFieldIsFloat(const DBObject *obj) {
    DBObjTableField *tableField = (DBObjTableField *) obj;
    return (tableField->Type() == DBTableFieldFloat ? true : false);
}
コード例 #18
0
ファイル: DBObjTables.C プロジェクト: ztessler/RGIS
DBInt DBTableFieldIsDate(const DBObject *obj) {
    DBObjTableField *tableField = (DBObjTableField *) obj;
    return (tableField->Type() == DBTableFieldDate ? true : false);
}
コード例 #19
0
ファイル: DBObjTables.C プロジェクト: ztessler/RGIS
DBInt DBTableFieldIsAxisVal(const DBObject *obj) {
    DBObjTableField *tableField = (DBObjTableField *) obj;
    return ((tableField->Type() == DBTableFieldInt) ||
            (tableField->Type() == DBTableFieldFloat) ||
            (tableField->Type() == DBTableFieldDate) ? true : false);
}
コード例 #20
0
ファイル: DBObjTables.C プロジェクト: ztessler/RGIS
DBInt DBTableFieldIsNumeric(const DBObject *obj) {
    DBObjTableField *tableField = (DBObjTableField *) obj;
    return ((tableField->Type() == DBTableFieldInt) ||
            (tableField->Type() == DBTableFieldFloat) ? true : false);
}
コード例 #21
0
ファイル: RGlibPoint.C プロジェクト: bmfekete/RGIS
DBInt RGlibPointInterStationTS(DBObjData *pntData, DBObjData *tsData, char *relateFldName, char *joinFldName) {
    DBInt first = true, tsIndex, tsRowNum = 0;
    DBObjTable *pntTBL = pntData->Table(DBrNItems), *tsTBL;
    DBObjectLIST<DBObjTableField> *fields;
    DBObjTableField *pntNextFLD = pntTBL->Field(RGlibNextStation);
    DBObjTableField *pntAreaFLD = pntTBL->Field(RGlibArea);
    DBObjTableField *pntInterStnFLD = pntTBL->Field(RGlibInterStation);
    DBObjTableField *pntRelateFLD;
    DBObjTableField *pntNewNextFLD;
    DBObjTableField *pntNewInterStnFLD;
    DBObjTableField *tsTimeFLD;
    DBObjTableField *tsJoinFLD;
    DBObjTableField *tsNextStnFLD, *tsInterStnFLD;
    DBObjRecord *pntRec, *nextPntRec, *tsRec, *tsIndexRec;
    DBDate curDate, date;

    if (pntNextFLD == (DBObjTableField *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Missing Next Station Field!");
        return (DBFault);
    }
    if (pntAreaFLD == (DBObjTableField *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Missing STN Area Field!");
        return (DBFault);
    }
    if (pntInterStnFLD == (DBObjTableField *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Missing Interfluvial Area Field!");
        return (DBFault);
    }

    tsTBL = tsData->Table(DBrNItems);
    tsNextStnFLD = new DBObjTableField(RGlibNextStation, DBTableFieldInt, "%8d", sizeof(DBInt));
    tsTBL->AddField(tsNextStnFLD);
    tsInterStnFLD = new DBObjTableField(RGlibInterStation, DBTableFieldFloat, "%9.1f", sizeof(DBFloat4));
    tsTBL->AddField(tsInterStnFLD);
    fields = tsTBL->Fields();
    for (tsTimeFLD = fields->First(); tsTimeFLD != (DBObjTableField *) NULL; tsTimeFLD = fields->Next())
        if (tsTimeFLD->Type() == DBTableFieldDate) break;
    if (tsTimeFLD == (DBObjTableField *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Missing Date Field!");
        return (DBFault);
    }
    if ((tsJoinFLD = tsTBL->Field(joinFldName)) == (DBObjTableField *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Missing Join Field!");
        return (DBFault);
    }
    fields = new DBObjectLIST<DBObjTableField>("Field List");
    fields->Add(new DBObjTableField(*tsTimeFLD));
    fields->Add(new DBObjTableField(*tsJoinFLD));
    tsTBL->ListSort(fields);
    delete fields;

    pntTBL = new DBObjTable(*pntTBL);
    pntNextFLD = pntTBL->Field(RGlibNextStation);
    pntAreaFLD = pntTBL->Field(RGlibArea);
    pntInterStnFLD = pntTBL->Field(RGlibInterStation);
    pntNewNextFLD = new DBObjTableField("NextStnTS", pntNextFLD->Type(), pntNextFLD->Format(), pntNextFLD->Length());
    pntNewInterStnFLD = new DBObjTableField("InterFluTS", pntInterStnFLD->Type(), pntInterStnFLD->Format(),
                                            pntInterStnFLD->Length());
    pntRelateFLD = pntTBL->Field(relateFldName);
    pntTBL->AddField(pntNewNextFLD);
    pntTBL->AddField(pntNewInterStnFLD);
    pntTBL->ListSort(pntRelateFLD);

    tsIndexRec = tsTBL->First(&tsIndex);
    for (tsRec = tsTBL->First(); tsRec != (DBObjRecord *) NULL; tsRec = tsTBL->Next()) {
        DBPause(tsRowNum++ * 100 / tsTBL->ItemNum());
        date = tsTimeFLD->Date(tsRec);
        if (date != curDate) {
            if (first) first = false;
            else {
                for (pntRec = pntTBL->First(); pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next()) {
                    if ((pntRec->Flags() & DBObjectFlagLocked) != DBObjectFlagLocked) continue;
                    for (nextPntRec = pntTBL->Item(pntNextFLD->Int(pntRec) - 1);
                         (nextPntRec != (DBObjRecord *) NULL) &&
                         ((nextPntRec->Flags() & DBObjectFlagLocked) != DBObjectFlagLocked);
                         nextPntRec = pntTBL->Item(pntNextFLD->Int(nextPntRec) - 1));
                    if (nextPntRec != (DBObjRecord *) NULL) {
                        pntNewNextFLD->Int(pntRec, nextPntRec->RowID() + 1);
                        pntNewInterStnFLD->Float(nextPntRec,
                                                 pntNewInterStnFLD->Float(nextPntRec) - pntAreaFLD->Float(pntRec));
                    }
                }
                pntRec = pntTBL->First();
                for (; tsIndexRec != (DBObjRecord *) NULL; tsIndexRec = tsTBL->Next(&tsIndex)) {
                    if (tsRec == tsIndexRec) break;
                    for (; pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next())
                        if (pntRelateFLD->Int(pntRec) == tsJoinFLD->Int(tsIndexRec)) {
                            tsNextStnFLD->Int(tsIndexRec, pntNewNextFLD->Int(pntRec));
                            tsInterStnFLD->Float(tsIndexRec, pntNewInterStnFLD->Float(pntRec));
                            break;
                        }
                    if (pntRec == (DBObjRecord *) NULL) pntRec = pntTBL->First();
                }
            }
            for (pntRec = pntTBL->First(); pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next()) {
                pntNewNextFLD->Int(pntRec, 0);
                pntNewInterStnFLD->Float(pntRec, pntAreaFLD->Float(pntRec));
                pntRec->Flags(DBObjectFlagLocked, DBClear);
            }
            curDate = date;
            pntRec = pntTBL->First();
        }
        for (; pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next())
            if (pntRelateFLD->Int(pntRec) == tsJoinFLD->Int(tsRec)) {
                pntRec->Flags(DBObjectFlagLocked, DBSet);
                break;
            }
        if (pntRec == (DBObjRecord *) NULL) pntRec = pntTBL->First();
    }
    if (!first) {
        for (pntRec = pntTBL->First(); pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next()) {
            if ((pntRec->Flags() & DBObjectFlagLocked) != DBObjectFlagLocked) continue;
            for (nextPntRec = pntTBL->Item(pntNextFLD->Int(pntRec) - 1);
                 (nextPntRec != (DBObjRecord *) NULL) &&
                 ((nextPntRec->Flags() & DBObjectFlagLocked) != DBObjectFlagLocked);
                 nextPntRec = pntTBL->Item(pntNextFLD->Int(nextPntRec) - 1));
            if (nextPntRec != (DBObjRecord *) NULL) {
                pntNewNextFLD->Int(pntRec, nextPntRec->RowID() + 1);
                pntNewInterStnFLD->Float(nextPntRec, pntNewInterStnFLD->Float(nextPntRec) - pntAreaFLD->Float(pntRec));
            }
        }
        pntRec = pntTBL->First();
        for (; tsIndexRec != (DBObjRecord *) NULL; tsIndexRec = tsTBL->Next(&tsIndex)) {
            if (tsRec == tsIndexRec) break;
            for (; pntRec != (DBObjRecord *) NULL; pntRec = pntTBL->Next())
                if (pntRelateFLD->Int(pntRec) == tsJoinFLD->Int(tsIndexRec)) {
                    tsNextStnFLD->Int(tsIndexRec, pntNewNextFLD->Int(pntRec));
                    tsInterStnFLD->Float(tsIndexRec, pntNewInterStnFLD->Float(pntRec));
                    break;
                }
            if (pntRec == (DBObjRecord *) NULL) pntRec = pntTBL->First();
        }
    }
    delete pntTBL;
    return (DBSuccess);
}
コード例 #22
0
ファイル: DBObjTables.C プロジェクト: ztessler/RGIS
DBInt DBTableFieldIsString(const DBObject *obj) {
    DBObjTableField *tableField = (DBObjTableField *) obj;
    return (tableField->Type() == DBTableFieldString ? true : false);
}
コード例 #23
0
ファイル: CMDtblStatistics.C プロジェクト: amiara/RGIS
int main (int argc,char *argv [])
	{
	int argPos, argNum = argc, numGrpNames = 0, i = 0;
	char **groupnames, *rename = (char *) NULL, *tableName = (char *) NULL;
	bool ascii = false;
	FieldOptions *head = (FieldOptions *) NULL, *p = (FieldOptions *) NULL, *temp = (FieldOptions *) NULL;
	Groups **groups = (Groups **) NULL;
	FILE *outFile = (FILE *) NULL;
	DBObjData *inData, *outData;
	DBObjTable *inTable, *outTable;
	DBObjTableField *field;
	DBObjRecord *inRecord, *outRecord;
	DBObjectLIST<DBObjTableField> *fields;

	if(argc <= 2) { doHelp(false,argv[0]); return(DBSuccess); }
	outData = new DBObjData("Untitled", DBTypeTable);
	outTable = outData->Table(DBrNItems);

	head = new FieldOptions(BAD,"","", (FieldOptions *) NULL);
	groupnames = (char **) malloc(sizeof(char *));

	for (argPos = 1;argPos < argNum;)
		{
		if (CMargTest(argv[argPos],"-f","--field"))
			{
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing operation and field after -f!"); return (CMfailed); }
			if(!strcmp(argv[argPos],"pct"))
				{
				if (argNum <= argPos + 2)
					{ CMmsgPrint (CMmsgUsrError,"Missing field and/or percentage after -f pct!"); return (CMfailed); }
				p = FOHierarchy(argv[argPos],argv[argPos+1],rename,atoi(argv[argPos+2]),head);
				argNum = CMargShiftLeft(argPos,argv,argNum);
				argNum = CMargShiftLeft(argPos,argv,argNum);
				}
			else if(!strcmp(argv[argPos],"num"))
				{
				char *num = new char[4];
				strcpy(num,"Num");
				p = FOHierarchy(argv[argPos],num,rename,-1,head);
				}
			else
				{
				if (argNum < argPos + 1)
					{ CMmsgPrint (CMmsgUsrError,"Missing operation or field after -f %s!",argv[argPos]); return (CMfailed); }
				p = FOHierarchy(argv[argPos],argv[argPos+1],rename,-1,head);
				argNum = CMargShiftLeft(argPos,argv,argNum);
				}
			p->setPrint(true);
			rename = (char *) NULL;
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest(argv[argPos],"-g","--group"))
			{
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing groupname!"); return (CMfailed); }
			if((groupnames = (char **) realloc(groupnames,(numGrpNames + 1) * sizeof(char *))) == (char **) NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return(DBFault); }
			groupnames[numGrpNames] = argv[argPos];
			numGrpNames++;
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest(argv[argPos],"-h","--help"))
			{
			argNum = CMargShiftLeft (argPos,argv,argNum);
			if(CMargTest(argv[argPos],"e","extend"))
				{
				doHelp(true,argv[0]);
				argNum = CMargShiftLeft (argPos,argv,argNum);
				}
			else doHelp(false,argv[0]);
			}
		if (CMargTest(argv[argPos],"-c","--ascii"))
			{
			ascii = true;
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest(argv[argPos],"-a","--table"))
			{
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing table name!"); return (CMfailed); }
			tableName = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest(argv[argPos],"-r","--rename"))
			{
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing field after -r!"); return (CMfailed); }
			rename = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest(argv[argPos],"-o","--output"))
			{
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing output filename!"); return (CMfailed); }
			if((outFile = fopen(argv[argPos],"w")) == (FILE *) NULL)
				{ CMmsgPrint (CMmsgUsrError,"Cannot open file %s",argv[argPos]); return (CMfailed); }
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest(argv[argPos],"-t","--title"))
			{
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing title!"); return (CMfailed); }
			outData->Name(argv[argPos]);
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest(argv[argPos],"-s","--subject"))
			{
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing subject!"); return (CMfailed); }
			outData->Document(DBDocSubject,argv[argPos]);
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest(argv[argPos],"-d","--domain"))
			{
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing domain!"); return (CMfailed); }
			outData->Document(DBDocGeoDomain,argv[argPos]);
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest(argv[argPos],"-v","--version"))
			{
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing version!"); return (CMfailed); }
			outData->Document(DBDocVersion,argv[argPos]);
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if ((argv[argPos][0] == '-') && (strlen (argv[argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError, "Unknown option: %s!",argv[argPos]); return (CMfailed); }
		argPos++;
		}

	if(outFile == (FILE *) NULL) outFile = stdout;
	if(head->next == (FieldOptions *) NULL) return(DBSuccess);

	inData = new DBObjData();
	if ((argNum > 1) && (strcmp(argv[1],"-") != 0)) inData->Read(argv[1]);
	else inData->Read(stdin);

	if (outData->Name() == (char *) NULL) outData->Name("Untitled");
	if (outData->Document(DBDocSubject) == (char *) NULL) outData->Document(DBDocSubject,inData->Document(DBDocSubject));
	if (outData->Document(DBDocGeoDomain) == (char *) NULL) outData->Document(DBDocGeoDomain,inData->Document(DBDocGeoDomain));
	if (outData->Document(DBDocVersion) == (char *) NULL) outData->Document(DBDocVersion,inData->Document(DBDocVersion));

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

	if((groups = (Groups **) malloc(numGrpNames * sizeof(Groups *))) == (Groups **) NULL)
		{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return(DBFault); }
	for(i = 0; i < numGrpNames; i++)
		{
		if((field = inTable->Field(groupnames[i])) == (DBObjTableField *) NULL)
			{ CMmsgPrint (CMmsgUsrError, "Invalid group name: %s",groupnames[i]); return (CMfailed); }
		if(DBTableFieldIsCategory(field))
			{
			groups[i] = new Groups();
			groups[i]->srcFLD = field;
			groups[i]->dstFLD = new DBObjTableField(*field);
			outTable->AddField(groups[i]->dstFLD);
//			CMmsgPrint (CMmsgUsrError, "Added Group: %s",groups[i]->dstFLD->Name());
			}
		else CMmsgPrint (CMmsgUsrError, "Group %s is not Category!",groupnames[i]);
		}
	delete groupnames;

	p = head->next;
	temp = head;
	while(p->next)
		{
		FieldOptions *duplicate = (FieldOptions *) NULL, *prev = p;
		if(!p->getPrint() && FLDExists(p,p->getOldName(),p->getFunc(),&duplicate))
			{ temp->next = p->next; delete p; p = temp->next; continue; }
		while(FLDExists(prev,prev->getOldName(),prev->getFunc(),&prev,&duplicate) && !duplicate->getPrint())
			{ prev->next = duplicate->next; delete duplicate; }
		temp = p;
		p = p->next;
		}
//	p = head->next;
//	while(p) { CMmsgPrint (CMmsgUsrError, "Added: o:%s n:%s p:",p->getOldName(),p->getNewName()); if(p->getPrint()) CMmsgPrint (CMmsgUsrError, "true"); else CMmsgPrint (CMmsgUsrError, "false"); p = p->next; }

	fields = inTable->Fields();
	p = head->next;
	while(p)
		{
		field = fields->Item (p->getOldName());
		if (p->getFunc() == MIN || p->getFunc() == MAX)
			p->field = new DBObjTableField(p->getNewName(),field->Type(),field->Format(),field->Length());
		else if(p->getFunc() == NUM || p->getFunc() == NONNULL)
			p->field = new DBObjTableField(p->getNewName(), DBTableFieldInt, DBHiddenField, sizeof (DBInt));
		else p->field = new DBObjTableField(p->getNewName(), DBTableFieldFloat, DBHiddenField, sizeof(DBFloat));
		if(p->getFunc() != NUM && p->getFunc() != NONNULL)
			{
//			if ((field = inTable->Field(p->getOldName())) == (DBObjTableField *) NULL)
			if (field == (DBObjTableField *) NULL)
				{
				CMmsgPrint (CMmsgUsrError, "Invalid field name: %s",p->getOldName());
				return(DBFault);
				}
			if (!DBTableFieldIsNumeric(field))
				{
				CMmsgPrint (CMmsgUsrError, "Field is not Numeric: %s",p->getOldName());
				return(DBFault);
				}
			}
		outTable->AddField(p->field);
		p = p->next;
		}
// MAKE SURE TO TEST FOR SPEED BY DECLARING INTS OUTSIDE OF FOR LOOPS!!!

	for (int inRecID = 0;inRecID < inTable->ItemNum();++inRecID)
		{
		inRecord = inTable->Item(inRecID);
		if ((outRecord = FindMatch(inRecord, outTable,(const Groups**) groups, numGrpNames)) != (DBObjRecord *) NULL)
			{
			p = head->next;
			while(p)
				{
				field = fields->Item (p->getOldName());
				switch(p->getFunc())
					{
					default:
						break;
					case NUM:
						p->field->Int(outRecord,p->field->Int(outRecord) + 1);
						break;
					case NONNULL:
						if (p->isInt())
							{
							if (field->Int(inRecord) != field->IntNoData()) p->field->Int(outRecord,p->field->Int(outRecord) + 1);
							}
						else
							{
							if (!CMmathEqualValues(field->Float(inRecord),field->FloatNoData()))
								p->field->Int(outRecord,p->field->Int(outRecord) + 1);
							}
						break;
					case MIN:
						if (p->isInt())
							{
							if(field->Int(inRecord) != field->IntNoData())
								{
								if (p->field->Int(outRecord) != p->field->IntNoData())
									{ if (field->Int(inRecord) < p->field->Int(outRecord)) p->field->Int(outRecord,field->Int(inRecord)); }
								else { p->field->Int(outRecord,field->Int(inRecord)); }
								}
							}
						else
							{
							if (!CMmathEqualValues(field->Float(inRecord),field->FloatNoData()))
								{
								if (!CMmathEqualValues(p->field->Float(inRecord),p->field->FloatNoData()))
									{ if (field->Float(inRecord) < p->field->Float(outRecord)) p->field->Float(outRecord,field->Float(inRecord)); }
								else { p->field->Float(outRecord,field->Float(inRecord)); }
								}
							}
						break;
					case MAX:
						if (p->isInt())
							{
							if(field->Int(inRecord) != field->IntNoData())
								{
								if (p->field->Int(outRecord) != p->field->IntNoData())
									{ if (field->Int(inRecord) > p->field->Int(outRecord)) p->field->Int(outRecord,field->Int(inRecord)); }
								else { p->field->Int(outRecord,field->Int(inRecord)); }
								}
							}
						else
							{
							if (!CMmathEqualValues(field->Float(inRecord),field->FloatNoData()))
								{
								if (!CMmathEqualValues(p->field->Float(inRecord),p->field->FloatNoData()))
									{ if (field->Float(inRecord) > p->field->Float(outRecord)) p->field->Float(outRecord,field->Float(inRecord)); }
								else { p->field->Float(outRecord,field->Float(inRecord)); }
								}
							}
						break;
					case SUM:
						if (p->isInt())
							{
							if(field->Int(inRecord) != field->IntNoData())
								p->field->Int(outRecord,p->field->Int(outRecord) + field->Int(inRecord));
							}
							else
							{
							if (!CMmathEqualValues(field->Float(inRecord),field->FloatNoData()))
								p->field->Float(outRecord,p->field->Float(outRecord) + field->Float(inRecord));
							}
						break;
					case DEV:
					case PCT:
					case MED:
						p->tailVal = p->tailVal->next = new Values();
						p->tailVal->val = field->Float(inRecord);
						p->tailVal->next = 0;
						break;
					case MOD:
						Values *cur = p->getHead();
						while(cur->next && !CMmathEqualValues(cur->val,field->Float(inRecord))) cur = cur->next;
						if(cur->next) cur->occur++;
						else
							{
							p->tailVal->val = field->Float(inRecord);
							p->tailVal->occur = 1;
							p->tailVal = p->tailVal->next = new Values();
							}
						break;
					}
				p = p->next;
				}
			}
		else
			{
			outRecord = outTable->Add();

			for(i = 0; i < numGrpNames; i++)
				{
				switch (groups[i]->srcFLD->Type())
					{
					default:
					case DBTableFieldString:
						groups[i]->dstFLD->String(outRecord,groups[i]->srcFLD->String(inRecord));
						break;
					case DBTableFieldInt:
						groups[i]->dstFLD->Int(outRecord,groups[i]->srcFLD->Int(inRecord));
						break;
					}
				}
			p = head->next;
			while(p)
				{
				field = fields->Item (p->getOldName());
				switch(p->getFunc())
					{
					default:
					case BAD:
						break;
					case NUM:
						p->setInt();
						p->field->Int(outRecord,1);
						break;
					case NONNULL:
						if (field->Type() == DBTableFieldInt)
							{
							p->setInt();
							if (field->Int(inRecord) != field->IntNoData()) p->field->Int(outRecord,1);
							else p->field->Int(outRecord,0);
							}
						else
							{
							if (!CMmathEqualValues(field->Float(inRecord),field->FloatNoData())) p->field->Int(outRecord,1);
							else p->field->Int(outRecord,0);
							}
						break;
					case MIN:
						if (field->Type() == DBTableFieldInt)
							{ p->setInt(); if (field->Int(inRecord) != field->IntNoData()) p->field->Int(outRecord,field->Int(inRecord)); }
						else
							{
							if(!CMmathEqualValues(field->Float(inRecord),field->FloatNoData()))
								p->field->Float(outRecord,field->Float(inRecord));
							}
						break;
					case MAX:
						if (field->Type() == DBTableFieldInt)
							{ p->setInt(); if (field->Int(inRecord) != field->IntNoData()) p->field->Int(outRecord,field->Int(inRecord)); }
						else
							{
							if(!CMmathEqualValues(field->Float(inRecord),field->FloatNoData()))
								p->field->Float(outRecord,field->Float(inRecord));
							}
						break;
					case SUM:
						if (field->Type() == DBTableFieldInt)
							{
							p->setInt();
							if (field->Int(inRecord) != field->IntNoData()) p->field->Int(outRecord,field->Int(inRecord));
							else p->field->Int(outRecord,0);
							}
						else
							{
							if(!CMmathEqualValues(field->Float(inRecord),field->FloatNoData())) p->field->Float(outRecord,field->Float(inRecord));
							else p->field->Float(outRecord,0.0);
							}
						break;
					case DEV:
					case PCT:
					case MED:
						p->tailVal = p->tailVal->next = new Values();
						p->tailVal->val = field->Float(inRecord);
						p->tailVal->next = 0;
						break;
					case MOD:
						p->tailVal->val = field->Float(inRecord);
						p->tailVal->occur = 1;
						p->tailVal = p->tailVal->next = new Values();
						break;
					}
				p = p->next;
				}
			}
		}

	for(int outRecID = 0; outRecID < outTable->ItemNum();++outRecID)
		{
		outRecord = outTable->Item(outRecID);
		p = head->next;
		FieldOptions *sum, *num;
		DBFloat mod;
		int occurrance;
		float i;
		bool mult;
		Values *cur;
		while(p)
			{
			field = fields->Item (p->getOldName());
			switch(p->getFunc())
				{
				case AVG:
					if((FLDExists(head,p->getOldName(),SUM,&sum)) && (FLDExists(head,p->getOldName(),NONNULL,&num)))
						p->field->Float(outRecord,sum->field->Float(outRecord) / (DBFloat) (num->field->Int(outRecord)));
					else CMmsgPrint (CMmsgUsrError, "Program Error! Could not find SUM or NONNULL in linked list! Please contact the GHAAS developers group!");
					break;
				case NAVG:
					if((FLDExists(head,p->getOldName(),SUM,&sum)) && (FLDExists(head,"NUM",NUM,&num)))
						p->field->Float(outRecord,sum->field->Float(outRecord) / (DBFloat) (num->field->Int(outRecord)));
					else CMmsgPrint (CMmsgUsrError, "Program Error! Could not find SUM or NUM in linked list! Please contact the GHAAS developers group!");
					break;
				case PCT:
				case MED:
					i = (float) (inTable->ItemNum() * p->getHead()->occur * 0.01) - 1;
					cur = p->getHead()->next;
					while(i > 0) { cur = cur->next; i--; }
					p->field->Float(outRecord,(cur->val + cur->next->val) / 2);
					break;
				case MOD:
					mod = 0.0;
					occurrance = 0;
					mult = false;
					cur = p->getHead();
					while(cur)
						{
						if(cur->occur > occurrance)
							{
							mod = cur->val;
							occurrance = cur->occur;
							mult = false;
							}
						else if(cur->occur == occurrance) mult = true;
						cur = cur->next;
						}
					if(mult) CMmsgPrint (CMmsgUsrError, "** Warning, multiple answers for MOD, listing first found!");
					p->field->Float(outRecord,mod);
					break;
				default:
					break;
				}
			p = p->next;
			}
		}

	p = head->next;
	while(p)
		{
		if(p->getFunc() == DEV)
			{
			FieldOptions *avg, *num;
			field = fields->Item (p->getOldName());
			if((FLDExists(head,p->getOldName(),AVG,&avg)) && (FLDExists(head,"NUM",NUM,&num)))
				{
				for(int outRecID = 0; outRecID < outTable->ItemNum();++outRecID)
					{
					outRecord = outTable->Item(outRecID);
					DBFloat sum = 0.0;
					Values *cur = p->getHead()->next;
					while(cur)
						{
//						sum += (DBFloat) (pow((cur->val - avg->field->Float(outRecord)),2));
						DBFloat add = (cur->val - avg->field->Float(outRecord));
						sum += (DBFloat) (add * add);
						cur = cur->next;
						}
					sum = sqrt(sum /(DBFloat) num->field->Int(outRecord));
					p->field->Float(outRecord,sum);
					}
				}
			else CMmsgPrint (CMmsgUsrError, "Program Error! Could not find AVG or NUM in linked list! Please contact the GHAAS developers group!");
			}
		p = p->next;
		}
// DELETE unnecessary fields which were for temp storage
	fields = outTable->Fields();
	p = head->next;
	while(p)
		{
		if(!p->getPrint()) outTable->DeleteField(fields->Item(p->getNewName()));
		p = p->next;
		}

	p = head->next;
	while(p)
		{
		if ((strcmp(p->field->Format(),DBHiddenField) == 0) && p->getPrint())
			{
			if(p->isInt())
				{
				int maxval = 0;
				for(int outRecID = 0; outRecID < outTable->ItemNum();++outRecID)
					{
					int val = p->field->Int(outTable->Item(outRecID));
					if (maxval < val) maxval = val; else if (maxval < -val) maxval = -val;
					}
				p->field->Format(DBMathIntAutoFormat(maxval));
				}
			else
				{
				float maxval = 0.0;
				for(int outRecID = 0; outRecID < outTable->ItemNum();++outRecID)
					{
					float val = p->field->Float(outTable->Item(outRecID));
					if (maxval < val) maxval = val; else if (maxval < -val) maxval = -val;
					}
				p->field->Format(DBMathFloatAutoFormat(maxval));
				}
			}
//		CMmsgPrint (CMmsgUsrError, "Format(%s)%d,%d: '%s'",p->getFuncName(),p->isInt(),p->getPrint(),p->field->Format());
		p = p->next;
		}

	DBObjectLIST<DBObjTableField> *list = new DBObjectLIST<DBObjTableField> ("Sorted Field List");
	for(i = 0; i < numGrpNames; i++) list->Add(groups[i]->dstFLD);
	outTable->ListSort(list);

if (ascii) DBExportASCIITable(outTable,outFile); else outData->Write(outFile);

/* CLEANUP ************************************************/
	if(outFile != stdout) fclose(outFile);
	for(i = 0; i < numGrpNames; i++) delete groups[i]->dstFLD;
	delete groups;
	p = head;
	while(p)
		{
		head = head->next;
		delete p;
		p = head;
		}
	return(DBSuccess);

}
コード例 #24
0
ファイル: DBObjTables.C プロジェクト: ztessler/RGIS
DBInt DBTableFieldIsCategory(const DBObject *obj) {
    DBObjTableField *tableField = (DBObjTableField *) obj;
    return ((tableField->Type() == DBTableFieldInt) ||
            (tableField->Type() == DBTableFieldString) ? true : false);
}