Blame view

GUI/SW2/SRC/src/process/PrcGaw.cpp 7.78 KB
886c558b   Steve Greedy   SACAMOS Public Re...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
//**************************************************************************************************
//                                           PrcGaw.cpp                                            *
//                                          ------------                                           *
// Started     : 2008-01-10                                                                        *
// Last Update : 2016-10-23                                                                        *
// Copyright   : (C) 2008-2016 MSWaters                                                            *
//**************************************************************************************************

//**************************************************************************************************
//                                                                                                 *
//      This program is free software; you can redistribute it and/or modify it under the          *
//      terms of the GNU General Public License as published by the Free Software Foundation;      *
//      either version 3 of the License, or (at your option) any later version.                    *
//                                                                                                 *
//**************************************************************************************************

#include "PrcGaw.hpp"

//**************************************************************************************************
// Constructor.

PrcGaw::PrcGaw( void ) : PrcBase( wxPROCESS_REDIRECT )
{
  // Initialize the object attributes
  m_oNameResults.Clear( );
  m_oNameLog    .Clear( );

  // Attempt to set and find the Gaw binary
  bSetBinFile( BIN_GAW );
}

//**************************************************************************************************
// Destructor.

PrcGaw::~PrcGaw( )
{
}

//**************************************************************************************************
// Set the simulation results file name.
//
// Argument List:
//   psFileName - a string containing the full path and file name
//
// Return Values:
//   true  - Success
//   false - Failure

bool  PrcGaw::bSetResultsFile( const wxString & rosFileName )
{
  wxFileName  ofn1;

  ofn1 = rosFileName;
  if( ofn1.GetPath( ).IsEmpty( ) ) ofn1.SetPath( wxT(".") );

  if( ! ofn1.IsOk( )       ) return( false );
  if( ! ofn1.FileExists( ) ) return( false );

  m_oNameResults = ofn1;

  return( true );
}

//**************************************************************************************************
// Filter the results file so that the data viewer utility is happy with it.
//
// There are several things that a data viewer can object to :
//  - gwave doesn't like the GNU-Cap banner at the start to the results file, so it's removed here.
//  - gwave doesn't like error messages interspersed with the lines of data, so they are removed
//    here.
//  - For good measure lines and fields are also formatted.
//
// Return Values:
//   true  - Success
//   false - Failure

bool  PrcGaw::bFilterFile( void )
{
  wxString  os1;
  size_t    sz1, sz2;
  wxChar    oc1;
  bool      bRtn=true;

  // Attempt to open the results file
  wxTextFile  oFileCct( m_oNameResults.GetFullPath( ) );
  if( ! oFileCct.Exists( ) ) return( false );
  if( ! oFileCct.Open( ) )   return( false );

  // Has this file been formatted already?
  if( oFileCct.GetFirstLine( ).GetChar( 0 ) == wxT('#') ) return( true );

  // Find the beginning of the data area (ie. the last line beginning with '#')
  for( sz1=sz2=0; sz1<oFileCct.GetLineCount( ); sz1++ )
  {
    os1 = oFileCct.GetLine( sz1 );
    if( ! os1.IsEmpty( ) )
      if( os1.GetChar( 0 ) == wxT('#') )
        sz2 = sz1;
  }

  // Delete the banner
  for( sz1=0; sz1<sz2; sz1++ ) oFileCct.RemoveLine( 0 );
  if( oFileCct.GetLineCount( ) <= 1 ) return( false );

  // Delete any simulator error messages eg. "open circuit: internal node 3"
  // (All lines should start with a digit except for the first)
  for( sz1=1; !oFileCct.Eof( ) && sz1<oFileCct.GetLineCount( ); sz1++ )
  {
    os1 = oFileCct.GetLine( sz1 );
    if( os1.Length( ) <= 1 )
    { // Delete empty lines
      oFileCct.RemoveLine( sz1 );
      sz1--;
      continue;
    }
    oc1 = os1.GetChar( 1 );
    if( ! wxIsdigit( oc1 ) )
    { // Delete non-data lines
      oFileCct.RemoveLine( sz1 );
      sz1--;
      continue;
    }
  }

  // Format each data line in the file
//  for( sz1=1; sz1<oFileCct.GetLineCount( ); sz1++ )
//    if( ! bFormatLine( oFileCct.GetLine( sz1 ) ) )
//      bRtn = false;

  oFileCct.Write( ); // Save the changes to disk
  oFileCct.Close( ); // Close the file

  return( bRtn );
}

//**************************************************************************************************
// Reformat the lines from the results file.
//
// Argument List:
//   rosLine - The line to be formatted
//
// Return Values:
//   true  - Success
//   false - Failure
/*
bool  PrcGaw::bFormatLine( wxString & rosLine )
{
  wxStringTokenizer  ostk1;
  wxString  os1, os2;

  // Check for an empty string
  if( rosLine.IsEmpty( ) )         return( false );

  // Break the line into fields
  ostk1.SetString( rosLine );
  if( ostk1.CountTokens( ) < 2 ) return( false );

  // Reformat the line
  while( ostk1.HasMoreTokens( ) )
  {
    os1 = ostk1.GetNextToken( );
    if( ! bFormatField( os1 ) )    return( false );
    if( os2.IsEmpty( ) ) os2 = os1;
    else                 os2 << wxT("     ") << os1;
  }

  rosLine = os2;

  return( true );
}
*/
//**************************************************************************************************
// Reformat the fields from the results file.
//
// Argument List:
//   rosField - The field to be formatted
//
// Return Values:
//   true  - Success
//   false - Failure
/*
bool  PrcGaw::bFormatField( wxString & rosField )
{
  wxString  os1;
  wxChar    oc1;
  size_t    szt1;

  // Check for an empty string
  if( rosField.IsEmpty( ) ) return( false );

  // Extract the value and the units
  oc1 = 0;
  for( szt1=0; szt1<rosField.Length( ); szt1++ )
  {
    oc1 = rosField.GetChar( szt1 );
    if( oc1!=wxT('-') && !wxIsdigit( oc1 ) && oc1!=wxT('.') ) break;
    else oc1 = 0;
  }
  os1 = rosField.Left( szt1 );

  // Reformat the field
  switch( oc1 )
  {
    case wxT('M'): os1 << wxT("E+06"); break;
    case wxT('K'): os1 << wxT("E+03"); break;
    case wxT('m'): os1 << wxT("E-03"); break;
    case wxT('u'): os1 << wxT("E-06"); break;
    case wxT('n'): os1 << wxT("E-09"); break;
    case wxT('p'): os1 << wxT("E-12"); break;
    case 0: break;
    default : return( false );
  }

  rosField = os1;

  return( true );
}
*/
//**************************************************************************************************
// View the results of a simulation.
//
// (Eg. using the following: gaw ../sch/test-amp1.gnucap.dc)
//
// Return Values:
//   true  - Success
//   false - Failure

bool  PrcGaw::bExec( void )
{
  wxString  os1;

  // Test file names needed by this function
  if( ! bBinExists( ) )                               return( false );
  if( !m_oNameResults.FileExists( ) || !m_oNameResults.IsOk( ) )
  {
    os1 = m_oNameResults.GetFullPath( );
    m_osErrMsg.Empty( );
    if( os1.IsEmpty( ) ) m_osErrMsg << wxT("The results file has not been set.");
    else                 m_osErrMsg << wxT("The results file doesn't exist : ") << os1;
    return( false );
  }

  // Append input file name to argument list
  if( ! bSetArgLst( m_oNameResults.GetFullPath( ) ) ) return( false );

  // Filter the file before passing it to the waveform viewer process
  if( ! bFilterFile( ) )                              return( false );

  // Execute the process
  if( ! PrcBase::bExecAsync( ) )                      return( false );

  return( true );
}

//**************************************************************************************************