C++ (Qt)QString readString(QFile& f, int count){ char* c = new char[count + 1]; f.read(c, count); c[count] = 0; // Null terminated return QString(c).trimmed();} void readFloatbuffer(QFile &f, float* f_buffer, int len){ f.read((char*)f_buffer, len * sizeof(*f_buffer));} void readInt32buffer(QFile &f, int* i_buffer, int len){ f.read((char*)i_buffer, len * sizeof(*i_buffer));} int readInt32(QFile &f){ int val; f.read((char*)&val, sizeof(val)); return val;} float readFloat(QFile &f){ float val; f.read((char*)&val, sizeof(val)); return val;} //ImplementationTempestDataLoader::TempestDataLoader(SharedData* data){ m_data = data;} TempestDataLoader::~TempestDataLoader(){} void TempestDataLoader::loadDataFromFile(QString fName){ QTime timer; timer.start(); m_data->fileName = fName; int numb[100]; // Prepare for read file QFileInfo fileInfo(fName); QString baseName = fileInfo.baseName(); QString pathName = fileInfo.absolutePath(); QString fname(pathName + "/" + baseName + ".mis"); // Read mis-file QFile file(fname); file.open(QIODevice::ReadOnly); file.read(16); int d = readInt32(file); int m = readInt32(file); int y = readInt32(file); m_data->initDate.setDate(y, m, d); file.read(54); m_data->progHeader1 = readString(file, 75); m_data->progHeader2 = readString(file, 75); file.read(12); readInt32buffer(file, numb, 100); m_data->wellCount = numb[2]; m_data->groupCount = numb[11]; m_data->aquaCount = numb[32]; m_data->quantCount = numb[37]; m_data->nx = numb[43]; m_data->ny = numb[44]; m_data->nz = numb[45]; file.read(12); int nc = readInt32(file); int nl = readInt32(file); readInt32(file); int ms = readInt32(file); int mp = readInt32(file); file.read(mp * 16 + nc * 16 + mp * 4 + nc * mp * 4 + mp * 4 + 3 * nc * 4 + nl * 16 + nc * nl * 4 + ms * 16 + nc * ms * 4); m_data->oilden = readFloat(file); m_data->gasden = readFloat(file); m_data->waterden = readFloat(file); file.close(); // Read ctl-file m_data->daysList.clear(); m_data->datesList.clear(); m_data->arrayList.clear(); m_data->yearsIndex.clear(); fname = pathName + "/" + baseName + ".ctl"; file.setFileName(fname); file.open(QIODevice::ReadOnly); file.read(12); while (file.pos() != file.size()) { readInt32(file); int isArray = readInt32(file); int isRate = readInt32(file); float value = readFloat(file); if (isArray == 1) m_data->arrayList.append(m_data->initDate.addDays((int)value)); if (isRate == 1) { m_data->daysList.append(value); m_data->datesList.append(m_data->initDate.addDays((int)value)); if (m_data->datesList.last().month() == 01) { m_data->yearsIndex.append(m_data->datesList.count() - 1); } } file.read(8); } file.close(); m_data->daysCount = m_data->daysList.count(); m_data->yearsCount = m_data->yearsIndex.count(); // Read rat-file fname = pathName + "/" + baseName + ".rat"; file.setFileName(fname); file.open(QIODevice::ReadOnly); m_data->wellNames.clear(); m_data->groupNames.clear(); m_data->aquiferNames.clear(); m_data->quantMnemonic.clear(); m_data->quantUnits.clear(); m_data->quantAssociated.clear(); m_data->quantDescription.clear(); for (int i = 0; i < m_data->wellCount; ++i) m_data->wellNames.append(readString(file, 16)); for (int i = 0; i < m_data->groupCount; ++i) m_data->groupNames.append(readString(file, 16)); for (int i = 0; i < m_data->aquaCount; ++i) m_data->aquiferNames.append(readString(file, 16)); for (int i = 0; i < m_data->quantCount; ++i) { m_data->quantMnemonic.append(readString(file, 16)); m_data->quantUnits.append(readString(file, 16)); m_data->quantAssociated.append(readString(file, 16)); m_data->quantDescription.append(readString(file, 48)); file.read(numb[39] * 4 + numb[40] * 4); } int leng = (numb[20] + numb[1] + 1) * (numb[15] + 2) + 2 * numb[20] + 4 * numb[1] + 2 * numb[1] * numb[4]; // Found max-array of float int fbufflen = numb[48]; if (fbufflen < 15) fbufflen = 15; if (fbufflen < leng) fbufflen = leng; float* fbuff = new float[fbufflen]; int* ibuff = new int[numb[46]]; // Initialization m_data->init(); int _status = 0; for (int istep = 0; istep < m_data->daysCount; ++istep) { for (int iw = 0; iw < m_data->wellCount; ++iw) { readInt32buffer(file, ibuff, numb[46]); _status = ibuff[3]; //IRPTR + IRLIM file.read(numb[4] * numb[47] * 4 + numb[6] * 2 * 4); //WRATE readFloatbuffer(file, fbuff, numb[48]); m_data->xloc[iw] = fbuff[0]; m_data->yloc[iw] = fbuff[1]; //WRVOL readFloatbuffer(file, fbuff, 15); m_data->opr[istep * m_data->wellCount + iw] = 0; m_data->gpr[istep * m_data->wellCount + iw] = 0; m_data->wpr[istep * m_data->wellCount + iw] = 0; m_data->wir[istep * m_data->wellCount + iw] = 0; if (_status == 1) { m_data->opr[istep * m_data->wellCount + iw] = fbuff[0]; m_data->gpr[istep * m_data->wellCount + iw] = fbuff[1]; m_data->wpr[istep * m_data->wellCount + iw] = fbuff[2]; } if (_status == 2) { m_data->wir[istep * m_data->wellCount + iw] = fbuff[1]; } m_data->opt[istep * m_data->wellCount + iw] = fbuff[5]; m_data->gpt[istep * m_data->wellCount + iw] = fbuff[6]; m_data->wpt[istep * m_data->wellCount + iw] = fbuff[7]; m_data->wit[istep * m_data->wellCount + iw] = fbuff[11]; //WRMS + WMCMP + WRCMP file.read(numb[1] * 3 * 4 + numb[4] * 2 * 4 + numb[4] * numb[1] * 4); //WVCMP if (numb[54] == 1) file.read(numb[4] * 15 * 4); //WVLAY if (numb[55] == 1) file.read(numb[4] * numb[51] * 4); } //Group data for (int ig = 0; ig < m_data->groupCount; ig++) { file.read(4); readFloatbuffer(file, fbuff, leng); file.read(numb[20] * numb[52] * 4); for (int iw = 0; iw < m_data->wellCount; iw++) { m_data->gwfr[ig * m_data->wellCount + iw] =readFloat(file); } file.read(numb[4] * numb[53] * 4); } //Aquifer data file.read(numb[32] * numb[33] * 4); // Quantities for (int iq = 0; iq < m_data->quantCount; ++iq) { m_data->qdata[istep * m_data->quantCount + iq] = readFloat(file); } } file.close(); delete[] ibuff; delete[] fbuff; m_data->elapsedTime = timer.elapsed();}