| Bsoft 2.0.5 Bernard's software package

Bplot.cpp
Go to the documentation of this file.
1
9 #include "Bplot.h"
10 #include "utilities.h"
11
12 // Declaration of global variables
13 extern int verbose; // Level of output to the screen
14
15 ostream& operator<<(ostream& output, Bplot* plot) {
16 long i, j, k;
17 // output.setf(ios::fixed, ios::floatfield);
18 output << plot->page(0).column(0).label();
19 for ( j=1; j<plot->columns(); j++ ) cout << tab << plot->page(0).column(j).label();
20 output << endl;
21 for ( i=0; i<plot->rows(); i++ ) {
22 output << (*plot)[i];
23 for ( j=1, k=plot->rows()+i; j<plot->columns(); j++, k+=plot->rows() )
24 output << tab << (*plot)[k];
25 output << endl;
26 }
27 return output;
28 }
29
30 Bplot::Bplot(Bstring& filename)
31 {
32 if ( filename.length() < 1 ) return;
33
34 if ( verbose & VERB_PROCESS )
35 cout << "# Reading plot file: " << filename << endl;
36
37 ifstream fps(filename.c_str());
38 if ( fps.fail() ) return;
39
40 char aline[1024];
41 long i(0), j;
42 int ncol(0), nrow(0);
43 Bstring sline;
44
45 // Title
46 while ( fps.getline(aline, 1024) && strncmp(aline, "%%Title:", 8) ) ;
47
48 Bstring plot_title(aline);
49 plot_title = plot_title.substr(8,plot_title.length());
50
51 // Start of data
52 while ( fps.getline(aline, 1024) && strncmp(aline, "/Data [", 7) ) ;
53
54 // Lables line
55 fps.getline(aline, 1024);
56 sline = aline;
57 Bstring* labels = sline.split();
58 Bstring* label;
59
60 // Determine number of rows and columns
61 while ( fps.getline(aline, 1024) && aline[0] != ']' ) {
62 if ( verbose & VERB_DEBUG )
63 cout << "DEBUG Bplot::Bplot: aline = \"" << aline << "\"" << endl;
64 sline = aline;
65 sline = sline.substr(0, sline.length() - 1);
66 vector<double> temp = sline.split_into_doubles(0);
67 if ( ncol < temp.size() ) ncol = temp.size();
68 nrow++;
69 }
70
71 if ( verbose ) {
72 cout << "Plot file: " << filename << endl;
73 cout << "Columns: " << ncol << endl;
74 cout << "Rows: " << nrow << endl;
75 cout << "Labels: ";
76 }
77
78 initialize(1, nrow, ncol);
79 title(plot_title);
80 page(0).title(plot_title);
81 page(0).columns(ncol);
82 for ( i=0, label = labels; i<ncol; i++, label = label->next ) {
83 page(0).column(i).number(i);
84 page(0).column(i).label(*label);
85 if ( verbose )
86 cout << " " << *label;
87 }
88
89 if ( verbose )
90 cout << endl << endl;
91
92 string_kill(labels);
93
94 fps.seekg(0);
95
96 // Start of data
97 while ( fps.getline(aline, 1024) && strncmp(aline, "/Data [", 7) ) ;
98
99 // Lables line
100 fps.getline(aline, 1024);
101
102 // Read the data
103 i = 0;
104 while ( fps.getline(aline, 1024) && aline[0] != ']' ) {
105 if ( verbose & VERB_DEBUG )
106 cout << "DEBUG Bplot::Bplot: aline = \"" << aline << "\"" << endl;
107 sline = aline;
108 vector<double> temp = sline.split_into_doubles(0);
109 for ( j=0; j<ncol; j++ ) data[j*nrow+i] = temp[j];
110 i++;
111 }
112 }
113
114 void Bplot::resolution_display(double* fsccut, double* dprcut)
115 {
116 long i;
117 double res(999), FSCsum(0), w, IVR;
118 double *s, *FSC, *DPR;
119 Bstring txt, label(page(0).axis(3).label());
120
121 s = data;
122 FSC = s + nr;
123 DPR = FSC + nr;
124
125 cout << "Resolution curves:" << endl;
126 cout << "s(1/A)\tRes(A)\t" << label;
127 if ( nc > 2 ) cout << "\tDPR";
128 cout << endl;
129
130 for ( i=0; i<nr; i++ ) {
131 if ( i ) res = 1/s[i];
132 w = M_PI*2*i;
133 if ( label == "FSC" ) w *= 2.0*i;
134 FSCsum += FSC[i]*w;
135 cout << showpoint << fixed << setprecision(5) << setw(7) << s[i] << tab
136 << setprecision(3) << setw(7) << res << tab
137 << setw(7) << FSC[i];
138 if ( nc > 2 ) cout << tab << setw(7) << DPR[i];
139 cout << endl;
140 }
141
142 if ( label == "FSC" ) IVR = pow(4.0*M_PI/(3.0*FSCsum), 1.0/3.0);
143 else IVR = sqrt(M_PI/FSCsum);
144 IVR /= s[1];
145
146 if ( fsccut || dprcut )
147 cout << endl << "Resolution estimates:" << endl;
148
149 if ( fsccut ) for ( i=0; i<4; i++ ) if ( fsccut[i] ) {
150 txt = label + Bstring(fsccut[i], "(%g): ") + Bstring(1/cut(1,fsccut[i],-1), "%g A");
151 page(0).add_text(txt);
152 cout << txt << endl;
153 }
154
155 if ( dprcut ) for ( i=0; i<4; i++ ) if ( dprcut[i] ) {
156 txt = Bstring(dprcut[i], "DPR(%g): ") + Bstring(1/cut(2,dprcut[i],1), "%g A");
157 page(0).add_text(txt);
158 cout << txt << endl;
159 }
160
161 txt = Bstring(IVR, "Information volume radius: %g A");
162 page(0).add_text(txt);
163 cout << txt << endl << endl;
164 }
165
166
Bplot::cut
double cut(long icol, double threshold, int dir=1)
Definition: Bplot.h:246
Bstring::substr
Bstring substr(long start, long len)
Definition: Bstring.cpp:324
Bplot::title
Bstring & title()
Definition: Bplot.h:189
utilities.h
Header file for general utilities.
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
Bcolumn::label
Bstring & label()
Definition: Bplot.h:63
Bstring::length
long length() const
Definition: Bstring.cpp:263
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
Bpage::column
Bcolumn & column(long i)
Definition: Bplot.h:110
Bplot.h
Header file for postscript output functions.
M_PI
#define M_PI
Definition: utilities.h:59
Bcolumn::number
long number()
Definition: Bplot.h:61
Bstring::next
Bstring * next
Definition: Bstring.h:31
Bpage::title
Bstring & title()
Definition: Bplot.h:100
verbose
int verbose
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:665
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Bplot::Bplot
Bplot()
Definition: Bplot.h:174
Bpage::add_text
void add_text(Bstring &s)
Definition: Bplot.h:122
operator<<
ostream & operator<<(ostream &output, Bplot *plot)
Definition: Bplot.cpp:15
Bstring
Definition: Bstring.h:29
Bplot::rows
void rows(long n)
Definition: Bplot.h:207
Bplot::page
Bpage & page(long i)
Definition: Bplot.h:211
Bpage::columns
void columns(long ncol)
Definition: Bplot.h:105
Bplot::resolution_display
void resolution_display(double *fsccut=NULL, double *dprcut=NULL)
Definition: Bplot.cpp:114
Bplot::columns
void columns(long n)
Definition: Bplot.h:209
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bstring::split
Bstring * split()
Definition: Bstring.cpp:597
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760
Bplot
Definition: Bplot.h:146