ascii_data_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: ascii_data_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: ASCII data file Import/Export
00034 % PlugInName: ascii_data_im_export
00035 % PlugInAuthor: Percy Zahl
00036 % PlugInAuthorEmail: zahl@users.sf.net
00037 % PlugInMenuPath: File/Import/ASCII
00038 
00039 % PlugInDescription
00040 \label{plugins:ascii_data_im_export}
00041 The \GxsmEmph{ascii\_data\_im\_export} plug-in supports reading of ASCII data files.
00042 Special but simple text header "Reuben-NSNOM" is suggested. Here is a sample file:
00043 
00044 {\tiny
00045 \begin{verbatim}
00046 scan length = 25.000000
00047 points/line = 25
00048 point spacing = 1.041667
00049 # lines =  25
00050 line spacing = 1.041667
00051 points in average = 1
00052 velocity = 2.000000
00053 lock-in time constant (msec) = 30.000000
00054 X origin = -1883.596000
00055 Y origin = 1321.116000
00056 
00057 end
00058 
00059 -1.5850 -1.5889 -1.5967 -1.5737 -1.5610 -1.5581 -1.5518 -1.5537 -1.9194 -2.2808 -2.2148 -2.1709 -2.1382 -2.1367 -2.1123 -2.0864 -2.0684 -2.0498 -2.0376 -2.0171 -1.9990 -1.9912 -1.9824 -1.9741 -1.9575
00060 -1.5796 -1.5811 -1.5684 -1.5718 -1.5625 -1.5552 -1.5425 -1.5488 -1.9272 -2.2764 -2.2104 -2.1660 -2.1387 -2.1294 -2.1094 -2.0801 -2.0645 -2.0464 -2.0337 -2.0229 -1.9961 -1.9883 -1.9824 -1.9717 -1.9604
00061 -1.5776 -1.5747 -1.5854 -1.5718 -1.5610 -1.5488 -1.5400 -1.5474 -1.9253 -2.2651 -2.2124 -2.1597 -2.1338 -2.1309 -2.0996 -2.0728 -2.0601 -2.0420 -2.0293 -2.0205 -1.9839 -1.9839 -1.9790 -1.9683 -1.9561
00062 -1.5688 -1.5840 -1.5825 -1.5640 -1.5518 -1.5488 -1.5361 -1.5430 -1.9395 -2.2607 -2.2070 -2.1548 -2.1309 -2.1250 -2.0942 -2.0708 -2.0557 -2.0391 -2.0264 -2.0156 -1.9912 -1.9810 -1.9712 -1.9653 -1.9502
00063 -1.5674 -1.5776 -1.5776 -1.5610 -1.5474 -1.5459 -1.5288 -1.5347 -1.9136 -2.2549 -2.1963 -2.1519 -2.1250 -2.1182 -2.0913 -2.0664 -2.0537 -2.0327 -2.0254 -2.0098 -1.9897 -1.9780 -1.9687 -1.9590 -1.9487
00064 -1.5610 -1.5732 -1.5732 -1.5566 -1.5439 -1.5391 -1.5259 -1.5337 -1.9502 -2.2471 -2.1919 -2.1445 -2.1196 -2.1123 -2.0850 -2.0620 -2.0420 -2.0278 -2.0146 -2.0054 -1.9868 -1.9712 -1.9609 -1.9531 -1.9424
00065 -1.5610 -1.5640 -1.5684 -1.5547 -1.5381 -1.5332 -1.5229 -1.5308 -1.9697 -2.2422 -2.1782 -2.1387 -2.1157 -2.1094 -2.0820 -2.0576 -2.0405 -2.0220 -2.0146 -2.0034 -1.9805 -1.9687 -1.9580 -1.9502 -1.9390
00066 -1.5562 -1.5625 -1.5640 -1.5483 -1.5308 -1.5283 -1.5171 -1.5107 -1.9854 -2.2378 -2.1797 -2.1367 -2.1123 -2.1030 -2.0742 -2.0542 -2.0337 -2.0171 -2.0098 -1.9961 -1.9741 -1.9624 -1.9517 -1.9453 -1.9316
00067 -1.5503 -1.5562 -1.5610 -1.5410 -1.5283 -1.5244 -1.5073 -1.5181 -1.9443 -2.2300 -2.1768 -2.1309 -2.1094 -2.1030 -2.0664 -2.0464 -2.0312 -2.0146 -2.0020 -1.9897 -1.9717 -1.9561 -1.9497 -1.9409 -1.9316
00068 -1.5459 -1.5532 -1.5581 -1.5400 -1.5239 -1.5171 -1.5073 -1.5044 -1.9302 -2.2227 -2.1738 -2.1260 -2.1021 -2.0967 -2.0693 -2.0435 -2.0264 -2.0083 -1.9990 -1.9849 -1.9653 -1.9531 -1.9453 -1.9395 -1.9253
00069 -1.5410 -1.5483 -1.5483 -1.5317 -1.5181 -1.5181 -1.5015 -1.4585 -1.9780 -2.2178 -2.1670 -2.1216 -2.0972 -2.0894 -2.0645 -2.0391 -2.0249 -2.0054 -1.9941 -1.9819 -1.9624 -1.9512 -1.9404 -1.9302 -1.9224
00070 -1.5337 -1.5410 -1.5425 -1.5244 -1.5137 -1.5132 -1.4951 -1.4966 -1.9224 -2.2114 -2.1597 -2.1172 -2.0957 -2.0864 -2.0601 -2.0327 -2.0171 -1.9990 -1.9912 -1.9741 -1.9561 -1.9453 -1.9375 -1.9287 -1.9165
00071 -1.5322 -1.5332 -1.5425 -1.5210 -1.5107 -1.5093 -1.4907 -1.4917 -1.9575 -2.2061 -2.1567 -2.1104 -2.0894 -2.0845 -2.0527 -2.0278 -2.0142 -1.9971 -1.9868 -1.9712 -1.9526 -1.9409 -1.9316 -1.9238 -1.9116
00072 -1.5308 -1.5181 -1.5361 -1.5088 -1.5059 -1.5015 -1.4873 -1.4873 -1.9653 -2.2036 -2.1523 -2.1060 -2.0864 -2.0786 -2.0464 -2.0229 -2.0142 -1.9941 -1.9790 -1.9634 -1.9482 -1.9360 -1.9297 -1.9194 -1.9058
00073 -1.5259 -1.5229 -1.5317 -1.5181 -1.4985 -1.4922 -1.4780 -1.4834 -1.9834 -2.1978 -2.1509 -2.1021 -2.0820 -2.0708 -2.0420 -2.0176 -2.0054 -1.9868 -1.9746 -1.9624 -1.9453 -1.9297 -1.9253 -1.9131 -1.9009
00074 -1.5229 -1.5225 -1.5273 -1.5117 -1.4873 -1.4937 -1.4780 -1.4785 -2.0308 -2.1885 -2.1489 -2.0952 -2.0757 -2.0679 -2.0405 -2.0127 -2.0010 -1.9819 -1.9712 -1.9561 -1.9395 -1.9282 -1.9180 -1.9116 -1.9009
00075 -1.5244 -1.5054 -1.5181 -1.4937 -1.4771 -1.4873 -1.4722 -1.4766 -2.0483 -2.1855 -2.1401 -2.0923 -2.0708 -2.0591 -2.0327 -2.0098 -1.9976 -1.9761 -1.9697 -1.9546 -1.9365 -1.9243 -1.9175 -1.9087 -1.8950
00076 -1.5229 -1.4893 -1.5103 -1.4180 -1.4687 -1.4771 -1.4687 -1.4722 -2.0327 -2.1812 -2.1279 -2.0864 -2.0635 -2.0542 -2.0234 -2.0000 -1.9941 -1.9717 -1.9624 -1.9487 -1.9331 -1.9175 -1.9102 -1.9023 -1.8887
00077 -1.4497 -1.4687 -1.4858 -1.4414 -1.4614 -1.4736 -1.4614 -1.4644 -2.0039 -2.1704 -2.1187 -2.0757 -2.0605 -2.0493 -2.0229 -2.0020 -1.9897 -1.9683 -1.9590 -1.9443 -1.9282 -1.9136 -1.9087 -1.8979 -1.8843
00078 -1.5229 -1.4478 -1.4917 -1.4893 -1.4766 -1.4736 -1.4497 -1.4429 -1.9790 -2.1523 -2.1050 -2.0786 -2.0566 -2.0513 -2.0205 -1.9990 -1.9854 -1.9653 -1.9590 -1.9409 -1.9243 -1.9131 -1.9014 -1.8921 -1.8809
00079 -1.5088 -1.3389 -1.4658 -1.4321 -1.4687 -1.4507 -1.4385 -1.4121 -2.0327 -2.1611 -2.1182 -2.0728 -2.0513 -2.0420 -2.0127 -1.9912 -1.9790 -1.9634 -1.9482 -1.9346 -1.9194 -1.9058 -1.8979 -1.8877 -1.8750
00080 -1.4707 -1.4678 -1.4507 -1.4443 -1.4707 -1.4067 -1.4521 -1.4463 -2.0117 -2.1494 -2.1123 -2.0684 -2.0508 -2.0376 -2.0083 -1.9897 -1.9741 -1.9590 -1.9453 -1.9302 -1.9160 -1.8994 -1.8921 -1.8857 -1.8706
00081 -1.4565 -1.5117 -1.4946 -1.4824 -1.4497 -1.4541 -1.4463 -1.4189 -2.0576 -2.1431 -2.0894 -2.0664 -2.0435 -2.0264 -2.0034 -1.9824 -1.9663 -1.9531 -1.9409 -1.9243 -1.9097 -1.8979 -1.8887 -1.8794 -1.8647
00082 -1.4893 -1.5044 -1.4858 -1.4658 -1.4722 -1.4551 -1.4307 -1.2671 -2.0464 -2.1357 -2.0967 -2.0576 -2.0356 -2.0205 -1.9990 -1.9780 -1.9683 -1.9487 -1.9365 -1.9194 -1.9067 -1.8931 -1.8843 -1.8735 -1.8628
00083 -1.4902 -1.5044 -1.4824 -1.4707 -1.4663 -1.4404 -1.4141 -1.3501 -2.1660 -2.1338 -2.0952 -2.0513 -2.0356 -2.0269 -1.9961 -1.9717 -1.9609 -1.9453 -1.9297 -1.9160 -1.9009 -1.8877 -1.8765 -1.8701 -1.8613
00084 \end{verbatim}
00085 }
00086 
00087 % PlugInUsage
00088 The plug-in is called by \GxsmMenu{File/Import/ASCII}. 
00089 Only import direction is implemented.
00090 
00091 %% OptPlugInKnownBugs
00092 %Not yet tested.
00093 
00094 % EndPlugInDocuSection
00095  * -------------------------------------------------------------------------------- 
00096  */
00097 
00098 #include <gtk/gtk.h>
00099 #include "config.h"
00100 #include "gxsm/plugin.h"
00101 #include "gxsm/dataio.h"
00102 #include "gxsm/action_id.h"
00103 #include "gxsm/util.h"
00104 #include "batch.h"
00105 #include "fileio.c"
00106 
00107 using namespace std;
00108 
00109 // Plugin Prototypes
00110 static void ascii_data_im_export_init (void);
00111 static void ascii_data_im_export_query (void);
00112 static void ascii_data_im_export_about (void);
00113 static void ascii_data_im_export_configure (void);
00114 static void ascii_data_im_export_cleanup (void);
00115 
00116 static void ascii_data_im_export_filecheck_load_callback (gpointer data );
00117 static void ascii_data_im_export_filecheck_save_callback (gpointer data );
00118 
00119 static void ascii_data_im_export_import_callback (GtkWidget *w, void *data);
00120 static void ascii_data_im_export_export_callback (GtkWidget *w, void *data);
00121 
00122 // Fill in the GxsmPlugin Description here
00123 GxsmPlugin ascii_data_im_export_pi = {
00124   NULL,                   // filled in and used by Gxsm, don't touch !
00125   NULL,                   // filled in and used by Gxsm, don't touch !
00126   0,                      // filled in and used by Gxsm, don't touch !
00127   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00128                           // filled in here by Gxsm on Plugin load, 
00129                           // just after init() is called !!!
00130   "Ascii_Data_Im_Export",
00131   NULL,                   // PlugIn's Categorie, set to NULL for all, I just don't want this always to be loaded!
00132   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00133   "Im/Export of the ASCII data file format.",
00134   "Percy Zahl",
00135   N_("_File/_Import/,_File/_Export/"),
00136   N_("ASCII,ASCII"),
00137   N_("ASCII import,ASCII export"),
00138   N_("ASCII data file import and export filter, using header for Reuben NSNOM."),
00139   NULL,          // error msg, plugin may put error status msg here later
00140   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00141   ascii_data_im_export_init,
00142   ascii_data_im_export_query,
00143   // about-function, can be "NULL"
00144   // can be called by "Plugin Details"
00145   ascii_data_im_export_about,
00146   // configure-function, can be "NULL"
00147   // can be called by "Plugin Details"
00148   ascii_data_im_export_configure,
00149   // run-function, can be "NULL", if non-Zero and no query defined, 
00150   // it is called on menupath->"plugin"
00151   NULL,
00152   // cleanup-function, can be "NULL"
00153   // called if present at plugin removeal
00154   ascii_data_im_export_cleanup
00155 };
00156 
00157 // Text used in Aboutbox, please update!!
00158   static const char *about_text = N_("GXSM ASCII data file Import/Export Plugin\n\n");
00159 
00160 static const char *file_mask = "*.asc";
00161 
00162 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00163 // Essential Plugin Function!!
00164 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00165   ascii_data_im_export_pi.description = g_strdup_printf(N_("Gxsm im_export plugin %s"), VERSION);
00166   return &ascii_data_im_export_pi; 
00167 }
00168 
00169 // Query Function, installs Plugin's in File/Import and Export Menupaths!
00170 // ----------------------------------------------------------------------
00171 // Import Menupath is "File/Import/GME Dat"
00172 // Export Menupath is "File/Export/GME Dat"
00173 // ----------------------------------------------------------------------
00174 // !!!! make sure the "ascii_data_im_export_cleanup()" function (see below) !!!!
00175 // !!!! removes the correct menuentries !!!!
00176 
00177 static void ascii_data_im_export_query(void)
00178 {
00179         gchar **path  = g_strsplit (ascii_data_im_export_pi.menupath, ",", 2);
00180         gchar **entry = g_strsplit (ascii_data_im_export_pi.menuentry, ",", 2);
00181         gchar **help  = g_strsplit (ascii_data_im_export_pi.help, ",", 2);
00182 
00183         static GnomeUIInfo menuinfo_i[] = { 
00184                 { GNOME_APP_UI_ITEM, NULL, NULL,
00185                   NULL, NULL,
00186                   NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_OPEN,
00187                   0, GDK_CONTROL_MASK, NULL },
00188                 GNOMEUIINFO_END
00189         };
00190         menuinfo_i[0].label  = entry[0];
00191         menuinfo_i[0].hint   = help[0];
00192         menuinfo_i[0].moreinfo  = (gpointer) ascii_data_im_export_import_callback; 
00193         menuinfo_i[0].user_data = ascii_data_im_export_pi.name;
00194 
00195         gnome_app_insert_menus (
00196                 GNOME_APP(ascii_data_im_export_pi.app->getApp()), 
00197                 path[0], 
00198                 menuinfo_i
00199                 );
00200         
00201 
00202         static GnomeUIInfo menuinfo_e[] = { 
00203                 { GNOME_APP_UI_ITEM, NULL, NULL,
00204                   NULL, NULL,
00205                   NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_SAVE,
00206                   0, GDK_CONTROL_MASK, NULL },
00207                 GNOMEUIINFO_END
00208         };
00209         menuinfo_e[0].label  = entry[1];
00210         menuinfo_e[0].hint   = help[1];
00211         menuinfo_e[0].moreinfo  = (gpointer) ascii_data_im_export_export_callback; 
00212         menuinfo_e[0].user_data = ascii_data_im_export_pi.name;
00213 
00214         gnome_app_insert_menus (
00215                 GNOME_APP(ascii_data_im_export_pi.app->getApp()), 
00216                 path[1],
00217                 menuinfo_e
00218                 );
00219 
00220         if(ascii_data_im_export_pi.status) g_free(ascii_data_im_export_pi.status); 
00221         ascii_data_im_export_pi.status = g_strconcat (
00222                 N_("Plugin query has attached "),
00223                 ascii_data_im_export_pi.name, 
00224                 N_(": File IO Filters are ready to use."),
00225                 NULL);
00226         
00227         // clean up
00228         g_strfreev (path);
00229         g_strfreev (entry);
00230         g_strfreev (help);
00231 
00232 // register this plugins filecheck functions with Gxsm now!
00233 // This allows Gxsm to check files from DnD, open, 
00234 // and cmdline sources against all known formats automatically - no explicit im/export is necessary.
00235         ascii_data_im_export_pi.app->ConnectPluginToLoadFileEvent (ascii_data_im_export_filecheck_load_callback);
00236         ascii_data_im_export_pi.app->ConnectPluginToSaveFileEvent (ascii_data_im_export_filecheck_save_callback);
00237 }
00238 
00239 
00240 // 5.) Start here with the plugins code, vars def., etc.... here.
00241 // ----------------------------------------------------------------------
00242 //
00243 
00244 
00245 // init-Function
00246 static void ascii_data_im_export_init(void)
00247 {
00248         PI_DEBUG (DBG_L2, ascii_data_im_export_pi.name << "Plugin Init");
00249 }
00250 
00251 // about-Function
00252 static void ascii_data_im_export_about(void)
00253 {
00254         const gchar *authors[] = { ascii_data_im_export_pi.authors, NULL};
00255         gtk_widget_show(gnome_about_new ( ascii_data_im_export_pi.name,
00256                                           VERSION,
00257                                           N_("(C) 2001 the Free Software Foundation"),
00258                                           about_text,
00259                                           authors,
00260                                           NULL, NULL, NULL
00261                                           ));
00262 }
00263 
00264 // configure-Function
00265 static void ascii_data_im_export_configure(void)
00266 {
00267         if(ascii_data_im_export_pi.app)
00268                 ascii_data_im_export_pi.app->message("ascii_data_im_export Plugin Configuration");
00269 }
00270 
00271 // cleanup-Function, make sure the Menustrings are matching those above!!!
00272 static void ascii_data_im_export_cleanup(void)
00273 {
00274         gchar **path  = g_strsplit (ascii_data_im_export_pi.menupath, ",", 2);
00275         gchar **entry = g_strsplit (ascii_data_im_export_pi.menuentry, ",", 2);
00276 
00277         gchar *tmp = g_strconcat (path[0], entry[0], NULL);
00278         gnome_app_remove_menus (GNOME_APP (ascii_data_im_export_pi.app->getApp()), tmp, 1);
00279         g_free (tmp);
00280 
00281         tmp = g_strconcat (path[1], entry[1], NULL);
00282         gnome_app_remove_menus (GNOME_APP (ascii_data_im_export_pi.app->getApp()), tmp, 1);
00283         g_free (tmp);
00284 
00285         g_strfreev (path);
00286         g_strfreev (entry);
00287 
00288         PI_DEBUG (DBG_L2, "Plugin Cleanup done.");
00289 }
00290 
00291 // make a new derivate of the base class "Dataio"
00292 class ascii_ImExportFile : public Dataio{
00293 public:
00294         ascii_ImExportFile(Scan *s, const char *n) : Dataio(s,n){ };
00295         virtual FIO_STATUS Read();
00296         virtual FIO_STATUS Write();
00297 private:
00298         FIO_STATUS import(const char *fname);
00299 };
00300 
00301 FIO_STATUS ascii_ImExportFile::Read(){
00302         FIO_STATUS ret;
00303         gchar *fname=NULL;
00304 
00305         fname = (gchar*)name;
00306 
00307         // name should have at least 4 chars: ".ext"
00308         if (fname == NULL || strlen(fname) < 4)
00309                 return  FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00310  
00311         // check for file exists and is OK !
00312         // else open File Dlg
00313         ifstream f;
00314         f.open(fname, ios::in);
00315         if(!f.good()){
00316                 PI_DEBUG (DBG_L2, "Error at file open. File not good/readable.");
00317                 return status=FIO_OPEN_ERR;
00318         }
00319         f.close();
00320 
00321         // Check all known File Types:
00322         if ((ret=import (fname)) !=  FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00323                 return ret;
00324 
00325         return  FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00326 }
00327 
00328 FIO_STATUS ascii_ImExportFile::import(const char *fname){
00329         double length = 1.;
00330         int columns = 1;
00331         int rows = 1;
00332         double dx = 1.;
00333         double dy = 1.;
00334         double x0 = 0.;
00335         double y0 = 0.;
00336         gchar line[0x4000];
00337 
00338         // Am I resposible for that file, is it a "Ascii" format ?
00339         ifstream f;
00340         GString *FileList=NULL;
00341 
00342         if (strncasecmp(fname+strlen(fname)-4,".asc",4)){
00343                 f.close ();
00344                 return status=FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00345         }
00346 
00347         f.open(name, ios::in);
00348         if (!f.good())
00349                 return status=FIO_OPEN_ERR;
00350         
00351         FileList = g_string_new ("Imported by GXSM from ASCII/NSNOM-Reuben data file.\n");
00352         g_string_sprintfa (FileList, "Original Filename: %s\n", fname);
00353         g_string_append (FileList, "Orig. Header: \n");
00354 
00355         // read header
00356         for (; f.good ();){
00357                 f.getline (line, 0x4000);
00358 
00359                 // append to comment
00360                 g_string_append (FileList, line);
00361                 g_string_append (FileList, "\n");
00362 
00363                 //                  0        1         2         3         4
00364                 //                  1234567890123456789012345678901234567890
00365                 if (strncmp (line, "scan length = ", 14) == 0)
00366                         length = atof (&line[14]);
00367                 if (strncmp (line, "points/line = ", 14) == 0)
00368                         columns = atoi (&line[14]);
00369                 if (strncmp (line, "# lines = ", 10) == 0)
00370                         rows = atoi (&line[10]);
00371                 if (strncmp (line, "point spacing = ", 16) == 0)
00372                         dx = atof (&line[16]);
00373                 if (strncmp (line, "line spacing = ", 15) == 0)
00374                         dy = atof (&line[15]);
00375                 if (strncmp (line, "X origin = ", 11) == 0)
00376                         x0 = atof (&line[11]);
00377                 if (strncmp (line, "Y origin = ", 11) == 0)
00378                         y0 = atof (&line[11]);
00379 
00380                 // header end mark? then skip to data start
00381                 if (strncmp (line, "end", 3) == 0){
00382                         f.getline (line, 0x4000);
00383                         break;
00384                 }
00385         }
00386 
00387         time_t t; // Scan - Startzeit eintragen 
00388         time(&t);
00389         gchar *tmp = g_strconcat ((ctime(&t)), " (Imported)", NULL); scan->data.ui.SetDateOfScan (tmp); g_free (tmp);
00390         scan->data.ui.SetName (fname);
00391         scan->data.ui.SetOriginalName (fname);
00392         scan->data.ui.SetType ("ASCII-NSNOM"); 
00393 
00394 
00395         // this is mandatory.
00396         scan->data.s.ntimes  = 1;
00397         scan->data.s.nvalues = 1;
00398   
00399   
00400         // put some usefull values in the ui structure
00401         if(getlogin()){
00402                 scan->data.ui.SetUser (getlogin());
00403         }
00404         else{
00405                 scan->data.ui.SetUser ("unkonwn user");
00406         }
00407 
00408         // initialize scan structure -- this is a minimum example
00409         scan->data.s.nx = columns;
00410         scan->data.s.ny = rows;
00411         scan->data.s.dx = dx * 1e4; // need Angstroems
00412         scan->data.s.dy = dy * 1e4;
00413         scan->data.s.dz = 1. * 1e4;
00414         scan->data.s.rx = length * 1e4;
00415         scan->data.s.ry = length * 1e4;
00416         scan->data.s.x0 = x0 * 1e4;
00417         scan->data.s.y0 = y0 * 1e4;
00418         scan->data.s.alpha = 0.;
00419 
00420         // be nice and reset this to some defined state
00421         scan->data.display.cpshigh       = 0.;
00422         scan->data.display.cpslow        = 0.;
00423         scan->data.display.cnttime       = 0.;
00424 
00425         // set the default view parameters
00426         scan->data.display.bright = 32.;
00427         scan->data.display.contrast = 1.0;
00428 
00429         // FYI: (PZ)
00430         //  scan->data.display.vrange_z  = ; // View Range Z in base ZUnits
00431         //  scan->data.display.voffset_z = 0; // View Offset Z in base ZUnits
00432         //  scan->AutoDisplay([...]); // may be used too...
00433   
00434         UnitObj *u = gapp->xsm->MakeUnit ("um", "X");
00435         scan->data.SetXUnit(u);
00436         delete u;
00437 
00438         u = gapp->xsm->MakeUnit ("um", "Y");
00439         scan->data.SetYUnit(u);
00440         delete u;
00441 
00442         u = gapp->xsm->MakeUnit ("um", "Z");
00443         scan->data.SetZUnit(u);
00444         delete u;
00445 
00446         scan->data.ui.SetComment (FileList->str);
00447         g_string_free(FileList, TRUE); 
00448         FileList=NULL;
00449 
00450 //      scan->data.s.dx = scan->data.s.rx / scan->data.s.nx;
00451 //      scan->data.s.dy = scan->data.s.ry / scan->data.s.ny;
00452 
00453         // Read Img Data.
00454         scan->mem2d->Resize (scan->data.s.nx, scan->data.s.ny, ZD_FLOAT);
00455 
00456         for (int row=scan->mem2d->GetNy ()-1; row >= 0; --row){
00457                 for (int col=0; col < scan->mem2d->GetNx (); ++col){
00458                         double value = 0.;
00459                         f >> value;
00460                         scan->mem2d->PutDataPkt (value, col, row);
00461                         if (! f.good ())
00462                                 break;
00463                 }
00464                 if (! f.good ())
00465                         break;
00466         }
00467 
00468         f.close ();
00469 
00470         scan->data.orgmode = SCAN_ORG_CENTER;
00471         scan->mem2d->data->MkXLookup (-scan->data.s.rx/2., scan->data.s.rx/2.);
00472         scan->mem2d->data->MkYLookup (-scan->data.s.ry/2., scan->data.s.ry/2.);
00473   
00474         return FIO_OK; 
00475 }
00476 
00477 
00478 FIO_STATUS ascii_ImExportFile::Write(){
00479         GtkWidget *dialog = gtk_message_dialog_new (NULL,
00480                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
00481                                                     GTK_MESSAGE_INFO,
00482                                                     GTK_BUTTONS_OK,
00483                                                     N_("Sorry, not yet implemented.")
00484                                                     );
00485         gtk_dialog_run (GTK_DIALOG (dialog));
00486         gtk_widget_destroy (dialog);
00487 
00488 #if 0
00489         gchar tmp[0x4004];
00490         const gchar *fname;
00491         ofstream f;
00492 
00493         memset (tmp, 0, sizeof (tmp));
00494 
00495         if(strlen(name)>0)
00496                 fname = (const char*)name;
00497         else
00498                 fname = gapp->file_dialog("File Export: ASCII"," ",file_mask,"","ASCII write");
00499         if (fname == NULL) return FIO_NO_NAME;
00500 
00501         // check if we like to handle this
00502         if (strncmp(fname+strlen(fname)-4,".asc",4))
00503                 return FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00504 
00505 
00506         f.open(name, ios::out);
00507         if (!f.good())
00508                 return status=FIO_OPEN_ERR;
00509 
00510 //      scan->mem2d->DataWrite(f);
00511 #endif
00512   return FIO_OK; 
00513 }
00514 
00515 // Plugin's Notify Cb's, registered to be called on file load/save to check file
00516 // return via filepointer, it is set to Zero or passed as Zero if file has been processed!
00517 // That's all fine, you should just change the Text Stings below...
00518 
00519 
00520 static void ascii_data_im_export_filecheck_load_callback (gpointer data ){
00521         gchar **fn = (gchar**)data;
00522         if (*fn){
00523                 PI_DEBUG (DBG_L2, 
00524                           "Check File: ascii_data_im_export_filecheck_load_callback called with >"
00525                           << *fn << "<" );
00526 
00527                 Scan *dst = gapp->xsm->GetActiveScan();
00528                 if(!dst){ 
00529                         gapp->xsm->ActivateFreeChannel();
00530                         dst = gapp->xsm->GetActiveScan();
00531                 }
00532                 ascii_ImExportFile fileobj (dst, *fn);
00533 
00534                 FIO_STATUS ret = fileobj.Read(); 
00535                 if (ret != FIO_OK){ 
00536                         // I'am responsible! (But failed)
00537                         if (ret != FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00538                                 *fn=NULL;
00539                         // no more data: remove allocated and unused scan now, force!
00540                         gapp->xsm->SetMode(-1, ID_CH_M_OFF, TRUE); 
00541                         PI_DEBUG (DBG_L2, "Read Error " << ((int)ret) << "!!!!!!!!" );
00542                 }else{
00543                         // got it!
00544                         *fn=NULL;
00545 
00546                         // Now update gxsm main window data fields
00547                         gapp->xsm->ActiveScan->GetDataSet(gapp->xsm->data);
00548                         gapp->spm_update_all();
00549                         dst->draw();
00550                 }
00551         }else{
00552                 PI_DEBUG (DBG_L2, "ascii_data_im_export_filecheck_load: Skipping" );
00553         }
00554 }
00555 
00556 static void ascii_data_im_export_filecheck_save_callback (gpointer data ){
00557         gchar **fn = (gchar**)data;
00558         if (*fn){
00559                 Scan *src;
00560                 PI_DEBUG (DBG_L2,
00561                           "Check File: ascii_data_im_export_filecheck_save_callback called with >"
00562                           << *fn << "<" );
00563 
00564                 ascii_ImExportFile fileobj (src = gapp->xsm->GetActiveScan(), *fn);
00565 
00566                 FIO_STATUS ret;
00567                 ret = fileobj.Write(); 
00568 
00569                 if(ret != FIO_OK){
00570                         // I'am responsible! (But failed)
00571                         if (ret != FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00572                                 *fn=NULL;
00573                         PI_DEBUG (DBG_L2, "Write Error " << ((int)ret) << "!!!!!!!!" );
00574                 }else{
00575                         // write done!
00576                         *fn=NULL;
00577                 }
00578         }else{
00579                 PI_DEBUG (DBG_L2, "ascii_data_im_export_filecheck_save: Skipping >" << *fn << "<" );
00580         }
00581 }
00582 
00583 // Menu Call Back Fkte
00584 
00585 static void ascii_data_im_export_import_callback(GtkWidget *w, void *data){
00586         gchar **help = g_strsplit (ascii_data_im_export_pi.help, ",", 2);
00587         gchar *dlgid = g_strconcat (ascii_data_im_export_pi.name, "-import", NULL);
00588         gchar *fn = gapp->file_dialog(help[0], NULL, file_mask, NULL, dlgid);
00589         g_strfreev (help); 
00590         g_free (dlgid);
00591         ascii_data_im_export_filecheck_load_callback (&fn );
00592 }
00593 
00594 static void ascii_data_im_export_export_callback(GtkWidget *w, void *data){
00595         gchar **help = g_strsplit (ascii_data_im_export_pi.help, ",", 2);
00596         gchar *dlgid = g_strconcat (ascii_data_im_export_pi.name, "-export", NULL);
00597         gchar *fn = gapp->file_dialog(help[1], NULL, file_mask, NULL, dlgid);
00598         g_strfreev (help); 
00599         g_free (dlgid);
00600         ascii_data_im_export_filecheck_save_callback (&fn );
00601 }

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