omicron_io.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: omicron_io.C
00006  * ========================================
00007  * 
00008  * Copyright (C) 2001 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  * some enhancements/changes:   Jan Beyer <beyer@ifm.liu.se>
00013  *
00014  * This program is free software; you can redistribute it and/or modify
00015  * it under the terms of the GNU General Public License as published by
00016  * the Free Software Foundation; either version 2 of the License, or
00017  * (at your option) any later version.
00018  *
00019  * This program is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License
00025  * along with this program; if not, write to the Free Software
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00027  */
00028 
00029 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00030 
00031 /* Please do not change the Begin/End lines of this comment section!
00032  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00033  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00034  * --------------------------------------------------------------------------------
00035 % BeginPlugInDocuSection
00036 % PlugInDocuCaption: Import/export of Scala SPM files (Omicron)
00037 
00038 % PlugInName: Omicron_IO
00039 
00040 % PlugInAuthor: Andreas Klust
00041 
00042 % PlugInAuthorEmail: klust@users.sf.net
00043 
00044 % PlugInMenuPath: File/Import/Omicron_SPM_Import
00045 
00046 % PlugInDescription
00047 
00048 This plug-in is responsible for the import and export of data in the SPM
00049 format used by Omicron's Scala software.  It supports both conventional,
00050 two-dimensional data such as topographic images and gridded spectroscopic
00051 data.  Data acquired using the point spectroscopy mode of the Scala system
00052 is not written in the SPM format.  Therefore, point spectroscopy data is
00053 ignored by this plug-in.
00054 
00055 In the Scala SPM format, data is saved in two parts:  Firstly, the data
00056 itself as binary file.  Secondly, additional information, e.g.\ scan size,
00057 in an extra ASCII file with the filename suffix ".par".  This parameter file
00058 can contain information on several images.  Therefore, for importing SPM
00059 files, the binary file must be selected.  The parameter file contains many
00060 comments making it human readable.
00061 
00062 % PlugInUsage
00063 When the Omicron\_IO plug-in is installed, Scala SPM files can be loaded like
00064 any other files supported by \Gxsm.  Alternatively, 
00065 \GxsmMenu{File/Import/Omicron SPM Import} can be used.
00066 
00067 
00068 % OptPlugInKnownBugs
00069 Exporting data in the Scala SPM format is not yet implemented.
00070 
00071 % EndPlugInDocuSection
00072  * -------------------------------------------------------------------------------- 
00073  */
00074 
00075 
00076 #include <gtk/gtk.h>
00077 #include <locale.h>
00078 
00079 #include "config.h"
00080 #include "gxsm/plugin.h"
00081 #include "gxsm/dataio.h"
00082 #include "gxsm/action_id.h"
00083 #include "gxsm/mem2d.h"
00084 #include "gxsm/unit.h"
00085 
00086 #ifndef WORDS_BIGENDIAN
00087 # define WORDS_BIGENDIAN 0
00088 #endif
00089 
00090 using namespace std;
00091 
00092 
00093 // Plugin Prototypes
00094 static void omicron_io_init (void);
00095 static void omicron_io_query (void);
00096 static void omicron_io_about (void);
00097 static void omicron_io_configure (void);
00098 static void omicron_io_cleanup (void);
00099 
00100 static void omicron_io_filecheck_load_callback (gpointer data );
00101 static void omicron_io_filecheck_save_callback (gpointer data );
00102 
00103 static void omicron_io_import_callback (GtkWidget *w, void *data);
00104 //static void omicron_io_export_callback (GtkWidget *w, void *data);
00105 
00106 
00107 
00108 
00109 // GxsmPlugin Description
00110 
00111 GxsmPlugin omicron_io_pi = {
00112   NULL,                   // filled in and used by Gxsm, don't touch !
00113   NULL,                   // filled in and used by Gxsm, don't touch !
00114   0,                      // filled in and used by Gxsm, don't touch !
00115   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00116                           // filled in here by Gxsm on Plugin load, 
00117                           // just after init() is called !!!
00118   "Omicron_IO",
00119   NULL,                   // PlugIn's Categorie, set to NULL for all, I just don't want this always to be loaded!
00120   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00121   "Im/Export of Omicron SPM files.",
00122   "Andreas Klust",
00123   N_("_File/Im,Export"),
00124   N_("..."),
00125   NULL,
00126   "This plug-in is responsible for the im/export of data in the file format used by Omicron's SCALA software.",
00127   NULL,          // error msg, plugin may put error status msg here later
00128   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00129   omicron_io_init,  
00130   omicron_io_query,  
00131   // about-function, can be "NULL"
00132   // can be called by "Plugin Details"
00133   omicron_io_about,
00134   // configure-function, can be "NULL"
00135   // can be called by "Plugin Details"
00136   omicron_io_configure,
00137   // run-function, can be "NULL", if non-Zero and no query defined, 
00138   // it is called on menupath->"plugin"
00139   NULL,
00140   // cleanup-function, can be "NULL"
00141   // called if present at plugin removeal
00142   omicron_io_cleanup
00143 };
00144 
00145 
00146 
00147 
00148 // Text used in Aboutbox
00149 static const char *about_text = N_("Gxsm data file import/export plugin\n\n"
00150                                    "This plugin reads Omicron SCALA SPM files."
00151         );
00152 
00153 
00154 
00155 
00156 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00157 // Essential Plugin Function!!
00158 
00159 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00160   omicron_io_pi.description = g_strdup_printf(N_("Gxsm omicron_io plugin %s"), VERSION);
00161   return &omicron_io_pi; 
00162 }
00163 
00164 
00165 
00166 
00167 
00168 // Query Function, installs Plugin's in File/Import and Export Menupaths!
00169 // ----------------------------------------------------------------------
00170 // Import Menupath is "File/Import/Omicron SPM import"
00171 // Export Menupath is "File/Export/Omicron SPM export"
00172 // ----------------------------------------------------------------------
00173 // !!!! make sure the "omicron_io_cleanup()" function (see below) !!!!
00174 // !!!! removes the correct menuentries !!!!
00175 
00176 static void omicron_io_query(void)
00177 {
00178   static GnomeUIInfo menuinfo_Import[] = { 
00179     { GNOME_APP_UI_ITEM, 
00180       N_("Omicron SPM Import"), N_("Import of the Omicron SPM format"), 
00181       (gpointer) omicron_io_import_callback, NULL,
00182       NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_OPEN,
00183       0, GDK_CONTROL_MASK, NULL },
00184     GNOMEUIINFO_END
00185   };
00186 
00187   gnome_app_insert_menus (
00188           GNOME_APP(omicron_io_pi.app->getApp()), 
00189           N_("_File/Import/"), 
00190           menuinfo_Import
00191           );
00192 
00193 //   static GnomeUIInfo menuinfo_Export[] = { 
00194 //     { GNOME_APP_UI_ITEM, 
00195 //       N_("Omicron SPM Export"), N_("Export of the Omicron SPM format"), 
00196 //       (gpointer) omicron_io_export_callback, NULL,
00197 //       NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_SAVE, 
00198 //       0, GDK_CONTROL_MASK, NULL },
00199 //     GNOMEUIINFO_END
00200 //   };
00201 
00202 //   gnome_app_insert_menus (
00203 //        GNOME_APP(omicron_io_pi.app->getApp()), 
00204 //        N_("_File/Export/"), 
00205 //        menuinfo_Export
00206 //        );
00207 
00208   if(omicron_io_pi.status) g_free(omicron_io_pi.status); 
00209   omicron_io_pi.status = g_strconcat (
00210           N_("Plugin query has attached "),
00211           omicron_io_pi.name, 
00212           N_(": File IO Filters are ready to use"),
00213           NULL);
00214 
00215 // register this plugins filecheck functions with Gxsm now!
00216 // This allows Gxsm to check files from DnD, open, 
00217 // and cmdline sources against all known formats automatically - no explicit im/export is necessary.
00218   omicron_io_pi.app->ConnectPluginToLoadFileEvent (omicron_io_filecheck_load_callback);
00219   omicron_io_pi.app->ConnectPluginToSaveFileEvent (omicron_io_filecheck_save_callback);
00220 }
00221 
00222 
00223 
00224 
00225 // init-Function
00226 
00227 static void omicron_io_init(void)
00228 {
00229   PI_DEBUG (DBG_L2, "omicron_io Plugin Init" );
00230 }
00231 
00232 
00233 
00234 
00235 
00236 // about-Function
00237 
00238 static void omicron_io_about(void)
00239 {
00240   const gchar *authors[] = { omicron_io_pi.authors, NULL};
00241   gtk_widget_show(gnome_about_new ( omicron_io_pi.name,
00242                                     VERSION,
00243                                     N_("(C) 2001 the Free Software Foundation"),
00244                                     about_text,
00245                                     authors,
00246                                     NULL, NULL, NULL
00247                                     ));
00248 }
00249 
00250 
00251 
00252 
00253 
00254 // configure-Function
00255 
00256 static void omicron_io_configure(void)
00257 {
00258   if(omicron_io_pi.app)
00259     omicron_io_pi.app->message("omicron_io Plugin Configuration");
00260 }
00261 
00262 
00263 
00264 
00265 
00266 // cleanup-Function, make sure the Menustrings are matching those above!!!
00267 
00268 static void omicron_io_cleanup(void)
00269 {
00270   PI_DEBUG (DBG_L2, "omicron_io Plugin Cleanup" );
00271   gnome_app_remove_menus (GNOME_APP (omicron_io_pi.app->getApp()),
00272                           N_("File/Import/Omicron SPM Import"), 1);
00273 //   gnome_app_remove_menus (GNOME_APP (omicron_io_pi.app->getApp()),
00274 //                        N_("File/Export/Omicron SPM Export"), 1);
00275 }
00276 
00277 
00278 
00279 
00280 
00281 // make a new derivate of the base class "Dataio"
00282 
00283 class Omicron_SPM_ImExportFile : public Dataio{
00284  public:
00285   Omicron_SPM_ImExportFile(Scan *s, const char *n) : Dataio(s,n){ };
00286   virtual FIO_STATUS Read();
00287   virtual FIO_STATUS Write();
00288  private:
00289   // binary data read
00290   FIO_STATUS spmReadDat(const gchar *fname);
00291   // gridded spectroscopy binary data read
00292   FIO_STATUS spmReadGridSpecDat(const gchar *fname);
00293   // parses ASCII parameter files
00294   FIO_STATUS spmReadPar(const gchar *fname, const gchar *fsuffix);
00295 
00296 };
00297 
00298 
00299 
00300 // spm import
00301 FIO_STATUS Omicron_SPM_ImExportFile::Read(){
00302         FIO_STATUS ret = FIO_OK;
00303         gchar *fdatname = (gchar*) name;
00304         gchar *fparname=NULL;
00305         gchar *fbasename=NULL;
00306         gchar *fsuffix=NULL;
00307         
00308         // name should have at least 4 chars: ".ext"
00309         if (name == NULL || strlen(name) < 4){
00310                 ret = FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00311                 return ret;
00312         }
00313         
00314         // split filename in basename and suffix,
00315         // generate parameter file name
00316         fbasename = g_strndup (name, strlen(name)-4);
00317         fsuffix = g_strdup (name+strlen(name)-4);
00318         fparname = g_strconcat (fbasename, ".par", NULL);
00319         
00320         // check for known file types
00321         // accepting topography forward (*.tf?) and backward (*.tb?) files
00322         // as well as (gridded) spectroscopy data (*.sf? and *.sb?)
00323         if ( strncmp(fsuffix,".tf", 3) && strncmp(fsuffix,".tb", 3) && \
00324              strncmp(fsuffix,".sf", 3) && strncmp(fsuffix,".sb", 3) )
00325                 ret = FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00326         else{  
00327                 
00328                 // check for data and par file exists and is OK
00329                 std::ifstream f;
00330                 f.open(fdatname, std::ios::in | std::ios::binary);
00331                 if(!f.good()){
00332                         PI_DEBUG (DBG_L2, "Omicron_SPM_ImExportFile::Read: data file error" );
00333                         ret = status = FIO_OPEN_ERR;
00334                 }
00335                 f.close();
00336                 f.open(fparname, std::ios::in);
00337                 if(!f.good()){
00338                         PI_DEBUG (DBG_L2, "Omicron_SPM_ImExportFile::Read: parameter file error" );
00339                         ret = status = FIO_OPEN_ERR;
00340                 }
00341                 f.close();
00342                 
00343                 
00344                 PI_DEBUG (DBG_L2, "Omicron_SPM_ImExportFile::Read: " << fdatname << 
00345                         " is a Omicron SPM File!" );
00346                 
00347                 
00348                 // parse parameter file
00349                 if ( ret == FIO_OK )
00350                         ret = spmReadPar (fparname, fsuffix);
00351                 
00352                 // read the binary data
00353                 if ( ret == FIO_OK ) {
00354                   if ( scan->data.s.nvalues == 1 )
00355                         ret = spmReadDat (fdatname);
00356                   else
00357                     ret = spmReadGridSpecDat (fdatname);
00358                 }
00359         }
00360 
00361         g_free (fbasename);
00362         g_free (fparname);
00363         g_free (fsuffix);
00364 
00365         scan->mem2d->data->MkYLookup(scan->data.s.y0, scan->data.s.y0+scan->data.s.ry);
00366         scan->mem2d->data->MkXLookup(scan->data.s.x0-scan->data.s.rx/2., scan->data.s.x0+scan->data.s.rx/2.);
00367         scan->mem2d->data->MkVLookup (-10., 10.);
00368         
00369         return ret;
00370 }
00371 
00372 
00373 FIO_STATUS Omicron_SPM_ImExportFile::spmReadDat(const gchar *fname)
00374 {
00375         // handle scan name
00376         scan->data.ui.SetName (fname);
00377         scan->data.ui.SetOriginalName (fname);
00378         
00379         // lets make a scan, and SPM files are of type short!
00380         scan->mem2d->Resize (
00381                 scan->data.s.nx,
00382                 scan->data.s.ny,
00383                 ZD_SHORT
00384                 );
00385 
00386         PI_DEBUG (DBG_L2, "Omicron_SPM_ImExportFile: Resize done." );
00387         
00388         
00389         // prepare buffer
00390         short *buf;
00391         if(!(buf = g_new(short, scan->data.s.nx*scan->data.s.ny)))
00392                 return FIO_NO_MEM;
00393         
00394         // read the actual data  
00395         std::ifstream f;
00396         f.open(fname, std::ios::in | std::ios::binary);
00397         if(f.good())
00398                 f.read((char*)buf, sizeof(short) * scan->data.s.nx * scan->data.s.ny);
00399         else {
00400                 g_free(buf);
00401                 return FIO_OPEN_ERR;  
00402         }
00403         f.close();
00404 
00405         // and put the data into mem2d
00406         short *pt = buf;
00407         char *cpt, low;
00408         for (int j=0; j < scan->data.s.ny; ++j)
00409           for (int i=0; i < scan->data.s.nx; ++i, ++pt) {
00410             // Scala SPM files are stored using big endian format
00411             if (!WORDS_BIGENDIAN)  {
00412               cpt = (char*)pt;
00413               low = cpt[0];
00414               cpt[0] = cpt[1];
00415               cpt[1] = low;
00416             }
00417 
00418             // Attention: Omicron seems to save last line first!
00419             scan->mem2d->PutDataPkt ((double)*pt, i, scan->data.s.ny-j-1);
00420           }
00421 
00422         g_free (buf);
00423         
00424         PI_DEBUG (DBG_L2, "Omicron_SPM_ImExportFile: Import done." );
00425         
00426         // read done.
00427         return FIO_OK; 
00428 }
00429 
00430 
00431 FIO_STATUS Omicron_SPM_ImExportFile::spmReadGridSpecDat(const gchar *fname) 
00432 {
00433   // handle scan name
00434         scan->data.ui.SetName (fname);
00435         scan->data.ui.SetOriginalName (fname);
00436         
00437         // lets make a spectro grid, and SPM files are of type short!
00438         scan->mem2d->Resize (
00439                 scan->data.s.nx,
00440                 scan->data.s.ny,
00441                 scan->data.s.nvalues,
00442                 ZD_SHORT
00443                 );
00444 
00445         PI_DEBUG (DBG_L2, "Omicron_SPM_ImExportFile: Resize done." );
00446         
00447         // prepare buffer
00448         short *buf;
00449         if(!(buf = g_new(short, scan->data.s.nx*scan->data.s.ny)))
00450                 return FIO_NO_MEM;
00451 
00452         // read the actual data
00453         // and put the data into mem2d
00454         ifstream f;
00455         f.open(fname, ios::in | ios::binary);
00456         for (int v=0; v < scan->data.s.nvalues; ++v) {
00457           if(f.good())
00458             f.read((char*)buf, sizeof(short) * scan->data.s.nx * scan->data.s.ny);
00459           else {
00460             g_free(buf);
00461             return FIO_OPEN_ERR;  
00462           }
00463 
00464           // and put the data into mem2d
00465           short *pt = buf;
00466           char *cpt, low;
00467           for (int j=0; j < scan->data.s.ny; ++j)
00468             for (int i=0; i < scan->data.s.nx; ++i, ++pt) {
00469               // Scala SPM files are stored using big endian format
00470               if (!WORDS_BIGENDIAN)  {
00471                 cpt = (char*)pt;
00472                 low = cpt[0];
00473                 cpt[0] = cpt[1];
00474                 cpt[1] = low;
00475               }
00476 
00477               // Attention: Omicron seems to save last line first!
00478               scan->mem2d->PutDataPkt ((double)*pt, i, scan->data.s.ny-j-1, v);
00479             }
00480           
00481         }
00482         f.close();
00483         
00484         g_free (buf);
00485         
00486         PI_DEBUG (DBG_L2, "Omicron_SPM_ImExportFile: Import done." );
00487         
00488         // read done.
00489         return FIO_OK; 
00490 }
00491 
00492 
00493 
00494 
00495 FIO_STATUS Omicron_SPM_ImExportFile::spmReadPar(const gchar *fname, const gchar *fsuffix)
00496 {
00497   char valid = FALSE, spectro = FALSE, spectrogrid = FALSE, dualmode = FALSE;
00498   int xspecpoints, yspecpoints;
00499   GString *comment = g_string_new(NULL);
00500 
00501   // first set some default parameters...
00502   setlocale(LC_NUMERIC, "C");           /* Scala SPM files have dots as decimal separator */
00503 
00504   // this is mandatory.
00505   scan->data.s.ntimes  = 1;
00506   scan->data.s.nvalues = 1;
00507 
00508   // put some usefull values in the ui structure
00509   if(getlogin()){
00510     scan->data.ui.SetUser (getlogin());
00511   }
00512   else{
00513     scan->data.ui.SetUser ("unknown user");
00514   }
00515   /* time_t t; // Scan - Startzeit eintragen 
00516   time(&t);
00517   gchar *tmp=g_strconcat ((ctime(&t)), " (Imported)", NULL);
00518   scan->data.ui.SetDateOfScan (tmp);
00519   g_free (tmp); */
00520   
00521   scan->data.ui.SetType ("Omicron SPM Type: SHT ");
00522 
00523   /* tmp=g_strconcat ("Imported by gxsm Omicron SPM import plugin from: ",
00524                    fname,
00525                    NULL);
00526   scan->data.ui.SetComment (tmp);
00527   g_free (tmp); */
00528   
00529   // initialize scan structure -- this is a minimum example
00530   scan->data.s.dx = 1;
00531   scan->data.s.dy = 1;
00532   scan->data.s.dz = 1;
00533   scan->data.s.rx = scan->data.s.nx;
00534   scan->data.s.ry = scan->data.s.ny;
00535   scan->data.s.x0 = 0;
00536   scan->data.s.y0 = 0;
00537   scan->data.s.alpha = 0;
00538   
00539   // be nice and reset this to some defined state
00540   scan->data.display.cpshigh       = 1e3;
00541   scan->data.display.cpslow        = 1.;
00542   scan->data.display.cnttime       = 1.;
00543   
00544   
00545   // start the real thing:
00546 
00547   // open the parameter file
00548   std::ifstream f;
00549   f.open(fname, std::ios::in);
00550   if(!f.good())
00551     return FIO_OPEN_ERR;  
00552 
00553   UnitObj *xu = gapp->xsm->MakeUnit ("nm", "X");
00554   scan->data.SetXUnit(xu);
00555   delete xu;
00556 
00557   UnitObj *yu = gapp->xsm->MakeUnit ("nm", "Y");
00558   scan->data.SetYUnit(yu);
00559   delete yu;
00560 
00561   /* read the par file line-by-line */
00562   gchar linebuf[100];
00563   while (!f.eof()) {
00564     
00565     f.getline (linebuf, 100);
00566 
00567     /* Scan Date */
00568     if ( !strncmp (linebuf, "Date", 4)) {
00569         gchar scandate[11];
00570         gchar scantime[6];
00571         sscanf (linebuf, "%*[^0-9]%10s %6s", scandate, scantime);
00572         scan->data.ui.SetDateOfScan ( g_strconcat(scandate, " ", scantime, NULL) );
00573     }
00574 
00575     /* user name */
00576     if ( !strncmp (linebuf, "User", 4) ) {
00577       char user[80];
00578       sscanf (linebuf, "%*[^:]: %80s", user);
00579       scan->data.ui.SetUser (user);
00580       PI_DEBUG (DBG_L2, " user: " << scan->data.ui.user );
00581     }
00582 
00583     /* Comment */
00584     if ( !strncmp (linebuf, "Comment", 7) ) {
00585 /*              GString *comment = g_string_new(NULL);*/
00586                 gchar c[100];
00587                 sscanf (linebuf, "%*[^:]: %[^\n]100s", c);
00588                 g_string_append(comment, c);
00589                 //g_free(c);
00590                 f.getline(linebuf,100);
00591                 while (strncmp (linebuf,";",1) != 0) {
00592                         sscanf(linebuf,"%*[ ]%[^\n]100s",linebuf);              /* Remove leading whitespaces*/
00593                         g_string_append (comment, linebuf);
00594                         f.getline(linebuf,100);
00595                 }
00596                 scan->data.ui.SetComment (comment->str);        /* This will destroy the former "imported by..." comment */
00597                 g_string_free(comment, TRUE);
00598                 PI_DEBUG (DBG_L2, " comment: " << scan->data.ui.comment );
00599     }
00600 
00601      // range: x
00602     if ( !strncmp (linebuf, "Field X Size in nm", 18) ) {
00603       double rx;
00604       sscanf (linebuf, "%*[^0-9]%lf", &rx);
00605       scan->data.s.rx = rx * 10;
00606       PI_DEBUG (DBG_L2, " rx = " << scan->data.s.rx );
00607     }
00608 
00609     // range: y
00610     if ( !strncmp (linebuf, "Field Y Size in nm", 18) ) {
00611       double ry;
00612       sscanf (linebuf, "%*[^0-9]%lf", &ry);
00613       scan->data.s.ry = ry * 10;
00614       PI_DEBUG (DBG_L2, " ry = " << scan->data.s.ry );
00615     }
00616 
00617     // scan size: nx
00618     if ( !strncmp (linebuf, "Image Size in X", 15) ) {
00619       int nx;
00620       sscanf (linebuf, "%*[^0-9]%d", &nx);
00621       scan->data.s.nx = nx;
00622       PI_DEBUG (DBG_L2, " nx = " << scan->data.s.nx );
00623     }
00624 
00625     // scan size: ny
00626     if ( !strncmp (linebuf, "Image Size in Y", 15) ) {
00627       int ny;
00628       sscanf (linebuf, "%*[^0-9]%d", &ny);
00629       scan->data.s.ny = ny;
00630       PI_DEBUG (DBG_L2, " ny = " << scan->data.s.ny );
00631     }
00632 
00633     // step size: x
00634     if ( !strncmp (linebuf, "Increment X", 11) ) {
00635       double dx;
00636       sscanf (linebuf, "%*[^0-9]%lf", &dx);
00637       scan->data.s.dx = dx * 10;
00638       PI_DEBUG (DBG_L2, " dx = " << scan->data.s.dx );
00639     }
00640 
00641     // step size: y
00642     if ( !strncmp (linebuf, "Increment Y", 11) ) {
00643       double dy;
00644       sscanf (linebuf, "%*[^0-9]%lf", &dy);
00645       scan->data.s.dy = dy * 10;
00646       PI_DEBUG (DBG_L2, " dy = " << scan->data.s.dy );
00647     }
00648 
00649     // scan angle
00650     if ( !strncmp (linebuf, "Scan Angle", 10) ) {
00651       double alf;
00652       sscanf (linebuf, "%*[^0-9-]%lf", &alf);
00653       scan->data.s.alpha = alf;
00654       PI_DEBUG (DBG_L2, " alpha = " << scan->data.s.alpha );
00655     }
00656 
00657     // offset: x
00658     if ( !strncmp (linebuf, "X Offset", 8) ) {
00659       double x0;
00660       sscanf (linebuf, "%*[^0-9-]%lf", &x0);
00661       scan->data.s.x0 = x0 * 10;
00662       PI_DEBUG (DBG_L2, " x0 = " << scan->data.s.x0 );
00663     }
00664 
00665     // offset: y
00666     if ( !strncmp (linebuf, "Y Offset", 8) ) {
00667       double y0;
00668       sscanf (linebuf, "%*[^0-9-]%lf", &y0);
00669       scan->data.s.y0 = y0 * 10;
00670       PI_DEBUG (DBG_L2, " y0 = " << scan->data.s.y0 );
00671     }
00672 
00673 
00674     // topo channel information
00675     if ( !strncmp (linebuf, "Topographic Channel", 19) ) {
00676       double dz;
00677       double lrz, urz;                  /* lower and upper Range Z */
00678       char fn[100], zunit[3], zlabel[2];
00679           gchar scantype[20], datatype[5];
00680       gchar *fs;
00681       
00682       f.getline (linebuf, 100); // forward vs. backward
00683           sscanf(linebuf, "%*[ ]%8s",scantype);
00684       f.getline (linebuf, 100); // min raw val
00685       f.getline (linebuf, 100); // max raw val
00686       
00687       f.getline (linebuf, 100); // min phys val
00688       sscanf (linebuf, " %lf", &lrz);
00689       f.getline (linebuf, 100); // max phys val
00690       sscanf (linebuf, " %lf", &urz);
00691       f.getline (linebuf, 100); // resolution
00692       sscanf (linebuf, " %lf", &dz);
00693       f.getline (linebuf, 100); // phys. unit
00694       sscanf (linebuf, "%*[ ]%2s", zunit);
00695       f.getline (linebuf, 100); // dat filename
00696       sscanf (linebuf, " %100s", fn);
00697       f.getline (linebuf, 100); // display name
00698           sscanf (linebuf, "%*[ ]%5s", datatype);
00699  
00700       // do we read the correct par set?
00701       fs = g_strdup (fn+strlen(fn)-4);
00702       if (!strcmp(fs,fsuffix)) {  // Yes, we do!
00703                 valid = TRUE;
00704                 scan->data.ui.SetType(g_strconcat(scantype, " ", datatype));
00705 
00706                 if (strcmp(zunit,"nm") == 0) {
00707                         scan->data.s.rz = (abs(lrz) + abs(urz))*10;
00708                         scan->data.s.dz = dz*10;
00709                         strcpy(zunit, "AA");
00710                         strcpy(zlabel, "Z");
00711                 }
00712                 else {
00713                         scan->data.s.rz = (abs(lrz) + abs(urz));
00714                         scan->data.s.dz = dz;
00715                         strcpy(zlabel, "I");            /* Topography always in nm, otherwise current ??? At least up to my little experience...*/
00716                 }
00717 
00718                 PI_DEBUG (DBG_L2, " z unit: " << zunit );
00719                 UnitObj *zu = gapp->xsm->MakeUnit (zunit, zlabel);
00720                 scan->data.SetZUnit(zu);
00721                 delete zu;
00722       }
00723     }
00724     
00725     
00726     // spectroscopic channel information
00727     if ( !strncmp (linebuf, "Spectroscopy Channel", 20) ) {
00728       double ds;
00729       char fn[100], zunit[6], vunit[6];
00730       gchar *fs;
00731       int nv;
00732       
00733       f.getline (linebuf, 100); // parameter
00734       f.getline (linebuf, 100); // forward vs. backward
00735       f.getline (linebuf, 100); // min raw val
00736       f.getline (linebuf, 100); // max raw val
00737       f.getline (linebuf, 100); // min phys val
00738       f.getline (linebuf, 100); // max phys val
00739       f.getline (linebuf, 100); // resolution
00740       sscanf (linebuf, " %lf", &ds);
00741       f.getline (linebuf, 100); // phys. unit
00742       sscanf (linebuf, " %5s", zunit);
00743       f.getline (linebuf, 100); // number of spectro points
00744       sscanf (linebuf, "%*[^0-9]%d", &nv);
00745       f.getline (linebuf, 100); // start point spectroscopy
00746       f.getline (linebuf, 100); // end point spectroscopy
00747       f.getline (linebuf, 100); // increment point spectroscopy
00748       f.getline (linebuf, 100); // acquisition time per spectroscopy point
00749       f.getline (linebuf, 100); // delay time per spectroscopy point
00750       f.getline (linebuf, 100); // feedback on/off
00751       f.getline (linebuf, 100); // dat filename
00752       sscanf (linebuf, " %100s", fn);
00753       f.getline (linebuf, 100); // display name
00754       
00755       // do we read the correct par set?
00756       fs = g_strdup (fn+strlen(fn)-4);
00757       if (!strcmp(fs,fsuffix)) {  // Yes, we do!
00758         valid = TRUE;
00759         spectro = TRUE;
00760         
00761         scan->data.s.nvalues = nv;
00762         
00763         PI_DEBUG (DBG_L2, " zunit: " << zunit );
00764         UnitObj *zu = gapp->xsm->MakeUnit (zunit, "I");
00765         scan->data.SetZUnit(zu);
00766         scan->data.s.dz = zu->Usr2Base(ds);       
00767         delete zu;
00768       }
00769     }
00770 
00771     // spectro points in x direction
00772     if ( !strncmp (linebuf, "Spectroscopy Points in X", 24) ) {
00773       sscanf (linebuf, "%*[^0-9]%d", &xspecpoints);
00774       PI_DEBUG (DBG_L2, " xspecpoints: " << xspecpoints );
00775     }
00776     
00777     // spectro points in y direction
00778     if ( !strncmp (linebuf, "Spectroscopy Lines in Y", 23) ) {
00779       sscanf (linebuf, "%*[^0-9]%d", &yspecpoints);
00780       PI_DEBUG (DBG_L2, " yspecpoints: " << yspecpoints );
00781     }
00782 
00783     // dual voltage mode
00784     if ( !strncmp (linebuf, "Dual mode", 9) ) {
00785       char buf[4];
00786       sscanf (linebuf, "%*[^:]: %3s", buf);
00787       if ( !strncmp (buf, "On", 2) ) dualmode = TRUE;
00788     }
00789 
00790     // gap voltage
00791     if ( !strncmp (linebuf, "Gap Voltage", 11) ) {
00792       double ugap;
00793       if (!dualmode || fsuffix[2] == 'f')  // either single volt or forw. dir
00794         sscanf (linebuf, "%*[^0-9-]%lf", &ugap);
00795       else {
00796         f.getline (linebuf, 100);
00797         sscanf (linebuf, "%*[^0-9-]%lf", &ugap);
00798       }
00799       scan->data.s.Bias = ugap;
00800       PI_DEBUG (DBG_L2, " ugap = " << scan->data.s.Bias );
00801     }
00802 
00803     // current feedback setpoint
00804     // missing unit support!
00805     if ( !strncmp (linebuf, "Feedback Set", 12) ) {
00806       double iset;
00807 /*        gchar tmp[100];*/
00808       sscanf (linebuf, "%*[^0-9-]%lf", &iset);
00809       scan->data.s.Current = iset;
00810 /*      doesn't work (yet) */
00811 /*        sprintf(tmp, "I_set: %4.2lf nA", iset);               
00812                 printf("Current Setpoint is %4.2lf.\n", iset);
00813                 printf("as a string: %14s\n",tmp);
00814           g_string_append(comment, tmp);
00815           scan->data.ui.SetComment(comment->str);
00816           g_free(tmp);*/
00817       PI_DEBUG (DBG_L2, " iset = " << scan->data.s.Current );
00818     }
00819 
00820   }
00821 
00822   f.close();
00823 
00824   
00825   // reading a spectro grid?
00826   if (spectro && xspecpoints > 0 && yspecpoints > 0 && \
00827       scan->data.s.nvalues > 1) {
00828     spectrogrid = TRUE;
00829     scan->data.s.nx = xspecpoints;
00830     scan->data.s.ny = yspecpoints;
00831     scan->data.s.dx = scan->data.s.rx / scan->data.s.nx;
00832     scan->data.s.dy = scan->data.s.ry / scan->data.s.ny;
00833   }
00834 
00835   // test for various errors:
00836   if (!valid) return FIO_INVALID_FILE;
00837   // single point spectra not (yet) implemented
00838   if (spectro && !spectrogrid) return FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00839 
00840   return FIO_OK; 
00841 }
00842 
00843 
00844 
00845 FIO_STATUS Omicron_SPM_ImExportFile::Write()
00846 {
00847 // to be done...
00848 
00849         return FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00850 }
00851 
00852 // Plugin's Notify Cb's, registered to be called on file load/save to check file
00853 // return via filepointer, it is set to Zero or passed as Zero if file has been processed!
00854 // That's all fine, you should just change the Text Stings below...
00855 
00856 
00857 static void omicron_io_filecheck_load_callback (gpointer data){
00858   gchar **fn = (gchar**)data;
00859   if (*fn){
00860     PI_DEBUG (DBG_L2, "Check File: omicron_io_filecheck_load_callback called with >"
00861          << *fn << "<" );
00862     
00863     Scan *dst = gapp->xsm->GetActiveScan();
00864     if(!dst){ 
00865       gapp->xsm->ActivateFreeChannel();
00866       dst = gapp->xsm->GetActiveScan();
00867     }
00868     Omicron_SPM_ImExportFile fileobj (dst, *fn);
00869     
00870     FIO_STATUS ret = fileobj.Read(); 
00871     if (ret != FIO_OK){ 
00872             // I'am responsible! (But failed)
00873             if (ret != FIO_NOT_RESPONSIBLE_FOR_THAT_FILE){
00874                     *fn=NULL;
00875                     PI_DEBUG (DBG_L2, "Read Error " << ((int)ret) << "!!!!!!!!" );
00876             }else{
00877                     PI_DEBUG (DBG_L2, "No Omicron Scala File!" );
00878             }
00879             // no more data: remove allocated and unused scan now, force!
00880             gapp->xsm->SetMode(-1, ID_CH_M_OFF, TRUE); 
00881     }else{
00882       // got it!
00883       *fn=NULL;
00884       
00885       // Now update gxsm main window data fields
00886       gapp->xsm->ActiveScan->GetDataSet(gapp->xsm->data);
00887       gapp->xsm->AutoDisplay ();
00888       gapp->spm_update_all();
00889       dst->draw();
00890     }
00891   }else{
00892     PI_DEBUG (DBG_L2, "omicron_io_filecheck_load: Skipping" );
00893   }
00894 }
00895 
00896 
00897 
00898 static void omicron_io_filecheck_save_callback ( gpointer data ){
00899   gchar **fn = (gchar**)data;
00900   if (*fn){
00901     Scan *src;
00902     PI_DEBUG (DBG_L2, "Check File: omicron_io_filecheck_save_callback called with >"
00903          << *fn << "<" );
00904     
00905     Omicron_SPM_ImExportFile fileobj (src = gapp->xsm->GetActiveScan(), *fn);
00906     
00907     FIO_STATUS ret;
00908     ret = fileobj.Write(); 
00909     
00910     if(ret != FIO_OK){
00911       // I'am responsible! (But failed)
00912       if (ret != FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00913         *fn=NULL;
00914       PI_DEBUG (DBG_L2, "Write Error " << ((int)ret) << "!!!!!!!!" );
00915     }else{
00916       // write done!
00917       *fn=NULL;
00918     }
00919   }else{
00920     PI_DEBUG (DBG_L2, "omicron_io_filecheck_save: Skipping >" << *fn << "<" );
00921   }
00922 }
00923 
00924 
00925 // Menu Call Back Fkte
00926 
00927 static void omicron_io_import_callback(GtkWidget *w, void *data)
00928 {
00929   gchar *fn = gapp->file_dialog("Omicron SPM Import", NULL,
00930                                 "*.*", 
00931                                 NULL, "SPM-Import");
00932   
00933   PI_DEBUG (DBG_L2, "FLDLG-IM::" << fn );
00934   omicron_io_filecheck_load_callback (&fn );
00935 }
00936 
00937 
00938 // static void omicron_io_export_callback(GtkWidget *w, void *data)
00939 // {
00940 //   gchar *fn = gapp->file_dialog("Omicron SPM Export", NULL,
00941 //                              "*.*",
00942 //                              "","SPM-Export");
00943   
00944 //   PI_DEBUG (DBG_L2, "FLDLG-EX::" << fn );
00945 //   omicron_io_filecheck_save_callback (&fn );
00946 // }
00947 

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