int main(int argc, char **argv) { OptionParser op; ProgName = Basename(argv[0]); if (op.AppendOptions(set_opts) < 0) { cerr << ProgName << " : " << op.GetErrMsg(); exit(1); } if (op.ParseOptions(&argc, argv, get_options) < 0) { cerr << ProgName << " : " << OptionParser::GetErrMsg(); exit(1); } MyBase::SetErrMsgCB(ErrMsgCBHandler); if (opt.help) { Usage(op, NULL); exit(0); } if (argc != 2) { Usage(op, "Wrong number of arguments"); exit(1); } if ((strlen(opt.cmap) == 0) && (strlen(opt.omap) == 0)) { Usage(op, "Wrong number of arguments"); exit(1); } TransferFunctionLite tf(8); if (MyBase::GetErrCode() !=0) exit(1); tf.setMinColorMapValue(0.0); tf.setMaxColorMapValue(1.0); tf.setMinOpacMapValue(0.0); tf.setMaxOpacMapValue(1.0); string vtffile(argv[1]); int rc; if (strlen(opt.cmap) != 0) { ProcessCMAP(&tf, opt.type); } if (strlen(opt.omap) != 0) { float point, o; vector <float> pvec, ovec; OpacityMapBase *omap = tf.getOpacityMap(0); omap->clear(); FILE *fp = fopen(opt.omap, "r"); if (! fp) { MyBase::SetErrMsg("fopen(%s) : %M", opt.omap); exit(1); } const char *format = "%f %f"; while ((rc = fscanf(fp, format, &point, &o)) == 2) { pvec.push_back(point); ovec.push_back(o); } vector <float> tmpvec = pvec; sort(tmpvec.begin(), tmpvec.end()); tf.setMinOpacMapValue(tmpvec[0]); tf.setMaxOpacMapValue(tmpvec[tmpvec.size()-1]); omap->minValue(tmpvec[0]); omap->maxValue(tmpvec[tmpvec.size()-1]); for (int i=0; i<pvec.size(); i++) { // omap->addNormControlPoint(pvec[i], ovec[i]); omap->addControlPoint(pvec[i], ovec[i]); } omap->minValue(0.0); omap->maxValue(1.0); if (ferror(fp)) { MyBase::SetErrMsg("Error parsing file %s", opt.omap); exit(1); } fclose(fp); } // End of if omap. // // Write output file. // ofstream fileout; fileout.open(vtffile.c_str()); if (! fileout) { MyBase::SetErrMsg( "Can't open file \"%s\" for writing", vtffile.c_str() ); exit(1); } if (! (tf.saveToFile(fileout))) exit(1); exit(0); } // End of Main.
int main(int argc, char **argv) { OptionParser op; const char *metafile; string s; MyBase::SetErrMsgCB(ErrMsgCB); ProgName = Basename(argv[0]); if (op.AppendOptions(set_opts) < 0) { cerr << ProgName << " : " << op.GetErrMsg(); exit(1); } if (op.ParseOptions(&argc, argv, get_options) < 0) { cerr << ProgName << " : " << op.GetErrMsg(); exit(1); } if (opt.help) { cerr << "Usage: " << ProgName << " [options] metafile datafile" << endl; op.PrintOptionHelp(stderr); exit(0); } if (argc != 2) { cerr << "Usage: " << ProgName << " [options] metafile " << endl; op.PrintOptionHelp(stderr); exit(1); } metafile = argv[1]; map <long, map <string, VarFileInfo > > statsvec; const MetadataVDC *metadata = new MetadataVDC(metafile); if (MyBase::GetErrCode() != 0) exit(1); if (getStats(metadata, statsvec) < 0) { exit(1); } string sort = opt.sort; int numApproximations; if (metadata->GetVDCType() == 2) { if (opt.level < 0) numApproximations = metadata->GetCRatios().size(); else numApproximations = opt.level+1; } else { if (opt.level < 0) numApproximations = metadata->GetNumTransforms()+1; else numApproximations = opt.level+1; } if (sort.compare("time") == 0) { map <long, map <string, VarFileInfo > >::iterator iter1; for (iter1 = statsvec.begin(); iter1 != statsvec.end(); iter1++) { map <string, VarFileInfo>::iterator iter2; for (iter2 = iter1->second.begin(); iter2 != iter1->second.end(); iter2++) { const VarFileInfo &vfiref = iter2->second; for(int j=0; j<numApproximations; j++) { PrintVariable(metadata,vfiref, j); } } } } else if (sort.compare("level") == 0) { for (int j=0; j<numApproximations; j++) { map <long, map <string, VarFileInfo > >::iterator iter1; for (iter1 = statsvec.begin(); iter1 != statsvec.end(); iter1++) { map <string, VarFileInfo>::iterator iter2; for (iter2 = iter1->second.begin(); iter2 != iter1->second.end(); iter2++) { const VarFileInfo &vfiref = iter2->second; PrintVariable(metadata,vfiref, j); } } } } else if (sort.compare("varname") == 0) { const vector <string> varNames = metadata->GetVariableNames(); vector <string>::const_iterator iter1; for (iter1=varNames.begin(); iter1 != varNames.end(); iter1++) { for (int j=0; j<numApproximations; j++) { map <long, map <string, VarFileInfo > >::iterator iter2; for (iter2 = statsvec.begin(); iter2 != statsvec.end(); iter2++) { const VarFileInfo &vfiref = iter2->second[*iter1];; PrintVariable(metadata,vfiref, j); } } } } else { MyBase::SetErrMsg("Invalid sort \"%s\"", sort.c_str()); exit(1); } exit(0); }