PsiHDF_im_export.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: PsiHDF_im_export.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  * --------------------------------------------------------------------------------
00032 % BeginPlugInDocuSection
00033 % PlugInDocuCaption: Park Scientific (HDF) data Import
00034 % PlugInName: PsiHDF_im_export
00035 % PlugInAuthor: Percy Zahl
00036 % PlugInAuthorEmail: zahl@users.sf.net
00037 % PlugInMenuPath: File/Import/PsiHDF
00038 
00039 % PlugInDescription
00040 \label{plugins:PsiHDF_im_export}
00041 The \GxsmEmph{PsiHDF\_im\_export} plug-in supports reading of
00042 Psi-HDFe files used by Park-Scientific AFM.
00043 
00044 % PlugInUsage
00045 The plug-in is called by \GxsmMenu{File/Import/PsiHDF}.
00046 
00047 % OptPlugInKnownBugs
00048 Not yet tested, porting to GXSM-2 in progress..
00049 
00050 % EndPlugInDocuSection
00051  * -------------------------------------------------------------------------------- 
00052  */
00053 
00054 #include <gtk/gtk.h>
00055 #include "config.h"
00056 #include "gxsm/plugin.h"
00057 #include "gxsm/dataio.h"
00058 #include "gxsm/action_id.h"
00059 #include "gxsm/util.h"
00060 #include "batch.h"
00061 #include "fileio.c"
00062 #include "psihdf.h"
00063 
00064 using namespace std;
00065 
00066 #define IMGMAXCOLORS 64
00067 
00068 // Plugin Prototypes
00069 static void PsiHDF_im_export_init (void);
00070 static void PsiHDF_im_export_query (void);
00071 static void PsiHDF_im_export_about (void);
00072 static void PsiHDF_im_export_configure (void);
00073 static void PsiHDF_im_export_cleanup (void);
00074 
00075 static void PsiHDF_im_export_filecheck_load_callback (gpointer data );
00076 static void PsiHDF_im_export_filecheck_save_callback (gpointer data );
00077 
00078 static void PsiHDF_im_export_import_callback (GtkWidget *w, void *data);
00079 static void PsiHDF_im_export_export_callback (GtkWidget *w, void *data);
00080 
00081 // Fill in the GxsmPlugin Description here
00082 GxsmPlugin PsiHDF_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   "PsiHDF-ImExport",
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   "Im/Export of PsiHDF file format.",
00093   "Percy Zahl",
00094   N_("_File/_Import/,_File/_Export/"),
00095   N_("PsiHDF,PsiHDF"),
00096   N_("PsiHDF import,PsiHDF export"),
00097   N_("Park Scientific HDF import and export filter."),
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   PsiHDF_im_export_init,
00101   PsiHDF_im_export_query,
00102   // about-function, can be "NULL"
00103   // can be called by "Plugin Details"
00104   PsiHDF_im_export_about,
00105   // configure-function, can be "NULL"
00106   // can be called by "Plugin Details"
00107   PsiHDF_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   PsiHDF_im_export_cleanup
00114 };
00115 
00116 // Text used in Aboutbox, please update!!
00117 static const char *about_text = N_("This GXSM plugin allows im- and export of the Park Scientifi HDF file format"
00118                                    " "
00119         );
00120 
00121 static const char *file_mask = "*.hdf";
00122 
00123 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00124 // Essential Plugin Function!!
00125 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00126   PsiHDF_im_export_pi.description = g_strdup_printf(N_("Gxsm im_export plugin %s"), VERSION);
00127   return &PsiHDF_im_export_pi; 
00128 }
00129 
00130 // Query Function, installs Plugin's in File/Import and Export Menupaths!
00131 // ----------------------------------------------------------------------
00132 // Import Menupath is "File/Import/GME Dat"
00133 // Export Menupath is "File/Export/GME Dat"
00134 // ----------------------------------------------------------------------
00135 // !!!! make sure the "PsiHDF_im_export_cleanup()" function (see below) !!!!
00136 // !!!! removes the correct menuentries !!!!
00137 
00138 static void PsiHDF_im_export_query(void)
00139 {
00140         gchar **path  = g_strsplit ( PsiHDF_im_export_pi.menupath, ",", 2);
00141         gchar **entry = g_strsplit ( PsiHDF_im_export_pi.menuentry, ",", 2);
00142         gchar **help  = g_strsplit ( PsiHDF_im_export_pi.help, ",", 2);
00143 
00144         static GnomeUIInfo menuinfo_i[] = { 
00145                 { GNOME_APP_UI_ITEM, NULL, NULL,
00146                   NULL, NULL,
00147                   NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_OPEN,
00148                   0, GDK_CONTROL_MASK, NULL },
00149                 GNOMEUIINFO_END
00150         };
00151         menuinfo_i[0].label  = entry[0];
00152         menuinfo_i[0].hint   = help[0];
00153         menuinfo_i[0].moreinfo  = (gpointer) PsiHDF_im_export_import_callback; 
00154         menuinfo_i[0].user_data = PsiHDF_im_export_pi.name;
00155 
00156         gnome_app_insert_menus (
00157                 GNOME_APP(PsiHDF_im_export_pi.app->getApp()), 
00158                 path[0], 
00159                 menuinfo_i
00160                 );
00161         
00162 
00163         static GnomeUIInfo menuinfo_e[] = { 
00164                 { GNOME_APP_UI_ITEM, NULL, NULL,
00165                   NULL, NULL,
00166                   NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_SAVE,
00167                   0, GDK_CONTROL_MASK, NULL },
00168                 GNOMEUIINFO_END
00169         };
00170         menuinfo_e[0].label  = entry[1];
00171         menuinfo_e[0].hint   = help[1];
00172         menuinfo_e[0].moreinfo  = (gpointer) PsiHDF_im_export_export_callback; 
00173         menuinfo_e[0].user_data = PsiHDF_im_export_pi.name;
00174 
00175         gnome_app_insert_menus (
00176                 GNOME_APP(PsiHDF_im_export_pi.app->getApp()), 
00177                 path[1],
00178                 menuinfo_e
00179                 );
00180 
00181         if(PsiHDF_im_export_pi.status) g_free(PsiHDF_im_export_pi.status); 
00182         PsiHDF_im_export_pi.status = g_strconcat (
00183                 N_("Plugin query has attached "),
00184                 PsiHDF_im_export_pi.name, 
00185                 N_(": File IO Filters are ready to use."),
00186                 NULL);
00187         
00188         // clean up
00189         g_strfreev (path);
00190         g_strfreev (entry);
00191         g_strfreev (help);
00192 
00193         // register this plugins filecheck functions with Gxsm now!
00194         // This allows Gxsm to check files from DnD, open, 
00195         // and cmdline sources against all known formats automatically - no explicit im/export is necessary.
00196         PsiHDF_im_export_pi.app->ConnectPluginToLoadFileEvent (PsiHDF_im_export_filecheck_load_callback);
00197         PsiHDF_im_export_pi.app->ConnectPluginToSaveFileEvent (PsiHDF_im_export_filecheck_save_callback);
00198 }
00199 
00200 
00201 // 5.) Start here with the plugins code, vars def., etc.... here.
00202 // ----------------------------------------------------------------------
00203 //
00204 
00205 
00206 // init-Function
00207 static void PsiHDF_im_export_init(void)
00208 {
00209         PI_DEBUG (DBG_L2, PsiHDF_im_export_pi.name << "Plugin Init");
00210 }
00211 
00212 // about-Function
00213 static void PsiHDF_im_export_about(void)
00214 {
00215         const gchar *authors[] = { PsiHDF_im_export_pi.authors, NULL};
00216         gtk_widget_show(gnome_about_new ( PsiHDF_im_export_pi.name,
00217                                           VERSION,
00218                                           N_("(C) 2001 the Free Software Foundation"),
00219                                           about_text,
00220                                           authors,
00221                                           NULL, NULL, NULL
00222                                           ));
00223 }
00224 
00225 // configure-Function
00226 static void PsiHDF_im_export_configure(void)
00227 {
00228         if(PsiHDF_im_export_pi.app)
00229                 PsiHDF_im_export_pi.app->message("PsiHDF_im_export Plugin Configuration");
00230 }
00231 
00232 // cleanup-Function, make sure the Menustrings are matching those above!!!
00233 static void PsiHDF_im_export_cleanup(void)
00234 {
00235         gchar **path  = g_strsplit (PsiHDF_im_export_pi.menupath, ",", 2);
00236         gchar **entry = g_strsplit (PsiHDF_im_export_pi.menuentry, ",", 2);
00237 
00238         gchar *tmp = g_strconcat (path[0], entry[0], NULL);
00239         gnome_app_remove_menus (GNOME_APP (PsiHDF_im_export_pi.app->getApp()), tmp, 1);
00240         g_free (tmp);
00241 
00242         tmp = g_strconcat (path[1], entry[1], NULL);
00243         gnome_app_remove_menus (GNOME_APP (PsiHDF_im_export_pi.app->getApp()), tmp, 1);
00244         g_free (tmp);
00245 
00246         g_strfreev (path);
00247         g_strfreev (entry);
00248 
00249         PI_DEBUG (DBG_L2, "Plugin Cleanup done.");
00250 }
00251 
00252 // make a new derivate of the base class "Dataio"
00253 class PsiHDF_ImExportFile : public Dataio{
00254 public:
00255         PsiHDF_ImExportFile(Scan *s, const char *n) : Dataio(s,n){ };
00256         virtual FIO_STATUS Read();
00257         virtual FIO_STATUS Write();
00258 private:
00259         FIO_STATUS import(const char *fname);
00260         int numDD;  // number of data descriptors
00261 };
00262 
00263 FIO_STATUS PsiHDF_ImExportFile::Read(){
00264         FIO_STATUS ret;
00265         gchar *fname=NULL;
00266 
00267         fname = (gchar*)name;
00268 
00269         // name should have at least 4 chars: ".ext"
00270         if (fname == NULL || strlen(fname) < 4)
00271                 return  FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00272  
00273         // check for file exists and is OK !
00274         // else open File Dlg
00275         ifstream f;
00276         f.open(fname, ios::in);
00277         if(!f.good()){
00278                 PI_DEBUG (DBG_L2, "File Fehler");
00279                 return status=FIO_OPEN_ERR;
00280         }
00281         f.close();
00282 
00283         // Check all known File Types:
00284         
00285         // is this a PsiHDF file?
00286         if ((ret=import (fname)) !=  FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00287                 return ret;
00288 
00289         return  FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00290 }
00291 
00292 //=======================================================================
00293 //
00294 // PsiHDF  -   HDF-Format von Park Scientific Instr.
00295 //
00296 // up to now only reading of HDF implemented
00297 //
00298 //=======================================================================
00299 FIO_STATUS PsiHDF_ImExportFile::import(const char *fname){
00300         ifstream f;
00301         gchar *tmp = NULL;
00302         GString *FileList=NULL;
00303 
00304         f.open(name, ios::in);
00305         if (!f.good())
00306                 return status=FIO_OPEN_ERR;
00307 
00308         // check some magics of this type...
00309         if (TRUE){
00310                 f.close ();
00311                 return FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00312         }
00313         
00314         time_t t; // Scan - Startzeit eintragen 
00315         time(&t);
00316         tmp = g_strconcat ((ctime(&t)), " (Imported)", NULL); scan->data.ui.SetDateOfScan (tmp); g_free (tmp);
00317         scan->data.ui.SetName (fname);
00318         scan->data.ui.SetOriginalName (fname);
00319         scan->data.ui.SetType ("old dat"); 
00320 
00321 
00322         // this is mandatory.
00323         scan->data.s.ntimes  = 1;
00324         scan->data.s.nvalues = 1;
00325   
00326   
00327         // put some usefull values in the ui structure
00328         if(getlogin()){
00329                 scan->data.ui.SetUser (getlogin());
00330         }
00331         else{
00332                 scan->data.ui.SetUser ("unkonwn user");
00333         }
00334 
00335         // initialize scan structure -- this is a minimum example
00336         scan->data.s.nx = 1;
00337         scan->data.s.ny = 1;
00338         scan->data.s.dx = 1;
00339         scan->data.s.dy = 1;
00340         scan->data.s.dz = 1;
00341         scan->data.s.rx = scan->data.s.nx;
00342         scan->data.s.ry = scan->data.s.ny;
00343         scan->data.s.x0 = 0;
00344         scan->data.s.y0 = 0;
00345         scan->data.s.alpha = 0;
00346 
00347         // be nice and reset this to some defined state
00348         scan->data.display.cpshigh       = 1e3;
00349         scan->data.display.cpslow        = 1.;
00350         scan->data.display.cnttime       = 1.;
00351 
00352         // set the default view parameters
00353         scan->data.display.bright = 32.;
00354         scan->data.display.contrast = 1.0;
00355 
00356         // FYI: (PZ)
00357         //  scan->data.display.vrange_z  = ; // View Range Z in base ZUnits
00358         //  scan->data.display.voffset_z = 0; // View Offset Z in base ZUnits
00359         //  scan->AutoDisplay([...]); // may be used too...
00360   
00361 
00362         FileList = g_string_new ("Imported by GXSM from old dat filetype.\n");
00363         g_string_sprintfa (FileList, "Original Filename: %s\n", fname);
00364 //      g_string_append (FileList, "blaa\n");
00365         
00366         int magic;
00367         PsiHEADER header;
00368 
00369         f.open(name, std::ios::in);
00370         if(!f.good())
00371                 return status=FIO_OPEN_ERR;
00372 
00373         // get magic number
00374         f.seekg(0, std::ios::beg);
00375         f.read((char*)(&magic), 4);
00376   
00377         if (magic != HDF_MAGIC_NUM)  {
00378                 XSM_DEBUG_ERROR (DBG_L1, "PsiHDF: wrong magic number! (magic = " << magic << " )");
00379                 return FIO_READ_ERR;
00380         }
00381   
00382         // read PSI binary Header
00383         f.seekg(PSI_HEADER_OFFSET, std::ios::beg);
00384         f.read((char*)&header, sizeof(PsiHEADER));
00385         // dirty hack to correct differences in the behavior of 16 and 32bit architectures:
00386         // under Linux, 32bit variables like int or float are moved to the beginning
00387         // of a 32bit segment.  unfortunately there are an odd number of shorts before the
00388         // float header.fXScansize :-(  This is corrected by the following hack:  the header
00389         // is read two times 
00390 # define XOFFS(X) ((char*)(&X) - (char*)(&header))
00391         f.seekg(PSI_HEADER_OFFSET + XOFFS(header.fXScanSize) + 2, std::ios::beg);
00392         f.read((char*)&header.fXScanSize, sizeof(PsiHEADER) - XOFFS(header.fXScanSize));
00393 
00394         if(f.fail()){
00395                 f.close();
00396                 return status=FIO_READ_ERR; 
00397         }
00398 
00399         /* grrrrrrrrrr
00400            XSM_DEBUG_ERROR (DBG_L1,  "PsiHDF: source: " << header.szSourceName );
00401            XSM_DEBUG_ERROR (DBG_L1,  "PsiHDF: mode: " << header.szImageMode );
00402            XSM_DEBUG_ERROR (DBG_L1,  "PsiHDF: image size: " << header.nCols << " x " << header.nRows );
00403            XSM_DEBUG_ERROR (DBG_L1,  "PsiHDF: scan size in um: " << header.fXScanSize << " x " << header.fYScanSize );
00404            XSM_DEBUG_ERROR (DBG_L1,  "PsiHDF: setpoint unit: " << header.szSetPointUnit );
00405            XSM_DEBUG_ERROR (DBG_L1,  "PsiHDF: scan rate: " << header.fScanRate );
00406            XSM_DEBUG_ERROR (DBG_L1,  "PsiHDF: data min: " << header.nDataMin << " max: " << header.nDataMax );
00407 
00408            char dum[4];
00409            f.seekg(0x03e2, std::ios::beg);
00410            f.read(dum, 4);
00411            XSM_DEBUG_ERROR (DBG_L1,  "dum: " << (int)dum[0] << " " << (int)dum[1] << " " << (int)dum[2] << " " << (int)dum[3] );
00412            XSM_DEBUG_ERROR (DBG_L1,  "dum: " << *((float*)dum) );
00413            f.seekg(0x03e6, std::ios::beg);
00414            f.read(dum, 4);
00415            XSM_DEBUG_ERROR (DBG_L1,  "dum: " << (int)dum[0] << " " << (int)dum[1] << " " << (int)dum[2] << " " << (int)dum[3] );
00416            XSM_DEBUG_ERROR (DBG_L1,  "dum: " << *((float*)dum) );
00417            XSM_DEBUG_ERROR (DBG_L1,  "dum size " << (int)((char*)&header.fXScanSize)[0] << " " << (int)((char*)&header.fXScanSize)[1] << " " << (int)((char*)&header.fXScanSize)[2] << " " << (int)((char*)&header.fXScanSize)[3] );
00418            XSM_DEBUG_ERROR (DBG_L1,  "dum size " << (int)((char*)&header.fYScanSize)[0] << " " << (int)((char*)&header.fYScanSize)[1] << " " << (int)((char*)&header.fYScanSize)[2] << " " << (int)((char*)&header.fYScanSize)[3] );
00419            XSM_DEBUG_ERROR (DBG_L1,  "sizeof(HEADER): " << sizeof(header) );
00420            XSM_DEBUG_ERROR (DBG_L1,  "offs header.nCols " << XOFFS(header.nCols) );
00421            XSM_DEBUG_ERROR (DBG_L1,  "offs header.nRows " << XOFFS(header.nRows) );
00422            XSM_DEBUG_ERROR (DBG_L1,  "offs header.dummy " << XOFFS(header.dummy) );
00423            XSM_DEBUG_ERROR (DBG_L1,  "offs header.fLowPass " << XOFFS(header.fLowPass) );
00424            XSM_DEBUG_ERROR (DBG_L1,  "offs header.b3rdOrder " << XOFFS(header.b3rdOrder) );
00425            XSM_DEBUG_ERROR (DBG_L1,  "offs header.bAutoFlatten " << XOFFS(header.bAutoFlatten) );
00426            XSM_DEBUG_ERROR (DBG_L1,  "offs header.fXScanSize " << XOFFS(header.fXScanSize) << " " << XOFFS(header.fYScanSize) );
00427         */
00428 
00429         // convert PSI header information to scan data
00430         // values in PSI header are in um, xxsm data has to be in Angstrom!
00431         scan->data.s.nx = header.nCols;
00432         scan->data.s.ny = header.nRows;
00433         scan->data.s.dx = header.fXScanSize * 10000. / header.nCols;
00434         scan->data.s.dy = header.fYScanSize * 10000. / header.nRows;
00435         scan->data.s.dz = header.fDataGain * 10000.;
00436         scan->data.s.rx = scan->data.s.nx*scan->data.s.dx;
00437         scan->data.s.ry = scan->data.s.ny*scan->data.s.dy;
00438         scan->data.s.x0 = header.fXOffset * 10000.;
00439         scan->data.s.y0 = header.fYOffset * 10000.;
00440         scan->data.s.alpha = 0;
00441         scan->data.ui.SetUser ("PSI SXM");
00442         tmp = g_strconcat ("PSI Mode: ", header.szImageMode, ", Source: ", header.szSourceName, NULL);
00443         scan->data.ui.SetComment (tmp);
00444         g_free (tmp);
00445   
00446         // read the data
00447         scan->mem2d->Resize (scan->data.s.nx, scan->data.s.ny);
00448         f.seekg (FILE_HEADER_SIZE, std::ios::beg);
00449         scan->mem2d->DataRead (f);
00450 
00451         scan->data.orgmode = SCAN_ORG_CENTER;
00452         scan->mem2d->data->MkXLookup (-scan->data.s.rx/2., scan->data.s.rx/2.);
00453         scan->mem2d->data->MkYLookup (-scan->data.s.ry/2., scan->data.s.ry/2.);
00454 
00455         if(f.fail()){
00456                 f.close();
00457                 return status=FIO_READ_ERR; 
00458         }
00459 
00460 
00461 
00462 
00463 
00464 
00465         scan->data.ui.SetComment (FileList->str);
00466         g_string_free(FileList, TRUE); 
00467         FileList=NULL;
00468 
00469         scan->data.s.dx = scan->data.s.rx / scan->data.s.nx;
00470         scan->data.s.dy = scan->data.s.ry / scan->data.s.ny;
00471 
00472         // convert to Ang
00473 //      scan->data.s.x0 *= pzAV_x / 32767.*10. * gx ;
00474 //      scan->data.s.y0 *= pzAV_y / 32767.*10. * gy ;
00475 
00476         // Read Img Data.
00477         
00478         scan->mem2d->Resize(scan->data.s.nx, scan->data.s.ny);
00479         scan->mem2d->DataRead(f, 1);
00480 
00481         scan->data.orgmode = SCAN_ORG_CENTER;
00482         scan->mem2d->data->MkXLookup (-scan->data.s.rx/2., scan->data.s.rx/2.);
00483         scan->mem2d->data->MkYLookup (-scan->data.s.ry/2., scan->data.s.ry/2.);
00484 
00485   
00486         return FIO_OK; 
00487 }
00488 
00489 
00490 FIO_STATUS PsiHDF_ImExportFile::Write(){
00491 
00492         GtkWidget *dialog = gtk_message_dialog_new (NULL,
00493                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
00494                                                     GTK_MESSAGE_INFO,
00495                                                     GTK_BUTTONS_OK,
00496                                                     N_("Sorry, not yet implemented.")
00497                                                     );
00498         gtk_dialog_run (GTK_DIALOG (dialog));
00499         gtk_widget_destroy (dialog);
00500 
00501 #if 0
00502         gchar tmp[0x4004];
00503         const gchar *fname;
00504         ofstream f;
00505 
00506         memset (tmp, 0, sizeof (tmp));
00507 
00508         if(strlen(name)>0)
00509                 fname = (const char*)name;
00510         else
00511                 fname = gapp->file_dialog("File Export: PsiHDF"," ","*.hdf","","PsiHDF write");
00512         if (fname == NULL) return FIO_NO_NAME;
00513 
00514         // check if we like to handle this
00515         if (strncmp(fname+strlen(fname)-4,".hdf",4))
00516                 return FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00517 
00518 
00519         f.open(name, ios::out);
00520         if (!f.good())
00521                 return status=FIO_OPEN_ERR;
00522 
00523 //      scan->mem2d->DataWrite(f);
00524 
00525 
00526         int pcnt=0;
00527         std::ofstream f;
00528     
00529         f.open(name, std::ios::out | std::ios::trunc);
00530         if(!f.good())
00531                 return status=FIO_OPEN_ERR;
00532 
00533         f.seekp(0, std::ios::beg); // Auf Headerstart Positionieren
00534 
00535         // Kopf erstellen
00536         scan->data.ui.SetName (name);
00537         Kopf.ScMode    = TopoGraphic;
00538         Kopf.Kennung   = 0xABCE; /* NEU !!, alt=0xABCD */
00539         if(strlen(scan->data.ui.user) > 39)
00540                 XSM_SHOW_ALERT(HINT_WARN, HINT_UNAME_TRUNC, " ", 0);
00541         if(strlen(scan->data.ui.comment) > 255)
00542                 XSM_SHOW_ALERT(HINT_WARN, HINT_COMMENT_TRUNC, " ", 0);
00543         strncpy(Kopf.UserName, scan->data.ui.user, 39);
00544         strncpy(Kopf.comment, scan->data.ui.comment, 255);
00545         Kopf.nx[pcnt] = scan->data.s.nx;
00546         Kopf.ny[pcnt] = scan->data.s.ny;
00547         //* ....->Inst wird nur wegen dat-Type benötigt .... :=(
00548  Kopf.dx[pcnt] = R2INT(scan->data.s.dx/gapp->xsm->Inst->XResolution());
00549         Kopf.dy[pcnt] = R2INT(scan->data.s.dy/gapp->xsm->Inst->YResolution());
00550         Kopf.x_Offset[pcnt] = R2INT(scan->data.s.x0/gapp->xsm->Inst->XResolution());
00551         Kopf.y_Offset[pcnt] = R2INT(scan->data.s.y0/gapp->xsm->Inst->XResolution());
00552         Kopf.DAtoAng_X = gapp->xsm->Inst->XResolution();
00553         Kopf.DAtoAng_Y = gapp->xsm->Inst->YResolution();
00554         Kopf.DAtoAng_Z = gapp->xsm->Inst->ZResolution();
00555         Kopf.Rotation  = (short)(rint(scan->data.s.alpha));
00556         Kopf.brightfac = scan->data.display.bright;
00557         Kopf.greyfac   = VRangeZ_to_Contrast (scan->data.display.vrange_z, scan->data.s.dz);
00558 //  Kopf.linefac   = scan->data.display.gamma;
00559         Kopf.forw_delay=10L;
00560         Kopf.back_delay=10L;
00561         Kopf.NumOfTopAve=1;
00562         // Kopf noch nicht vollständig ausgefüllt !
00563 
00564         f.write((const char*)&Kopf, sizeof(HEADER));
00565         if(f.fail()){
00566                 f.close();
00567                 return status=FIO_WRITE_ERR; 
00568         }
00569 
00570         scan->mem2d->DataWrite(f);
00571 
00572         if(f.fail()){
00573                 f.close();
00574                 return status=FIO_WRITE_ERR; 
00575         }
00576         f.close();
00577 
00578 
00579 
00580 #endif
00581   return FIO_OK; 
00582 }
00583 
00584 // Plugin's Notify Cb's, registered to be called on file load/save to check file
00585 // return via filepointer, it is set to Zero or passed as Zero if file has been processed!
00586 // That's all fine, you should just change the Text Stings below...
00587 
00588 
00589 static void PsiHDF_im_export_filecheck_load_callback (gpointer data ){
00590         gchar **fn = (gchar**)data;
00591         if (*fn){
00592                 PI_DEBUG (DBG_L2, 
00593                           "Check File: PsiHDF_im_export_filecheck_load_callback called with >"
00594                           << *fn << "<" );
00595 
00596                 Scan *dst = gapp->xsm->GetActiveScan();
00597                 if(!dst){ 
00598                         gapp->xsm->ActivateFreeChannel();
00599                         dst = gapp->xsm->GetActiveScan();
00600                 }
00601                 PsiHDF_ImExportFile fileobj (dst, *fn);
00602 
00603                 FIO_STATUS ret = fileobj.Read(); 
00604                 if (ret != FIO_OK){ 
00605                         // I'am responsible! (But failed)
00606                         if (ret != FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00607                                 *fn=NULL;
00608                         // no more data: remove allocated and unused scan now, force!
00609                         gapp->xsm->SetMode(-1, ID_CH_M_OFF, TRUE); 
00610                         PI_DEBUG (DBG_L2, "Read Error " << ((int)ret) << "!!!!!!!!" );
00611                 }else{
00612                         // got it!
00613                         *fn=NULL;
00614 
00615                         // Now update gxsm main window data fields
00616                         gapp->xsm->ActiveScan->GetDataSet(gapp->xsm->data);
00617                         gapp->spm_update_all();
00618                         dst->draw();
00619                 }
00620         }else{
00621                 PI_DEBUG (DBG_L2, "PsiHDF_im_export_filecheck_load: Skipping" );
00622         }
00623 }
00624 
00625 static void PsiHDF_im_export_filecheck_save_callback (gpointer data ){
00626         gchar **fn = (gchar**)data;
00627         if (*fn){
00628                 Scan *src;
00629                 PI_DEBUG (DBG_L2,
00630                           "Check File: PsiHDF_im_export_filecheck_save_callback called with >"
00631                           << *fn << "<" );
00632 
00633                 PsiHDF_ImExportFile fileobj (src = gapp->xsm->GetActiveScan(), *fn);
00634 
00635                 FIO_STATUS ret;
00636                 ret = fileobj.Write(); 
00637 
00638                 if(ret != FIO_OK){
00639                         // I'am responsible! (But failed)
00640                         if (ret != FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00641                                 *fn=NULL;
00642                         PI_DEBUG (DBG_L2, "Write Error " << ((int)ret) << "!!!!!!!!" );
00643                 }else{
00644                         // write done!
00645                         *fn=NULL;
00646                 }
00647         }else{
00648                 PI_DEBUG (DBG_L2, "PsiHDF_im_export_filecheck_save: Skipping >" << *fn << "<" );
00649         }
00650 }
00651 
00652 // Menu Call Back Fkte
00653 
00654 static void PsiHDF_im_export_import_callback(GtkWidget *w, void *data){
00655         gchar **help = g_strsplit (PsiHDF_im_export_pi.help, ",", 2);
00656         gchar *dlgid = g_strconcat (PsiHDF_im_export_pi.name, "-import", NULL);
00657         gchar *fn = gapp->file_dialog(help[0], NULL, file_mask, NULL, dlgid);
00658         g_strfreev (help); 
00659         g_free (dlgid);
00660         PsiHDF_im_export_filecheck_load_callback (&fn );
00661 }
00662 
00663 static void PsiHDF_im_export_export_callback(GtkWidget *w, void *data){
00664         gchar **help = g_strsplit (PsiHDF_im_export_pi.help, ",", 2);
00665         gchar *dlgid = g_strconcat (PsiHDF_im_export_pi.name, "-export", NULL);
00666         gchar *fn = gapp->file_dialog(help[1], NULL, file_mask, NULL, dlgid);
00667         g_strfreev (help); 
00668         g_free (dlgid);
00669         PsiHDF_im_export_filecheck_save_callback (&fn );
00670 }

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