ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/md_code/InitializeFromFile.cpp
(Generate patch)

Comparing trunk/mdtools/md_code/InitializeFromFile.cpp (file contents):
Revision 11 by mmeineke, Tue Jul 9 18:40:59 2002 UTC vs.
Revision 162 by mmeineke, Thu Oct 31 21:20:49 2002 UTC

# Line 9 | Line 9
9   #include <sys/stat.h>
10  
11   #include "ReadWrite.hpp"
12 + #include "simError.h"
13  
14  
15   InitializeFromFile :: InitializeFromFile( char *in_name ){
16  
17    c_in_file = fopen(in_name, "r");
18    if(c_in_file == NULL){
19 <    printf("Cannot open file: %s\n", in_name);
20 <    exit(8);
19 >    sprintf(painCave.errMsg,
20 >            "Cannot open file: %s\n", in_name);
21 >    painCave.isFatal = 1;
22 >    simError();
23    }
24    
25    strcpy( c_in_name, in_name);
# Line 28 | Line 31 | InitializeFromFile :: ~InitializeFromFile( ){
31    int error;
32    error = fclose( c_in_file );
33    if( error ){
34 <    fprintf( stderr, "Error closing %s\n", c_in_name );
34 >    sprintf( painCave.errMsg,
35 >             "Error closing %s\n", c_in_name );
36 >    simError();
37    }
38    return;
39   }
# Line 60 | Line 65 | void InitializeFromFile :: read_xyz( SimInfo* entry_pl
65    DirectionalAtom* dAtom;
66  
67    if( n_atoms != entry_plug->n_atoms ){
68 <    fprintf( stderr,
68 >    sprintf( painCave.errMsg,
69               "Initialize from File error. %s n_atoms, %d, "
70               "does not match the BASS file's n_atoms, %d.\n",
71               c_in_name, n_atoms, entry_plug->n_atoms );
72 <    exit(8);
72 >    painCave.isFatal = 1;
73 >    simError();
74    }
75    
76    //read and toss the comment line
77    
78    eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
79    if(eof_test == NULL){
80 <    printf("error in reading commment in %s\n", c_in_name);
81 <    exit(8);
80 >    sprintf( painCave.errMsg,
81 >             "error in reading commment in %s\n", c_in_name);
82 >    painCave.isFatal = 1;
83 >    simError();
84    }
85  
86    for( i=0; i < n_atoms; i++){
87      
88      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
89      if(eof_test == NULL){
90 <      printf("error in reading file %s\n"
91 <             "natoms  = %d; index = %d\n"
92 <             "error reading the line from the file.\n",
93 <             c_in_name, n_atoms, i );
94 <      exit(8);
90 >      sprintf(painCave.errMsg,
91 >              "error in reading file %s\n"
92 >              "natoms  = %d; index = %d\n"
93 >              "error reading the line from the file.\n",
94 >              c_in_name, n_atoms, i );
95 >      painCave.isFatal = 1;
96 >      simError();
97      }
98  
99      foo = strtok(read_buffer, " ,;\t");
# Line 91 | Line 101 | void InitializeFromFile :: read_xyz( SimInfo* entry_pl
101      // check the atom name to the current atom
102  
103      if( strcmp( foo, atoms[i]->getType() ) ){
104 <      fprintf( stderr,
104 >      sprintf( painCave.errMsg,
105                 "Initialize from file error. Atom %s at index %d "
106                 "in file %s does not"
107                 " match the BASS atom %s.\n",
108                 foo, i, c_in_name, atoms[i]->getType() );
109 <      exit(8);
109 >      painCave.isFatal = 1;
110 >      simError();
111      }
112      
113      // get the positions
114  
115      foo = strtok(NULL, " ,;\t");
116      if(foo == NULL){
117 <      printf("error in reading postition x from %s\n"
118 <             "natoms  = %d, index = %d\n",
119 <             c_in_name, n_atoms, i );
120 <      exit(8);
117 >      sprintf( painCave.errMsg,
118 >               "error in reading postition x from %s\n"
119 >               "natoms  = %d, index = %d\n",
120 >               c_in_name, n_atoms, i );
121 >      painCave.isFatal = 1;
122 >      simError();
123      }
124      (void)sscanf( foo, "%lf", &rx );
125    
126      foo = strtok(NULL, " ,;\t");
127      if(foo == NULL){
128 <      printf("error in reading postition y from %s\n"
129 <             "natoms  = %d, index = %d\n",
130 <             c_in_name, n_atoms, i );
131 <      exit(8);
128 >      sprintf( painCave.errMsg,
129 >               "error in reading postition y from %s\n"
130 >               "natoms  = %d, index = %d\n",
131 >               c_in_name, n_atoms, i );
132 >      painCave.isFatal = 1;
133 >      simError();
134      }
135      (void)sscanf( foo, "%lf", &ry );
136      
137      foo = strtok(NULL, " ,;\t");
138      if(foo == NULL){
139 <      printf("error in reading postition z from %s\n"
140 <             "natoms  = %d, index = %d\n",
141 <             c_in_name, n_atoms, i );
142 <      exit(8);
139 >      sprintf( painCave.errMsg,
140 >               "error in reading postition z from %s\n"
141 >               "natoms  = %d, index = %d\n",
142 >               c_in_name, n_atoms, i );
143 >      painCave.isFatal = 1;
144 >      simError();
145      }
146      (void)sscanf( foo, "%lf", &rz );
147      
# Line 132 | Line 149 | void InitializeFromFile :: read_xyz( SimInfo* entry_pl
149  
150      foo = strtok(NULL, " ,;\t");
151      if(foo == NULL){
152 <      printf("error in reading velocity x from %s\n"
153 <             "natoms  = %d, index = %d\n",
154 <             c_in_name, n_atoms, i );
155 <      exit(8);
152 >      sprintf( painCave.errMsg,
153 >               "error in reading velocity x from %s\n"
154 >               "natoms  = %d, index = %d\n",
155 >               c_in_name, n_atoms, i );
156 >      painCave.isFatal = 1;
157 >      simError();
158      }
159      (void)sscanf( foo, "%lf", &vx );
160      
161      foo = strtok(NULL, " ,;\t");
162      if(foo == NULL){
163 <      printf("error in reading velocity y from %s\n"
164 <             "natoms  = %d, index = %d\n",
165 <             c_in_name, n_atoms, i );
166 <      exit(8);
163 >      sprintf( painCave.errMsg,
164 >               "error in reading velocity y from %s\n"
165 >               "natoms  = %d, index = %d\n",
166 >               c_in_name, n_atoms, i );
167 >      painCave.isFatal = 1;
168 >      simError();
169      }
170      (void)sscanf( foo, "%lf", &vy );
171      
172      foo = strtok(NULL, " ,;\t");
173      if(foo == NULL){
174 <      printf("error in reading velocity z from %s\n"
175 <             "natoms  = %d, index = %d\n",
176 <             c_in_name, n_atoms, i );
177 <      exit(8);
174 >      sprintf( painCave.errMsg,
175 >               "error in reading velocity z from %s\n"
176 >               "natoms  = %d, index = %d\n",
177 >               c_in_name, n_atoms, i );
178 >      painCave.isFatal = 1;
179 >      simError();
180      }
181      (void)sscanf( foo, "%lf", &vz );
182      
# Line 164 | Line 187 | void InitializeFromFile :: read_xyz( SimInfo* entry_pl
187        
188        foo = strtok(NULL, " ,;\t");
189        if(foo == NULL){
190 <        printf("error in reading quaternion 0 from %s\n"
191 <               "natoms  = %d, index = %d\n",
192 <               c_in_name, n_atoms, i );
193 <        exit(8);
190 >        sprintf(painCave.errMsg,
191 >                "error in reading quaternion 0 from %s\n"
192 >                "natoms  = %d, index = %d\n",
193 >                c_in_name, n_atoms, i );
194 >        painCave.isFatal = 1;
195 >        simError();
196        }
197        (void)sscanf( foo, "%lf", &q[0] );
198        
199        foo = strtok(NULL, " ,;\t");
200        if(foo == NULL){
201 <        printf("error in reading quaternion 1 from %s\n"
202 <               "natoms  = %d, index = %d\n",
203 <               c_in_name, n_atoms, i );
204 <        exit(8);
201 >        sprintf( painCave.errMsg,
202 >                 "error in reading quaternion 1 from %s\n"
203 >                 "natoms  = %d, index = %d\n",
204 >                 c_in_name, n_atoms, i );
205 >        painCave.isFatal = 1;
206 >        simError();
207        }
208        (void)sscanf( foo, "%lf", &q[1] );
209        
210        foo = strtok(NULL, " ,;\t");
211        if(foo == NULL){
212 <        printf("error in reading quaternion 2 from %s\n"
213 <               "natoms  = %d, index = %d\n",
214 <               c_in_name, n_atoms, i );
215 <        exit(8);
212 >        sprintf( painCave.errMsg,
213 >                 "error in reading quaternion 2 from %s\n"
214 >                 "natoms  = %d, index = %d\n",
215 >                 c_in_name, n_atoms, i );
216 >        painCave.isFatal = 1;
217 >        simError();
218        }
219        (void)sscanf( foo, "%lf", &q[2] );
220 <
220 >      
221        foo = strtok(NULL, " ,;\t");
222        if(foo == NULL){
223 <        printf("error in reading quaternion 3 from %s\n"
224 <               "natoms  = %d, index = %d\n",
225 <               c_in_name, n_atoms, i );
226 <        exit(8);
223 >        sprintf( painCave.errMsg,
224 >                 "error in reading quaternion 3 from %s\n"
225 >                 "natoms  = %d, index = %d\n",
226 >                 c_in_name, n_atoms, i );
227 >        painCave.isFatal = 1;
228 >        simError();
229        }
230        (void)sscanf( foo, "%lf", &q[3] );
231        
# Line 202 | Line 233 | void InitializeFromFile :: read_xyz( SimInfo* entry_pl
233        
234        foo = strtok(NULL, " ,;\t");
235        if(foo == NULL){
236 <        printf("error in reading angular momentum jx from %s\n"
237 <               "natoms  = %d, index = %d\n",
238 <               c_in_name, n_atoms, i );
239 <        exit(8);
236 >        sprintf( painCave.errMsg,
237 >                 "error in reading angular momentum jx from %s\n"
238 >                 "natoms  = %d, index = %d\n",
239 >                 c_in_name, n_atoms, i );
240 >        painCave.isFatal = 1;
241 >        simError();
242        }
243        (void)sscanf( foo, "%lf", &jx );
244        
245        foo = strtok(NULL, " ,;\t");
246        if(foo == NULL){
247 <        printf("error in reading angular momentum jy from %s\n"
248 <               "natoms  = %d, index = %d\n",
249 <               c_in_name, n_atoms, i );
250 <        exit(8);
247 >        sprintf( painCave.errMsg,
248 >                 "error in reading angular momentum jy from %s\n"
249 >                 "natoms  = %d, index = %d\n",
250 >                 c_in_name, n_atoms, i );
251 >        painCave.isFatal = 1;
252 >        simError();
253        }
254        (void)sscanf( foo, "%lf", &jy );
255        
256        foo = strtok(NULL, " ,;\t");
257        if(foo == NULL){
258 <        printf("error in reading angular momentum jz from %s\n"
259 <               "natoms  = %d, index = %d\n",
260 <               c_in_name, n_atoms, i );
261 <        exit(8);
258 >        sprintf( painCave.errMsg,
259 >                 "error in reading angular momentum jz from %s\n"
260 >                 "natoms  = %d, index = %d\n",
261 >                 c_in_name, n_atoms, i );
262 >        painCave.isFatal = 1;
263 >        simError();
264        }
265        (void)sscanf( foo, "%lf", &jz );
266        

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines