bool AmberNetcdf::parseFrame() { if (_current_frame >= _nframes) return(false); readRawFrame(_current_frame); return(true); }
QByteArray StandardSerialPortBackend::readDataFrame(uint size, bool verbose) { // qDebug() << "!d" << tr("DBG -- Serial Port readDataFrame..."); QByteArray data = readRawFrame(size + 1, verbose); if (data.isEmpty()) { return data; } quint8 expected = (quint8)data.at(size); quint8 got = sioChecksum(data, size); if (expected == got) { data.resize(size); return data; } else { if (verbose) { qWarning() << "!w" << tr("Data frame checksum error, expected: %1, got: %2. (%3)") .arg(expected) .arg(got) .arg(QString(data.toHex())); } data.clear(); return data; } }
void AmberNetcdf::init(const char* name, const uint natoms) { int retval; retval = nc_open(name, NC_NOWRITE, &_ncid); if (retval) throw(FileOpenError(name, "", retval)); // May want to preserve code here in the future... // Read and validate global attributes... readGlobalAttributes(); if (_conventions.empty() || _conventionVersion.empty()) throw(FileOpenError(name, "Unable to find convention global attributes. Is this really an Amber NetCDF trajectory?")); if (_conventions.find("AMBER") == std::string::npos) throw(FileOpenError(name, "Cannot find AMBER tag in global attribues. Is this really an Amber NetCDF trajectory?")); if (_conventionVersion != std::string("1.0")) throw(FileOpenError(name, "Convention version is '" + _conventionVersion + "', but only 1.0 is supported for Amber NetCDF trajectories.")); // Verify # of atoms match... int atom_id; retval = nc_inq_dimid(_ncid, "atom", &atom_id); if (retval) throw(FileOpenError(name, "Cannot read atom id"), retval); retval = nc_inq_dimlen(_ncid, atom_id, &_natoms); if (retval) throw(FileOpenError(name, "Cannot read atom length", retval)); if (_natoms != natoms) throw(FileOpenError(name, "AmberNetcdf has different number of atoms than expected")); // Get nframes int frame_id; retval = nc_inq_dimid(_ncid, "frame", &frame_id); if (retval) throw(FileOpenError(name, "Cannot read frame information", retval)); retval = nc_inq_dimlen(_ncid, frame_id, &_nframes); // Check for periodic cells... retval = nc_inq_varid(_ncid, "cell_lengths", &_cell_lengths_id); _periodic = !retval; // Any additional validation should go here... // Get coord-id for later use... retval = nc_inq_varid(_ncid, "coordinates", &_coord_id); if (retval) throw(FileOpenError(name, "Cannot get id for coordinates", retval)); // Attempt to determine timestep by looking at dT between frames 1 & 2 if (_nframes >= 2) { int time_id; retval = nc_inq_varid(_ncid, "time", &time_id); if (!retval) { float t0, t1; size_t idx[1]; idx[0] = 0; retval = nc_get_var1_float(_ncid, time_id, idx, &t0); if (retval) throw(FileOpenError(name, "Cannot get first time point", retval)); idx[0] = 1; retval = nc_get_var1_float(_ncid, time_id, idx, &t1); if (retval) throw(FileOpenError(name, "Cannot get second time point", retval)); // Assume units are in picoseconds _timestep = (t1-t0)*1e-12; } } // Now cache the first frame... readRawFrame(0); cached_first = true; }