monitor.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 #include <iostream>
00029 #include <time.h>
00030 #include "monitor.h"
00031 #include "meldungen.h"
00032 #include "unit.h"
00033 #include "xsmdebug.h"
00034 
00035 Monitor::Monitor(gchar *name){
00036   dt=10.0;
00037 
00038   if(name)
00039     logname = g_strdup(name);
00040   else{
00041     char buf[64];
00042     time_t t;
00043     time(&t);               // 012345678901234567890123456789
00044     strcpy(buf, ctime(&t)); // Thu Jun 25 12:44:55 1998
00045     buf[7]=0; buf[24]=0;
00046     logname = g_strdup_printf("Ev_%3s%4s.log", &buf[4], &buf[20]);
00047     XSM_DEBUG (DBG_L2, "LogName:>" << logname << "<" );
00048   }
00049 
00050   for(int i=0; i < MAXMONITORFIELDS; ++i)
00051     Fields[i] = NULL;
00052 
00053   LogEvent("Monitor", "startup");
00054 }
00055 
00056 Monitor::~Monitor(){
00057   if(logname)
00058     g_free(logname);
00059   for(gchar **field = Fields; *field; ++field)
00060       g_free(*field);
00061 }
00062 
00063 void Monitor::SetLogName(char *name){
00064   if(logname)
00065     g_free(logname);
00066   logname = g_strdup(name);
00067 }
00068 
00069 gint Monitor::Load(gchar *fname){
00070   std::ifstream f;
00071   return 0;
00072 }
00073 
00074 gint Monitor::Save(gchar *fname){
00075   std::ofstream f;
00076   time_t t;
00077   time(&t); 
00078 
00079   f.open(fname, std::ios::out | std::ios::trunc);
00080   if(!f.good()){
00081     return 1;
00082   }
00083   f << "# Monitor Data\n" << "# Date: " << ctime(&t) << "#" << fname << "\n";
00084   
00085   //  foralllines...
00086   f << "\n";
00087 
00088   f.close();
00089   return 0;
00090 }
00091 
00092 void Monitor::Messung(float val, gchar *txt){
00093   /*
00094   char buf[256];
00095   time_t t;
00096   time(&t);               // 012345678901234567890123456789
00097   strcpy(buf, ctime(&t)); // Thu Jun 25 12:44:55 1998
00098   buf[24]=0;
00099  
00100   strcpy(Field[0], buf);
00101   sprintf(Field[1], "%6.0f  ", val);
00102   if(!nlast)
00103     f0=fn;
00104   sprintf(Field[2], "------  ");
00105   sprintf(Field[3], "------  ");
00106   if(txt)
00107     sprintf(Field[LastField-1], "*X: %3d %s", nlast, txt);
00108   else
00109     sprintf(Field[LastField-1], "*X: %3d", nlast);
00110 
00111   AppLine();
00112   */
00113 }
00114 
00115 void Monitor::LogEvent(gchar *Action, gchar *Entry){
00116   PutEvent(Action, Entry);
00117 }
00118 
00119 void Monitor::PutEvent(gchar *Action, gchar *Entry){
00120   //  return;
00121   for(gchar **field = Fields; *field; ++field){
00122     g_free(*field);
00123     *field=NULL;
00124   }
00125   time_t t;
00126   time(&t);
00127   Fields[0] = g_strdup(ctime(&t)); Fields[0][24]=' ';
00128   Fields[1] = g_strdup_printf("%10s : ",Action);
00129   Fields[2] = g_strdup_printf("%30s : ",Entry);
00130   Fields[3] = g_strdup_printf("%10.6f ",0.0);
00131   Fields[4] = g_strdup_printf("%10.6f ",0.0);
00132   Fields[5] = g_strdup_printf("%10.6f ",0.0);
00133   Fields[6] = NULL;
00134 
00135   AppLine();
00136 }
00137 
00138 gint Monitor::AppLine(){
00139   // Autologging
00140   if(logname){
00141     std::ofstream f;
00142     f.open(logname, std::ios::out | std::ios::app);
00143     if(!f.good()){
00144       std::cerr << ERR_SORRY << "\n" << ERR_FILEWRITE << ": " << logname << std::endl;
00145       return 1;
00146     }
00147     
00148     for(gchar **field = Fields; *field; ++field)
00149       f << *field;
00150     f << "\n";
00151     f.close();
00152   }
00153   return 0;
00154 }
00155 
00156 // END

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