• 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 23302
  • 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

    There's no need to open in append mode unless you want to append to the previous contents of the file (i.e. not overwrite it at the time of opening). Each succesive ocnPrint with the same port will append to the output stream until the file is closed.

    You can't use fprintf with a waveform object; you'd have to iterate over the points in the waveform object - for example:

    /* abDumpWaveform.il
    
    Author     A.D.Beckett
    Group      Custom IC, Cadence Design Systems Ltd.
    Machine    SUN
    Date       Oct 23, 1997 
    Modified   Jan 31, 2005 
    By         A.D.Beckett
    
    Functions for dumping a waveform to a file
    
    Examples:
    
    abDumpWaveform(VT("/c") "data_c.out")
    abDumpWaveform(VT("/c") "data_c.out" "%e %e\n") ;; exponential format
    
    abDumpWaveformSplit() is equivalent to abDumpWaveform, but splits
    into files a little less than 2Gbytes (the split limit is an optional
    argument).
    
    ;; sampled output.
    ;; note that linRg and logRg generate a range of values,
    ;; with args from, to, step.
    abDumpSampledWaveform(VT("/c") linRg(0.01 0.05 0.005) "data_c.out")
    
    ;; multi-variable output
    ;; all waveforms must share same x-axis, as it doesn't do any interpolation (for
    ;; speed reasons). Interpolation could be done by collecting all the x-values, and
    ;; then using the value function.
    abDumpWaveforms("data.out" VT("/c") VT("/z") VT("/a"))
    abDumpWaveforms("data.out" VT("/c") VT("/z") VT("/a") ?format "%-10g" ?separator ",")
    
    ;; can also write out multiple files if presented with a family
    abDumpFamily(VT("/c") "data.out")
    
    ***************************************************
    
    SCCS Info: @(#) abDumpWaveform.il 11/20/08.15:26:13 1.6
    
    */
    
    /*****************************************************************
    *                                                                *
    *  (abDumpWaveform wave fileName @optional (format "%g %g\n"))   *
    *                                                                *
    * Take a waveform object, write it out to the fileName specified *
    *          with the format given. No sampling is done.           *
    *                                                                *
    *****************************************************************/
    
    (procedure (abDumpWaveform wave fileName @optional (format "%g %g\n"))
      (let (port (xVec (drGetWaveformXVec wave))
                 (yVec (drGetWaveformYVec wave)))
           (unless (setq port (outfile fileName))
                   (error "Could not write to file %s\n" fileName))
           (for pos 0 (sub1 (drVectorLength xVec))
                (fprintf port format
                         (drGetElem xVec pos)
                         (drGetElem yVec pos))
                )
           (close port)
           ))
    
    /*****************************************************************
    *                                                                *
    *         (abDumpWaveformSplit wave fileName @optional           *
    *            (format "%g %g\n") (split 2**31-512) )              *
    *                                                                *
    * Take a waveform object, write it out to the fileName specified *
    *     with the format given. No sampling is done. Splits into    *
    *      multiple files when the number of bytes exceeds split     *
    *                                                                *
    *****************************************************************/
    
    (procedure (abDumpWaveformSplit wave fileName @optional (format "%g %g\n") (split 2**31-512))
      (let (port (xVec (drGetWaveformXVec wave))
                 (yVec (drGetWaveformYVec wave))
                 str (len 0) (suffix 0))
           (unless (setq port (outfile fileName))
                   (error "Could not write to file %s\n" fileName))
           (for pos 0 (sub1 (drVectorLength xVec))
                (sprintf str format
                         (drGetElem xVec pos)
                         (drGetElem yVec pos))
                (setq len (plus (strlen str) len))
                (when (greaterp len split)
                      (close port)
                      (postincrement suffix)
                      (setq len (strlen str))
                      (unless (setq port (outfile (sprintf nil "%s_%d" fileName suffix)))
                              (error "Could not write to file %s_%d\n" fileName suffix))
                      )
                (fprintf port "%s" str)
                )
           (close port)
           ))
    
    /********************************************************************
    *                                                                   *
    * (abDumpFamily family fileNamePrefix @optional (format "%g %g\n")) *
    *                                                                   *
    * Write out a sequence of files for a family. Could potentially do  *
    *  this automatically inside abDumpWaveform, but it's hard without  *
    *                     using private functions.                      *
    *                                                                   *
    ********************************************************************/
    
    (procedure (abDumpFamily family fileNamePrefix @optional (format "%g %g\n"))
      (let ((xVec (drGetWaveformXVec family))
            (yVec (drGetWaveformYVec family))
            index
            )
           (if (drIsWaveform family)
               ; then
               (abDumpWaveform family fileNamePrefix format)
               ;else
               (for pos 0 (sub1 (drVectorLength xVec))
                    (setq index (drGetElem xVec pos))
                    (unless (stringp index)
                            (sprintf index "%L" index))
                    (rexCompile "[^a-zA-Z0-9.]")
                    (setq index (rexReplace index "_" 0))
                    (abDumpWaveform
                     (drGetElem yVec pos)
                     (sprintf nil "%s_%s" fileNamePrefix index)
                     format
                     )
                    )
               ) ; if
           ))
    
    /*********************************************************************************
    *                                                                                *
    *   (abDumpWaveforms fileName @key (format "%g") (separator " ") @rest waves)    *
    *                                                                                *
    *    Write out a group of waveforms with a common x-axis to a file. It checks    *
    * to see if the x-axis is the same, because otherwise some kind of interpolation *
    *    would be necessary. An optional format string can be specified, so that     *
    *   the precision can be controlled. Also, an optional separator may be given.   *
    *                                                                                *
    *********************************************************************************/
    
    (procedure (abDumpWaveforms fileName @key (format "%g") (separator " ") @rest waves)
      (let (port xVec)
           (setq xVec (drGetWaveformXVec (car waves)))
           ;-----------------------------------------------------------------
           ; check to see if all waveforms have same X-axis
           ;-----------------------------------------------------------------
           (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))
           (for pos 0 (sub1 (drVectorLength xVec))
                (fprintf port format
                         (drGetElem xVec pos))
                (foreach wave waves
                         (fprintf port "%s" separator)
                         (fprintf port format (drGetElem (drGetWaveformYVec wave) pos))
                         )
                (fprintf port "\n")
                )
           (close port)
           ))
    
    /**********************************************************************************
    *                                                                                 *
    * (abDumpSampledWaveform wave samplePoints fileName @optional (format "%g %g\n")) *
    *                                                                                 *
    *      Dump the waveform at the sampled points passed in. wave is a waveform      *
    *            object, samplePoints is a list of x points to sample at,             *
    * fileName is the file to write to, and format is an optional formatting string.  *
    *                                                                                 *
    **********************************************************************************/
    
    (procedure (abDumpSampledWaveform wave samplePoints fileName @optional (format "%g %g\n"))
      (let (port) 
           (unless (setq port (outfile fileName))
                   (error "Could not write to file %s\n" fileName))
           (foreach point samplePoints
                    (fprintf port format
                             point
                             (value wave point))
                    )
           (close port)
           ))
    
    

     

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

    There's no need to open in append mode unless you want to append to the previous contents of the file (i.e. not overwrite it at the time of opening). Each succesive ocnPrint with the same port will append to the output stream until the file is closed.

    You can't use fprintf with a waveform object; you'd have to iterate over the points in the waveform object - for example:

    /* abDumpWaveform.il
    
    Author     A.D.Beckett
    Group      Custom IC, Cadence Design Systems Ltd.
    Machine    SUN
    Date       Oct 23, 1997 
    Modified   Jan 31, 2005 
    By         A.D.Beckett
    
    Functions for dumping a waveform to a file
    
    Examples:
    
    abDumpWaveform(VT("/c") "data_c.out")
    abDumpWaveform(VT("/c") "data_c.out" "%e %e\n") ;; exponential format
    
    abDumpWaveformSplit() is equivalent to abDumpWaveform, but splits
    into files a little less than 2Gbytes (the split limit is an optional
    argument).
    
    ;; sampled output.
    ;; note that linRg and logRg generate a range of values,
    ;; with args from, to, step.
    abDumpSampledWaveform(VT("/c") linRg(0.01 0.05 0.005) "data_c.out")
    
    ;; multi-variable output
    ;; all waveforms must share same x-axis, as it doesn't do any interpolation (for
    ;; speed reasons). Interpolation could be done by collecting all the x-values, and
    ;; then using the value function.
    abDumpWaveforms("data.out" VT("/c") VT("/z") VT("/a"))
    abDumpWaveforms("data.out" VT("/c") VT("/z") VT("/a") ?format "%-10g" ?separator ",")
    
    ;; can also write out multiple files if presented with a family
    abDumpFamily(VT("/c") "data.out")
    
    ***************************************************
    
    SCCS Info: @(#) abDumpWaveform.il 11/20/08.15:26:13 1.6
    
    */
    
    /*****************************************************************
    *                                                                *
    *  (abDumpWaveform wave fileName @optional (format "%g %g\n"))   *
    *                                                                *
    * Take a waveform object, write it out to the fileName specified *
    *          with the format given. No sampling is done.           *
    *                                                                *
    *****************************************************************/
    
    (procedure (abDumpWaveform wave fileName @optional (format "%g %g\n"))
      (let (port (xVec (drGetWaveformXVec wave))
                 (yVec (drGetWaveformYVec wave)))
           (unless (setq port (outfile fileName))
                   (error "Could not write to file %s\n" fileName))
           (for pos 0 (sub1 (drVectorLength xVec))
                (fprintf port format
                         (drGetElem xVec pos)
                         (drGetElem yVec pos))
                )
           (close port)
           ))
    
    /*****************************************************************
    *                                                                *
    *         (abDumpWaveformSplit wave fileName @optional           *
    *            (format "%g %g\n") (split 2**31-512) )              *
    *                                                                *
    * Take a waveform object, write it out to the fileName specified *
    *     with the format given. No sampling is done. Splits into    *
    *      multiple files when the number of bytes exceeds split     *
    *                                                                *
    *****************************************************************/
    
    (procedure (abDumpWaveformSplit wave fileName @optional (format "%g %g\n") (split 2**31-512))
      (let (port (xVec (drGetWaveformXVec wave))
                 (yVec (drGetWaveformYVec wave))
                 str (len 0) (suffix 0))
           (unless (setq port (outfile fileName))
                   (error "Could not write to file %s\n" fileName))
           (for pos 0 (sub1 (drVectorLength xVec))
                (sprintf str format
                         (drGetElem xVec pos)
                         (drGetElem yVec pos))
                (setq len (plus (strlen str) len))
                (when (greaterp len split)
                      (close port)
                      (postincrement suffix)
                      (setq len (strlen str))
                      (unless (setq port (outfile (sprintf nil "%s_%d" fileName suffix)))
                              (error "Could not write to file %s_%d\n" fileName suffix))
                      )
                (fprintf port "%s" str)
                )
           (close port)
           ))
    
    /********************************************************************
    *                                                                   *
    * (abDumpFamily family fileNamePrefix @optional (format "%g %g\n")) *
    *                                                                   *
    * Write out a sequence of files for a family. Could potentially do  *
    *  this automatically inside abDumpWaveform, but it's hard without  *
    *                     using private functions.                      *
    *                                                                   *
    ********************************************************************/
    
    (procedure (abDumpFamily family fileNamePrefix @optional (format "%g %g\n"))
      (let ((xVec (drGetWaveformXVec family))
            (yVec (drGetWaveformYVec family))
            index
            )
           (if (drIsWaveform family)
               ; then
               (abDumpWaveform family fileNamePrefix format)
               ;else
               (for pos 0 (sub1 (drVectorLength xVec))
                    (setq index (drGetElem xVec pos))
                    (unless (stringp index)
                            (sprintf index "%L" index))
                    (rexCompile "[^a-zA-Z0-9.]")
                    (setq index (rexReplace index "_" 0))
                    (abDumpWaveform
                     (drGetElem yVec pos)
                     (sprintf nil "%s_%s" fileNamePrefix index)
                     format
                     )
                    )
               ) ; if
           ))
    
    /*********************************************************************************
    *                                                                                *
    *   (abDumpWaveforms fileName @key (format "%g") (separator " ") @rest waves)    *
    *                                                                                *
    *    Write out a group of waveforms with a common x-axis to a file. It checks    *
    * to see if the x-axis is the same, because otherwise some kind of interpolation *
    *    would be necessary. An optional format string can be specified, so that     *
    *   the precision can be controlled. Also, an optional separator may be given.   *
    *                                                                                *
    *********************************************************************************/
    
    (procedure (abDumpWaveforms fileName @key (format "%g") (separator " ") @rest waves)
      (let (port xVec)
           (setq xVec (drGetWaveformXVec (car waves)))
           ;-----------------------------------------------------------------
           ; check to see if all waveforms have same X-axis
           ;-----------------------------------------------------------------
           (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))
           (for pos 0 (sub1 (drVectorLength xVec))
                (fprintf port format
                         (drGetElem xVec pos))
                (foreach wave waves
                         (fprintf port "%s" separator)
                         (fprintf port format (drGetElem (drGetWaveformYVec wave) pos))
                         )
                (fprintf port "\n")
                )
           (close port)
           ))
    
    /**********************************************************************************
    *                                                                                 *
    * (abDumpSampledWaveform wave samplePoints fileName @optional (format "%g %g\n")) *
    *                                                                                 *
    *      Dump the waveform at the sampled points passed in. wave is a waveform      *
    *            object, samplePoints is a list of x points to sample at,             *
    * fileName is the file to write to, and format is an optional formatting string.  *
    *                                                                                 *
    **********************************************************************************/
    
    (procedure (abDumpSampledWaveform wave samplePoints fileName @optional (format "%g %g\n"))
      (let (port) 
           (unless (setq port (outfile fileName))
                   (error "Could not write to file %s\n" fileName))
           (foreach point samplePoints
                    (fprintf port format
                             point
                             (value wave point))
                    )
           (close port)
           ))
    
    

     

    • 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