sranger_hwi_eventhandling.C

Go to the documentation of this file.
00001 /* Gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Copyright (C) 1999,2000,2001,2002,2003 Percy Zahl
00006  *
00007  * Authors: Percy Zahl <zahl@users.sf.net>
00008  * additional features: Andreas Klust <klust@users.sf.net>
00009  * WWW Home: http://gxsm.sf.net
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00024  */
00025 
00026 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00027 
00028 /* ignore this module for docuscan
00029 % PlugInModuleIgnore
00030 */
00031 
00032 
00033 
00034 #include <locale.h>
00035 #include <libintl.h>
00036 
00037 #include <time.h>
00038 
00039 #include "glbvars.h"
00040 #include "plug-ins/hard/modules/dsp.h"
00041 #include <fcntl.h>
00042 #include <sys/ioctl.h>
00043 
00044 #include "gxsm/action_id.h"
00045 
00046 #include "dsp-pci32/xsm/xsmcmd.h"
00047 
00048 #include "sranger_hwi_control.h"
00049 #include "sranger_hwi.h"
00050 #include "gtkspinbuttonsci.h"
00051 #include "../plug-ins/hard/modules/sranger_ioctl.h"
00052 
00053 #define UTF8_DEGREE    "\302\260"
00054 #define UTF8_MU        "\302\265"
00055 #define UTF8_ANGSTROEM "\303\205"
00056 
00057 #define CONV_16(X) X = sranger_hwi_hardware->int_2_sranger_int (X)
00058 #define CONV_32(X) X = sranger_hwi_hardware->long_2_sranger_long (X)
00059 
00060 extern GxsmPlugin sranger_hwi_pi;
00061 extern sranger_hwi_dev *sranger_hwi_hardware;
00062 
00063 // SR specific conversions and lookups
00064 
00065 #define SRV2     (2.05/32767.)
00066 #define SRV10    (10.0/32767.)
00067 #define PhaseFac (1./16.)
00068 #define BiasFac  (gapp->xsm->Inst->Dig2VoltOut (1.) / gapp->xsm->Inst->BiasV2V (1.))
00069 #define ZAngFac  (gapp->xsm->Inst->Dig2ZA (1))
00070 #define XAngFac  (gapp->xsm->Inst->Dig2XA (1))
00071 #define YAngFac  (gapp->xsm->Inst->Dig2YA (1))
00072 
00073 #define MAX_NUM_CHANNELS 25
00074 
00075 static int   msklookup[] = { 0x0000020, 0x0000040, 0x0000080, 0x0000100, 0x0000200, 0x0000010, 0x0000400, 0, 
00076                              0x0000001, 0x0000002, 
00077                              0x0000800, 0x0001000, 0x0002000, 0x0004000, 0x0008000,
00078                              0x0100000, 0x0200000, 0x0400000, 0x0800000, 0x1000000, 0x2000000, 0x4000000,
00079                              -1 
00080 };
00081 
00082 static int   expdi_lookup[] = { PROBEDATA_ARRAY_AIC0, PROBEDATA_ARRAY_AIC1, PROBEDATA_ARRAY_AIC2, PROBEDATA_ARRAY_AIC3,
00083                                 PROBEDATA_ARRAY_AIC4, PROBEDATA_ARRAY_AIC5_FBS, PROBEDATA_ARRAY_AIC6, PROBEDATA_ARRAY_AIC7,
00084                                 PROBEDATA_ARRAY_AIC5OUT_ZMON, PROBEDATA_ARRAY_AIC6OUT_UMON, 
00085                                 PROBEDATA_ARRAY_LCK0, PROBEDATA_ARRAY_LCK1A, PROBEDATA_ARRAY_LCK1B, PROBEDATA_ARRAY_LCK2A, PROBEDATA_ARRAY_LCK2B,
00086                                 PROBEDATA_ARRAY_TIME, PROBEDATA_ARRAY_XS, PROBEDATA_ARRAY_YS, PROBEDATA_ARRAY_ZS,  PROBEDATA_ARRAY_U, PROBEDATA_ARRAY_PHI,
00087                                 PROBEDATA_ARRAY_SEC,
00088                                 0
00089 };
00090 
00091 static char* lablookup[]  = { "ADC0", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5-I","ADC6","ADC7",
00092                               "Zmon", "Umon", 
00093                               "LockIn0", "LockIn1stA", "LockIn1stB", "LockIn2ndA", "LockIn2ndB",
00094                               "Time", "XS",   "YS",   "ZS",   "Bias", "Phase", "VP-Section",
00095                               NULL
00096 };
00097 
00098 static char* unitlookup[] = { "V",   "V",    "V",    "V",    "V",    "V",     "V",   "V",
00099                               UTF8_ANGSTROEM,   "V",    
00100                               "V", "dV", "dV",  "ddV", "ddV",
00101                               "ms", UTF8_ANGSTROEM, UTF8_ANGSTROEM, UTF8_ANGSTROEM, "V", "deg", "#",
00102                               NULL
00103 };
00104 
00105 
00106 
00107 int DSPControl::Probing_eventcheck_callback( GtkWidget *widget, DSPControl *dspc){
00108         static int warm=FALSE;
00109         static ProfileControl *pc[MAX_NUM_CHANNELS][MAX_NUM_CHANNELS];
00110         int popped=0;
00111         GArray **garr;
00112         double DAC2Ulookup[]={ SRV10, SRV10,  SRV10,  SRV10,  SRV10,  SRV10,   SRV10,  SRV10,
00113                                ZAngFac, BiasFac, SRV10,  SRV10,  SRV10, SRV10,  SRV10,  
00114                                1e3/dspc->frq_ref, XAngFac, YAngFac, ZAngFac, BiasFac, PhaseFac, 1.,
00115                                0.
00116         };
00117 
00118         // initialize only once, reuse later
00119         if (!warm){
00120                 for (int i=0; i<MAX_NUM_CHANNELS; ++i)
00121                         for (int j=0; j<MAX_NUM_CHANNELS; ++j)
00122                                 pc[i][j]=NULL;
00123                 warm=TRUE;
00124         }
00125 
00126         // pop off all available data from stack
00127         while ((garr = dspc->pop_probedata_arrays ()) != NULL){
00128                 ++popped;
00129                 
00130 // atach event to active channel, if one exists -- raster mode ------------------------------
00131 
00132                 ScanEvent *se = NULL;
00133                 if (gapp->xsm->ActiveScan){
00134                         // find first section header and take this X,Y coordinates as reference -- start of probe event
00135                         int sec = 0;
00136                         for (int j=0; j<dspc->last_probe_data_index; ++j){
00137                                 int s = (int) g_array_index (garr [PROBEDATA_ARRAY_SEC], double, j);
00138                                 if (s < (sec-1)) 
00139                                         sec = s;
00140                                 if (s >= sec || j == dspc->last_probe_data_index-1 || j == 0){
00141                                         sec = s+1;
00142                                 } else
00143                                         continue;
00144                                 
00145                                 se = new ScanEvent (
00146                                         gapp->xsm->Inst->Dig2XA ((long) round (
00147                                                        g_array_index (garr [PROBEDATA_ARRAY_X0], double, j)
00148                                                      + g_array_index (garr [PROBEDATA_ARRAY_XS], double, j))
00149                                                 ),
00150                                         gapp->xsm->Inst->Dig2YA ((long) round (
00151                                                        g_array_index (garr [PROBEDATA_ARRAY_Y0], double, j)
00152                                                      + g_array_index (garr [PROBEDATA_ARRAY_YS], double, j))
00153                                                 ),
00154                                         gapp->xsm->Inst->Dig2ZA ((long) round (
00155 //                                                     g_array_index (garr [PROBEDATA_ARRAY_Z0], double, j)
00156                                                        0.
00157                                                      + g_array_index (garr [PROBEDATA_ARRAY_ZS], double, j))
00158                                                 )
00159                                         );
00160                                 gapp->xsm->ActiveScan->mem2d->AttachScanEvent (se);
00161                                 break;
00162                         }
00163                 }
00164 
00165                 // if we have attached an scan event, so fill it with data now
00166                 if (se){
00167                         // find chunksize (total # data sources)
00168                         int chunksize = 0;
00169                         GPtrArray *glabarray = g_ptr_array_new ();
00170                         GPtrArray *gsymarray = g_ptr_array_new ();
00171 
00172                         for (int src=0; msklookup[src]>=0 && src < MAX_NUM_CHANNELS; ++src)
00173                                 if (dspc->Source & msklookup[src]){
00174                                         g_ptr_array_add (glabarray, (gpointer) lablookup[src]);
00175                                         g_ptr_array_add (gsymarray, (gpointer) unitlookup[src]);
00176                                         ++chunksize;
00177                                 }
00178                 
00179                         if (chunksize > 0 && chunksize < MAX_NUM_CHANNELS){
00180                                 double dataset[MAX_NUM_CHANNELS];
00181                                 ProbeEntry *pe = new ProbeEntry ("Probe", time(0), glabarray, gsymarray, chunksize);
00182                                 for (int i = 0; i < dspc->last_probe_data_index; i++){
00183                                         int j=0;
00184                                         for (int src=0; msklookup[src]>=0 && src < MAX_NUM_CHANNELS; ++src){
00185                                                 if (dspc->Source & msklookup[src])
00186                                                         dataset[j++] = DAC2Ulookup[src] * g_array_index (garr [expdi_lookup[src]], double, i);
00187                                         }
00188                                         pe->add ((double*)&dataset);
00189                                 }
00190                                 se->add_event (pe);
00191                         }
00192                 }
00193 
00194 // on-the-fly visualisation graphs update ------------------------------
00195 
00196                 if (dspc->raster_auto_flags & FLAG_AUTO_PLOT){
00197 
00198                         for (int xmap=0; msklookup[xmap]>=0; ++xmap){
00199                                 if ((dspc->XSource & msklookup[xmap]) && (dspc->Source & msklookup[xmap]))
00200                                         for (int src=0; msklookup[src]>=0; ++src){
00201                                                 if ((dspc->PSource & msklookup[src]) && (dspc->Source & msklookup[src])){
00202 
00203                                                         UnitObj *UXaxis = new UnitObj(unitlookup[xmap], " ", "g", lablookup[xmap]);
00204                                                         UnitObj *UYaxis = new UnitObj(unitlookup[src],  " ", "g", lablookup[src]);
00205                                                         double xmult = DAC2Ulookup[xmap];
00206                                                         double ymult = DAC2Ulookup[src];
00207                                                         double xmin, xmax, x;
00208 
00209                                                         // find min and max X limit
00210                                                         xmin = xmax = xmult * g_array_index (garr [expdi_lookup[xmap]], double, 0);
00211                                                         for(int i = 1; i < dspc->last_probe_data_index; i++){
00212                                                                 x = xmult * g_array_index (garr [expdi_lookup[xmap]], double, i);
00213                                                                 if (x > xmax) xmax = x;
00214                                                                 if (x < xmin) xmin = x;
00215                                                         }
00216 
00217                                                         UXaxis->SetAlias (lablookup[xmap]);
00218                                                         UYaxis->SetAlias (lablookup[src]);
00219                                                         if (!pc[xmap][src]){
00220                                                                 gchar   *title  = g_strdup_printf ("Raster Vector Probe, Channel: %s", lablookup[src]);
00221                                                                 pc[xmap][src] = new ProfileControl (title, 
00222                                                                                                     dspc->last_probe_data_index, 
00223                                                                                                     UXaxis, UYaxis, 
00224                                                                                                     xmin, xmax,
00225                                                                                                     lablookup[src]);
00226                                                                 g_free (title);
00227                                                         } else {
00228                                                                 pc[xmap][src]->scan1d->mem2d->Resize (dspc->last_probe_data_index, 1);
00229                                                                 pc[xmap][src]->SetXrange (xmin, xmax);
00230                                                         }
00231                         
00232                                                         for(int i = 0; i < dspc->last_probe_data_index; i++){
00233                                                                 pc[xmap][src]->SetPoint (i, 
00234                                                                                          xmult * g_array_index (garr [expdi_lookup[xmap]], double, i),
00235                                                                                          ymult * g_array_index (garr [expdi_lookup[src]], double, i));
00236                                                         }
00237                                                         sranger_hwi_pi.app->xsm->AddProfile (pc[xmap][src]); // give it to Surface, it takes care about removing it...
00238         
00239                                                         pc[xmap][src]->drawScans ();
00240                                                         pc[xmap][src]->UpdateArea ();
00241                                                         pc[xmap][src]->show ();
00242 //                                      pc[xmap][src]->unref (); // nothing depends on it, so decrement refcount
00243 //                                      pc[xmap][src] = NULL; // get rid of it now
00244                                                 }
00245                                         }
00246                         }
00247                 }
00248                 
00249                 free_probedata_array_set (garr, dspc);  
00250         }
00251 
00252         if (popped > 0)
00253                 if (gapp->xsm->ActiveScan)
00254                         gapp->xsm->ActiveScan->view->update_events ();
00255 
00256         return 0;
00257 }
00258 
00259 int DSPControl::Probing_graph_callback( GtkWidget *widget, DSPControl *dspc){
00260 // show and update data pv graph
00261         static int warm=FALSE;
00262         static ProfileControl *pc[MAX_NUM_CHANNELS][MAX_NUM_CHANNELS];
00263         
00264         if (!warm){
00265                 for (int i=0; i<MAX_NUM_CHANNELS; ++i)
00266                         for (int j=0; j<MAX_NUM_CHANNELS; ++j)
00267                                 pc[i][j]=NULL;
00268                 warm=TRUE;
00269         }
00270 
00271         if (!dspc->current_probe_data_index) 
00272                 return 0;
00273         
00274 
00275         double DAC2Ulookup[]={ SRV10, SRV10,  SRV10,  SRV10,  SRV10,  SRV10,   SRV10,  SRV10,
00276                                ZAngFac, BiasFac, SRV10,  SRV10,  SRV10, SRV10,  SRV10,  
00277                                1e3/dspc->frq_ref, XAngFac, YAngFac, ZAngFac, BiasFac, PhaseFac, 1.,
00278                                0.
00279         };
00280                 
00281 
00282 //xxxxxxxxxxxxx atach event to active channel, if one exists -- manual mode xxxxxxxxxxxxxxxxxxxxx
00283         ScanEvent *se = NULL;
00284         if (gapp->xsm->ActiveScan){
00285                 // find first section header and take this X,Y coordinates as reference -- start of probe event
00286                 int sec = 0;
00287                 for (int j=0; j<dspc->current_probe_data_index; ++j){
00288                         int s = (int) g_array_index (dspc->garray_probedata [PROBEDATA_ARRAY_SEC], double, j);
00289                         if (s < (sec-1)) 
00290                                 sec = s;
00291                         if (s >= sec || j == dspc->current_probe_data_index-1 || j == 0)
00292                                 sec = s+1;
00293                         else
00294                                 continue;
00295                         
00296 
00297 //                      se = new ScanEvent (
00298 //                              gapp->xsm->data.s.x0 + gapp->xsm->Inst->Dig2XA ((int)g_array_index (dspc->garray_probedata [PROBEDATA_ARRAY_XS], double, j)),
00299 //                              gapp->xsm->data.s.y0 + gapp->xsm->Inst->Dig2YA ((int)g_array_index (dspc->garray_probedata [PROBEDATA_ARRAY_YS], double, j))
00300 //                              );
00301 
00302                         se = new ScanEvent (
00303                                 gapp->xsm->Inst->Dig2XA ((long) round (
00304                                                                  g_array_index (dspc->garray_probedata [PROBEDATA_ARRAY_X0], double, j)
00305                                                                  + g_array_index (dspc->garray_probedata [PROBEDATA_ARRAY_XS], double, j))
00306                                         ),
00307                                 gapp->xsm->Inst->Dig2YA ((long) round (
00308                                                                  g_array_index (dspc->garray_probedata [PROBEDATA_ARRAY_Y0], double, j)
00309                                                                  + g_array_index (dspc->garray_probedata [PROBEDATA_ARRAY_YS], double, j))
00310                                         ),
00311                                 gapp->xsm->Inst->Dig2ZA ((long) round (
00312 //                                                               g_array_index (dspc->garray_probedata [PROBEDATA_ARRAY_Z0], double, j)
00313                                                                  0.
00314                                                                  + g_array_index (dspc->garray_probedata [PROBEDATA_ARRAY_ZS], double, j))
00315                                         )
00316                                 );
00317                         gapp->xsm->ActiveScan->mem2d->AttachScanEvent (se);
00318                         break;
00319                 }
00320         }
00321 
00322         // if we have attached an scan event, so fill it with data now
00323         if (se){
00324                 // find chunksize (total # data sources)
00325                 int chunksize = 0;
00326                 GPtrArray *glabarray = g_ptr_array_new ();
00327                 GPtrArray *gsymarray = g_ptr_array_new ();
00328 
00329                 for (int src=0; msklookup[src]>=0 && src < MAX_NUM_CHANNELS; ++src)
00330                         if (dspc->Source & msklookup[src]){
00331                                 g_ptr_array_add (glabarray, (gpointer) lablookup[src]);
00332                                 g_ptr_array_add (gsymarray, (gpointer) unitlookup[src]);
00333                                 ++chunksize;
00334                         }
00335                 
00336                 if (chunksize > 0 && chunksize < MAX_NUM_CHANNELS){
00337                         double dataset[MAX_NUM_CHANNELS];
00338                         ProbeEntry *pe = new ProbeEntry ("Probe", time(0), glabarray, gsymarray, chunksize);
00339                         for (int i = 0; i < dspc->current_probe_data_index; i++){
00340                                 int j=0;
00341                                 for (int src=0; msklookup[src]>=0 && src < MAX_NUM_CHANNELS; ++src){
00342                                         if (dspc->Source & msklookup[src])
00343                                                 dataset[j++] = DAC2Ulookup[src] * g_array_index (dspc->garray_probedata [expdi_lookup[src]], double, i);
00344                                 }
00345                                 pe->add ((double*)&dataset);
00346                         }
00347                         se->add_event (pe);
00348                 }
00349                 gapp->xsm->ActiveScan->view->update_events ();
00350         }
00351 
00352 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
00353 
00354 // on-the-fly visualisation graphs update
00355         for (int xmap=0; msklookup[xmap]>=0; ++xmap){
00356                 if ((dspc->XSource & msklookup[xmap]) && (dspc->Source & msklookup[xmap]))
00357                         for (int src=0; msklookup[src]>=0; ++src){
00358                                 if ((dspc->PSource & msklookup[src]) && (dspc->Source & msklookup[src])){
00359 
00360                                         UnitObj *UXaxis = new UnitObj(unitlookup[xmap], " ", "g", lablookup[xmap]);
00361                                         UnitObj *UYaxis = new UnitObj(unitlookup[src],  " ", "g", lablookup[src]);
00362                                         double xmult = DAC2Ulookup[xmap];
00363                                         double ymult = DAC2Ulookup[src];
00364                                         double xmin, xmax, x;
00365 
00366                                         // find min and max X limit
00367                                         xmin = xmax = xmult * g_array_index (dspc->garray_probedata [expdi_lookup[xmap]], double, 0);
00368                                         for(int i = 1; i < dspc->current_probe_data_index; i++){
00369                                                 x = xmult * g_array_index (dspc->garray_probedata [expdi_lookup[xmap]], double, i);
00370                                                 if (x > xmax) xmax = x;
00371                                                 if (x < xmin) xmin = x;
00372                                         }
00373 
00374                                         UXaxis->SetAlias (lablookup[xmap]);
00375                                         UYaxis->SetAlias (lablookup[src]);
00376                                         if (!pc[xmap][src]){
00377                                                 gchar   *title  = g_strdup_printf ("Vector Probe, Channel: %s", lablookup[src]);
00378                                                 pc[xmap][src] = new ProfileControl (title, 
00379                                                                                     dspc->current_probe_data_index, 
00380                                                                                     UXaxis, UYaxis, 
00381                                                                                     xmin, xmax,
00382                                                                                     lablookup[src]);
00383                                                 g_free (title);
00384                                         } else {
00385                                                 pc[xmap][src]->scan1d->mem2d->Resize (dspc->current_probe_data_index, 1);
00386                                                 pc[xmap][src]->SetXrange (xmin, xmax);
00387                                         }
00388 //                                      std::cout << "SRPCP Xlimits: " << xmin << " :: " << xmax << std::endl;
00389                         
00390                                         for(int i = 0; i < dspc->current_probe_data_index; i++){
00391                                                 pc[xmap][src]->SetPoint (i, 
00392                                                                          xmult * g_array_index (dspc->garray_probedata [expdi_lookup[xmap]], double, i),
00393                                                                          ymult * g_array_index (dspc->garray_probedata [expdi_lookup[src]], double, i));
00394                                         }
00395                                         sranger_hwi_pi.app->xsm->AddProfile (pc[xmap][src]); // give it to Surface, it takes care about removing it...
00396         
00397                                         pc[xmap][src]->drawScans ();
00398                                         pc[xmap][src]->UpdateArea ();
00399                                         pc[xmap][src]->show ();
00400 //                                      pc[xmap][src]->unref (); // nothing depends on it, so decrement refcount
00401 //                                      pc[xmap][src] = NULL; // get rid of it now
00402                                 }
00403                         }
00404         }
00405 
00406         return 0;
00407 }
00408 
00409 void DSPControl::add_user_event_now (gchar* message, gint addflag){
00410         static  UserEntry *pe=NULL;
00411 
00412         if (!gapp->xsm->ActiveScan){
00413                 pe=NULL;
00414                 return;
00415         }
00416 
00417         if (pe && addflag){
00418                 pe->add (message);
00419         } else {
00420                 static ANALOG_VALUES    dsp_analog;
00421                 lseek (sranger_hwi_hardware->dsp_alternative, sranger_hwi_hardware->magic_data.AIC_in, SRANGER_SEEK_DATA_SPACE);
00422                 read  (sranger_hwi_hardware->dsp_alternative, &dsp_analog, sizeof (dsp_analog));
00423 
00424                 // from DSP to PC
00425                 CONV_16 (dsp_analog.x_scan);
00426                 CONV_16 (dsp_analog.y_scan);
00427                 CONV_16 (dsp_analog.z_scan);
00428 
00429                 CONV_16 (dsp_analog.x_offset);
00430                 CONV_16 (dsp_analog.y_offset);
00431                 CONV_16 (dsp_analog.z_offset);
00432 
00433                 double xy[3] = {
00434                         gapp->xsm->Inst->Dig2XA ((long) round (dsp_analog.x_scan + dsp_analog.x_offset)),
00435                         gapp->xsm->Inst->Dig2YA ((long) round (dsp_analog.y_scan + dsp_analog.y_offset)),
00436                         gapp->xsm->Inst->Dig2ZA ((long) round (dsp_analog.z_scan + dsp_analog.z_offset))
00437                 };
00438 
00439                 GSList *events_close_by = gapp->xsm->ActiveScan->mem2d->ReportScanEvents (NULL, NULL, xy);
00440                 ScanEvent* se = NULL;
00441                 if (events_close_by){
00442                         if (fabs (((ScanEvent*)(events_close_by->data))->distance (xy)) < 0.1) // if closer than 0.1A, take this to add!
00443                                 se = (ScanEvent*)(events_close_by->data);
00444                         g_slist_free (events_close_by);
00445                 }
00446                 if (!se){
00447                         se = new ScanEvent (xy[0], xy[1], xy[2]);
00448                         gapp->xsm->ActiveScan->mem2d->AttachScanEvent (se);
00449                 }
00450                 UserEntry *pe = new UserEntry ("User", time(0));
00451                 pe->add (message);
00452                 se->add_event (pe);
00453         }
00454         gapp->xsm->ActiveScan->view->update_events ();
00455 }
00456 
00457 int DSPControl::Probing_save_callback( GtkWidget *widget, DSPControl *dspc){
00458         int sec;
00459 // show and update data pv graph
00460         if (!dspc->current_probe_data_index) 
00461                 return 0;
00462         
00463 
00464         double DAC2Ulookup[]={ SRV10, SRV10,  SRV10,  SRV10,  SRV10,  SRV10,   SRV10,  SRV10,
00465                                ZAngFac, BiasFac, SRV10,  SRV10,  SRV10,   SRV10,  SRV10,   
00466                                1e3/dspc->frq_ref, XAngFac, YAngFac, ZAngFac, BiasFac, PhaseFac, 1.,
00467                                0.
00468         };
00469                
00470         gchar *separator = "\t";
00471 
00472         std::ofstream f;
00473         gchar *fntmp = g_strdup_printf ("%s%03d-%s.vpdata", gapp->xsm->data.ui.basename, ++gapp->xsm->counter, "VP");
00474         
00475         f.open (fntmp);
00476 
00477         f << "# GXSM Vector Probe Data :: VPVersion=00.01 vdate=20040117" << std::endl;
00478         f << "# Date                   :: date=" << "N/A" << std::endl;
00479         f << "# FileName               :: name=" << fntmp << std::endl;
00480         f << "# GXSM-Main-Offset       :: X0=" << gapp->xsm->data.s.x0 << " Ang" <<  "  Y0=" << gapp->xsm->data.s.y0 << " Ang" << std::endl;
00481         gchar *tmp = g_strdup(gapp->xsm->data.ui.comment);
00482         
00483         f << "# GXSM-Main-Comment      :: comment=\n\"" << tmp << "\"" << std::endl;
00484         g_free (tmp);
00485         f << "# Probe Data Number      :: N=" << dspc->current_probe_data_index << std::endl;
00486         f << "# Data Sources Mask      :: Source=" << dspc->Source << std::endl;
00487         f << "# X-map Sources Mask     :: XSource=" << dspc->XSource << std::endl;
00488         f << "#C " << std::endl;
00489         f << "#C VP Channel Map and Units lookup table used:=table [## msk expdi, lab, DAC2U, unit/DAC, Active]" << std::endl;
00490 
00491         for (int i=0; msklookup[i] >= 0; ++i)
00492                 f << "# Cmap[" << i << "]" << separator 
00493                   << msklookup[i] << separator 
00494                   << expdi_lookup[i] << separator 
00495                   << lablookup[i] << separator 
00496                   << DAC2Ulookup[i] << separator 
00497                   << unitlookup[i] << "/DAC" << separator 
00498                   << (dspc->Source & msklookup[i] ? "Yes":"No") << std::endl;
00499 
00500         f << "#C " << std::endl;
00501         f << "#C Full Position Vector List at Section boundaries follows :: PositionVectorList" << std::endl;
00502         sec = 0;
00503         for (int j=0; j<dspc->current_probe_data_index; ++j){
00504                 int s = (int) g_array_index (dspc->garray_probedata [PROBEDATA_ARRAY_SEC], double, j);
00505                 if (s < (sec-1)) 
00506                         sec = s;
00507                 if (s >= sec || j == dspc->current_probe_data_index-1 || j == 0){
00508                         f << "# S[" << s << "]  :: VP[" << j <<"]=(";
00509                         sec = s+1;
00510                 } else
00511                         continue;
00512 
00513                 for (int i=13; msklookup[i]>=0; ++i){
00514                         double ymult = DAC2Ulookup[i];
00515                         if (i>13) 
00516                                 f << ", ";
00517                         f << " \"" << lablookup[i] << "\"="
00518                           << (ymult * g_array_index (dspc->garray_probedata [expdi_lookup[i]], double, j))
00519                           << " " << unitlookup[i];
00520                 }
00521                 f << ")" << std::endl;
00522         }
00523 
00524         f << "#C " << std::endl;
00525         f << "#C Data Table             :: data=" << std::endl;
00526 
00527         for (int i = -1; i < dspc->current_probe_data_index; i++){
00528                 if (i == -1)
00529                         f << "#C Index" << separator;
00530                 else
00531                         f << i << separator;
00532 
00533                 for (int xmap=0; msklookup[xmap]>=0; ++xmap)
00534                         if ((dspc->XSource & msklookup[xmap]) && (dspc->Source & msklookup[xmap])){
00535                                 double xmult = DAC2Ulookup[xmap];
00536                                 if (i == -1)
00537                                         f << "\"" << lablookup[xmap] << " (" << unitlookup[xmap] << ")\"" << separator;
00538                                 else
00539                                         f << (xmult * g_array_index (dspc->garray_probedata [expdi_lookup[xmap]], double, i)) << separator;
00540                         }
00541 
00542                 for (int src=0; msklookup[src]>=0; ++src)
00543                         if (dspc->Source & msklookup[src]){
00544                                 double ymult = DAC2Ulookup[src];
00545                                 if (i == -1)
00546                                         f << "\"" << lablookup[src] << " (" << unitlookup[src] << ")\"" << separator;
00547                                 else
00548                                         f << (ymult * g_array_index (dspc->garray_probedata [expdi_lookup[src]], double, i)) << separator;
00549                         }
00550 
00551                 f << std::endl;
00552         }
00553         f << "#C " << std::endl;
00554         f << "#C END." << std::endl;
00555         f.close ();
00556 
00557         // update counter on main window!
00558         gapp->spm_update_all();
00559         gapp->SetStatus(N_("Saved VP data: "), fntmp);
00560         gchar *bbt = g_strdup_printf ("Save now - last: %s", fntmp);
00561         gtk_button_set_label (GTK_BUTTON (dspc->save_button), bbt);
00562         g_free (bbt);
00563         g_free (fntmp);
00564 
00565         
00566         return 0;
00567 }
00568 
00569 
00570 
00571 #define DEFAULT_PROBE_LEN 256 // can increase automatically, just more efficient
00572 
00573 void DSPControl::push_probedata_arrays (){
00574         GArray **garr = new GArray*[NUM_PROBEDATA_ARRAYS];
00575         for (int i=0; i<NUM_PROBEDATA_ARRAYS; ++i){
00576                 garr [i] = garray_probedata [i];
00577                 garray_probedata [i] = g_array_sized_new (FALSE, TRUE, sizeof (double), DEFAULT_PROBE_LEN); // preallocated, can increase
00578         }
00579         probedata_list =  g_slist_prepend (probedata_list, garr); // push on list
00580         last_probe_data_index = current_probe_data_index;
00581 
00582         ++num_probe_events;
00583 }
00584 
00585 // return last dataset and removed it from list, does not touch data itself
00586 GArray** DSPControl::pop_probedata_arrays (){
00587         if (probedata_list){
00588                 GSList *last = g_slist_last (probedata_list);
00589                 if (last){
00590                         GArray **garr = (GArray **) (last->data);
00591                         probedata_list = g_slist_delete_link (probedata_list, last);
00592                         return garr;
00593                 }
00594         }
00595         return NULL;
00596 }
00597 
00598 void DSPControl::free_probedata_array_set (GArray** garr, DSPControl *dc){
00599         for (int i=0; i<NUM_PROBEDATA_ARRAYS; ++i)
00600                 g_array_free (garr[i], TRUE);
00601 }
00602 
00603 void DSPControl::free_probedata_arrays (){
00604         if (!probedata_list) 
00605                 return;
00606         g_slist_foreach (probedata_list, (GFunc) DSPControl::free_probedata_array_set, this);
00607         g_slist_free (probedata_list);
00608         probedata_list = NULL;  
00609         num_probe_events = 0;
00610 }
00611 
00612 void DSPControl::init_probedata_arrays (){
00613         for (int i=0; i<NUM_PROBEDATA_ARRAYS; ++i){
00614                 if (!garray_probedata[i]){
00615                         garray_probedata [i] = g_array_sized_new (FALSE, TRUE, sizeof (double), DEFAULT_PROBE_LEN); // preallocated, can increase
00616                 }
00617                 else
00618                         g_array_set_size (garray_probedata [i], 0);
00619         }
00620         current_probe_data_index = 0;
00621         nun_valid_data_sections = 0;
00622 }
00623 
00624 void DSPControl::add_probedata(double data[13]){ 
00625         int i,j;
00626         for (i = PROBEDATA_ARRAY_AIC5OUT_ZMON, j=0; i <= PROBEDATA_ARRAY_LCK2B; ++i, ++j){
00627                 if (i == PROBEDATA_ARRAY_AIC6){
00628                         double dummy=0.;
00629                         // skip AIC6,7
00630                         g_array_append_val (garray_probedata[i++], dummy);
00631                         g_array_append_val (garray_probedata[i++], dummy);
00632                 }
00633                 g_array_append_val (garray_probedata[i], data[j]);
00634         }
00635 
00636 #ifdef TTY_DEBUG
00637         std::cout << "pvd[" << current_probe_data_index << "][M[zu]AIC[50123467]L[120]]: ";
00638         for (i = PROBEDATA_ARRAY_AIC5OUT_ZMON, j=0; i <= PROBEDATA_ARRAY_LCK2B; ++i, ++j)
00639                 std::cout << data[j] << ", ";
00640         std::cout << std::endl;
00641 #endif
00642 
00643         current_probe_data_index++;     
00644 }
00645 
00646 void DSPControl::add_probevector(){ 
00647         int i,j, sec;
00648         double ds, val, multi, fixptm;
00649         sec =  (int) (ds = g_array_index (garray_probedata [PROBEDATA_ARRAY_SEC], double, current_probe_data_index-1));
00650         g_array_append_val (garray_probedata [PROBEDATA_ARRAY_SEC], ds);
00651         g_array_append_val (garray_probedata [PROBEDATA_ARRAY_INDEX], current_probe_data_index);
00652         multi = dsp_vector_list[sec].dnx + 1;
00653         fixptm = 1./(1<<16);
00654 
00655 #ifdef TTY_DEBUG
00656         std::cout << "+pv[" << current_probe_data_index << "] (m=" << multi << "): ";
00657 #endif
00658         for (i = PROBEDATA_ARRAY_TIME, j=0; i < PROBEDATA_ARRAY_SEC; ++i, ++j){
00659                 val = g_array_index (garray_probedata[i], double, current_probe_data_index-1);
00660                 switch (i){
00661                 case PROBEDATA_ARRAY_TIME:
00662                         val += multi;
00663                         break;
00664                 case PROBEDATA_ARRAY_X0:
00665                         val += dsp_vector_list[sec].f_dx0*multi*fixptm;
00666                         break;
00667                 case PROBEDATA_ARRAY_Y0:
00668                         val += dsp_vector_list[sec].f_dy0*multi*fixptm;
00669                         break;
00670                 case PROBEDATA_ARRAY_PHI:
00671                         val += dsp_vector_list[sec].f_dphi*multi*fixptm;
00672                         break;
00673                 case PROBEDATA_ARRAY_XS:
00674                         val -= dsp_vector_list[sec].f_dx*multi*fixptm;
00675                         break;
00676                 case PROBEDATA_ARRAY_YS:
00677                         val -= dsp_vector_list[sec].f_dy*multi*fixptm;
00678                         break;
00679                 case PROBEDATA_ARRAY_ZS:
00680                         val -= dsp_vector_list[sec].f_dz*multi*fixptm;
00681                         break;
00682                 case PROBEDATA_ARRAY_U:
00683                         val += dsp_vector_list[sec].f_du*multi*fixptm;
00684                         break;
00685                 default:
00686                         break; // error!!!!
00687                 }
00688                 g_array_append_val (garray_probedata[i], val);
00689 #ifdef TTY_DEBUG
00690                 std::cout << val << ", ";
00691 #endif
00692         }
00693         ++nun_valid_data_sections;
00694 
00695 #ifdef TTY_DEBUG
00696         std::cout << sec << std::endl;
00697 #endif
00698 }
00699 
00700 void DSPControl::set_probevector(double pv[9]){ 
00701         int i,j;
00702         g_array_append_val (garray_probedata [PROBEDATA_ARRAY_INDEX], current_probe_data_index);
00703         for (i = PROBEDATA_ARRAY_TIME, j=0; i <= PROBEDATA_ARRAY_SEC; ++i, ++j)
00704                 g_array_append_val (garray_probedata[i], pv[j]);
00705 
00706         
00707 #ifdef TTY_DEBUG
00708         std::cout << "pv[" << current_probe_data_index << "]_[txyz0xyzSus]set: ";
00709         for (i = PROBEDATA_ARRAY_TIME, j=0; i <= PROBEDATA_ARRAY_SEC; ++i, ++j)
00710                 std::cout << pv[j] << ", ";
00711         std::cout << std::endl;
00712 #endif
00713 }
00714 
00715 

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