--- trunk/mdtools/md_code/InitializeFromFile.cpp 2002/07/09 18:40:59 11 +++ trunk/mdtools/md_code/InitializeFromFile.cpp 2002/10/31 21:20:49 162 @@ -9,14 +9,17 @@ #include #include "ReadWrite.hpp" +#include "simError.h" InitializeFromFile :: InitializeFromFile( char *in_name ){ c_in_file = fopen(in_name, "r"); if(c_in_file == NULL){ - printf("Cannot open file: %s\n", in_name); - exit(8); + sprintf(painCave.errMsg, + "Cannot open file: %s\n", in_name); + painCave.isFatal = 1; + simError(); } strcpy( c_in_name, in_name); @@ -28,7 +31,9 @@ InitializeFromFile :: ~InitializeFromFile( ){ int error; error = fclose( c_in_file ); if( error ){ - fprintf( stderr, "Error closing %s\n", c_in_name ); + sprintf( painCave.errMsg, + "Error closing %s\n", c_in_name ); + simError(); } return; } @@ -60,30 +65,35 @@ void InitializeFromFile :: read_xyz( SimInfo* entry_pl DirectionalAtom* dAtom; if( n_atoms != entry_plug->n_atoms ){ - fprintf( stderr, + sprintf( painCave.errMsg, "Initialize from File error. %s n_atoms, %d, " "does not match the BASS file's n_atoms, %d.\n", c_in_name, n_atoms, entry_plug->n_atoms ); - exit(8); + painCave.isFatal = 1; + simError(); } //read and toss the comment line eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); if(eof_test == NULL){ - printf("error in reading commment in %s\n", c_in_name); - exit(8); + sprintf( painCave.errMsg, + "error in reading commment in %s\n", c_in_name); + painCave.isFatal = 1; + simError(); } for( i=0; i < n_atoms; i++){ eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); if(eof_test == NULL){ - printf("error in reading file %s\n" - "natoms = %d; index = %d\n" - "error reading the line from the file.\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf(painCave.errMsg, + "error in reading file %s\n" + "natoms = %d; index = %d\n" + "error reading the line from the file.\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } foo = strtok(read_buffer, " ,;\t"); @@ -91,40 +101,47 @@ void InitializeFromFile :: read_xyz( SimInfo* entry_pl // check the atom name to the current atom if( strcmp( foo, atoms[i]->getType() ) ){ - fprintf( stderr, + sprintf( painCave.errMsg, "Initialize from file error. Atom %s at index %d " "in file %s does not" " match the BASS atom %s.\n", foo, i, c_in_name, atoms[i]->getType() ); - exit(8); + painCave.isFatal = 1; + simError(); } // get the positions foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading postition x from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading postition x from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &rx ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading postition y from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading postition y from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &ry ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading postition z from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading postition z from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &rz ); @@ -132,28 +149,34 @@ void InitializeFromFile :: read_xyz( SimInfo* entry_pl foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading velocity x from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading velocity x from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &vx ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading velocity y from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading velocity y from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &vy ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading velocity z from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading velocity z from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &vz ); @@ -164,37 +187,45 @@ void InitializeFromFile :: read_xyz( SimInfo* entry_pl foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading quaternion 0 from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf(painCave.errMsg, + "error in reading quaternion 0 from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &q[0] ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading quaternion 1 from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading quaternion 1 from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &q[1] ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading quaternion 2 from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading quaternion 2 from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &q[2] ); - + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading quaternion 3 from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading quaternion 3 from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &q[3] ); @@ -202,28 +233,34 @@ void InitializeFromFile :: read_xyz( SimInfo* entry_pl foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading angular momentum jx from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading angular momentum jx from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &jx ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading angular momentum jy from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading angular momentum jy from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &jy ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - printf("error in reading angular momentum jz from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, i ); - exit(8); + sprintf( painCave.errMsg, + "error in reading angular momentum jz from %s\n" + "natoms = %d, index = %d\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); } (void)sscanf( foo, "%lf", &jz );