sdfimport.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  * Quick nine points Gxsm Plugin GUIDE by PZ:
00006  * ------------------------------------------------------------
00007  * 1.) Make a copy of this "nanoimport.C" to "your_plugins_name.C"!
00008  * 2.) Replace all "nanoimport" by "your_plugins_name" 
00009  *     --> please do a search and replace starting here NOW!! (Emacs doese preserve caps!)
00010  * 3.) Decide: One or Two Source Math: see line 54
00011  * 4.) Fill in GxsmPlugin Structure, see below
00012  * 5.) Replace the "about_text" below a desired
00013  * 6.) * Optional: Start your Code/Vars definition below (if needed more than the run-fkt itself!), 
00014  *       Goto Line 155 ff. please, and see comment there!!
00015  * 7.) Fill in math code in sdfimport_run(), 
00016  *     have a look at the Data-Access methods infos at end
00017  * 8.) Add sdfimport.C to the Makefile.am in analogy to others
00018  * 9.) Make a "make; make install"
00019  * A.) Call Gxsm->Tools->reload Plugins, be happy!
00020  * ... That's it!
00021  * 
00022  * Gxsm Plugin Name: sdfimport.C
00023  * ========================================
00024  * 
00025  * Copyright (C) 1999 The Free Software Foundation
00026  *
00027  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00028  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00029  *
00030  * This program is free software; you can redistribute it and/or modify
00031  * it under the terms of the GNU General Public License as published by
00032  * the Free Software Foundation; either version 2 of the License, or
00033  * (at your option) any later version.
00034  *
00035  * This program is distributed in the hope that it will be useful,
00036  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00037  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00038  * GNU General Public License for more details.
00039  *
00040  * You should have received a copy of the GNU General Public License
00041  * along with this program; if not, write to the Free Software
00042  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00043  */
00044 /* Please do not change the Begin/End lines of this comment section!
00045  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00046  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00047  * --------------------------------------------------------------------------------
00048 % BeginPlugInDocuSection
00049 % PlugInDocuCaption: Import of Surface Data Format files
00050 % PlugInName: sdfimport
00051 % PlugInAuthor: Stefan Schroeder
00052 % PlugInAuthorEmail: stefan_fkp@users.sf.net
00053 % PlugInMenuPath: File/Import/SDF-import
00054 
00055 % PlugInDescription
00056 \label{plugins:sdfimport}
00057 The \GxsmEmph{sdfimport} plug-in supports reading files
00058 as defined by the surfstand group (search internet for 'surfstand'),
00059 a group, sponsored by the EU to develop a basis for 3D surface
00060 roughness standards.
00061 
00062 % PlugInUsage
00063 The plug-in is called by \GxsmMenu{File/Import/SDF-import}.
00064 
00065 % OptPlugInNotes
00066 No endianess independent code -- no cross platform data exchange possible.
00067 
00068 % OptPlugInKnownBugs
00069 The scaling of the data, especially in Z direction is not well tested.
00070 
00071 % EndPlugInDocuSection
00072  * -------------------------------------------------------------------------------- 
00073  */
00074 
00075 #include <gtk/gtk.h>
00076 #include "config.h"
00077 #include "gxsm/plugin.h"
00078 #include "gxsm/dataio.h"
00079 #include "gxsm/action_id.h"
00080 
00081 using namespace std;
00082 
00083 // Plugin Prototypes
00084 static void sdfimport_init( void );
00085 static void sdfimport_about( void );
00086 static void sdfimport_configure( void );
00087 static void sdfimport_cleanup( void );
00088 
00089 static void sdfimport_run(GtkWidget *w, void *data);
00090 
00091 // Fill in the GxsmPlugin Description here
00092 GxsmPlugin sdfimport_pi = {
00093   NULL,                   // filled in and used by Gxsm, don't touch !
00094   NULL,                   // filled in and used by Gxsm, don't touch !
00095   0,                      // filled in and used by Gxsm, don't touch !
00096   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00097                           // filled in here by Gxsm on Plugin load, 
00098                           // just after init() is called !!!
00099   // ----------------------------------------------------------------------
00100   // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc
00101   "SDFimport",
00102   // Plugin's Category - used to autodecide on Pluginloading or ignoring
00103   // NULL: load, else
00104   // example: "+noHARD +STM +AFM"
00105   // load only, if "+noHARD: no hardware" and Instrument is STM or AFM
00106   // +/-xxxHARD und (+/-INST or ...)
00107   NULL,
00108   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00109   "Imports from SDF Data",                   
00110   // Author(s)
00111   "Stefan Schroeder",
00112   // Menupath to position where it is appendet to
00113   N_("_File/_Import/"),
00114   // Menuentry
00115   N_("SDF"),
00116   // help text shown on menu
00117   N_("Import SDF File"),
00118   // more info...
00119   "no more info",
00120   NULL,          // error msg, plugin may put error status msg here later
00121   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00122   // init-function pointer, can be "NULL", 
00123   // called if present at plugin load
00124   sdfimport_init,  
00125   // query-function pointer, can be "NULL", 
00126   // called if present after plugin init to let plugin manage it install itself
00127   NULL, // query should be "NULL" for Gxsm-Math-Plugin !!!
00128   // about-function, can be "NULL"
00129   // can be called by "Plugin Details"
00130   sdfimport_about,
00131   // configure-function, can be "NULL"
00132   // can be called by "Plugin Details"
00133   sdfimport_configure,
00134   // run-function, can be "NULL", if non-Zero and no query defined, 
00135   // it is called on menupath->"plugin"
00136   sdfimport_run, // run should be "NULL" for Gxsm-Math-Plugin !!!
00137   // cleanup-function, can be "NULL"
00138   // called if present at plugin removeal
00139   sdfimport_cleanup
00140 };
00141 
00142 // Text used in Aboutbox, please update!!
00143 static const char *about_text = N_("Gxsm SDF Data Import Plugin\n\n"
00144                                    "This plugin reads in a datafile\n"
00145                                    "in sdf-format.");
00146 
00147 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00148 // Essential Plugin Function!!
00149 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00150   sdfimport_pi.description = g_strdup_printf(N_("Gxsm MathOneArg sdfimport plugin %s"), VERSION);
00151   return &sdfimport_pi; 
00152 }
00153 
00154 // 5.) Start here with the plugins code, vars def., etc.... here.
00155 // ----------------------------------------------------------------------
00156 //
00157 
00158 
00159 // init-Function
00160 static void sdfimport_init(void)
00161 {
00162   PI_DEBUG (DBG_L2, "sdfimport Plugin Init" );
00163 }
00164 
00165 // about-Function
00166 static void sdfimport_about(void)
00167 {
00168   const gchar *authors[] = { sdfimport_pi.authors, NULL};
00169   gtk_widget_show(gnome_about_new ( sdfimport_pi.name,
00170                                     VERSION,
00171                                     N_("(C) 2000 the Free Software Foundation"),
00172                                     about_text,
00173                                     authors,
00174                                     NULL, NULL, NULL
00175                           ));
00176 }
00177 
00178 // configure-Function
00179 static void sdfimport_configure(void)
00180 {
00181   if(sdfimport_pi.app)
00182     sdfimport_pi.app->message("sdfimport Plugin Configuration");
00183 }
00184 
00185 // cleanup-Function
00186 static void sdfimport_cleanup(void)
00187 {
00188   PI_DEBUG (DBG_L2, "sdfimport Plugin Cleanup" );
00189 }
00190 
00191 class SDFFile : public Dataio{
00192 public:
00193   SDFFile(Scan *s, const char *n) : Dataio(s,n){};
00194   virtual FIO_STATUS Read();
00195   virtual FIO_STATUS Write(){ return FIO_OK; };
00196 private:
00197   int dummy;
00198 };
00199 
00200 FIO_STATUS SDFFile::Read(){
00201 
00202   PI_DEBUG (DBG_L1, "***** Importing SDF-file. *****" );
00203 
00204   ifstream SDFinputstream;
00205   char SDFversionnumber [9];
00206   char SDFmanufacturerid [11];
00207   char SDFcreationdate [13];
00208   char SDFmodificationtime [13];
00209   short SDFnumpoints;
00210   short SDFnumprofiles;
00211   double SDFxscale;
00212   double SDFyscale;
00213   double SDFzscale;
00214   double SDFzresolution;
00215   char SDFcompression [2];
00216   char SDFdatatype [2];
00217   char SDFchecktype [2];
00218 
00219   SDFinputstream.open(name, ios::in);
00220 
00221   // mostly copied from nanoscope importfilter.
00222   if(!SDFinputstream.good())
00223     return status=FIO_OPEN_ERR;
00224   // Initialize with default!
00225 
00226   PI_DEBUG (DBG_L1, "Reading data... -- this is as worse as it could be to be portable:-(" );;
00227   SDFinputstream.read((char*)&SDFversionnumber, 8);
00228   SDFversionnumber[8] = '\0';
00229   SDFinputstream.read((char*)&SDFmanufacturerid, 10);
00230   SDFmanufacturerid[10] = '\0';
00231   SDFinputstream.read((char*)&SDFcreationdate, 12);
00232   SDFcreationdate[12] = '\0';
00233   SDFinputstream.read((char*)&SDFmodificationtime, 12);
00234   SDFmodificationtime[12] = '\0';
00235   SDFinputstream.read((char*)&SDFnumpoints, 2);
00236   SDFinputstream.read((char*)&SDFnumprofiles, 2);
00237   SDFinputstream.read((char*)&SDFxscale, 8);
00238   SDFinputstream.read((char*)&SDFyscale, 8);
00239   SDFinputstream.read((char*)&SDFzscale, 8);
00240   SDFinputstream.read((char*)&SDFzresolution, 8);
00241   SDFinputstream.read((char*)&SDFcompression, 1);
00242   SDFcompression[1] = '\0';
00243   SDFinputstream.read((char*)&SDFdatatype, 1);
00244   SDFdatatype[1] = '\0';
00245   SDFinputstream.read((char*)&SDFchecktype, 1);
00246   SDFchecktype[1] = '\0';
00247 
00248   PI_DEBUG (DBG_L1, "Filename = " << name );
00249   PI_DEBUG (DBG_L1, "Versionnumber = " << SDFversionnumber );
00250   PI_DEBUG (DBG_L1, "Manufacturer = " << SDFmanufacturerid );
00251   PI_DEBUG (DBG_L1, "Creationdate = " << SDFcreationdate );
00252   PI_DEBUG (DBG_L1, "Modificationtime = " << SDFmodificationtime );
00253   PI_DEBUG (DBG_L1, "Number of points = " << SDFnumpoints );
00254   PI_DEBUG (DBG_L1, "Number of profiles = " << SDFnumprofiles );
00255   PI_DEBUG (DBG_L1, "Xscale = " << SDFxscale );
00256   PI_DEBUG (DBG_L1, "Yscale = " << SDFyscale );
00257   PI_DEBUG (DBG_L1, "Zscale = " << SDFzscale );
00258   PI_DEBUG (DBG_L1, "Zresolution = " << SDFzresolution );
00259   PI_DEBUG (DBG_L1, "Compression = " << SDFcompression );
00260   PI_DEBUG (DBG_L1, "Datatype = " << SDFdatatype );
00261   PI_DEBUG (DBG_L1, "Checktype = " << SDFchecktype );
00262 
00263   /* convert Header data to mem2D data. */
00264   scan->data.s.nx = SDFnumpoints;
00265   scan->data.s.ny = SDFnumprofiles;
00266   scan->data.s.dx = SDFxscale * 10e9; // unit?
00267   scan->data.s.dy = SDFyscale * 10e9; // unit?
00268   scan->data.s.dz = SDFzscale * 10e9;
00269   scan->data.s.rx = SDFxscale * 10e9 * SDFnumpoints;
00270   scan->data.s.ry = SDFyscale * 10e9 * SDFnumprofiles;
00271 
00272   scan->data.ui.SetUser (SDFmanufacturerid);
00273 
00274   gchar *tmp=g_strconcat ("SDF-fileimport: ",
00275                           "Compression: ,", SDFcompression,
00276                           "Datatype: ,", SDFdatatype,
00277                           "Creationdate: ", SDFcreationdate,
00278                           NULL);
00279   scan->data.ui.SetComment (tmp);
00280   g_free (tmp);
00281 
00282   PI_DEBUG (DBG_L1, "Reading data...");
00283 
00284   scan->mem2d->Resize (scan->data.s.nx, scan->data.s.ny);
00285   scan->mem2d->DataRead (SDFinputstream);
00286 
00287   scan->data.orgmode = SCAN_ORG_CENTER;
00288   scan->mem2d->data->MkXLookup (-scan->data.s.rx/2., scan->data.s.rx/2.);
00289   scan->mem2d->data->MkYLookup (-scan->data.s.ry/2., scan->data.s.ry/2.);
00290 
00291   if(SDFinputstream.fail()){
00292     SDFinputstream.close();
00293     return status=FIO_READ_ERR; 
00294   }
00295 
00296   PI_DEBUG (DBG_L1, "***** Finished importing SDF-file. *****");
00297   SDFinputstream.close(); // finished all ops with file.
00298 
00299   return status=FIO_OK;
00300 }
00301 
00302 
00303 // run-Function
00304 static void sdfimport_run(GtkWidget *w, void *data)
00305 {
00306     Scan *dst;
00307     gchar *nfname = gapp->file_dialog("sdf-file to load", NULL, 
00308                                       "*.sdf", NULL, "sdf-Import");
00309     if( !nfname ) return;
00310 
00311     gapp->xsm->ActivateFreeChannel();
00312     SDFFile sdfFile(dst = gapp->xsm->GetActiveScan(), nfname);
00313 
00314     if(!dst){ 
00315       gapp->xsm->ActivateFreeChannel();
00316       dst = gapp->xsm->GetActiveScan();
00317     }
00318     if(sdfFile.Read() != FIO_OK){ 
00319       // no more data: remove allocated and unused scan now, force!
00320       gapp->xsm->SetMode(-1, ID_CH_M_OFF, TRUE); 
00321     }
00322     gapp->spm_update_all();
00323     dst->draw();
00324     dst=NULL;
00325 }

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