LTSpice .raw data format

I would like to write a program to automate several simulations from LTSpice and post-process the resulting .raw file data.

Is there a document that is available the describes the LTSpice .raw data file format?

Thank you,

David

  • +1
    •  Super User 
    on Feb 17, 2019 9:48 PM over 1 year ago

    Hello David,

    You can use LTspiceXVII in batch mode. See the help pages: Modes of Operation -> Command Line Switches

    When you then use the option -ascii, you will get a raw-file formatted in ASCII-text. This would be the easiest way. It's suitable if you have not too much data points. I remember a colleague who told me that he read the ASCII raw-file with Python for further processing.

    The raw-format is not officially disclosed, but everybody can explore it with a hex editor. In principle the format could change at some day, but it's practically the same since at least 15 years.

    Example for .TRAN
    The time is in double, the voltage and current values are in float. If double precision is forced by .options numdgt=10  (any number >6), then the voltage and current values are stored in double too. Are you aware that the header of the raw-file is in 16bit unicode?

    .....
    .....
    Variables:
        0    time    time
        1    V(a)    voltage
        2    I(R1)    device_current
        3    I(V1)    device_current
    Binary:
    double float float float double float float float double ........

    If you work with Matlab, you could use an available Matlab-script for reading the raw-file.
    There is also a small program ltsputil.exe to convert a raw-file into a text-file.

    Helmut

  • +1
    •  Super User 
    on Feb 20, 2019 10:22 PM over 1 year ago in reply to helmuts

    Hello David,

    I just tried a search with Google:  ltspice raw-file format

    I got a lot of results from other LTspice-users who have already written programs in Matlab and Python to read data from raw-files. This could save you a lot of time. Please try a search with Google.

    Best regards,
    Helmut

  • Hello David,

    Yes, there are many documents available to read raw files from LTspice to any software language like Matlab or Python.
    I would recommend using ltspice package which is available in python.

    If you have any queries feel free to contact me:)

    link:https://pypi.org/project/ltspice/

    Thanks & Regards,

    Goutham M S

  • Hello, hope all is fine.

    I actually have sort of the same problem. I scripted a python code so as to generate automatically LTspice netlists since the simulations I run are of very complicated circuits. I have been looking for two days now for a python command that will ask LTspice to simulate the netlist so as to generate the raw file for me to extract data needed. I, unfortunately, did not manage to find one. 

    All suggestions are welcomed and are desperately awaited.

    Thanks in advance.

    Kaoutar Slight smile

  • Dear Kaoutar,

    To run LTspice simulations in python you can "import ltspice" module via pip for example and trigger your netlist file via batch which would generate raw files for your simulations and run that raw file in python to make the plots.

    ### create a bat file ### for example 

    "C:\Program Files\LTC\LTspiceXVII\XVIIx64.exe" -b "C:\Users\Desktop\file.net"

    ###################

    ## python code example ##

    import os

    import subprocess #<to run batch file>

    import ltspice #<to run spice simulations on python>

    import matplotlib.pyplot as plt #<to generate plots>

    bathfile= os.chidr("<path where ''file.bat' file stored>")

    netlist = os.chidr("< path where 'file.net' stored>")

    subprocess.call([r"{path}".format(path=batpath))])  # triggers batch file in back end

    rawfile = os.chidr("<path were generated raw file is stored>")

    l = ltspice.Ltspice(rawfile)
    
    l.parse() # Data loading sequence. It may take few minutes.
    time = l.getTime() # creates simulation time data frame

    V_source = l.getData('V(source)')
    I_load= l.getData('I')
    
    plt.plot(time, V_source)
    plt.plot(time, I_load)
    plt.show()
    ################################################### 

    Hope this helps what your looking for.

    Thanks & Regards,
    Goutham