int DBImportDMGrid (DBObjData *data,const char *fileName) { FILE *file; DBInt ret; if ((file = fopen (fileName,"r")) == (FILE *) NULL) { CMmsgPrint (CMmsgSysError, "File Opening Error in: %s %d",__FILE__,__LINE__); return (DBFault); } ret = DBImportDMGrid (data,file); fclose (file); return (ret); }
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; DBInt gridType = DBFault; DBObjData *data; 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], "-y", "--type")) { int typeCodes[] = {DBTypeGridContinuous, DBTypeGridDiscrete}; const char *types[] = {"continuous", "discrete", (char *) NULL}; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing gridtype!"); return (CMfailed); } if ((gridType = CMoptLookup(types, argv[argPos], true)) == CMfailed) { CMmsgPrint(CMmsgUsrError, "Invalid grid type!"); return (CMfailed); } gridType = typeCodes[gridType]; 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] <dm file> <rgis file>", 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, " -y,--type [continuous|discrete]"); 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 (title == (char *) NULL) { CMmsgPrint(CMmsgUsrError, "Title is not set!"); return (CMfailed); } if (subject == (char *) NULL) subject = (char *) "Default Subject"; if (domain == (char *) NULL) domain = (char *) "Default Domain"; if (version == (char *) NULL) version = (char *) "0.01pre"; if (gridType == DBFault) gridType = DBTypeGridContinuous; data = new DBObjData(title, gridType); ret = (argNum > 1) && (strcmp(argv[1], "-") != 0) ? DBImportDMGrid(data, argv[1]) : DBImportDMGrid(data, stdin); if (ret == DBFault) { delete data; return (DBFault); } data->Document(DBDocSubject, subject); data->Document(DBDocGeoDomain, domain); data->Document(DBDocVersion, version); if (shadeSet != DBFault) { data->Flags(DBDataFlagDispModeContShadeSets, DBClear); data->Flags(shadeSet, DBSet); } ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout); delete data; if (verbose) RGlibPauseClose(); return (ret); }