prcgwave.cpp

来自「gspiceui电子CAD仿真程序.用于电路参数模拟仿真」· C++ 代码 · 共 255 行

CPP
255
字号
//*****************************************************************************//                                  PrcGWave.cpp                              *//                                 --------------                             *//  Started     : 29/03/2004                                                  *//  Last Update : 09/06/2005                                                  *//  Copyright   : (C) 2004 by MSWaters                                        *//  Email       : M.Waters@bom.gov.au                                         *//*****************************************************************************//*****************************************************************************//                                                                            *//    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 2 of the License, or       *//    (at your option) any later version.                                     *//                                                                            *//*****************************************************************************#include "PrcGWave.hpp"//*****************************************************************************// Constructor.PrcGWave::PrcGWave( void ) : PrcBase( wxPROCESS_DEFAULT ){  // Initialize the object attributes  m_oFnmResults.Clear( );  m_oFnmLog    .Clear( );  // Attempt to set and find the gnetlist binary  bSetBinary( wxT("gwave") );}//*****************************************************************************// Destructor.PrcGWave::~PrcGWave( ){}//*****************************************************************************// Set the simulation results file name.//// Argument List://   psFileName - a string containing the full path and file name//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PrcGWave::bSetResults( const wxString & rosFileName ){  wxFileName  oFName;  oFName = rosFileName;  if( oFName.GetPath( ).IsEmpty( ) ) oFName.SetPath( wxT(".") );  if( ! oFName.IsOk( )       ) return( FALSE );  if( ! oFName.FileExists( ) ) return( FALSE );  m_oFnmResults = oFName;  return( TRUE );}//*****************************************************************************// Delete the simulator banner message at the top of the results file.// (This is a bodge added temporarily so that GWave can be used as the results// plotter. GWave doesn't like the GnuCap banner at the start to the file so// remove it. 29/03/2004 ???)//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PrcGWave::bFormatFile( void ){  wxString  os1;  size_t    szt1, szt2;  wxChar    oc1;  bool      bRtn=TRUE;  // Attempt to open the results file  wxTextFile  oFileCct( m_oFnmResults.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( szt1=szt2=0; szt1<oFileCct.GetLineCount( ); szt1++ )  {    os1 = oFileCct.GetLine( szt1 );    if( ! os1.IsEmpty( ) )      if( os1.GetChar( 0 ) == wxT('#') )        szt2 = szt1;  }  // Delete the banner  for( szt1=0; szt1<szt2; szt1++ ) 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( szt1=1; !oFileCct.Eof( ) && szt1<oFileCct.GetLineCount( ); szt1++ )  {    os1 = oFileCct.GetLine( szt1 );    if( os1.Length( ) <= 1 )    { // Delete empty lines      oFileCct.RemoveLine( szt1 );      szt1--;      continue;    }    oc1 = os1.GetChar( 1 );    if( ! wxIsdigit( oc1 ) )    { // Delete non-data lines      oFileCct.RemoveLine( szt1 );      szt1--;      continue;    }  }  // Format each data line in the file  for( szt1=1; szt1<oFileCct.GetLineCount( ); szt1++ )    if( ! bFormatLine( oFileCct.GetLine( szt1 ) ) )      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 - Failurebool  PrcGWave::bFormatLine( wxString & rosLine ){  wxStringTokenizer  oStrTok;  wxString  os1, os2;  // Check for an empty string  if( rosLine.IsEmpty( ) )         return( FALSE );  // Break the line into fields  oStrTok.SetString( rosLine );  if( oStrTok.CountTokens( ) < 2 ) return( FALSE );  // Reformat the line  for( ; oStrTok.HasMoreTokens( ); )  {    os1 = oStrTok.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 - Failurebool  PrcGWave::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: gwave ../sch/test-amp1.gnucap.dc)//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PrcGWave::bExec( void ){  wxString  os1;  // Test file names needed by this function  if( ! bBinExists( ) )                              return( FALSE );  if( !m_oFnmResults.FileExists( ) || !m_oFnmResults.IsOk( ) )  {    os1  = m_oFnmResults.GetFullPath( );    m_osError.Empty( );    if( os1.IsEmpty( ) )         m_osError << wxT("The results file has not been set.");    else m_osError << wxT("The results file doesn't exist : ") << os1;     return( FALSE );  }  // Append input file name to argument list  if( ! bSetArgLst( m_oFnmResults.GetFullPath( ) ) ) return( FALSE );  // Format the file before passing it to the plotter process  if( ! bFormatFile( ) )                             return( FALSE );  // Execute the process  if( ! PrcBase::bExec( ) )                          return( FALSE );  return( TRUE );}//*****************************************************************************

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?