Beispiel #1
0
void KstImageDialogI::fillFieldsForEdit() {
  fillFieldsForEditNoUpdate();

  KstImagePtr ip = kst_cast<KstImage>(_dp);
  if (!ip) {
    return; // shouldn't be needed
  }
  ip->readLock();
  
  // set the type of image
  _w->_colorOnly->setChecked(ip->hasColorMap() && !ip->hasContourMap());
  _w->_contourOnly->setChecked(ip->hasContourMap() && !ip->hasColorMap());
  _w->_colorAndContour->setChecked(ip->hasColorMap() && ip->hasContourMap());

  // set the matrix
  _w->_matrix->setSelection(ip->matrixTag());

  ip->unlock();

  //update the groups and enables
  // won't call fillFieldsForEditNoUpdate again because
  // fillFieldsForEdit is not called in _editMultipleMode
  updateGroups();
  adjustSize();
  resize(minimumSizeHint());
  setFixedHeight(height());
}
Beispiel #2
0
void KstBindImage::setMatrix(KJS::ExecState *exec, const KJS::Value& value) {
  KstMatrixPtr mp = extractMatrix(exec, value);
  if (mp) {
    KstImagePtr d = makeImage(_d);
    if (d) {
      KstWriteLocker wl(d);
      d->setMatrix(mp);
    }
  }
}
Beispiel #3
0
/* returns true if succesful */
bool KstCsdDialogI::newObject() {
    QString tag_name = _tagName->text();
    if (tag_name == defaultTag) {
        tag_name = KST::suggestCSDName(_w->_vector->selectedVector());
    }

    // verify that the curve name is unique
    if (KstData::self()->dataTagNameNotUnique(tag_name)) {
        _tagName->setFocus();
        return false;
    }

    if (_w->_vector->selectedVector().isEmpty()) {
        KMessageBox::sorry(this, i18n("New CSD not made: define vectors first."));
        return false;
    }

    KST::vectorList.lock().readLock();
    KstVectorPtr p = *KST::vectorList.findTag(_w->_vector->selectedVector());
    KST::vectorList.lock().unlock();
    if (!p) {
        kstdFatal() << "Bug in kst: the vector field in CSD dialog refers to "
                    << "a non existant vector...." << endl;
    }

    ApodizeFunction apodizeFxn = ApodizeFunction(_w->_kstFFTOptions->ApodizeFxn->currentItem());
    bool apodize = _w->_kstFFTOptions->Apodize->isChecked();
    double gaussianSigma = _w->_kstFFTOptions->Sigma->value();
    bool removeMean = _w->_kstFFTOptions->RemoveMean->isChecked();
    bool average = _w->_kstFFTOptions->Interleaved->isChecked();
    int windowSize = _w->_windowSize->value();
    int length = _w->_kstFFTOptions->FFTLen->value();
    double freq = _w->_kstFFTOptions->SampRate->text().toDouble();
    PSDType output = PSDType(_w->_kstFFTOptions->Output->currentItem());
    QString vectorUnits = _w->_kstFFTOptions->VectorUnits->text();
    QString rateUnits = _w->_kstFFTOptions->RateUnits->text();
    _w->_kstFFTOptions->synch();

    KstCSDPtr csd = new KstCSD(tag_name, p, freq, average, removeMean,
                               apodize, apodizeFxn, windowSize, length, gaussianSigma, output,
                               vectorUnits, rateUnits);
    //csd->setInterpolateHoles(_w->_kstFFTOptions->InterpolateHoles->isChecked());

    KstImagePtr image = createImage(csd);

    KST::dataObjectList.lock().writeLock();
    KST::dataObjectList.append(csd.data());
    KST::dataObjectList.append(image.data());
    KST::dataObjectList.lock().unlock();

    csd = 0L;
    emit modified();
    return true;
}
Beispiel #4
0
KJS::Value KstBindImage::matrix(KJS::ExecState *exec) const {
  KstImagePtr d = makeImage(_d);
  if (d) {
    KstReadLocker rl(d);
    KstMatrixPtr mp = d->matrix();
    if (mp) {
      return KJS::Object(new KstBindMatrix(exec, mp));
    }
  }
  return KJS::Null();
}
Beispiel #5
0
KJS::Value KstBindImage::minMaxThreshold(KJS::ExecState *exec, const KJS::List& args) {
  Q_UNUSED(args)

  KstImagePtr d = makeImage(_d);
  if (!d) {
    return createInternalError(exec);
  }

  if (args.size() != 0) {
    return createSyntaxError(exec);
  }

  KstReadLocker rl(d);

  d->setThresholdToMinMax();
  return KJS::Undefined();
}
Beispiel #6
0
void KstBindImage::setMap(KJS::ExecState *exec, const KJS::Value& value) {
  unsigned i = 0;

  if (value.type() != KJS::NumberType || !value.toUInt32(i)) {
    return createPropertyTypeError(exec);
  }

  if (i > 2) {
    return createPropertyRangeError(exec);
  }

  KstImagePtr d = makeImage(_d);
  if (d) {
    KstWriteLocker wl(d);
    switch (i) {
      case 0:
        d->setHasContourMap(false);
        d->setHasColorMap(true);
        break;
      case 1:
        d->setHasContourMap(true);
        d->setHasColorMap(false);
        break;
      case 2:
        d->setHasContourMap(true);
        d->setHasColorMap(true);
        break;
    }
  }
}
Beispiel #7
0
KJS::Object KstBindImage::construct(KJS::ExecState *exec, const KJS::List& args) {
  KstMatrixPtr matrix;

  if (args.size() > 0) {
    matrix = extractMatrix(exec, args[0]);
    if (!matrix) {
      return createTypeError(exec, 0);
    }
  }

  KstImagePtr image = new KstImage(QString::null, matrix, 10, QColor(0,0,0), 1);

  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(image.data());
  KST::dataObjectList.lock().unlock();

  return KJS::Object(new KstBindImage(exec, image));
}
Beispiel #8
0
KJS::Value KstBindImage::smartThreshold(KJS::ExecState *exec, const KJS::List& args) {
  KstImagePtr d = makeImage(_d);
  if (!d) {
    return createInternalError(exec);
  }

  if (args.size() != 1) {
    return createSyntaxError(exec);
  }

  if (args[0].type() != KJS::NumberType) {
    return createTypeError(exec, 0);
  }

  double per = args[0].toNumber(exec);
  KstReadLocker rl(d);

  d->setThresholdToSpikeInsensitive(per);
  return KJS::Undefined();
}
Beispiel #9
0
bool KstImageDialogI::editObject() {
  KstImageList imList = kstObjectSubList<KstDataObject,KstImage>(KST::dataObjectList);
  
  // if editing multiple objects, edit each one
  if (_editMultipleMode) {
    _numContourLinesDirty = _w->_numContourLines->text() != " ";
    _contourWeightDirty = _w->_contourWeight->text() != " ";
    _paletteDirty = _w->_colorPalette->currentPaletteIndex() != 0;
    _matrixDirty = _w->_matrix->_matrix->currentItem() != 0;
    _lowerZDirty = !_w->_lowerZ->text().isEmpty();
    _upperZDirty = !_w->_upperZ->text().isEmpty();

    bool didEdit = false;
    for (uint i = 0; i < _editMultipleWidget->_objectList->count(); ++i) {
      if (_editMultipleWidget->_objectList->isSelected(i)) {
        // get the pointer to the object
        KstImageList::Iterator imIter = imList.findTag(_editMultipleWidget->_objectList->text(i));
        if (imIter == imList.end()) {
          return false;
        }

        KstImagePtr imPtr = *imIter;

        if (!editSingleObject(imPtr)) {
          return false;
        }
        didEdit = true;
      }
    }

    if (!didEdit) {
      KMessageBox::sorry(this, i18n("Select one or more objects to edit."));
      return false;
    }
  } else {
    KstImagePtr ip = kst_cast<KstImage>(_dp);
    // verify that the curve name is unique
    QString tag_name = _tagName->text();
    if (!ip || (tag_name != ip->tagName() && KstData::self()->dataTagNameNotUnique(tag_name))) {
      _tagName->setFocus();
      return false;
    }

    ip->writeLock();
    ip->setTagName(KstObjectTag(tag_name, ip->tag().context())); // FIXME: doesn't allow changing tag context
    ip->unlock();

    // then edit the object
    _colorOnlyDirty = true;
    _contourOnlyDirty = true;
    _colorAndContourDirty = true;
    _paletteDirty = true;
    _lowerZDirty = true;
    _upperZDirty = true;
    _realTimeAutoThresholdDirty = true;
    _numContourLinesDirty = true;
    _contourWeightDirty = true;
    _useVariableWeightDirty = true;
    _contourColorDirty = true;
    if (!editSingleObject(ip)) {
      return false;
    }
  }
  emit modified();
  return true;
}
Beispiel #10
0
bool KstImageDialogI::editSingleObject(KstImagePtr imPtr) {
  KstMatrixPtr pMatrix;
  if (_matrixDirty) {
    //find the pMatrix
    KST::matrixList.lock().readLock();
    pMatrix = *KST::matrixList.findTag(_w->_matrix->selectedMatrix());
    KST::matrixList.lock().unlock();

    if (!pMatrix) {
      KMessageBox::sorry(this, i18n("Matrix is a 2D grid of numbers, used to create image", "Could not find pMatrix."));
      return false;
    }
  } else {
    imPtr->readLock();
    pMatrix = imPtr->matrix();
    imPtr->unlock();
  }

  imPtr->writeLock();

  // if image type was changed, get all parameters from the dialog
  if (_contourOnlyDirty || _colorOnlyDirty || _colorAndContourDirty) {
    double lowerZDouble, upperZDouble;
    if (!checkParameters(lowerZDouble, upperZDouble)) {
      //KMessageBox::sorry(this, i18n("Image type was changed: Lower Z threshold cannot be higher than Upper Z threshold."));
      //pMatrix->unlock();
      imPtr->unlock();
      return false;
    }
    if (_w->_contourOnly->isChecked()) {
      //need a contour map only
      QColor tempColor = _w->_contourColor->color();
      imPtr->changeToContourOnly(imPtr->tagName(), pMatrix, _w->_numContourLines->text().toInt(), tempColor,
                              _w->_useVariableWeight->isChecked() ? -1 : _w->_contourWeight->value());
    } else if (_w->_colorOnly->isChecked()) {
      //need a color map only
      KPalette* newPal = new KPalette(_w->_colorPalette->selectedPalette());
      imPtr->changeToColorOnly(imPtr->tagName(), pMatrix, lowerZDouble, upperZDouble,
                            _w->_realTimeAutoThreshold->isChecked(), newPal);
    } else {
      //need both a contour map and colour map
      QColor tempColor = _w->_contourColor->color();
      KPalette* newPal = new KPalette(_w->_colorPalette->selectedPalette());
      imPtr->changeToColorAndContour(imPtr->tagName(), pMatrix, lowerZDouble, upperZDouble,
                                  _w->_realTimeAutoThreshold->isChecked(), newPal,
                                  _w->_numContourLines->text().toInt(), tempColor,
                                  _w->_useVariableWeight->isChecked() ? -1 : _w->_contourWeight->value());
    }
  } else {
    // get the current or new parameters as required
    QColor pContourColor;
    double pLowerZ, pUpperZ;
    int pNumContours, pContourWeight;
    bool pRealTimeAutoThreshold, pUseVariableWeight;

    if (_lowerZDirty) {
      pLowerZ = _w->_lowerZ->text().toDouble();
    } else {
      pLowerZ = imPtr->lowerThreshold();
    }

    if (_upperZDirty) {
      pUpperZ = _w->_upperZ->text().toDouble();
    } else {
      pUpperZ = imPtr->upperThreshold();
    }

    if (_realTimeAutoThresholdDirty) {
      pRealTimeAutoThreshold = _w->_realTimeAutoThreshold->isChecked();
    } else {
      pRealTimeAutoThreshold = imPtr->autoThreshold();
    }

    if (_numContourLinesDirty) {
      pNumContours = _w->_numContourLines->text().toInt();
    } else {
      pNumContours = imPtr->numContourLines();
    }

    if (_contourWeightDirty) {
      pContourWeight = _w->_contourWeight->value();
    } else {
      pContourWeight = imPtr->contourWeight();
    }

    if (_useVariableWeightDirty) {
      pUseVariableWeight = _w->_useVariableWeight->isChecked();
    } else {
      pUseVariableWeight = imPtr->contourWeight() == -1;
    }

    if (_contourColorDirty) {
      pContourColor = _w->_contourColor->color();
    } else {
      pContourColor = imPtr->contourColor();
    }

    // check parameters for color map
    if (imPtr->hasColorMap()) {
      if (pLowerZ > pUpperZ) {
        //KMessageBox::sorry(this, i18n("The Lower Z threshold cannot be higher than Upper Z threshold."));
        //pMatrix->unlock();
        imPtr->unlock();
        return false;
      }
    }

    // don't change the image type, just change applicable settings for the
    // current image type
    if (imPtr->hasContourMap() && !imPtr->hasColorMap()) {
      imPtr->changeToContourOnly(imPtr->tagName(), pMatrix, pNumContours, pContourColor,
          pUseVariableWeight ? -1 : pContourWeight);
    } else {
      KPalette *palette;
      if (_paletteDirty) {
        palette = new KPalette(_w->_colorPalette->selectedPalette());
      } else {
        palette = imPtr->palette();
      }

      if (imPtr->hasColorMap() && !imPtr->hasContourMap()) {
        imPtr->changeToColorOnly(imPtr->tagName(), pMatrix, pLowerZ, pUpperZ,
            pRealTimeAutoThreshold, palette);
      } else {
        // images always have at least one of color or contour maps
        imPtr->changeToColorAndContour(imPtr->tagName(), pMatrix, pLowerZ, pUpperZ,
            pRealTimeAutoThreshold, palette,
            pNumContours, pContourColor,
            pUseVariableWeight ? -1 : pContourWeight);
      }
    }
  }


  imPtr->unlock();

  return true;
}
Beispiel #11
0
bool KstImageDialogI::newObject() {
  //if matrixCombo is empty then display an error message
  if (_w->_matrix->selectedMatrix().isEmpty()){
    KMessageBox::sorry(this, i18n("Matrix is a 2D grid of numbers, used to create image", "New image not made: define matrix first."));
    return false;
  }

  //do some checks on the inputs
  double lowerZDouble, upperZDouble;
  if (!checkParameters(lowerZDouble, upperZDouble)) {
    return false;
  }

  KST::matrixList.lock().readLock();
  KstMatrixPtr matrix = *KST::matrixList.findTag(_w->_matrix->selectedMatrix());
  KST::matrixList.lock().unlock();
  if (!matrix) {
    KMessageBox::sorry(this, i18n("Matrix is a 2D grid of numbers, used to create image", "Could not find matrix."));
    return false;
  }
  KST::dataObjectList.lock().readLock();
  matrix->readLock();

  //create a unique name
  QString tag_name = KST::suggestImageName(matrix->tag());
  if (KstData::self()->dataTagNameNotUnique(tag_name)) {
    _tagName->setFocus();
    matrix->unlock();
    KST::dataObjectList.lock().unlock();
    return false;
  }

  KstImagePtr image;
  if (_w->_contourOnly->isChecked()) {
    //need a contour map only
    QColor tempColor = _w->_contourColor->color();
    image = new KstImage(tag_name, matrix, _w->_numContourLines->text().toInt(), tempColor,
                         _w->_useVariableWeight->isChecked() ? -1 : _w->_contourWeight->value());
  } else if (_w->_colorOnly->isChecked()) {
    //need a color map only
    KPalette* newPal = new KPalette(_w->_colorPalette->selectedPalette());
    image = new KstImage(tag_name, matrix, lowerZDouble, upperZDouble,
                         _w->_realTimeAutoThreshold->isChecked(), newPal);
  } else {
    //need both a contour map and colour map
    QColor tempColor = _w->_contourColor->color();
    KPalette* newPal = new KPalette(_w->_colorPalette->selectedPalette());
    image = new KstImage(tag_name, matrix, lowerZDouble, upperZDouble,
                         _w->_realTimeAutoThreshold->isChecked(), newPal,
                         _w->_numContourLines->text().toInt(), tempColor,
                         _w->_useVariableWeight->isChecked() ? -1 : _w->_contourWeight->value());
  }
  matrix->unlock();
  KST::dataObjectList.lock().unlock();
  placeInPlot(image);
  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(image.data());
  KST::dataObjectList.lock().unlock();
  image = 0L; // drop the reference
  emit modified();
  return true;
}
Beispiel #12
0
void KstImageDialogI::fillFieldsForEditNoUpdate() {
  KstImagePtr ip = kst_cast<KstImage>(_dp);
  if (!ip) {
    return; // shouldn't be needed
  }

  KstImageList images = kstObjectSubList<KstDataObject, KstImage>(KST::dataObjectList);

  ip->readLock();
  // fill in the tag name
  _tagName->setText(ip->tagName());

  // fill in the other parameters
  _w->_lowerZ->setText(QString::number(ip->lowerThreshold()));
  _w->_upperZ->setText(QString::number(ip->upperThreshold()));
  _w->_realTimeAutoThreshold->setChecked(ip->autoThreshold());

  _w->_colorPalette->refresh(ip->paletteName());
  _w->_numContourLines->setValue(ip->numContourLines());
  _w->_contourColor->setColor(ip->contourColor());
  int tempWeight = ip->contourWeight();
  _w->_useVariableWeight->setChecked(tempWeight == -1);
  if (tempWeight >= 0) {
    _w->_contourWeight->setValue(tempWeight);
  }

  ip->unlock();

  //don't place the image in edits
  _w->_curvePlacement->hide();

  updateEnables();
}
Beispiel #13
0
KstBindImage::KstBindImage(KJS::ExecState *exec, KstImagePtr d)
: KstBindDataObject(exec, d.data(), "Image") {
  KJS::Object o(this);
  addBindings(exec, o);
}
int main(int argc, char *argv[]) {
    int i_file, i_v, i_curve;
    int i_plot;
    QString fullPath;

    KAboutData aboutData("kst", I18N_NOOP("Kst"),
                         KSTVERSION, description, KAboutData::License_GPL,
                         I18N_NOOP("(c) 2000-2007 Barth Netterfield"),
                         0,
                         "http://kst.kde.org/");
    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/");
    aboutData.addAuthor("Sumus Technology Limited",
                        I18N_NOOP("Developed for the University of British Columbia"),
                        "*****@*****.**",
                        "http://www.sumusltd.com/");
    aboutData.addAuthor("Rick Chern",
                        I18N_NOOP("University of British Columbia"),
                        "",
                        "");
    aboutData.addAuthor("Duncan Hanson",
                        I18N_NOOP("University of British Columbia"),
                        "",
                        "");
    aboutData.addAuthor("Nicolas Brisset",
                        "",
                        "",
                        "");
    aboutData.addAuthor("Matthew Truch",
                        "",
                        "http://matt.truch.net/",
                        "*****@*****.**");
    aboutData.addAuthor("Theodore Kisner",
                        "",
                        "*****@*****.**",
                        "");
    aboutData.setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"),
                            I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails"));

    KCmdLineArgs::init( argc, argv, &aboutData );
    KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.

    KApplication app;
    KImageIO::registerFormats();

    KstDialogs::replaceSelf(new KstGuiDialogs);
    KstData::replaceSelf(new KstGuiData);
    KstApp::initialize();

    atexit(exitHelper);

    if (app.isRestored()) {
        RESTORE(KstApp)
    } else {
        KstApp *kst = new KstApp;
        InType in;
        QColor color;
        QCStringList ycolList;
        QCStringList matrixList;
        QCStringList yEqList;
        QCStringList psdList;
        QCStringList hsList;
        QCStringList errorList;
        unsigned int i_ycol;
        QCStringList::Iterator hs_string;
        QCStringList::Iterator eq_i;
        QCStringList::Iterator mat_i;
        bool showQuickStart = false;
        bool showDataWizard = false;
        bool nOK;
        int n_y = 0;
        KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

        CheckForCMDErrors(args);

        QString wizardfile = args->getOption("w");
        QString printfile = args->getOption("print");
        QString pngfile = args->getOption("png");
        bool print_and_exit = false;

        if (printfile != "<none>") {
            print_and_exit = true;
        }
        if (pngfile != "<none>") {
            print_and_exit = true;
        }

        if (!print_and_exit) {
            app.setMainWidget(kst);
            QRect rect = KGlobalSettings::desktopGeometry(kst);
            kst->resize(5 * rect.width() / 6, 5 * rect.height() / 6);
            kst->show();
        }

        // get Y axis columns
        ycolList = args->getOptionList("y");
        matrixList = args->getOptionList("z");
        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() + matrixList.count();
        if (n_y > 0) {
            QString creatingEquations = i18n("Creating equations");
            QString creatingCurves = i18n("Creating curves");
            QString creatingPlots = i18n("Creating plots");
            int count;
            int handled;

            kst->slotUpdateProgress( 0, 0, QString::null );

            SetCMDOptions(args, in, n_y);

            KstTopLevelViewPtr tlv = kst->activeView();

            if (!tlv) {
                // if there was no active view then we create one...
                kst->newWindow(false);
                tlv = kst->activeView();
            }

            if (!tlv) {
                kstdError() << i18n("Can't create a view.") << endl;
                return 0;
            }

            CreatePlots(in, tlv);
            Kst2DPlotList plist = kstObjectSubList<KstViewObject, Kst2DPlot>(tlv->children());

            i_plot = 0;
            Kst2DPlotPtr plot = *plist.at(i_plot);

            KstVCurveList vcurves = kstObjectSubList<KstBaseCurve,KstVCurve>(plot->Curves);

            // 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) {
                        count = yEqList.size();
                        handled = 0;
                        kst->slotUpdateProgress( count, handled, creatingEquations );

                        for (eq_i = yEqList.begin(); eq_i != yEqList.end(); ++eq_i) {
                            eqS = *eq_i;
                            if (NoVectorEq(eqS)) {
                                KstEquationPtr eq = new KstEquation(KST::suggestEQName(eqS), eqS, min, max, n);
                                KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(eq->tag(), true),
                                                                eq->vX(), eq->vY(), 0L, 0L, 0L, 0L,
                                                                KstColorSequence::next(vcurves,plot->backgroundColor()));
                                KST::dataObjectList.lock().writeLock();
                                KST::dataObjectList.append(eq.data());
                                KST::dataObjectList.append(vc.data());
                                KST::dataObjectList.lock().unlock();
                                plot->addCurve(vc.data());

                                if (in.sep_plots) {
                                    i_plot++;
                                    if (i_plot < in.n_plots) {
                                        plot = *plist.at(i_plot);
                                    }
                                }
                            }

                            handled++;
                            kst->slotUpdateProgress( count, handled, creatingEquations );
                        }
                    }
                }
            }

            // make the requested curves for each data file
            count = args->count();
            handled = 0;
            kst->slotUpdateProgress( count, handled, creatingCurves );

            for (i_curve = i_v = 0, i_file = 0; i_file < args->count(); i_file++) {
                // make the file
                if (QFile::exists(args->arg(i_file))) {
                    fullPath = QFileInfo(args->arg(i_file)).absFilePath();
                } else {
                    fullPath = args->arg(i_file);
                }

                KstDataSourcePtr file = KstDataSource::loadSource(fullPath);

                if (file) {
                    if (!file->isValid() || file->isEmpty()) {
                        kstdError() << i18n("No data in file %1.  Trying to continue...").arg(args->arg(i_file)) << endl;
                        // The file might get data later!
                    }

                    KST::dataObjectList.lock().writeLock();
                    KST::dataSourceList.append(file);
                    KST::dataObjectList.lock().unlock();

                    KstRVectorPtr yvector;
                    KstRVectorPtr evector;
                    KstVCurvePtr curve;
                    KstPSDPtr psd;
                    KstHistogramPtr hs;
                    KstRVectorPtr xvector;

                    if (!ycolList.isEmpty()) { // if there are some xy plots
                        // make the x axis vector
                        xvector = GetOrCreateVector(args->getOption("x"), file, in);
                        if (xvector) {
                            // make the y axis vectors
                            for (i_ycol = 0; i_ycol < ycolList.count(); ++i_ycol ) {
                                yvector = GetOrCreateVector(*(ycolList.at(i_ycol)), file, in);
                                if (yvector) {
                                    // make the curves
                                    color = KstColorSequence::next(vcurves,plot->backgroundColor());
                                    curve = new KstVCurve(KST::suggestCurveName(yvector->tag(), false),
                                                          KstVectorPtr(xvector), KstVectorPtr(yvector),
                                                          0L, 0L, 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);
                                        if (evector) {
                                            curve->setYError(KstVectorPtr(evector));
                                            curve->setYMinusError(KstVectorPtr(evector));
                                        }
                                    }

                                    KST::dataObjectList.lock().writeLock();
                                    KST::dataObjectList.append(curve.data());
                                    KST::dataObjectList.lock().unlock();
                                    plot->addCurve(curve.data());

                                    if (in.sep_plots) {
                                        plot->setTagName(curve->tag());
                                        i_plot++;
                                        if (i_plot < in.n_plots) {
                                            plot = *plist.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) {
                            KstEquationPtr eq;

                            eqS = *eq_i;
                            ProcessEq(eqS, file, in, &eq_ok);

                            if (xeq) {
                                eq = new KstEquation(KST::suggestEQName(eqS), eqS, min,max,n);
                            } else {
                                if (!xvector) {
                                    xvector = GetOrCreateVector(args->getOption("x"), file, in);
                                }
                                if (xvector) {
                                    eq = new KstEquation(KST::suggestEQName(eqS), eqS, KstVectorPtr(xvector), true);
                                }
                            }

                            if (eq) {
                                KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(eq->tag(), true),
                                                                eq->vX(), eq->vY(), 0L, 0L, 0L, 0L,
                                                                KstColorSequence::next(vcurves,plot->backgroundColor()));
                                KST::dataObjectList.lock().writeLock();
                                KST::dataObjectList.append(eq.data());
                                KST::dataObjectList.append(vc.data());
                                KST::dataObjectList.lock().unlock();
                                plot->addCurve(vc.data());

                                if (in.sep_plots) {
                                    plot->setTagName(eq->tag());
                                    i_plot++;
                                    if (i_plot <in.n_plots) {
                                        plot = *plist.at(i_plot);
                                    }
                                }
                            }
                        }
                    }

                    if (psdList.count() > 0) { // if there are some psd plots
                        KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
                        for (QCStringList::ConstIterator it = psdList.begin(); it != psdList.end(); ++it) {

                            yvector = GetOrCreateVector(*it, file, in);
                            if (yvector) {
                                color = KstColorSequence::next(vcurves,plot->backgroundColor());

                                psd = new KstPSD( KST::suggestPSDName(yvector->tag()), // FIXME: this was yvector->field(), is this right?
                                                  KstVectorPtr(yvector), in.rate, true, in.len,
                                                  true, true, in.VUnits, in.RUnits, WindowOriginal);
                                KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(psd->tag(), true),
                                                                psd->vX(), psd->vY(), 0L, 0L, 0L, 0L, color);
                                if (in.has_points) {
                                    vc->setHasPoints(true);
                                    vc->setHasLines(false);
                                }
                                KST::dataObjectList.lock().writeLock();
                                KST::dataObjectList.append(psd.data());
                                KST::dataObjectList.append(vc.data());
                                KST::dataObjectList.lock().unlock();
                                plot->addCurve(vc.data());

                                if (in.sep_plots) {
                                    plot->setTagName(psd->tag());
                                    i_plot++;
                                    if (i_plot <in.n_plots) {
                                        plot = *plist.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_string = hsList.begin(); hs_string != hsList.end(); ++hs_string) {
                            yvector = GetOrCreateVector(*hs_string, file, in);
                            if (yvector) {
                                color = KstColorSequence::next(vcurves,plot->backgroundColor());

                                KstHistogram::AutoBin(KstVectorPtr(yvector), &N, &max, &min);

                                hs = new KstHistogram(KST::suggestHistogramName(yvector->tag()),
                                                      KstVectorPtr(yvector), min, max, N, KST_HS_NUMBER);
                                KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(hs->tag(), true),
                                                                hs->vX(), hs->vY(),
                                                                0L, 0L, 0L, 0L, color);

                                vc->setHasPoints(false);
                                vc->setHasLines(false);
                                vc->setHasBars(true);
                                vc->setBarStyle(1);

                                KST::dataObjectList.lock().writeLock();
                                KST::dataObjectList.append(hs.data());
                                KST::dataObjectList.append(vc.data());
                                KST::dataObjectList.lock().unlock();
                                plot->addCurve(vc.data());

                                if (in.sep_plots) {
                                    plot->setTagName(hs->tag());
                                    i_plot++;
                                    if (i_plot < in.n_plots) {
                                        plot = *plist.at(i_plot);
                                    }
                                }
                            }
                        } // next histogram
                    } // end (if there are some histograms)

                    if (matrixList.count() > 0) { // if there are some matrixes
                        for (mat_i = matrixList.begin(); mat_i != matrixList.end(); ++mat_i) {
                            QString tag_name = KST::suggestMatrixName(*mat_i);
                            if (!file->isValidMatrix(*mat_i)) {
                                startupErrors.append(i18n("Failed to create matrix '%1' from file '%2'.").arg(*mat_i).arg(file->fileName()));
                            }
                            KstRMatrixPtr matrix = new KstRMatrix(file, *mat_i,
                                                                  KstObjectTag(tag_name, file->tag()),
                                                                  0,0,-1,-1,false,false,0);
                            // xStart, yStart, xNumSteps, yNumSteps,
                            //doAve, doSkip, skip);

                            // Time to create the image from the matrix
                            tag_name = KST::suggestImageName(matrix->tag());
                            QStringList palList = KPalette::getPaletteList();
                            QString pal;
                            if (palList.contains("IDL 13 RAINBOW")) {
                                pal = QString("IDL 13 RAINBOW");
                            } else {
                                pal = QString(*palList.at(0));
                            }

                            KPalette* newPal = new KPalette(pal);
                            KstImagePtr image = new KstImage(tag_name, KstMatrixPtr(matrix), 0.0, 1.0,
                                                             true, newPal);
                            plot->addCurve(KstBaseCurvePtr(image));
                            KST::dataObjectList.lock().writeLock();
                            KST::dataObjectList.append(image.data());
                            KST::dataObjectList.lock().unlock();
                            image = 0L; // drop the reference

                            if (in.sep_plots) {
                                plot->setTagName(matrix->tag());
                                i_plot++;
                                if (i_plot < in.n_plots) {
                                    plot = *plist.at(i_plot);
                                }
                            }
                        }
                    }
                } else {
                    startupErrors.append(i18n("Failed to load file '%1'.").arg(args->arg(i_file)));
                }
                handled++;
                kst->slotUpdateProgress( count, handled, creatingCurves );
            } // next data file

            count = in.n_plots;
            handled = 0;
            kst->slotUpdateProgress( count, handled, creatingPlots );
            for (i_plot = 0; i_plot < in.n_plots; i_plot++) {
                plot = *plist.at(i_plot);
                plot->generateDefaultLabels();

                // if we have only images in a plot then set the scale mode to AUTO (instead of AUTOBORDER)
                KstImageList images = kstObjectSubList<KstBaseCurve,KstImage>(plot->Curves);
                if (images.count() == plot->Curves.count()) {
                    plot->setXScaleMode(AUTO);
                    plot->setYScaleMode(AUTO);
                }

                if (plot->Curves.count() > 3 || in.dolegend) {
                    KstViewLegendPtr vl = plot->getOrCreateLegend();
                    vl->resizeFromAspect(0.1, 0.1, 0.2, 0.1);
                    vl->setBorderWidth(2);
                }
                handled++;
                kst->slotUpdateProgress( count, handled, creatingPlots );
            }

            kst->slotUpdateProgress( 0, 0, QString::null );
        } 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
                                  args->getOption("n").toInt(&nOK), // override number of frames
                                  args->getOption("f").toInt(&nOK), // override starting frame
                                  args->getOption("s").toInt(&nOK), // override skip
                                  args->isSet("a"),                 // add averaging
                                  !print_and_exit);                 // delayed
        } else {
            //kst->openDocumentFile();
            showQuickStart = true;
        }

        if (args->isSet("nq")) {
            showQuickStart = false;
        }
        if (args->isSet("w")) {
            showDataWizard = true;
            showQuickStart = false;
        }

        if (printfile != "<none>") {
            kst->forceUpdate();
            kst->immediatePrintToFile(printfile, false);
        }

        if (pngfile != "<none>") {
            kst->forceUpdate();
            kst->immediatePrintToPng(pngfile);
        }

        kst->document()->setModified(false);

        if (print_and_exit) {
            delete kst;
            return 0;
        } else {
            kst->updateDialogs();

            if (showQuickStart) {
                kst->showQuickStartDialog();
            }
            if (showDataWizard) {
                kst->showDataWizardWithFile(wizardfile);
            }
            for (size_t i = 0; i < startupErrors.size(); ++i) {
                KstDebug::self()->log(startupErrors[i], KstDebug::Error);
            }
            startupErrors.clear();
        }

        // LEAVE THIS HERE - causes crashes otherwise!
        int rc = app.exec();
        delete kst;
        return rc;
    }

    return app.exec();
}