# # Set up everything in S-Lang code and execute it from Perl # use strict; use Inline 'SLang'; # access the fit results from Perl # print "Now in perl\n"; my $res = get_par ("ptest"); print "Fit results:\n"; foreach my $par ( @{$res} ) { printf " parameter: %-15s ", $$par{name}; if ( $$par{frozen} ) { printf "[frozen at %g]\n", $$par{value}; } else { printf "value = %g\n", $$par{value}; } } __END__ __SLang__ require ("sherpa"); % The sin(x) term is just to make sure the values % do not exactly match a polynomial. % print ("Setting up a model"); variable x = [1:80:2] * 0.1; variable y = -10.5 - 2.5 * x + 4 * x^2 + sin(x); variable e = abs (y) * 0.1; () = set_axes (1,x); () = set_data (1,y); () = set_errors (1,e); print ("Setting up a model"); () = create_model ("polynom1d","ptest"); () = set_par ("ptest.c0", "thawed", 1); () = set_par ("ptest.c1", "thawed", 1); () = set_par ("ptest.c2", "thawed", 1); () = set_source_expr (1, "ptest"); print ("Fitting the model"); () = run_fit (1);