Browse Source

Some minor changes (especially limiting the range of variables if

possible)
tempestpy_adaptions
Thomas Heinemann 13 years ago
committed by Lanchid
parent
commit
5c7c23f4d6
  1. 2
      src/exceptions/file_IO_exception.h
  2. 2
      src/exceptions/wrong_file_format.h
  3. 24
      src/parser/read_tra_file.cpp
  4. 3
      test/parser/readme.txt

2
src/exceptions/file_IO_exception.h

@ -2,7 +2,7 @@
* file_IO_exception.h
*
* Created on: 16.08.2012
* Author: thomas
* Author: Thomas Heinemann
*/
#ifndef MRMC_EXCEPTIONS_FILE_IO_EXCEPTION_H_

2
src/exceptions/wrong_file_format.h

@ -2,7 +2,7 @@
* wrong_file_format.h
*
* Created on: 16.08.2012
* Author: thomas
* Author: Thomas Heinemann
*/
#ifndef WRONG_FILE_FORMAT_H_

24
src/parser/read_tra_file.cpp

@ -40,10 +40,8 @@ static uint_fast32_t make_first_pass(FILE* p) {
pantheios::log_ERROR("make_first_pass was called with NULL! (SHOULD NEVER HAPPEN)");
throw exceptions::file_IO_exception ("make_first_pass: File not readable (this should be checked before calling this function!)");
}
char s[1024], states[7], transitions[12];
int rows=0, row=0, col=0, non_zero=0;
double val=0.0;
char s[1024]; //String buffer
uint_fast32_t rows=0, non_zero=0;
//Reading No. of states
if (fgets(s, 1024, p) != NULL) {
@ -64,6 +62,8 @@ static uint_fast32_t make_first_pass(FILE* p) {
//And increase number of transitions
while (NULL != fgets( s, 1024, p ))
{
uint_fast32_t row=0, col=0;
double val=0.0;
if (sscanf( s, "%d%d%lf", &row, &col, &val ) != 3) {
throw mrmc::exceptions::wrong_file_format();
}
@ -84,10 +84,8 @@ static uint_fast32_t make_first_pass(FILE* p) {
sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename) {
FILE *p;
char s[1024];
uint_fast32_t rows, row, col, nnz, non_zero;
double val = 0.0;
int count = 0;
char s[1024];
uint_fast32_t rows, non_zero;
sparse::StaticSparseMatrix<double> *sp = NULL;
p = fopen(filename, "r");
@ -108,8 +106,12 @@ sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename) {
}
}
//Reading No. of transitions
/* Reading No. of transitions
* Note that the result is not used in this function as make_first_pass()
* computes the relevant number (non_zero)
*/
if (fgets(s, 1024, p) != NULL) {
uint_fast32_t nnz=0;
if (sscanf( s, "TRANSITIONS %d", &nnz) == 0) {
throw mrmc::exceptions::wrong_file_format();
}
@ -133,6 +135,8 @@ sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename) {
//Reading transitions (one per line) and saving the results in the matrix
while (NULL != fgets( s, 1024, p ))
{
uint_fast32_t row=0, col=0;
double val = 0.0;
if (sscanf( s, "%d%d%lf", &row, &col, &val) != 3) {
throw mrmc::exceptions::wrong_file_format();
}
@ -142,12 +146,10 @@ sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename) {
pantheios::integer(row), " x ",
pantheios::integer(col));
sp->addNextValue(row,col,val);
++count;
}
(void)fclose(p);
pantheios::log_DEBUG("Written ", pantheios::integer(count), " Elements");
pantheios::log_DEBUG("Finalizing Matrix");
sp->finalize();
return sp;

3
test/parser/readme.txt

@ -0,0 +1,3 @@
Note: *.tra-Files starting with "wrong_format" are to produce an error when
being parsed. Hence, spelling errors and wrong formats are on purpose.
DO NOT CORRECT THEM!
Loading…
Cancel
Save