Exemple #1
0
int MFOptionParse (int argc, char *argv []) {
	int argNum = argc, argPos, i;
	int MFLoadConfig (const char *,int (*) (const char *, const char *));

	for (argPos = 1;argPos < argNum;) {
		if (CMargTest (argv [argPos],"-p","--option")) {
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) < 1) {
				CMmsgPrint (CMmsgUsrError,"Missing option argument!\n");
				return (CMfailed);
			}
			for (i = 0;i < (int) strlen (argv[argPos]);++i) if (argv [argPos][i] == '=') break;
			if (i == (int) strlen (argv [argPos])) {
				CMmsgPrint (CMmsgAppError,"Illformed option [%s]!\n",argv [argPos]);
				return (CMfailed);
			}
			argv [argPos][i] = '\0';
			_MFOptionNew (argv [argPos],argv [argPos] + i + 1);
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
		}
		if (CMargTest (argv [argPos],"-pl","--option-listfile")) {
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) < 1) {
				CMmsgPrint (CMmsgUsrError,"Missing option argument!\n");
				return (CMfailed);
			}
			MFLoadConfig (argv [argPos],_MFOptionNew);
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
		}
		argPos++;
	}
	return (argNum);
}
Exemple #2
0
int main(int argc, char* argv[])
{
	int argPos = 0, argNum = argc, ncid;
	char *fname = (char *) NULL, *tname = "time";
	FILE *output = stdout;
	NCtable_t *tbl = (NCtable_t *) NULL;

	initMemInfo();
	for(argPos = 1; argPos < argNum;) {
		if (CMargTest(argv[argPos],"-d","--debug"))
                    {
                    SetDebug();
                    CMargShiftLeft(argPos,argv,argc);
                    argNum--;
                    continue;
                    }
		if (CMargTest(argv[argPos],"-h","--help")) {
			if((argPos + 1 < argNum) && (argv[argPos+1][0] == 'e')) doHelp (CMprgName(argv[0]),true);
			else doHelp (CMprgName (argv[0]),false);
			cleanup(NCsucceeded);
		}
		if (CMargTest(argv[argPos],"-t","--table"))
		{
			CMargShiftLeft(argPos,argv,argc); argNum--;
			tname = argv[argPos];
			CMargShiftLeft(argPos,argv,argc); argNum--;
			continue;
		}
		if (CMargTest(argv[argPos],"-f","--file"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError,"Missing file!");  return (CMfailed); }
			fname = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-o","--output"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError,"Missing output!");  return (CMfailed); }
			if(output != stdout) { CMmsgPrint (CMmsgUsrError, "Output file defined twice!"); cleanup(NCfailed); }
			if((output = fopen(argv[argPos],"w")) == (FILE *) NULL)
				{ CMmsgPrint (CMmsgUsrError, "Cannot open for writing: %s",argv[argPos]); cleanup(NCfailed); }
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if ((argv[argPos][0] == '-') && (strlen (argv[argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError, "Unknown option: %s!",argv[argPos]); cleanup(NCfailed); }
		argPos++;
	}
	if(fname == (char *) NULL) { doHelp(argv[0],false); CMmsgPrint (CMmsgUsrError, "No file specified!"); cleanup(NCfailed); }
	if(nc_open(fname,NC_NOWRITE,&ncid) != NC_NOERR) { CMmsgPrint (CMmsgUsrError, "Error opening file!"); cleanup(NCfailed); }
	if((tbl = NCtableOpen(ncid,tname)) == (NCtable_t *) NULL) { CMmsgPrint (CMmsgUsrError, "Error opening table!"); cleanup(NCfailed); }
	if(GetDebug()) CMmsgPrint (CMmsgUsrError, "Loaded file!");
	NCtableExportAscii(tbl,output);
	cleanup(NCsucceeded);
}
Exemple #3
0
int main (int argc, char *argv [])
{
   int argPos, argNum = argc, ret = CMfailed, port=CMfailed, socket=CMfailed;
   
   for (argPos = 1;argPos < argNum;) {
		if (CMargTest(argv[argPos],"-p","--port")) {
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			if (port != CMfailed) CMmsgPrint (CMmsgUsrError,"Skipping port redefinition!");
			else {
			}
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-s","--socket")) {
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			if (socket != CMfailed) CMmsgPrint (CMmsgUsrError,"Skipping socket redefinition!");
			else {
			}
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
		}
Help:	if (CMargTest(argv[argPos],"-h","--help")) {
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) < argPos) break;
			CMmsgPrint (CMmsgUsrError,"%s [options]",CMprgName(argv[0]));
			CMmsgPrint (CMmsgUsrError,"  -p, --port");
			CMmsgPrint (CMmsgUsrError,"  -s, --socket");
			CMmsgPrint (CMmsgUsrError,"  -h,--help");
			ret = CMsucceeded;
			goto Stop;
		}
		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1)) {
			CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]);
			goto Stop;
		}
      argPos++;
	}
	if (argNum > 1) { CMmsgPrint (CMmsgUsrError,"Extra arguments!"); return (CMfailed); }

   {
      DBObjData *data;
   }
   
   ret = CMsucceeded;
   
Stop:
	return (ret);
}
Exemple #4
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    DBObjData *data;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest (argv[argPos], "-V", "--verbose")) {
            verbose = true;
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-h", "--help")) {
            CMmsgPrint(CMmsgInfo, "%s [options] <rgis file> <dm file>", CMfileName(argv[0]));
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

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

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

    ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? DBExportDMGrid(data, argv[2]) : DBExportDMGrid(data, stdin);
    delete data;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Exemple #5
0
int main (int argc,char *argv [])

	{
	int argPos, argNum = argc, ret, verbose = false;
	char *title  = (char *) NULL, *subject = (char *) NULL;
	char *domain = (char *) NULL, *version = (char *) NULL;
	DBInt stepNum = 0, offset = 0, doSum = false;
	DBObjData *tsData, *data;

	for (argPos = 1;argPos < argNum; )
		{
		if (CMargTest (argv [argPos],"-a","--aggregate"))
			{
			int sumCodes  [] = { false, true	};
			const char *sumStrs [] = { "avg", "sum", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing aggregation method!"); return (CMfailed); }
			if ((doSum = CMoptLookup (sumStrs,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid aggregation method!"); return (CMfailed); }
			doSum = sumCodes [doSum];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-o","--offset"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing offset!");       return (CMfailed); }
			if (sscanf (argv [argPos],"%d",&offset) != 1)
				{ CMmsgPrint (CMmsgUsrError,"Invalid number of steps!");	return (CMfailed); }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-e","--step"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing number of steps!"); return (CMfailed); }
			if (sscanf (argv [argPos],"%d",&stepNum) != 1)
				{ CMmsgPrint (CMmsgUsrError,"Invalid number of steps!"); 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); }
			title = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-u","--subject"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing subject!");      return (CMfailed); }
			subject = 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); }
			domain  = 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); }
			version  = 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 (CMmsgSysError,"%s [options] <input grid> <output grid>",CMprgName(argv[0]));
			CMmsgPrint (CMmsgSysError,"     -a,--aggregate [avg|sum]");
			CMmsgPrint (CMmsgSysError,"     -o,--offset    [offset]");
			CMmsgPrint (CMmsgSysError,"     -e,--step      [number of steps]");
			CMmsgPrint (CMmsgSysError,"     -t,--title     [dataset title]");
			CMmsgPrint (CMmsgSysError,"     -u,--subject   [subject]");
			CMmsgPrint (CMmsgSysError,"     -d,--domain    [domain]");
			CMmsgPrint (CMmsgSysError,"     -v,--version   [version]");
			CMmsgPrint (CMmsgSysError,"     -V,--verbose");
			CMmsgPrint (CMmsgSysError,"     -h,--help");
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); }
		argPos++;
		}

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

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

	if (title	== (char *) NULL)	title   = tsData->Name ();
	if (subject == (char *) NULL)	subject = tsData->Document (DBDocSubject);
	if (domain	== (char *) NULL)	domain  = tsData->Document (DBDocGeoDomain);
	if (version == (char *) NULL) version = tsData->Document (DBDocVersion);	

	data = DBGridToGrid (tsData);
	data->Name (title);
	data->Document (DBDocSubject,subject);
	data->Document (DBDocGeoDomain,domain);
	data->Document (DBDocVersion,version);	

	if ((ret = RGlibSeasonMean (tsData, data, stepNum, offset, doSum)) == DBSuccess)
		ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? data->Write (argv [2]) : data->Write (stdout);

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

	{
	int argPos, argNum = argc, ret, verbose = false;
	bool downhill = true;
	char *title  = (char *) NULL;
	char *domain = (char *) NULL, *version = (char *) NULL;
	DBObjData *outData, *inData, *basinData = (DBObjData *) NULL;
	DBInt DBGridCont2Network (DBObjData *,DBObjData *, bool);

	for (argPos = 1;argPos < argNum; )
		{
		if (CMargTest(argv[argPos],"-b","--basin_pack")) {
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing basin pack filename!"); return (CMfailed); }
			else {
				if (basinData != (DBObjData *) NULL)
					CMmsgPrint (CMmsgWarning,"Ignoring redefined basin pack");
				else {
					basinData = new DBObjData ();
					if (basinData->Read (argv [argPos]) == DBFault) {
						CMmsgPrint (CMmsgUsrError, "Basin data reading error");
						delete basinData;
						basinData = (DBObjData *) NULL;
						return (CMfailed);
					}
				}
			}
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-g","--gradient")) {
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing gradient method!"); return (CMfailed); }
			else {
				const char *options [] = { "down", "up", (char *) NULL };
				bool methods [] = { true, false };
				DBInt code;

				if ((code = CMoptLookup (options,argv [argPos],false)) == CMfailed) {
					CMmsgPrint (CMmsgWarning,"Ignoring illformed gradient method [%s]!",argv [argPos]);
				}
				else downhill = methods [code];
			}
			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); }
			title = 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); }
			domain  = 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); }
			version  = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-V","--verbose"))
			{
			verbose = true;
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-h","--help"))
			{
			CMmsgPrint (CMmsgInfo,"%s [options] <input file> <output file>",CMprgName(argv[0]));
			CMmsgPrint (CMmsgInfo,"     -b,--basin_pack [basin pack file]");
			CMmsgPrint (CMmsgInfo,"     -g,--gradient   [down|up]");
			CMmsgPrint (CMmsgInfo,"     -t,--title      [dataset title]");
			CMmsgPrint (CMmsgInfo,"     -d,--domain     [domain]");
			CMmsgPrint (CMmsgInfo,"     -v,--version    [version]");
			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]);

	inData = new DBObjData ();
	ret = (argNum > 1) && (strcmp (argv [1],"-") != 0) ? inData->Read (argv [1]) : inData->Read (stdin);
	if ((ret == DBFault) || (inData->Type () != DBTypeGridContinuous)) { ret = DBFault;  goto Stop; }
	inData->LinkedData (basinData);

	if (title	== (char *) NULL)	title = (char *) "Regridded Network";
	if (domain  == (char *) NULL) domain  = inData->Document (DBDocGeoDomain);
	if (version == (char *) NULL) version = (char *) "0.01pre";

	outData = new DBObjData (title,DBTypeNetwork);
	outData->Document (DBDocSubject,"STNetwork");
	outData->Document (DBDocGeoDomain,domain);
	outData->Document (DBDocVersion,version);

	if (DBGridCont2Network (inData,outData, downhill) == DBFault) {
		CMmsgPrint (CMmsgUsrError,"Grid create network failed!");
		ret = DBFault;
		goto Stop;
	}

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

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

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

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

    data = new DBObjData();
    if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) {
        delete data;
        if (argNum > 1) CMmsgPrint(CMmsgUsrError, "File error in: %s", argv[1]);
        return (DBFault);
    }

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

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

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

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

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

    free(expressions);
    delete data;
    delete variables;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Exemple #8
0
int main(int argc, char* argv[])

	{
	int argPos, argNum = argc, ret, verbose = false;
	int layerID, kernel = 3, offset = 0, i, layerNum, beginLayerID, endLayerID, num;
	DBPosition pos;
	char *title  = (char *) NULL, *subject = (char *) NULL;
	char *domain = (char *) NULL, *version = (char *) NULL;
	int shadeSet = DBDataFlagDispModeContGreyScale;
	DBFloat value, sum;
	DBObjData *inData,   *outData;
	DBGridIF  *inGridIF, *outGridIF;
	DBObjRecord *inLayerRec, *outLayerRec;

	for (argPos = 1;argPos < argNum; )
		{
		if (CMargTest (argv [argPos],"-k","--kernelsize"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing kernel size!"); return (CMfailed); }
			if (sscanf (argv[argPos],"%d",&kernel) != 1)
				{
				CMmsgPrint (CMmsgUsrError,"Invalid kernel size!");
				return (CMfailed);
				}
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-f","--kerneloffset"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing kernel offset!"); return (CMfailed); }
			if (sscanf (argv[argPos],"%d",&offset) != 1)
				{
				CMmsgPrint (CMmsgUsrError,"Invalid kernel offset!");
				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); }
			title = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-u","--subject"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing subject!");      return (CMfailed); }
			subject = 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); }
			domain  = 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); }
			version  = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-s","--shadeset"))
			{
			int shadeCodes [] = {	DBDataFlagDispModeContStandard,
			                        DBDataFlagDispModeContGreyScale,
			                        DBDataFlagDispModeContBlueScale,
			                        DBDataFlagDispModeContBlueRed,
			                        DBDataFlagDispModeContElevation };
			const char *shadeSets [] = { "standard","grey","blue","blue-to-red","elevation", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing shadeset!");     return (CMfailed); }
			if ((shadeSet = CMoptLookup (shadeSets,argv [argPos],true)) == CMfailed)
				{ CMmsgPrint (CMmsgUsrError,"Invalid shadeset!");     return (CMfailed); }
			shadeSet = shadeCodes [shadeSet];
			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 grid> <output grid>",CMfileName(argv[0]));
			CMmsgPrint (CMmsgInfo,"     -k,--kernelsize");
			CMmsgPrint (CMmsgInfo,"     -f,--kerneloffset");
			CMmsgPrint (CMmsgInfo,"     -V,--verbose");
			CMmsgPrint (CMmsgInfo,"     -h,--help");
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1))
			{
			CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]);
			return (CMfailed);
			}
		argPos++;
		}
	if (argNum > 3)
		{
		CMmsgPrint (CMmsgUsrError,"Extra arguments!");
		return (CMfailed);
		}
	if (verbose) RGlibPauseOpen (argv[0]);

	inData = new DBObjData ();
	ret = (argNum > 1) && (strcmp (argv [1],"-") != 0) ? inData->Read (argv [1]) : inData->Read (stdin);
	if ((ret == DBFault) || ((inData->Type () != DBTypeGridContinuous) && (inData->Type () != DBTypeGridDiscrete)))
		{
		delete inData;
		return (CMfailed);
		}
	inGridIF = new DBGridIF (inData);
	if ((outData = DBGridToGrid (inData,DBTypeGridContinuous)) == (DBObjData *) NULL) return (CMfailed);

	if (title   != (char *) NULL) outData->Name     (title);
	if (subject != (char *) NULL) outData->Document (DBDocSubject,   subject);
	if (domain  != (char *) NULL) outData->Document (DBDocGeoDomain, domain);
	if (version != (char *) NULL) outData->Document (DBDocVersion,   version);
	outGridIF = new DBGridIF (outData);

	layerNum = inGridIF->LayerNum ();
	for (layerID = 0;layerID < layerNum;++layerID)
		{
		inLayerRec = inGridIF->Layer (layerID);;
		if (layerID == 0)
			{
			outLayerRec = outGridIF->Layer (layerID);
			outGridIF->RenameLayer (outLayerRec, inLayerRec->Name ());
			}
		else outLayerRec = outGridIF->AddLayer (inLayerRec->Name ());

		beginLayerID = layerID >= offset ? layerID - offset : 0;
		endLayerID   = (layerID - offset + kernel) < layerNum ? (layerID - offset + kernel) : layerNum;
//		CMmsgPrint (CMmsgDebug, "LayerID: %d Kernel: %d Offset: %d     Begin: %d  End: %d", layerID, kernel, offset, beginLayerID, endLayerID);
		for (pos.Row = 0; pos.Row < inGridIF->RowNum (); pos.Row++)
			{
			for (pos.Col = 0; pos.Col < inGridIF->ColNum (); pos.Col++)
				{
				num = 0;
				sum = 0.0;
				for (i = beginLayerID; i < endLayerID; ++i)
					{
					if (inGridIF->Value (i, pos, &value) == false) continue;
					sum = sum + value;
					num++;
					}
				outGridIF->Value (outLayerRec,pos,num > 0 ? sum / (DBFloat) num : outGridIF->MissingValue ());
				}
			}
		outGridIF->RecalcStats (outLayerRec);
		}
	ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? outData->Write (argv [2]) : outData->Write (stdout);

	delete inGridIF;
	delete outGridIF;
	delete inData;
	delete outData;
	if (verbose) RGlibPauseClose ();
	return (ret);
	}
Exemple #9
0
int main (int argc,char *argv [])

	{
	int argPos, argNum = argc, ret, verbose = false;
	char *title  = (char *) NULL, *subject = (char *) NULL;
	char *domain = (char *) NULL, *version = (char *) NULL;
	char *networkName = (char *) NULL;
	DBObjData *data, *netData, *grdData;

	for (argPos = 1;argPos < argNum; )
		{
		if (CMargTest (argv [argPos],"-n","--network"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing network!");       return (CMfailed); }
			networkName = argv [argPos];
			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); }
			title = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-u","--subject"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing subject!");       return (CMfailed); }
			subject = 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); }
			domain  = 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); }
			version  = 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 grid> <output grid>",CMfileName(argv[0]));
			CMmsgPrint (CMmsgInfo,"     -n,--network   [network]");
			CMmsgPrint (CMmsgInfo,"     -t,--title     [dataset title]");
			CMmsgPrint (CMmsgInfo,"     -u,--subject   [subject]");
			CMmsgPrint (CMmsgInfo,"     -d,--domain    [domain]");
			CMmsgPrint (CMmsgInfo,"     -v,--version   [version]");
			CMmsgPrint (CMmsgInfo,"     -V,--verbose");
			CMmsgPrint (CMmsgInfo,"     -h,--help");
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); }
		argPos++;
		}

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

	if (networkName == (char *) NULL)
		{ CMmsgPrint (CMmsgUsrError,"Network is not specified"); return (CMfailed); }

	netData = new DBObjData ();
	if ((netData->Read (networkName) == DBFault) || (netData->Type () != DBTypeNetwork))
		{ delete netData; return (CMfailed); }

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

	if (title	== (char *) NULL)   title = (char *) "Basin Histogram";
	if (subject == (char *) NULL) subject = grdData->Document (DBDocSubject);
	if (domain	== (char *) NULL)  domain = netData->Document (DBDocGeoDomain);
	if (version == (char *) NULL) version = (char *) "0.01pre";

	data = new DBObjData (title,DBTypeTable);
	data->Document (DBDocSubject,subject);
	data->Document (DBDocGeoDomain,domain);
	data->Document (DBDocVersion,version);

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

	delete data; delete netData; delete grdData;
	if (verbose) RGlibPauseClose ();
	return (ret);
	}
Exemple #10
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, data, dataNum = 0, verbose = false;
    char *title = (char *) NULL, *subject = (char *) NULL;
    char *domain = (char *) NULL, *version = (char *) NULL;
    char *output = (char *) NULL, **dataList = (char **) NULL;
    DBObjData *grdData, *appData;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest (argv[argPos], "-o", "--output")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing output grid!");
                return (CMfailed);
            }
            output = argv[argPos];
            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);
            }
            title = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-u", "--subject")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing subject!");
                return (CMfailed);
            }
            subject = 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);
            }
            domain = 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);
            }
            version = 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] <append grid0> ..... <append gridN>", CMfileName(argv[0]));
            CMmsgPrint(CMmsgInfo, "     -o,--output    [ouptput grid]");
            CMmsgPrint(CMmsgInfo, "     -t,--title     [dataset title]");
            CMmsgPrint(CMmsgInfo, "     -u,--subject   [subject]");
            CMmsgPrint(CMmsgInfo, "     -d,--domain    [domain]");
            CMmsgPrint(CMmsgInfo, "     -v,--version   [version]");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

    if (argNum < 2) {
        CMmsgPrint(CMmsgUsrError, "Nothing to append");
        return (DBFault);
    }
    dataNum = argNum - 1;
    if ((dataList = (char **) realloc(dataList, dataNum * sizeof(char *))) == (char **) NULL) {
        CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__);
        return (DBFault);
    }
    for (data = 0; data < dataNum; ++data) {
        dataList[data] = argv[data + 1];
    }
    if (verbose) RGlibPauseOpen(argv[0]);

    grdData = new DBObjData();
    ret = (strcmp(dataList[0], "-") != 0) ? grdData->Read(dataList[0]) : grdData->Read(stdin);
    if ((ret == DBFault) || ((grdData->Type() & DBTypeGrid) != DBTypeGrid)) {
        delete grdData;
        return (CMfailed);
    }

    if (title != (char *) NULL) grdData->Name(title);
    if (subject != (char *) NULL) grdData->Document(DBDocSubject, subject);
    if (domain != (char *) NULL) grdData->Document(DBDocGeoDomain, domain);
    if (version != (char *) NULL) grdData->Document(DBDocVersion, version);

    for (data = 1; data < dataNum; ++data) {
        appData = new DBObjData();
        if (appData->Read(dataList[data]) == DBFault) {
            delete grdData;
            delete appData;
            return (CMfailed);
        }
        if (DBGridAppend(grdData, appData) == DBFault) {
            delete grdData;
            delete appData;
            return (CMfailed);
        }
        delete appData;
    }

    ret = (output != (char *) NULL) && (strcmp(argv[2], "-") != 0) ? grdData->Write(output) : grdData->Write(stdout);

    delete grdData;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Exemple #11
0
int main (int argc,char *argv [])
{
	int argPos, argNum = argc, ncid, varid;
	double range[2];
	char *title = NULL, *type = NULL, *domain = NULL, *subject = NULL, *ref = NULL, *inst = NULL, *source = NULL, *comments = NULL;
	VarNode_t *head, *last;
	if((last = head = malloc(sizeof(VarNode_t))) == (VarNode_t *) NULL)
		{ CMmsgPrint (CMmsgAppError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return(NCfailed); }
	for (argPos = 1;argPos < argNum;)
	{
		if (CMargTest(argv[argPos],"-h","--help"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            {
                            doHelp(CMfileName(argv[0]),0);
                            break;
                            }
                        else
                            doHelp(CMfileName(argv[0]),(strcmp(argv[argPos],"extend") == 0) ||
                                                      (strcmp(argv[argPos],"e")      == 0));
			continue;
		}
		if (CMargTest(argv[argPos],"-l","--longname"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError, "Missing variable Name!"); return (CMfailed); }
			last->text = true;
			last->var = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError, "Missing Long Name!"); return (CMfailed); }
			last->dat = argv[argPos];
			last->attrib = NCnameVALongName;
			if((last = last->next = malloc(sizeof(VarNode_t))) == NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return(NCfailed); }
			last->dat = last->dat2 = (char *) NULL;
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-n","--standardname"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError, "Missing variable Name!"); return (CMfailed); }
			last->text = true;
			last->var = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError, "Missing Standard Name!"); return (CMfailed); }
			last->dat = argv[argPos];
			last->attrib = NCnameVAStandardName;
			if((last = last->next = malloc(sizeof(VarNode_t))) == NULL)
                            { CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d"); return(CMfailed); }
			last->dat = last->dat2 = (char *) NULL;
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-U","--units"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError, "Missing variable!"); return (CMfailed); }
			last->text = true;
			last->var = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError, "Missing Units!"); return (CMfailed); }
			last->dat = argv[argPos];
			last->attrib = NCnameVAUnits;
			if((last = last->next = malloc(sizeof(VarNode_t))) == NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return(NCfailed); }
			last->dat = last->dat2 = (char *) NULL;
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-v","--validrange"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError, "Missing variable!"); return (CMfailed); }
// ********************        CHECK HERE!!! ************************
			last->text = false;
			last->var = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing upper range!"); return (CMfailed); }
			last->dat = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing lower range!"); return (CMfailed); }
			last->dat2 = argv[argPos];
			last->attrib = NCnameVAValidRange;
			if((last = last->next = malloc(sizeof(VarNode_t))) == NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return(NCfailed); }
			last->dat = last->dat2 = (char *) NULL;
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-o","--offset"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError, "Missing variable!"); return (CMfailed); }
			last->text = false;
			last->var = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError, "Missing offset!"); return (CMfailed); }
			last->dat = argv[argPos];
			last->attrib = NCnameVAAddOffset;
			if((last = last->next = malloc(sizeof(VarNode_t))) == NULL)
                            { CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return(CMfailed); }
			last->dat = last->dat2 = (char *) NULL;
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-s","--scalefactor"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing variable!"); return (CMfailed); }
			last->text = false;
			last->var = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing scale factor!"); return (CMfailed); }
			last->dat = argv[argPos];
			last->attrib = NCnameVAScaleFactor;
			if((last = last->next = malloc(sizeof(VarNode_t))) == NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return(NCfailed); }
			last->dat = last->dat2 = (char *) NULL;
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-t","--title"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing Title!"); return (CMfailed); }
			title = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-y","--type"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing Type!"); return (CMfailed); }
			type = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-d","--domain"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing Domain!"); return (CMfailed); }
			domain = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-s","--subject"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing Subject!"); return (CMfailed); }
			subject = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-r","--references"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing References!"); return (CMfailed); }
			ref = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-i","--institution"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing Institution!"); return (CMfailed); }
			inst = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-s","--source"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing Source!"); return (CMfailed); }
			source = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-c","--comments"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError, "Missing Comment!"); return (CMfailed); }
			comments = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if ((argv[argPos][0] == '-') && (strlen (argv[argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError, "Unknown option: %s!",argv[argPos]); return (NCfailed); }
	argPos++;
	}
	last->next = (VarNode_t *) NULL;
	if ((argNum > 1) && (strcmp(argv[1],"-") != 0)) {
		if(nc_open(argv[1],NC_WRITE,&ncid) != NC_NOERR) { CMmsgPrint (CMmsgUsrError, "Error opening file: %s!",argv[1]); return (NCfailed); }
	} else doHelp(CMfileName(argv[0]),1);
	if(nc_redef(ncid) != NC_NOERR) { CMmsgPrint (CMmsgUsrError, "Cannot place into redef mode!"); return (NCfailed); }

	last = head;
	while(last->next != (VarNode_t *) NULL)
	{
		if(nc_inq_varid(ncid,last->var,&varid) != NC_NOERR) { CMmsgPrint (CMmsgUsrError, "Error finding %s variable",last->var); return (NCfailed); }
		if(last->text)
		{
			if(nc_put_att_text(ncid, varid, last->attrib,strlen(last->dat), last->dat) != NC_NOERR)
				{ CMmsgPrint (CMmsgUsrError, "Error changing attribute: %s!", last->attrib); return (NCfailed); }
		}
	  	else
		{
			if(last->dat2 != (char *) NULL)
				{
				range[0] = atof(last->dat);
				range[1] = atof(last->dat2);
				if(nc_put_att_double(ncid, varid, last->attrib,NC_DOUBLE, 2, range) != NC_NOERR)
					{ CMmsgPrint (CMmsgUsrError, "Error changing attribute: %s!", last->attrib); return (NCfailed); }
				}
			else
				{
				range[0] = atof(last->dat);
				if(nc_put_att_double(ncid, varid, last->attrib,NC_DOUBLE, 1, range) != NC_NOERR)
					{ CMmsgPrint (CMmsgUsrError, "Error changing attribute: %s!", last->attrib); return (NCfailed); }
				}
		}
		last = last->next;
	}
	
	if((title != NULL) && (nc_put_att_text(ncid, NC_GLOBAL, NCnameGATitle,strlen(title), title) != NC_NOERR))
		{ CMmsgPrint (CMmsgUsrError, "Error changing attribute: title!"); return (NCfailed); }
	if(type != NULL) if(nc_put_att_text(ncid, NC_GLOBAL, NCnameGADataType,strlen(type), type) != NC_NOERR)
		{ CMmsgPrint (CMmsgUsrError, "Error changing attribute; type!"); return (NCfailed); }
	if((domain != NULL) && (nc_put_att_text(ncid, NC_GLOBAL, NCnameGADomain, strlen(domain), domain) != NC_NOERR))
		{ CMmsgPrint (CMmsgUsrError, "Error changing attribute: domain!"); return (NCfailed); }
	if((subject != NULL) && (nc_put_att_text(ncid, NC_GLOBAL, NCnameGASubject, strlen(subject), subject) != NC_NOERR))
		{ CMmsgPrint (CMmsgUsrError, "Error changing attribute: subject!"); return (NCfailed); }
	if((ref != NULL) && (nc_put_att_text(ncid, NC_GLOBAL, NCnameGAReferences, strlen(ref), ref) != NC_NOERR))
		{ CMmsgPrint (CMmsgUsrError, "Error changing attribute: references!"); return (NCfailed); }
	if((inst != NULL) && (nc_put_att_text(ncid, NC_GLOBAL, NCnameGAInstitution, strlen(inst), inst) != NC_NOERR))
		{ CMmsgPrint (CMmsgUsrError, "Error changing attribute: institution!"); return (NCfailed); }
	if((source != NULL) && (nc_put_att_text(ncid, NC_GLOBAL, NCnameGASource, strlen(source), source) != NC_NOERR))
		{ CMmsgPrint (CMmsgUsrError, "Error changing attribute: source!"); return (NCfailed); }
	if((comments != NULL) && (nc_put_att_text(ncid, NC_GLOBAL, NCnameGAComments, strlen(comments), comments) != NC_NOERR))
		{ CMmsgPrint (CMmsgUsrError, "Error changing attribute: comments!"); return (NCfailed); }

	if(nc_close(ncid) != NC_NOERR) { CMmsgPrint (CMmsgUsrError, "Error commiting changes to file!"); return (NCfailed); }
	return 0;
}
Exemple #12
0
static int _MFModelParse (int argc, char *argv [],int argNum, int (*conf) ()) {
	FILE *inFile;
	bool testOnly = false;
	int argPos, ret, help = false;
	int i, varID, intVal;
	float floatVal;
	char *startDate = (char *) NULL, *endDate = (char *) NULL;
	MFVariable_t *var;
	int MFLoadConfig (const char *,int (*) (const char *, const char *, bool));
	bool _MFOptionNew (char *,char *), _MFOptionTestInUse ();

	for (argPos = 1;argPos < argNum;) {
		if (CMargTest (argv [argPos],"-i","--input")) {
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) < 1) {
				CMmsgPrint (CMmsgUsrError,"Missing input argument!\n");
				return (CMfailed);
			}
			for (i = 0;i < (int) strlen (argv[argPos]);++i) if (argv [argPos][i] == '=') break;
			if (i == (int) strlen (argv [argPos])) {
				CMmsgPrint  (CMmsgUsrError,"Illformed input variable [%s] in: %s:%d\n",argv [argPos],__FILE__,__LINE__);
				return (CMfailed);
			}
			argv [argPos][i] = '\0';
			if (MFVarSetPath (argv [argPos],argv [argPos] + i + 1, false, MFInput) == (MFVariable_t *) NULL)  return (CMfailed);
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
		}
		if (CMargTest (argv [argPos],"-o","--output")) {
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) < 1) {
				CMmsgPrint (CMmsgUsrError,"Missing _MFModelOutput argument!\n");
				return (CMfailed);
			}
			for (i = 0;i < (int) strlen (argv[argPos]);++i) if (argv [argPos][i] == '=') break;
			if (i == (int) strlen (argv [argPos])) {
				CMmsgPrint (CMmsgUsrError,"Illformed _MFModelOutput variable [%s]!\n",argv [argPos]);
				return (CMfailed);
			}
			argv [argPos][i] = '\0';
			if (_MFModelOutputNew (argv [argPos],argv [argPos] + i + 1,false) == CMfailed) return (CMfailed);
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
	 	}
		if (CMargTest (argv [argPos],"-t","--state")) {
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) < 1) {
				CMmsgPrint (CMmsgUsrError,"Missing _MFModelOutput argument!\n");
				return (CMfailed);
			}
			for (i = 0;i < (int) strlen (argv[argPos]);++i) if (argv [argPos][i] == '=') break;
			if (i == (int) strlen (argv [argPos])) {
				CMmsgPrint (CMmsgUsrError,"Illformed _MFModelOutput variable [%s]!\n",argv [argPos]);
				return (CMfailed);
			}
			argv [argPos][i] = '\0';
			if (_MFModelOutputNew (argv [argPos],argv [argPos] + i + 1, true) == CMfailed) return (CMfailed);
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
	 	}
		if (CMargTest (argv [argPos],"-s","--start")) {
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) < 1) {
				CMmsgPrint (CMmsgUsrError,"Missing start time!\n");
				return (CMfailed);
			}
			startDate = argv [argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
		}
		if (CMargTest (argv [argPos],"-n","--end")) {
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) < 1) {
				CMmsgPrint (CMmsgUsrError,"Missing end time!\n");
				return (CMfailed);
			}
			endDate = argv [argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
		}
		if (CMargTest (argv [argPos],"-T","--testonly")) {
			testOnly = true;
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
		}
		if (CMargTest (argv [argPos],"-m","--message")) {
			const char *types [] = { "sys_error", "app_error", "usr_error", "debug", "warning", "info", (char *) NULL };
			CMmsgType msgTypes [] = { CMmsgSysError, CMmsgAppError, CMmsgUsrError, CMmsgDebug, CMmsgWarning, CMmsgInfo };
			int type;
			const char *modes [] = { "file:", "on", "off", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) < 1) {
				CMmsgPrint (CMmsgUsrError,"Missing message argument!\n");
				return (CMfailed);
			}

			if ((type = CMoptLookup (types,argv [argPos],false)) == CMfailed) {
				CMmsgPrint (CMmsgWarning,"Ignoring illformed message [%s]!\n",argv [argPos]);
			}
			else {
				switch (CMoptLookup (modes, argv [argPos] + strlen (types [type]) + 1, false)) {
					case 0: CMmsgSetStreamFile (msgTypes [type], argv [argPos] + strlen (types [type]) + 1 + strlen (modes [0]));
					case 1: CMmsgSetStatus     (msgTypes [type], true);  break;
					case 2: CMmsgSetStatus     (msgTypes [type], false); break;
					default:
						CMmsgPrint (CMmsgWarning,"Ignoring illformed message [%s]!\n",argv [argPos]);
						break;
				}
			}
			if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break;
			continue;
		}
		if (CMargTest (argv [argPos],"-h","--help")) {
			help = true;
			CMmsgPrint (CMmsgInfo,"%s [options] <domain>\n",CMfileName (argv [0]));
			CMmsgPrint (CMmsgInfo,"     -s,  --start      [start date in the form of \"yyyy-mm-dd\"]\n");
			CMmsgPrint (CMmsgInfo,"     -n,  --end        [end date in the form of \"yyyy-mm-dd\"]\n");
			CMmsgPrint (CMmsgInfo,"     -i,  --input      [variable=source]\n");
			CMmsgPrint (CMmsgInfo,"     -o,  --output     [variable=destination]\n");
			CMmsgPrint (CMmsgInfo,"     -r,  --state      [variable=statefile]\n");
			CMmsgPrint (CMmsgInfo,"     -ol, --output-listfile [output listfile]\n");
			CMmsgPrint (CMmsgInfo,"     -p,  --option     [option=content]\n");
			CMmsgPrint (CMmsgInfo,"     -r,  --route      [variable]\n");
			CMmsgPrint (CMmsgInfo,"     -T,  --testonly\n");
			CMmsgPrint (CMmsgInfo,"     -m,  --message    [sys_error|app_error|usr_error|debug|warning|info]=[on|off|file=<filename>]\n");
			CMmsgPrint (CMmsgInfo,"     -h,  --help\n");
			break;
		}
		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1)) {
			CMmsgPrint (CMmsgUsrError,"Unknown option [%s]!\n",argv [argPos]);
			return (CMfailed);
		}
		argPos++;
	}

	if (startDate == (char *) NULL) startDate = "XXXX-01-01";
	if (endDate   == (char *) NULL) endDate   = "XXXX-12-31";

	if (!MFDateSetStart   (startDate)) { CMmsgPrint (CMmsgAppError,"Error: Invalid start date!\n"); ret = CMfailed; }
	if (!MFDateSetCurrent (startDate)) ret = CMfailed;
	if (!MFDateSetEnd     (endDate))   { CMmsgPrint (CMmsgAppError,"Error: Invalid end date!\n");   ret = CMfailed; }
	if (ret == CMfailed) return (CMfailed);

	ret = conf ();
	if (help) { MFOptionPrintList (); return (CMfailed); }
	if (ret == CMfailed) return (CMfailed);
	if (testOnly) {
		CMmsgPrint (CMmsgInfo, "ID  %10s %30s[%10s] %6s %5s NStep %3s %4s %8s Output",
			      "Start_Date", "Variable","Unit","Type", "TStep", "Set", "Flux", "Initial");
		for (var = MFVarGetByID (varID = 1);var != (MFVariable_t *) NULL;var = MFVarGetByID (++varID))
			if ((strncmp (var->Name,"__",2) != 0) || var->Initial)
				CMmsgPrint (CMmsgInfo, "%3i %10s %30s[%10s] %6s %5s %5d %3s %4s %8s %6s",
					varID,var->Header.Date,var->Name,var->Unit,MFVarTypeString (var->Header.DataType),MFDateTimeStepString (var->TStep),var->NStep,
					CMyesNoString (var->Set),CMyesNoString (var->Flux),CMyesNoString (var->Initial), CMyesNoString (var->OutPath != (char *) NULL));
		return (CMfailed);
	}

	if ((argNum) > 2) { CMmsgPrint (CMmsgUsrError,"Extra arguments!");           return (CMfailed); }
	if ((argNum) < 2) { CMmsgPrint (CMmsgUsrError,"Missing Template Coverage!"); return (CMfailed); }

	if ((inFile = strcmp (argv [1],"-") != 0 ? fopen (argv [1],"r") : stdin) == (FILE *) NULL) {
		CMmsgPrint (CMmsgAppError,"%s: Template Coverage [%s] Opening error!",CMfileName (argv [0]),argv [1]);
		return (CMfailed);
	}
	if ((_MFDomain = MFDomainGet (inFile)) == (MFDomain_t *) NULL)	return (CMfailed);

	for (var = MFVarGetByID (varID = 1);var != (MFVariable_t *) NULL;var = MFVarGetByID (++varID)) {
		if (var->InStream == (MFDataStream_t *) NULL) var->TStep = MFTimeStepDay;
		else if ((var->Initial == false) && (MFDateSetCurrent (var->Header.Date) == false))
			CMmsgPrint (CMmsgWarning,"Warning: Invalid date in input (%s)",var->Name);
		if (var->Flux) sprintf (var->Unit + strlen (var->Unit),"/%s",MFDateTimeStepUnit (var->TStep));
	}
	MFDateRewind ();

	if (strcmp (startDate,MFDateGetCurrent ()) != 0)//zero. strings are equal
		CMmsgPrint (CMmsgWarning,"Warning: Adjusting start date (%s,%s)!",startDate, MFDateGetCurrent ());

	for (var = MFVarGetByID (varID = 1);var != (MFVariable_t *) NULL;var = MFVarGetByID (++varID)) {
		switch (var->Header.DataType) {
			case MFInput:
				CMmsgPrint (CMmsgAppError, "Error: Unresolved variable (%s [%s] %s)!",var->Name,var->Unit, MFVarTypeString (var->Header.DataType));
				ret = CMfailed;
				break;
			case MFRoute:
			case MFOutput:
				var->Header.DataType = MFFloat;
				var->Header.Missing.Float = MFDefaultMissingFloat;
			default:
				if (var->Data == (void *) NULL) {
					var->Header.ItemNum = _MFDomain->ObjNum;
					if ((var->Data = (void *) calloc (var->Header.ItemNum,MFVarItemSize (var->Header.DataType))) == (void *) NULL) {
						CMmsgPrint (CMmsgSysError,"Memory Allocation Error in: %s:%d",__FILE__,__LINE__);
						ret = CMfailed;
					}
					switch (var->Header.DataType) {
						case MFByte:
						case MFShort:
						case MFInt:
							intVal   = var->InStream == (MFDataStream_t *) NULL ? 0 : var->InStream->Handle.Int;
							for (i = 0;i < var->Header.ItemNum;++i) MFVarSetInt   (varID,i,intVal);
							break;
						case MFFloat:
						case MFDouble:
							floatVal = var->InStream == (MFDataStream_t *) NULL ? 0.0 : var->InStream->Handle.Float;
							for (i = 0;i < var->Header.ItemNum;++i) MFVarSetFloat (varID,i,floatVal);
							break;
					}
				}
				else {
					if (var->Header.ItemNum != _MFDomain->ObjNum) {
						CMmsgPrint (CMmsgAppError,"Error: Inconsistent data stream (%s [%s])!",var->Name,var->Unit);
						ret = CMfailed;
					}
					else if (var->Initial) {
						while (MFDataStreamRead (var) == MFContinue);
						MFDataStreamClose (var->InStream);
						var->InPath = (char *) NULL;
						var->InStream = (MFDataStream_t *) NULL;
					}
					switch (var->TStep) {
						default:	var->NStep = 1; break;
						case MFTimeStepMonth: var->NStep = MFDateGetMonthLength (); break;
						case MFTimeStepYear:	 var->NStep = 365; break;
					}
				}
				if (!var->Initial && !var->Set) {
					CMmsgPrint (CMmsgWarning,"Warning: Ignoring unused variable (%s)!",var->Name);
					MFDataStreamClose (var->InStream);
					var->InPath = (char *) NULL;
					var->InStream = (MFDataStream_t *) NULL;
					var->Set = true;
					var->Initial = true;
				}
				break;
		}
	}

	for (i = 0;i < _MFModelOutNum;++i) MFVarSetPath (_MFModelOutput [i].Name, _MFModelOutput [i].Path, _MFModelOutput [i].State, MFOutput);
	free (_MFModelOutput);

	CMmsgPrint (CMmsgInfo, "ID  %10s %30s[%10s] %6s %5s NStep %3s %4s %8s Output", "Start_Date", "Variable","Unit","Type", "TStep", "Set", "Flux", "Initial");
	for (var = MFVarGetByID (varID = 1);var != (MFVariable_t *) NULL;var = MFVarGetByID (++varID))
		if ((strncmp (var->Name,"__",2) != 0) || var->Initial)
			CMmsgPrint (CMmsgInfo, "%3i %10s %30s[%10s] %6s %5s %5d %3s %4s %8s %6s",
				varID,var->Header.Date,var->Name,var->Unit,MFVarTypeString (var->Header.DataType),MFDateTimeStepString (var->TStep),var->NStep,
				CMyesNoString (var->Set),CMyesNoString (var->Flux),CMyesNoString (var->Initial), CMyesNoString (var->OutPath != (char *) NULL));
	if (ret == CMfailed) return (CMfailed);
	_MFOptionTestInUse ();
	return (ret);
}
Exemple #13
0
int main (int argc,char *argv [])

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    delete data;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Exemple #15
0
int main(int argc, char *argv[]) {
    FILE *outFile;
    DBInt argPos, argNum = argc, ret;
    char *tmplName = (char *) NULL, *fieldName = (char *) NULL;
    DBObjData *grdData, *tmplData = (DBObjData *) NULL;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest (argv[argPos], "-m", "--template")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing network!");
                return (CMfailed);
            }
            tmplName = 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 fieldname!");
                return (CMfailed);
            }
            fieldName = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-h", "--help")) {
            CMmsgPrint(CMmsgInfo, "%s [options] <input grid> <output datastream>", CMfileName(argv[0]));
            CMmsgPrint(CMmsgInfo, "     -m,--template     [template coverage]");
            CMmsgPrint(CMmsgInfo, "     -f,--field        [fieldname]");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

    if (argNum > 3) {
        CMmsgPrint(CMmsgUsrError, "Extra arguments!");
        return (CMfailed);
    }

    outFile = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? fopen(argv[2], "w") : stdout;
    if (outFile == (FILE *) NULL) {
        CMmsgPrint(CMmsgSysError, "Output file Opening error in: %s %d", __FILE__, __LINE__);
        exit(DBFault);
    }

    grdData = new DBObjData();
    ret = (argNum > 1) && (strcmp(argv[1], "-") != 0) ? grdData->Read(argv[1]) : grdData->Read(stdin);
    if ((ret == DBFault) || ((grdData->Type() & DBTypeGrid) != DBTypeGrid)) {
        delete grdData;
        if (outFile != stdout) fclose(outFile);
        return (CMfailed);
    }

    if (tmplName != (char *) NULL) {
        tmplData = new DBObjData();
        if (tmplData->Read(tmplName) == DBFault) {
            delete grdData;
            if (outFile != stdout) fclose(outFile);
            delete tmplData;
            return (CMfailed);
        }
    }

    ret = RGlibRGIS2DataStream(grdData, tmplData, fieldName, outFile);
    if (tmplData != (DBObjData *) NULL) delete tmplData;
    delete grdData;
    if (outFile != stdout) fclose(outFile);
    return (ret);
}
Exemple #16
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    char *title = (char *) NULL, *subject = (char *) NULL;
    char *domain = (char *) NULL, *version = (char *) NULL;
    DBInt doMin = true, reportValue = true;
    int shadeSet = DBDataFlagDispModeContGreyScale;
    bool changeShadeSet = false;
    DBObjData *tsData, *data;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest (argv[argPos], "-m", "--mode")) {
            int codes[] = {true, false};
            const char *strs[] = {"min", "max", (char *) NULL};

            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing min-max method!");
                return (CMfailed);
            }
            if ((doMin = CMoptLookup(strs, argv[argPos], true)) == DBFault) {
                CMmsgPrint(CMmsgUsrError, "Invalid min-max method!");
                return (CMfailed);
            }
            doMin = codes[doMin];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-r", "--report")) {
            int codes[] = {true, false};
            const char *strs[] = {"value", "layer", (char *) NULL};

            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing report method!");
                return (CMfailed);
            }
            if ((reportValue = CMoptLookup(strs, argv[argPos], true)) == DBFault) {
                CMmsgPrint(CMmsgUsrError, "Invalid report method!");
                return (CMfailed);
            }
            reportValue = codes[reportValue];
            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);
            }
            title = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-u", "--subject")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing subject!");
                return (CMfailed);
            }
            subject = 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);
            }
            domain = 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);
            }
            version = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-s", "--shadeset")) {
            int shadeCodes[] = {DBDataFlagDispModeContStandard,
                                DBDataFlagDispModeContGreyScale,
                                DBDataFlagDispModeContBlueScale,
                                DBDataFlagDispModeContBlueRed,
                                DBDataFlagDispModeContElevation
                               };
            const char *shadeSets[] = {"standard", "grey", "blue", "blue-to-red", "elevation", (char *) NULL};

            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing shadeset!");
                return (CMfailed);
            }
            if ((shadeSet = CMoptLookup(shadeSets, argv[argPos], true)) == CMfailed) {
                CMmsgPrint(CMmsgUsrError, "Invalid shadeset!");
                return (CMfailed);
            }
            shadeSet = shadeCodes[shadeSet];
            changeShadeSet = true;
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-V", "--verbose")) {
            verbose = true;
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-h", "--help")) {
            CMmsgPrint(CMmsgInfo, "%s [options] <input grid> <output grid>", CMfileName(argv[0]));
            CMmsgPrint(CMmsgInfo, "     -m,--mode      [min|max]");
            CMmsgPrint(CMmsgInfo, "     -r,--report    [value|layer]");
            CMmsgPrint(CMmsgInfo, "     -t,--title     [dataset title]");
            CMmsgPrint(CMmsgInfo, "     -u,--subject   [subject]");
            CMmsgPrint(CMmsgInfo, "     -d,--domain    [domain]");
            CMmsgPrint(CMmsgInfo, "     -v,--version   [version]");
            CMmsgPrint(CMmsgInfo, "     -s,--shadeset  [standard|grey|blue|blue-to-red|elevation]");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

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

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

    if (title   == (char *) NULL) title   = tsData->Name();
    if (subject == (char *) NULL) subject = tsData->Document(DBDocSubject);
    if (domain  == (char *) NULL) domain  = tsData->Document(DBDocGeoDomain);
    if (version == (char *) NULL) version = tsData->Document(DBDocVersion);

    data = reportValue ? DBGridToGrid(tsData, DBTypeGridContinuous, DBTableFieldFloat, sizeof(DBFloat)) :
           DBGridToGrid(tsData, DBTypeGridContinuous, DBTableFieldInt,   sizeof(DBInt));
    data->Name(title);
    data->Document(DBDocSubject,   subject);
    data->Document(DBDocGeoDomain, domain);
    data->Document(DBDocVersion,   version);
    if (changeShadeSet && (data->Type() == DBTypeGridContinuous)) {
        data->Flags(DBDataFlagDispModeContShadeSets, DBClear);
        data->Flags(shadeSet, DBSet);
    }

    if ((ret = RGlibMinMax(tsData, data, doMin,reportValue)) == DBSuccess)
        ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout);

    delete tsData;
    delete data;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Exemple #17
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    char *title = (char *) NULL, *subject = (char *) NULL;
    char *domain = (char *) NULL, *version = (char *) NULL;
    char *output = (char *) NULL;
    int shadeSet = DBDataFlagDispModeContGreyScale;
    bool setShadeSet = false;
    DBObjData *grdData, *mergeData, *retData;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest (argv[argPos], "-o", "--output")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing merge grid!");
                return (CMfailed);
            }
            output = argv[argPos];
            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);
            }
            title = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-u", "--subject")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing subject!");
                return (CMfailed);
            }
            subject = 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);
            }
            domain = 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);
            }
            version = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-s", "--shadeset")) {
            int shadeCodes[] = {DBDataFlagDispModeContStandard,
                                DBDataFlagDispModeContGreyScale,
                                DBDataFlagDispModeContBlueScale,
                                DBDataFlagDispModeContBlueRed,
                                DBDataFlagDispModeContElevation};
            const char *shadeSets[] = {"standard", "grey", "blue", "blue-to-red", "elevation", (char *) NULL};

            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing shadeset!");
                return (CMfailed);
            }
            if ((shadeSet = CMoptLookup(shadeSets, argv[argPos], true)) == CMfailed) {
                CMmsgPrint(CMmsgUsrError, "Invalid shadeset!");
                return (CMfailed);
            }
            shadeSet = shadeCodes[shadeSet];
            setShadeSet = true;
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-V", "--verbose")) {
            verbose = true;
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-h", "--help")) {
            CMmsgPrint(CMmsgInfo, "%s [options] <input grid0> <input grid1> ... <input gridN>", CMfileName(argv[0]));
            CMmsgPrint(CMmsgInfo, "     -o,--output    [merged grid]");
            CMmsgPrint(CMmsgInfo, "     -t,--title     [dataset title]");
            CMmsgPrint(CMmsgInfo, "     -u,--subject   [subject]");
            CMmsgPrint(CMmsgInfo, "     -d,--domain    [domain]");
            CMmsgPrint(CMmsgInfo, "     -v,--version   [version]");
            CMmsgPrint(CMmsgInfo, "     -s,--shadeset  [standard|grey|blue|blue-to-red|elevation]");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

    if (verbose) RGlibPauseOpen(argv[0]);

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

    for (argPos = 2; argPos < argNum; ++argPos) {
        mergeData = new DBObjData();
        if (mergeData->Read(argv[argPos]) == DBFault) {
            delete grdData;
            delete mergeData;
            return (CMfailed);
        }
        if ((retData = DBGridMerge(grdData, mergeData)) == (DBObjData *) NULL) {
            delete grdData;
            delete mergeData;
            return (CMfailed);
        }
        delete grdData;
        delete mergeData;
        grdData = retData;
    }

    if (title != (char *) NULL) retData->Name(title);
    if (subject != (char *) NULL) retData->Document(DBDocSubject, subject);
    if (domain != (char *) NULL) retData->Document(DBDocGeoDomain, domain);
    if (version != (char *) NULL) retData->Document(DBDocVersion, version);
    if (setShadeSet) {
        retData->Flags(DBDataFlagDispModeContShadeSets, DBClear);
        retData->Flags(shadeSet, DBSet);
    }

    ret = output != (char *) NULL ? grdData->Write(output) : grdData->Write(stdout);

    delete grdData;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Exemple #18
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    char *title = (char *) NULL, *subject = (char *) NULL;
    char *domain = (char *) NULL, *version = (char *) NULL;
    DBObjData *srcData, *dstData;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest (argv[argPos], "-t", "--title")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing title!");
                return (CMfailed);
            }
            title = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-u", "--subject")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing subject!");
                return (CMfailed);
            }
            subject = 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);
            }
            domain = 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);
            }
            version = 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 grid> <output grid>", CMfileName(argv[0]));
            CMmsgPrint(CMmsgInfo, "     -t,--title     [dataset title]");
            CMmsgPrint(CMmsgInfo, "     -u,--subject   [subject]");
            CMmsgPrint(CMmsgInfo, "     -d,--domain    [domain]");
            CMmsgPrint(CMmsgInfo, "     -v,--version   [version]");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

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

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

    if ((dstData = DBGridToGrid(srcData)) == (DBObjData *) NULL) {
        delete srcData;
        return (CMfailed);
    }

    if (title   == (char *) NULL)   title = (char *) "Cell Statistics";
    if (subject == (char *) NULL) subject = srcData->Document(DBDocSubject);
    if (domain  == (char *) NULL)  domain = srcData->Document(DBDocGeoDomain);
    if (version == (char *) NULL) version = (char *) "0.01pre";

    dstData->Name(title);
    dstData->Document(DBDocSubject, subject);
    dstData->Document(DBDocGeoDomain, domain);
    srcData->Document(DBDocVersion, version);

    if ((ret = RGlibGridCellStats(srcData, dstData)) == DBSuccess)
        ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ?
              dstData->Write(argv[2]) : dstData->Write(stdout);

    delete srcData;
    delete dstData;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Exemple #19
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    float coeff;
    char *title = (char *) NULL, *subject = (char *) NULL;
    char *domain = (char *) NULL, *version = (char *) NULL;
    char *netName = (char *) NULL, *weightName = (char *) NULL;
    DBInt shadeSet = DBFault, areaMult = true, coeffSet = false;
    DBObjData *data, *netData, *weightData, *grdData;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest (argv[argPos], "-n", "--network")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing network!");
                return (CMfailed);
            }
            netName = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-w", "--weight")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing weight grid!");
                return (CMfailed);
            }
            weightName = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-m", "--mode")) {
            int modeCodes[] = {true, false};
            const char *modes[] = {"rate", "volume", (char *) NULL};

            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing accumulation mode!");
                return (CMfailed);
            }
            if ((areaMult = CMoptLookup(modes, argv[argPos], true)) == DBFault) {
                CMmsgPrint(CMmsgUsrError, "Invalid accumulation mode!");
                return (CMfailed);
            }
            areaMult = modeCodes[areaMult];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-f", "--coefficient")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing coefficient!");
                return (CMfailed);
            }
            if (sscanf(argv[argPos], "%f", &coeff) != 1) {
                CMmsgPrint(CMmsgUsrError, "Invalid coefficient");
                return (CMfailed);
            }
            coeffSet = true;
            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);
            }
            title = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-u", "--subject")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing subject!");
                return (CMfailed);
            }
            subject = 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);
            }
            domain = 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);
            }
            version = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-s", "--shadeset")) {
            int shadeCodes[] = {DBDataFlagDispModeContStandard,
                                DBDataFlagDispModeContGreyScale,
                                DBDataFlagDispModeContBlueScale,
                                DBDataFlagDispModeContBlueRed,
                                DBDataFlagDispModeContElevation};
            const char *shadeSets[] = {"standard", "grey", "blue", "blue-to-red", "elevation", (char *) NULL};

            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing shadeset!");
                return (CMfailed);
            }
            if ((shadeSet = CMoptLookup(shadeSets, argv[argPos], true)) == DBFault) {
                CMmsgPrint(CMmsgUsrError, "Invalid shadeset!");
                return (CMfailed);
            }
            shadeSet = shadeCodes[shadeSet];
            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 grid> <output grid>", CMfileName(argv[0]));
            CMmsgPrint(CMmsgInfo, "     -n,--network     [network coverage]");
            CMmsgPrint(CMmsgInfo, "     -w,--weight      [weight grid]");
            CMmsgPrint(CMmsgInfo, "     -f,--coefficient [coefficient]");
            CMmsgPrint(CMmsgInfo, "     -m,--mode        [rate|volume]");
            CMmsgPrint(CMmsgInfo, "     -t,--title       [dataset title]");
            CMmsgPrint(CMmsgInfo, "     -u,--subject     [subject]");
            CMmsgPrint(CMmsgInfo, "     -d,--domain      [domain]");
            CMmsgPrint(CMmsgInfo, "     -v,--version     [version]");
            CMmsgPrint(CMmsgInfo, "     -s,--shadeset    [standard|grey|blue|blue-to-red|elevation");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

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

    if (netName == (char *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Network is not specified");
        return (CMfailed);
    }

    netData = new DBObjData();
    if ((netData->Read(netName) == DBFault) || (netData->Type() != DBTypeNetwork)) {
        delete netData;
        return (CMfailed);
    }
    if (weightName != (char *) NULL) {
        weightData = new DBObjData();
        if (weightData->Read(weightName) == DBFault) {
            delete netData;
            return (CMfailed);
        }
    }
    else weightData = (DBObjData *) NULL;

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

    if (title == (char *) NULL) title = (char *) "Accumulated Grid";
    if (subject == (char *) NULL) subject = grdData->Document(DBDocSubject);
    if (domain == (char *) NULL) domain = netData->Document(DBDocGeoDomain);
    if (version == (char *) NULL) version = (char *) "0.01pre";

    data = DBNetworkToGrid(netData, DBTypeGridContinuous);
    data->Name(title);
    data->Document(DBDocSubject, subject);
    data->Document(DBDocGeoDomain, domain);
    data->Document(DBDocVersion, version);
    if (shadeSet != DBFault) {
        data->Flags(DBDataFlagDispModeContShadeSets, DBClear);
        data->Flags(shadeSet, DBSet);
    }

    if (coeffSet == false) coeff = areaMult ? 0.000001 : 1.0;
    ret = _CMDnetErosion(netData, grdData, weightData, data, coeff, areaMult);
    if (ret == DBSuccess)
        ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout);

    delete data;
    delete netData;
    delete grdData;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Exemple #20
0
int main(int argc, char *argv[]) {
    int argPos = 0, argNum = argc, ret = CMfailed, itemSize, itemID;
    FILE *inFile = stdin, *outFile = stdout;
    void *items = (void *) NULL;
    MFVarHeader_t header;

    if (argNum < 2) goto Help;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest(argv[argPos], "-i", "--item")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing sampling item!");
                return (CMfailed);
            }
            if ((sscanf(argv[argPos], "%d", &itemID)) != 1) {
                CMmsgPrint(CMmsgUsrError, "Invalid sampling item");
                return (CMfailed);
            }
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        Help:
        if (CMargTest(argv[argPos], "-h", "--help")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) < argPos) break;
            CMmsgPrint(CMmsgUsrError, "%s [options] <in datastream> <out datastream>", CMfileName(argv[0]));
            CMmsgPrint(CMmsgUsrError, "  -i, --item [item]");
            CMmsgPrint(CMmsgUsrError, "  -h,--help");
            ret = CMsucceeded;
            goto Stop;
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }
    if (argNum > 3) {
        CMmsgPrint(CMmsgUsrError, "Extra arguments!");
        goto Stop;
    }

    if ((inFile = (argNum > 1) && (strcmp(argv[1], "-") != 0) ? fopen(argv[1], "r") : stdin) == (FILE *) NULL) {
        CMmsgPrint(CMmsgSysError, "Input file opening error in: %s %d", __FILE__, __LINE__);
        goto Stop;
    }
    if ((outFile = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? fopen(argv[2], "w") : stdout) == (FILE *) NULL) {
        CMmsgPrint(CMmsgSysError, "Output file opening error in: %s %d", __FILE__, __LINE__);
        goto Stop;
    }

    while (MFVarReadHeader(&header, inFile)) {
        if (items == (void *) NULL) {
            itemSize = MFVarItemSize(header.DataType);
            if ((items = (void *) calloc(header.ItemNum, itemSize)) == (void *) NULL) {
                CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s:%d", __FILE__, __LINE__);
                goto Stop;
            }
        }
        if ((int) fread(items, itemSize, header.ItemNum, inFile) != header.ItemNum) {
            CMmsgPrint(CMmsgSysError, "Input reading error in: %s:%d", __FILE__, __LINE__);
            goto Stop;
        }
        if ((itemID < 0) || (itemID >= header.ItemNum)) {
            CMmsgPrint(CMmsgAppError, "Invalid Item id [%d]", itemID);
            continue;
        }
        switch (header.DataType) {
            case MFByte:
                if (((char *) items)[itemID] != header.Missing.Int)
                    fprintf(outFile, "%s\t%d\n", header.Date, (int) ((char *) items)[itemID]);
                else
                    fprintf(outFile, "%s\t\n", header.Date);
                break;
            case MFShort:
                if (header.Swap != 1) MFSwapHalfWord(((short *) items) + itemID);
                if (((short *) items)[itemID] != header.Missing.Int)
                    fprintf(outFile, "\t%d\n", (int) ((short *) items)[itemID]);
                else
                    fprintf(outFile, "%s\t\n", header.Date);
                break;
            case MFInt:
                if (header.Swap != 1) MFSwapWord(((int *) items) + itemID);
                if (((int *) items)[itemID] != header.Missing.Int)
                    fprintf(outFile, "%s\t%d\n", header.Date, (int) ((int *) items)[itemID]);
                else
                    fprintf(outFile, "%s\t\n", header.Date);
                break;
            case MFFloat:
                if (header.Swap != 1) MFSwapWord(((float *) items) + itemID);
                if (CMmathEqualValues(((float *) items)[itemID], header.Missing.Float) == false)
                    fprintf(outFile, "%s\t%f\n", header.Date, (float) ((float *) items)[itemID]);
                else
                    fprintf(outFile, "%s\t\n", header.Date);
                break;
            case MFDouble:
                if (header.Swap != 1) MFSwapLongWord(((double *) items) + itemID);
                if (CMmathEqualValues(((double *) items)[itemID], header.Missing.Float) == false)
                    fprintf(outFile, "%s\t%lf\n", header.Date, (double) ((double *) items)[itemID]);
                else
                    fprintf(outFile, "%s\t\n", header.Date);
                break;
        }
    }
    ret = CMsucceeded;
    Stop:
    if (inFile != stdin) fclose(inFile);
    if (outFile != stdout) fclose(outFile);
    return (ret);
}
Exemple #21
0
int main (int argc,char *argv [])

	{
	int argPos, argNum = argc, ret, verbose = false;
	char *title  = (char *) NULL, *subject = (char *) NULL;
	char *domain = (char *) NULL, *version = (char *) NULL;
	DBInt shadeSet = DBFault;
	char *gridName   = (char *) NULL;
	char *relateName = (char *) NULL;
	char *joinName   = (char *) NULL;
	char *varName    = (char *) NULL;
	char *dateName   = (char *) NULL;
	DBObjData *grdData, *tabData, *outData;

	for (argPos = 1;argPos < argNum; )
		{
		if (CMargTest (argv [argPos],"-g","--grid"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing grid!");         return (CMfailed); }
			gridName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-r","--relate"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing relate field!"); return (CMfailed); }
			relateName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-j","--join"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing join field!");   return (CMfailed); }
			joinName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-i","--variable"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing variable field!"); return (CMfailed); }
			varName = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-a","--date"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing date field!");   return (CMfailed); }
			dateName = argv [argPos];
			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); }
			title = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-u","--subject"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing subject!");      return (CMfailed); }
			subject = 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); }
			domain  = 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); }
			version  = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-s","--shadeset"))
			{
			int shadeCodes [] = {	DBDataFlagDispModeContStandard,
											DBDataFlagDispModeContGreyScale,
											DBDataFlagDispModeContBlueScale,
											DBDataFlagDispModeContBlueRed,
											DBDataFlagDispModeContElevation };
			const char *shadeSets [] = {	"standard","grey","blue","blue-to-red","elevation", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing shadeset!");     return (CMfailed); }
			if ((shadeSet = CMoptLookup (shadeSets,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid shadeset!");     return (CMfailed); }
			shadeSet = shadeCodes [shadeSet];
			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 table> <output grid>",CMfileName(argv[0]));
			CMmsgPrint (CMmsgInfo,"     -g,--grid      [discrete grid coverage]");
			CMmsgPrint (CMmsgInfo,"     -r,--relate    [relate field]");
			CMmsgPrint (CMmsgInfo,"     -j,--join      [join field]");
			CMmsgPrint (CMmsgInfo,"     -i,--variable  [variable field]");
			CMmsgPrint (CMmsgInfo,"     -a,--date      [date field]");
			CMmsgPrint (CMmsgInfo,"     -u,--subject   [subject]");
			CMmsgPrint (CMmsgInfo,"     -d,--domain    [domain]");
			CMmsgPrint (CMmsgInfo,"     -v,--version   [version]");
			CMmsgPrint (CMmsgInfo,"     -s,--shadeset  [standard|grey|blue|blue-to-red|elevation]");
			CMmsgPrint (CMmsgInfo,"     -V,--verbose");
			CMmsgPrint (CMmsgInfo,"     -h,--help");
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); }
		argPos++;
		}

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

	if (gridName   == (char *) NULL) { CMmsgPrint (CMmsgUsrError,"Discrete grid is mandatory");		return (CMfailed); }
	if (relateName == (char *) NULL) { CMmsgPrint (CMmsgUsrError,"Relate field is mandatory"); 		return (CMfailed); }
	if (joinName   == (char *) NULL) { CMmsgPrint (CMmsgUsrError,"Join field is mandatory");			return (CMfailed); }
	if (varName    == (char *) NULL) { CMmsgPrint (CMmsgUsrError,"Variable field is mandatory");	return (CMfailed); }

	grdData = new DBObjData ();
	if ((grdData->Read (gridName) != DBSuccess) || (grdData->Type () != DBTypeGridDiscrete))
		{ delete grdData; CMmsgPrint (CMmsgUsrError,"Grid File Reading Error!"); return (CMfailed); }

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

	if (title	== (char *) NULL)  title   = (char *) "Time Series";
	if (subject == (char *) NULL)  subject = tabData->Document (DBDocSubject);
	if (domain	== (char *) NULL)  domain  = grdData->Document (DBDocGeoDomain);
	if (version == (char *) NULL)  version = (char *) "0.01pre";

	if ((outData = DBGridToGrid (grdData,DBTypeGridContinuous)) == (DBObjData *) NULL) return (CMfailed);

	outData->Name (title);
	outData->Document (DBDocSubject,subject);
	outData->Document (DBDocGeoDomain,domain);
	outData->Document (DBDocVersion,version);
	if (shadeSet != DBFault)
		{
		outData->Flags (DBDataFlagDispModeContShadeSets,DBClear);
		outData->Flags (shadeSet,DBSet);
		}

	if ((ret = RGlibGridUniformGrid (grdData,tabData,relateName,joinName,varName,dateName,outData)) == DBSuccess)
		ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? outData->Write (argv [2]) : outData->Write (stdout);

	delete grdData; delete tabData; delete outData;
	if (verbose) RGlibPauseClose ();
	return (DBSuccess);
	}
Exemple #22
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    DBInt recID;
    DBObjData *data;
    char *tableName = (char *) NULL;
    char *fieldIDName = (char *) NULL;
    char *fieldXName = (char *) NULL;
    char *fieldYName = (char *) NULL;
    DBObjTable *table;
    DBObjTableField *fieldID, *fieldX, *fieldY;
    DBObjRecord *record;
    DBNetworkIF *netIF;
	DBCoordinate coord;

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

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

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

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

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

    netIF = new DBNetworkIF(data);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	{
	int argPos, argNum = argc, ret, verbose = false;
	char *title  = (char *) NULL, *subject = (char *) NULL;
	char *domain = (char *) NULL, *version = (char *) NULL;
	char *zoneGridName = (char *) NULL;
	DBObjData *data, *zGrdData, *cGrdData;

	for (argPos = 1;argPos < argNum; )
		{
		if (CMargTest (argv [argPos],"-z","--zonegrid"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing zonegrid!");     return (CMfailed); }
			zoneGridName = argv [argPos];
			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); }
			title = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-u","--subject"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing subject!");      return (CMfailed); }
			subject = 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); }
			domain  = 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); }
			version  = 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 grid> <output table>",CMprgName(argv[0]));
			CMmsgPrint (CMmsgInfo,"     -z,--zonegrid  [discrete grid coverage]");
			CMmsgPrint (CMmsgInfo,"     -t,--title     [dataset title]");
			CMmsgPrint (CMmsgInfo,"     -u,--subject   [subject]");
			CMmsgPrint (CMmsgInfo,"     -d,--domain    [domain]");
			CMmsgPrint (CMmsgInfo,"     -v,--version   [version]");
			CMmsgPrint (CMmsgInfo,"     -V,--verbose");
			CMmsgPrint (CMmsgInfo,"     -h,--help");
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); }
		argPos++;
		}

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

	if (zoneGridName == (char *) NULL)
		{ CMmsgPrint (CMmsgUsrError,"Zone grid is not specified"); return (CMfailed); }

	zGrdData = new DBObjData ();
	if ((zGrdData->Read (zoneGridName) == DBFault) || (zGrdData->Type () != DBTypeGridDiscrete))
		{ delete zGrdData; return (CMfailed); }

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

	if (title	== (char *) NULL)   title = (char *) "Zone Histogram";
	if (subject == (char *) NULL) subject = cGrdData->Document (DBDocSubject);
	if (domain	== (char *) NULL)  domain = zGrdData->Document (DBDocGeoDomain);
	if (version == (char *) NULL) version = (char *) "0.01pre";

	data = new DBObjData (title,DBTypeTable);
	data->Document (DBDocSubject,subject);
	data->Document (DBDocGeoDomain,domain);
	data->Document (DBDocVersion,version);

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

	delete data; delete zGrdData; delete cGrdData;
	if (verbose) RGlibPauseClose ();
	return (ret);
	}
Exemple #26
0
int main(int argc, char* argv[]){
	bool All_Fields = false;
	char *title    = (char *) NULL, *subject   = (char *) NULL, *domain = (char *) NULL, *version = (char *) NULL;
	char *citation = (char *) NULL, *institute = (char *) NULL, *source = (char *) NULL, *person  = (char *) NULL;
	char *comment  = (char *) NULL, *type      = (char *) NULL, ch = 'x';
	int argPos, argNum = argc, verbose = false;
	FILE *file = (FILE *) NULL;
	DBObjData *dbData = new DBObjData();
	DBDataHeader header;

	if (argc == 1) { Show_Usage(argv[0]); return 0; }

	for (argPos = 1;argPos < argNum; )
		{
		if (CMargTest (argv [argPos],"-a","--all")) {
   		All_Fields = true;
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-V","--verbose")) {
			verbose = true;
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-h","--help")) { Show_Usage(argv[0]); return 0; }
		if ((file == (FILE *) NULL) && (access(argv[argPos],R_OK) == 0)) file = fopen(argv[argPos],"r");
						// ugly but working method to search for input filename.
		argPos++;
		}

	if (file != (FILE *) NULL)
		{
		if (header.Read(file) == DBFault) { delete dbData; return(DBFault); }
		fseek(file,0,SEEK_SET); //go back to beginning of file
		if (dbData->Read(file) == DBFault) { delete dbData; return(DBFault); }
		fclose(file);
		}
	else
		{
		CMmsgPrint (CMmsgUsrError,"No data file, reading from stdin!");
		if (header.Read(stdin) == DBFault) { delete dbData; return(DBFault); }
		if (dbData->Read(stdin) == DBFault) { delete dbData; return(DBFault); }
		}

	if(All_Fields)
		{
		title     = dbData->Name();
		domain    = dbData->Document(DBDocGeoDomain);
		subject   = dbData->Document(DBDocSubject);
		version   = dbData->Document(DBDocVersion);
		type      = DBDataTypeString(header.Type ());
		institute = dbData->Document(DBDocCitationInst); 
		person    = dbData->Document(DBDocOwnerPerson);
		citation  = dbData->Document(DBDocCitationRef);
		comment   = dbData->Document(DBDocComment);
		source    = dbData->Document(DBDocSourcePerson);
		}
	else
		{
		for (argPos = 1;argPos < argNum; ) {
			if (CMargTest (argv [argPos],"-t","--title")) {
				title = dbData->Name();
				if(title == (char *) NULL) title = &ch;
				if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
				continue;
			}
			if (CMargTest (argv [argPos],"-d","--domain")) {
				domain = dbData->Document(DBDocGeoDomain);
				if(domain == (char *) NULL) domain = &ch;
				if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
				continue;
			}
			if (CMargTest (argv [argPos],"-s","--subject")) {
				subject = dbData->Document(DBDocSubject);
				if(subject == (char *) NULL) subject = &ch;
				if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
				continue;
			}
			if (CMargTest (argv [argPos],"-v","--version")) {
				version = dbData->Document(DBDocVersion);
				if(version == (char *) NULL) version = &ch;
				if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
				continue;
			}
			if (CMargTest (argv [argPos],"-n","--institute")) {
				institute = dbData->Document(DBDocCitationInst); 
				if(institute == (char *) NULL) institute = &ch;
				if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
				continue;
			}
			if (CMargTest (argv [argPos],"-p","--person")) {
				person = dbData->Document(DBDocOwnerPerson);
				if(person == (char *) NULL) person = &ch;
				if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
				continue;
			}
			if (CMargTest (argv [argPos],"-i","--citation")) {
				citation = dbData->Document(DBDocCitationRef);
				if(citation == (char *) NULL) citation = &ch;
				if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
				continue;
			}
			if (CMargTest (argv [argPos],"-c","--comment")) {
				comment = dbData->Document(DBDocComment);
				if(comment == (char *) NULL) comment = &ch;
				if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
				continue;
			}
			if (CMargTest (argv [argPos],"-S","--source")) {
				source = dbData->Document(DBDocSourcePerson);
				if(source == (char *) NULL) source = &ch;
				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 (argNum > 3) { CMmsgPrint (CMmsgUsrError,"Extra arguments!"); return (CMfailed); }
	if (verbose) RGlibPauseOpen (argv[0]);


	if (title     == &ch) printf("Title: N/A\n");              else if (title     != (char *) NULL) printf("Title: %s\n",             title);
	if (domain    == &ch) printf("Domain: N/A\n");             else if (domain    != (char *) NULL) printf("Domain: %s\n",            domain);
	if (subject   == &ch) printf("Subject: N/A\n");            else if (subject   != (char *) NULL) printf("Subject: %s\n",           subject);
	if (version   == &ch) printf("Version: N/A\n");            else if (version   != (char *) NULL) printf("Version: %s\n",           version);
	if (type      == &ch) printf("Data Type: N/A\n");          else if (type      != (char *) NULL) printf("Data Type: %s\n",         type);
	if (institute == &ch) printf("Citation Institute: N/A\n"); else if (institute != (char *) NULL) printf("Citation Institute: %s\n",institute); 
	if (citation  == &ch) printf("Citation Reference: N/A\n"); else if (citation  != (char *) NULL) printf("Citation Reference: %s\n",citation);
	if (person    == &ch) printf("Person: N/A\n");             else if (person    != (char *) NULL) printf("Person: %s\n",            person);
	if (source    == &ch) printf("Source: N/A\n");             else if (source    != (char *) NULL) printf("Source: %s\n",            source);
	if (comment   == &ch) printf("Comment: N/A\n");            else if (comment   != (char *) NULL) printf("Comment: %s\n",           comment);

	if (verbose) RGlibPauseClose ();
	return (0);
}
Exemple #27
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    char *title = (char *) NULL, *subject = (char *) NULL;
    char *domain = (char *) NULL, *version = (char *) NULL;
    int shadeSet = DBFault;
    DBInt stepNum = DBFault, offset = 0;
    DBObjData *tsData, *data;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest (argv[argPos], "-n", "--number")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing step number!");
                return (CMfailed);
            }
            if (sscanf(argv[argPos], "%d", &stepNum) != 1) {
                CMmsgPrint(CMmsgUsrError, "Invalid stepnum!");
                return (CMfailed);
            }
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-o", "--offset")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing offset!");
                return (CMfailed);
            }
            if (sscanf(argv[argPos], "%d", &offset) != 1) {
                CMmsgPrint(CMmsgUsrError, "Invalid offset!");
                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);
            }
            title = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-u", "--subject")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing subject!");
                return (CMfailed);
            }
            subject = 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);
            }
            domain = 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);
            }
            version = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-s", "--shadeset")) {
            int shadeCodes[] = {DBDataFlagDispModeContStandard,
                                DBDataFlagDispModeContGreyScale,
                                DBDataFlagDispModeContBlueScale,
                                DBDataFlagDispModeContBlueRed,
                                DBDataFlagDispModeContElevation};
            const char *shadeSets[] = {"standard", "grey", "blue", "blue-to-red", "elevation", (char *) NULL};

            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing shadeset!");
                return (CMfailed);
            }
            if ((shadeSet = CMoptLookup(shadeSets, argv[argPos], true)) == DBFault) {
                CMmsgPrint(CMmsgUsrError, "Invalid shadeset!");
                return (CMfailed);
            }
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            shadeSet = shadeCodes[shadeSet];
            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 grid> <output grid>", CMfileName(argv[0]));
            CMmsgPrint(CMmsgInfo, "     -n,--number   [# of steps]");
            CMmsgPrint(CMmsgInfo, "     -o,--offset    [offset]");
            CMmsgPrint(CMmsgInfo, "     -t,--title     [dataset title]");
            CMmsgPrint(CMmsgInfo, "     -u,--subject   [subject]");
            CMmsgPrint(CMmsgInfo, "     -d,--domain    [domain]");
            CMmsgPrint(CMmsgInfo, "     -v,--version   [version]");
            CMmsgPrint(CMmsgInfo, "     -s,--shadeset  [standard|grey|blue|blue-to-red|elevation]");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

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

    if (stepNum == DBFault) {
        CMmsgPrint(CMmsgUsrError, "Cycle step number is not set!");
        return (CMfailed);
    }
    tsData = new DBObjData();
    ret = (argNum > 1) && (strcmp(argv[1], "-") != 0) ? tsData->Read(argv[1]) : tsData->Read(stdin);
    if ((ret == DBFault) || (tsData->Type() != DBTypeGridContinuous)) {
        delete tsData;
        return (CMfailed);
    }

    data = DBGridToGrid(tsData);

    if (title == (char *) NULL) title = tsData->Name();
    if (subject == (char *) NULL) subject = tsData->Document(DBDocSubject);
    if (domain == (char *) NULL) domain = tsData->Document(DBDocGeoDomain);
    if (version == (char *) NULL) version = tsData->Document(DBDocVersion);
    if (shadeSet == DBFault) shadeSet = DBDataFlagDispModeContGreyScale;

    data->Name(title);
    data->Document(DBDocSubject, subject);
    data->Document(DBDocGeoDomain, domain);
    data->Document(DBDocVersion, version);
    data->Flags(DBDataFlagDispModeContShadeSets, DBClear);
    data->Flags(shadeSet, DBSet);

    if ((ret = RGlibCycleMean(tsData, data, stepNum, offset)) == DBSuccess)
        ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout);

    delete tsData;
    delete data;
    if (verbose) RGlibPauseClose();
    return (ret);
}
Exemple #28
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, tblLayout;
    int tblLayouts[2];
    const char *layoutTexts[] = {"vertical", "horizontal", (char *) NULL};
    char *sample = (char *) NULL;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest (argv[argPos], "-S", "--sample")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argc)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "%s: Missing sampling coverage!", CMfileName(argv[0]));
                return (CMfailed);
            }
            sample = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argc)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-L", "--layout")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argc)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing layout!");
                return (CMfailed);
            }
            if ((tblLayout = CMoptLookup(layoutTexts, argv[argPos], true)) == CMfailed) {
                CMmsgPrint(CMmsgUsrError, "%s: Invalid table layout [%s]!", CMfileName(argv[0]), argv[argPos]);
                return (CMfailed);
            }
            tblLayout = tblLayouts[tblLayout];
            if ((argNum = CMargShiftLeft(argPos, argv, argc)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-h", "--help")) {
            fprintf(stdout, "%s [options] <ncgis grid> <ascii table>", CMfileName(argv[0]));
            fprintf(stdout, "     -S,--sampling");
            fprintf(stdout, "     -L,--layout [vertical|horizontal]");
            fprintf(stdout, "     -h,--help");
            return (NCsucceeded);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }
    if (sample == (char *) NULL) {
        CMmsgPrint(CMmsgUsrError, "%s: Missing template!", CMfileName(argv[0]));
        return (CMfailed);
    }

    if (argNum < 2) {
        CMmsgPrint(CMmsgUsrError, "%s: Too few arguments!", CMfileName(argv[0]));
        return (CMfailed);
    }
/*
	if ((objGrid = NCObjDataOpen (argv [1],true)) == (NCObjData_t *) NULL) return (CMfailed);
	if ((objGrid->DType != NCTypeContGrid) && (objGrid->DType != NCTypeDiscGrid))
	{
		CMmsgPrint (CMmsgUsrError, "%s: Non-grid input coverage!", CMfileName (argv [0]));
		NCObjDataFree (objGrid);
		return (CMfailed);
	}
	if ((objData = NCObjDataOpen (sample,true)) == (NCObjData_t *) NULL)
	{
		NCObjDataFree (objGrid);
		return (CMfailed);
	}
	if ((objData->DType != NCTypePoint)    && (objData->DType != NCTypeNetwork))
	{
		CMmsgPrint (CMmsgUsrError, "%s: Invalid sampling coverage!", CMfileName (argv [0]));
		NCObjDataFree (objGrid);
		NCObjDataFree (objData);
		return (CMfailed);
	}
	objTable = NCGridContPointSampling (objGrid,objData,tblLayout);

	NCObjDataFree (objGrid);
	NCObjDataFree (objData);
*/
    return (CMsucceeded);
}
Exemple #29
0
int main (int argc,char *argv [])

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

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

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

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

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

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

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

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

	free (fieldNames);
	delete data;
	if (verbose) RGlibPauseClose ();
	return (ret);
	}
Exemple #30
0
int main(int argc, char *argv[]) {
    int argPos, argNum = argc, ret, verbose = false;
    char *title = (char *) NULL, *subject = (char *) NULL;
    char *domain = (char *) NULL, *version = (char *) NULL;
    DBObjData *netData, *pntData;

    for (argPos = 1; argPos < argNum;) {
        if (CMargTest (argv[argPos], "-t", "--title")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing title!");
                return (CMfailed);
            }
            title = argv[argPos];
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break;
            continue;
        }
        if (CMargTest (argv[argPos], "-u", "--subject")) {
            if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) {
                CMmsgPrint(CMmsgUsrError, "Missing subject!");
                return (CMfailed);
            }
            subject = 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);
            }
            domain = 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);
            }
            version = 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 network> <output point>", CMfileName(argv[0]));
            CMmsgPrint(CMmsgInfo, "     -t,--title     [dataset title]");
            CMmsgPrint(CMmsgInfo, "     -u,--subject   [subject]");
            CMmsgPrint(CMmsgInfo, "     -d,--domain    [domain]");
            CMmsgPrint(CMmsgInfo, "     -v,--version   [version]");
            CMmsgPrint(CMmsgInfo, "     -V,--verbose");
            CMmsgPrint(CMmsgInfo, "     -h,--help");
            return (DBSuccess);
        }
        if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) {
            CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]);
            return (CMfailed);
        }
        argPos++;
    }

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

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

    if (title == (char *) NULL) title = (char *) "River Confluences";
    if (subject == (char *) NULL) subject = netData->Document(DBDocSubject);
    if (domain == (char *) NULL) domain = (char *) netData->Document(DBDocGeoDomain);
    if (version == (char *) NULL) version = (char *) "0.01pre";

    pntData = new DBObjData(title, DBTypeVectorPoint);
    pntData->Document(DBDocSubject, subject);
    pntData->Document(DBDocGeoDomain, domain);
    pntData->Document(DBDocVersion, version);

    if ((ret = RGlibNetworkConfluences(netData, pntData)) == DBSuccess)
        ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? pntData->Write(argv[2]) : pntData->Write(stdout);

    delete netData;
    delete pntData;
    if (verbose) RGlibPauseClose();
    return (ret);
}