References MaxEntryList::count(), MaxEntryList::CURVE, QGpCoreTools::endl(), HistogramWidget::fillGrid(), filter(), MaxEntryList::FK, help(), HistogramWidget::initGrid(), QGpCoreTools::LinearScale, MaxEntryList::load(), QGpCoreTools::LogScale, HistogramWidget::maxEntryList(), mode, MSG_ID, scaleType, scaleTypeForced, HistogramWidget::select(), MaxEntryList::setType(), HistogramWidget::show(), sOut(), MaxEntryList::SPAC, MaxEntryList::TFA, tfaAmpH, tfaAmpZ, tfaDelay, tfaFactor, tfaNppf, tfaNppm, tmax, tmin, MaxEntryList::toStream(), HistogramWidget::toStream(), QGpCoreTools::tr(), and w.
{
Application a(argc, argv, help);
SciFigsGlobal s;
QString maxFile;
QString fileType;
enum Mode {Gui, Mean, Median, Max};
Mode mode=Gui;
double minValue=0.0, maxValue=0.0;
int nClasses=200;
int i, j=1;
for(i=1; i<argc; i++) {
QByteArray arg=argv[i];
if(arg[0]=='-') {
if(arg=="-type") {
CoreApplication::checkOptionArg(i, argc, argv);
fileType=argv[i];
} else if(arg=="-min") {
CoreApplication::checkOptionArg(i, argc, argv);
minValue=atof(argv[i] );
} else if(arg=="-max") {
CoreApplication::checkOptionArg(i, argc, argv);
maxValue=atof(argv[i] );
} else if(arg=="-n") {
CoreApplication::checkOptionArg(i, argc, argv);
nClasses=atoi(argv[i] );
} else if(arg=="-mean") {
mode=Mean;
} else if(arg=="-median") {
mode=Median;
} else if(arg=="-m") {
mode=Max;
} else if(arg=="-linear") {
scaleTypeForced=true;
scaleType=LinearScale;
} else if(arg=="-log") {
scaleTypeForced=true;
scaleType=LogScale;
} else if(arg=="-tmin") {
CoreApplication::checkOptionArg(i, argc, argv);
tmin=atof(argv[i]);
} else if(arg=="-tmax") {
CoreApplication::checkOptionArg(i, argc, argv);
tmax=atof(argv[i]);
} else if(arg=="-tfaNppm") {
CoreApplication::checkOptionArg(i, argc, argv);
tfaNppm=atof(argv[i] );
} else if(arg=="-tfaNppf") {
CoreApplication::checkOptionArg(i, argc, argv);
tfaNppf=atoi(argv[i] );
} else if(arg=="-tfaFactor") {
CoreApplication::checkOptionArg(i, argc, argv);
tfaFactor=atof(argv[i] );
} else if(arg=="-tfaAmpZ") {
CoreApplication::checkOptionArg(i, argc, argv);
tfaAmpZ=atof(argv[i] );
} else if(arg=="-tfaAmpH") {
CoreApplication::checkOptionArg(i, argc, argv);
tfaAmpH=atof(argv[i] );
} else if(arg=="-tfaDelay") {
CoreApplication::checkOptionArg(i, argc, argv);
tfaDelay=atof(argv[i] );
} else {
App::stream() << tr("max2curve: bad option %1, see -help").arg(argv[i]) << endl;
return 2;
}
} else {
argv[j++]=argv[i];
}
}
if(j < argc) {
argv[j]=0;
argc=j;
}
if(argc>1) {
maxFile=argv[1];
}
switch (mode) {
case Max:
case Gui:
break;
case Mean:
case Median:
if(minValue>=maxValue) {
App::stream() << tr("Minimum and maximum are equal. These values must be defined by "
"options -min and -max, see -help for details.") << endl;
return 2;
}
break;
}
if(maxFile.isEmpty()) {
maxFile=Message::getOpenFileName(tr("Loading max file"),
tr("max file (*.max)"));
if(maxFile.isEmpty()) return 2;
}
MaxEntryList * maxList=new MaxEntryList;
if(!fileType.isEmpty()) {
if(fileType=="FK") maxList->setType(MaxEntryList::FK);
else if(fileType=="SPAC") maxList->setType(MaxEntryList::SPAC);
else if(fileType=="TFA") maxList->setType(MaxEntryList::TFA);
else if(fileType=="CURVE") maxList->setType(MaxEntryList::CURVE);
}
if(!maxList->load(maxFile)) {
delete maxList;
return 2;
}
if(maxList->isEmpty()) {
Message::warning(MSG_ID, tr("Loading max file"),
tr("No max result can be loaded"));
return 2;
}
HistogramWidget * w=new HistogramWidget(maxList);
w->setWindowTitle(QString("max2curve - %2 - %1").arg(maxFile));
int appReturn=0;
if(mode==Gui) {
filter(w);
if( !w->select(scaleTypeForced, scaleType) ) {
delete w;
return 2;
}
fprintf(stderr,"Filtering: remaining %i entries\n",w->maxEntryList()->count());
w->show();
appReturn=a.exec();
} else {
filter(w);
w->initGrid(nClasses, minValue, maxValue, scaleType);
fprintf(stderr,"Filtering: remaining %i entries\n",w->maxEntryList()->count());
if(w->maxEntryList()->isEmpty()) {
fprintf(stderr,"No entries, abort\n");
delete w;
return 2;
}
QTextStream sOut(stdout);
switch (mode) {
case Max:
w->maxEntryList()->toStream(sOut);
break;
case Mean:
w->fillGrid();
w->addMeanCurve();
sOut << QString("# Mean curve from file %1\n").arg(maxFile);
w->toStream(sOut, 0);
break;
case Median:
w->fillGrid();
w->addMedianCurve();
sOut << QString("# Median curve from file %1\n").arg(maxFile);
w->toStream(sOut, 0);
case Gui:
break;
}
}
delete w;
return appReturn;
}