forked from johannesgerer/jburkardt-f
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubpak.f90
8769 lines (7751 loc) · 199 KB
/
subpak.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
subroutine angle_shift ( alpha, beta, gamma )
!*****************************************************************************80
!
!! ANGLE_SHIFT shifts angle ALPHA to lie between BETA and BETA+2PI.
!
! Discussion:
!
! The input angle ALPHA is shifted by multiples of 2 * PI to lie
! between BETA and BETA+2*PI.
!
! The resulting angle GAMMA has all the same trigonometric function
! values as ALPHA.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 14 June 2007
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, real ( kind = 8 ) ALPHA, the angle to be shifted.
!
! Input, real ( kind = 8 ) BETA, defines the lower endpoint of
! the angle range.
!
! Output, real ( kind = 8 ) GAMMA, the shifted angle.
!
implicit none
real ( kind = 8 ) alpha
real ( kind = 8 ) beta
real ( kind = 8 ) gamma
real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00
if ( alpha < beta ) then
gamma = beta - mod ( beta - alpha, 2.0D+00 * pi ) + 2.0D+00 * pi
else
gamma = beta + mod ( alpha - beta, 2.0D+00 * pi )
end if
return
end
subroutine angle_shift_deg ( alpha, beta, gamma )
!*****************************************************************************80
!
!! ANGLE_SHIFT_DEG shifts angle ALPHA to lie between BETA and BETA+360.
!
! Discussion:
!
! The input angle ALPHA is shifted by multiples of 360 to lie
! between BETA and BETA+360.
!
! The resulting angle GAMMA has all the same trigonometric function
! values as ALPHA.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 14 June 2007
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, real ( kind = 8 ) ALPHA, the angle to be shifted, in degrees.
!
! Input, real ( kind = 8 ) BETA, defines the lower endpoint of
! the angle range.
!
! Output, real ( kind = 8 ) GAMMA, the shifted angle.
!
implicit none
real ( kind = 8 ) alpha
real ( kind = 8 ) beta
real ( kind = 8 ) gamma
if ( alpha < beta ) then
gamma = beta - mod ( beta - alpha, 360.0D+00 ) + 360.0D+00
else
gamma = beta + mod ( alpha - beta, 360.0D+00 )
end if
return
end
subroutine angle_to_rgb ( angle, r, g, b )
!*****************************************************************************80
!
!! ANGLE_TO_RGB returns a color on the perimeter of the color hexagon.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 07 December 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, real ( kind = 8 ) ANGLE, the angle in the color hexagon.
! The sextants are defined by the following points:
! 0 degrees, 1, 0, 0, red;
! 60 degrees, 1, 1, 0, yellow;
! 120 degrees, 0, 1, 0, green;
! 180 degrees, 0, 1, 1, cyan;
! 240 degrees, 0, 0, 1, blue;
! 300 degrees, 1, 0, 1, magenta.
!
! Output, real ( kind = 8 ) R, G, B, RGB specifications for the color
! that lies at the given angle, on the perimeter of the color hexagon. One
! value will be 1, and one value will be 0.
!
implicit none
real ( kind = 8 ) angle
real ( kind = 8 ) angle2
real ( kind = 8 ) b
real ( kind = 8 ) g
real ( kind = 8 ), parameter :: degrees_to_radians = &
3.141592653589793D+00 / 180.0D+00
real ( kind = 8 ) r
angle = mod ( angle, 360.0D+00 )
if ( angle < 0.0D+00 ) then
angle = angle + 360.0D+00
end if
if ( angle <= 60.0D00 ) then
angle2 = degrees_to_radians * 3.0D+00 * angle / 4.0D+00
r = 1.0D+00
g = tan ( angle2 )
b = 0.0D+00
else if ( angle <= 120.0D+00 ) then
angle2 = degrees_to_radians * 3.0D+00 * angle / 4.0D+00
r = cos ( angle2 ) / sin ( angle2 )
g = 1.0D+00
b = 0.0D+00
else if ( angle <= 180.0D+00 ) then
angle2 = degrees_to_radians * 3.0D+00 * ( angle - 120.0D+00 ) / 4.0D+00
r = 0.0D+00
g = 1.0D+00
b = tan ( angle2 )
else if ( angle <= 240.0D+00 ) then
angle2 = degrees_to_radians * 3.0D+00 * ( angle - 120.0D+00 ) / 4.0D+00
r = 0.0D+00
g = cos ( angle2 ) / sin ( angle2 )
b = 1.0D+00
else if ( angle <= 300.0D+00 ) then
angle2 = degrees_to_radians * 3.0D+00 * ( angle - 240.0D+00 ) / 4.0D+00
r = tan ( angle2 )
g = 0.0D+00
b = 1.0D+00
else if ( angle <= 360.0D+00 ) then
angle2 = degrees_to_radians * 3.0D+00 * ( angle - 240.0D+00 ) / 4.0D+00
r = 1.0D+00
g = 0.0D+00
b = cos ( angle2 ) / sin ( angle2 )
end if
return
end
subroutine axis_limits ( xmin, xmax, ndivs, pxmin, pxmax, pxdiv, nticks )
!*****************************************************************************80
!
!! AXIS_LIMITS returns "nice" axis limits for a plot.
!
! Discussion:
!
! The routine is given information about the range of a variable, and
! the number of divisions desired. It returns suggestions for
! labeling a plotting axis for the variable, including the
! starting and ending points, the length of a single division,
! and a suggested tick marking for the axis.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 21 March 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, real ( kind = 8 ) XMIN, XMAX, the lower and upper values that
! must be included on the axis. XMIN must be less than XMAX.
!
! Input, integer ( kind = 4 ) NDIVS, the number of divisions desired along
! the axis.
!
! Output, real ( kind = 8 ) PXMIN, PXMAX, the recommended lower and upper
! axis bounds. It will be the case that PXMIN <= XMIN < XMAX <= PXMAX.
!
! Output, real ( kind = 8 ) PXDIV, the recommended size of a single division.
!
! Output, integer ( kind = 4 ) NTICKS, a suggested number of ticks to use,
! if subdividing each of the NDIVS divisions of the axis.
!
implicit none
integer ( kind = 4 ), parameter :: nsteps = 5
real ( kind = 8 ) best
real ( kind = 8 ) good
integer ( kind = 4 ) i
integer ( kind = 4 ) ihi
integer ( kind = 4 ) ilo
integer ( kind = 4 ) intlog
integer ( kind = 4 ), dimension ( nsteps ) :: iticks = (/ 5, 4, 4, 5, 5 /)
integer ( kind = 4 ) ival
integer ( kind = 4 ) j
integer ( kind = 4 ) ndivs
integer ( kind = 4 ) nticks
real ( kind = 8 ) pxmax
real ( kind = 8 ) pxmax2
real ( kind = 8 ) pxmin
real ( kind = 8 ) pxmin2
real ( kind = 8 ) pxdiv
real ( kind = 8 ) pxdiv2
real ( kind = 8 ) r8_log_10
real ( kind = 8 ) reldif
real ( kind = 8 ), dimension ( nsteps ) :: steps = (/ &
1.0D+00, 2.0D+00, 4.0D+00, 5.0D+00, 10.0D+00 /)
real ( kind = 8 ) temp
real ( kind = 8 ) xmax
real ( kind = 8 ) xmin
if ( xmin == xmax ) then
xmin = xmin - 0.5D+00
xmax = xmax + 0.5D+00
else if ( xmax < xmin ) then
temp = xmin
xmin = xmax
xmax = temp
end if
if ( ndivs <= 0 ) then
ndivs = 5
end if
!
! Set RELDIF, the size of the X interval divided by the largest X.
!
if ( xmax /= xmin ) then
reldif = ( xmax - xmin ) / max ( abs ( xmax ), abs ( xmin ) )
else
reldif = 0.0D+00
end if
!
! If RELDIF tells us that XMIN and XMAX are extremely close,
! do some simple things.
!
if ( reldif < 0.00001D+00 ) then
if ( xmax == 0.0D+00 ) then
pxdiv = 1.0D+00
else
intlog = int ( r8_log_10 ( xmax ) )
if ( intlog < 0 ) then
intlog = intlog - 1
end if
pxdiv = 10.0D+00**intlog
if ( 1.0D+00 < pxdiv ) then
pxdiv = 1.0D+00
end if
end if
nticks = 5
pxmin = xmax - real ( ndivs / 2, kind = 8 ) * pxdiv
pxmax = xmax + real ( ndivs - ( ndivs / 2 ), kind = 8 ) * pxdiv
!
! But now handle the more general case, when XMIN and XMAX
! are relatively far apart.
!
else
best = -999.0D+00
!
! On second loop, increase INTLOG by 1.
!
do j = 1, 2
!
! Compute INTLOG, roughly the logarithm base 10 of the range
! divided by the number of divisions.
!
intlog = int ( r8_log_10 ( ( xmax - xmin ) &
/ real ( ndivs, kind = 8 ) ) ) + ( j - 1 )
if ( xmax - xmin < real ( ndivs, kind = 8 ) ) then
intlog = intlog - 1
end if
!
! Now consider taking 1, 2, 4, 5 or 10 steps of size 10**INTLOG:
!
do i = 1, nsteps
!
! Compute the size of each step.
!
pxdiv2 = steps(i) * 10.0D+00**intlog
!
! Make sure NDIVS steps can reach from XMIN to XMAX, at least.
!
if ( xmax <= xmin + ndivs * pxdiv2 ) then
!
! Now decide where to start the axis.
! Start the axis at PXMIN2, to the left of XMIN, and
! representing a whole number of steps of size PXDIV2.
!
if ( 0.0D+00 <= xmin ) then
ival = int ( xmin / pxdiv2 )
else
ival = int ( xmin / pxdiv2 ) - 1
end if
pxmin2 = ival * pxdiv2
!
! PXMAX2 is, of course, NDIVS steps above PXMIN2.
!
pxmax2 = pxmin2 + ndivs * pxdiv2
!
! Only consider going on if PXMAX2 is at least XMAX.
!
if ( xmax <= pxmax2 ) then
!
! Now judge this grid by the relative amount of wasted axis length.
!
good = ( xmax - xmin ) / ( pxmax2 - pxmin2 )
if ( best < good ) then
best = good
pxmax = pxmax2
pxmin = pxmin2
pxdiv = pxdiv2
nticks = iticks(i)
end if
end if
end if
end do
end do
end if
!
! If necessary, adjust the locations of PXMIN and PXMAX so that the
! interval is more symmetric in containing XMIN through XMAX.
!
do
ilo = int ( xmin - pxmin ) / pxdiv
ihi = int ( pxmax - xmax ) / pxdiv
if ( ihi < ilo + 2 ) then
exit
end if
pxmin = pxmin - pxdiv
pxmax = pxmax - pxdiv
end do
return
end
subroutine bar_check ( digit, check )
!*****************************************************************************80
!
!! BAR_CHECK computes the check digit for a barcode.
!
! Formula:
!
! CHECK = SUM ( I = 1, 11, by 2's ) DIGIT(I)
! + 3 * SUM ( I = 2, 10, by 2's ) DIGIT(I)
!
! CHECK = MOD ( 10 - MOD ( CHECK, 10 ), 10 )
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 23 March 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) DIGIT(12), entries 1 through 11 of DIGIT
! contain the digits of the bar code. Each entry must be between 0 and 9.
! The 12th digit should be the check digit.
!
! Output, integer ( kind = 4 ) CHECK, the correct check digit. If the bar
! code is correct, then DIGIT(12) should equal CHECK.
!
implicit none
integer ( kind = 4 ) check
integer ( kind = 4 ) digit(12)
check = sum ( digit(1:11:2) ) + 3 * sum ( digit(2:10:2) )
check = mod ( 10 - mod ( check, 10 ), 10 )
return
end
subroutine bar_code ( digit, bar )
!*****************************************************************************80
!
!! BAR_CODE constructs the 113 character barcode from 11 digits.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 23 March 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input/output, integer ( kind = 4 ) DIGIT(12).
! On input, the first 11 entries of DIGIT contain a code to be
! turned into a barcode.
! On output, the 12-th entry of DIGIT is a check digit.
!
! Output, character ( len = 113 ) BAR, the bar code corresponding to the
! digit information.
!
implicit none
character ( len = 113 ) bar
integer ( kind = 4 ) check
character ( len = 7 ) codel
character ( len = 7 ) coder
integer ( kind = 4 ) digit(12)
integer ( kind = 4 ) i
!
! 9 character quiet zone.
!
bar(1:9) = '000000000'
!
! 3 character guard pattern.
!
bar(10:12) = '101'
!
! 7 character product category.
!
call bar_digit_code_left ( digit(1), codel )
bar(13:19) = codel
!
! 35 characters contain the 5 digit manufacturer code.
!
do i = 1, 5
call bar_digit_code_left ( digit(i+1), codel )
bar(20+(i-1)*7:20+(i-1)*7+6) = codel
end do
!
! Center guard pattern.
!
bar(55:59) = '01010'
!
! 35 characters contain the 5 digit product code.
!
do i = 1, 5
call bar_digit_code_right ( digit(i+6), coder )
bar(60+(i-1)*7:60+(i-1)*7+6) = coder
end do
!
! Compute the check digit.
!
call bar_check ( digit, check )
digit(12) = check
call bar_digit_code_right ( digit(12), coder )
bar(95:101) = coder
!
! Guard pattern.
!
bar(102:104) = '101'
!
! Quiet zone.
!
bar(105:113) = '000000000'
return
end
subroutine bar_digit_code_left ( digit, codel )
!*****************************************************************************80
!
!! BAR_DIGIT_CODE_LEFT returns the 7 character left bar code for a digit.
!
! Example:
!
! DIGIT = 3
! CODEL = '0111101'
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 August 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) DIGIT, the digit, between 0 and 9.
!
! Output, character ( len = 7 ) CODEL, the left code for the digit.
!
implicit none
character ( len = 7 ) codel
integer ( kind = 4 ) digit
if ( digit == 0 ) then
codel = '0001101'
else if ( digit == 1 ) then
codel = '0011001'
else if ( digit == 2 ) then
codel = '0010011'
else if ( digit == 3 ) then
codel = '0111101'
else if ( digit == 4 ) then
codel = '0100011'
else if ( digit == 5 ) then
codel = '0110001'
else if ( digit == 6 ) then
codel = '0101111'
else if ( digit == 7 ) then
codel = '0111011'
else if ( digit == 8 ) then
codel = '0110111'
else if ( digit == 9 ) then
codel = '0001011'
else
codel = '???????'
end if
return
end
subroutine bar_digit_code_right ( digit, coder )
!*****************************************************************************80
!
!! BAR_DIGIT_CODE_RIGHT returns the 7 character right bar code for a digit.
!
! Example:
!
! DIGIT = 3
! CODER = '1000010'
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 August 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) DIGIT, the digit, between 0 and 9.
!
! Output, character ( len = 7 ) CODER, the right code for the digit.
!
implicit none
character ( len = 7 ) coder
integer ( kind = 4 ) digit
if ( digit == 0 ) then
coder = '1110010'
else if ( digit == 1 ) then
coder = '1100110'
else if ( digit == 2 ) then
coder = '1101100'
else if ( digit == 3 ) then
coder = '1000010'
else if ( digit == 4 ) then
coder = '1011100'
else if ( digit == 5 ) then
coder = '1001110'
else if ( digit == 6 ) then
coder = '1010000'
else if ( digit == 7 ) then
coder = '1000100'
else if ( digit == 8 ) then
coder = '1001000'
else if ( digit == 9 ) then
coder = '1110100'
else
coder = '???????'
end if
return
end
function bmi_english ( w_lb, h_ft, h_in )
!*****************************************************************************80
!
!! BMI_ENGLISH computes the body mass index given English measurements.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 07 December 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, real ( kind = 8 ) W_LB, the body weight in pounds.
!
! Input, real ( kind = 8 ) H_FT, H_IN, the body height in feet and inches
!
! Output, real ( kind = 8 ) BMI_ENGLISH, the body mass index.
!
implicit none
real ( kind = 8 ) bmi_english
real ( kind = 8 ) bmi_metric
real ( kind = 8 ) feet_to_meters
real ( kind = 8 ) h_ft
real ( kind = 8 ) h_in
real ( kind = 8 ) h_m
real ( kind = 8 ) pounds_to_kilograms
real ( kind = 8 ) w_kg
real ( kind = 8 ) w_lb
w_kg = pounds_to_kilograms ( w_lb )
h_m = feet_to_meters ( h_ft + ( h_in / 12.0D+00 ) )
bmi_english = bmi_metric ( w_kg, h_m )
return
end
function bmi_metric ( w_kg, h_m )
!*****************************************************************************80
!
!! BMI_METRIC computes the body mass index given metric measurements.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 07 December 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, real ( kind = 8 ) W_KG, the body weight in kilograms.
!
! Input, real ( kind = 8 ) H_M, the body height in meters.
!
! Output, real ( kind = 8 ) BMI_METRIC, the body mass index.
!
implicit none
real ( kind = 8 ) bmi_metric
real ( kind = 8 ) h_m
real ( kind = 8 ) w_kg
bmi_metric = ( w_kg / h_m ) / h_m
return
end
function ch_is_digit ( c )
!*****************************************************************************80
!
!! CH_IS_DIGIT is TRUE if C is a decimal digit.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 09 August 1999
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, character C, the character to be analyzed.
!
! Output, logical CH_IS_DIGIT, is TRUE if C is a digit.
!
implicit none
character c
logical ch_is_digit
if ( lle ( '0', c ) .and. lle ( c, '9' ) ) then
ch_is_digit = .true.
else
ch_is_digit = .false.
end if
return
end
function degrees_to_radians ( degrees )
!*****************************************************************************80
!
!! DEGREES_TO_RADIANS converts an angle measure from degrees to radians.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 11 December 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, real ( kind = 8 ) DEGREES, the angle measure in degrees.
!
! Output, real ( kind = 8 ) DEGREES_TO_RADIANS, the angle measure in radians.
!
implicit none
real ( kind = 8 ) degrees
real ( kind = 8 ) degrees_to_radians
real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00
degrees_to_radians = ( degrees / 180.0D+00 ) * pi
return
end
function e_constant ( )
!*****************************************************************************80
!
!! E_CONSTANT returns the value of E.
!
! Discussion:
!
! "E" was named in honor of Euler, but is known as Napier's constant.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 12 December 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Output, real ( kind = 8 ) E_CONSTANT, the base of the natural
! logarithm system.
!
implicit none
real ( kind = 8 ) e_constant
e_constant = 2.718281828459045D+00
return
end
function euler_constant ( )
!*****************************************************************************80
!
!! EULER_CONSTANT returns the value of the Euler-Mascheroni constant.
!
! Discussion:
!
! The Euler-Mascheroni constant is often denoted by a lower-case
! Gamma. Gamma is defined as
!
! Gamma = limit ( M -> oo ) ( Sum ( 1 <= N <= M ) 1 / N ) - Log ( M )
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 12 December 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Output, real ( kind = 8 ) EULER_CONSTANT, the value of the
! Euler-Mascheroni constant.
!
implicit none
real ( kind = 8 ) euler_constant
euler_constant = 0.5772156649015328D+00
return
end
subroutine fac_div ( prime_num, npower1, npower2, npower3 )
!*****************************************************************************80
!
!! FAC_DIV divides two quantities represented as prime factors.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 15 August 1999
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) PRIME_NUM, the index of the highest prime
! number used in the representations.
!
! Input, integer ( kind = 4 ) NPOWER1(PRIME_NUM), the powers of primes
! in the representation of the first quantity.
!
! Input, integer ( kind = 4 ) NPOWER2(PRIME_NUM), the powers of primes
! in the representation of the second quantity.
!
! Output, integer ( kind = 4 ) NPOWER3(PRIME_NUM), the powers of primes
! in the representation of the quotient.
!
implicit none
integer ( kind = 4 ) prime_num
integer ( kind = 4 ) npower1(prime_num)
integer ( kind = 4 ) npower2(prime_num)
integer ( kind = 4 ) npower3(prime_num)
npower3(1:prime_num) = npower1(1:prime_num) - npower2(1:prime_num)
return
end
subroutine fac_gcd ( prime_num, npower1, npower2, npower3 )
!*****************************************************************************80
!
!! FAC_GCD finds the GCD of two products of prime factors.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 15 August 1999
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) PRIME_NUM, the index of the highest prime
! number used in the representations.
!
! Input, integer ( kind = 4 ) NPOWER1(PRIME_NUM), the powers of primes
! in the representation of the first quantity. All the powers
! must be nonnegative.
!
! Input, integer ( kind = 4 ) NPOWER2(PRIME_NUM), the powers of primes
! in the representation of the second quantity. All the powers
! must be nonnegative.
!
! Output, integer ( kind = 4 ) NPOWER3(PRIME_NUM), the powers of primes
! in the representation of the GCD.
!
implicit none
integer ( kind = 4 ) prime_num
integer ( kind = 4 ) i
integer ( kind = 4 ) npower1(prime_num)
integer ( kind = 4 ) npower2(prime_num)
integer ( kind = 4 ) npower3(prime_num)
do i = 1, prime_num
if ( npower1(i) < 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'FAC_GCD - Fatal error!'
write ( *, '(a)' ) ' One of the powers is negative!'
stop
end if
if ( npower2(i) < 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'FAC_GCD - Fatal error!'
write ( *, '(a)' ) ' One of the powers is negative!'
stop
end if
npower3(i) = min ( npower1(i), npower2(i) )
end do
return
end
subroutine fac_lcm ( prime_num, npower1, npower2, npower3 )
!*****************************************************************************80
!
!! FAC_LCM finds the LCM of two products of prime factors.