Tcl SpiceGenTcl package (v0.71)

::SpiceGenTcl::Ngspice::SimulatorsTop, Main, Index

ClassesTop, Main, Index

Batch [::SpiceGenTcl::Ngspice::Simulators]Top, Main, Index

Method summary
constructorConstructor for the class.
configureConfigure properties.
getLogSee ::SpiceGenTcl::Simulator.getLog
readDataReads raw data file, create RawFile object and return it's reference name.
readLogReads log file of last simulation and save it's content to Log variable.
runSee ::SpiceGenTcl::Simulator.run
runAndReadRuns netlist circuit file.
Properties
-dataReadable, writable.
-logReadable, writable.
-nameReadable, writable.
-runlocationReadable, writable.
Superclasses

::SpiceGenTcl::Simulator

Subclasses

BatchLiveLog

constructor [::SpiceGenTcl::Ngspice::Simulators::Batch]Batch, Top, Main, Index

Creates batch ngspice simulator that can be attached to top-level Circuit.

Batch create OBJNAME ?args?
Batch new ?args?
Parameters
nameName of simulator object.
runLocationLocation at which input netlist is stored and all output files will be saved, default is current directory.
method constructor {args} {

    # Creates batch ngspice simulator that can be attached to top-level Circuit.
    #  name - name of simulator object
    #  runLocation - location at which input netlist is stored and all output files will be saved,
    #   default is current directory
    argparse -help {Creates batch ngspice simulator that can be attached to top-level 'Circuit'} {
        {name -help {Name of simulator object}}
        {runLocation -optional -default . -help {Location at which input netlist is stored and all output files will be saved}}
    }
    my configure -name $name
    my variable Command
    global tcl_platform
    if {[string match -nocase {*windows nt*} $tcl_platform(os)]} { ##nagelfar nocover
        set Command ngspice_con
    } else {
        set Command ngspice
    }
    my configure -runlocation $runLocation
}

readData [::SpiceGenTcl::Ngspice::Simulators::Batch]Batch, Top, Main, Index

Reads raw data file, create RawFile object and return it's reference name.

BATCHOBJ readData ?args?
Parameters
method readData {args} {

    # Reads raw data file, create RawFile object and return it's reference name.
    argparse -help {Reads raw data file, create RawFile object and return it's reference name} {}
    my variable data
    set data [::SpiceGenTcl::RawFile new [file join [my configure -runlocation] ${LastRunFileName}.raw] * ngspice]
    return
}

readLog [::SpiceGenTcl::Ngspice::Simulators::Batch]Batch, Top, Main, Index

Reads log file of last simulation and save it's content to Log variable.

BATCHOBJ readLog ?args?
Parameters
method readLog {args} {

    # Reads log file of last simulation and save it's content to Log variable.
    argparse -help {Reads log file of last simulation and save it's content to Log variable} {}
    set logFile [open [file join [my configure -runlocation] ${LastRunFileName}.log] r+]
    set log [read $logFile]
    close $logFile
    return
}

runAndRead [::SpiceGenTcl::Ngspice::Simulators::Batch]Batch, Top, Main, Index

Runs netlist circuit file.

OBJECT runAndRead circuitStr ?-nodelete?
Parameters
-nodeleteFlag to forbid simulation file deletion.
circuitStrTop-level netlist string.
method runAndRead {args} {

    # Runs netlist circuit file.
    #  circuitStr - top-level netlist string
    #  -nodelete - flag to forbid simulation file deletion
    # Synopsis: circuitStr ?-nodelete?
    argparse -pfirst -help {Runs netlist circuit file} {
        {circuitStr -help {Top-level netlist string}}
        {-nodelete -help {Flag to forbid simulation file deletion}}
    }
    my variable Command
    set firstLine [@ [split $circuitStr \n] 0]
    set runLocation [my configure -runlocation]
    set cirFile [open [file join $runLocation ${firstLine}.cir] w+]
    puts $cirFile $circuitStr
    close $cirFile
    set rawFileName [file join $runLocation ${firstLine}.raw]
    set logFileName [file join $runLocation ${firstLine}.log]
    set cirFileName [file join $runLocation ${firstLine}.cir]
    exec {*}[list $Command -b -r $rawFileName -o $logFileName $cirFileName]
    set LastRunFileName $firstLine
    my readLog
    my readData
    if {![info exists nodelete]} {
        file delete $rawFileName
        file delete $logFileName
        file delete $cirFileName
    }
}

BatchLiveLog [::SpiceGenTcl::Ngspice::Simulators]Top, Main, Index

Method summary
configureConfigure properties.
getLogSee ::SpiceGenTcl::Simulator.getLog
readDataSee Batch.readData
readLogSee Batch.readLog
runSee ::SpiceGenTcl::Simulator.run
runAndReadRuns netlist circuit file.
Properties
-dataReadable, writable.
-logReadable, writable.
-nameReadable, writable.
-runlocationReadable, writable.
Superclasses

Batch

runAndRead [::SpiceGenTcl::Ngspice::Simulators::BatchLiveLog]BatchLiveLog, Top, Main, Index

Runs netlist circuit file.

OBJECT runAndRead circuitStr ?-nodelete?
Parameters
-nodeleteFlag to forbid simulation file deletion.
circuitStrTop-level netlist string.
method runAndRead {args} {

    # Runs netlist circuit file.
    #  circuitStr - top-level netlist string
    #  -nodelete - flag to forbid simulation file deletion
    # Synopsis: circuitStr ?-nodelete?
    argparse -pfirst -help {Runs netlist circuit file} {
        {circuitStr -help {Top-level netlist string}}
        {-nodelete -help {Flag to forbid simulation file deletion}}
    }
    my variable Command
    my variable LastRunFileName
    set firstLine [@ [split $circuitStr \n] 0]
    set runLocation [my configure -runlocation]
    set cirFile [open [file join $runLocation ${firstLine}.cir] w+]
    puts $cirFile $circuitStr
    close $cirFile
    set rawFileName [file join $runLocation ${firstLine}.raw]
    set logFileName [file join $runLocation ${firstLine}.log]
    set cirFileName [file join $runLocation ${firstLine}.cir]
    set command [list $Command -b $cirFileName -r $rawFileName]
    set chan [open "|$command 2>@1"]
    set logData {}
    while {[gets $chan line] >= 0} {
        puts $line
        set logData [join [list $logData $line] \n]
        if {[eof $chan]} {
            close $chan
        }
    }
    close $chan
    set LastRunFileName ${firstLine}
    my configure -log $logData
    my readData
    if {![info exists nodelete]} {
        file delete $rawFileName
        file delete $logFileName
        file delete $cirFileName
    }
}

Shared [::SpiceGenTcl::Ngspice::Simulators]Top, Main, Index

Method summary
constructorConstructor for the class.
destructorDestructor for the class.
configureConfigure properties.
getLogSee ::SpiceGenTcl::Simulator.getLog
readDataGets data, create RawFile object and return it's reference name.
readLogGets log of last simulation and save it's content to Log variable.
runSee ::SpiceGenTcl::Simulator.run
runAndReadRuns circuit.
Properties
-dataReadable, writable.
-liblocationReadable, writable.
-logReadable, writable.
-nameReadable, writable.
-simhandleReadable, writable.
Superclasses

::SpiceGenTcl::Simulator

constructor [::SpiceGenTcl::Ngspice::Simulators::Shared]Shared, Top, Main, Index

Creates batch ngspice simulator that can be attached to top-level Circuit.

Shared create OBJNAME ?args?
Shared new ?args?
Parameters
nameName of simulator object.
runLocationLocation at which input netlist is stored and all output files will be saved, default is current directory.
method constructor {args} {

    # Creates batch ngspice simulator that can be attached to top-level Circuit.
    #  name - name of simulator object
    #  runLocation - location at which input netlist is stored and all output files will be saved,
    #   default is current directory
    package require ngspicetclbridge
    argparse -help {Creates batch ngspice simulator that can be attached to top-level 'Circuit'} {
        {name -help {Name of simulator object}}
        {liblocation -optional -default /usr/local/lib/libngspice.so -help {Location of .so/.dll library}}
    }
    my configure -name $name -liblocation $liblocation
    my configure -simhandle [ngspicetclbridge::new $liblocation]
}

destructor [::SpiceGenTcl::Ngspice::Simulators::Shared]Shared, Top, Main, Index

SHAREDOBJ destroy
method destructor {} {

    $simhandle destroy
}

readData [::SpiceGenTcl::Ngspice::Simulators::Shared]Shared, Top, Main, Index

Gets data, create RawFile object and return it's reference name.

SHAREDOBJ readData ?args?
Parameters
method readData {args} {

    # Gets data, create RawFile object and return it's reference name.
    argparse -help {Gets data, create RawFile object and return it's reference name} {}
    my variable data
    set data [::SpiceGenTcl::RawFile new -shared $simhandle {} * ngspice]
    return
}

readLog [::SpiceGenTcl::Ngspice::Simulators::Shared]Shared, Top, Main, Index

Gets log of last simulation and save it's content to Log variable.

SHAREDOBJ readLog ?args?
Parameters
method readLog {args} {

    # Gets log of last simulation and save it's content to Log variable.
    argparse -help {Gets log of last simulation and save it's content to Log variable} {}
    set log [$simhandle messages]
    return
}

runAndRead [::SpiceGenTcl::Ngspice::Simulators::Shared]Shared, Top, Main, Index

Runs circuit.

OBJECT runAndRead circuitStr
Parameters
circuitStrTop-level netlist string.
method runAndRead {args} {

    # Runs circuit.
    #  circuitStr - top-level netlist string
    # Synopsis: circuitStr
    argparse -pfirst -help {Runs circuit} {
        {circuitStr -help {Top-level netlist string}}
    }
    set circuitList [split $circuitStr \n]
    set firstLine [@ $circuitList 0]
    $simhandle circuit [lappend circuitList .end]
    ngspicetclbridge::run $simhandle
    my readLog
    my readData
}