forked from landreman/regcoil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
splines.f90
4342 lines (4240 loc) · 127 KB
/
splines.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module splines
use stel_kinds
implicit none
private
public :: spline, periodic_spline
public :: new_spline, delete_spline
public :: new_periodic_spline, delete_periodic_spline
public :: splint, dsplint, periodic_splint
public :: inter_d_cspl, inter_cspl
public :: fitp_curv1, fitp_curvp1
public :: fitp_curv2, fitp_curvp2
public :: fitp_surf1, fitp_surf2
public :: lf_spline, fitp_curvd
type :: spline
integer :: n
real(dp), dimension (:), pointer :: x, y, y2
end type spline
type :: periodic_spline
integer :: n
real(dp) :: period
real(dp), dimension (:), pointer :: x, y, y2
end type periodic_spline
contains
subroutine new_spline (n, x, y, spl)
implicit none
integer, intent (in) :: n
real(dp), dimension (n), intent (in) :: x, y
type (spline), intent (out) :: spl
real(dp), dimension (n) :: temp
integer :: ierr
spl%n = n
allocate (spl%x(n),spl%y(n))
spl%x = x
spl%y = y
allocate (spl%y2(n))
call fitp_curv1 (n, x, y, 0.0_dp, 0.0_dp, 3, spl%y2, temp, 1.0_dp, ierr)
end subroutine new_spline
subroutine new_periodic_spline (n, x, y, period, spl)
implicit none
integer, intent (in) :: n
real(dp), dimension (n), intent (in) :: x, y
real(dp), intent (in) :: period
type (periodic_spline), intent (out) :: spl
real(dp), dimension (2*n) :: temp
integer :: ierr
spl%n = n
spl%period = period
allocate (spl%x(n),spl%y(n))
spl%x = x
spl%y = y
allocate (spl%y2(n))
call fitp_curvp1 (n,x,y,period,spl%y2,temp,1.0_dp,ierr)
end subroutine new_periodic_spline
subroutine delete_spline (spl)
implicit none
type (spline), intent (in out) :: spl
spl%n = 0
deallocate (spl%x,spl%y)
nullify (spl%x)
nullify (spl%y)
deallocate (spl%y2)
nullify (spl%y2)
end subroutine delete_spline
subroutine delete_periodic_spline (spl)
implicit none
type (periodic_spline), intent (in out) :: spl
spl%n = 0
spl%period = 0.0_dp
deallocate (spl%x,spl%y)
nullify (spl%x)
nullify (spl%y)
deallocate (spl%y2)
nullify (spl%y2)
end subroutine delete_periodic_spline
function splint (x, spl)
implicit none
real(dp), intent (in) :: x
type (spline), intent (in) :: spl
real(dp) :: splint
splint = fitp_curv2 (x, spl%n, spl%x, spl%y, spl%y2, 1.0_dp)
end function splint
function periodic_splint (x, spl)
implicit none
real(dp), intent (in) :: x
type (periodic_spline), intent (in) :: spl
real(dp) :: periodic_splint
periodic_splint = fitp_curvp2 &
(x, spl%n, spl%x, spl%y, spl%period, spl%y2, 1.0_dp)
end function periodic_splint
function dsplint (x, spl)
implicit none
real(dp), intent (in) :: x
type (spline), intent (in) :: spl
real(dp) :: dsplint
dsplint = fitp_curvd (x, spl%n, spl%x, spl%y, spl%y2, 1.0_dp)
end function dsplint
function splintint (x0, x1, spl)
implicit none
real(dp), intent (in) :: x0, x1
type (spline), intent (in) :: spl
real(dp) :: splintint
splintint = fitp_curvi (x0,x1,spl%n,spl%x,spl%y,spl%y2,1.0_dp)
end function splintint
function periodic_splintint (x0, x1, spl)
implicit none
real(dp), intent (in) :: x0, x1
type (periodic_spline), intent (in) :: spl
real(dp) :: periodic_splintint
periodic_splintint = fitp_curvpi &
(x0,x1,spl%n,spl%x,spl%y,spl%period,spl%y2, 1.0_dp)
end function periodic_splintint
subroutine inter_d_cspl(n,r,data,m,x,dint,ddint)
implicit none
integer, intent(in) :: n, m
real(dp), dimension(n), intent(in) :: r, data
real(dp), dimension(m), intent(in) :: x
real(dp), dimension(m), intent(out) :: dint, ddint
integer, parameter :: max=1000
real(dp), dimension(max) :: ddata, temp
integer :: i,ierr
if (n .gt. max) then
write (*,*) 'error in inter_d_cspl'
write (*,*) 'increase max'
stop
endif
ierr = 0
call fitp_curv1(n,r,data,0.0_dp,0.0_dp,3,ddata,temp,1.0_dp,ierr)
if (ierr .ne. 0) then
if (ierr .eq. 1) then
write (*,*) 'FITPACK: curv1 error: n < 2'
elseif (ierr .eq. 2) then
write (*,*) 'FITPACK: curv1 error: x-values not increasing'
else
write (*,*) 'FITPACK: curv1 error'
endif
stop
endif
do i=1,m
dint(i) = fitp_curv2 (x(i),n,r,data,ddata,1.0_dp)
ddint(i)= fitp_curvd (x(i),n,r,data,ddata,1.0_dp)
enddo
end subroutine inter_d_cspl
subroutine inter_cspl(n,r,data,m,x,dint)
implicit none
integer, intent(in) :: n, m
real(dp), dimension(n), intent(in) :: r, data
real(dp), dimension(m), intent(in) :: x
real(dp), dimension(m), intent(out) :: dint
integer, parameter :: max=1000
real(dp), dimension(max) :: ddata, temp
integer :: i,ierr
if (n .gt. max) then
write (*,*) 'error in inter_cspl'
write (*,*) 'increase max'
stop
endif
ierr = 0
call fitp_curv1(n,r,data,0.0_dp,0.0_dp,3,ddata,temp,1.0_dp,ierr)
if (ierr .ne. 0) then
if (ierr .eq. 1) then
write (*,*) 'FITPACK: curv1 error: n < 2'
elseif (ierr .eq. 2) then
write (*,*) 'FITPACK: curv1 error: x-values not increasing'
else
write (*,*) 'FITPACK: curv1 error'
endif
stop
endif
do i=1,m
dint(i) = fitp_curv2 (x(i),n,r,data,ddata,1.0_dp)
enddo
end subroutine inter_cspl
subroutine inter_getspl (n, x, y, y2)
implicit none
integer, intent(in) :: n
real(dp), dimension(:), intent(in) :: x, y
real(dp), dimension(:), intent(out) :: y2
integer, parameter :: max=1000
real(dp), dimension(max) :: temp
integer :: ierr
if (n .gt. max) then
write (*,*) 'error in inter_getspl'
write (*,*) 'increase max'
stop
endif
ierr = 0
call fitp_curv1(n,x,y,0.0_dp,0.0_dp,3,y2,temp,1.0_dp,ierr)
if (ierr .ne. 0) then
if (ierr .eq. 1) then
write (*,*) 'FITPACK: curv1 error: n < 2'
elseif (ierr .eq. 2) then
write (*,*) 'FITPACK: curv1 error: x-values not increasing'
else
write (*,*) 'FITPACK: curv1 error'
endif
stop
endif
end subroutine inter_getspl
real(dp) function inter_splint (x0, n, x, y, y2)
real(dp), intent(in) :: x0
integer, intent(in) :: n
real(dp), dimension(n), intent(in) :: x, y, y2
inter_splint = fitp_curv2 (x0, n, x, y, y2, 1.0_dp)
end function inter_splint
real(dp) function inter_dsplint (x0, n, x, y, y2)
real(dp), intent(in) :: x0
integer, intent(in) :: n
real(dp), dimension(n), intent(in) :: x, y, y2
inter_dsplint = fitp_curvd (x0, n, x, y, y2, 1.0_dp)
end function inter_dsplint
real(dp) function inter_d2splint (x0, n, x, y, y2)
real(dp), intent(in) :: x0
integer, intent(in) :: n
real(dp), dimension(n), intent(in) :: x, y, y2
real(dp) :: yx(500)
data yx(1)/1.0_dp/
save yx
integer :: i
if (yx(1) .ne. 0.0_dp) then
do i=1,500
yx(i) = 0.0_dp
enddo
endif
inter_d2splint = fitp_curv2 (x0, n, x, y2, yx, 1e5_dp)
end function inter_d2splint
subroutine inter_getpspl (n, x, p, y, y2)
implicit none
integer, intent(in) :: n
real(dp), dimension(n), intent(in) :: x, y
real(dp), dimension(n), intent(out) :: y2
real(dp), intent(in) :: p
integer, parameter :: max=1000
real(dp), dimension(max) :: temp
integer :: ierr
if (n .gt. max) then
write (*,*) 'error in inter_getpspl'
write (*,*) 'increase max'
stop
endif
ierr=0
call fitp_curvp1(n,x,y,p,y2,temp,1.0_dp,ierr)
if (ierr .ne. 0) then
if (ierr .eq. 1) then
write (*,*) 'FITPACK: curvp1 error: n < 2'
elseif (ierr .eq. 2) then
write (*,*) 'FITPACK: curvp1 error: p <= x(n)-x(1)'
elseif (ierr .eq. 3) then
write (*,*) 'FITPACK: curvp1 error: x-values not increasing'
else
write (*,*) 'FITPACK: curv1 error'
endif
stop
endif
end subroutine inter_getpspl
real(dp) function inter_psplint (x0, n, x, p, y, y2)
real(dp), intent(in) :: x0
real(dp), intent(in) :: p
integer, intent(in) :: n
real(dp), dimension(n), intent(in) :: x, y, y2
inter_psplint = fitp_curvp2 (x0, n, x, y, p, y2, 1.0_dp)
end function inter_psplint
real(dp) function inter_pdsplint (x0, n, x, p, y, y2)
real(dp), intent(in) :: x0
real(dp), intent(in) :: p
integer, intent(in) :: n
real(dp), dimension(n), intent(in) :: x, y, y2
inter_pdsplint = fitp_curvpd (x0, n, x, y, p, y2, 1.0_dp)
end function inter_pdsplint
! From inet!cs.utexas.edu!cline Tue Oct 31 17:10:31 CST 1989
! Received: from mojave.cs.utexas.edu by cs.utexas.edu (5.59/1.44)
! id AA29509; Tue, 31 Oct 89 17:11:51 CST
! Posted-Date: Tue, 31 Oct 89 17:10:31 CST
! Message-Id: <8910312310.AA04442@mojave.cs.utexas.edu>
! Received: by mojave.cs.utexas.edu (14.5/1.4-Client)
! id AA04442; Tue, 31 Oct 89 17:10:34 cst
! Date: Tue, 31 Oct 89 17:10:31 CST
! X-Mailer: Mail User's Shell (6.5 4/17/89)
! From: cline@cs.utexas.edu (Alan Cline)
! To: ehg@research.att.com
! Subject: New FITPACK Subset for netlib
!
!
! This new version of FITPACK distributed by netlib is about 20% of
! the total package in terms of characters, lines of code, and num-
! ber of subprograms. However, these 25 subprograms represent about
! 95% of usages of the package. What has been omitted are such ca-
! pabilities as:
! 1. Automatic tension determination,
! 2. Derivatives, arclengths, and enclosed areas for planar
! curves,
! 3. Three dimensional curves,
! 4. Special surface fitting using equispacing assumptions,
! 5. Surface fitting in annular, wedge, polar, toroidal, lunar,
! and spherical geometries,
! 6. B-splines in tension generation and usage,
! 7. General surface fitting in three dimensional space.
!
! (The code previously circulated in netlib is less than 10% of the
! total package and is more than a decade old. Its usage is dis-
! couraged.)
!
! Please note: Two versions of the subroutine snhcsh are included.
! Both serve the same purpose: obtaining approximations to certain
! hyperbolic trigonometric-like functions. The first is less accu-
! rate (but more efficient) than the second. Installers should se-
! lect the one with the precision they desire.
!
! Interested parties can obtain the entire package on disk or tape
! from Pleasant Valley Software, 8603 Altus Cove, Austin TX (USA),
! 78759 at a cost of $495 US. A 340 page manual is available for
! $30 US per copy. The package includes examples and machine
! readable documentation.
subroutine fitp_curv1 (n,x,y,slp1,slpn,islpsw,yp,temp,sigma,ierr)
implicit none
integer, intent(in) :: n, islpsw
integer, intent(out) :: ierr
real(dp), dimension(n), intent(in) :: x, y
real(dp), dimension(n), intent(out) :: yp, temp
real(dp), intent(in) :: slp1,slpn,sigma
!
! coded by alan kaylor cline
! from fitpack -- january 26, 1987
! a curve and surface fitting package
! a product of pleasant valley software
! 8603 altus cove, austin, texas 78759, usa
!
! this subroutine determines the parameters necessary to
! compute an interpolatory spline under tension through
! a sequence of functional values. the slopes at the two
! ends of the curve may be specified or omitted. for actual
! computation of points on the curve it is necessary to call
! the function curv2.
!
! on input--
!
! n is the number of values to be interpolated (n.ge.2).
!
! x is an array of the n increasing abscissae of the
! functional values.
!
! y is an array of the n ordinates of the values, (i. e.
! y(k) is the functional value corresponding to x(k) ).
!
! slp1 and slpn contain the desired values for the first
! derivative of the curve at x(1) and x(n), respectively.
! the user may omit values for either or both of these
! parameters and signal this with islpsw.
!
! islpsw contains a switch indicating which slope data
! should be used and which should be estimated by this
! subroutine,
! = 0 if slp1 and slpn are to be used,
! = 1 if slp1 is to be used but not slpn,
! = 2 if slpn is to be used but not slp1,
! = 3 if both slp1 and slpn are to be estimated
! internally.
!
! yp is an array of length at least n.
!
! temp is an array of length at least n which is used for
! scratch storage.
!
! and
!
! sigma contains the tension factor. this value indicates
! the curviness desired. if abs(sigma) is nearly zero
! (e.g. .001) the resulting curve is approximately a
! cubic spline. if abs(sigma) is large (e.g. 50.) the
! resulting curve is nearly a polygonal line. if sigma
! equals zero a cubic spline results. a standard value
! for sigma is approximately 1. in absolute value.
!
! on output--
!
! yp contains the values of the second derivative of the
! curve at the given nodes.
!
! ierr contains an error flag,
! = 0 for normal return,
! = 1 if n is less than 2,
! = 2 if x-values are not strictly increasing.
!
! and
!
! n, x, y, slp1, slpn, islpsw and sigma are unaltered.
!
! this subroutine references package modules ceez, terms,
! and snhcsh.
!
!-----------------------------------------------------------
integer :: i, ibak, nm1, np1
real(dp) :: sdiag1, diag1, delxnm, dx1, diag, sdiag2, dx2, diag2
real(dp) :: delxn, slpp1, delx1, sigmap, c3, c2, c1, slppn, delx2
nm1 = n-1
np1 = n+1
ierr = 0
if (n .le. 1) go to 8
if (x(n) .le. x(1)) go to 9
!
! denormalize tension factor
!
sigmap = abs(sigma)*real(n-1,dp)/(x(n)-x(1))
!
! approximate end slopes
!
if (islpsw .ge. 2) go to 1
slpp1 = slp1
go to 2
1 delx1 = x(2)-x(1)
delx2 = delx1+delx1
if (n .gt. 2) delx2 = x(3)-x(1)
if (delx1 .le. 0. .or. delx2 .le. delx1) go to 9
call fitp_ceez (delx1,delx2,sigmap,c1,c2,c3,n)
slpp1 = c1*y(1)+c2*y(2)
if (n .gt. 2) slpp1 = slpp1+c3*y(3)
2 if (islpsw .eq. 1 .or. islpsw .eq. 3) go to 3
slppn = slpn
go to 4
3 delxn = x(n)-x(nm1)
delxnm = delxn+delxn
if (n .gt. 2) delxnm = x(n)-x(n-2)
if (delxn .le. 0. .or. delxnm .le. delxn) go to 9
call fitp_ceez (-delxn,-delxnm,sigmap,c1,c2,c3,n)
slppn = c1*y(n)+c2*y(nm1)
if (n .gt. 2) slppn = slppn+c3*y(n-2)
!
! set up right hand side and tridiagonal system for yp and
! perform forward elimination
!
4 delx1 = x(2)-x(1)
if (delx1 .le. 0.) go to 9
dx1 = (y(2)-y(1))/delx1
call fitp_terms (diag1,sdiag1,sigmap,delx1)
yp(1) = (dx1-slpp1)/diag1
temp(1) = sdiag1/diag1
if (n .eq. 2) go to 6
do i = 2,nm1
delx2 = x(i+1)-x(i)
if (delx2 .le. 0.) go to 9
dx2 = (y(i+1)-y(i))/delx2
call fitp_terms (diag2,sdiag2,sigmap,delx2)
diag = diag1+diag2-sdiag1*temp(i-1)
yp(i) = (dx2-dx1-sdiag1*yp(i-1))/diag
temp(i) = sdiag2/diag
dx1 = dx2
diag1 = diag2
sdiag1 = sdiag2
end do
6 diag = diag1-sdiag1*temp(nm1)
yp(n) = (slppn-dx1-sdiag1*yp(nm1))/diag
!
! perform back substitution
!
do i = 2,n
ibak = np1-i
yp(ibak) = yp(ibak)-temp(ibak)*yp(ibak+1)
end do
return
!
! too few points
!
8 ierr = 1
return
!
! x-values not strictly increasing
!
9 ierr = 2
return
end subroutine fitp_curv1
subroutine fitp_curvs (n,x,y,d,isw,s,eps,ys,ysp,sigma,temp,ierr)
implicit none
integer, intent(in) :: n, isw
integer, intent(out) :: ierr
real(dp), dimension(n), intent(in) :: x, y, d
real(dp), dimension(n,9), intent(out) :: temp
real(dp), dimension(n), intent(out) :: ys, ysp
real(dp), intent(in) :: sigma,s,eps
!
! coded by alan kaylor cline
! from fitpack -- january 26, 1987
! a curve and surface fitting package
! a product of pleasant valley software
! 8603 altus cove, austin, texas 78759, usa
!
! this subroutine determines the parameters necessary to
! compute a smoothing spline under tension. for a given
! increasing sequence of abscissae (x(i)), i = 1,..., n and
! associated ordinates (y(i)), i = 1,..., n, the function
! determined minimizes the summation from i = 1 to n-1 of
! the square of the second derivative of f plus sigma
! squared times the difference of the first derivative of f
! and (f(x(i+1))-f(x(i)))/(x(i+1)-x(i)) squared, over all
! functions f with two continuous derivatives such that the
! summation of the square of (f(x(i))-y(i))/d(i) is less
! than or equal to a given constant s, where (d(i)), i = 1,
! ..., n are a given set of observation weights. the
! function determined is a spline under tension with third
! derivative discontinuities at (x(i)), i = 2,..., n-1. for
! actual computation of points on the curve it is necessary
! to call the function curv2. the determination of the curve
! is performed by subroutine curvss, the subroutine curvs
! only decomposes the workspace for curvss.
!
! on input--
!
! n is the number of values to be smoothed (n.ge.2).
!
! x is an array of the n increasing abscissae of the
! values to be smoothed.
!
! y is an array of the n ordinates of the values to be
! smoothed, (i. e. y(k) is the functional value
! corresponding to x(k) ).
!
! d is a parameter containing the observation weights.
! this may either be an array of length n or a scalar
! (interpreted as a constant). the value of d
! corresponding to the observation (x(k),y(k)) should
! be an approximation to the standard deviation of error.
!
! isw contains a switch indicating whether the parameter
! d is to be considered a vector or a scalar,
! = 0 if d is an array of length n,
! = 1 if d is a scalar.
!
! s contains the value controlling the smoothing. this
! must be non-negative. for s equal to zero, the
! subroutine does interpolation, larger values lead to
! smoother funtions. if parameter d contains standard
! deviation estimates, a reasonable value for s is
! float(n).
!
! eps contains a tolerance on the relative precision to
! which s is to be interpreted. this must be greater than
! or equal to zero and less than or equal to one. a
! reasonable value for eps is sqrt(2./float(n)).
!
! ys is an array of length at least n.
!
! ysp is an array of length at least n.
!
! sigma contains the tension factor. this value indicates
! the degree to which the first derivative part of the
! smoothing functional is emphasized. if sigma is nearly
! zero (e. g. .001) the resulting curve is approximately a
! cubic spline. if sigma is large (e. g. 50.) the
! resulting curve is nearly a polygonal line. if sigma
! equals zero a cubic spline results. a standard value for
! sigma is approximately 1.
!
! and
!
! temp is an array of length at least 9*n which is used
! for scratch storage.
!
! on output--
!
! ys contains the smoothed ordinate values.
!
! ysp contains the values of the second derivative of the
! smoothed curve at the given nodes.
!
! ierr contains an error flag,
! = 0 for normal return,
! = 1 if n is less than 2,
! = 2 if s is negative,
! = 3 if eps is negative or greater than one,
! = 4 if x-values are not strictly increasing,
! = 5 if a d-value is non-positive.
!
! and
!
! n, x, y, d, isw, s, eps, and sigma are unaltered.
!
! this subroutine references package modules curvss, terms,
! and snhcsh.
!
!-----------------------------------------------------------
!
! decompose temp into nine arrays and call curvss
!
call fitp_curvss (n,x,y,d,isw,s,eps,ys,ysp,sigma,temp(1,1), &
temp(1,2),temp(1,3),temp(1,4),temp(1,5), &
temp(1,6),temp(1,7),temp(1,8),temp(1,9), &
ierr)
end subroutine fitp_curvs
real(dp) function fitp_curv2 (t,n,x,y,yp,sigma)
implicit none
integer, intent(in) :: n
real(dp), dimension(n), intent(in) :: x, y, yp
real(dp), intent(in) :: t, sigma
!
! coded by alan kaylor cline
! from fitpack -- january 26, 1987
! a curve and surface fitting package
! a product of pleasant valley software
! 8603 altus cove, austin, texas 78759, usa
!
! this function interpolates a curve at a given point
! using a spline under tension. the subroutine curv1 should
! be called earlier to determine certain necessary
! parameters.
!
! on input--
!
! t contains a real value to be mapped onto the interpo-
! lating curve.
!
! n contains the number of points which were specified to
! determine the curve.
!
! x and y are arrays containing the abscissae and
! ordinates, respectively, of the specified points.
!
! yp is an array of second derivative values of the curve
! at the nodes.
!
! and
!
! sigma contains the tension factor (its sign is ignored).
!
! the parameters n, x, y, yp, and sigma should be input
! unaltered from the output of curv1.
!
! on output--
!
! curv2 contains the interpolated value.
!
! none of the input parameters are altered.
!
! this function references package modules intrvl and
! snhcsh.
!
!-----------------------------------------------------------
integer :: i, im1
real(dp) :: ss, sigdel, dummy, s1, s2, sum, sigmap
real(dp) :: del1, del2, dels
!
! determine interval
!
im1 = fitp_intrvl(t,x,n)
i = im1+1
!
! denormalize tension factor
!
sigmap = abs(sigma)*real(n-1,dp)/(x(n)-x(1))
!
! set up and perform interpolation
!
del1 = t-x(im1)
del2 = x(i)-t
dels = x(i)-x(im1)
sum = (y(i)*del1+y(im1)*del2)/dels
if (sigmap .ne. 0.) go to 1
fitp_curv2 = sum-del1*del2*(yp(i)*(del1+dels)+yp(im1)*(del2+dels))/(6.*dels)
return
1 sigdel = sigmap*dels
call fitp_snhcsh (ss,dummy,sigdel,-1)
call fitp_snhcsh (s1,dummy,sigmap*del1,-1)
call fitp_snhcsh (s2,dummy,sigmap*del2,-1)
fitp_curv2 = sum+(yp(i)*del1*(s1-ss)+yp(im1)*del2*(s2-ss))/(sigdel*sigmap*(1.+ss))
return
end function fitp_curv2
real(dp) function fitp_curvd (t,n,x,y,yp,sigma)
implicit none
integer, intent(in) :: n
real(dp), dimension(n), intent(in) :: x, y, yp
real(dp), intent(in) :: t, sigma
!
! coded by alan kaylor cline
! from fitpack -- january 26, 1987
! a curve and surface fitting package
! a product of pleasant valley software
! 8603 altus cove, austin, texas 78759, usa
!
! this function differentiates a curve at a given point
! using a spline under tension. the subroutine curv1 should
! be called earlier to determine certain necessary
! parameters.
!
! on input--
!
! t contains a real value at which the derivative is to be
! determined.
!
! n contains the number of points which were specified to
! determine the curve.
!
! x and y are arrays containing the abscissae and
! ordinates, respectively, of the specified points.
!
! yp is an array of second derivative values of the curve
! at the nodes.
!
! and
!
! sigma contains the tension factor (its sign is ignored).
!
! the parameters n, x, y, yp, and sigma should be input
! unaltered from the output of curv1.
!
! on output--
!
! curvd contains the derivative value.
!
! none of the input parameters are altered.
!
! this function references package modules intrvl and
! snhcsh.
!
!-----------------------------------------------------------
integer :: i, im1
real(dp) :: ss, sigdel, dummy, c1, c2, sum, sigmap
real(dp) :: del1, del2, dels
!
! determine interval
!
im1 = fitp_intrvl(t,x,n)
i = im1+1
!
! denormalize tension factor
!
sigmap = abs(sigma)*real(n-1,dp)/(x(n)-x(1))
!
! set up and perform differentiation
!
del1 = t-x(im1)
del2 = x(i)-t
dels = x(i)-x(im1)
sum = (y(i)-y(im1))/dels
if (sigmap .ne. 0.) go to 1
fitp_curvd = sum+(yp(i)*(2.*del1*del1-del2*(del1+dels))- &
yp(im1)*(2.*del2*del2-del1*(del2+dels))) &
/(6.*dels)
return
1 sigdel = sigmap*dels
call fitp_snhcsh (ss,dummy,sigdel,-1)
call fitp_snhcsh (dummy,c1,sigmap*del1,1)
call fitp_snhcsh (dummy,c2,sigmap*del2,1)
fitp_curvd = sum+(yp(i)*(c1-ss)-yp(im1)*(c2-ss))/(sigdel*sigmap*(1.+ss))
return
end function fitp_curvd
real(dp) function fitp_curvi (xl,xu,n,x,y,yp,sigma)
implicit none
integer, intent(in) :: n
real(dp), intent(in) :: xl, xu, sigma
real(dp), dimension(n), intent(in) :: x, y, yp
!
! coded by alan kaylor cline
! from fitpack -- january 26, 1987
! a curve and surface fitting package
! a product of pleasant valley software
! 8603 altus cove, austin, texas 78759, usa
!
! this function integrates a curve specified by a spline
! under tension between two given limits. the subroutine
! curv1 should be called earlier to determine necessary
! parameters.
!
! on input--
!
! xl and xu contain the upper and lower limits of inte-
! gration, respectively. (sl need not be less than or
! equal to xu, curvi (xl,xu,...) .eq. -curvi (xu,xl,...) ).
!
! n contains the number of points which were specified to
! determine the curve.
!
! x and y are arrays containing the abscissae and
! ordinates, respectively, of the specified points.
!
! yp is an array from subroutine curv1 containing
! the values of the second derivatives at the nodes.
!
! and
!
! sigma contains the tension factor (its sign is ignored).
!
! the parameters n, x, y, yp, and sigma should be input
! unaltered from the output of curv1.
!
! on output--
!
! curvi contains the integral value.
!
! none of the input parameters are altered.
!
! this function references package modules intrvl and
! snhcsh.
!
!-----------------------------------------------------------
integer :: i, ilp1, ilm1, il, ium1, iu
real(dp) :: delu1, delu2, c2, ss, cs, cu2, cl1, cl2, cu1
real(dp) :: dell1, dell2, deli, c1, ssign, sigmap
real(dp) :: xxl, xxu, t1, t2, dummy, dels, sum, del1, del2
!
! denormalize tension factor
!
sigmap = abs(sigma)*real(n-1,dp)/(x(n)-x(1))
!
! determine actual upper and lower bounds
!
xxl = xl
xxu = xu
ssign = 1.
if (xl .lt. xu) go to 1
xxl = xu
xxu = xl
ssign = -1.
if (xl .gt. xu) go to 1
!
! return zero if xl .eq. xu
!
fitp_curvi = 0.
return
!
! search for proper intervals
!
1 ilm1 = fitp_intrvl (xxl,x,n)
il = ilm1+1
ium1 = fitp_intrvl (xxu,x,n)
iu = ium1+1
if (il .eq. iu) go to 8
!
! integrate from xxl to x(il)
!
sum = 0.
if (xxl .eq. x(il)) go to 3
del1 = xxl-x(ilm1)
del2 = x(il)-xxl
dels = x(il)-x(ilm1)
t1 = (del1+dels)*del2/(2.*dels)
t2 = del2*del2/(2.*dels)
sum = t1*y(il)+t2*y(ilm1)
if (sigma .eq. 0.) go to 2
call fitp_snhcsh (dummy,c1,sigmap*del1,2)
call fitp_snhcsh (dummy,c2,sigmap*del2,2)
call fitp_snhcsh (ss,cs,sigmap*dels,3)
sum = sum+((dels*dels*(cs-ss/2.)-del1*del1*(c1-ss/2.)) &
*yp(il)+del2*del2*(c2-ss/2.)*yp(ilm1))/ &
(sigmap*sigmap*dels*(1.+ss))
go to 3
2 sum = sum-t1*t1*dels*yp(il)/6. &
-t2*(del1*(del2+dels)+dels*dels)*yp(ilm1)/12.
!
! integrate over interior intervals
!
3 if (iu-il .eq. 1) go to 6
ilp1 = il+1
do i = ilp1,ium1
dels = x(i)-x(i-1)
sum = sum+(y(i)+y(i-1))*dels/2.
if (sigma .eq. 0.) go to 4
call fitp_snhcsh (ss,cs,sigmap*dels,3)
sum = sum+(yp(i)+yp(i-1))*dels*(cs-ss/2.)/(sigmap*sigmap*(1.+ss))
go to 5
4 sum = sum-(yp(i)+yp(i-1))*dels*dels*dels/24.
5 continue
end do
!
! integrate from x(iu-1) to xxu
!
6 if (xxu .eq. x(ium1)) go to 10
del1 = xxu-x(ium1)
del2 = x(iu)-xxu
dels = x(iu)-x(ium1)
t1 = del1*del1/(2.*dels)
t2 = (del2+dels)*del1/(2.*dels)
sum = sum+t1*y(iu)+t2*y(ium1)
if (sigma .eq. 0.) go to 7
call fitp_snhcsh (dummy,c1,sigmap*del1,2)
call fitp_snhcsh (dummy,c2,sigmap*del2,2)
call fitp_snhcsh (ss,cs,sigmap*dels,3)
sum = sum+(yp(iu)*del1*del1*(c1-ss/2.)+yp(ium1)* &
(dels*dels*(cs-ss/2.)-del2*del2*(c2-ss/2.))) &
/(sigmap*sigmap*dels*(1.+ss))
go to 10
7 sum = sum-t1*(del2*(del1+dels)+dels*dels)*yp(iu)/12.-t2*t2*dels*yp(ium1)/6.
go to 10
!
! integrate from xxl to xxu
!
8 delu1 = xxu-x(ium1)
delu2 = x(iu)-xxu
dell1 = xxl-x(ium1)
dell2 = x(iu)-xxl
dels = x(iu)-x(ium1)
deli = xxu-xxl
t1 = (delu1+dell1)*deli/(2.*dels)
t2 = (delu2+dell2)*deli/(2.*dels)
sum = t1*y(iu)+t2*y(ium1)
if (sigma .eq. 0.) go to 9
call fitp_snhcsh (dummy,cu1,sigmap*delu1,2)
call fitp_snhcsh (dummy,cu2,sigmap*delu2,2)
call fitp_snhcsh (dummy,cl1,sigmap*dell1,2)
call fitp_snhcsh (dummy,cl2,sigmap*dell2,2)
call fitp_snhcsh (ss,dummy,sigmap*dels,-1)
sum = sum+(yp(iu)*(delu1*delu1*(cu1-ss/2.) &
-dell1*dell1*(cl1-ss/2.)) &
+yp(ium1)*(dell2*dell2*(cl2-ss/2.) &
-delu2*delu2*(cu2-ss/2.)))/ &
(sigmap*sigmap*dels*(1.+ss))
go to 10
9 sum = sum-t1*(delu2*(dels+delu1)+dell2*(dels+dell1))* &
yp(iu)/12. &
-t2*(dell1*(dels+dell2)+delu1*(dels+delu2))* &
yp(ium1)/12.
!
! correct sign and return
!
10 fitp_curvi = ssign*sum
return
end function fitp_curvi
subroutine fitp_curvp1 (n,x,y,p,yp,temp,sigma,ierr)
implicit none
integer, intent(in) :: n
integer, intent(out) :: ierr
real(dp), intent(in) :: sigma, p
real(dp), dimension(:), intent(in) :: x, y
real(dp), dimension(:), intent(out) :: yp, temp
!! real(dp) x(n),y(n),p,yp(n),temp(2*n),sigma
! real(dp) x(n),y(n),p,yp(n),temp(1),sigma
!
! coded by alan kaylor cline
! from fitpack -- january 26, 1987
! a curve and surface fitting package
! a product of pleasant valley software
! 8603 altus cove, austin, texas 78759, usa
!
! this subroutine determines the parameters necessary to
! compute a periodic interpolatory spline under tension
! through a sequence of functional values. for actual ends
! of the curve may be specified or omitted. for actual
! computation of points on the curve it is necessary to call
! the function curvp2.
!
! on input--
!
! n is the number of values to be interpolated (n.ge.2).
!
! x is an array of the n increasing abscissae of the
! functional values.