/* abSortXValues.il Language SKILL Date Aug 26, 2009 Modified Jan 02, 2021 Function to sort the inner sweep to be sorted by x-value. For harmonic data (such as that from pac, qpac), the order is by harmonic number - so if you try to use the value() function, you may get garbage results because value() expects the x-axis to be monotonic. Usually you would use the harmonic() function to get a particular harmonic - this is to allow you to get a fixed frequency instead (if you're doing a sweep of frequency, you may not be interested in a fixed harmonic id). Usage: a=abSortXValues(v("/net6")) plot(value(a 100k)) Add to the calculator using the "fx" button in the function panel or expression builder. This includes the template for the calculator, so that is all you should need to do. Updated in version 1.3 to handle x-axes which are strings; also preserves name/units from axes and no longer requires abWaveToList (to make the code more portable) *************************************************** SCCS Info: @(#) abSortXValues.il 01/02/21.10:41:14 1.3 */ /******************************************************************************* * DISCLAIMER: The following code is provided for Cadence customers to use at * * their own risk. The code may require modification to satisfy the * * requirements of any user. The code and any modifications to the code may * * not be compatible with current or future versions of Cadence products. * * THE CODE IS PROVIDED "AS IS" AND WITH NO WARRANTIES, INCLUDING WITHOUT * * LIMITATION ANY EXPRESS WARRANTIES OR IMPLIED WARRANTIES OF MERCHANTABILITY * * OR FITNESS FOR A PARTICULAR USE. * *******************************************************************************/ (defun abSortXValues (wave) (cond ((drIsWaveform wave) (let (srcXVec dstXVec srcYVec dstYVec compare len xyList newWave) (setq srcXVec (drGetWaveformXVec wave)) (setq srcYVec (drGetWaveformYVec wave)) (setq len (drVectorLength srcXVec)) (setq dstXVec (drCreateVec (drType srcXVec) len)) (setq dstYVec (drCreateVec (drType srcYVec) len)) ;----------------------------------------------------------------- ; Choose appropriate comparison function dependent upon the ; type, sort by x-values, and populate new vectors ;----------------------------------------------------------------- (setq compare (if (eq (drType srcXVec) 'string) (lambda (a b) (minusp (alphaNumCmp a b))) 'lessp)) (for i 0 (sub1 len) (setq xyList (tconc xyList (list (drGetElem srcXVec i) (drGetElem srcYVec i))))) ;----------------------------------------------------------------- ; note that xyList is a tconc structure, so pass the car to the ; sort function ;----------------------------------------------------------------- (setq xyList (sortcar (car xyList) compare)) (foreach pair xyList (drAddElem dstXVec (car pair)) (drAddElem dstYVec (cadr pair)) ) ;----------------------------------------------------------------- ; Copy across vector properties to get units, name etc ;----------------------------------------------------------------- (foreach prop (getq srcXVec ?) (putprop dstXVec (get srcXVec prop) prop)) (foreach prop (getq srcYVec ?) (putprop dstYVec (get srcYVec prop) prop)) (setq newWave (drCreateWaveform dstXVec dstYVec)) (famSetExpr newWave `(abSortXValues ,(famGetExpr wave))) newWave ) ) ((famIsFamily wave) (let (new) (setq new (famMap 'abSortXValues wave)) ;----------------------------------------------------------------- ; Remove any harmonic information, because it won't be correct ; as the order of the underlying waveforms no longer matches ;----------------------------------------------------------------- (remprop new 'harmonic) (remprop new '__harmonicList) new ) ) (t (error "abSortXValues - can't handle %L\n" wave) ) ) ; cond ) ; defun ; ;;;;;;;;;;;;;;;;;;;;;;;;;; GUI builder information ;;;;;;;;;;;;;;;;;;;;;;;;;;; ocnmRegGUIBuilder( '(nil function abSortXValues name abSortXValues description "Sort points into order based on x value" category ("Custom Functions") analysis (nil general (nil args (wave ) signals (nil wave (nil prompt "Waveform" tooltip "Waveform" ) ) params(nil ) inputrange t ) ) outputs(result) ) )