forked from PrincetonUniversity/SPEC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumrec.f90
720 lines (579 loc) · 20.9 KB
/
numrec.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
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
!title (numerics) ! Some miscellaneous numerical routines.
!latex \briefly{miscellaneous ``numerical'' routines}
!l tex \calledby{\link{}}
!l tex \calls{\link{}}
!latex \tableofcontents
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
!latex \subsection{Outline}
!latex This file contains various miscellaneous ``numerical'' routines as described below.
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
!l tex \begin{itemize}
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
!l tex \item \type{gi00aa}
!subroutine gi00aa( ii, jj, ig ) ! not used; SRH: 27 Feb 18;
!
! implicit none
!
! INTEGER, intent(in) :: ii,jj
! INTEGER, intent(out) :: ig
!
! if( ( ii.eq.1 .and. jj.eq.1 ) ) ig = 1
! if( ( ii.eq.1 .and. jj.eq.2 ) .or. ( ii.eq.2 .and. jj.eq.1 ) ) ig = 2
! if( ( ii.eq.1 .and. jj.eq.3 ) .or. ( ii.eq.3 .and. jj.eq.1 ) ) ig = 3
! if( ( ii.eq.2 .and. jj.eq.2 ) ) ig = 4
! if( ( ii.eq.2 .and. jj.eq.3 ) .or. ( ii.eq.3 .and. jj.eq.2 ) ) ig = 5
! if( ( ii.eq.3 .and. jj.eq.3 ) ) ig = 6
!
! return
!
!end subroutine gi00aa
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
!latex \subsection{\type{gi00ab}}
!latex \begin{enumerate}
!latex \item This routine assigns the Fourier mode labels that converts a double-sum into a single sum; i.e., the $m_j$ and $n_j$ are assigned where
!latex \be f(\t,\z) & = & \sum_{n=0}^{N} f_{0,n}\cos(-n \, N_P \, \z)
!latex + \sum_{m=1}^{M} \sum_{n=-N}^{N} f_{m,n}\cos(m\t-n \, N_P \, \z) \\
!latex & = & \sum_j f_j \cos(m_j\t-n_j\z), \label{eq:condensedFourierrepresentation}
!latex \ee
!latex where $N\equiv $ \type{Ntor} and $M\equiv $ \type{Mpol} are given on input, and $N_P \equiv $ \type{Nfp} is the field periodicity.
!latex \end{enumerate}
subroutine gi00ab( Mpol, Ntor, Nfp, mn, im, in )
implicit none
INTEGER, intent(in) :: Mpol, Ntor, Nfp, mn
INTEGER, intent(out) :: im(mn), in(mn)
INTEGER :: imn, mm, nn
imn = 0
; mm = 0
;do nn = 0, Ntor
; imn = imn+1 ; im(imn) = mm ; in(imn) = nn*Nfp
;enddo
;
do mm = 1, Mpol
do nn = -Ntor, Ntor
imn = imn+1 ; im(imn) = mm ; in(imn) = nn*Nfp
enddo
enddo
return
end subroutine gi00ab
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
subroutine getimn(Mpol, Ntor, Nfp, mi, ni, idx)
! convert m and n to index
implicit none
integer, intent(in) :: Mpol, Ntor, Nfp, mi, ni
integer, intent(out) :: idx
if (mi.gt.Mpol .or. mi.lt.0 .or. ni.gt.Ntor*Nfp .or. ni.lt.-Ntor*Nfp ) then
idx = 0
elseif (mi .eq. 0) then
idx = 1 + ni / Nfp
else
idx = 1 + Ntor + (2 * Ntor + 1) * (mi - 1) + (ni / Nfp + Ntor + 1)
end if
end subroutine getimn
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
!latex \subsection{\type{tfft}}
!latex \begin{enumerate}
!latex \item This constructs the ``forward'' Fourier transform.
!latex \item Given a set of data, $(f_{i},g_{i})$ for $i = 1, \dots N_\theta N_\zeta$, on a regular two-dimensional angle grid,
!latex where $\theta_j = 2 \pi j / N_\theta$ for $j = 0, N_\theta-1$, and
!latex $\zeta_k = 2 \pi k / N_\zeta $ for $k = 0, N_\zeta -1$.
!latex The ``packing'' is governed by $i = 1 + j + k N_\theta$.
!latex The ``discrete'' resolution is $N_\theta \equiv $ \type{Nt}, $N_\zeta \equiv $ \type{Nz} and \type{Ntz} $=$ \type{Nt} $\times$ \type{Nz},
!latex which are set in \link{preset}.
!latex \item The Fourier harmonics consistent with \Eqn{condensedFourierrepresentation} are constructed.
!latex The mode identification labels appearing in \Eqn{condensedFourierrepresentation} are $m_j \equiv $ \type{im(j)} and $n_j \equiv $ \type{in(j)},
!latex which are set in \link{global} via a call to \type{gi00ab}.
!latex \end{enumerate}
subroutine tfft( Nt, Nz, ijreal, ijimag, mn, im, in, efmn, ofmn, cfmn, sfmn, ifail )
use constants, only : half, zero, pi2
use fileunits, only : ounit
use inputlist, only : Nfp
use allglobal, only : pi2nfp
use fftw_interface
#ifdef OPENMP
use OMP_LIB
#endif
implicit none
intrinsic aimag
INTEGER :: Nt, Nz, mn, im(1:mn), in(1:mn), Ntz, imn, ifail, mm, nn
REAL :: ijreal(1:Nt*Nz), ijimag(1:Nt*Nz), efmn(1:mn), ofmn(1:mn), cfmn(1:mn), sfmn(1:mn)
LOGICAL :: Lcheck = .false.
INTEGER :: jj, kk, ithread
!REAL :: jireal(1:Nt*Nz), jiimag(1:Nt*Nz), arg, ca, sa
REAL :: arg, ca, sa
COMPLEX(C_DOUBLE_COMPLEX) :: z1, z2, z3
GETTHREAD
!if( Lcheck ) then ; jireal = ijreal ; jiimag = ijimag
!endif
do jj = 1, Nz ; cplxin(:,jj,ithread) = CMPLX( ijreal((jj-1)*Nt+1:jj*Nt), ijimag((jj-1)*Nt+1:jj*Nt), KIND=C_DOUBLE_COMPLEX )
enddo
call fftw_execute_dft( planf, cplxin(:,:,ithread), cplxout(:,:,ithread) ) !Forward transform
Ntz = Nt * Nz
cplxout(:,:,ithread) = cplxout(:,:,ithread) / Ntz
cplxout(1,1,ithread) = half*cplxout(1,1,ithread)
do imn = 1, mn
mm = im(imn); nn = in(imn) / Nfp
z1 = cplxout(1 + MOD(Nt - mm, Nt), 1 + MOD(Nz + nn, Nz),ithread)
z2 = cplxout(1 + mm, 1 + MOD(Nz - nn, Nz),ithread)
z3 = z1 + z2
efmn(imn) = real(z3); cfmn(imn) = aimag(z3)
z3 = z1 - z2
ofmn(imn) = aimag(z3); sfmn(imn) = -real(z3)
enddo
if( .not.Lcheck ) return
ijreal(1:Ntz) = zero ; ijimag(1:Ntz) = zero
do jj = 0, Nt-1
do kk = 0, Nz-1
do imn = 1, mn ; arg = im(imn) * jj * pi2 / Nt - in(imn) * kk * pi2nfp / Nz ; ca = cos(arg) ; sa = sin(arg)
ijreal(1+jj+kk*Nt) = ijreal(1+jj+kk*Nt) + efmn(imn) * ca + ofmn(imn) * sa
ijimag(1+jj+kk*Nt) = ijimag(1+jj+kk*Nt) + cfmn(imn) * ca + sfmn(imn) * sa
enddo
enddo
enddo
!write(ounit,'("tfft : ",10x," : Fourier reconstruction error =",2es15.5," ;")') sqrt(sum((ijreal-jireal)**2)/Ntz), sqrt(sum((ijimag-jiimag)**2)/Ntz)
return
end subroutine tfft
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
!latex \subsection{\type{invfft}}
!latex \begin{enumerate}
!latex \item Given the Fourier harmonics, the data on a regular angular grid are constructed.
!latex \item This is the inverse routine to \type{tfft}.
!latex \end{enumerate}
subroutine invfft( mn, im, in, efmn, ofmn, cfmn, sfmn, Nt, Nz, ijreal, ijimag )
use constants, only : zero, two, half
use inputlist, only : Nfp
use fftw_interface
#ifdef OPENMP
use OMP_LIB
#endif
implicit none
INTEGER, intent(in) :: mn, im(mn), in(mn)
REAL , intent(in) :: efmn(mn), ofmn(mn), cfmn(mn), sfmn(mn)
INTEGER, intent(in) :: Nt, Nz
REAL , intent(out) :: ijreal(Nt*Nz), ijimag(Nt*Nz) ! output real space;
INTEGER :: imn, jj, mm, nn, ithread
GETTHREAD
cplxin(:,:,ithread) = zero
!Copy real arrays to complex
do imn = 1,mn ; mm = im(imn) ; nn = in(imn) / Nfp
cplxin(1 + MOD(Nt - mm, Nt), 1 + MOD(Nz + nn, Nz),ithread) = &
half * CMPLX(efmn(imn) - sfmn(imn), cfmn(imn) + ofmn(imn), KIND=C_DOUBLE_COMPLEX)
cplxin(1 + mm, 1 + MOD(Nz - nn, Nz),ithread) = &
half * CMPLX(efmn(imn) + sfmn(imn), cfmn(imn) - ofmn(imn), KIND=C_DOUBLE_COMPLEX)
enddo
cplxin(1,1,ithread) = two*cplxin(1,1,ithread)
call fftw_execute_dft(planb, cplxin(:,:,ithread), cplxout(:,:,ithread)) !Inverse transform
!Copy complex result back to real arrays
do jj=1,Nz
ijreal((jj-1)*Nt+1:jj*Nt) = real(cplxout(:,jj,ithread))
ijimag((jj-1)*Nt+1:jj*Nt) = aimag(cplxout(:,jj,ithread))
enddo
return
end subroutine invfft
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
!latex \subsection{\type{gauleg}}
!latex \begin{enumerate}
!latex \item Compute Gaussian integration weights and abscissae.
!latex \item From Numerical Recipes.
!latex \end{enumerate}
subroutine gauleg( n, weight, abscis, ifail )
use constants, only : zero, one, two, pi
implicit none
intrinsic abs, cos, epsilon
INTEGER, intent(in) :: n
REAL, dimension(n), intent(out) :: weight, abscis
INTEGER, intent(out) :: ifail
INTEGER, parameter :: maxiter=16
INTEGER :: m, j, i, irefl, iter
REAL :: z1,z,pp,p3,p2,p1
REAL, parameter :: eps = epsilon(z)
!Error checking
if( n < 1 ) then ; ifail = 2 ; return
endif
m = (n + 1)/2 !Roots are symmetric in interval, so we only need half
do i=1,m !Loop over desired roots
irefl = n + 1 - i
if (i .ne. irefl) then
z = cos(pi*(i - 0.25)/(n + 0.5)) ! Approximate ith root
else !For an odd number of abscissae, the center must be at zero by symmetry.
z = 0.0
endif
!Refine by Newton method
do iter=1,maxiter
p1 = one; p2 = zero ! Initialize recurrence relation
do j=1,n !Recurrence relation to get P(x)
p3 = p2; p2 = p1
p1 = ((two*j - one)*z*p2 - (j - one)*p3)/j
enddo !j
pp = n*(z*p1 - p2)/(z*z - one) !Derivative of P(x)
z1 = z; z = z1 - p1/pp !Newton iteration
if (abs(z - z1) .le. eps) exit !Convergence test
enddo !iter
if (iter > maxiter) then
ifail = 1; return
endif
abscis(i) = -z; abscis(irefl) = z
weight(i) = two/((one - z*z)*pp*pp)
weight(irefl) = weight(i)
enddo !i
ifail = 0
end subroutine gauleg
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
#ifdef DELETETHIS
!l tex \subsection{\type{svdcmp}} ! not used; SRH: 27 Feb 18;
subroutine svdcmp(a,m,n,mp,np,w,v)
use constants,only:zero,one
implicit none
integer nMaX,M,n,MP,nP,i,j,jj,k,l,its,nM
parameter (nMaX=500)
REAL :: a(MP,nP),w(nP),v(nP,nP),rv1(nMaX)
REAL :: c,F,g,H,s,X,Y,Z,scale,anorM,pythag,oone
!stop "svdcmp : to be deleted?"
g=zero
scale=zero
anorm=zero
do 25 i=1,n
l=i+1
rv1(i)=scale*g
g=zero
s=zero
scale=zero
if(i.le.m)then
do 11 k=i,m
scale=scale+abs(a(k,i))
11 continue
if(scale.ne.zero)then
do 12 k=i,m
a(k,i)=a(k,i)/scale
s=s+a(k,i)*a(k,i)
12 continue
f=a(i,i)
g=-sign(sqrt(s),f)
h=f*g-s
a(i,i)=f-g
do 15 j=l,n
s=zero
do 13 k=i,m
s=s+a(k,i)*a(k,j)
13 continue
f=s/h
do 14 k=i,m
a(k,j)=a(k,j)+f*a(k,i)
14 continue
15 continue
do 16 k=i,m
a(k,i)=scale*a(k,i)
16 continue
endif
endif
w(i)=scale *g
g=zero
s=zero
scale=zero
if((i.le.m).and.(i.ne.n))then
do 17 k=l,n
scale=scale+abs(a(i,k))
17 continue
if(scale.ne.zero)then
do 18 k=l,n
a(i,k)=a(i,k)/scale
s=s+a(i,k)*a(i,k)
18 continue
f=a(i,l)
g=-sign(sqrt(s),f)
h=f*g-s
a(i,l)=f-g
do 19 k=l,n
rv1(k)=a(i,k)/h
19 continue
do 23 j=l,m
s=zero
do 21 k=l,n
s=s+a(j,k)*a(i,k)
21 continue
do 22 k=l,n
a(j,k)=a(j,k)+s*rv1(k)
22 continue
23 continue
do 24 k=l,n
a(i,k)=scale*a(i,k)
24 continue
endif
endif
anorm=max(anorm,(abs(w(i))+abs(rv1(i))))
25 continue
do 32 i=n,1,-1
if(i.lt.n)then
if(g.ne.zero)then
do 26 j=l,n
v(j,i)=(a(i,j)/a(i,l))/g
26 continue
do 29 j=l,n
s=zero
do 27 k=l,n
s=s+a(i,k)*v(k,j)
27 continue
do 28 k=l,n
v(k,j)=v(k,j)+s*v(k,i)
28 continue
29 continue
endif
do 31 j=l,n
v(i,j)=zero
v(j,i)=zero
31 continue
endif
v(i,i)=one
g=rv1(i)
l=i
32 continue
do 39 i=min(m,n),1,-1
l=i+1
g=w(i)
do 33 j=l,n
a(i,j)=zero
33 continue
if(g.ne.zero)then
g=one/g
do 36 j=l,n
s=zero
do 34 k=l,m
s=s+a(k,i)*a(k,j)
34 continue
f=(s/a(i,i))*g
do 35 k=i,m
a(k,j)=a(k,j)+f*a(k,i)
35 continue
36 continue
do 37 j=i,m
a(j,i)=a(j,i)*g
37 continue
else
do 38 j= i,m
a(j,i)=zero
38 continue
endif
a(i,i)=a(i,i)+one
39 continue
do 49 k=n,1,-1
do 48 its=1,30
do 41 l=k,1,-1
nm=l-1
if((abs(rv1(l))+anorm).eq.anorm) goto 2
if((abs(w(nm))+anorm).eq.anorm) goto 1
41 continue
1 c=zero
s=one
do 43 i=l,k
f=s*rv1(i)
rv1(i)=c*rv1(i)
if((abs(f)+anorm).eq.anorm) goto 2
g=w(i)
h=pythag(f,g)
w(i)=h
h=one/h
c= (g*h)
s=-(f*h)
do 42 j=1,m
y=a(j,nm)
z=a(j,i)
a(j,nm)=(y*c)+(z*s)
a(j,i)=-(y*s)+(z*c)
42 continue
43 continue
2 z=w(k)
if(l.eq.k)then
if(z.lt.zero)then
w(k)=-z
do 44 j=1,n
v(j,k)=-v(j,k)
44 continue
endif
goto 3
endif
if(its.eq.30) stop "svdcmp : no convergence"
x=w(l)
nm=k-1
y=w(nm)
g=rv1(nm)
h=rv1(k)
f=((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y)
oone=one
g=pythag(f,oone)
f=((x-z)*(x+z)+h*((y/(f+sign(g,f)))-h))/x
c=one
s=one
do 47 j=l,nm
i=j+1
g=rv1(i)
y=w(i)
h=s*g
g=c*g
z=pythag(f,h)
rv1(j)=z
c=f/z
s=h/z
f= (x*c)+(g*s)
g=-(x*s)+(g*c)
h=y*s
y=y*c
do 45 jj=1,n
x=v(jj,j)
z=v(jj,i)
v(jj,j)= (x*c)+(z*s)
v(jj,i)=-(x*s)+(z*c)
45 continue
z=pythag(f,h)
w(j)=z
if(z.ne.zero)then
z=one/z
c=f*z
s=h*z
endif
f= (c*g)+(s*y)
x=-(s*g)+(c*y)
do 46 jj=1,m
y=a(jj,j)
z=a(jj,i)
a(jj,j)= (y*c)+(z*s)
a(jj,i)=-(y*s)+(z*c)
46 continue
47 continue
rv1(l)=zero
rv1(k)=f
w(k)=x
48 continue
3 continue
49 continue
return
end
#endif
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
#ifdef DELETETHIS
!l tex \subsection{\type{pythag}} ! not used; SRH: 27 Feb 18;
REAL function pythag(a,b)
implicit none
REAL :: a,b
REAL :: absa,absb
!stop "pythag : to be deleted?"
absa=abs(a)
absb=abs(b)
if(absa.gt.absb) then
pythag=absa*sqrt(1.+(absb/absa)**2)
else
if(absb.eq.0.) then
pythag=0.
else
pythag=absb*sqrt(1.+(absa/absb)**2)
endif
endif
return
end function pythag
#endif
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
#ifdef DELETETHIS
!l tex \subsection{\type{svbksb}} ! not used; SRH: 27 Feb 18;
subroutine svbksb(u,w,v,M,n,MP,nP,b,X)
implicit none
integer nMaX,M,n,MP,nP,i,j,jj
parameter (nMaX=10000)
REAL, intent(in) :: b(MP)
REAL :: u(MP,nP),w(nP),v(nP,nP),X(nP),tMP(nMaX)
REAL :: s
!stop "svbksb : to be deleted?"
do 12 j=1,n
s=0.
if(w(j).ne.0.)then
do 11 i=1,M
s=s+u(i,j)*b(i)
11 continue
s=s/w(j)
endif
tMP(j)=s
12 continue
do 14 j=1,n
s=0.
do 13 jj=1,n
s=s+v(j,jj)*tMP(jj)
13 continue
X(j)=s
14 continue
return
end
#endif
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
#ifdef DELETETHIS
!l tex \subsection{\type{sort}} ! not used; SRH: 27 Feb 18;
subroutine sort(n,ra)
implicit none
integer n,l,ir,i,j
REAL :: ra(n),rra
!stop "sort : to be deleted?"
if(n.eq.1) return
l=n/2+1
ir=n
10 continue
if(l.gt.1)then
l=l-1
rra=ra(l)
else
rra=ra(ir)
ra(ir)=ra(1)
ir=ir-1
if(ir.eq.1)then
ra(1)=rra
return
endif
endif
i=l
j=l+l
20 if(j.le.ir)then
if(j.lt.ir)then
if(ra(j).lt.ra(j+1))j=j+1
endif
if(rra.lt.ra(j))then
ra(i)=ra(j)
i=j
j=j+j
else
j=ir+1
endif
goto 20
endif
ra(i)=rra
goto 10
end
#endif
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
#ifdef DELETETHIS
!l tex \subsection{\type{singvalues}} ! not used; SRH: 27 Feb 18;
subroutine singvalues(nrow,ncol,Mat,b,sx,cutoff,wsvd) ! nrow = nconstraints ; ncol = nfreedom
implicit none
INTEGER, intent(in) :: nrow,ncol
REAL,intent(in) :: Mat(nrow,ncol),b(nrow)
integer i,nev
REAL :: Mato(nrow,ncol)
REAL :: sx(ncol)
REAL :: vsvd(ncol,ncol),wsvd(ncol),wsvdc(ncol)
REAL :: cutoff,wmax,wmin
sx=0.0;wsvd=0.0;vsvd=0.0;wsvdc=0.0;wmax=0.0;Mato=Mat
call svdcmp(Mato,nrow,ncol,nrow,ncol,wsvd,vsvd)
wsvdc=wsvd
call sort(ncol,wsvdc)
wmax=wsvdc(ncol)
wmin=abs(wmax)*cutoff
wsvdc=0.0;nev=0
do i=1,ncol
if(abs(wsvd(i)).ge.wmin) then;wsvdc(i)=wsvd(i);nev=nev+1
endif
enddo
call svbksb(Mato,wsvdc,vsvd,nrow,ncol,nrow,ncol,b,sx)
!Mat=Mato
call sort(ncol,wsvd)
return
end subroutine singvalues
#endif
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
!l tex \end{itemize}
!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!