KJS::Value KstBindDataSource::frameCount(KJS::ExecState *exec, const KJS::List& args) { QString field; if (args.size() == 1) { if (args[0].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Number(0); } field = args[0].toString(exec).qstring(); } else if (args.size() != 0) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires at most one argument."); exec->setException(eobj); return KJS::Number(0); } KstDataSourcePtr s = makeSource(_d); if (!s) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Number(0); } s->writeLock(); int rc = s->frameCount(field); s->unlock(); return KJS::Number(rc); }
void KstVectorDialogI::new_I() { KstDataSourcePtr file; KstRVectorPtr vector; KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); QString tag_name = Select->currentText(); tag_name.replace(i18n("<New_Vector>"), Field->currentText()); KST::vectorList.lock().readLock(); int i_c = KST::vectorList.count() + 1; KST::vectorList.lock().readUnlock(); while (KST::dataTagNameNotUnique(tag_name, false)) { tag_name.sprintf("V%d-", i_c); tag_name += Field->currentText(); i_c++; } /* if there is not an active KstFile, create one */ { KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findFileName(FileName->url()); if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(FileName->url()); if (!file || !file->isValid()) { KMessageBox::sorry(0L, i18n("The file could not be loaded.")); return; } if (file->frameCount() < 1) { KMessageBox::sorry(0L, i18n("The file does not contain data.")); return; } KST::dataSourceList.append(file); } else { file = *it; } KST::dataSourceList.lock().writeUnlock(); } if (!file->isValidField(Field->currentText())) { KMessageBox::sorry(0L, i18n("The requested field is not defined for the requested file.")); return; } /* create the vector */ vector = new KstRVector(file, Field->currentText(), tag_name, (CountFromEnd->isChecked() ? -1 : F0->value()), (ReadToEnd->isChecked() ? -1 : N->value()), Skip->value(), DoSkip->isChecked(), DoFilter->isChecked()); emit vectorCreated(KstVectorPtr(vector)); vector = 0L; vectorList.clear(); emit modified(); }
void KstChangeNptsDialogI::applyNptsChange() { KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (uint i = 0; i < CurveList->count(); ++i) { if (CurveList->isSelected(i)) { KstRVectorPtr vector = *(rvl.findTag(CurveList->text(i))); if (vector) { int f0, n; vector->readLock(); KstDataSourcePtr ds = vector->dataSource(); if (_kstDataRange->isStartRelativeTime() && ds) { ds->readLock(); f0 = ds->sampleForTime(_kstDataRange->f0Value()); ds->unlock(); } else if (_kstDataRange->isStartAbsoluteTime() && ds) { ds->readLock(); f0 = ds->sampleForTime(_kstDataRange->f0DateTimeValue()); ds->unlock(); } else { f0 = int(_kstDataRange->f0Value()); } if (_kstDataRange->isRangeRelativeTime() && ds) { ds->readLock(); double nValStored = _kstDataRange->nValue(); if (_kstDataRange->CountFromEnd->isChecked()) { int frameCount = ds->frameCount(vector->field()); double msCount = ds->relativeTimeForSample(frameCount - 1); n = frameCount - 1 - ds->sampleForTime(msCount - nValStored); } else { double fTime = ds->relativeTimeForSample(f0); n = ds->sampleForTime(fTime + nValStored) - ds->sampleForTime(fTime); } ds->unlock(); } else { n = int(_kstDataRange->nValue()); } vector->unlock(); vector->writeLock(); vector->changeFrames( (_kstDataRange->CountFromEnd->isChecked() ? -1 : f0), (_kstDataRange->ReadToEnd->isChecked() ? -1 : n), _kstDataRange->Skip->value(), _kstDataRange->DoSkip->isChecked(), _kstDataRange->DoFilter->isChecked()); vector->unlock(); } } } _modifiedRange = false; // avoid re-entering the dialog QTimer::singleShot(0, this, SLOT(emitDocChanged())); }
const QString& KstIfaceImpl::loadVector(const QString& file, const QString& field) { KstDataSourcePtr src; /* generate or find the kstfile */ KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findFileName(file); if (it == KST::dataSourceList.end()) { src = KstDataSource::loadSource(file); if (!src || !src->isValid()) { KST::dataSourceList.lock().writeUnlock(); return QString::null; } if (src->frameCount() < 1) { KST::dataSourceList.lock().writeUnlock(); return QString::null; } KST::dataSourceList.append(src); } else { src = *it; } src->writeLock(); KST::dataSourceList.lock().writeUnlock(); KST::vectorList.lock().readLock(); QString vname = "V" + QString::number(KST::vectorList.count() + 1); while (KST::vectorTagNameNotUnique(vname, false)) { vname = "V" + QString::number(KST::vectorList.count() + 1); } KST::vectorList.lock().readUnlock(); KstVectorPtr p = new KstRVector(src, field, vname, 0, -1, 0, false, false); KST::addVectorToList(p); src->writeUnlock(); if (p) { _doc->forceUpdate(); _doc->setModified(); return p->tagName(); } return QString::null; }
void KstChangeFileDialogI::applyFileChange() { KstDataSourcePtr file; KstRVectorPtr vector; KstWriteLocker ml(&KST::dataSourceList.lock()); /* if there is not an active KstFile, create one */ KstDataSourceList::Iterator it; for (it = KST::dataSourceList.begin(); it != KST::dataSourceList.end(); ++it) { if ((*it)->fileName() == ChangeFileName->currentText()) { file = *it; break; } } if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(ChangeFileName->currentText()); if (!file || !file->isValid()) { KMessageBox::sorry(0L, i18n("%1: Unable to open file.").arg(ChangeFileName->currentText())); return; } if (file->frameCount() < 1) { KMessageBox::sorry(0L, i18n("%1: File does not contain data. Operation canceled.").arg(ChangeFileName->currentText())); return; } KST::dataSourceList.append(file); } KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (int i = 0; i < (int)ChangeFileCurveList->count(); i++) { if (ChangeFileCurveList->isSelected(i)) { vector = rvl[i]; if (!file->isValidField(vector->getField())) { KMessageBox::sorry(0L, i18n("%1: Field is not defined for the requested file.").arg(vector->getField())); } else { vector->changeFile(file); } } } /** purge unused files */ //KST::fileList.Purge(); emit docChanged(); }
void KstVectorDialogI::edit_I() { KstDataSourcePtr file; KstRVectorPtr vector; int index = Select->currentItem(); if (index < 0) { KMessageBox::sorry(0L, i18n("You need to select an active vector to edit.")); return; } KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); if (unsigned(index) >= vectorList.count()) { new_I(); } else { /* verify that the vector name is unique */ if (Select->currentText() != vectorList[index]->tagName()) { if (KST::dataTagNameNotUnique(Select->currentText())) return; } /* if there is not an active KstFile, create one */ { KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findFileName(FileName->url()); if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(FileName->url()); if (!file || !file->isValid()) { KMessageBox::sorry(0L, i18n("The file could not be opened.")); return; } if (file->frameCount() < 1) { KMessageBox::sorry(0L, i18n("The file does not contain data.")); return; } KST::dataSourceList.append(file); } else { file = *it; } KST::dataSourceList.lock().writeUnlock(); } if (!file->isValidField(Field->currentText())) { KMessageBox::sorry(0L, i18n("The requested field is not defined for the requested file\n")); return; } vector = vectorList[index]; /* change the vector */ vector->change(file, Field->currentText(), Select->currentText(), (CountFromEnd->isChecked() ? -1 : F0->value()), (ReadToEnd->isChecked() ? -1 : N->value()), Skip->value(), DoSkip->isChecked(), DoFilter->isChecked()); /** purge unused files */ //doc->fileList.Purge(); vector = 0L; vectorList.clear(); emit modified(); } }
void KstQuickPSDDialogI::apply(bool autolabel) { KstDataSourcePtr file; KstVectorPtr vx; KstRVectorPtr trv; KstPlot *plot; int i_v; QString v_name, c_name; bool x_is_new; KstPSDCurvePtr curve; double new_freq; int new_len; if (KST::plotList.count() < 1) { addPlot(); return; } if (SourceVector->isChecked()) { // set vx from existing vectors i_v = Vectors->currentItem(); KstReadLocker ml(&KST::vectorList.lock()); if (i_v >= (int)KST::vectorList.count()) { return; } vx = KST::vectorList[i_v]; } else { // set vx from data file specification KstReadLocker ml(&KST::dataSourceList.lock()); /* generate or find the kstfile */ KstDataSourceList::Iterator it = KST::dataSourceList.findFileName(FileName->url()); if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(FileName->url()); if (!file || !file->isValid()) { KMessageBox::sorry(0L, i18n("The file could not be loaded.")); return; } if (file->frameCount() < 1) { KMessageBox::sorry(0L, i18n("The file does not contain data.")); return; } KST::dataSourceList.append(file); } else { file = *it; } KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); x_is_new = true; /**** Build the XVector ***/ /* make sure there are no vectors with the current vectors props */ for (i_v = 0; unsigned(i_v) < rvl.count(); i_v++) { trv = rvl[i_v]; if ((trv->filename() == FileName->url()) && (trv->getField() == Field->text()) && (trv->reqStartFrame() == F0->value()) && (trv->reqNumFrames() == N->value()) && (trv->skip() == Skip->value()) && (trv->doSkip() == DoSkip->isChecked()) && (trv->doAve() == DoFilter->isChecked()) && (trv->readToEOF() == ReadToEnd->isChecked()) && (trv->countFromEOF() == CountFromEnd->isChecked())) { x_is_new = false; i_v = rvl.count(); vx = trv; } } if (x_is_new) { KST::vectorList.lock().readLock(); /* If not, Generate a unique vector name */ v_name = "V" + QString::number(KST::vectorList.count()+1)+"-" + Field->text(); while (KST::vectorList.findTag(v_name) != KST::vectorList.end()) { v_name += "'"; } KST::vectorList.lock().readUnlock(); KST::dataObjectList.lock().readLock(); while (KST::dataObjectList.findTag(v_name) != KST::dataObjectList.end()) { v_name += "'"; } KST::dataObjectList.lock().readUnlock(); if (!file->isValidField(Field->text())) { KMessageBox::sorry(0L, i18n("The requested field is not defined for the requested file.")); return; } /* generate and append the vector */ trv = new KstRVector(file, Field->text(), v_name, (CountFromEnd->isChecked() ? -1 : F0->value()), (ReadToEnd->isChecked() ? -1 : N->value()), Skip->value(), DoSkip->isChecked(), DoFilter->isChecked()); KST::addVectorToList(KstVectorPtr(trv)); vx = trv; } } /**** Build the PSD ***/ /* find new_freq */ new_freq = PSDSampRate->text().toDouble(); if (new_freq <= 0) { KMessageBox::sorry(0L, i18n("The sample rate must be greater than 0.")); return; } /* find new_len */ new_len = PSDFFTLen->text().toInt(); if (new_len < 2) { KMessageBox::sorry(0L, i18n("The FFT length must be greater than 2^2.")); return; } /* create the psd curve name */ KST::dataObjectList.lock().writeLock(); c_name = "PSD"+QString::number(KST::dataObjectList.count()+1) + "-" + vx->tagName(); while (KST::dataObjectList.findTag(c_name) != KST::dataObjectList.end()) { c_name+="'"; } KST::vectorList.lock().readLock(); while (KST::vectorList.findTag(c_name) != KST::vectorList.end()) { c_name+="'"; } KST::vectorList.lock().readUnlock(); /* create the psd curve */ curve = new KstPSDCurve(c_name, vx, new_freq, new_len, PSDVectorUnits->text(), PSDRateUnits->text(), _curveAppearance->color()); curve->setHasPoints(_curveAppearance->showPoints()); curve->setHasLines(_curveAppearance->showLines()); curve->setLineWidth(_curveAppearance->lineWidth()); curve->setLineStyle(_curveAppearance->lineStyle()); curve->Point.setType(_curveAppearance->pointType()); KST::dataObjectList.append(curve.data()); KST::dataObjectList.lock().writeUnlock(); /* assign curve to plot */ plot = KST::plotList.FindKstPlot(PlotList->currentText()); plot->addCurve(curve); if (autolabel) plot->GenerateDefaultLabels(); close(); emit docChanged(); update(); }
bool KstVectorDialogI::editSingleObjectRV(KstVectorPtr vcPtr) { KstRVectorPtr rvp = kst_cast<KstRVector>(vcPtr); KstDataSourcePtr file; if (_fileNameDirty) { // if there is not an active KstFile, create one KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_w->FileName->url()); if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(_w->FileName->url()); if (!file || !file->isValid()) { KST::dataSourceList.lock().unlock(); KMessageBox::sorry(this, i18n("The file could not be opened.")); return false; } if (file->isEmpty()) { KST::dataSourceList.lock().unlock(); KMessageBox::sorry(this, i18n("The file does not contain data.")); return false; } KST::dataSourceList.append(file); } else { file = *it; } KST::dataSourceList.lock().unlock(); } else { KstRVectorList vcList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (uint i = 0; i < _editMultipleWidget->_objectList->count(); i++) { if (_editMultipleWidget->_objectList->isSelected(i)) { // get the pointer to the object KstRVectorList::Iterator vcIter = vcList.findTag(_editMultipleWidget->_objectList->text(i)); if (vcIter == vcList.end()) { return false; } KstRVectorPtr rvp = *vcIter; rvp->readLock(); file = rvp->dataSource(); rvp->unlock(); } } } file->writeLock(); if (rvp) { QString pField; if (_fileNameDirty) { pField = _w->Field->currentText(); if (!file->isValidField(pField)) { KMessageBox::sorry(this, i18n("The requested field is not defined for the requested file.")); file->unlock(); return false; } } else { pField = rvp->field(); } int f0 = 0, n = 0; if (_f0Dirty) { if (_w->_kstDataRange->isStartRelativeTime()) { f0 = file->sampleForTime(_w->_kstDataRange->f0Value()); } else if (_w->_kstDataRange->isStartAbsoluteTime()) { bool ok = false; f0 = file->sampleForTime(_w->_kstDataRange->f0DateTimeValue(), &ok); if (!ok) { file->unlock(); KMessageBox::sorry(this, i18n("The requested field or file could not use the specified date.")); return false; } } else { f0 = int(_w->_kstDataRange->f0Value()); } } if (_nDirty) { if (_w->_kstDataRange->isRangeRelativeTime()) { double nValStored = _w->_kstDataRange->nValue(); if (_w->_kstDataRange->CountFromEnd->isChecked()) { int frameCount = file->frameCount(_w->Field->currentText()); double msCount = file->relativeTimeForSample(frameCount - 1); n = frameCount - 1 - file->sampleForTime(msCount - nValStored); } else { double fTime = file->relativeTimeForSample(f0); n = file->sampleForTime(fTime + nValStored) - file->sampleForTime(fTime); } } else { n = int(_w->_kstDataRange->nValue()); } } // use existing requested start and number of frames if not dirty rvp->readLock(); if (!_f0Dirty) { f0 = rvp->reqStartFrame(); } if (!_nDirty) { n = rvp->reqNumFrames(); } // other parameters for multiple edit bool pCountFromEnd, pReadToEnd, pDoSkip, pDoFilter; int pSkip; if (_countFromEndDirty) { pCountFromEnd = _w->_kstDataRange->CountFromEnd->isChecked(); } else { pCountFromEnd = rvp->countFromEOF(); } if (_readToEndDirty) { pReadToEnd = _w->_kstDataRange->ReadToEnd->isChecked(); } else { pReadToEnd = rvp->readToEOF(); } if (_skipDirty) { pSkip = _w->_kstDataRange->Skip->value(); } else { pSkip = rvp->skip(); } if (_doSkipDirty) { pDoSkip = _w->_kstDataRange->DoSkip->isChecked(); } else { pDoSkip = rvp->doSkip(); } if (_doFilterDirty) { pDoFilter = _w->_kstDataRange->DoFilter->isChecked(); } else { pDoFilter = rvp->doAve(); } rvp->unlock(); // change the vector rvp->writeLock(); rvp->change(file, pField, rvp->tag(), pCountFromEnd ? -1 : f0, pReadToEnd ? -1 : n, pSkip, pDoSkip, pDoFilter); rvp->unlock(); } else { KstSVectorPtr svp = kst_cast<KstSVector>(_dp); if (!svp) { file->unlock(); return true; // shouldn't be needed } double x0 = _w->_xMin->text().toDouble(); double x1 = _w->_xMax->text().toDouble(); int n = _w->_N->value(); svp->writeLock(); svp->changeRange(x0, x1, n); svp->setTagName(KstObjectTag(_tagName->text(), svp->tag().context())); // FIXME: doesn't verify uniqueness, doesn't allow changing tag context svp->unlock(); } file->unlock(); return true; }
bool KstVectorDialogI::newObject() { KstDataSourcePtr file; QString tag_name = _tagName->text(); if (_w->_readFromSource->isChecked()) { tag_name.replace(defaultTag, _w->Field->currentText()); tag_name = KST::suggestVectorName(tag_name); // if there is not an active DataSource, create one { KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_w->FileName->url()); if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(_w->FileName->url()); if (!file || !file->isValid()) { KST::dataSourceList.lock().unlock(); KMessageBox::sorry(this, i18n("The file could not be loaded.")); return false; } if (file->isEmpty()) { KST::dataSourceList.lock().unlock(); KMessageBox::sorry(this, i18n("The file does not contain data.")); return false; } KST::dataSourceList.append(file); } else { file = *it; } KST::dataSourceList.lock().unlock(); } file->readLock(); if (!file->isValidField(_w->Field->currentText())) { file->unlock(); KMessageBox::sorry(this, i18n("The requested field is not defined for the requested file.")); return false; } int f0, n; if (_w->_kstDataRange->isStartRelativeTime()) { f0 = file->sampleForTime(_w->_kstDataRange->f0Value()); } else if (_w->_kstDataRange->isStartAbsoluteTime()) { bool ok = false; f0 = file->sampleForTime(_w->_kstDataRange->f0DateTimeValue(), &ok); if (!ok) { file->unlock(); KMessageBox::sorry(this, i18n("The requested field or file could not use the specified date.")); return false; } } else { f0 = int(_w->_kstDataRange->f0Value()); } if (_w->_kstDataRange->isRangeRelativeTime()) { double nValStored = _w->_kstDataRange->nValue(); if (_w->_kstDataRange->CountFromEnd->isChecked()) { int frameCount = file->frameCount(_w->Field->currentText()); double msCount = file->relativeTimeForSample(frameCount - 1); n = frameCount - 1 - file->sampleForTime(msCount - nValStored); } else { double fTime = file->relativeTimeForSample(f0); n = file->sampleForTime(fTime + nValStored) - file->sampleForTime(fTime); } } else { n = int(_w->_kstDataRange->nValue()); } file->unlock(); // create the vector KstRVectorPtr vector = new KstRVector( file, _w->Field->currentText(), KstObjectTag(tag_name, file->tag(), false), _w->_kstDataRange->CountFromEnd->isChecked() ? -1 : f0, _w->_kstDataRange->ReadToEnd->isChecked() ? -1 : n, _w->_kstDataRange->Skip->value(), _w->_kstDataRange->DoSkip->isChecked(), _w->_kstDataRange->DoFilter->isChecked()); emit vectorCreated(KstVectorPtr(vector)); vector = 0L; emit modified(); } else { double x0 = _w->_xMin->text().toDouble(); double x1 = _w->_xMax->text().toDouble(); int n = _w->_N->value(); QString tagname = _tagName->text(); if (tagname == defaultTag) { tagname = KST::suggestVectorName(QString("(%1..%2)").arg(x0).arg(x1)); } KstSVectorPtr svector = new KstSVector(x0, x1, n, KstObjectTag(tagname, KstObjectTag::globalTagContext)); emit vectorCreated(KstVectorPtr(svector)); svector = 0L; emit modified(); } return true; }
int main(int argc, char *argv[]) { int i_file, i_v, i_curve; int i_plot; KAboutData aboutData( "kst", I18N_NOOP("Kst"), "0.95-devel", description, KAboutData::License_GPL, I18N_NOOP("(c) 2000-2003 Barth Netterfield"), 0, "http://extragear.kde.org/apps/kst.php"); aboutData.addAuthor("Barth Netterfield", I18N_NOOP("Original author and maintainer."), "*****@*****.**", "http://omega.astro.utoronto.ca/"); aboutData.addAuthor("Staikos Computing Services Inc.", I18N_NOOP("Developed for the University of Toronto."), "*****@*****.**", "http://www.staikos.net/"); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; KImageIO::registerFormats(); if (app.isRestored()) { RESTORE(KstApp) } else { KstApp *kst = new KstApp; struct InType in; QColor color; QCStringList ycolList; QCStringList yEqList; QCStringList psdList; QCStringList hsList; QCStringList errorList; unsigned int i_ycol; QCStringList::Iterator psd; QCStringList::Iterator hs; QCStringList::Iterator eq_i; bool nOK; /* temp variables: these all get stuck into list objects */ KstDataSourcePtr file; KstRVector *xvector=NULL; KstRVector *yvector; KstRVector *evector; KstVCurve *curve; KstPSDCurve *psdcurve; KstEquationCurve *eqcurve; KstHistogram *hscurve; KstPlot *plot; int n_y, n_eq=0; /* Parse command line args */ KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); CheckForCMDErrors(args); // Initialise the plugin loader and collection. PluginCollection::self(); /* get Y axis collums */ ycolList = args->getOptionList("y"); yEqList = args->getOptionList("ye"); psdList = args->getOptionList("p"); hsList = args->getOptionList("h"); errorList = args->getOptionList("e"); // y axis or PSD specified, so the files are data files, not kst files. n_y = ycolList.count() + psdList.count() + hsList.count() + yEqList.count(); if (n_y > 0) { SetCMDOptions(args, in, n_y); CreatePlots(in); i_plot = 0; plot = KST::plotList.at(i_plot); /* make stand alone equations if there are no files */ if (args->count()<1) { if (!yEqList.isEmpty()) { QString eqS; double max, min; int n; bool xeq; SetEqXRanges(args->getOption("xe"), &min, &max, &n, &xeq); if (xeq) { for (eq_i = yEqList.begin(); eq_i != yEqList.end(); ++eq_i) { eqS = *eq_i; if (NoVectorEq(eqS)) { eqcurve = new KstEquationCurve(QString("E")+QString::number(n_eq+1)+ "-" + eqS, eqS, min,max,n, KstColorSequence::next()); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eqcurve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(eqcurve); if (in.sep_plots) { i_plot++; if (i_plot <in.n_plots) plot = KST::plotList.at(i_plot); } } } } } } /* Make the requested curves for each data file */ for (i_curve = i_v = 0, i_file = 0; i_file < args->count(); i_file++) { /* Make the file */ file = KstDataSource::loadSource(args->arg(i_file)); if (!file) { kdWarning() << I18N_NOOP("Error: No data in file: ") << args->arg(i_file) << endl; delete kst; exit(0); } if (!file->isValid() || file->frameCount() < 1) { kdWarning() << I18N_NOOP("Error: No data in file: ") << args->arg(i_file) << endl; // The file might get data later! } KST::dataObjectList.lock().writeLock(); KST::dataSourceList.append(file); KST::dataObjectList.lock().writeUnlock(); if (!ycolList.isEmpty()) { // if there are some xy plots /* make the x axis vector */ xvector = GetOrCreateVector(args->getOption("x"), file, in); /* make the y axis vectors */ for (i_ycol = 0; i_ycol < ycolList.count(); ++i_ycol ) { yvector = GetOrCreateVector(*(ycolList.at(i_ycol)), file, in); /* make the curves */ color = KstColorSequence::next(); curve = new KstVCurve(QString("C") + QString::number(1+i_curve++) + "-" + yvector->getField(), KstVectorPtr(xvector), KstVectorPtr(yvector), 0L, 0L, color); if (in.has_points) { curve->setHasPoints(true); curve->setHasLines(false); } if (i_ycol<errorList.count()) { evector = GetOrCreateVector(*(errorList.at(i_ycol)), file, in); curve->setYError(KstVectorPtr(evector)); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(curve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(curve); if (in.sep_plots) { i_plot++; if (i_plot < in.n_plots) plot = KST::plotList.at(i_plot); } // end (if they are separate plots) } // next y col } // end (if there are some xy plots) if (!yEqList.isEmpty()) { QString eqS; double max, min; int n; bool xeq, eq_ok; SetEqXRanges(args->getOption("xe"), &min, &max, &n, &xeq); for (eq_i = yEqList.begin(); eq_i != yEqList.end(); ++eq_i) { eqS = *eq_i; ProcessEq(eqS, file, in, &eq_ok); if (xeq) { eqcurve = new KstEquationCurve(QString("E")+QString::number(n_eq+1)+ "-" + eqS, eqS, min,max,n, KstColorSequence::next()); } else { if (xvector==NULL) xvector = GetOrCreateVector(args->getOption("x"), file, in); eqcurve = new KstEquationCurve(QString("E")+QString::number(n_eq+1)+eqS, eqS, KstVectorPtr(xvector), true, KstColorSequence::next()); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eqcurve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(eqcurve); if (in.sep_plots) { i_plot++; if (i_plot <in.n_plots) plot = KST::plotList.at(i_plot); } } } if (psdList.count() > 0) { // if there are some psd plots KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for(psd = psdList.begin(); psd != psdList.end(); ++psd ) { yvector = GetOrCreateVector(*psd, file, in); color = KstColorSequence::next(); psdcurve = new KstPSDCurve(QString("P") + QString::number(1+i_curve++) + "-" + yvector->getField(), KstVectorPtr(yvector), in.rate, in.len, in.VUnits,in.RUnits, color); if (in.has_points) { psdcurve->setHasPoints(true); psdcurve->setHasLines(false); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(psdcurve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(psdcurve); if (in.sep_plots) { i_plot++; if (i_plot <in.n_plots) plot = KST::plotList.at(i_plot); } } // next psd } // end (if there are some psds) if (hsList.count()>0) { // if there are some histograms double max, min; int N; KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (hs = hsList.begin(); hs != hsList.end(); ++hs ) { yvector = GetOrCreateVector(*hs, file, in); color = KstColorSequence::next(); KstHistogram::AutoBin(KstVectorPtr(yvector), &N, &max, &min); hscurve = new KstHistogram(QString("H") + QString::number(1+i_curve++) + "-" + yvector->getField(), KstVectorPtr(yvector), min, max, N, KST_HS_NUMBER, color); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(KstDataObjectPtr(hscurve)); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(hscurve); if (in.sep_plots) { i_plot++; if (i_plot < in.n_plots) plot = KST::plotList.at(i_plot); } } // next histogram } // end (if there are some histograms) } // next data file for (i_plot = 0; i_plot < in.n_plots; i_plot++) { KST::plotList.at(i_plot)->GenerateDefaultLabels(); } KST::plotList.setPlotCols(in.n_cols); } else if (args->count() > 0) { /* open a kst file */ /* some of the options can be overridden */ kst->openDocumentFile(args->arg(0), args->getOption("F"), // override FileName // override number of frames args->getOption("n").toInt(&nOK), // override starting frame args->getOption("f").toInt(&nOK), // override skip args->getOption("s").toInt(&nOK), // add averaging args->isSet("a")); } else { //kst->openDocumentFile(); } QString printfile; printfile = args->getOption("print"); QString pngfile; pngfile = args->getOption("png"); bool print_and_exit = false; if (printfile!="<none>") { args->clear(); kst->forceUpdate(); kst->immediatePrintToFile(printfile); print_and_exit = true; } if (pngfile!="<none>") { args->clear(); kst->forceUpdate(); kst->immediatePrintToPng(pngfile); print_and_exit = true; } if (print_and_exit) { delete kst; exit(0); } else { args->clear(); app.setMainWidget(kst); kst->show(); } // LEAVE THIS HERE - causes crashes otherwise! int rc = app.exec(); delete kst; return rc; } return app.exec(); }
int main(int argc, char *argv[]) { KInstance inst("d2asc"); KstDataSourcePtr file; int i; char field_list[40][120], filename[180]; bool do_hex[40]; int n_field=0; int start_frame=0, n_frames=2000000; bool do_ave = false, do_skip = false; int n_skip = 0; int NS=0, i_S; if (argc < 3 || argv[1][0] == '-') Usage(); for (i = 0; i < 40; i++) do_hex[i] = false; strcpy(filename, argv[1]); for (i = 2; i < argc; i++) { if (argv[i][0] == '-') { if (argv[i][1] == 'f') { i++; start_frame = atoi(argv[i]); } else if (argv[i][1] == 'n') { i++; n_frames = atoi(argv[i]); } else if (argv[i][1] == 's') { i++; n_skip = atoi(argv[i]); if (n_skip>0) do_skip = true; } else if (argv[i][1] == 'a') { do_ave = true; } else if (argv[i][1] == 'x') { i++; strcpy(field_list[n_field], argv[i]); do_hex[n_field] = true; n_field++; } else { Usage(); } } else { strcpy(field_list[n_field], argv[i]); n_field++; } } if (!do_skip) do_ave = false; file = KstDataSource::loadSource(filename); if (!file || !file->isValid() || file->frameCount() < 1) { fprintf(stderr, "d2asc error: file %s has no data\n", filename); exit(0); } /** make vectors and fill the list **/ QPtrList<KstRVector> vlist; vlist.setAutoDelete(true); for (i=0; i<n_field; i++) { if (!file->isValidField(field_list[i])) { fprintf(stderr, "d2asc error: field %s in file %s is not valid\n", field_list[i], filename); exit(0); } vlist.append(new KstRVector(file, field_list[i], "tag", start_frame, n_frames, n_skip, n_skip>0, do_ave)); } /* find NS */ for (i = 0; i < n_field; i++) { while (vlist.at(i)->update(-1) != KstObject::NO_CHANGE) ; // read vector if (vlist.at(i)->sampleCount() > NS) NS = vlist.at(i)->sampleCount(); } for (i_S = 0; i_S < NS; i_S++) { for (i = 0; i < n_field; i++) { if (do_hex[i]) { printf("%4x ", (int)vlist.at(i)->interpolate(i_S, NS)); } else { printf("%.12g ", vlist.at(i)->interpolate(i_S, NS)); } } printf("\n"); } }