defc.f 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. *DECK DEFC
  2. SUBROUTINE DEFC (NDATA, XDATA, YDATA, SDDATA, NORD, NBKPT, BKPT,
  3. + MDEIN, MDEOUT, COEFF, LW, W)
  4. C***BEGIN PROLOGUE DEFC
  5. C***PURPOSE Fit a piecewise polynomial curve to discrete data.
  6. C The piecewise polynomials are represented as B-splines.
  7. C The fitting is done in a weighted least squares sense.
  8. C***LIBRARY SLATEC
  9. C***CATEGORY K1A1A1, K1A2A, L8A3
  10. C***TYPE DOUBLE PRECISION (EFC-S, DEFC-D)
  11. C***KEYWORDS B-SPLINE, CONSTRAINED LEAST SQUARES, CURVE FITTING
  12. C***AUTHOR Hanson, R. J., (SNLA)
  13. C***DESCRIPTION
  14. C
  15. C This subprogram fits a piecewise polynomial curve
  16. C to discrete data. The piecewise polynomials are
  17. C represented as B-splines.
  18. C The fitting is done in a weighted least squares sense.
  19. C
  20. C The data can be processed in groups of modest size.
  21. C The size of the group is chosen by the user. This feature
  22. C may be necessary for purposes of using constrained curve fitting
  23. C with subprogram DFC( ) on a very large data set.
  24. C
  25. C For a description of the B-splines and usage instructions to
  26. C evaluate them, see
  27. C
  28. C C. W. de Boor, Package for Calculating with B-Splines.
  29. C SIAM J. Numer. Anal., p. 441, (June, 1977).
  30. C
  31. C For further discussion of (constrained) curve fitting using
  32. C B-splines, see
  33. C
  34. C R. J. Hanson, Constrained Least Squares Curve Fitting
  35. C to Discrete Data Using B-Splines, a User's
  36. C Guide. Sandia Labs. Tech. Rept. SAND-78-1291,
  37. C December, (1978).
  38. C
  39. C Input.. All TYPE REAL variables are DOUBLE PRECISION
  40. C NDATA,XDATA(*),
  41. C YDATA(*),
  42. C SDDATA(*)
  43. C The NDATA discrete (X,Y) pairs and the Y value
  44. C standard deviation or uncertainty, SD, are in
  45. C the respective arrays XDATA(*), YDATA(*), and
  46. C SDDATA(*). No sorting of XDATA(*) is
  47. C required. Any non-negative value of NDATA is
  48. C allowed. A negative value of NDATA is an
  49. C error. A zero value for any entry of
  50. C SDDATA(*) will weight that data point as 1.
  51. C Otherwise the weight of that data point is
  52. C the reciprocal of this entry.
  53. C
  54. C NORD,NBKPT,
  55. C BKPT(*)
  56. C The NBKPT knots of the B-spline of order NORD
  57. C are in the array BKPT(*). Normally the
  58. C problem data interval will be included between
  59. C the limits BKPT(NORD) and BKPT(NBKPT-NORD+1).
  60. C The additional end knots BKPT(I),I=1,...,
  61. C NORD-1 and I=NBKPT-NORD+2,...,NBKPT, are
  62. C required to compute the functions used to fit
  63. C the data. No sorting of BKPT(*) is required.
  64. C Internal to DEFC( ) the extreme end knots may
  65. C be reduced and increased respectively to
  66. C accommodate any data values that are exterior
  67. C to the given knot values. The contents of
  68. C BKPT(*) is not changed.
  69. C
  70. C NORD must be in the range 1 .LE. NORD .LE. 20.
  71. C The value of NBKPT must satisfy the condition
  72. C NBKPT .GE. 2*NORD.
  73. C Other values are considered errors.
  74. C
  75. C (The order of the spline is one more than the
  76. C degree of the piecewise polynomial defined on
  77. C each interval. This is consistent with the
  78. C B-spline package convention. For example,
  79. C NORD=4 when we are using piecewise cubics.)
  80. C
  81. C MDEIN
  82. C An integer flag, with one of two possible
  83. C values (1 or 2), that directs the subprogram
  84. C action with regard to new data points provided
  85. C by the user.
  86. C
  87. C =1 The first time that DEFC( ) has been
  88. C entered. There are NDATA points to process.
  89. C
  90. C =2 This is another entry to DEFC(). The sub-
  91. C program DEFC( ) has been entered with MDEIN=1
  92. C exactly once before for this problem. There
  93. C are NDATA new additional points to merge and
  94. C process with any previous points.
  95. C (When using DEFC( ) with MDEIN=2 it is import-
  96. C ant that the set of knots remain fixed at the
  97. C same values for all entries to DEFC( ).)
  98. C LW
  99. C The amount of working storage actually
  100. C allocated for the working array W(*).
  101. C This quantity is compared with the
  102. C actual amount of storage needed in DEFC( ).
  103. C Insufficient storage allocated for W(*) is
  104. C an error. This feature was included in DEFC
  105. C because misreading the storage formula
  106. C for W(*) might very well lead to subtle
  107. C and hard-to-find programming bugs.
  108. C
  109. C The length of the array W(*) must satisfy
  110. C
  111. C LW .GE. (NBKPT-NORD+3)*(NORD+1)+
  112. C (NBKPT+1)*(NORD+1)+
  113. C 2*MAX(NDATA,NBKPT)+NBKPT+NORD**2
  114. C
  115. C Output.. All TYPE REAL variables are DOUBLE PRECISION
  116. C MDEOUT
  117. C An output flag that indicates the status
  118. C of the curve fit.
  119. C
  120. C =-1 A usage error of DEFC( ) occurred. The
  121. C offending condition is noted with the SLATEC
  122. C library error processor, XERMSG( ). In case
  123. C the working array W(*) is not long enough, the
  124. C minimal acceptable length is printed.
  125. C
  126. C =1 The B-spline coefficients for the fitted
  127. C curve have been returned in array COEFF(*).
  128. C
  129. C =2 Not enough data has been processed to
  130. C determine the B-spline coefficients.
  131. C The user has one of two options. Continue
  132. C to process more data until a unique set
  133. C of coefficients is obtained, or use the
  134. C subprogram DFC( ) to obtain a specific
  135. C set of coefficients. The user should read
  136. C the usage instructions for DFC( ) for further
  137. C details if this second option is chosen.
  138. C COEFF(*)
  139. C If the output value of MDEOUT=1, this array
  140. C contains the unknowns obtained from the least
  141. C squares fitting process. These N=NBKPT-NORD
  142. C parameters are the B-spline coefficients.
  143. C For MDEOUT=2, not enough data was processed to
  144. C uniquely determine the B-spline coefficients.
  145. C In this case, and also when MDEOUT=-1, all
  146. C values of COEFF(*) are set to zero.
  147. C
  148. C If the user is not satisfied with the fitted
  149. C curve returned by DEFC( ), the constrained
  150. C least squares curve fitting subprogram DFC( )
  151. C may be required. The work done within DEFC( )
  152. C to accumulate the data can be utilized by
  153. C the user, if so desired. This involves
  154. C saving the first (NBKPT-NORD+3)*(NORD+1)
  155. C entries of W(*) and providing this data
  156. C to DFC( ) with the "old problem" designation.
  157. C The user should read the usage instructions
  158. C for subprogram DFC( ) for further details.
  159. C
  160. C Working Array.. All TYPE REAL variables are DOUBLE PRECISION
  161. C W(*)
  162. C This array is typed DOUBLE PRECISION.
  163. C Its length is specified as an input parameter
  164. C in LW as noted above. The contents of W(*)
  165. C must not be modified by the user between calls
  166. C to DEFC( ) with values of MDEIN=1,2,2,... .
  167. C The first (NBKPT-NORD+3)*(NORD+1) entries of
  168. C W(*) are acceptable as direct input to DFC( )
  169. C for an "old problem" only when MDEOUT=1 or 2.
  170. C
  171. C Evaluating the
  172. C Fitted Curve..
  173. C To evaluate derivative number IDER at XVAL,
  174. C use the function subprogram DBVALU( ).
  175. C
  176. C F = DBVALU(BKPT,COEFF,NBKPT-NORD,NORD,IDER,
  177. C XVAL,INBV,WORKB)
  178. C
  179. C The output of this subprogram will not be
  180. C defined unless an output value of MDEOUT=1
  181. C was obtained from DEFC( ), XVAL is in the data
  182. C interval, and IDER is nonnegative and .LT.
  183. C NORD.
  184. C
  185. C The first time DBVALU( ) is called, INBV=1
  186. C must be specified. This value of INBV is the
  187. C overwritten by DBVALU( ). The array WORKB(*)
  188. C must be of length at least 3*NORD, and must
  189. C not be the same as the W(*) array used in the
  190. C call to DEFC( ).
  191. C
  192. C DBVALU( ) expects the breakpoint array BKPT(*)
  193. C to be sorted.
  194. C
  195. C***REFERENCES R. J. Hanson, Constrained least squares curve fitting
  196. C to discrete data using B-splines, a users guide,
  197. C Report SAND78-1291, Sandia Laboratories, December
  198. C 1978.
  199. C***ROUTINES CALLED DEFCMN
  200. C***REVISION HISTORY (YYMMDD)
  201. C 800801 DATE WRITTEN
  202. C 890531 Changed all specific intrinsics to generic. (WRB)
  203. C 890531 REVISION DATE from Version 3.2
  204. C 891214 Prologue converted to Version 4.0 format. (BAB)
  205. C 900510 Change Prologue comments to refer to XERMSG. (RWC)
  206. C 900607 Editorial changes to Prologue to make Prologues for EFC,
  207. C DEFC, FC, and DFC look as much the same as possible. (RWC)
  208. C 920501 Reformatted the REFERENCES section. (WRB)
  209. C***END PROLOGUE DEFC
  210. C
  211. C SUBROUTINE FUNCTION/REMARKS
  212. C
  213. C DBSPVN( ) COMPUTE FUNCTION VALUES OF B-SPLINES. FROM
  214. C THE B-SPLINE PACKAGE OF DE BOOR NOTED ABOVE.
  215. C
  216. C DBNDAC( ), BANDED LEAST SQUARES MATRIX PROCESSORS.
  217. C DBNDSL( ) FROM LAWSON-HANSON, SOLVING LEAST
  218. C SQUARES PROBLEMS.
  219. C
  220. C DSORT( ) DATA SORTING SUBROUTINE, FROM THE
  221. C SANDIA MATH. LIBRARY, SAND77-1441.
  222. C
  223. C XERMSG( ) ERROR HANDLING ROUTINE
  224. C FOR THE SLATEC MATH. LIBRARY.
  225. C SEE SAND78-1189, BY R. E. JONES.
  226. C
  227. C DCOPY( ),DSCAL( ) SUBROUTINES FROM THE BLAS PACKAGE.
  228. C
  229. C WRITTEN BY R. HANSON, SANDIA NATL. LABS.,
  230. C ALB., N. M., AUGUST-SEPTEMBER, 1980.
  231. C
  232. DOUBLE PRECISION BKPT(*),COEFF(*),W(*),SDDATA(*),XDATA(*),YDATA(*)
  233. INTEGER LW, MDEIN, MDEOUT, NBKPT, NDATA, NORD
  234. C
  235. EXTERNAL DEFCMN
  236. C
  237. INTEGER LBF, LBKPT, LG, LPTEMP, LWW, LXTEMP, MDG, MDW
  238. C
  239. C***FIRST EXECUTABLE STATEMENT DEFC
  240. C LWW=1 USAGE IN DEFCMN( ) OF W(*)..
  241. C LWW,...,LG-1 W(*,*)
  242. C
  243. C LG,...,LXTEMP-1 G(*,*)
  244. C
  245. C LXTEMP,...,LPTEMP-1 XTEMP(*)
  246. C
  247. C LPTEMP,...,LBKPT-1 PTEMP(*)
  248. C
  249. C LBKPT,...,LBF BKPT(*) (LOCAL TO DEFCMN( ))
  250. C
  251. C LBF,...,LBF+NORD**2 BF(*,*)
  252. C
  253. MDG = NBKPT+1
  254. MDW = NBKPT-NORD+3
  255. LWW = 1
  256. LG = LWW + MDW*(NORD+1)
  257. LXTEMP = LG + MDG*(NORD+1)
  258. LPTEMP = LXTEMP + MAX(NDATA,NBKPT)
  259. LBKPT = LPTEMP + MAX(NDATA,NBKPT)
  260. LBF = LBKPT + NBKPT
  261. CALL DEFCMN(NDATA,XDATA,YDATA,SDDATA,
  262. 1 NORD,NBKPT,BKPT,
  263. 2 MDEIN,MDEOUT,
  264. 3 COEFF,
  265. 4 W(LBF),W(LXTEMP),W(LPTEMP),W(LBKPT),
  266. 5 W(LG),MDG,W(LWW),MDW,LW)
  267. RETURN
  268. END