⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prcgnucap.cpp

📁 gspiceui电子CAD仿真程序.用于电路参数模拟仿真
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  }  if( roSim.roasGetSimCmds( ).IsEmpty( ) ) return( FALSE );  return( TRUE );}//*****************************************************************************// Create a list of arguments for the Spice PRINT command based on the test// components and test nodes specified in a Simulation object. A prefix may be// specified which is prepended to each argument in the list.//// Argument List://   roSim     - The Simulation object//   rosPrefix - The prefix to be prepended to each argument//// Return Values://   Success - A list of correctly formatted arguments//   Failure - An empty stringwxString & PrcGnuCap::rosMakeArgsPR( Simulation & roSim, wxString & rosPrefix ){  static  wxString  osArgs;  wxChar  oc1;  size_t  szt1;  osArgs.Empty( );  // Add any components to derivation list for this parameter  for( szt1=0; szt1<roSim.roasGetTstCpnts( ).GetCount( ); szt1++ )    osArgs << wxT(' ') << rosPrefix << roSim.roasGetTstCpnts( ).Item( szt1 )           << wxT(')');  // Add any nodes to derivation list for voltage only  for( oc1=0, szt1=0; szt1<rosPrefix.Length( ); szt1++ )  {    oc1 = rosPrefix.GetChar( szt1 );    if( ! wxIsspace( oc1 ) ) break;  }  if( oc1==wxT('v') || oc1==wxT('V') )  {    for( szt1=0; szt1<roSim.roasGetTstNodes( ).GetCount( ); szt1++ )      osArgs << wxT(' ') << rosPrefix << roSim.roasGetTstNodes( ).Item( szt1 )             << wxT(')');  }    return( osArgs );}//*****************************************************************************// Check / format the component lines in the Simulation object so that they are// compatible with GnuCAP.//// Argument List://   roasCpnts - The list of component lines//// Return Value://   TRUE  - Success//   FALSE - Failurebool  PrcGnuCap::bFmtCpnts( wxArrayString & roasCpnts ){  wxStringTokenizer  oStrTok;  wxString  os1, osNodeC;  size_t  szt1;  for( szt1=0; szt1<roasCpnts.GetCount( ); szt1++ )  {    oStrTok.SetString( roasCpnts[ szt1 ] );    os1 = oStrTok.GetNextToken( );    if( wxToupper( os1.GetChar( 0 ) ) != wxT('Q') ) continue;    if( oStrTok.CountTokens( ) != 4 )               continue;    osNodeC = oStrTok.GetNextToken( );    // Add substrate node to BJT definitions    os1 << wxT(' ') << osNodeC << wxT(' ') << oStrTok.GetNextToken( )        << wxT(' ') << oStrTok.GetNextToken( ) << wxT(' ') << osNodeC        << wxT(' ') << oStrTok.GetNextToken( );    roasCpnts.RemoveAt( szt1 );    roasCpnts.Insert( os1, szt1 );  }  return( TRUE );}//*****************************************************************************// Format the results file eg. get rid of simulation engine banner message.//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PrcGnuCap::bFmtResultsFile( void ){  wxString  os1, os2;  size_t    szt1, szt2;  wxChar    oc1;  // Attempt to open the results file  wxTextFile  oFile( m_oFnmResults.GetFullPath( ) );  if( ! oFile.Exists( ) ) return( FALSE );  if( ! oFile.Open( ) )   return( FALSE );  // Find the beginning of the data area (ie. the last line beginning with '#')  for( szt1=szt2=0; szt1<oFile.GetLineCount( ); szt1++ )  {    os1 = oFile.GetLine( szt1 );    if( ! os1.IsEmpty( ) )      if( os1.GetChar( 0 ) == wxT('#') )        szt2 = szt1;  }  // Delete the banner  for( szt1=0; szt1<szt2; szt1++ ) oFile.RemoveLine( 0 );  // Insert the input variable name into the column labels  // Format the column header line  os1 = oFile.GetFirstLine( );  if( ! bFmtResultsHead( os1 ) )    { oFile.Close( ); return( FALSE ); }  oFile.GetFirstLine( ) = os1;  // 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; !oFile.Eof( ) && szt1<oFile.GetLineCount( ); szt1++ )  {    os1 = oFile.GetLine( szt1 );    if( os1.Length( ) <= 1 )    { // Delete empty lines      oFile.RemoveLine( szt1 );      szt1--;      continue;    }    oc1 = os1.GetChar( 1 );    if( ! wxIsdigit( oc1 ) )    { // Delete non-data lines      oFile.RemoveLine( szt1 );      szt1--;      continue;    }  }  // Format data lines  for( szt1=1; szt1<oFile.GetLineCount( ); szt1++ )  {    os1 = oFile.GetLine( szt1 );    bFmtResultsLine( os1 );    oFile.GetLine( szt1 ) = os1;  }  // Need last line to end with a '\n' or text control will not load it  if( oFile.GetLastLine( ).Last( ) != wxT('\n') )    oFile.GetLastLine( ) << wxT('\n');  oFile.Write( ); // Save the changes to disk  oFile.Close( ); // Close the file  return( TRUE );}//*****************************************************************************// Format the column header from the results file.//// Argument List://   rosLine - The column header to be formatted//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PrcGnuCap::bFmtResultsHead( wxString & rosLine ){  wxStringTokenizer  oStrTok;  wxString  os1;  int  i1;  // Tokenize the string  oStrTok.SetString( rosLine );  if( oStrTok.CountTokens( ) < 1 ) return( FALSE );  // Replace the first field if m_osInput is not empty  os1 = oStrTok.GetNextToken( );  if( m_osInput.IsEmpty( ) ) rosLine = os1;  else                       rosLine = (wxString) wxT('#') + m_osInput;  // Format each field  while( oStrTok.HasMoreTokens( ) )  {    // Place a new field at every 12 columns    i1 = 12 - (rosLine.Length( ) % 12);    rosLine.Append( wxT(' '), i1 );    rosLine << oStrTok.GetNextToken( );  }  return( TRUE );}//*****************************************************************************// Format a data line from the results file.//// Argument List://   rosLine - The data line to be formatted//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PrcGnuCap::bFmtResultsLine( wxString & rosLine ){  wxStringTokenizer  oStrTok;  wxString  os1;  double    f1;  int       i1;  // Tokenize the string  oStrTok.SetString( rosLine );  if( oStrTok.CountTokens( ) < 1 ) return( FALSE );  // Format each field  rosLine.Empty( );  while( oStrTok.HasMoreTokens( ) )  {    if( rosLine.Length( ) > 0 )    { // Place a new field at every 12 columns      i1 = 12 - (rosLine.Length( ) % 12) - 1;      rosLine.Append( wxT(' '), i1 );    }    os1 = oStrTok.GetNextToken( );    if( ! ConvertType::bStrToFlt( os1, &f1 ) ) f1  =      -9.999e+99;    if( ! ConvertType::bFltToStr( f1, os1 ) )  os1 = wxT("-9.999e+99");    rosLine << os1;  }  return( TRUE );}//*****************************************************************************// Parse the simulation commands strings found in a Simulation object and load// the values back into the Simulation object.//// Arguments://   roSim - The simulation object//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PrcGnuCap::bParseSim( Simulation & roSim ){  const wxArrayString & roasCmds=roSim.roasGetSimCmds( );  wxString  os1;  size_t    szt1;  // Set the default state of some of the simulation object attributes  roSim.bSetOutPar( Simulation::ePAR_VLT,   TRUE );  roSim.bSetOutCpx( Simulation::eCPX_MAG,   TRUE );  roSim.bSetOutCpx( Simulation::eCPX_MAGDB, TRUE );  // Go through the simulation commands and attempt to parse them  for( szt1=0; szt1<roasCmds.GetCount( ); szt1++ )  {    os1 = roasCmds.Item( szt1 );    if( bParseCmdOPT( os1, roSim ) ) continue;    if( bParseCmdGEN( os1, roSim ) ) continue;    if( bParseCmdOP ( os1, roSim ) ) continue;    if( bParseCmdDC ( os1, roSim ) ) continue;    if( bParseCmdAC ( os1, roSim ) ) continue;    if( bParseCmdTR ( os1, roSim ) ) continue;    if( bParseCmdFO ( os1, roSim ) ) continue;    if( bParseCmdPR ( os1, roSim ) ) continue;  }  return( TRUE );}//*****************************************************************************// Create the simulation commands from the values found in a Simulation object// and load the command string back into the Simulation object.//// Arguments://   roSim - The simulation object//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PrcGnuCap::bMakeSim( Simulation & roSim ){  wxFileName  ofn1;  wxString  os1;  int  i1;  // Clear error attributes  m_osError.Empty( );  // Only execute simulation if it isn't already running  if( bIsExec( ) )    { m_osError = wxT("Simulation already running");         return( FALSE ); }  // Check / format lines for compatibility with GnuCAP  if( ! bFmtCpnts( roSim.m_oasCpnts ) )    { m_osError = wxT("Incompatibility with simulator");     return( FALSE ); }  // Create the simulator commands  if( ! bMakeCmds( roSim ) )    { m_osError = wxT("Couldn't create simulator commands"); return( FALSE ); }  // Save circuit description and SPICE commands to file  ofn1 = roSim.roGetLoadFile( );  if( ofn1.GetFullName( ).Find( wxT(".gspiceui.") ) == -1 )    ofn1.SetName( ofn1.GetName( ) + wxT(".gspiceui") );  if( ! roSim.bSaveFile( ofn1.GetFullPath( ) ) )    { m_osError = wxT("Simulation couldn't be saved to file"); return(FALSE); }  // Construct the command line to execute the simulation  os1 = wxT("-b ") + roSim.roGetSaveFile( ).GetFullPath( );  if( ! bSetArgLst( os1.c_str( ) ) )    { m_osError = wxT("Couldn't set argument list");         return( FALSE ); }  // Create the results file name  os1 = roSim.roGetLoadFile( ).GetPath( ) + wxT('/')      + roSim.roGetLoadFile( ).GetName( );  i1 = os1.Find( wxT(".gspiceui") );  if( i1 > 0 ) os1 = os1.Truncate( (size_t) i1 );  os1 << wxT('.') << roGetBinary( ).GetName( );  switch( roSim.eGetAnaType( ) )  {    case Simulation::eANA_OP: os1 << wxT(".op"); break;    case Simulation::eANA_DC: os1 << wxT(".dc"); break;    case Simulation::eANA_AC: os1 << wxT(".ac"); break;    case Simulation::eANA_TR: os1 << wxT(".tr"); break;    case Simulation::eANA_FO: os1 << wxT(".fo"); break;    default: return( FALSE );  }  if( ! bSetResultsFile( os1.c_str( ) ) )    { m_osError = wxT("Couldn't set results file name");     return( FALSE ); }  return( TRUE );}//*****************************************************************************// Check for error messages in the simulator output ???//  bData = FALSE;//  for( os1=oFileCct.GetFirstLine(); !oFileCct.Eof(); os1=oFileCct.GetNextLine())//  {//    if( os1.Length( ) <= 1 ) continue;//    oc1 = os1.GetChar( 0 );//    if( bData )//    { // Look for simulator error messages//      if( !wxIsdigit( oc1 ) && oc1!=wxT(' ') && oc1!=wxT('-') )//      { // Simulation error message found//        osError = wxT("Error/s encountered running simulation");//        break;//      }//    }//    else//    { // Look for the beginning of the simulation data//      if( oc1 == wxT('#') ) bData = TRUE;//    }//  }//*****************************************************************************// Execute a simulation.//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PrcGnuCap::bExec( void ){  wxString  os1, os2;  // Execute the simulation  if( ! PrcBase::bExec( ) )      return( FALSE );  // Save the simulation results to the log file  os1 = roGetLogFile( ).GetFullPath( );  if( ! bSaveOutput( os1 ) )     return( FALSE );  // Copy the log file to the results file  os2 = roGetResultsFile( ).GetFullPath( );  if( ! wxCopyFile( os1, os2 ) ) return( FALSE );  // Format the simulation results  if( ! bFmtResultsFile( ) )     return( FALSE );  return( TRUE );}//*****************************************************************************

⌨️ 快捷键说明

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