Fixed a bug in findcross in c_functions.c

Recompiled binaries for Windows xp 32bit
master
Per.Andreas.Brodtkorb 15 years ago
parent 24360c33f8
commit 205f94d0f8

Binary file not shown.

@ -19,31 +19,31 @@ This module gives gives detailed information and easy access to all datasets
included in WAFO
"""
#from pylab import load
#from scipy.io import read_array
from numpy import (loadtxt,nan)
from numpy import (loadtxt, nan)
import os
__path2data = os.path.dirname( os.path.realpath(__file__))
__path2data = os.path.dirname(os.path.realpath(__file__))
__all__ =['atlantic','gfaks89','gfaksr89','japansea','northsea','sea','sfa89',
'sn','yura87']
__all__ = ['atlantic', 'gfaks89', 'gfaksr89', 'japansea', 'northsea', 'sea',
'sfa89', 'sn', 'yura87']
_NANS = set(['nan', 'NaN', '-1.#IND00+00', '1.#IND00+00', '-1.#INF00+00'])
def _tofloat(x):
return nan if x in _NANS else float(x or 0)
_MYCONVERTER = {}
for i in range(2):
_MYCONVERTER[i] = _tofloat
def _load(file):
""" local load function
"""
return loadtxt(os.path.join(__path2data,file))
def _tofloat(x):
if x=='nan' or x=='NaN':
y = nan
else:
y = float(x or 0)
return y
return loadtxt(os.path.join(__path2data, file))
def _loadnan(file):
""" local load function accepting nan's
"""
myconverter = {0: _tofloat, 1: _tofloat}
return loadtxt(os.path.join(__path2data,file),converters=myconverter)
return loadtxt(os.path.join(__path2data, file), converters=_MYCONVERTER)
def atlantic():
"""
@ -437,6 +437,6 @@ def yura87():
japansea
"""
return _load('yura87.dat')
if __name__=='__main__':
if __name__ == '__main__':
import doctest
doctest.testmod()
doctest.testmod()

@ -41,7 +41,7 @@ from numpy import r_
from numpy import sign
from numpy import sin
from numpy import sqrt
from numpy import unique1d
from numpy import unique
from numpy import vstack
from numpy import where
from numpy import zeros
@ -275,7 +275,7 @@ def _findcross(xn):
n = len(xn)
iz, = (xn == 0).nonzero()
if any(iz):
if len(iz)>0:
# Trick to avoid turning points on the crossinglevel.
if iz[0] == 0:
if len(iz) == n:
@ -283,14 +283,15 @@ def _findcross(xn):
return zeros(0, dtype=np.int)
diz = diff(iz)
ix = iz((diz > 1).argmax())
if not any(ix):
if len(diz)>0 and (diz>1).any():
ix = iz[(diz > 1).argmax()]
else:
ix = iz[-1]
#x(ix) is a up crossing if x(1:ix) = v and x(ix+1) > v.
#x(ix) is a downcrossing if x(1:ix) = v and x(ix+1) < v.
xn[0:ix] = -xn[ix + 1]
iz = iz[ix::]
xn[0:ix+1] = -xn[ix + 1]
iz = iz[ix+1::]
for ix in iz.tolist():
xn[ix] = xn[ix - 1]
@ -328,6 +329,8 @@ def findcross(x, v=0.0, kind=None):
-------
>>> from matplotlib import pylab as plb
>>> ones = plb.ones
>>> findcross([0, 1, -1, 1],0)
array([0, 1, 2])
>>> v = 0.75
>>> t = plb.linspace(0,7*plb.pi,250)
>>> x = plb.sin(t)
@ -988,7 +991,7 @@ def findoutliers(x, zcrit=0.0, dcrit=None, ddcrit=None, verbose=False):
indg = ones(xn.size, dtype=bool)
if ind.size > 1:
ind = unique1d(ind)
ind = unique(ind)
indg[ind] = 0
indg, = nonzero(indg)
@ -1862,8 +1865,8 @@ def tranproc(x, f, x0, *xi):
return y #y0,y1,y2,y3,y4
def test_find_cross():
t = findcross([0, 0, 1, -1, 1],0)
def test_common_shape():
@ -1979,8 +1982,8 @@ def _test_parse_kwargs():
print out1
if __name__ == "__main__":
if False: # True:#
if True:# False: #
import doctest
doctest.testmod()
else:
_test_discretize2()
test_find_cross()

Binary file not shown.

Binary file not shown.

@ -1,13 +1,13 @@
"""
Modify this file if another plotbackend is wanted.
"""
import warnings
if False:
try:
from scitools import easyviz as plotbackend
print('wafo.wafodata: plotbackend is set to scitools.easyviz')
except:
print('wafo: Unable to load scitools.easyviz as plotbackend')
warnings.warn('wafo: Unable to load scitools.easyviz as plotbackend')
plotbackend = None
else:
try:
@ -15,5 +15,5 @@ else:
plotbackend.interactive(True)
print('wafo.wafodata: plotbackend is set to matplotlib.pyplot')
except:
print('wafo: Unable to load matplotlib.pyplot as plotbackend')
warnings.warn('wafo: Unable to load matplotlib.pyplot as plotbackend')
plotbackend = None

Binary file not shown.

@ -140,13 +140,13 @@ void findcross(double *y, double v, int *ind, int n, int *info)
for (i=1; i<n; i++) {
start=i;
if ( y[i]< v){
ind[ix] = i; /* first crossing is a down crossing*/
ind[ix] = i-1; /* first crossing is a down crossing*/
ix++;
dcross=-1; /* The next crossing is a up-crossing*/
goto L120;
}
else if ( y[i]> v){
ind[ix] = i; /* first crossing is a up-crossing*/
ind[ix] = i-1; /* first crossing is a up-crossing*/
ix++;
dcross=1; /*The next crossing is a down-crossing*/
goto L120;

Loading…
Cancel
Save