//***************************************************************** // File name: TestSpectrum.cpp // // Classes defined: // none // // Classes referenced: // SpeHeader -- Member class to read spectral header // MFMData -- Member class to read MFM data // FSMStepHeader -- Member class to read an FSM step header // FSMStepData -- Member class to read one step of FSM data // B3Spectrum -- Base class to read an ASCII spectral file // // Classes referenced: // none // // Purpose: Sample code to demonstrate the use of the B3Spectrum // class. Invokes B3Spectrum to read every spectrum and verify // the format and internal consistency of a Pioneer 10/11 // spectral file. // // General design philosophy: // 1) Code is designed to resemble JAVA. // 2) Most constructors call other functions to open, read, // and close files and perform calculations. These other // functions may have more general application. // 3) Text files are read line by line, converted to string // streams and tokenized using the '<<' opperator. // 4) The STL String class is used to represent character // strings. Strings are passed by value to take advantage of // the translation capability of the copy constructor. // 5) Classes, structures and arrays are passed by reference // whenever possible. // 6) Variables of member classes are left public. For // other classes, variables are protected and accessed by // access functions. // // Notes and warnings: This code compiles and runs correctly // under Borland C++ version 5.1 on a Windows 95 system with 32 // MB of memory. It should run on most other systems and // compilers, but it may be necessary to change the names of // the files on some systems. There may also be // problems with use of STRING variables under non-standard // implementations of the Standard Template Library. // // Author: P. R. Gazis 16-MAY-1999 // Modified: 30-JUN-1999 //***************************************************************** #include #include #include #include #include #include #include #include // Classes from the Standard Template Library #include using namespace std; // #include "h:\b3spectra\cppcode\B3Spectrum.cpp" #include "B3Spectrum.cpp" //***************************************************************** // Main routine // // Purpose: Query user to get input filespec for a Pioneer 10/11 // spectral file. Then invoke class B3Spectrum and read // through the spectral file to verify that the format is // correct and the headers and data are internally consistent. // // Functions: // main() -- main routine // // Author: P. R. Gazis 17-MAY-1999 // Modified: 30-JUN-1999 //***************************************************************** //***************************************************************** // main() -- Verify Pioneer 10/11 ASCII spectral file main() { cout << "TestSpectrum: And so it begins...\n"; // Get control parameters cout << "TestSpectrum: Enter speFileSpec\n"; string speFileSpec; cin >> speFileSpec; // Instantiate B3Spectrum; B3Spectrum spectrum( speFileSpec); // Loop: Read spectral file until done for( int i = 0; i < 100; i++) { if( spectrum.isSpeFileOpen() == 0) break; spectrum.read(); if( spectrum.eof() != 0) { cout << "TestSpectrum: finished with " << i << " cycles\n"; break; } } // Report accounting information cout << "TestSpectrum\n" << " nSpectra: " << setw( 7) << spectrum.nSpectra() << "\n" << " nSpeHeaders: " << setw( 7) << spectrum.nSpeHeaders() << " " << setw( 7) << spectrum.nBadSpeHeaders() << "\n" << " nMFMRecords: " << setw( 7) << spectrum.nMFMRecords() << " " << setw( 7) << spectrum.nBadMFMRecords() << " " << setw( 7) << spectrum.nBadMFMValuesA() << " " << setw( 7) << spectrum.nBadMFMValuesB() << "\n" << " nFSMStepHeaders: " << setw( 7) << spectrum.nFSMStepHeaders() << " " << setw( 7) << spectrum.nBadFSMStepHeaders() << "\n" << " nFSMStepRecords: " << setw( 7) << spectrum.nFSMStepRecords() << " " << setw( 7) << spectrum.nBadFSMStepRecords() << " " << setw( 7) << spectrum.nBadFSMStepValuesA() << " " << setw( 7) << spectrum.nBadFSMStepValuesB() << "\n" << " nRecs: " << setw( 7) << spectrum.nRecs() << "\n"; // Close files and terminate routine cout << "\n"; cout << "TestSpectrum: Th-th-th-that's all, folks!\n"; }