void BufferConverters::charToFloatInterleaved( float* f, const char* rc, const char* lc, int n ) { for (int i = 0; i < n; i++) { charToFloat( f[2*i+0], rc[2*i], rc[2*i+1] ); charToFloat( f[2*i+1], lc[2*i], lc[2*i+1] ); } }
void BufferConverters::charToFloat( float* f, const char* c, int n ) { for (int i = 0; i < n; i++) { charToFloat( f[i], c[2*i], c[2*i+1] ); } }
// PARSER float parser::parseDigit(char *p, int &iStartParse, bool bReturnParseIndex, bool bIsNegative) { // Max len of float digit const int iFloatRange = 8; char cDigitStrPart[iFloatRange]; int i = iStartParse, k = 0; int iSingModifier=bIsNegative ? -1 :1; for (; p[i] && (isDigit(p[i]) || p[i] == '.'); i++, k++) cDigitStrPart[k] = p[i]; cDigitStrPart[k] = '\0'; if (bReturnParseIndex) iStartParse = i-1; return charToFloat(cDigitStrPart,0,k-1) * iSingModifier; }
//----------------------------------------------------------------------------- void GuiEditor::valueChanged (CControl* control) { //effect->setParameterAutomated (control->getTag (), control->getValue ()); float value; int ival; const char* text; std::string result; char* tempt; switch (control->getTag()) { case kBufferSize: ((COptionMenu*)(control))->getCurrent(tempt); ival = ((COptionMenu*)(control))->getIndex(tempt); updateBufferSize(ival); break; case kGain: value = control->getValue(); result = floatToString(value*maxGain); gainDisplay->setText(result.c_str()); updateGain(value*maxGain); break; case kGainText: text = ((CTextEdit*)(control))->getText(); value = charToFloat(text); gainFader->setValue(value/(float)maxGain); updateGain(value); break; case kXScale: value = control->getValue(); result = floatToString(value*maxXScale); xScaleDisplay->setText(result.c_str()); updateXScale(value*maxXScale); break; case kXScaleText: text = ((CTextEdit*)(control))->getText(); value = charToFloat(text); xScaleFader->setValue(value/(float)maxXScale); updateXScale(value); break; case kYScale: value = control->getValue(); result = floatToString(value*maxYScale); yScaleDisplay->setText(result.c_str()); updateYScale(value*maxYScale); break; case kYScaleText: text = ((CTextEdit*)(control))->getText(); value = charToFloat(text); yScaleFader->setValue(value/(float)maxYScale); updateYScale(value); break; case kResponse: value = control->getValue(); result = floatToString(value); responseDisplay->setText(result.c_str()); updateResponse(value); break; case kResponseText: text = ((CTextEdit*)(control))->getText(); value = charToFloat(text); responseFader->setValue(value); updateResponse(value); break; case kBands: ival = (int)(control->getValue()*maxBands); result = intToString(ival); bandsDisplay->setText(result.c_str()); bandsFader->setValue(((float)ival)/(float)maxBands); updateBands(ival); break; case kBandsText: text = ((CTextEdit*)(control))->getText(); ival = charToInt(text); bandsFader->setValue((float)value/(float)maxBands); updateBands(ival); break; case kAmpScale: ((COptionMenu*)(control))->getCurrent(tempt); ival = ((COptionMenu*)(control))->getIndex(tempt); updateAmpScale(ival); break; case kType: ((COptionMenu*)(control))->getCurrent(tempt); ival = ((COptionMenu*)(control))->getIndex(tempt); updateType(ival); break; case kDisplay: ((COptionMenu*)(control))->getCurrent(tempt); ival = ((COptionMenu*)(control))->getIndex(tempt); updateDisplayt(ival); break; case kResampling: ((COptionMenu*)(control))->getCurrent(tempt); ival = ((COptionMenu*)(control))->getIndex(tempt); updateResampling(ival); break; case kFreqScale: ((COptionMenu*)(control))->getCurrent(tempt); ival = ((COptionMenu*)(control))->getIndex(tempt); updateFreqScale(ival); break; case kAddress: text = ((CTextEdit*)(control))->getText(); updateAddress(text); break; case kPort: text = ((CTextEdit*)(control))->getText(); ival = charToInt(text); updatePort(ival); break; case kHost: text = ((CTextEdit*)(control))->getText(); updateHost(text); break; } }
Structure* PDBReader::readStructure(Alphabet* alphabet, char* filename, const char* backboneAtomName) { FILE* infile = fopen(filename, "r"); if (infile == NULL) { return 0; } Structure* structure = new Structure(alphabet, filename); // Create the entries from the PDB file. char recordType[7]; char serialNumber[6]; char atomName[5]; char altLoc[2]; char residueName[4]; char chain[2]; char resID[5]; char insertion[2]; char x[9]; char y[9]; char z[9]; // Go through the file and parse out the records. char line[1024]; Coordinate3D backboneCoord; Residue* currentResidue = NULL; while (!feof(infile)) { // Get the next line. if (fgets(line, 1023, infile) == NULL) break; // Make sure this is an atom or hetatom record. parseField(recordType, line, 0, 6); if (strcmp(recordType, "ATOM") == 0 || strcmp(recordType, "HETATOM") == 0) { // Parse the fields. parseField(serialNumber, line, 6, 5); parseField(atomName, line, 12, 4); parseField(altLoc, line, 16, 1); parseField(residueName, line, 17, 3); parseField(chain, line, 21, 1); parseField(resID, line, 22, 4); parseField(insertion, line, 26, 1); parseField(x, line, 30, 8); parseField(y, line, 38, 8); parseField(z, line, 46, 8); // If this is a new residue, save the old one (if we have one) and start over. if (currentResidue == NULL || (strcmp(resID, currentResidue->getResID()) != 0 || strcmp(insertion, currentResidue->getInsertionName()) != 0)) { if (currentResidue != NULL) { structure->addResidue(currentResidue->getName(), backboneCoord, currentResidue); } // Start the new residue. backboneCoord.unset(); currentResidue = new Residue(residueName, resID, insertion); } // If this is a backbone atom, save it. if (strcmp(atomName, backboneAtomName) == 0) { backboneCoord.set(charToFloat(x), charToFloat(y), charToFloat(z)); } // Add the atom to the list. currentResidue->addAtom(new Atom(atomName, charToFloat(x),charToFloat(y),charToFloat(z))); } else if (strcmp(recordType, "TER") == 0) { break; } } // If we have one last residue, save it. if (currentResidue != NULL) { structure->addResidue(currentResidue->getName(), backboneCoord, currentResidue); } fclose(infile); return structure; }