void Cube::parseGridData(TextStream& textStream) { QList<double> data; while (!textStream.atEnd()) { data += textStream.nextLineAsDoubles(); } QList<Data::Geometry*> geometryList(m_dataBank.findData<Data::Geometry>()); if (geometryList.isEmpty()) { m_errors.append("Geometry data not found in cube file"); return; } try { Data::SurfaceType type(Data::SurfaceType::CubeData); Data::GridSize size(m_origin, m_delta, m_nx, m_ny, m_nz); Data::CubeData* cube(new Data::CubeData(*(geometryList.last()),size, type, data)); m_dataBank.append(cube); QFileInfo info(m_filePath); cube->setLabel(info.completeBaseName()); } catch (std::out_of_range const& err) { m_errors.append("Invalid grid data in cube file"); } }
// Note the grid data is read in as bohr, but converted to angstroms in the // Grid constructor bool QChemPlot::parse(TextStream& textStream) { QList<double> values; QList<Data::SurfaceType> surfaceTypes(parseForProperties(textStream)); unsigned nProperties(surfaceTypes.size()); if (nProperties < 1) goto error; values = textStream.nextLineAsDoubles(); if ((unsigned)values.size() != 3 + nProperties) goto error; {/**/ double xMin(values[0]); double yMin(values[1]); double zMin(values[2]); double xMax(xMin); double yMax(yMin); double zMax(zMin); typedef QList<double> List; List* data = new List[nProperties]; for (unsigned i = 0; i < nProperties; ++i) { data[i].append(values[i+3]); } unsigned nx(1), ny(1), nz(1); while (!textStream.atEnd()) { if ((unsigned)values.size() == 3 + nProperties) { if (values[0] > xMax) { xMax = values[0]; ++nx; } if (values[1] > yMax) { yMax = values[1]; ++ny; } if (values[2] > zMax) { zMax = values[2]; ++nz; } for (unsigned i = 0; i < nProperties; ++i) { data[i].append(values[i+3]); } } values = textStream.nextLineAsDoubles(); } qglviewer::Vec delta((xMax-xMin)/nx, (yMax-yMin)/ny, (zMax-zMin)/nz); qglviewer::Vec origin(xMin, yMin, zMin); Data::GridDataList* gridList(new Data::GridDataList); try { for (unsigned i = 0; i < nProperties; ++i) { Data::GridSize size(origin, delta, nx, ny, nz); gridList->append(new Data::GridData(size, surfaceTypes[i])); } m_dataBank.append(gridList); } catch (...) { m_errors.append("Problem creating QChem plot data"); delete gridList; } delete[] data; }/**/ return m_errors.isEmpty(); error: QString msg("Problem parsing QChem plot data, line "); m_errors.append(msg += QString::number(textStream.lineNumber())); return false; }