00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 #include <math.h>
00087 #include <gtk/gtk.h>
00088 #include "config.h"
00089 #include "gxsm/plugin.h"
00090 #include "gxsm/action_id.h"
00091 #include "gxsm/app_profile.h"
00092
00093 static void histogram_init( void );
00094 static void histogram_about( void );
00095 static void histogram_configure( void );
00096 static void histogram_cleanup( void );
00097 static gboolean histogram_run( Scan *Src );
00098
00099 GxsmPlugin histogram_pi = {
00100 NULL,
00101 NULL,
00102 0,
00103 NULL,
00104 "Histogram-M1S-Stat",
00105 NULL,
00106 NULL,
00107 "Percy Zahl",
00108 N_("_Math/_Statistics/"),
00109 N_("Histogram"),
00110 N_("calc. Z (height) Distribution"),
00111 "no more info",
00112 NULL,
00113 NULL,
00114 histogram_init,
00115 NULL,
00116 histogram_about,
00117 histogram_configure,
00118 NULL,
00119 histogram_cleanup
00120 };
00121
00122 GxsmMathOneSrcNoDestPlugin histogram_m1s_pi = {
00123 histogram_run
00124 };
00125
00126 static const char *about_text = N_("Gxsm Histogram Plugin\n\n"
00127 "calculates Z (height) distribution / Histogram");
00128 static UnitObj *Events = NULL;
00129
00130 GxsmPlugin *get_gxsm_plugin_info ( void ){
00131 histogram_pi.description = g_strdup_printf(N_("Gxsm MathOneArg histogram plugin %s"), VERSION);
00132 return &histogram_pi;
00133 }
00134
00135 GxsmMathOneSrcNoDestPlugin *get_gxsm_math_one_src_no_dest_plugin_info( void ) {
00136 return &histogram_m1s_pi;
00137 }
00138
00139 static void histogram_init(void)
00140 {
00141 PI_DEBUG (DBG_L2, "Histogram Plugin Init");
00142 }
00143
00144 static void histogram_about(void)
00145 {
00146 const gchar *authors[] = { histogram_pi.authors, NULL};
00147 gtk_widget_show(gnome_about_new ( histogram_pi.name,
00148 VERSION,
00149 N_("(C) 2000 the Free Software Foundation"),
00150 about_text,
00151 authors,
00152 NULL, NULL, NULL
00153 ));
00154 }
00155
00156 static void histogram_configure(void)
00157 {
00158 if(histogram_pi.app)
00159 histogram_pi.app->message("Histogram Plugin Configuration");
00160 }
00161
00162 static void histogram_cleanup(void)
00163 {
00164 PI_DEBUG (DBG_L2, "Histogram Plugin Cleanup");
00165 if (Events){
00166 delete Events;
00167 Events = NULL;
00168 }
00169 }
00170
00171 static gboolean histogram_run(Scan *Src)
00172 {
00173 PI_DEBUG (DBG_L2, "TR Histogram");
00174 double high, low, zrange, dz, bin_width, dz_norm;
00175 double dnum;
00176 int bin_num;
00177 gchar *lp, *hp, *rp, *dzp ;
00178 if (!Events){
00179 Events = new UnitObj("#","#","g","Count");
00180 Events->SetAlias ("Events");
00181 }
00182
00183
00184 Src->mem2d->HiLo(&high, &low, FALSE, NULL, NULL, 1);
00185 dz = Src->data.s.dz;
00186 low *= dz;
00187 high *= dz;
00188 zrange = high-low;
00189 gchar *txt = g_strdup_printf("Enter number of bins:\n"
00190 "Zmin: %s (%g) ... Zmax: %s (%g)\n"
00191 "Zrange: %s (%g)\n"
00192 "dZ: %s (%g)\n"
00193 "Max Bins: %d\n",
00194 lp=Src->data.Zunit->UsrString(low), low,
00195 hp=Src->data.Zunit->UsrString(high), high,
00196 rp=Src->data.Zunit->UsrString(zrange), zrange,
00197 dzp=Src->data.Zunit->UsrString(dz), dz,
00198 (int)(zrange/dz));
00199 g_free(lp);
00200 g_free(hp);
00201 g_free(rp);
00202 g_free(dzp);
00203 dnum = zrange/dz/3;
00204 histogram_pi.app->ValueRequest ("Enter Value", "Number of Bins", txt,
00205 Events,
00206 1., zrange/dz, "g", &dnum);
00207 g_free(txt);
00208
00209 bin_num = (int)dnum;
00210 bin_width = zrange / bin_num;
00211 dz_norm = 1./bin_width;
00212
00213 txt = g_strdup_printf ("Histogram of %d bins, %g width", bin_num, bin_width);
00214 ProfileControl *pc = new ProfileControl (txt,
00215 bin_num,
00216 Src->data.Zunit, Events,
00217 low, high, "Histogram");
00218 g_free (txt);
00219
00220 for(int i = 0; i < bin_num; i++)
00221 pc->SetPoint (i, 0.);
00222
00223 for(int col = 0; col < Src->mem2d->GetNx(); col++)
00224 for(int line = 0; line < Src->mem2d->GetNy(); line++){
00225 double f = (dz*Src->mem2d->GetDataPkt(col,line) - low) / bin_width;
00226 int bin = (int)f;
00227
00228 if (bin < bin_num){
00229 double f1 = (bin+1) * bin_width;
00230 if ((f+dz_norm) > f1){
00231 pc->AddPoint (bin, f-bin);
00232 ++bin;
00233 if (bin < bin_num)
00234 pc->AddPoint (bin, bin-f);
00235 }
00236 else
00237 pc->AddPoint (bin, 1.);
00238 }
00239 }
00240
00241 pc->drawScans ();
00242 pc->UpdateArea ();
00243 pc->show ();
00244
00245 histogram_pi.app->xsm->AddProfile (pc);
00246 pc->unref ();
00247
00248 return MATH_OK;
00249 }