示例#1
0
static KstRVector *GetOrCreateVector(const QString& field, KstDataSourcePtr file, InType &in) {
    int i_v = 0, n_v;
    KstRVector *V;
    KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);

    n_v = vectorList.count();

    for (i_v=0; i_v<n_v; i_v++) {
        V = *vectorList.at(i_v);
        if (V->field() == field && V->filename() == file->fileName()) {
            return V;
        }
    }

    V = new KstRVector(file, field, KstObjectTag(KST::suggestVectorName(field), file->tag(), false), in.f, in.n, in.skip, in.doskip, in.doave);
    if (!V->isValid()) {
        if (file->fileType() == "stdin") {
            startupErrors.append(i18n("Failed to create vector '%1' from file '%2'.  Trying again later.").arg(field).arg(file->fileName()));
        } else {
            startupErrors.append(i18n("Failed to create vector '%1' from file '%2'.").arg(field).arg(file->fileName()));
            V = 0L;
        }
    } else {
    }

    return V;
}
示例#2
0
void KstApp::reload() {
  KstReadLocker ml(&KST::vectorList.lock());
  for (KstVectorList::Iterator i = KST::vectorList.begin(); i != KST::vectorList.end(); ++i) {
    KstRVector *r = dynamic_cast<KstRVector*>((*i).data());
    if (r) {
      r->reload();
    }
  }
}
示例#3
0
void KstIfaceImpl::reloadVector(const QString& vector) {
  KstReadLocker ml(&KST::vectorList.lock());
  KstVectorList::Iterator v = KST::vectorList.findTag(vector);
  if (v != KST::vectorList.end()) {
    (*v)->writeLock();
    KstRVector *r = dynamic_cast<KstRVector*>((*v).data());
    if (r) {
      r->reload();
    }
    (*v)->writeUnlock();
  }
}
示例#4
0
KstRVector *GetOrCreateVector(QString field, KstDataSourcePtr file, struct InType &in) {
  int i_v = 0, n_v;
  KstRVector *V;
  KstRVectorList vectorList =
    kstObjectSubList<KstVector,KstRVector>(KST::vectorList);

  n_v = vectorList.count();

  for (i_v=0; i_v<n_v; i_v++) {
    V = *vectorList.at(i_v);
    if (V->getField() == field) {
      if (V->filename() == file->fileName()) {
	return (V);
      }
    }
  }
  V = new KstRVector(file, field,
			  QString("V") + QString::number(1 + i_v++)
                          + "-" + field,
                          in.f, in.n, in.skip, in.doskip, in.doave);
  if (!V->isValid()) {
    kdError() << I18N_NOOP("Error: Invalid field: ") << V->getField()
              << endl << I18N_NOOP("File: ") << V->filename() << endl;
    exit(0); // fixme: this can cause crashes
  }

  return V;
}
示例#5
0
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();
}