vint8 class_interpreter::check_command_duplicates() { vint8 module_number = modules.size (); vector <char*> commands; vint8 counter; for (counter = 0; counter <module_number; counter ++) { modules[(vector_size) counter]->get_commands(& commands); } sort (commands.begin (), commands.end (), CharpLess()); vint8 number = commands.size (); vPrint ("%li commands found.\n", number); vint8 flag = 0; for (counter = 0; counter < number-1; counter ++) { if (function_compare_strings(commands[(vector_size) counter], commands [(vector_size) (counter + 1)]) == 0) { vPrint("duplicate command: %s\n", commands[(vector_size) counter]); flag = 1; } } if (flag == 0) { vPrint ("no duplicates were found\n"); } return 1; }
// This command allows us to process text commands that are // stored in a file. vint8 class_interpreter::process_command_file() { char buffer[500]; vPrint("Input name of command file: "); vScan("%s", buffer); return process_command_file1(buffer); }
vint8 class_interpreter::main_loop(vint8 argc, char ** argv) { // If there was a command-line argument, we need to just process a script file. if (argc > 1) { if (argc != 2) { exit_error("usage: %s [script_file]\n", argv[0]); } const char * script_file = argv[1]; process_command_file1(script_file); return 0; } // If no arguments were passed, then we just start the interactive // loop. char command[1000]; while(1) { vPrint(">> "); vScan("%s", command); vint8 return_code = process_command(command); // if the user decided to exit... if (return_code == 2) { break; } } return 0; }
vint8 class_base_module::set_data_dir() { // Added by Diego if (!g_data_directory) std::cout << "There is no current data directory" << std::endl; else std::cout << "The current data directory is:\n\t" << g_data_directory << std::endl; char buffer[1000]; vPrint("\nenter new directory:\n"); vScan("%s", buffer); // Added by Diego if (strlen(buffer) <= 1) { std::cout << "The data directory was not updated" << std::endl; return 1; } else { std::cout << "The data directory was changed to:\n\t" << g_data_directory << std::endl; } vdelete2(g_data_directory); g_data_directory = vCopyString(buffer); return 1; }
vint8 class_base_module::set_code_dir() { char buffer[1000]; vPrint("\nenter new directory:\n"); vScan("%s", buffer); vdelete2(g_code_directory); g_code_directory = vCopyString(buffer); return 1; }
vint8 class_base_module::set_nessie() { char buffer[1000]; vPrint("\nenter new directory:\n"); vScan("%s", buffer); vdelete2(nessie); nessie = vCopyString(buffer); return 1; }
const void QuaternionManipulator::qPrintAngleAxis(const std::string& s, const Quaternion& q) { std::cout << s << " = "; float thetaf; Vector axis_f; qToAngleAxis(q, thetaf, axis_f); std::cout << "angle = " << thetaf << " "; vPrint("axis", axis_f); }
list<InterestingDecayBetaGamma* > DataQueryBetaGamma::RunQuery(double minBeta, double maxBeta) const { vPrint(4,"Query parameters: Min beta time: %f s, max beta time: %f s.\n", minBeta, maxBeta); list<InterestingDecayBetaGamma* > toReturn; map< Nukleid, Isotop*> myIsotopeMap = myENSDF->getAllIsotopes(); vPrint(4,"Searching through isotopes.\n"); for(map< Nukleid, Isotop*>::iterator it = myIsotopeMap.begin(); it!=myIsotopeMap.end(); it++) { list<InterestingDecayBetaGamma* > tempList = DetectInterestingStuffWithThisIsotope(it->second, minBeta, maxBeta); toReturn.insert(toReturn.end(), tempList.begin(), tempList.end()); } vPrint(5, "Number of interesting decays: %d", toReturn.size()); for(list<InterestingDecayBetaGamma*>::iterator it = toReturn.begin(); it!=toReturn.end(); it++) { vPrint(3,"%s\n",(*it)->toString(0,0).c_str()); } return toReturn; }
void QuaternionManipulator::qtest2() { HEADER("TEST 2 : Rotation of 90 degrees about the y-axis with matrix") Vector axis = {0.0f, 1.0f, 0.0f, 1.0f}; Quaternion q = qFromAngleAxis(90.0f, axis); qPrint(" q", q); Vector vi = {7.0f, 0.0f, 0.0f, 1.0f}; vPrint("vi", vi); Vector ve = {0.0f, 0.0f, -7.0f, 1.0f}; vPrint("ve", ve); Matrix m; qGLMatrix(q,m); Vector vf = mMultiply(m, vi); vPrint("vf", vf); assert(vEqual(vf, ve)); }
vint8 class_interpreter::list_commands() { vint8 module_number = modules.size (); vector <char*> commands; vint8 counter; for (counter = 0; counter <module_number; counter ++) { modules[(vector_size) counter]->get_commands(& commands); } sort (commands.begin (), commands.end (), CharpLess()); vint8 number = commands.size (); vPrint ("%li commands found.\n", number); for (counter = 0; counter < number-1; counter ++) { vPrint ("%s\n", commands[(vector_size) counter]); } return 1; }
vint8 class_interpreter::process_command(const char * command) { if (command == 0) return 0; if (command[0] == 0) return 0; if (strcmp(command, "file") == 0) { process_command_file(); return 1; } if (strcmp(command, "system") == 0) { char system_command[1000]; vGetNonEmptyLine(system_command, 990); system(system_command); return 1; } if (strcmp(command, "x") == 0) { // 2 signifies we should exit. vMainWindowToForeground(); return 2; } vint8 number = modules.size(); vint8 success = 0; vint8 i; for (i = 0; i < number; i++) { vint8 success = modules[(vector_size) i]->process_command(command); if (success == 1) { return 1; } } // we only get here if success is 0. vPrint("??? %s is not a recognized command\n", command); return 1; }
vint8 class_interpreter::process_command_file2(const char * pathname) { // Possibly we are already executing commands from another // file and one of those asks us to execute this file. Then, // we must save the previous FILE * object, process the // new file, and then restore the previous file. FILE * previous_input_file_pointer = 0; // If we are processing another command file, save the status // of that file if (input_file_pointer != 0) { previous_input_file_pointer = input_file_pointer; } // Open the requested file, return failure if we can't open it. input_file_pointer = fopen(pathname, vFOPEN_READ); if (input_file_pointer == 0) { vPrint("Can't find input file %s\n", pathname); input_file_pointer = previous_input_file_pointer; return 0; } // Process commands from the file until we read all the contents // of the file. If there is nothing more to read, we are done while(1) { char command[100]; vint8 items = vScan("%s", command); // If we reached the end of file (or a read error has occured) // we are done. if (items != 1) break; process_command(command); } fclose(input_file_pointer); // Restore the previous file (if any) input_file_pointer = previous_input_file_pointer; return 1; }
const LevelRecord * DataQueryBetaGamma::findNextLevel(const Dataset * datasetToCheck, const GammaRecord * gammaToMatch) const { if(gammaToMatch->getLevelRecord()==NULL) { vPrint(3,"WARNING: No level record for this gamma record: %s\n", gammaToMatch->getCardStrings().front().c_str()); return NULL; } double guessedLevelEnergy = (gammaToMatch->getLevelRecord()->getEnergy() - gammaToMatch->getDecayEnergy()); double bestMatch = 1E99; LevelRecord * found = NULL; list<LevelRecord *> myLevelRecords = datasetToCheck->getLevelRecords(); for(list<LevelRecord* >::iterator it = myLevelRecords.begin(); it!=myLevelRecords.end(); it++) { //vPrint(17,"Comparing energy %f with guessed energy %f, the gamma energy was %f.\n", (*it)->getEnergy(), guessedLevelEnergy, gammaToMatch->getDecayEnergy()); double tmp = fabs((*it)->getEnergy()-guessedLevelEnergy); if(tmp<bestMatch && (tmp<guessedLevelEnergy*0.3 || tmp<100 )) //allow 10 % difference or 10 keV difference. { bestMatch = tmp; found = *it; } } return found; }
VOID vFormatAndPrint( IN DWORD dwMsgId ) { // // It would have been so easy to use // CString MessageText; // MessageText.FormatMessage(dwMsgId); // But what happens if the error message is that we are out of memory. // CString allocates memory, so CString might fail, the message might not // get printed, and the user wont know what happened to the program. // Therefore, we cannot use dynamic allocation of mem here. // TCHAR szMessageText[ERROR_MESSAGE_NUMCHARS]; if ( ! LoadString( (HINSTANCE)GetModuleHandle(NULL),// handle to resource module dwMsgId, // resource identifier szMessageText, // resource buffer ERROR_MESSAGE_NUMCHARS ) // num chars in buffer ) { // // The size of 1024 is big enough. But if for some reason, the error // message becomes real big, the buffer will be filled with part of the // message. But no crash will happen. The only other thing we need to // check for is whether LoadString() could actually find the string with the // corresponding dwMsgID. In this case, we cant print anything, so we // quietly return. // return; } vPrint(szMessageText); return; }
//=============================================== // Unit Tests //=============================================== int main() { // set for command line argument -t to run unit tests. bool test = true; if (test) { std::cout<<"\n=================\nBegin UNIT TESTS\n=================\n\n"; Light::Light n = *new Light::Light(0, 1, 1, 0, 0.5, 0.5, 0.5); n.print(); Intersect::Intersect i = *new Intersect::Intersect(); if(i.isHit()) { std::cout<<"INCORRECT! hit is true.\n\n"; } else { std::cout<<"CORRECT! hit is false.\n\n"; i.setHit(true); } if(i.isHit()) { std::cout<<"CORRECT! hit is true.\n\n"; } else { std::cout<<"INCORRECT! hit is false.\n\n"; } std::vector<float> ptest(3); ptest[0] = 0; ptest[1] = 1; ptest[2] = 2; i.setPoint(ptest); std::vector<float> p = i.getPoint(); std::cout<< "[" << p[0] << ", " << p[1] << ", " << p[2] << "]\n"; Vertex::Vertex a = *new Vertex::Vertex(0,0,0); Vertex::Vertex b = *new Vertex::Vertex(1,0,0); Vertex::Vertex c = *new Vertex::Vertex(0,1,0); a.print(); a = a.sub(b); a.print(); std::vector<float> d = c.toVec(); std::cout<<"vec ["<< d[0] << ", " << d[1] << ", " << d[2] << "]\n"; Vertex::Vertex e1 = *new Vertex::Vertex(d); e1.print(); Vertex a1 = *new Vertex::Vertex(0,1,0); Vertex b1 = *new Vertex::Vertex(1,-1,0); Vertex c1 = *new Vertex::Vertex(-1,-1,0); Triangle t = *new Triangle::Triangle(a1,b1,c1); p[0] = 0; p[1] = 0; p[2] = 0; std::vector<float> e(3); e[0] = 0; e[1] = 0; e[2] = 3; Ray::Ray r = *new Ray::Ray(e, p); i = t.intersect(r); if (i.isHit()) { std::cout<<"Triangle Intersected - OKAY\n"; } Sphere::Sphere s = *new Sphere::Sphere(1, p); if (s.intersect(r).isHit()) { std::cout<<"Sphere Intersected - OKAY\n"; } e[0] = 0; e[1] = -4; e[2] = -4; p[0] = 1; p[1] = 1; p[2] = -1; r.setEye(e); r.setPoint(p); std::cout<<"projected "; vPrint(r.project(1.5)); PPM* ppm = new PPM(640, 480, 255); int val; for (float h = 0; h<480; h++) { for (float w =0; w<640; w++) { val = h;//std::min(255, (int)((w/639)*255.0f)); ppm->addPixel(*(new Pixel::Pixel(val, val, val))); } } ppm->save("output"); /* for (float h = 0; h < 3; h++) { for (float w = 0; w< ppm->getW(); w++) { std::cout<<w<<" "; ppm->getPixel(w, h).print(); } } */ std::cout<<"End PPM tests\n"; Pixel::Pixel px = *new Pixel::Pixel(255, 255, 255); Pixel::Pixel black = *new Pixel::Pixel(0,0,0); Pixel::Pixel pfloat = *new Pixel::Pixel(1.0f, 0.9f, 0.05f); Pixel::Pixel pmax = *new Pixel::Pixel(2.0f, 1.0f, 0.5f); px.print(); black.print(); black.add(px); black.print(); pfloat.print(); pmax.print(); std::vector<float> test1(3); test1[0] = 1; test1[1] = 0; test1[2] = 0.5; std::vector<float> test2(3); test2[0] = 0; test2[1] = 1; test2[2] = 0.5; std::cout<<vDot(test1, test2)<<"\n"; vPrint(vSub(test1, test2)); vPrint(vAdd(test1, test2)); vPrint(vMult(test1, test2)); vPrint(normalize(test1)); vPrint(normalize(test2)); vPrint(vCross(test1, test2)); vPrint(vScale(-1, test1)); std::cout<<"\n=================\nEnd UNIT TESTS\n=================\n\n"; return 0; } else { return 0; } }
TEST(VariadicTemplate, VariadicPrintf) { using Dog = smart_pointer::Dog; Dog dog("Henry"); vPrint("hello\n", std::string("world\n"), 'h', '\n', 10, '\n', 11.111, '\n', dog, '\n'); }
void cdecl Print (DWORD level, LPTSTR pszLine, ...) { va_list arg; va_start (arg, pszLine); vPrint (level, pszLine, arg); }
list<InterestingDecayBetaGamma* > DataQueryBetaGamma::DetectInterestingStuffWithThisIsotope(const Isotop * isotopToCheck, double minBeta, double maxBeta) const { list<InterestingDecayBetaGamma* > toReturn; vPrint(7, "Searching through isotope %s.\n", isotopToCheck->getNukleid().toString().c_str()); list<Dataset* > myDatasets = isotopToCheck->getDatasets(); vPrint(9, "%d datasets to search.\n",myDatasets.size()); for(list<Dataset* >::iterator ir = myDatasets.begin(); ir!=myDatasets.end(); ir++) { vPrint(15, "Searching through a dataset within isotope %s.\n", isotopToCheck->getNukleid().toString().c_str()); list<LevelRecord *> myLevelsList = (*ir)->getLevelRecords(); myLevelsList.sort(&CompareElementsForSort); vector<LevelRecord *> myLevels; vPrint(22, "We have the following levels:\n"); for(list<LevelRecord *>::iterator it = myLevelsList.begin(); it!=myLevelsList.end(); it++) { if(*it!=NULL) { myLevels.push_back(*it); vPrint(22,"Energy: %f, HalfLife: %f\n", (*it)->getEnergy(), (*it)->getHalfLife()); } } //now create decay matrix. vector<vector<double> > adjacencyMatrix; adjacencyMatrix.push_back(vector<double>()); //first row and column contains BETA information (in practice only first row...) for(vector<LevelRecord *>::const_iterator it = myLevels.begin(); it!=myLevels.end(); it++) { adjacencyMatrix.push_back(vector<double>()); } for(vector<vector<double> >::iterator it = adjacencyMatrix.begin(); it!=adjacencyMatrix.end(); it++) { for(unsigned int i = 0; i<adjacencyMatrix.size(); i++) it->push_back(0); } vPrint(16,"Decay matrix created.\n"); vector<vector<double> > finalAdjacencyMatrix = adjacencyMatrix; list<GammaRecord *> myGammas = (*ir)->getGammaRecords(); for(list<GammaRecord *>::iterator it = myGammas.begin(); it!=myGammas.end(); it++) { const LevelRecord * Lstart = (*it)->getLevelRecord(); const LevelRecord * Lend = findNextLevel(*ir, *it); if(Lstart==NULL || Lend==NULL) { vPrint(7, "NULL level detected.\n"); if(Lstart!=NULL) vPrint(8,"SLevel: %f\n", Lstart->getEnergy()); if(Lend!=NULL) vPrint(8,"ELevel: %f\n", Lend->getEnergy()); vPrint(8,"Gamma: %f\n", (*it)->getDecayEnergy()); list<GammaRecord *>::iterator ir = it; it++; myGammas.erase(ir); it--; } else { unsigned int startP = -1, stopP = -1; unsigned int count = 1; for(vector<LevelRecord *>::const_iterator ia = myLevels.begin(); ia!=myLevels.end(); ia++) { if((*ia)==Lstart) startP = count; if((*ia)==Lend) stopP = count; ++count; } if(startP<0 || stopP<0) //if this happens, something is terribly wrong with the program. throw DataFileException("Pointer went out of bounds."); else if(startP==stopP) //if this happens, it means the level the gamma left from is the same as the level it fell to. Cannot be allowed. { vPrint(8, "Warning: Gamma level without energy detected."); list<GammaRecord *>::iterator ir = it; it++; myGammas.erase(ir); it--; } else { vPrint(22, "startP: %d, stopP: %d\n", startP, stopP); adjacencyMatrix[startP][stopP]=(*it)->getTransitionIntensity(); //+1 corrected for. //from startP level to stopP level. } } } #ifdef SLOWDEBUG //now the adjacency matrix is filled with the intensities... vPrint(16,"Adjacency matrix filled with intensities:\n"); for(unsigned int i = 0; i<adjacencyMatrix.size(); i++){ for(unsigned int j = 0; j<adjacencyMatrix.size(); j++) vPrint(20, "%f ", adjacencyMatrix[i][j]); vPrint(20,"\n"); } #endif list<BetaRecordWrapper*> foundBetas; list<BetaRecordWrapper*> myBetaRecords = (*ir)->getBetaRecords(); for(list<BetaRecordWrapper*>::const_iterator it = myBetaRecords.begin(); it!=myBetaRecords.end(); it++) { const ParentRecord * P = (*it)->getParentRecord(); if(P!=NULL && minBeta<=P->getHalfLife() && maxBeta>=P->getHalfLife()) { foundBetas.push_back(*it); } #ifdef SLOWDEBUG else { if(P==NULL) vPrint(18,"Not adding beta, parent null.\n"); else vPrint(18,"Not adding beta, half-life %f, parent %s.\n", P->getHalfLife(), P->getNukleid().toString().c_str()); } #endif } for(list<BetaRecordWrapper*>::const_iterator it = foundBetas.begin(); it!=foundBetas.end(); it++) { list<BetaRecordWrapper*>::const_iterator ip = it; for(ip++; ip!=foundBetas.end(); ip++) { if((*it)->getLevelRecord()==(*ip)->getLevelRecord()) { vPrint(22,"Energy: %f, HalfLife: %f\n", (*it)->getLevelRecord()->getEnergy(), (*it)->getLevelRecord()->getHalfLife()); vPrint(22, "B1: %s.\n", (*it)->getCardStrings().front().c_str()); vPrint(22, "B2: %s.\n", (*ip)->getCardStrings().front().c_str()); throw DataFileException("Two different betas goes to the same level."); } } } if(foundBetas.size()>0 && myGammas.size()>0) { //Now add beta intensity to each level... double levelSum = 0; for(list<BetaRecordWrapper*>::const_iterator it = foundBetas.begin(); it!=foundBetas.end(); it++) { unsigned int toLevel = -1; int count = 0; for(vector<LevelRecord *>::const_iterator ip = myLevels.begin(); ip!=myLevels.end(); ip++) { ++count; if((*it)->getLevelRecord()==(*ip)) { toLevel = count; break; } } if(toLevel<0) throw DataFileException("LevelRecord not found!"); adjacencyMatrix[0][toLevel] = (*it)->getIntensityOfBetaDecayBranch()/100; #ifdef SLOWDEBUG vPrint(20, "Beta intensity: %f, to level %d.\n",adjacencyMatrix[0][toLevel], toLevel); //+1 corrected for. #endif levelSum +=adjacencyMatrix[0][toLevel]; } finalAdjacencyMatrix[0][0] = levelSum; //now normalize outgoing intensity from a level to 1. vPrint(15, "Now normalizing...\n"); for(unsigned int i = 1; i<adjacencyMatrix.size(); i++) { double rowSum = 1E-90; for(unsigned int j = 1; j<adjacencyMatrix.size(); j++) { rowSum+=adjacencyMatrix[i][j]; } for(unsigned int j = 1; j<adjacencyMatrix.size(); j++) { adjacencyMatrix[i][j]/=rowSum; } } #ifdef SLOWDEBUG vPrint(20,"New normalized matrix:\n"); for(unsigned int i = 0; i<adjacencyMatrix.size(); i++){ for(unsigned int j = 0; j<adjacencyMatrix.size(); j++) vPrint(20, "%f ", adjacencyMatrix[i][j]); vPrint(20,"\n"); } #endif //now compute final Gamma intensities. vPrint(16,"Final Gamma intensities computed.\n"); for(unsigned int i = 0; i<adjacencyMatrix.size(); i++) { #ifdef SLOWDEBUG vPrint(20,"%f ", finalAdjacencyMatrix[i][0]); #endif for(unsigned int j = 1; j<adjacencyMatrix.size(); j++) { finalAdjacencyMatrix[i][j] = adjacencyMatrix[i][j]*finalAdjacencyMatrix[i][0]; #ifdef SLOWDEBUG vPrint(20,"%f ", finalAdjacencyMatrix[i][j]); #endif finalAdjacencyMatrix[j][0]+= finalAdjacencyMatrix[i][j]; } #ifdef SLOWDEBUG vPrint(20,"\n"); #endif } //adjacency matrix computation completed! toReturn.push_back( new InterestingDecayBetaGamma( finalAdjacencyMatrix, myLevels, foundBetas, foundBetas.front()->getParentRecord()->getNukleid(), myMassTable->getMassObject(foundBetas.front()->getParentRecord()->getNukleid()), myMassTable->getMassObject(foundBetas.front()->getNukleid()))); vPrint(12,"New InterestingDecay object created.\n"); } else { vPrint(16, "No suitable Beta records found for isotope %s.\n",isotopToCheck->getNukleid().toString().c_str()); vPrint(16, "Stats: Number of found betas: %d, total: %d, number of gammas: %d.\n", foundBetas.size(),myBetaRecords.size(), myGammas.size()); } } vPrint(15,"All interesting decays for this isotope detected.\n"); return toReturn; }
void cdecl Print (LPTSTR pszLine, ...) { va_list arg; va_start (arg, pszLine); vPrint (dlSTANDARD, pszLine, arg); }