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
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 #include <gtk/gtk.h>
00097 #include "config.h"
00098 #include "gxsm/plugin.h"
00099
00100 static void spasim_init( void );
00101 static void spasim_about( void );
00102 static void spasim_configure( void );
00103 static void spasim_cleanup( void );
00104 static gboolean spasim_run( Scan *Src, Scan *Dest );
00105
00106 GxsmPlugin spasim_pi = {
00107 NULL,
00108 NULL,
00109 0,
00110 NULL,
00111 "Spasim-M1S-F1D",
00112 NULL,
00113 NULL,
00114 "Percy Zahl",
00115 N_("_Math/_Statistics/"),
00116 N_("SPALEED Sim."),
00117 N_("Simulate SPALEED!"),
00118 "no more info",
00119 NULL,
00120 NULL,
00121 spasim_init,
00122 NULL,
00123 spasim_about,
00124 spasim_configure,
00125 NULL,
00126 spasim_cleanup
00127 };
00128
00129 GxsmMathOneSrcPlugin spasim_m1s_pi = {
00130 spasim_run
00131 };
00132
00133 static const char *about_text = N_("Gxsm Spasim Plugin\n\n"
00134 "This Plugin simulates a SPA-LEED measurement (WaveLenght as input)\n"
00135 "on the Src-Channel's Scan:\n"
00136 "1.) Phase Transformation, using e^(2pi i Z(x,y)/WaveLength)\n"
00137 "2.) 2D FT( Phase Transformed Image)\n"
00138 "3.) Result = |FT(\")|^2");
00139
00140 double WaveLengthDefault=0.0;
00141 int EnableInvAng=0;
00142 double WaveLengthLast=3.141;
00143
00144 GxsmPlugin *get_gxsm_plugin_info ( void ){
00145 spasim_pi.description = g_strdup_printf(N_("Gxsm MathOneArg spasim plugin %s"), VERSION);
00146 return &spasim_pi;
00147 }
00148
00149 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00150 return &spasim_m1s_pi;
00151 }
00152
00153 static void spasim_init(void)
00154 {
00155 PI_DEBUG (DBG_L2, "Spasim Plugin Init");
00156 }
00157
00158 static void spasim_about(void)
00159 {
00160 const gchar *authors[] = { spasim_pi.authors, NULL};
00161 gtk_widget_show(gnome_about_new ( spasim_pi.name,
00162 VERSION,
00163 N_("(C) 2000 the Free Software Foundation"),
00164 about_text,
00165 authors,
00166 NULL, NULL, NULL
00167 ));
00168 }
00169
00170 static void spasim_configure(void)
00171 {
00172 double flg;
00173 spasim_pi.app->ValueRequest("Enter Value", "WaveLength",
00174 "Default WaveLength, if set to Zero I will ask later!",
00175 spasim_pi.app->xsm->Z_Unit,
00176 0., 1000., ".3f", &WaveLengthDefault);
00177 flg = EnableInvAng;
00178 spasim_pi.app->ValueRequest("Configure", "Enable InvAng (0/1)?",
00179 "Use inv Ang for lenght scale?\n"
00180 "(Note: sorry, but profile won't work w this!)",
00181 spasim_pi.app->xsm->Unity,
00182 0., 1., ".0f", &flg);
00183 EnableInvAng=flg>0?1:0;
00184 }
00185
00186 static void spasim_cleanup(void)
00187 {
00188 PI_DEBUG (DBG_L2, "Spasim Plugin Cleanup");
00189 }
00190
00191 static gboolean spasim_run(Scan *Src, Scan *Dest)
00192 {
00193 double WaveLength = WaveLengthLast;
00194
00195 if(fabs(WaveLengthDefault) > 1e-10)
00196 WaveLength = WaveLengthDefault;
00197 else
00198 spasim_pi.app->ValueRequest("Enter Value", "WaveLength",
00199 "I need WaveLength for SpaSim!",
00200 spasim_pi.app->xsm->Z_Unit,
00201 1e-3, 1e3, ".3f", &WaveLength);
00202 WaveLengthLast = WaveLength;
00203
00204
00205 PI_DEBUG (DBG_L2, "F2D SpaSim");
00206
00207
00208 Dest->mem2d->Resize(Dest->data.s.nx, Dest->data.s.ny, ZD_FLOAT);
00209
00210
00211 Dest->mem2d->data->MkXLookup(-Src->mem2d->GetNx()/2, Src->mem2d->GetNx()/2);
00212 Dest->mem2d->data->MkYLookup(-Src->mem2d->GetNy()/2, Src->mem2d->GetNy()/2);
00213 if (EnableInvAng){
00214 InvUnit ux("invA","invA", "X Lenght", Src->data.s.rx);
00215 InvUnit uy("invA","invA", "Y Lenght", Src->data.s.ry);
00216 Dest->data.SetXUnit(&ux);
00217 Dest->data.SetYUnit(&uy);
00218 }else{
00219 LinUnit ux("pix","pix", "X pos");
00220 LinUnit uy("pix","pix", "Y pos");
00221 Dest->data.SetXUnit(&ux);
00222 Dest->data.SetYUnit(&uy);
00223 }
00224 LinUnit lu("CPS","CPS", "Int.");
00225 Dest->data.SetZUnit(&lu);
00226
00227
00228 fftw_complex *in = new fftw_complex [Src->mem2d->GetNy() * Src->mem2d->GetNx()];
00229 fftw_complex *out = new fftw_complex [Src->mem2d->GetNy() * Src->mem2d->GetNx()];
00230
00231
00232
00233
00234 for (int pos=0, col=0; col < Src->mem2d->GetNx (); ++col)
00235 for (int line=0; line < Src->mem2d->GetNy (); ++line, ++pos){
00236 double arg = 2.*M_PI * Src->data.s.dz
00237 * Src->mem2d->GetDataPkt(col, line)
00238 / WaveLength;
00239 c_re(in[pos]) = cos(arg);
00240 c_im(in[pos]) = sin(arg);
00241 }
00242
00243
00244
00245 fftw_plan plan = fftw_plan_dft_2d (Src->mem2d->GetNx (), Src->mem2d->GetNy (), in, out, FFTW_FORWARD, FFTW_ESTIMATE);
00246
00247 fftw_execute (plan);
00248
00249
00250 for (int pos=0, col=0; col < Src->mem2d->GetNx (); ++col)
00251 for (int line=0; line < Src->mem2d->GetNy (); ++line, ++pos)
00252 Dest->mem2d->PutDataPkt ( c_re (out[pos]) * c_re (out[pos])
00253 + c_im (out[pos]) * c_im (out[pos]),
00254 QSWP (col, Src->mem2d->GetNx ()),
00255 QSWP (line, Src->mem2d->GetNy ()) );
00256
00257
00258 fftw_destroy_plan (plan);
00259
00260
00261 delete in;
00262 delete out;
00263
00264 return MATH_OK;
00265 }