Example program for handling errors in the Mascot results files.
/* ############################################################################## # file: resfile_error.cpp # # 'msparser' toolkit example code # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1998-2005 Matrix Science Limited All Rights Reserved. # # # ############################################################################## # $Source: parser/examples/test_cxx/resfile_error.cpp $ # # $Author: villek@matrixscience.com $ # # $Date: 2018-07-30 16:23:53 +0100 $ # # $Revision: 1b450440f9c97e1e41d0fc6016a27d68951d4532 | MSPARSER_REL_2_8_1-0-gea32989045 $ # # $NoKeywords:: $ # ############################################################################## */ #include "msparser.hpp" #include <iostream> #include <time.h> #include <iomanip> // All the classes are part of the matrix_science namespace using namespace matrix_science; /*****************************************************************************/ /* Local functions */ /* (This test harness is 'C' and not C++) */ /*****************************************************************************/ static void checkErrorHandler(ms_mascotresfile & file); /*****************************************************************************/ /* main */ /* Call this program with a single argument - the name of the .dat file */ /*****************************************************************************/ int main(int argc, char * argv[]) { if (argc == 2) { ms_mascotresfile file(argv[1]); if (file.isValid()) { checkErrorHandler(file); } else std::cout << "Error: " << file.getLastErrorString() << std::endl; } else std::cout << "Must supply the name of a .dat file as a command line argument" << std::endl; return 0; } /*****************************************************************************/ /* checkErrorHandler */ /* Calls a couple of functions with invalid arguments */ /*****************************************************************************/ static void checkErrorHandler(ms_mascotresfile & file) { std::cout << "Testing the error handling... " << std::endl; std::cout << "=========================================" << std::endl; int numQueries = file.getNumQueries(); file.getObservedCharge(numQueries + 40); // Should fail std::cout << "Error number: " << file.getLastError() << std::endl; std::cout << "Error string: " << file.getLastErrorString() << std::endl; file.clearAllErrors(); std::cout << "Cleared all errors - should have no errors left: " << file.getNumberOfErrors() << " errors left" << std::endl << std::endl; for (int x=1; x <= 20; x++) file.getObservedCharge(numQueries + x); // Should fail // Now, the best way, print out all errors. std::cout << "More errors added - there are now " << file.getNumberOfErrors() << " errors" << std::endl; for (int i=1; i <= file.getNumberOfErrors(); i++) { std::cout << "Error number: " << file.getErrorNumber(i) << " : " << file.getErrorString(i) << std::endl; } std::cout << std::endl; file.clearAllErrors(); } /* will give the output: # resfile_error_handling F981123.dat Testing the error handling... ========================================= Error number: 4 Error string: c:\inetpub\mascot\data\F981123.dat. Query out of range. In function getObservedCharge. Request query 44, num queries: 4 Cleared all errors - should have no errors left: 0 errors left More errors added - there are now 2 errors Error number: 4 : c:\inetpub\mascot\data\F981123.dat. Query out of range. In function getObservedCharge. Request query 5, num queries: 4 Error number: 4 : c:\inetpub\mascot\data\F981123.dat. Query out of range. In function getObservedCharge. Request query 6, num queries: 4 (Error repeated 19 times) */
Copyright © 2022 Matrix Science Ltd. All Rights Reserved. Generated on Thu Mar 31 2022 01:12:29 |