• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC Design
  3. Writing a waveform and sampled version of that into a file...

Stats

  • Locked Locked
  • Replies 9
  • Subscribers 125
  • Views 22981
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Writing a waveform and sampled version of that into a file without using ocnPrint

yayla
yayla over 14 years ago

Hi all,

       I have recently started to learn ocean script and tried to make some analysis. I have looked at the forum to find a solution but I couldn't. My problem is that I am running a tran analysis and saving voltages by writing save('v "/outp"). After that, I am sampling this wave with some step as

out_sampled = sample(VT("outp") 1e-8 4e-8 "linear" 1e-12)

My question is that without using ocnPrint how I could save wave itself (VT("/outp") and out_sampled) into a file. Probably, I will need to use fprintf() but I am not quite sure how to do that.

I will appreciate if you could help.

 

Thanks,

 yayla

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 14 years ago

    Yayla,

    Not really. You could sample the signal in Matlab, I guess - one way is to use cds_interpsig(sig,'time',20) to sample it to 20 evenly spaced points.

    There's also some functions I wrote a while back to dump out PSF - but I have not tested these in ages (I removed them from the abDumpWaveforms.il listing above in order to make it a little shorter):

    /*************************************************************************
    *                                                                        *
    * Some global variables which enable simpler specification of the header *
    *                      part of the ASCII PSF file.                       *
    *                                                                        *
    *************************************************************************/
    
    (setq abAsciiPSFTokenMap
      '((TOK_CR "\n")
        (TOK_PROP "PROP( ")
        (TOK_STRUCT "STRUCT( ")
        (TOK_OPEN "( ")
        (TOK_CLOSE ") ")
        (TOK_STAR "* ")
        )
      )
    
    (setq abAsciiPSFHeader
      '(
        HEADER TOK_CR
        "PSFversion" "1.00" TOK_CR
        TYPE TOK_CR
        "sweep" FLOAT DOUBLE TOK_PROP TOK_CR
        "key" "sweep" TOK_CR
        TOK_CLOSE TOK_CR
        "V" FLOAT DOUBLE TOK_PROP TOK_CR
        "units" "V" TOK_CR
        "key" "node" TOK_CR
        "tolerance" 1.00000e-06 TOK_CR
        TOK_CLOSE TOK_CR
        SWEEP TOK_CR
        "time" "sweep" TOK_PROP TOK_CR
        "sweep_direction" 0 TOK_CR
        "units" "s" TOK_CR
        "plot" 0 TOK_CR
        "grid" 1 TOK_CR
        TOK_CLOSE TOK_CR
        )
      )
    
    (setq abAsciiPSFLogFile
      '(
        HEADER TOK_CR
        "PSFversion" "1.00" TOK_CR
        "Log Generator" "drlLog rev. 1.0" TOK_CR
        "Log Time Stamp" "Thu Jan  3 16:23:59 2002" TOK_CR
        "simulator" "spectre" TOK_CR
        "version" "4.4.6.122001" TOK_CR
        "date" "4:23:59 PM, Thur Jan 3, 2002" TOK_CR
        "design" "myres.scs" TOK_CR
        TYPE TOK_CR
        "analysisInst" TOK_STRUCT TOK_CR
        "analysisType" STRING TOK_STAR TOK_CR
        "dataFile" STRING TOK_STAR TOK_CR
        "format" STRING TOK_STAR TOK_CR
        "parent" STRING TOK_STAR TOK_CR
        "sweepVariable" ARRAY TOK_OPEN TOK_STAR TOK_CLOSE STRING TOK_STAR TOK_CR
        "description" STRING TOK_STAR TOK_CR
        TOK_CLOSE TOK_CR
        VALUE TOK_CR
        "tran-tran" "analysisInst" TOK_OPEN TOK_CR
        "tran" TOK_CR
        "tran.tran" TOK_CR
        "PSF" TOK_CR
        "" TOK_CR
        TOK_OPEN "time" TOK_CLOSE TOK_CR
        "Transient Analysis `tran'" TOK_CR
        TOK_CLOSE TOK_CR
        END TOK_CR
        )
      )
    
    /***************************************************************
    *                                                              *
    *                 (abDumpPSFMagic port magic)                  *
    *                                                              *
    *   A function for dumping the "magic" tokenised PSF header    *
    *  format information, to make writing the ASCII PSF simpler   *
    *                    (believe it or not...)                    *
    *                                                              *
    ***************************************************************/
    
    (procedure (abDumpPSFMagic port magic)
      (let (mapped)
           ;-----------------------------------------------------------------
           ; Ensure that the PSF token map has been created
           ;-----------------------------------------------------------------
           (unless (boundp 'abPSFTokenMap)
                   (setq abPSFTokenMap (makeTable 'PSFTokenMap nil))
                   (foreach tokenMap abAsciiPSFTokenMap
                            (setarray abPSFTokenMap (car tokenMap) (cadr tokenMap))
                            )
                   )
           ;-----------------------------------------------------------------
           ; Now write out each word in the magic list, mapping if necessary
           ;-----------------------------------------------------------------
           (foreach word magic
                    (if (setq mapped (arrayref abPSFTokenMap word))
                        (fprintf port mapped)
                        (progn
                         (print word port)
                         (fprintf port " ")
                         )
                        )
                    )
           )
      )
    
    /***************************************************************
    *                                                              *
    *       (abDumpWaveformsToAsciiPSF fileName @rest waves)       *
    *                                                              *
    *     Create an ASCII PSF file containing the waves passed     *
    *  as remaining arguments. Note that all must have the same X  *
    *                             axis                             *
    *                                                              *
    ***************************************************************/
    
    (procedure (abDumpWaveformsToAsciiPSF fileName @rest waves)
      (let (port xVec (waveNum 1))
           ;-----------------------------------------------------------------
           ; If a list of waves is passed in, use that instead
           ;-----------------------------------------------------------------
           (when (listp (car waves)) (setq waves (car waves)))
           ;-----------------------------------------------------------------
           ; Get the x vector of the first waveform
           ;-----------------------------------------------------------------
           (setq xVec (drGetWaveformXVec (car waves)))
           ;-----------------------------------------------------------------
           ; check to see if all waveforms have same X-axis
           ; much simpler this way...
           ;-----------------------------------------------------------------
           (when (exists wave waves (neq xVec (drGetWaveformXVec wave)))
                 (error "All waveforms must have same x-axis")
                 )
           (unless (setq port (outfile fileName))
                   (error "Could not write to file %s\n" fileName))
           (abDumpPSFMagic port abAsciiPSFHeader)
           (abDumpPSFMagic port `(TRACE TOK_CR "group" GROUP ,(length waves) TOK_CR))
           ;-----------------------------------------------------------------
           ; Create a waveform name for each waveform
           ;-----------------------------------------------------------------
           (abDumpPSFMagic port
                           (foreach mapcan wave waves
                                    ; next line is just to fool lint
                                    wave
                                    (list (sprintf nil "wave%d" (postincrement waveNum)) "V" 'TOK_CR)
                                    ))
           (abDumpPSFMagic port `(VALUE TOK_CR))
           ;-----------------------------------------------------------------
           ; Now write out the actual data
           ;-----------------------------------------------------------------
           (for pos 0 (sub1 (drVectorLength xVec))
                (fprintf port "\"time\" %.14e\n\"group\" " (drGetElem xVec pos))
                (foreach wave waves
                         (fprintf port "%.14e\n" (drGetElem (drGetWaveformYVec wave) pos))
                         )
                )
           (abDumpPSFMagic port `(END TOK_CR))
           (close port)
           )
      )
    
    /***************************************************************
    *                                                              *
    *         (abDumpWaveformsToBinPSF rawdir @rest waves)         *
    *                                                              *
    *   Specify a raw directory, and a number of waveforms, this   *
    *      will create an ASCII PSF file and then use the psf      *
    *               utility to convert it to binary.               *
    *                                                              *
    ***************************************************************/
    
    (procedure (abDumpWaveformsToBinPSF rawdir @rest waves)
      (let (port)
           (if (or (isDir rawdir) (createDir rawdir))
               (progn
                (apply 'abDumpWaveformsToAsciiPSF (cons (strcat rawdir "/tran.asc") waves))
                (setq port (outfile (strcat rawdir "/logFile")))
                (when port
                      (abDumpPSFMagic port abAsciiPSFLogFile)
                      (close port))
                ;------------------------------------------------------------
                ; Use the transpose option (-x) (think this is right...)
                ;------------------------------------------------------------
                (system 
                 (sprintf nil "psf -x -i %s/tran.asc -o %s/tran.tran"
                          rawdir rawdir)
                 )
                t
                )
               (error "Could not create directory %s" rawdir)
               )
           )
      ) 
    
    

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 14 years ago

    Yayla,

    Not really. You could sample the signal in Matlab, I guess - one way is to use cds_interpsig(sig,'time',20) to sample it to 20 evenly spaced points.

    There's also some functions I wrote a while back to dump out PSF - but I have not tested these in ages (I removed them from the abDumpWaveforms.il listing above in order to make it a little shorter):

    /*************************************************************************
    *                                                                        *
    * Some global variables which enable simpler specification of the header *
    *                      part of the ASCII PSF file.                       *
    *                                                                        *
    *************************************************************************/
    
    (setq abAsciiPSFTokenMap
      '((TOK_CR "\n")
        (TOK_PROP "PROP( ")
        (TOK_STRUCT "STRUCT( ")
        (TOK_OPEN "( ")
        (TOK_CLOSE ") ")
        (TOK_STAR "* ")
        )
      )
    
    (setq abAsciiPSFHeader
      '(
        HEADER TOK_CR
        "PSFversion" "1.00" TOK_CR
        TYPE TOK_CR
        "sweep" FLOAT DOUBLE TOK_PROP TOK_CR
        "key" "sweep" TOK_CR
        TOK_CLOSE TOK_CR
        "V" FLOAT DOUBLE TOK_PROP TOK_CR
        "units" "V" TOK_CR
        "key" "node" TOK_CR
        "tolerance" 1.00000e-06 TOK_CR
        TOK_CLOSE TOK_CR
        SWEEP TOK_CR
        "time" "sweep" TOK_PROP TOK_CR
        "sweep_direction" 0 TOK_CR
        "units" "s" TOK_CR
        "plot" 0 TOK_CR
        "grid" 1 TOK_CR
        TOK_CLOSE TOK_CR
        )
      )
    
    (setq abAsciiPSFLogFile
      '(
        HEADER TOK_CR
        "PSFversion" "1.00" TOK_CR
        "Log Generator" "drlLog rev. 1.0" TOK_CR
        "Log Time Stamp" "Thu Jan  3 16:23:59 2002" TOK_CR
        "simulator" "spectre" TOK_CR
        "version" "4.4.6.122001" TOK_CR
        "date" "4:23:59 PM, Thur Jan 3, 2002" TOK_CR
        "design" "myres.scs" TOK_CR
        TYPE TOK_CR
        "analysisInst" TOK_STRUCT TOK_CR
        "analysisType" STRING TOK_STAR TOK_CR
        "dataFile" STRING TOK_STAR TOK_CR
        "format" STRING TOK_STAR TOK_CR
        "parent" STRING TOK_STAR TOK_CR
        "sweepVariable" ARRAY TOK_OPEN TOK_STAR TOK_CLOSE STRING TOK_STAR TOK_CR
        "description" STRING TOK_STAR TOK_CR
        TOK_CLOSE TOK_CR
        VALUE TOK_CR
        "tran-tran" "analysisInst" TOK_OPEN TOK_CR
        "tran" TOK_CR
        "tran.tran" TOK_CR
        "PSF" TOK_CR
        "" TOK_CR
        TOK_OPEN "time" TOK_CLOSE TOK_CR
        "Transient Analysis `tran'" TOK_CR
        TOK_CLOSE TOK_CR
        END TOK_CR
        )
      )
    
    /***************************************************************
    *                                                              *
    *                 (abDumpPSFMagic port magic)                  *
    *                                                              *
    *   A function for dumping the "magic" tokenised PSF header    *
    *  format information, to make writing the ASCII PSF simpler   *
    *                    (believe it or not...)                    *
    *                                                              *
    ***************************************************************/
    
    (procedure (abDumpPSFMagic port magic)
      (let (mapped)
           ;-----------------------------------------------------------------
           ; Ensure that the PSF token map has been created
           ;-----------------------------------------------------------------
           (unless (boundp 'abPSFTokenMap)
                   (setq abPSFTokenMap (makeTable 'PSFTokenMap nil))
                   (foreach tokenMap abAsciiPSFTokenMap
                            (setarray abPSFTokenMap (car tokenMap) (cadr tokenMap))
                            )
                   )
           ;-----------------------------------------------------------------
           ; Now write out each word in the magic list, mapping if necessary
           ;-----------------------------------------------------------------
           (foreach word magic
                    (if (setq mapped (arrayref abPSFTokenMap word))
                        (fprintf port mapped)
                        (progn
                         (print word port)
                         (fprintf port " ")
                         )
                        )
                    )
           )
      )
    
    /***************************************************************
    *                                                              *
    *       (abDumpWaveformsToAsciiPSF fileName @rest waves)       *
    *                                                              *
    *     Create an ASCII PSF file containing the waves passed     *
    *  as remaining arguments. Note that all must have the same X  *
    *                             axis                             *
    *                                                              *
    ***************************************************************/
    
    (procedure (abDumpWaveformsToAsciiPSF fileName @rest waves)
      (let (port xVec (waveNum 1))
           ;-----------------------------------------------------------------
           ; If a list of waves is passed in, use that instead
           ;-----------------------------------------------------------------
           (when (listp (car waves)) (setq waves (car waves)))
           ;-----------------------------------------------------------------
           ; Get the x vector of the first waveform
           ;-----------------------------------------------------------------
           (setq xVec (drGetWaveformXVec (car waves)))
           ;-----------------------------------------------------------------
           ; check to see if all waveforms have same X-axis
           ; much simpler this way...
           ;-----------------------------------------------------------------
           (when (exists wave waves (neq xVec (drGetWaveformXVec wave)))
                 (error "All waveforms must have same x-axis")
                 )
           (unless (setq port (outfile fileName))
                   (error "Could not write to file %s\n" fileName))
           (abDumpPSFMagic port abAsciiPSFHeader)
           (abDumpPSFMagic port `(TRACE TOK_CR "group" GROUP ,(length waves) TOK_CR))
           ;-----------------------------------------------------------------
           ; Create a waveform name for each waveform
           ;-----------------------------------------------------------------
           (abDumpPSFMagic port
                           (foreach mapcan wave waves
                                    ; next line is just to fool lint
                                    wave
                                    (list (sprintf nil "wave%d" (postincrement waveNum)) "V" 'TOK_CR)
                                    ))
           (abDumpPSFMagic port `(VALUE TOK_CR))
           ;-----------------------------------------------------------------
           ; Now write out the actual data
           ;-----------------------------------------------------------------
           (for pos 0 (sub1 (drVectorLength xVec))
                (fprintf port "\"time\" %.14e\n\"group\" " (drGetElem xVec pos))
                (foreach wave waves
                         (fprintf port "%.14e\n" (drGetElem (drGetWaveformYVec wave) pos))
                         )
                )
           (abDumpPSFMagic port `(END TOK_CR))
           (close port)
           )
      )
    
    /***************************************************************
    *                                                              *
    *         (abDumpWaveformsToBinPSF rawdir @rest waves)         *
    *                                                              *
    *   Specify a raw directory, and a number of waveforms, this   *
    *      will create an ASCII PSF file and then use the psf      *
    *               utility to convert it to binary.               *
    *                                                              *
    ***************************************************************/
    
    (procedure (abDumpWaveformsToBinPSF rawdir @rest waves)
      (let (port)
           (if (or (isDir rawdir) (createDir rawdir))
               (progn
                (apply 'abDumpWaveformsToAsciiPSF (cons (strcat rawdir "/tran.asc") waves))
                (setq port (outfile (strcat rawdir "/logFile")))
                (when port
                      (abDumpPSFMagic port abAsciiPSFLogFile)
                      (close port))
                ;------------------------------------------------------------
                ; Use the transpose option (-x) (think this is right...)
                ;------------------------------------------------------------
                (system 
                 (sprintf nil "psf -x -i %s/tran.asc -o %s/tran.tran"
                          rawdir rawdir)
                 )
                t
                )
               (error "Could not create directory %s" rawdir)
               )
           )
      ) 
    
    

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information