Ejemplo n.º 1
0
// NewSpline creates a new Spline struct
func New(s SplineType, xa, ya []float64) (*Spline, error) {

	// Check inputs
	nx := len(xa)
	ny := len(ya)
	if nx != ny {
		return nil, fmt.Errorf("Incompatible dimensions in NewSpline: x(%d) != y(%d)", nx, ny)
	}

	// Convert type of spline
	sptype, err := convertSplineType(s)
	if err != nil {
		return nil, err
	}

	// Create a new object
	sp := new(Spline)
	sp.sp = C.gsl_spline_alloc(sptype, C.size_t(nx))
	sp.acc = C.gsl_interp_accel_alloc()

	// Initialize the spline object
	ret := C.gsl_spline_init(sp.sp, (*C.double)(&xa[0]), (*C.double)(&ya[0]), C.size_t(nx))
	if ret != 0 {
		return nil, gsl.Errno(ret)
	}

	return sp, nil
}
Ejemplo n.º 2
0
func SplineAlloc(t *GslInterpType, size int) *GslSpline {
	_ref := C.gsl_spline_alloc((*C.gsl_interp_type)(unsafe.Pointer(t.Ptr())), C.size_t(size))
	_result := &GslSpline{}
	gogsl.InitializeGslReference(_result, uintptr(unsafe.Pointer(_ref)))
	return _result
}