div_scan.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  * plugin_helper reports your answers as
00006 author          =Percy Zahl
00007 email                   =zahl@users.sf.net
00008 pluginname              =div_scan
00009 pluginmenuentry         =Div X
00010 menupath                =Math/Arithmetic/
00011 entryplace              =Arithmetic
00012 shortentryplace =AR
00013 abouttext               =Divide Active by X channel
00014 smallhelp               =My new Plugin does useful things
00015 longhelp                =This is a detailed help for my Plugin.
00016  * 
00017  * Gxsm Plugin Name: div_scan.C
00018  * ========================================
00019  * 
00020  * Copyright (C) 1999 The Free Software Foundation
00021  *
00022  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00023  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00024  *
00025  * This program is free software; you can redistribute it and/or modify
00026  * it under the terms of the GNU General Public License as published by
00027  * the Free Software Foundation; either version 2 of the License, or
00028  * (at your option) any later version.
00029  *
00030  * This program is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00033  * GNU General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU General Public License
00036  * along with this program; if not, write to the Free Software
00037  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00038  */
00039 
00040 
00041 /* Please do not change the Begin/End lines of this comment section!
00042  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00043  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00044  * All "% PlugInXXX" commentary tags are mandatory
00045  * All "% OptPlugInXXX" tags are optional and can be removed or commented in
00046  * --------------------------------------------------------------------------------
00047 % BeginPlugInDocuSection
00048 % PlugInDocuCaption: Divide scans
00049 % PlugInName: div_scan
00050 % PlugInAuthor: Percy Zahl
00051 % PlugInAuthorEmail: zahl@users.sf.net
00052 % PlugInMenuPath: Math/Arithmetic/Div X
00053 
00054 % PlugInDescription
00055 Divide the Z-values of two scans.
00056 
00057 % PlugInUsage
00058 Call \GxsmMenu{Math/Arithmetic/Div X}.
00059 
00060 % OptPlugInSources
00061 The active channel is divided by the X channel.
00062 
00063 %% OptPlugInObjects
00064 %A optional rectangle is used for data extraction...
00065 
00066 % OptPlugInDest
00067 The computation result is placed into an existing math channel, else
00068 into a new created math channel. The result is of type \GxsmEmph{float}.
00069 
00070 % OptPlugInNotes
00071 Both scans are required to have the same size in pixels. Thers is an
00072 $\epsilon = 10^{-8}$ defined as minimal divisor, if the absolute value
00073 of the divisor is smaller than $\epsilon$ the original divident data
00074 is kept unchanged.
00075 
00076 % EndPlugInDocuSection
00077  * -------------------------------------------------------------------------------- 
00078  */
00079 
00080 #include <gtk/gtk.h>
00081 #include "config.h"
00082 #include "gxsm/plugin.h"
00083 
00084 // Plugin Prototypes
00085 static void div_scan_init( void );
00086 static void div_scan_about( void );
00087 static void div_scan_configure( void );
00088 static void div_scan_cleanup( void );
00089 
00090 // Define Type of math plugin here, only one line should be commented in!!
00091 // #define GXSM_ONE_SRC_PLUGIN__DEF
00092 #define GXSM_TWO_SRC_PLUGIN__DEF
00093 
00094 // Math-Run-Function, use only one of (automatically done :=)
00095 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00096 // "OneSrc" Prototype
00097  static gboolean div_scan_run( Scan *Src, Scan *Dest );
00098 #else
00099 // "TwoSrc" Prototype
00100  static gboolean div_scan_run( Scan *Src1, Scan *Src2, Scan *Dest );
00101 #endif
00102 
00103 // Fill in the GxsmPlugin Description here
00104 GxsmPlugin div_scan_pi = {
00105   NULL,                   // filled in and used by Gxsm, don't touch !
00106   NULL,                   // filled in and used by Gxsm, don't touch !
00107   0,                      // filled in and used by Gxsm, don't touch !
00108   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00109                           // filled in here by Gxsm on Plugin load, 
00110                           // just after init() is called !!!
00111   // ----------------------------------------------------------------------
00112   // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc
00113   "div_scan-"
00114 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00115   "M1S"
00116 #else
00117   "M2S"
00118 #endif
00119   "-AR",
00120   // Plugin's Category - used to autodecide on Pluginloading or ignoring
00121   // NULL: load, else
00122   // example: "+noHARD +STM +AFM"
00123   // load only, if "+noHARD: no hardware" and Instrument is STM or AFM
00124   // +/-xxxHARD und (+/-INST or ...)
00125   NULL,
00126   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00127   "This is a detailed help for my Plugin.",                   
00128   // Author(s)
00129   "Percy Zahl",
00130   // Menupath to position where it is appendet to
00131   N_("_Math/_Arithmetic/"),
00132   // Menuentry
00133   N_("Div X"),
00134   // help text shown on menu
00135   N_("This is a detailed help for my Plugin."),
00136   // more info...
00137   "My new Plugin does useful things",
00138   NULL,          // error msg, plugin may put error status msg here later
00139   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00140   // init-function pointer, can be "NULL", 
00141   // called if present at plugin load
00142   div_scan_init,  
00143   // query-function pointer, can be "NULL", 
00144   // called if present after plugin init to let plugin manage it install itself
00145   NULL, // query should be "NULL" for Gxsm-Math-Plugin !!!
00146   // about-function, can be "NULL"
00147   // can be called by "Plugin Details"
00148   div_scan_about,
00149   // configure-function, can be "NULL"
00150   // can be called by "Plugin Details"
00151   div_scan_configure,
00152   // run-function, can be "NULL", if non-Zero and no query defined, 
00153   // it is called on menupath->"plugin"
00154   NULL, // run should be "NULL" for Gxsm-Math-Plugin !!!
00155   // cleanup-function, can be "NULL"
00156   // called if present at plugin removeal
00157   div_scan_cleanup
00158 };
00159 
00160 // special math Plugin-Strucure, use
00161 // GxsmMathOneSrcPlugin div_scan_m1s_pi -> "OneSrcMath"
00162 // GxsmMathTwoSrcPlugin div_scan_m2s_pi -> "TwoSrcMath"
00163 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00164  GxsmMathOneSrcPlugin div_scan_m1s_pi
00165 #else
00166  GxsmMathTwoSrcPlugin div_scan_m2s_pi
00167 #endif
00168  = {
00169    // math-function to run, see prototype(s) above!!
00170    div_scan_run
00171  };
00172 
00173 // Text used in Aboutbox, please update!!
00174 static const char *about_text = N_("Gxsm div_scan Plugin\n\n"
00175                                    "Divide Active by X channel");
00176 
00177 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00178 // Essential Plugin Function!!
00179 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00180   div_scan_pi.description = g_strdup_printf(N_("Gxsm MathOneArg div_scan plugin %s"), VERSION);
00181   return &div_scan_pi; 
00182 }
00183 
00184 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 
00185 // used to find out which Math Type the Plugin is!! 
00186 // Essential Plugin Function!!
00187 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00188 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00189   return &div_scan_m1s_pi; 
00190 }
00191 #else
00192 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 
00193   return &div_scan_m2s_pi; 
00194 }
00195 #endif
00196 
00197 /* Here we go... */
00198 // init-Function
00199 static void div_scan_init(void)
00200 {
00201   PI_DEBUG (DBG_L2, "div_scan Plugin Init");
00202 }
00203 
00204 // about-Function
00205 static void div_scan_about(void)
00206 {
00207   const gchar *authors[] = { div_scan_pi.authors, NULL};
00208   gtk_widget_show(gnome_about_new ( div_scan_pi.name,
00209                                     VERSION,
00210                                     N_("(C) 2000 the Free Software Foundation"),
00211                                     about_text,
00212                                     authors,
00213                                     NULL, NULL, NULL
00214                                     ));
00215 }
00216 
00217 // configure-Function
00218 static void div_scan_configure(void)
00219 {
00220   if(div_scan_pi.app)
00221     div_scan_pi.app->message("div_scan Plugin Configuration");
00222 }
00223 
00224 // cleanup-Function
00225 static void div_scan_cleanup(void)
00226 {
00227   PI_DEBUG (DBG_L2, "div_scan Plugin Cleanup");
00228 }
00229 
00230 // run-Function
00231 static gboolean div_scan_run(Scan *Src1, Scan *Src2, Scan *Dest)
00232 {
00233         int merr=0;
00234         double divisor;
00235 
00236         const double eps = 1e-8;
00237 
00238         if(   Src1->mem2d->GetNx() != Src2->mem2d->GetNx() 
00239               || Src1->mem2d->GetNy() != Src2->mem2d->GetNy())
00240                 return MATH_SIZEERR;
00241 
00242         Dest->mem2d->Resize (Dest->mem2d->GetNx(), Dest->mem2d->GetNy(), ZD_FLOAT);
00243 
00244         Dest->mem2d->ConvertFrom(Src1->mem2d, 0,0, 0,0, Dest->mem2d->GetNx(),Dest->mem2d->GetNy());
00245 
00246 //      for(int v=0; v<Dest->mem2d->GetNv (); ++v)
00247         for(int line=0; line<Dest->mem2d->GetNy (); ++line)
00248                 for(int col=0; col<Dest->mem2d->GetNx (); ++col){
00249                         divisor = Src2->mem2d->GetDataPkt (col, line);
00250                         if (fabs (divisor) > eps)
00251                                 Dest->mem2d->data->Zdiv(divisor, col, line);
00252                 }
00253 
00254         return MATH_OK;
00255 }
00256 
00257 

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