void Vector::oldChange(QByteArray &data) {
  if (!data.isEmpty()) {
    _saveable = true;
    _saveData = true;

    QDataStream qds(data);

    int sz = qMax(qint64((size_t)(INITSIZE)), qint64(data.size()/sizeof(double)));
    resize(sz, true);

    double sum=0.0;
    for (int i = 0; i<sz; ++i) {
      qds >> _v[i];
      if(!i) {
          _min=_max=_minPos=sum=_v[i];
          _minPos=qMax(_minPos,0.0);
      } else {
          _min=qMin(_v[i],_min);
          _max=qMax(_v[i],_max);
          _minPos=qMin(qMax(_v[i],0.0),_minPos);
          sum+=_v[i];
      }
    }
    _mean=sum/double(_size);
  }
KstAMatrix::KstAMatrix(const QDomElement &e) : KstMatrix() {
  _editable = true;

  double in_xMin = 0, in_yMin = 0, in_xStep = 1, in_yStep = 1;
  int in_nX = 2, in_nY = 2;
  QString in_tag = QString::null; 

  // must get the grid dimensions before the data
  QDomNode n = e.firstChild();
  while (!n.isNull()) {
    QDomElement e = n.toElement();
    if (!e.isNull()) {
      if (e.tagName() == "tag") {
        setTagName(KstObjectTag::fromString(e.text()));
      } else if (e.tagName() == "nx") {
        in_nX = e.text().toInt();
      } else if (e.tagName() == "ny") {
        in_nY = e.text().toInt();
      } else if (e.tagName() == "xmin") {
        in_xMin = e.text().toDouble();
      } else if (e.tagName() == "ymin") {
        in_yMin = e.text().toDouble();
      } else if (e.tagName() == "xstep") {
        in_xStep = e.text().toDouble();
      } else if (e.tagName() == "ystep") {
        in_yStep = e.text().toDouble();
      }
    }
    n = n.nextSibling();
  }
  _saveable = true;
  resizeZ(in_nX*in_nY, true);

  // now get the z data
  if (in_nX*in_nY > 0) {
    QDomNode n = e.firstChild();
    while (!n.isNull()) {
      QDomElement e = n.toElement();
      if (!e.isNull()) {
        if (e.tagName() == "data") {
          QCString qcs(e.text().latin1());
          QByteArray qbca;
          KCodecs::base64Decode(qcs, qbca);
          QByteArray qba = qUncompress(qbca);
          QDataStream qds(qba, IO_ReadOnly);
          int i;
          // fill in the raw array with the data
          for (i = 0; i < in_nX*in_nY && !qds.atEnd(); i++) {
            qds >> _z[i];  // stored in the same order as it was saved
          }
          if (i < in_nX*in_nY) {
            KstDebug::self()->log(i18n("Saved matrix contains less data than it claims."), KstDebug::Warning);
            resizeZ(i, false);
          }
        }
      }
      n = n.nextSibling();
    }
KstVector::KstVector(const QDomElement& e)
    : KstPrimitive(), _nsum(0), _scalars(11) {
    QByteArray qba;
    _v = 0L;
    _size = 0;
    int sz = INITSIZE;
    KstObjectTag in_tag = KstObjectTag::invalidTag;

    _editable = false;
    NumShifted = 0;
    NumNew = 0;
    _isScalarList = false;
    _saveable = false;
    _saveData = false;

    QDomNode n = e.firstChild();
    while (!n.isNull()) {
        QDomElement e = n.toElement();
        if (!e.isNull()) {
            if (e.tagName() == "tag") {
                in_tag = KstObjectTag::fromString(e.text());
            } else if (e.tagName() == "data") {
                QCString qcs(e.text().latin1());
                QByteArray qbca;
                KCodecs::base64Decode(qcs, qbca);
                qba = qUncompress(qbca);
                sz = kMax((size_t)(INITSIZE), qba.size()/sizeof(double));
            }
        }
        n = n.nextSibling();
    }

    if (!in_tag.isValid()) {
        QString nt = i18n("Anonymous Vector %1");

        do {
            KstObject::setTagName(KstObjectTag(nt.arg(anonymousVectorCounter++), in_tag.context()));
        } while (KstData::self()->vectorTagNameNotUnique(tagName(), false));
    } else {
        KstObject::setTagName(KST::suggestUniqueVectorTag(in_tag));
    }

    createScalars();
    resize(sz, true);

    if (!qba.isEmpty()) {
        _saveable = true;
        _saveData = true;
        QDataStream qds(qba, IO_ReadOnly);
        for (int i = 0; !qds.atEnd(); ++i) {
            qds >> _v[i];
        }
    }
Example #4
0
int main(int argc, char ** argv)
{
    QHash<QString,WhitLocation> hash;
    
    QCoreApplication app(argc,argv);
    QFile input("listall");
    QFile index("whitindex.cal");
    QFile output("whitdefinitions.cal");

    input.open(QFile::ReadOnly);
    index.open(QFile::WriteOnly);
    output.open(QFile::WriteOnly);

    QTextStream is(&input);
    QTextStream ins(&index);

    QString line;

    while(!is.atEnd())
    {
        line = is.readLine();
        
        QProcess process;
        QStringList args;
        args.push_back(line);
        process.start("./words", args);
        process.waitForStarted();
        process.write("\n\n\n\n\n");
        process.waitForFinished();
        QByteArray ret = process.readAllStandardOutput();
        QString retstring(ret);

        app.processEvents();
        
        ins << line << endl;
        ins << QString::number(output.pos()) << endl;
        QByteArray outd = retstring.toUtf8();
        ins << outd.length() << endl;
        WhitLocation wl;
        wl.pos = output.pos();
        wl.len = outd.length();
        line=line.remove("\n");
        hash[line]=wl;
        output.write(outd);
        output.flush();
    }

    QFile output2("whitindexhash.cal");
    output2.open(QFile::WriteOnly);
    QDataStream qds(&output2);
    qds << hash;
}
Example #5
0
void Vector::change(QByteArray &data) {
  if (!data.isEmpty()) {
    _saveable = true;
    _saveData = true;

    int sz = qMax((size_t)(INITSIZE), data.size()/sizeof(double));
    resize(sz, true);

    QDataStream qds(data);
    for (int i = 0; !qds.atEnd(); ++i) {
      qds >> _v[i];
    }
  }
/** Save vector information */
void EditableVector::save(QXmlStreamWriter &s) {
  s.writeStartElement("editablevector");
  saveNameInfo(s, VNUM|XNUM);

  if (_saveData) {
    QByteArray qba(length()*sizeof(double), '\0');
    QDataStream qds(&qba, QIODevice::WriteOnly);

    for (int i = 0; i < length(); i++) {
      qds << _v[i];
    }

    s.writeTextElement("data", qCompress(qba).toBase64());
  }
  s.writeEndElement();
}
void EditableMatrix::save(QXmlStreamWriter &xml) {

  QByteArray qba(_zSize*sizeof(double), '\0');
  QDataStream qds(&qba, QIODevice::WriteOnly);

  for (int i = 0; i < _zSize; i++) {
    qds << _z[i];
  }

  xml.writeStartElement(staticTypeTag);
  xml.writeAttribute("xmin", QString::number(minX()));
  xml.writeAttribute("ymin", QString::number(minY()));
  xml.writeAttribute("nx", QString::number(xNumSteps()));
  xml.writeAttribute("ny", QString::number(yNumSteps()));
  xml.writeAttribute("xstep", QString::number(xStepSize()));
  xml.writeAttribute("ystep", QString::number(yStepSize()));
  xml.writeTextElement("data", qCompress(qba).toBase64());
  saveNameInfo(xml, VNUM|MNUM|XNUM);
  xml.writeEndElement();
}
Example #8
0
QDomDocument TestEditableMatrix::makeDOMElement(const QString& tag, const int nx, const int ny, const double xmin, const double ymin, const double xstep, const double ystep, const int dataSize) {
  // Should be some boundary checking in the constructor.
  QDomDocument amDOM("amdocument");
  QDomElement amElement, child, dataset;
  QDomText text;

  amElement = amDOM.createElement("amDOMTest");

  child = amDOM.createElement("tag");
  text = amDOM.createTextNode(tag);
  child.appendChild(text);
  amElement.appendChild(child);

  child = amDOM.createElement("nx");
  text = amDOM.createTextNode(QString::number(nx));
  child.appendChild(text);
  amElement.appendChild(child);

  child = amDOM.createElement("ny");
  text = amDOM.createTextNode(QString::number(ny));
  child.appendChild(text);
  amElement.appendChild(child);

  child = amDOM.createElement("xmin");
  text = amDOM.createTextNode(QString::number(xmin));
  child.appendChild(text);
  amElement.appendChild(child);

  child = amDOM.createElement("ymin");
  text = amDOM.createTextNode(QString::number(ymin));
  child.appendChild(text);
  amElement.appendChild(child);

  child = amDOM.createElement("xstep");
  text = amDOM.createTextNode(QString::number(xstep));
  child.appendChild(text);
  amElement.appendChild(child);

  child = amDOM.createElement("ystep");
  text = amDOM.createTextNode(QString::number(ystep));
  child.appendChild(text);
  amElement.appendChild(child);


  child = amDOM.createElement("data");
  QByteArray qba;
  qba.reserve(dataSize*sizeof(double));
  QDataStream qds(&qba, QIODevice::WriteOnly);

  for (int i = 0; i < dataSize; i++) {
    qds << 1.1;
  }

  text = amDOM.createTextNode(QString(qCompress(qba).toBase64()));

  child.appendChild(text);
  amElement.appendChild(child);

  amDOM.appendChild(amElement);

  return amDOM;
}