void FFDemux::abort() { QMutexLocker mL(&mutex); for (FormatContext *fmtCtx : asConst(formatContexts)) fmtCtx->abort(); abortFetchTracks = true; }
void move(char p1, char p2){ char a = top[p1], b = top[p2]; char k = top[p1]; top[p1] = c[k].u; c[k].u = top[p2]; top[p2] = k; if(!--ps[p1]) mL(p1), --ct; ps[p2]++; }
void FFDemux::addFormatContext(QString url, const QString ¶m) { FormatContext *fmtCtx = new FormatContext(reconnectStreamed); { QMutexLocker mL(&mutex); formatContexts.append(fmtCtx); } if (!url.contains("://")) url.prepend("file://"); if (fmtCtx->open(url, param)) streams_info.append(fmtCtx->streamsInfo); else { { QMutexLocker mL(&mutex); formatContexts.erase(formatContexts.end() - 1); } delete fmtCtx; } }
void SimpleVis::soundBuffer( const bool enable ) { QMutexLocker mL( &mutex ); const int arrSize = enable ? ( ceil( sndLen * w.srate ) * w.chn * sizeof( float ) ) : 0; if ( arrSize != tmpData.size() || arrSize != w.soundData.size() ) { tmpDataPos = 0; tmpData.clear(); if ( arrSize ) { tmpData.resize( arrSize ); const int oldSize = w.soundData.size(); w.soundData.resize( arrSize ); if ( arrSize > oldSize ) memset( w.soundData.data() + oldSize, 0, arrSize - oldSize ); } else w.soundData.clear(); } }
void SimpleVis::sendSoundData( const QByteArray &data ) { if ( !w.tim.isActive() || !data.size() ) return; QMutexLocker mL( &mutex ); if ( !tmpData.size() ) return; int newDataPos = 0; while ( newDataPos < data.size() ) { const int size = qMin( data.size() - newDataPos, tmpData.size() - tmpDataPos ); fltcpy( ( float * )( tmpData.data() + tmpDataPos ), ( const float * )( data.data() + newDataPos ), size ); newDataPos += size; tmpDataPos += size; if ( tmpDataPos == tmpData.size() ) { memcpy( w.soundData.data(), tmpData.constData(), tmpDataPos ); tmpDataPos = 0; } } }
void ReceiveFromDevice::ProcessMessage() { switch(data[1]) { case COMSTACK_FREE_SPACE_MESS: { device->freeSpace = *((uint16_t*)(data+2)); //Thread synchronisation - notify wxMutexLocker mL(device->freeSpaceM); if(device->freeSpace > 128) { int i = 2; i = 6; } device->freeSpaceC.Signal(); } break; case LAST_PROC_ITEM_STACK: { device->lastItemStack = *((uint32_t*)(data+2)); //Thread synchronisation - notify wxMutexLocker mL(device->lastItemStackM); device->lastItemStackC.Signal(); } break; case CUR_PROC_ITEM_STACK: { device->curItemStack = *((uint32_t*)(data+2)); //Thread synchronisation - notify wxMutexLocker mL(device->curItemStackM); device->curItemStackC.Signal(); } break; case AXES_POSITION: { float p[7]; for(int i = 0; i != 7; i++) { p[i] = *((float*)(data+i*sizeof(float)+2)); } wxString t; t << wxT("X: ") << p[0] << wxT("\tY: ") << p[1] << wxT("\tZ: ") << p[2]; position << p[0] << "\t" << p[1] << "\t" << p[5] << "\t" <<p[6]<<endl; MainWindow* w = (MainWindow*)(wnd); w->statusBar->SetStatusText(t, 2); Point add; add.x = p[0]; add.y = p[1]; w->middlePanel->AddToTrajectory(add); } break; case DEBUG_POSITION_INFO: { //Incomming message is position info for debugging float p[3]; for(int u = 0; u != 21; u++) { uint32_t time = *((uint32_t*)(data+2+u*12)); for(int i = 0; i != 3; i++) { p[i] = *((float*)(data+i*sizeof(float)+6+u*12)); } debugPosition << time << "\t" << p[0] << "\t" << p[1] << "\t" << p[0] << "\n"; } } break; case ERROR_MESS: { wxString text = wxT("Zaøízení odeslalo chybu: "); switch(data[2]) { case ERR_COMSTACKOWERFLOW: text << wxT("Pøeteèení vstupního bufferu"); break; default: text << wxT("Neznámá chyba"); break; } wxMessageBox(text, wxT("Chyba!"), wxOK | wxICON_EXCLAMATION); } break; default: { } } }
Playlist::Entries FFDemux::fetchTracks(const QString &url, bool &ok) { if (url.contains("://{") || !url.startsWith("file://")) return {}; const auto createFmtCtx = [&] { FormatContext *fmtCtx = new FormatContext; { QMutexLocker mL(&mutex); formatContexts.append(fmtCtx); } return fmtCtx; }; const auto destroyFmtCtx = [&](FormatContext *fmtCtx) { { QMutexLocker mL(&mutex); const int idx = formatContexts.indexOf(fmtCtx); if (idx > -1) formatContexts.remove(idx); } delete fmtCtx; }; if (url.endsWith(".cue", Qt::CaseInsensitive)) { QFile cue(url.mid(7)); if (cue.size() <= 0xFFFF && cue.open(QFile::ReadOnly | QFile::Text)) { QList<QByteArray> data = Functions::textWithFallbackEncoding(cue.readAll()).split('\n'); QString title, performer, audioUrl; double index0 = -1.0, index1 = -1.0; QHash<int, QPair<double, double>> indexes; Playlist::Entries entries; Playlist::Entry entry; int track = -1; const auto maybeFlushTrack = [&](int prevTrack) { if (track <= 0) return; const auto cutFromQuotation = [](QString &str) { const int idx1 = str.indexOf('"'); const int idx2 = str.lastIndexOf('"'); if (idx1 > -1 && idx2 > idx1) str = str.mid(idx1 + 1, idx2 - idx1 - 1); else str.clear(); }; cutFromQuotation(title); cutFromQuotation(performer); if (!title.isEmpty() && !performer.isEmpty()) entry.name = performer + " - " + title; else if (title.isEmpty() && !performer.isEmpty()) entry.name = performer; else if (!title.isEmpty() && performer.isEmpty()) entry.name = title; if (entry.name.isEmpty()) { if (entry.parent == 1) entry.name = tr("Track") + " " + QString::number(prevTrack); else entry.name = Functions::fileName(entry.url, false); } title.clear(); performer.clear(); if (prevTrack > 0) { if (index0 <= 0.0) index0 = index1; // "INDEX 00" doesn't exist, use "INDEX 01" indexes[prevTrack].first = index0; indexes[prevTrack].second = index1; if (entries.count() <= prevTrack) entries.resize(prevTrack + 1); entries[prevTrack] = entry; } else { entries.prepend(entry); } entry = Playlist::Entry(); entry.parent = 1; entry.url = audioUrl; index0 = index1 = -1.0; }; const auto parseTime = [](const QByteArray &time) { int m = 0, s = 0, f = 0; if (sscanf(time.constData(), "%2d:%2d:%2d", &m, &s, &f) == 3) return m * 60.0 + s + f / 75.0; return -1.0; }; entry.url = url; entry.GID = 1; for (QByteArray &line : data) { line = line.trimmed(); if (track < 0) { if (line.startsWith("TITLE ")) title = line; else if (line.startsWith("PERFORMER ")) performer = line; else if (line.startsWith("FILE ")) { const int idx = line.lastIndexOf('"'); if (idx > -1) { audioUrl = line.mid(6, idx - 6); if (!audioUrl.isEmpty()) audioUrl.prepend(Functions::filePath(url)); } } } else if (line.startsWith("FILE ")) { // QMPlay2 supports CUE files which uses only single audio file return {}; } if (line.startsWith("TRACK ")) { if (entries.isEmpty() && audioUrl.isEmpty()) break; if (line.endsWith(" AUDIO")) { const int prevTrack = track; track = line.mid(6, 2).toInt(); if (track < 99) maybeFlushTrack(prevTrack); else track = 0; } else { track = 0; } } else if (track > 0) { if (line.startsWith("TITLE ")) title = line; else if (line.startsWith("PERFORMER ")) performer = line; else if (line.startsWith("INDEX 00 ")) index0 = parseTime(line.mid(9)); else if (line.startsWith("INDEX 01 ")) index1 = parseTime(line.mid(9)); } } maybeFlushTrack(track); for (int i = entries.count() - 1; i >= 1; --i) { Playlist::Entry &entry = entries[i]; const bool lastItem = (i == entries.count() - 1); const double start = indexes.value(i).second; const double end = indexes.value(i + 1, {-1.0, -1.0}).first; if (entry.url.isEmpty() || start < 0.0 || (end <= 0.0 && !lastItem)) { entries.removeAt(i); continue; } const QString param = QString("CUE:%1:%2").arg(start).arg(end); if (lastItem && end < 0.0) // Last entry doesn't have specified length in CUE file { FormatContext *fmtCtx = createFmtCtx(); if (fmtCtx->open(entry.url, param)) entry.length = fmtCtx->length(); destroyFmtCtx(fmtCtx); if (abortFetchTracks) { ok = false; return {}; } } else { entry.length = end - start; } entry.url = QString("%1://{%2}%3").arg(DemuxerName, entry.url, param); } if (!entries.isEmpty()) return entries; } } OggHelper oggHelper(url.mid(7), abortFetchTracks); if (oggHelper.io) { Playlist::Entries entries; int i = 0; for (const OggHelper::Chain &chains : oggHelper.getOggChains(ok)) { const QString param = QString("OGG:%1:%2:%3").arg(++i).arg(chains.first).arg(chains.second); FormatContext *fmtCtx = createFmtCtx(); if (fmtCtx->open(url, param)) { Playlist::Entry entry; entry.url = QString("%1://{%2}%3").arg(DemuxerName, url, param); entry.name = fmtCtx->title(); entry.length = fmtCtx->length(); entries.append(entry); } destroyFmtCtx(fmtCtx); if (abortFetchTracks) { ok = false; return {}; } } if (ok && !entries.isEmpty()) { for (int i = 0; i < entries.count(); ++i) entries[i].parent = 1; Playlist::Entry entry; entry.name = Functions::fileName(url, false); entry.url = url; entry.GID = 1; entries.prepend(entry); return entries; } } return {}; }
antlr::RefToken FMTLexer::nextToken() { antlr::RefToken theRetToken; for (;;) { antlr::RefToken theRetToken; int _ttype = antlr::Token::INVALID_TYPE; resetText(); try { // for lexical and char stream error handling switch ( LA(1)) { case 0x22 /* '\"' */ : case 0x27 /* '\'' */ : { mSTRING(true); theRetToken=_returnToken; break; } case 0x28 /* '(' */ : { mLBRACE(true); theRetToken=_returnToken; break; } case 0x29 /* ')' */ : { mRBRACE(true); theRetToken=_returnToken; break; } case 0x2f /* '/' */ : { mSLASH(true); theRetToken=_returnToken; break; } case 0x2c /* ',' */ : { mCOMMA(true); theRetToken=_returnToken; break; } case 0x41 /* 'A' */ : case 0x61 /* 'a' */ : { mA(true); theRetToken=_returnToken; break; } case 0x3a /* ':' */ : { mTERM(true); theRetToken=_returnToken; break; } case 0x24 /* '$' */ : { mNONL(true); theRetToken=_returnToken; break; } case 0x46 /* 'F' */ : case 0x66 /* 'f' */ : { mF(true); theRetToken=_returnToken; break; } case 0x44 /* 'D' */ : case 0x64 /* 'd' */ : { mD(true); theRetToken=_returnToken; break; } case 0x45 /* 'E' */ : case 0x65 /* 'e' */ : { mE(true); theRetToken=_returnToken; break; } case 0x47 /* 'G' */ : case 0x67 /* 'g' */ : { mG(true); theRetToken=_returnToken; break; } case 0x49 /* 'I' */ : case 0x69 /* 'i' */ : { mI(true); theRetToken=_returnToken; break; } case 0x4f /* 'O' */ : case 0x6f /* 'o' */ : { mO(true); theRetToken=_returnToken; break; } case 0x42 /* 'B' */ : case 0x62 /* 'b' */ : { mB(true); theRetToken=_returnToken; break; } case 0x5a /* 'Z' */ : { mZ(true); theRetToken=_returnToken; break; } case 0x7a /* 'z' */ : { mZZ(true); theRetToken=_returnToken; break; } case 0x51 /* 'Q' */ : case 0x71 /* 'q' */ : { mQ(true); theRetToken=_returnToken; break; } case 0x48 /* 'H' */ : case 0x68 /* 'h' */ : { mH(true); theRetToken=_returnToken; break; } case 0x54 /* 'T' */ : case 0x74 /* 't' */ : { mT(true); theRetToken=_returnToken; break; } case 0x4c /* 'L' */ : case 0x6c /* 'l' */ : { mL(true); theRetToken=_returnToken; break; } case 0x52 /* 'R' */ : case 0x72 /* 'r' */ : { mR(true); theRetToken=_returnToken; break; } case 0x58 /* 'X' */ : case 0x78 /* 'x' */ : { mX(true); theRetToken=_returnToken; break; } case 0x2e /* '.' */ : { mDOT(true); theRetToken=_returnToken; break; } case 0x9 /* '\t' */ : case 0x20 /* ' ' */ : { mWHITESPACE(true); theRetToken=_returnToken; break; } case 0x2b /* '+' */ : case 0x2d /* '-' */ : case 0x30 /* '0' */ : case 0x31 /* '1' */ : case 0x32 /* '2' */ : case 0x33 /* '3' */ : case 0x34 /* '4' */ : case 0x35 /* '5' */ : case 0x36 /* '6' */ : case 0x37 /* '7' */ : case 0x38 /* '8' */ : case 0x39 /* '9' */ : { mNUMBER(true); theRetToken=_returnToken; break; } default: if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x4d /* 'M' */ ) && (LA(3) == 0x4f /* 'O' */ ) && (LA(4) == 0x41 /* 'A' */ )) { mCMOA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x4d /* 'M' */ ) && (LA(3) == 0x4f /* 'O' */ ) && (LA(4) == 0x49 /* 'I' */ )) { mCMOI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x4d /* 'M' */ ) && (LA(3) == 0x6f /* 'o' */ )) { mCMoA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x44 /* 'D' */ ) && (LA(3) == 0x49 /* 'I' */ )) { mCDI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x4d /* 'M' */ ) && (LA(3) == 0x49 /* 'I' */ )) { mCMI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x53 /* 'S' */ ) && (LA(3) == 0x49 /* 'I' */ )) { mCSI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x53 /* 'S' */ ) && (LA(3) == 0x46 /* 'F' */ )) { mCSF(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x44 /* 'D' */ ) && (LA(3) == 0x57 /* 'W' */ )) { mCDWA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x44 /* 'D' */ ) && (LA(3) == 0x77 /* 'w' */ )) { mCDwA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x41 /* 'A' */ ) && (LA(3) == 0x50 /* 'P' */ )) { mCAPA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x41 /* 'A' */ ) && (LA(3) == 0x70 /* 'p' */ )) { mCApA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x25 /* '%' */ ) && (LA(2) == 0x22 /* '\"' */ || LA(2) == 0x27 /* '\'' */ )) { mCSTRING(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x6d /* 'm' */ )) { mCmoA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x59 /* 'Y' */ )) { mCYI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x48 /* 'H' */ )) { mCHI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x68 /* 'h' */ )) { mChI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x64 /* 'd' */ )) { mCdwA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x61 /* 'a' */ )) { mCapA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ || LA(1) == 0x63 /* 'c' */ ) && (true)) { mC(true); theRetToken=_returnToken; } else if ((LA(1) == 0x25 /* '%' */ ) && (true)) { mPERCENT(true); theRetToken=_returnToken; } else { if (LA(1)==EOF_CHAR) { uponEOF(); _returnToken = makeToken(antlr::Token::EOF_TYPE); } else {throw antlr::NoViableAltForCharException(LA(1), getFilename(), getLine(), getColumn());} } } if ( !_returnToken ) goto tryAgain; // found SKIP token _ttype = _returnToken->getType(); _ttype = testLiteralsTable(_ttype); _returnToken->setType(_ttype); return _returnToken; } catch (antlr::RecognitionException& e) { throw antlr::TokenStreamRecognitionException(e); } catch (antlr::CharStreamIOException& csie) { throw antlr::TokenStreamIOException(csie.io); } catch (antlr::CharStreamException& cse) { throw antlr::TokenStreamException(cse.getMessage()); } tryAgain:; } }
void OpenGL2Writer::writeOSD(const QList<const QMPlay2OSD *> &osds) { QMutexLocker mL(&drawable->osdMutex); drawable->osdList = osds; }
void DiffractionDataSingleCrystal::ImportHklIobsGroup(const string &fileName,const unsigned int skipLines) { //configure members mNbRefl=0; mNbGroup=0; mH.resize(500); mK.resize(500); mL.resize(500); mObsIntensity.resize(500); mObsSigma.resize(500); mGroupIndex.resize(500); mGroupIobs.resize(500); mGroupSigma.resize(500); mGroupWeight.resize(500); //Import data { //:TODO: Skip the lines if required !!! cout << "inputing reflections from file : "+fileName<<endl; ifstream fin (fileName.c_str()); if(!fin) { throw ObjCrystException("DiffractionDataSingleCrystal::ImportHklIobs() : \ Error opening file for input:"+fileName); } string buffer; REAL h,k,l,iobs,sigma; while(true) { getline(fin,buffer); istringstream linestream(buffer); int nn = (linestream >> h >> k >> l) ? 3 : 0; nn += bool(linestream >> iobs); nn += bool(linestream >> sigma); const int n = nn; if(n<3) break; mH(mNbRefl)=h; mK(mNbRefl)=k; mL(mNbRefl)=l; mGroupIndex(mNbRefl)=mNbGroup; //cout<<mNbRefl<<" "<<h<<" "<<k<<" "<<l<<"(g="<<mNbGroup<<") n="<<n; if(n>=4) { //cout<<" Iobs="<<iobs; mObsIntensity(mNbRefl)=iobs; if(n!=5) sigma=sqrt(fabs(iobs)+1e-6); mObsSigma(mNbRefl)=sigma; mGroupIobs(mNbGroup)=iobs; mGroupSigma(mNbGroup)=sigma; mGroupWeight(mNbGroup)=1/(sigma*sigma+1e-6); mNbGroup++; if(mNbGroup==mGroupIobs.numElements()) { mGroupIobs.resizeAndPreserve(mNbGroup+500); mGroupSigma.resizeAndPreserve(mNbGroup+500); mGroupWeight.resizeAndPreserve(mNbGroup+500); } } else { mObsIntensity(mNbRefl)=0; mObsSigma(mNbRefl)=0; } //cout<<endl; mNbRefl++; if(mNbRefl==mH.numElements()) { mH.resizeAndPreserve(mNbRefl+500); mK.resizeAndPreserve(mNbRefl+500); mL.resizeAndPreserve(mNbRefl+500); mObsIntensity.resizeAndPreserve(mNbRefl+500); mObsSigma.resizeAndPreserve(mNbRefl+500); mGroupIndex.resizeAndPreserve(mNbRefl+500); } if(fin.eof()) break; } fin.close(); } // This must NOT be changed with this kind of data. mGroupOption.SetChoice(2); // So de-register the option so that it is hidden from the user's view mOptionRegistry.DeRegister(mGroupOption); mClockMaster.RemoveChild(mGroupOption.GetClock()); //Finish mH.resizeAndPreserve(mNbRefl); mK.resizeAndPreserve(mNbRefl); mL.resizeAndPreserve(mNbRefl); mObsIntensity.resizeAndPreserve(mNbRefl); mObsSigma.resizeAndPreserve(mNbRefl); mWeight.resize(mNbRefl); mGroupIndex.resizeAndPreserve(mNbRefl);// this will change after sorting reflections mGroupIobs.resizeAndPreserve(mNbGroup); mGroupWeight.resizeAndPreserve(mNbGroup); mGroupSigma.resizeAndPreserve(mNbGroup); const REAL minIobs=mObsIntensity.max()*1e-6; for(int i=0;i<mNbRefl;i++) if(mObsIntensity(i)<minIobs) mWeight(i)=1./minIobs; else mWeight(i)=1./mObsIntensity(i); mHasObservedData=true; mMultiplicity.resize(mNbRefl); mMultiplicity=1; this->PrepareHKLarrays(); { char buf [200]; sprintf(buf,"Imported HKLIobs, with %d reflections",(int)mNbRefl); (*fpObjCrystInformUser)((string)buf); } this->SortReflectionBySinThetaOverLambda(); this->CalcIcalc(); }
void DiffractionDataSingleCrystal::ImportHklIobsSigmaJanaM91(const string &fileName) { //configure members mNbRefl=1000;//reasonable beginning value ? mH.resize(mNbRefl); mK.resize(mNbRefl); mL.resize(mNbRefl); mObsIntensity.resize(mNbRefl); mObsSigma.resize(mNbRefl); //Import data { cout << "inputing reflections from Jana98 file : "+fileName<<endl; ifstream fin (fileName.c_str()); if(!fin) { throw ObjCrystException("DiffractionDataSingleCrystal::ImportHklIobsSigmaJanaM91() : \ Error opening file for input:"+fileName); } long i=0; REAL tmpH; REAL junk; fin >> tmpH; while(tmpH != 999) { // :TODO: A little faster.... //:TODO: Check for the end of the stream if(!fin.good()) {throw...} i++; if(i>=mNbRefl) { cout << mNbRefl << " reflections imported..." << endl; mNbRefl+=1000; mH.resizeAndPreserve(mNbRefl); mK.resizeAndPreserve(mNbRefl); mL.resizeAndPreserve(mNbRefl); mObsIntensity.resizeAndPreserve(mNbRefl); mObsSigma.resizeAndPreserve(mNbRefl); } mH(i)=tmpH; fin >> mK(i); fin >> mL(i); fin >> mObsIntensity(i); fin >> mObsSigma(i); fin >> junk; fin >> junk; fin >> junk; fin >> junk; fin >> tmpH; } fin.close(); mNbRefl=i; cout << mNbRefl << " reflections imported." << endl; mH.resizeAndPreserve(mNbRefl); mK.resizeAndPreserve(mNbRefl); mL.resizeAndPreserve(mNbRefl); mObsIntensity.resizeAndPreserve(mNbRefl); mObsSigma.resizeAndPreserve(mNbRefl); } //Finish mWeight.resize(mNbRefl); mWeight=1; mMultiplicity.resize(mNbRefl); mMultiplicity=1; // Keep a copy as squared F(hkl), to enable fourier maps // :TODO: stop using mObsIntensity and just keep mFhklObsSq ? mFhklObsSq=mObsIntensity; mClockFhklObsSq.Click(); this->PrepareHKLarrays(); this->SortReflectionBySinThetaOverLambda(); cout << "Finished storing data..."<< endl ; mHasObservedData=true; { char buf [200]; sprintf(buf,"Imported HKLIobsSigma from Jana, with %d reflections",(int)mNbRefl); (*fpObjCrystInformUser)((string)buf); } }
void DiffractionDataSingleCrystal::ImportShelxHKLF4(const string &fileName) { VFN_DEBUG_ENTRY("DiffractionDataSingleCrystal::ImportShelxHKLF4():"<<fileName,10); char buf[101]; //configure members mNbRefl=100; mH.resize(mNbRefl); mK.resize(mNbRefl); mL.resize(mNbRefl); mObsIntensity.resize(mNbRefl); mObsSigma.resize(mNbRefl); long h=1,k=1,l=1,i=0; float iobs,sigma; //Import data { VFN_DEBUG_MESSAGE("inputing reflections from file (HKLF4): "<<fileName,10); ifstream fin (fileName.c_str()); if(!fin) { throw ObjCrystException("DiffractionDataSingleCrystal::ImportShelxHKLF4() : Error opening file for input:"+fileName); } for(;;) { fin.getline(buf,100); h=(int) atoi(string(buf).substr(0,4).c_str()); k=(int) atoi(string(buf).substr(4,4).c_str()); l=(int) atoi(string(buf).substr(8,4).c_str()); iobs=(float) atof(string(buf).substr(12,8).c_str()); sigma=(float) atof(string(buf).substr(20,8).c_str()); if((abs(h)+abs(k)+abs(l))==0) break; if(i==mNbRefl) { mNbRefl+=100; mH.resizeAndPreserve(mNbRefl); mK.resizeAndPreserve(mNbRefl); mL.resizeAndPreserve(mNbRefl); mObsIntensity.resizeAndPreserve(mNbRefl); mObsSigma.resizeAndPreserve(mNbRefl); } mH(i)=REAL(h); mK(i)=REAL(k); mL(i)=REAL(l); mObsIntensity(i)=REAL(iobs); mObsSigma(i)=REAL(sigma); i++; } VFN_DEBUG_MESSAGE("Finished reading from file (HKLF4) ",10); fin.close(); } //Finish mNbRefl=i; mH.resizeAndPreserve(mNbRefl); mK.resizeAndPreserve(mNbRefl); mL.resizeAndPreserve(mNbRefl); mObsIntensity.resizeAndPreserve(mNbRefl); mObsSigma.resizeAndPreserve(mNbRefl); mWeight.resize(mNbRefl); this->SetWeightToInvSigma2(1e-4,0); mHasObservedData=true; mMultiplicity.resize(mNbRefl); mMultiplicity=1; // Keep a copy as squared F(hkl), to enable fourier maps // :TODO: stop using mObsIntensity and just keep mFhklObsSq ? mFhklObsSq=mObsIntensity; mClockFhklObsSq.Click(); this->PrepareHKLarrays(); this->SortReflectionBySinThetaOverLambda(); { char buf [200]; sprintf(buf,"Imported Shelx HKLF 4 file, with %d reflections",(int)mNbRefl); (*fpObjCrystInformUser)((string)buf); } VFN_DEBUG_EXIT("DiffractionDataSingleCrystal::ImportShelxHKLF4() read "<<mNbRefl<<" reflections",10); }
void DiffractionDataSingleCrystal::ImportHklIobsSigma(const string &fileName, const long nbRefl, const int skipLines) { //configure members mNbRefl=nbRefl; mH.resize(mNbRefl); mK.resize(mNbRefl); mL.resize(mNbRefl); mObsIntensity.resize(mNbRefl); mObsSigma.resize(mNbRefl); //Import data { cout << "inputing reflections from file : "+fileName<<endl; ifstream fin (fileName.c_str()); if(!fin) { throw ObjCrystException("DiffractionDataSingleCrystal::ImportHklIobsSigma() : \ Error opening file for input:"+fileName); } if(skipLines>0) {//Get rid of first lines if required char tmpComment[200]; for(int i=0;i<skipLines;i++) fin.getline(tmpComment,150); } cout << "Number of reflections to import : " << nbRefl << endl ; for(long i=0;i<nbRefl;i++) { // :TODO: A little faster.... //:TODO: Check for the end of the stream if(!fin.good()) {throw...} fin >> mH(i); fin >> mK(i); fin >> mL(i); fin >> mObsIntensity(i); fin >> mObsSigma(i); //cout << mH(i)<<" "<<mK(i)<<" "<<mL(i)<<" "<<mObsIntensity(i)<<" "<<mObsSigma(i)<<endl; } cout << "Finished reading data>"<< endl; fin.close(); } //Finish mWeight.resize(mNbRefl); this->SetWeightToInvSigma2(1e-4,0); mHasObservedData=true; mMultiplicity.resize(mNbRefl); mMultiplicity=1; // Keep a copy as squared F(hkl), to enable fourier maps // :TODO: stop using mObsIntensity and just keep mFhklObsSq ? mFhklObsSq=mObsIntensity; mClockFhklObsSq.Click(); this->PrepareHKLarrays(); this->SortReflectionBySinThetaOverLambda(); { char buf [200]; sprintf(buf,"Imported HKLIobsSigma, with %d reflections",(int)mNbRefl); (*fpObjCrystInformUser)((string)buf); } cout << "Finished storing data..."<< endl ; }
CrystVector_long DiffractionDataSingleCrystal::SortReflectionBySinThetaOverLambda(const REAL maxSTOL) { TAU_PROFILE("DiffractionDataSingleCrystal::SortReflectionBySinThetaOverLambda()","void ()",TAU_DEFAULT); VFN_DEBUG_ENTRY("DiffractionDataSingleCrystal::SortReflectionBySinThetaOverLambda()",5) // ScatteringData::SortReflectionBySinThetaOverLambda only sorts H,K,L and multiplicity. CrystVector_long index=this->ScatteringData::SortReflectionBySinThetaOverLambda(maxSTOL); if(mObsIntensity.numElements()==mNbRefl) { CrystVector_REAL tmpObs,tmpSigma,tmpWeight; tmpObs=mObsIntensity; tmpSigma=mObsSigma; tmpWeight=mWeight; for(long i=0;i<mNbRefl;i++) { mObsIntensity(i)=tmpObs(index(i)); mObsSigma(i)=tmpSigma(index(i)); mWeight(i)=tmpWeight(index(i)); } // Keep a copy as squared F(hkl), to enable fourier maps // :TODO: stop using mObsIntensity and just keep mFhklObsSq ? mFhklObsSq=mObsIntensity; mClockFhklObsSq.Click(); if(mGroupOption.GetChoice()==2) { CrystVector_long tmp;//,oldgroup(mNbGroup);; tmp=mGroupIndex; for(long i=0;i<mNbRefl;i++) mGroupIndex(i)=tmp(index(i)); /* for(long i=0;i<mNbRefl;i++) cout<<mIntH(i)<<" "<<mIntK(i)<<" "<<mIntL(i)<<" " <<mObsIntensity(i)<<" "<<mObsSigma(i)<<" "<<mWeight(i)<< ":"<<mGroupIndex(i)<<endl; */ // Now re-index the groups of reflections in // ascending order { index.resize(mNbGroup); index=-1; long group=0; CrystVector_REAL oldGroupIobs, oldGroupWeight,oldGroupSigma; oldGroupIobs =mGroupIobs; oldGroupWeight=mGroupWeight; oldGroupSigma=mGroupSigma; for(long i=0;i<mNbRefl;i++) { if(index(mGroupIndex(i))==-1)// first reflection of a group ? { mGroupIobs(group)=oldGroupIobs(mGroupIndex(i)); mGroupSigma(group)=oldGroupSigma(mGroupIndex(i)); mGroupWeight(group)=oldGroupWeight(mGroupIndex(i)); //oldgroup(group)=mGroupIndex(i); index(mGroupIndex(i))=group++; } mGroupIndex(i)=index(mGroupIndex(i)); } } /* cout<<mIntH.numElements()<<"," <<mIntK.numElements()<<"," <<mIntL.numElements()<<"," <<oldgroup.numElements()<<","<<mGroupIndex.numElements()<<endl; for(long i=0;i<mNbRefl;i++) cout<<mIntH(i)<<" "<<mIntK(i)<<" "<<mIntL(i)<<endl <<" :"<<oldgroup(mGroupIndex(i))<<"->"<<mGroupIndex(i)<<endl; */ // Now re-group the reflections index=SortSubs(mGroupIndex); { CrystVector_long oldH,oldK,oldL,oldMult; oldH=mH; oldK=mK; oldL=mL; oldMult=mMultiplicity; tmpObs=mObsIntensity; tmpSigma=mObsSigma; tmpWeight=mWeight; for(long i=0;i<mNbRefl;i++) { const long subs=index(i); mH(i)=oldH(subs); mK(i)=oldK(subs); mL(i)=oldL(subs); mMultiplicity(i)=oldMult(subs); mObsIntensity(i)=tmpObs(subs); mObsSigma(i)=tmpSigma(subs); mWeight(i)=tmpWeight(subs); } mClockHKL.Click(); this->PrepareHKLarrays(); this->CalcSinThetaLambda(); } // re-write mGroupIndex so that it marks the // last reflection of each group. index=mGroupIndex; mGroupIndex.resize(mNbGroup); long group=0; for(long i=0;i<mNbRefl;i++) if(index(i)!=group) mGroupIndex(group++)=i; mGroupIndex(mNbGroup-1)=mNbRefl; } } else {// if there are no observed values, enter dummy ones mObsIntensity.resize(mNbRefl); mObsSigma.resize(mNbRefl); mWeight.resize(mNbRefl); mObsIntensity=100.; mObsSigma=1.; mWeight=1.; mFhklObsSq.resize(0); mClockFhklObsSq.Click(); } VFN_DEBUG_EXIT("DiffractionDataSingleCrystal::SortReflectionBySinThetaOverLambda()",5) return index; }