rhk2000_import.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: rhk2000_im_export.C
00006  * ========================================
00007  * 
00008  * Copyright (C) 2004 The Free Software Foundation
00009  *
00010  * Authors: Peter Wahl <wahl@fkf.mpg.de>
00011  *
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  * --------------------------------------------------------------------------------
00032 % BeginPlugInDocuSection
00033 % PlugInDocuCaption: Import Tool for RHK STM-200
00034 
00035 % PlugInName: RHK2000-Import
00036 
00037 % PlugInAuthor: Peter Wahl
00038 
00039 % PlugInAuthorEmail: wahl@fkf.mpg.de
00040 
00041 % PlugInMenuPath: File/Import/RHK STM-200 import 
00042 
00043 % PlugInDescription
00044 
00045 This plug-in is responsible for importing files saved by RHK STM-2000 systems.
00046 The STM-2000 system is the STM electronics manufactured by RHK based on SGI 
00047 workstations.
00048 
00049 % PlugInUsage
00050 Registers itself for loading files with the filename suffix ".Stm".
00051 
00052 % EndPlugInDocuSection
00053  * -------------------------------------------------------------------------------- 
00054  */
00055 
00056 
00057 #include <gtk/gtk.h>
00058 #include "config.h"
00059 #include "gxsm/plugin.h"
00060 #include "gxsm/dataio.h"
00061 #include "gxsm/action_id.h"
00062 #include "gxsm/util.h"
00063 
00064 #include <sstream>
00065 
00066 using namespace std;
00067 
00068 #define IMGMAXCOLORS 64
00069 
00070 // Plugin Prototypes
00071 static void rhk200_im_export_init (void);
00072 static void rhk200_im_export_query (void);
00073 static void rhk200_im_export_about (void);
00074 static void rhk200_im_export_configure (void);
00075 static void rhk200_im_export_cleanup (void);
00076 
00077 static void rhk200_im_export_filecheck_load_callback (gpointer data );
00078 
00079 static void rhk200_im_export_import_callback (GtkWidget *w, void *data);
00080 
00081 // Fill in the GxsmPlugin Description here
00082 GxsmPlugin rhk200_im_export_pi = {
00083   NULL,                   // filled in and used by Gxsm, don't touch !
00084   NULL,                   // filled in and used by Gxsm, don't touch !
00085   0,                      // filled in and used by Gxsm, don't touch !
00086   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00087                           // filled in here by Gxsm on Plugin load, 
00088                           // just after init() is called !!!
00089   "Rhk200_Import",
00090   NULL,                // PlugIn's Categorie, set to NULL for all, I just don't want this always to be loaded!
00091   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00092   "Import of RHK STM-200 data format.",
00093   "Peter Wahl",
00094   N_("File/Import"),
00095   N_("..."),
00096   NULL,
00097   "no more info for abc",
00098   NULL,          // error msg, plugin may put error status msg here later
00099   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00100   rhk200_im_export_init,  
00101   rhk200_im_export_query,  
00102   // about-function, can be "NULL"
00103   // can be called by "Plugin Details"
00104   rhk200_im_export_about,
00105   // configure-function, can be "NULL"
00106   // can be called by "Plugin Details"
00107   NULL, //rhk200_im_export_configure,
00108   // run-function, can be "NULL", if non-Zero and no query defined, 
00109   // it is called on menupath->"plugin"
00110   NULL,
00111   // cleanup-function, can be "NULL"
00112   // called if present at plugin removeal
00113   rhk200_im_export_cleanup
00114 };
00115 
00116 // Text used in Aboutbox, please update!!
00117 static const char *about_text = N_("Gxsm RHK STM-200 Data File Import Plugin\n\n"
00118                                    "This plugin reads in STM-200 datafiles."
00119         );
00120 
00121 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00122 // Essential Plugin Function!!
00123 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00124   rhk200_im_export_pi.description = g_strdup_printf(N_("Gxsm rhk200_im_export plugin %s"), VERSION);
00125   return &rhk200_im_export_pi; 
00126 }
00127 
00128 // Query Function, installs Plugin's in File/Import and Export Menupaths!
00129 // ----------------------------------------------------------------------
00130 // Import Menupath is "File/Import/abc import"
00131 // ----------------------------------------------------------------------
00132 // !!!! make sure the "rhk200_im_export_cleanup()" function (see below) !!!!
00133 // !!!! removes the correct menuentries !!!!
00134 
00135 static void rhk200_im_export_query(void)
00136 {
00137   static GnomeUIInfo menuinfo_Import[] = { 
00138     { GNOME_APP_UI_ITEM, 
00139       N_("RHK STM-200 Import"), N_("Import of the RHK STM-200 format"), 
00140       (gpointer) rhk200_im_export_import_callback, NULL,
00141       NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_OPEN,
00142       0, GDK_CONTROL_MASK, NULL },
00143     GNOMEUIINFO_END
00144   };
00145 
00146   gnome_app_insert_menus (
00147           GNOME_APP(rhk200_im_export_pi.app->getApp()), 
00148           N_("File/Import/"), 
00149           menuinfo_Import
00150           );
00151 
00152 
00153   if(rhk200_im_export_pi.status) g_free(rhk200_im_export_pi.status); 
00154   rhk200_im_export_pi.status = g_strconcat (
00155           N_("Plugin query has attached "),
00156           rhk200_im_export_pi.name, 
00157           N_(": File Input Filter is ready to use"),
00158           NULL);
00159 
00160 // register this plugins filecheck functions with Gxsm now!
00161 // This allows Gxsm to check files from DnD, open, 
00162 // and cmdline sources against all known formats automatically - no explicit im/export is necessary.
00163         rhk200_im_export_pi.app->ConnectPluginToLoadFileEvent (rhk200_im_export_filecheck_load_callback);
00164 }
00165 
00166 
00167 // 5.) Start here with the plugins code, vars def., etc.... here.
00168 // ----------------------------------------------------------------------
00169 //
00170 
00171 
00172 // init-Function
00173 static void rhk200_im_export_init(void)
00174 {
00175   PI_DEBUG (DBG_L2, "rhk200_import Plugin Init" );
00176 }
00177 
00178 // about-Function
00179 static void rhk200_im_export_about(void)
00180 {
00181   const gchar *authors[] = { rhk200_im_export_pi.authors, NULL};
00182   gtk_widget_show(gnome_about_new ( rhk200_im_export_pi.name,
00183                                     VERSION,
00184                                     N_("(C) 2001 the Free Software Foundation"),
00185                                     about_text,
00186                                     authors,
00187                                     NULL, NULL, NULL
00188                                     ));
00189 }
00190 
00191 // configure-Function
00192 static void rhk200_im_export_configure(void)
00193 {
00194   if(rhk200_im_export_pi.app)
00195     rhk200_im_export_pi.app->message("rhk200_im_export Plugin Configuration");
00196 }
00197 
00198 // cleanup-Function, make sure the Menustrings are matching those above!!!
00199 static void rhk200_im_export_cleanup(void)
00200 {
00201   PI_DEBUG (DBG_L2, "rhk200_im_export Plugin Cleanup" );
00202   gnome_app_remove_menus (GNOME_APP (rhk200_im_export_pi.app->getApp()),
00203                           N_("File/Import/RHK STM-200 Import"), 1);
00204 }
00205 
00206 // make a new derivate of the base class "Dataio"
00207 class rhk200_ImExportFile : public Dataio{
00208  public:
00209   rhk200_ImExportFile(Scan *s, const char *n) : Dataio(s,n){ };
00210   virtual FIO_STATUS Read();
00211   virtual FIO_STATUS Write();
00212  private:
00213   bool topo;
00214   double gain;
00215   int pix,lin;
00216   int bit,img,type,page,adt,dat;
00217   double adf,daf,max_ad,min_ad,max_da,min_da;
00218   double a_v[4];
00219   string a_name[4],a_unit[4];
00220   double d_v[2];
00221   string d_name[2],d_unit[2];
00222   string user,date,dx[2];
00223   double scan_range[3],offset[3],scan_sensitivity[3][3],compensation[3];
00224   int sch,sgn;
00225   double sweep_time,angle,temp;
00226   int feedback_channel,image_channel,points[2];
00227   int nad,nda,sweeps,rcl,das,ssm,scg;
00228   double bias_range[2];
00229   double dwell,hold,sadf,sdaf,ex[2];
00230   double c_v[4];
00231   string microscope_name;
00232   double offset_sensitivity[3][3];
00233   string software;
00234   double version;
00235   int jbl;
00236   char sum;
00237   string fbs;
00238   double signal_gain[4],ro[4],junction_bias,loop_setpoint,los,scv,osv;
00239   double time_constant,int_loop_gain,prop_gain,diff_gain,as[2],ppg;
00240   int gettag(istream &is,string tag,string &val);
00241   int gettag(istream &is,string tag,int &val);
00242   int gethextag(istream &is,string tag,int &val);
00243   int gettag(istream &is,string tag,char &val);
00244   int gettag(istream &is,string tag,double &val);
00245   int gettag(istream &is,string tag);
00246   void checktopo();
00247   int readhead(istream &is);
00248   void readtopo(istream &is);
00249   void readspec(istream &is);
00250   FIO_STATUS rhkRead(const char *fname);
00251 };
00252 
00253 int rhk200_ImExportFile::gettag(istream &is,string tag)
00254 {
00255   string buf;
00256   is>>buf; 
00257   if(buf==tag)
00258     return 0;
00259   else {
00260     cerr<<buf<<" "<<tag<<endl;
00261     PI_DEBUG (DBG_L2,"Unexpected tag.");
00262     return -1;
00263   }
00264 }
00265 
00266 int rhk200_ImExportFile::gettag(istream &is,string tag,int &val)
00267 {
00268   string buf;
00269   is>>buf;
00270   if(buf==tag) {
00271     is>>val;
00272     return 0;
00273   } else {
00274     cerr<<buf<<" "<<tag<<endl;
00275     PI_DEBUG (DBG_L2,"Unexpected tag.");
00276     return -1;
00277   }
00278 }
00279 
00280 int rhk200_ImExportFile::gethextag(istream &is,string tag,int &val)
00281 {
00282   string buf;
00283   is>>buf;
00284   if(buf==tag) {
00285     is>>hex>>val>>dec;
00286     return 0;
00287   } else {
00288     cerr<<buf<<" "<<tag<<endl;
00289     PI_DEBUG (DBG_L2,"Unexpected tag.");
00290     return -1;
00291   }
00292 }
00293 
00294 int rhk200_ImExportFile::gettag(istream &is,string tag,char &val)
00295 {
00296   string buf;
00297   is>>buf;
00298   if(buf==tag) {
00299     is>>val;
00300     return 0;
00301   } else {
00302     cerr<<buf<<" "<<tag<<endl;
00303     PI_DEBUG (DBG_L2,"Unexpected tag.");
00304     return -1;
00305   }
00306 }
00307 
00308 int rhk200_ImExportFile::gettag(istream &is,string tag,double &val)
00309 {
00310   string buf;
00311   is>>buf;
00312   if(buf==tag) {
00313     is>>val;
00314     return 0;
00315   } else {
00316     cerr<<buf<<" "<<tag<<endl;
00317     PI_DEBUG (DBG_L2,"Unexpected tag.");
00318     return -1;
00319   }
00320 }
00321 
00322 int rhk200_ImExportFile::gettag(istream &is,string tag,string &val)
00323 {
00324   string buf;
00325   is>>buf;
00326   if(buf==tag) {
00327     char line[101];
00328     is.ignore(1);
00329     is.getline(line,100);
00330     val=string(line);
00331     return 0;
00332   } else {
00333     cerr<<buf<<" "<<tag<<endl;
00334     PI_DEBUG (DBG_L2,"Unexpected tag.");
00335     return -1;
00336   }
00337 }
00338 
00339 // d2d import :=)
00340 FIO_STATUS rhk200_ImExportFile::Read(){
00341         FIO_STATUS ret;
00342         gchar *fname=NULL;
00343 
00344         fname = (gchar*)name;
00345 
00346         // name should have at least 4 chars: ".ext"
00347         if (fname == NULL || strlen(fname) < 4)
00348                 return  FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00349  
00350         // check for file exists and is OK !
00351         // else open File Dlg
00352         ifstream f;
00353         f.open(fname, ios::in);
00354         if(!f.good()){
00355                 PI_DEBUG (DBG_L2, "File Fehler" );
00356                 return status=FIO_OPEN_ERR;
00357         }
00358         f.close();
00359 
00360         // Check all known File Types:
00361         
00362         // abc ".abc" type?
00363         if ((ret=rhkRead (fname)) !=  FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00364                 return ret;
00365 
00366         return  FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00367 }
00368 
00369 int rhk200_ImExportFile::readhead(istream &is)
00370 {
00371         int error;
00372         string dumstr;
00373         error+=gettag(is,"SwV",dumstr);
00374         error+=gettag(is,"Pix",pix); error+=gettag(is,"Lin",lin); error+=gettag(is,"Bit",bit); 
00375         if(bit!=16) return -1;
00376         error+=gettag(is,"Img",img); error+=gettag(is,"PTy",type); error+=gettag(is,"Pag",page);
00377         error+=gettag(is,"ADT",adt); error+=gettag(is,"DAT",dat); error+=gettag(is,"ADF",adf); 
00378         error+=gettag(is,"DAF",daf); error+=gettag(is,"MAD",max_ad); error+=gettag(is,"mAD",min_ad);
00379         error+=gettag(is,"MDA",max_da); error+=gettag(is,"mDA",min_da);
00380         for(int i=0;i<4;i++) {
00381           ostringstream tagname;
00382           tagname<<"A"<<i<<"V";
00383           error+=gettag(is,tagname.str(),a_v[i]);
00384           tagname.str("");
00385           tagname<<"A"<<i<<"N";
00386           error+=gettag(is,tagname.str(),a_name[i]);
00387           tagname.str("");
00388           tagname<<"A"<<i<<"U";
00389           error+=gettag(is,tagname.str(),a_unit[i]);
00390         }
00391         for(int i=0;i<2;i++) {
00392           ostringstream tagname;
00393           tagname<<"D"<<i<<"V";
00394           error+=gettag(is,tagname.str(),d_v[i]);
00395           tagname.str("");
00396           tagname<<"D"<<i<<"N";
00397           error+=gettag(is,tagname.str(),d_name[i]);
00398           tagname.str("");
00399           tagname<<"D"<<i<<"U";
00400           error+=gettag(is,tagname.str(),d_unit[i]);
00401         }
00402         error+=gettag(is,"Usr",user); error+=gettag(is,"STm",date);
00403         error+=gettag(is,"Dx0",dx[0]); error+=gettag(is,"Dx1",dx[1]); 
00404         for(int i=0;i<3;i++) {
00405           ostringstream tagname;
00406           tagname<<"SR"<<i;
00407           error+=gettag(is,tagname.str(),scan_range[i]);
00408         }
00409         for(int i=0;i<3;i++) {
00410           ostringstream tagname;
00411           tagname<<"OS"<<i;
00412           error+=gettag(is,tagname.str(),offset[i]);
00413         }
00414         for(int i=0;i<3;i++) {
00415           ostringstream tagname;
00416           tagname<<"CM"<<i;
00417           error+=gettag(is,tagname.str(),compensation[i]);
00418         }
00419         error+=gettag(is,"SCh",sch); error+=gethextag(is,"SGn",sgn);
00420         error+=gettag(is,"LTm",sweep_time); error+=gettag(is,"SAn",angle);
00421         error+=gettag(is,"Tmp",temp); error+=gettag(is,"FbC",feedback_channel);
00422         error+=gettag(is,"ImC",image_channel); 
00423         error+=gettag(is,"XPt",points[0]); error+=gettag(is,"YPt",points[1]);
00424         error+=gettag(is,"NAD",nad); error+=gettag(is,"NDA",nda);
00425         error+=gettag(is,"NSw",sweeps); error+=gettag(is,"Rcl",rcl); 
00426         error+=gettag(is,"DAs",das); error+=gettag(is,"SSm",ssm);
00427         error+=gettag(is,"ScG",scg); 
00428         error+=gettag(is,"LoB",bias_range[0]); error+=gettag(is,"HiB",bias_range[1]);
00429         error+=gettag(is,"Dwl",dwell); error+=gettag(is,"Hld",hold);
00430         error+=gettag(is,"ADf",sadf); error+=gettag(is,"DAf",sdaf);
00431         error+=gettag(is,"ExH",ex[0]); error+=gettag(is,"ExL",ex[1]);
00432         for(int i=0;i<4;i++) {
00433           ostringstream tagname;
00434           tagname<<"C"<<i<<"V";
00435           error+=gettag(is,tagname.str(),c_v[i]);
00436         }
00437         error+=gettag(is,"MNm",microscope_name);
00438         for(int i=0;i<3;i++)
00439           for(int j=0;j<3;j++) {
00440             ostringstream tagname;
00441             tagname<<"S"<<i<<j;
00442             error+=gettag(is,tagname.str(),scan_sensitivity[i][j]);
00443           }
00444         for(int i=0;i<3;i++)
00445           for(int j=0;j<3;j++) {
00446             ostringstream tagname;
00447             tagname<<"O"<<i<<j;
00448             error+=gettag(is,tagname.str(),offset_sensitivity[i][j]);
00449           }
00450         error+=gettag(is,"ENm",software); error+=gettag(is,"EVr",version);
00451         error+=gettag(is,"JBL",jbl); error+=gettag(is,"Sum",sum);
00452         error+=gettag(is,"FBS",fbs);
00453         for(int i=0;i<4;i++) {
00454           ostringstream tagname;
00455           tagname<<"SG"<<i;
00456           error+=gettag(is,tagname.str(),signal_gain[i]);
00457         }
00458         for(int i=0;i<4;i++) {
00459           ostringstream tagname;
00460           tagname<<"RO"<<i;
00461           error+=gettag(is,tagname.str(),ro[i]);
00462         }
00463         error+=gettag(is,"JBs",junction_bias); error+=gettag(is,"SPt",loop_setpoint);
00464         error+=gettag(is,"LOs",los); error+=gettag(is,"SCV",scv);
00465         error+=gettag(is,"OSV",osv); error+=gettag(is,"TCn",time_constant);
00466         error+=gettag(is,"LpG",int_loop_gain); error+=gettag(is,"PrG",prop_gain);
00467         error+=gettag(is,"DrG",diff_gain); 
00468         error+=gettag(is,"AS0",as[0]); error+=gettag(is,"AS1",as[1]);
00469         error+=gettag(is,"PPG",ppg);
00470         if(!error) return error;
00471         gain=1.0/(signal_gain[image_channel]*a_v[image_channel]*(1<<((sgn>>(4*image_channel))&0x000f)));
00472         if(a_name[image_channel]=="Z Signal") gain*=scan_sensitivity[2][0]*scv/max_ad;
00473         loop_setpoint=loop_setpoint/a_v[feedback_channel]*ppg;
00474         //from here on, the RHK header contains 3D-related stuff which we are not interested in
00475         checktopo();
00476         return 0;
00477 }
00478 
00479 void rhk200_ImExportFile::checktopo()
00480 {
00481   if((points[0]==0)&&(points[1]==0)) topo=true;
00482   else {
00483     if(a_name[image_channel]=="Lockin") topo=false;
00484     else {
00485       topo=true;
00486       cerr<<"Warning: Detected topography in file with spectroscopy grid."<<endl;
00487     }
00488   }
00489 }
00490 
00491 void rhk200_ImExportFile::readtopo(istream &is)
00492 {
00493   int nx,ny;
00494   short dumint;
00495   char *dumptr=(char *)&dumint;
00496   nx=pix; ny=lin; 
00497   scan->data.s.ntimes  = 1;
00498   scan->data.s.nvalues = 1; 
00499   scan->mem2d->Resize (scan->data.s.nx = nx,scan->data.s.ny = ny,ZD_SHORT);
00500   
00501   is.seekg(2048);
00502   for(int j=0; j<scan->data.s.ny; j++)
00503     for(int i=0; i<scan->data.s.nx; i++) {
00504       is.read((char *)&dumint,sizeof(short));
00505       swap(dumptr[0],dumptr[1]);
00506       scan->mem2d->PutDataPkt (dumint,i ,j );
00507     }
00508 }
00509 
00510 void rhk200_ImExportFile::readspec(istream &is)
00511 {
00512   cerr<<"To be implemented !"<<endl;
00513   int nx=points[0],ny=points[1],speclinesize=sweeps*lin;
00514   short dumint;
00515   float *buf=new float(scan->data.s.nvalues = pix);
00516   char *dumptr=(char *)&dumint;
00517   scan->data.s.ntimes  = 1;
00518   scan->mem2d->Resize (scan->data.s.nx = nx, scan->data.s.ny = ny, scan->data.s.nvalues, ZD_FLOAT);
00519   is.seekg(2048);
00520   for(int j=0; j<scan->data.s.ny; j++)
00521     for(int i=0; i<scan->data.s.nx; i++) {
00522       for(int n=0; n<scan->data.s.nvalues; n++) buf[n]=0.0;
00523       for(int m=0; m<speclinesize; m++ )
00524         if(!(m%2)) for(int n=0; n<scan->data.s.nvalues; n++) {
00525           is.read((char *)&dumint,sizeof(short));
00526           swap(dumptr[0],dumptr[1]); 
00527           buf[n]+=(float)dumint;
00528         } 
00529         else for(int n=scan->data.s.nvalues; n>0; n--) {
00530           is.read((char *)&dumint,sizeof(short));
00531           swap(dumptr[0],dumptr[1]); 
00532           buf[n-1]+=(float)dumint;
00533         }
00534       for(int n=0; n<scan->data.s.nvalues; n++)
00535         scan->mem2d->PutDataPkt (buf[n]/speclinesize,i ,j, n );
00536     }
00537   delete buf;
00538 }
00539 
00540 //to be done:
00541 // * support for spectroscopy, dI/dV-maps
00542 FIO_STATUS rhk200_ImExportFile::rhkRead(const char *fname){
00543         int error=0;
00544 
00545         // Am I resposible for that file, is it in RHK STM2000 format ?
00546         if (strncmp(fname+strlen(fname)-4,".Stm",4)&&strncmp(fname+strlen(fname)-4,".sts",4))
00547                 return FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00548         
00549         // feel free to do a more sophisticated file type check...
00550         ifstream is(fname,ios::in);
00551         if(gettag(is,"Ss*")) {
00552           PI_DEBUG (DBG_L2, "Magic file number not detected - probably not an STM2000 file.");
00553           is.close();
00554           return FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00555         } else PI_DEBUG (DBG_L2, "It's an RHK File!" );
00556         if(readhead(is)) {
00557           PI_DEBUG (DBG_L2, "Error - returning !");
00558           is.close();
00559           return FIO_INVALID_FILE;
00560         }
00561         
00562         cerr<<"Read head ... "<<endl;
00563         if(topo) readtopo(is);
00564         else readspec(is);
00565         
00566         cerr<<"Read topo ... "<<endl;
00567         
00568         // put some usefull values in the ui structure
00569         scan->data.ui.SetUser (user.c_str());
00570         scan->data.ui.SetName (fname);
00571         scan->data.ui.SetOriginalName (fname);
00572         scan->data.ui.SetType ("RHK STM-2000"); 
00573         scan->data.ui.SetComment((dx[0]+"\n"+dx[1]).c_str());
00574 
00575         // initialize scan structure -- this is a minimum example
00576         scan->data.s.rx = scan_sensitivity[0][0]*scan_range[0];
00577         scan->data.s.ry = scan_sensitivity[1][0]*scan_range[1];
00578         scan->data.s.dx = scan->data.s.rx/scan->data.s.nx;
00579         scan->data.s.dy = scan->data.s.ry/scan->data.s.ny;
00580         scan->data.s.x0 = offset_sensitivity[0][0]*offset[0];
00581         scan->data.s.y0 = offset_sensitivity[1][0]*offset[1];
00582         scan->data.s.alpha = angle;
00583         double dz=gain/32768.0;
00584         UnitObj *zu = gapp->xsm->MakeUnit ("nm","nm");
00585         scan->data.s.dz = zu->Usr2Base(dz);
00586         scan->data.SetZUnit(zu);
00587         delete zu;
00588         scan->data.s.Bias=junction_bias;
00589         scan->data.s.Current = loop_setpoint;
00590         scan->data.ui.SetDateOfScan(date.c_str());
00591         scan->mem2d->data->MkYLookup(scan->data.s.y0, scan->data.s.y0+scan->data.s.ry);
00592         scan->mem2d->data->MkXLookup(scan->data.s.x0-scan->data.s.rx/2., scan->data.s.x0+scan->data.s.rx/2.);
00593 
00594         // be nice and reset this to some defined state
00595         scan->data.display.cpshigh       = 1e3;
00596         scan->data.display.cpslow        = 1.;
00597         scan->data.display.cnttime       = 1.;
00598 
00599         // set the default view parameters
00600         scan->data.display.bright = 32.;
00601         scan->data.display.contrast = 1.0;
00602 
00603         // FYI: (PZ)
00604         //  scan->data.display.vrange_z  = ; // View Range Z in base ZUnits
00605         //  scan->data.display.voffset_z = 0; // View Offset Z in base ZUnits
00606         //  scan->AutoDisplay([...]); // may be used too...
00607   
00608 
00609         // abc read done.
00610         is.close();
00611         cerr<<"Done initialization"<<endl;
00612         return FIO_OK; 
00613 }
00614 
00615 
00616 FIO_STATUS rhk200_ImExportFile::Write(){
00617   return FIO_OK; 
00618 }
00619 
00620 // Plugin's Notify Cb's, registered to be called on file load/save to check file
00621 // return via filepointer, it is set to Zero or passed as Zero if file has been processed!
00622 // That's all fine, you should just change the Text Stings below...
00623 
00624 static void rhk200_im_export_filecheck_load_callback (gpointer data ){
00625         gchar **fn = (gchar**)data;
00626         if (*fn){
00627                 PI_DEBUG (DBG_L2, "checking >" << *fn << "<" );
00628 
00629                 Scan *dst = gapp->xsm->GetActiveScan();
00630                 if(!dst){ 
00631                         gapp->xsm->ActivateFreeChannel();
00632                         dst = gapp->xsm->GetActiveScan();
00633                 }
00634 
00635                 rhk200_ImExportFile fileobj (dst, *fn);
00636 
00637                 FIO_STATUS ret = fileobj.Read(); 
00638                 if (ret != FIO_OK){ 
00639                         // I'am responsible! (But failed)
00640                         if (ret != FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00641                                 *fn=NULL;
00642                         // no more data: remove allocated and unused scan now, force!
00643                         gapp->xsm->SetMode(-1, ID_CH_M_OFF, TRUE); 
00644                         PI_DEBUG (DBG_L2, "Read Error " << ((int)ret) );
00645                 }else{
00646                         // got it!
00647                         *fn=NULL;
00648 
00649                         // Now update gxsm main window data fields
00650                         gapp->xsm->ActiveScan->GetDataSet(gapp->xsm->data);
00651                         gapp->spm_update_all();
00652                         dst->draw();
00653                 }
00654         }else{
00655                 PI_DEBUG (DBG_L2, "Skipping" << *fn << "<" );
00656         }
00657 }
00658 
00659 
00660 // Menu Call Back Fkte
00661 
00662 static void rhk200_im_export_import_callback(GtkWidget *w, void *data){
00663 //                                "known extensions: pgm h16 nsc d2d dat sht byt flt dbl",
00664         gchar *fn = gapp->file_dialog("RHK STM-200 Import", NULL,
00665                                   "*.Stm", 
00666                                   NULL, "RHK STM-200 Import");
00667 
00668     PI_DEBUG (DBG_L2, "FLDLG-IM::" << fn );
00669     rhk200_im_export_filecheck_load_callback (&fn );
00670 }

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