spasimkz.C

Go to the documentation of this file.
00001 /* Gnome gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Gxsm Plugin Name: spasimkz.C
00006  * ========================================
00007  * 
00008  * Copyright (C) 1999 The Free Software Foundation
00009  *
00010  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00011  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00026  */
00027 
00028 /* Please do not change the Begin/End lines of this comment section!
00029  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00030  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00031  * All "% PlugInXXX" commentary tags are mandatory
00032  * All "% OptPlugInXXX" tags are optional
00033  * --------------------------------------------------------------------------------
00034 % BeginPlugInDocuSection
00035 % PlugInDocuCaption: SPA--LEED 1D profile simulation $k_z$.
00036 % PlugInName: spasimkz
00037 % PlugInAuthor: Percy Zahl
00038 % PlugInAuthorEmail: zahl@users.sf.net
00039 % PlugInMenuPath: Math/Statistics/SPALEED Simkz
00040 
00041 % PlugInDescription
00042 Calculates SPA--LEED Profiles over phase (S) e.g. a $k_z$-plot:\\
00043 For each phase S (S=2 StepHeight/WaveLength) a 1D fourier
00044 transformation is calculated for all image lines, which are phase
00045 transformed before. All transformed lines for this phase are summed up
00046 and stored to the new image as Line 'S'.
00047 
00048 Def. Phase Transformation:
00049 \[e^{2\pi i S Z(x,y)}\]
00050 
00051 %\clearpage
00052 Algorithm (shortened, extracted from source):
00053 
00054 \begin{verbatim}
00055  for(i=0, S=PhaseStart; i<Dest->data.s.ny; S+=PhaseStep, ++i){
00056     // PhaseTrans:
00057     // transform scan data to complex data with correct phase
00058     double sf = 2. * M_PI * S * Src->data.s.dz / StepHeight;
00059     for (int line=0; line < Src->mem2d->GetNy(); line++) {
00060         Src->mem2d->data->SetPtr(0, line);
00061         for (int col=0; col < Src->mem2d->GetNx(); col++) {
00062             double arg = sf * Src->mem2d->data->GetNext();
00063             c_re(htrans[col]) = cos(arg);
00064             c_im(htrans[col]) = sin(arg);
00065         }
00066 
00067       // do FFT
00068       fftw( plan, 1, htrans, 1, 0, hkspc, 1, 0);
00069 
00070       // StoreAbsolute, Add to Dest [double]
00071       Dest->mem2d->data->SetPtr(0, i);
00072       for (int j = 0; j<Src->mem2d->GetNx(); ++j){
00073           int k=QSWP(j, Dest->mem2d->GetNx());
00074           Dest->mem2d->data->SetNext( 
00075               Dest->mem2d->data->GetThis()
00076               + c_re(hkspc[k])*c_re(hkspc[k]) 
00077               + c_im(hkspc[k])*c_im(hkspc[k])
00078                                     );
00079       }
00080     }
00081   }
00082 \end{verbatim}
00083 
00084 
00085 % PlugInUsage
00086 Call from \GxsmMenu{Math/Statistics/SPALEED Simkz.} and input the step
00087 height, phase range and phase step size.
00088 
00089 % OptPlugInSources
00090 The active channel is used as data source.
00091 
00092 %% OptPlugInObjects
00093 %A optional rectangle is used for data extraction...
00094 
00095 % OptPlugInDest
00096 The computation result is placed into an existing math channel, else into a new created math channel.
00097 
00098 % OptPlugInConfig
00099 Use the Plug-In configurator to set default values. Use the entry
00100 \GxsmEmph{Ask Next} to prevent or reenable further asking for
00101 parameters (1 will ask, 0 not).
00102 
00103 %% OptPlugInFiles
00104 %Does it uses, needs, creates any files? Put info here!
00105 
00106 %% OptPlugInKnownBugs
00107 %
00108 
00109 %% OptPlugInNotes
00110 %
00111 
00112 %% OptPlugInHints
00113 %
00114 
00115 % EndPlugInDocuSection
00116  * -------------------------------------------------------------------------------- 
00117  */
00118 
00119 
00120 #include <gtk/gtk.h>
00121 #include "config.h"
00122 #include "gxsm/plugin.h"
00123 
00124 static void spasimkz_init( void );
00125 static void spasimkz_about( void );
00126 static void spasimkz_configure( void );
00127 static void spasimkz_cleanup( void );
00128 static gboolean spasimkz_run( Scan *Src, Scan *Dest );
00129 
00130 GxsmPlugin spasimkz_pi = {
00131   NULL,
00132   NULL,
00133   0,
00134   NULL,
00135   "SpasimKZ-M1S-ST",
00136   NULL, //"-SPALEED -ELSLEED",
00137   NULL,
00138   "Percy Zahl",
00139   N_("_Math/_Statistics/"),
00140   N_("SPALEED Simkz"),
00141   N_("Simulate SPALEED, kz-Scan!"),
00142   "no more info",
00143   NULL,
00144   NULL,
00145   spasimkz_init,
00146   NULL,
00147   spasimkz_about,
00148   spasimkz_configure,
00149   NULL,
00150   spasimkz_cleanup
00151 };
00152 
00153 GxsmMathOneSrcPlugin spasimkz_m1s_pi = {
00154   spasimkz_run
00155 };
00156 
00157 static const char *about_text = N_("Gxsm Spasimkz Plugin\n\n"
00158                                    "Calculates SPALEED Profiles over S\n"
00159                                    "e.g. a kz-plot:\n"
00160                                    "For each phase S (S=2 StepHeight/WaveLength)\n"
00161                                    "a 1D FT is done for all before Phase Transformed\n"
00162                                    "Lines. All transformed lines for this phase\n"
00163                                    "are summed up and stored to the new image as Line 'S'.");
00164 
00165 double StepHeight=3.141;
00166 double PhaseStart=0.5, PhaseEnd=3.5, PhaseStep=0.01;
00167 int    ask=1;
00168 
00169 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00170   spasimkz_pi.description = g_strdup_printf(N_("Gxsm MathOneArg spasimkz plugin %s"), VERSION);
00171   return &spasimkz_pi; 
00172 }
00173 
00174 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 
00175   return &spasimkz_m1s_pi; 
00176 }
00177 
00178 static void spasimkz_init(void)
00179 {
00180   PI_DEBUG (DBG_L2, "Spasimkz Plugin Init");
00181 }
00182 
00183 static void spasimkz_about(void)
00184 {
00185   const gchar *authors[] = { spasimkz_pi.authors, NULL};
00186   gtk_widget_show(gnome_about_new ( spasimkz_pi.name,
00187                                     VERSION,
00188                                     N_("(C) 2000 the Free Software Foundation"),
00189                                     about_text,
00190                                     authors,
00191                                     NULL, NULL, NULL
00192                                     ));
00193 }
00194 
00195 static void spasimkz_configure(void)
00196 {
00197   GtkWidget *dialog;
00198   GtkWidget *vbox;
00199   GtkWidget *hbox;
00200   GtkWidget *info;
00201   GtkWidget *input;
00202   Gtk_EntryControl *ec;
00203 
00204   dialog = gnome_dialog_new(_("SPA-LEED kz-Scan simulation parameters"),
00205                             GNOME_STOCK_BUTTON_OK,
00206                             NULL); 
00207         
00208   gnome_dialog_set_close(GNOME_DIALOG(dialog), FALSE);
00209   gnome_dialog_close_hides(GNOME_DIALOG(dialog), FALSE);
00210   gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);
00211 
00212   vbox = gtk_vbox_new (FALSE, 0);
00213   gtk_widget_show (vbox);
00214 
00215   gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),
00216                      vbox, TRUE, TRUE, GNOME_PAD);
00217 
00218   info = gtk_label_new ("SPA-LEED kz-Scan simulation parameters");
00219   gtk_widget_show (info);
00220   gtk_box_pack_start(GTK_BOX(vbox), info, TRUE, TRUE, GNOME_PAD);
00221 
00222   input = spasimkz_pi.app->mygtk_create_input("Step Height", vbox, hbox);
00223   ec = new Gtk_EntryControl(spasimkz_pi.app->xsm->Z_Unit, 
00224                            "Value out of range !", 
00225                            &StepHeight, 
00226                            0., 1000., ".3f", input);
00227 
00228   input = spasimkz_pi.app->mygtk_create_input("Phase Start", vbox, hbox);
00229   ec = new Gtk_EntryControl(spasimkz_pi.app->xsm->Unity, 
00230                            "Value out of range !",
00231                            &PhaseStart,
00232                            -1., 100., ".3f", input);
00233 
00234   input = spasimkz_pi.app->mygtk_create_input("Phase End", vbox, hbox);
00235   ec = new Gtk_EntryControl(spasimkz_pi.app->xsm->Unity, 
00236                            "Value out of range !",
00237                            &PhaseEnd,
00238                            0., 100., ".3f", input);
00239 
00240   input = spasimkz_pi.app->mygtk_create_input("Phase Step", vbox, hbox);
00241   ec = new Gtk_EntryControl(spasimkz_pi.app->xsm->Unity, 
00242                            "Value out of range !",
00243                            &PhaseStep,
00244                            1e-4, 1., ".4f", input);
00245 
00246   input = spasimkz_pi.app->mygtk_create_input("Ask next", vbox, hbox);
00247   ec = new Gtk_EntryControl(spasimkz_pi.app->xsm->Unity, 
00248                            "only True=1 or False=0 !",
00249                            &ask,
00250                            0., 1., ".0f", input);
00251 
00252 
00253   gtk_widget_show(dialog);
00254 
00255   gnome_dialog_run_and_close(GNOME_DIALOG(dialog));
00256 } 
00257 
00258 static void spasimkz_cleanup(void)
00259 {
00260   PI_DEBUG (DBG_L2, "Spasimkz Plugin Cleanup");
00261 }
00262 
00263 static gboolean spasimkz_run(Scan *Src, Scan *Dest)
00264 {
00265   double S;
00266   int i;
00267 
00268 // SPA-LEED image simulation
00269   PI_DEBUG (DBG_L2, "F2D Spasimkz");
00270 
00271   if(ask){
00272       spasimkz_configure();
00273   }while(PhaseEnd < PhaseStart || (PhaseEnd - PhaseStart) < PhaseStep );
00274 
00275   if(PhaseEnd < PhaseStart || (PhaseEnd - PhaseStart) < PhaseStep )
00276     return MATH_SIZEERR;
00277 
00278   // allocate memory for the complex data and one line buffer
00279   Dest->data.s.ny = (int)((PhaseEnd - PhaseStart)/PhaseStep+0.5);
00280 
00281   Dest->mem2d->Resize(Dest->data.s.nx, Dest->data.s.ny, ZD_FLOAT);
00282   Dest->mem2d->data->MkXLookup(-100., 100.);
00283   Dest->mem2d->data->MkYLookup(PhaseStart, PhaseEnd);
00284 
00285   fftw_complex *htrans = new fftw_complex[Src->mem2d->GetNx()];
00286   fftw_complex *hkspc  = new fftw_complex[Src->mem2d->GetNx()];
00287   fftw_plan plan = fftw_plan_dft_1d (Src->mem2d->GetNx(), htrans, hkspc, FFTW_FORWARD, FFTW_ESTIMATE);
00288 
00289   PI_DEBUG (DBG_L2, "SIMKZ START: " << PhaseStart << " ..[" << PhaseStep << "].. " << PhaseEnd );
00290 
00291   for(i=0, S=PhaseStart; i<Dest->data.s.ny; S+=PhaseStep, ++i){
00292     gchar *mld = g_strdup_printf("SIMKZ: %d/%d S=%5.2f", 
00293                                  i, Dest->data.s.ny, S);
00294     gapp->SetStatus(mld); 
00295     g_free(mld);
00296     SET_PROGRESS((gfloat)i/(gfloat)Dest->data.s.ny);
00297 
00298     // PhaseTrans:
00299     // transform scan data to complex data with correct phase
00300     double sf = 2. * M_PI * S * Src->data.s.dz / StepHeight;
00301     for (int line=0; line < Src->mem2d->GetNy(); line++) {
00302         Src->mem2d->data->SetPtr(0, line);
00303         for (int col=0; col < Src->mem2d->GetNx(); col++) {
00304             double arg = sf * Src->mem2d->data->GetNext();
00305             c_re(htrans[col]) = cos(arg);
00306             c_im(htrans[col]) = sin(arg);
00307         }
00308 
00309         // FFTW
00310         fftw_execute (plan);
00311 
00312         // StoreAbsolute, Add to Dest [double]
00313         Dest->mem2d->data->SetPtr(0, i);
00314         for (int j = 0; j<Src->mem2d->GetNx(); ++j){
00315                 int k=QSWP(j, Dest->mem2d->GetNx());
00316                 Dest->mem2d->data->SetNext( Dest->mem2d->data->GetThis()
00317                                             + c_re(hkspc[k])*c_re(hkspc[k]) 
00318                                             + c_im(hkspc[k])*c_im(hkspc[k])
00319                         );
00320       }
00321     }
00322   }
00323 
00324   fftw_destroy_plan (plan);
00325   SET_PROGRESS(0);
00326 
00327   // free memory
00328   delete htrans;
00329   delete hkspc;
00330 
00331   return MATH_OK;
00332 }

Generated on Sat Apr 1 09:04:23 2006 for GXSM by  doxygen 1.4.6