Debian Codegraph @

07p/plaut04/src/readFM.c++

raw
1 #include "readFM.h"
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include "gplaut04.h"
7 #include "bifurcation.h"
8
9 extern UserData clientData;
10 //////////////////////////////////////////////////////////////////////////////////
11 //
12 int
13 readFM(const char* dFileName, const int size)
14 //
15 //////////////////////////////////////////////////////////////////////////////////
16 {
17 int state = 0;
18
19 char buffer[256];
20 int branch, point, prevpoint, myid;
21 int maxndim = clientData.maxndim;
22 bool eigenvalues;
23
24 float fl1, fl2;
25 FILE * inFile;
26 inFile = fopen(dFileName, "r");
27
28 if (!inFile)
29 {
30 printf("Cannot open the diagnostic file. \n");
31 state = 1;
32 return state;
33 }
34
35 char * next;
36
37 long icounter = 1, branchcounter = 0;
38 int rowi = 0;
39 prevpoint = -1;
40 int branchi = 0;
41
42 while ( (next = fgets(buffer, sizeof(buffer), inFile)) != NULL
43 && icounter < size)
44 {
45 if (strstr(buffer, "Total Time") != NULL)
46 {
47 /* New branch */
48 branchcounter += myBifNode->numVerticesEachBranch(branchi++);
49 icounter = branchcounter + 1;
50 }
51
52 eigenvalues = strstr(buffer, "Eigenvalue") != NULL;
53 if(eigenvalues || strstr(buffer, "Multiplier") != NULL)
54 {
55 if(clientData.multipliers == NULL) {
56 clientData.multipliers = new float[size*maxndim][2];
57 clientData.numFM = new int[size];
58 }
59 clientData.numFM[icounter] = 0;
60 rowi = 0;
61 do
62 {
63 int ret;
64 if(eigenvalues)
65 ret = sscanf(buffer, "%d%d Eigenvalue %d: %e%e",
66 &branch, &point, &myid, &fl1, &fl2);
67 else
68 ret = sscanf(buffer, "%d%d Multiplier %d%e%e",
69 &branch, &point, &myid, &fl1, &fl2);
70 if(ret != 5) {
71 if (rowi == 0)
72 --icounter;
73 break;
74 }
75 if (point == prevpoint && rowi == 0)
76 --icounter;
77 prevpoint = point;
78 clientData.multipliers[icounter*maxndim+rowi][0] = fl1;
79 clientData.multipliers[icounter*maxndim+rowi][1] = fl2;
80 rowi++;
81 } //end inner while
82 while( fgets(buffer, sizeof(buffer), inFile) &&
83 (strstr(buffer, "Multiplier") != NULL ||
84 strstr(buffer, "Eigenvalue") != NULL) );
85 if(rowi !=0)
86 clientData.numFM[icounter] = eigenvalues ? -rowi : rowi;
87 ++icounter;
88 }
89 } // end outter while
90 fclose(inFile);
91
92 return state;
93 }
94
95