| 212 | } |
| 213 | |
| 214 | int |
| 215 | FilePlotter::plotFile(void) |
| 216 | { |
| 217 | /* |
| 218 | * first pass: 1) open file |
| 219 | * 2) determine number of entries on first line ASSSSSUME same through file |
| 220 | * 3) determine number of lines and bounds [xmin, xmax, ymin, ymax] |
| 221 | * 4) close the file |
| 222 | */ |
| 223 | |
| 224 | // open file |
| 225 | ifstream theFile; |
| 226 | theFile.open(fileName1, ios::in); |
| 227 | |
| 228 | if (theFile.bad()) { |
| 229 | opserr << "WARNING - FilePlotter::FilePlotter()"; |
| 230 | opserr << " - could not open file " << fileName1 << endln; |
| 231 | return -1; |
| 232 | } |
| 233 | |
| 234 | double xMin, xMax, yMin, yMax; |
| 235 | xMin = 0; xMax = 0; yMin =0; yMax =0; |
| 236 | double xValue, yValue; |
| 237 | |
| 238 | // determine number of elements in each line |
| 239 | // NOTE ASSUMES ALL LINES HAVE THE SAME NUMBER OF ELEMENTS |
| 240 | char c; |
| 241 | int numLineEntries = 0; |
| 242 | int numLines = 0; |
| 243 | |
| 244 | while (theFile.get(c) && (c!= EOF) && c != '\n') { |
| 245 | if (!isspace(c)) { |
| 246 | theFile.putback(c); |
| 247 | |
| 248 | theFile >> xValue; |
| 249 | for (int i=0; i<cols->Size(); i++) { |
| 250 | if (i%2 == 0) { // an xValue if numLineEntries == colX |
| 251 | if (numLineEntries == (*cols)(i)) { |
| 252 | if (xValue < xMin) xMin = xValue; |
| 253 | if (xValue > xMax) xMax = xValue; |
| 254 | } |
| 255 | } else { // a y value if (numLineEntries == colY) { |
| 256 | if (numLineEntries == (*cols)(i)) { |
| 257 | if (xValue < yMin) yMin = xValue; |
| 258 | if (xValue > yMax) yMax = xValue; |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | |
| 264 | numLineEntries ++; |
| 265 | } |
| 266 | numLines =1; |
| 267 | } |
| 268 | |
| 269 | |
| 270 | if (data1a == 0 || data1b == 0 || |
| 271 | data1a->Size() != numLineEntries || data1b->Size() != numLineEntries) { |
no test coverage detected