|
Next: COD Up: Fortran interface Previous: The DEMO program
A user functionThe calling sequences for the four subroutines required to create a user component are: SUBROUTINE UINFO(IPAR, CNAME, NPAR) INTEGER IPAR, NPAR CHARACTER CNAME*(*) C--- C IPAR I The parameter number. C CNAME O The name of the parameter IPAR. Note if IPAR=0, then C -return the name of the model. C NPAR O The number of parameters in your user model. C--- C********* SUBROUTINE ULIMIT(PVAL, PLIM, NT, NPAR) REAL PVAL(*), PLIM(3,*) INTEGER NT, NPAR C--- C PVAL(*) I/O The current parameter values C PLIM(1,*) I If <0 then the corresponding parameter is frozen C NT I Pointer to first parameter value in array PVAL(*) C NPAR I Number of parameters C--- C********* REAL FUNCTION UFNY(X, PVAL, NT, NPAR) REAL X, PVAL(*) INTEGER NT, NPAR C--- C X I The current X value C PVAL I The current parameter values C NT I Pointer to first parameter value in array PVAL(*) C NPAR I Number of parameters C--- C********* SUBROUTINE UDERIV(X, PVAL, PLIM, DERIV, NT, NPAR) REAL X, PVAL(*), PLIM(3,*), DERIV(*) INTEGER NT, NPAR C--- C X I The current X value C PVAL I The current parameter values C PLIM I The constraints array C DERIV O The calculated derivative C NT I Pointer to first parameter value in array PVAL(*) C NPAR I Number of parameters C---The file XANADU:[LIB.UFNY]UFNYDEMO.FOR contains the source
code for the built-in DEMO user component. You should copy
that file and use it as a template for any file that you create.
When FIT starts, it calls UINFO with
ULIMIT is always called after any parameter values have been changed
and before UFNY is called.
The purpose of ULIMIT is two-fold.
First, it should check the parameter values in
UFNY is the function that actually calculates user component at
location
UDERIV should calculate the derivative of the UFNY function with respect
to each parameter. The version contained in
If If you able to compute the analytic derivative of your function with respect to the parameter values, then you should use it, as an accurate derivative can greatly improve the fitting process. NOTE, slow convergence is most often due to the derivative being incorrectly calculated. If you find that c2 drops slowly, and that FIT is unable to precisely locate the minimum, then you should carefully check both your equations and the UDERIV implementation for typical errors, such as an incorrect sign. Once you have a working function, you should test it in PLT. Use the MOdel ? command to see if your component is listed. If not make sure you have linked a new version, and that your are running that new version. Next define a model that is composed only of your new component, and enter a resonable set of parameters. Do not attempt to fit at this time, but rather just plot the data and model. Use the Fit Plot 200 command to ensure that the function is evaluated at 200 points over the visible range. Is the plotted function what you expected? If it is not then you should carefully examine your code. Once the function is doing what you expect, then you can try to fit it. If certain parameter values can cause a program crash, then you should write a version of ULIMIT that prohibits these values.
Next: COD Up: Fortran interface Previous: The DEMO program
Web Page Maintained by: Dr. Lawrence E. Brown elwin@redshift.gsfc.nasa.gov |