OpenCMISS-Iron Internal API Documentation
maths.f90
Go to the documentation of this file.
1 
43 
45 MODULE maths
46 
47  USE base_routines
48  USE constants
49  USE kinds
51  USE strings
52 
53 #include "macros.h"
54 
55  IMPLICIT NONE
56 
57  PRIVATE
58 
59  !Module parameters
60 
61  !Module types
62 
63  !Interfaces
64 
66  INTERFACE cross_product
67  MODULE PROCEDURE crossproductintg
68  MODULE PROCEDURE crossproductsp
69  MODULE PROCEDURE crossproductdp
70  END INTERFACE cross_product
71 
73  INTERFACE crossproduct
74  MODULE PROCEDURE crossproductintg
75  MODULE PROCEDURE crossproductsp
76  MODULE PROCEDURE crossproductdp
77  END INTERFACE crossproduct
78 
80  INTERFACE d_cross_product
81  MODULE PROCEDURE dcrossproductintg
82  MODULE PROCEDURE dcrossproductsp
83  MODULE PROCEDURE dcrossproductdp
84  END INTERFACE d_cross_product
85 
87  INTERFACE dcrossproduct
88  MODULE PROCEDURE dcrossproductintg
89  MODULE PROCEDURE dcrossproductsp
90  MODULE PROCEDURE dcrossproductdp
91  END INTERFACE dcrossproduct
92 
94  INTERFACE determinant
95  MODULE PROCEDURE determinantfullintg
96  MODULE PROCEDURE determinantfullsp
97  MODULE PROCEDURE determinantfulldp
98  END INTERFACE determinant
99 
101  INTERFACE edp
102  MODULE PROCEDURE edpsp
103  MODULE PROCEDURE edpdp
104  END INTERFACE edp
105 
107  INTERFACE eigenvalue
108  MODULE PROCEDURE eigenvaluefullsp
109  MODULE PROCEDURE eigenvaluefulldp
110  END INTERFACE eigenvalue
111 
113  INTERFACE eigenvector
114  MODULE PROCEDURE eigenvectorfullsp
115  MODULE PROCEDURE eigenvectorfulldp
116  END INTERFACE eigenvector
117 
119  INTERFACE i0
120  MODULE PROCEDURE i0dp
121  MODULE PROCEDURE i0sp
122  END INTERFACE i0
123 
125  INTERFACE i1
126  MODULE PROCEDURE i1dp
127  MODULE PROCEDURE i1sp
128  END INTERFACE i1
129 
131  INTERFACE invert
132  MODULE PROCEDURE invertfullsp
133  MODULE PROCEDURE invertfulldp
134  END INTERFACE invert
135 
137  INTERFACE k0
138  MODULE PROCEDURE k0dp
139  MODULE PROCEDURE k0sp
140  END INTERFACE k0
141 
143  INTERFACE k1
144  MODULE PROCEDURE k1dp
145  MODULE PROCEDURE k1sp
146  END INTERFACE k1
147 
149  INTERFACE kdp
150  MODULE PROCEDURE kdpdp
151  MODULE PROCEDURE kdpsp
152  END INTERFACE kdp
153 
155  INTERFACE identitymatrix
156  MODULE PROCEDURE identitymatrixsp
157  MODULE PROCEDURE identitymatrixdp
158  END INTERFACE identitymatrix
159 
161  INTERFACE l2norm
162  MODULE PROCEDURE l2normsp
163  MODULE PROCEDURE l2normdp
164  END INTERFACE l2norm
165 
167  INTERFACE matrix_product
168  MODULE PROCEDURE matrixproductsp
169  MODULE PROCEDURE matrixproductdp
170  END INTERFACE matrix_product
171 
173  INTERFACE matrixproduct
174  MODULE PROCEDURE matrixproductsp
175  MODULE PROCEDURE matrixproductdp
176  END INTERFACE matrixproduct
177 
180  MODULE PROCEDURE matrixtransposeproductsp
181  MODULE PROCEDURE matrixtransposeproductdp
182  END INTERFACE matrixtransposeproduct
183 
186  MODULE PROCEDURE matrixproducttransposesp
187  MODULE PROCEDURE matrixproducttransposedp
188  END INTERFACE matrixproducttranspose
189 
192  MODULE PROCEDURE matrixtransposesp
193  MODULE PROCEDURE matrixtransposedp
194  END INTERFACE matrix_transpose
195 
197  INTERFACE matrixtranspose
198  MODULE PROCEDURE matrixtransposesp
199  MODULE PROCEDURE matrixtransposedp
200  END INTERFACE matrixtranspose
201 
204  MODULE PROCEDURE matrixvectorproductsp
205  MODULE PROCEDURE matrixvectorproductdp
206  END INTERFACE matrix_vector_product
207 
210  MODULE PROCEDURE matrixvectorproductsp
211  MODULE PROCEDURE matrixvectorproductdp
212  END INTERFACE matrixvectorproduct
213 
216  MODULE PROCEDURE matrixtransposevectorproductsp
217  MODULE PROCEDURE matrixtransposevectorproductdp
218  END INTERFACE matrixtransposevectorproduct
219 
221  INTERFACE normalise
222  MODULE PROCEDURE normalisesp
223  MODULE PROCEDURE normalisedp
224  END INTERFACE normalise
225 
228  MODULE PROCEDURE normcrossproductsp
229  MODULE PROCEDURE normcrossproductdp
230  END INTERFACE norm_cross_product
231 
234  MODULE PROCEDURE normcrossproductsp
235  MODULE PROCEDURE normcrossproductdp
236  END INTERFACE normcrossproduct
237 
240  MODULE PROCEDURE solvesmalllinearsystemsp
241  MODULE PROCEDURE solvesmalllinearsystemdp
242  END INTERFACE solve_small_linear_system
243 
246  MODULE PROCEDURE solvesmalllinearsystemsp
247  MODULE PROCEDURE solvesmalllinearsystemdp
248  END INTERFACE solvesmalllinearsystem
249 
251  INTERFACE coth
252  MODULE PROCEDURE cothsp
253  MODULE PROCEDURE cothdp
254  END INTERFACE coth
255 
260 
261 
262 CONTAINS
263 
264  !
265  !================================================================================================================================
266  !
267 
269  SUBROUTINE crossproductintg(a,b,c,err,error,*)
270 
271  !Argument variables
272  INTEGER(INTG), INTENT(IN) :: a(:)
273  INTEGER(INTG), INTENT(IN) :: b(:)
274  INTEGER(INTG), INTENT(OUT) :: c(:)
275  INTEGER(INTG), INTENT(OUT) :: err
276  TYPE(varying_string), INTENT(OUT) :: error
277  !Local variables
278 
279  enters("CrossProductIntg",err,error,*999)
280 
281  IF(SIZE(a,1)==SIZE(b,1)) THEN
282  IF(SIZE(c,1)==3) THEN
283  SELECT CASE(SIZE(a,1))
284  CASE(3)
285  c(1)=a(2)*b(3)-a(3)*b(2)
286  c(2)=a(3)*b(1)-a(1)*b(3)
287  c(3)=a(1)*b(2)-a(2)*b(1)
288  CASE DEFAULT
289  CALL flagerror("Invalid vector size.",err,error,*999)
290  END SELECT
291  ELSE
292  CALL flagerror("The vector c is not the correct size.",err,error,*999)
293  ENDIF
294  ELSE
295  CALL flagerror("The vectors a and b are not the same size.",err,error,*999)
296  ENDIF
297 
298  exits("CrossProductIntg")
299  RETURN
300 999 errorsexits("CrossProductIntg",err,error)
301  RETURN 1
302 
303  END SUBROUTINE crossproductintg
304 
305  !
306  !================================================================================================================================
307  !
308 
310  SUBROUTINE crossproductsp(a,b,c,err,error,*)
311 
312  !Argument variables
313  REAL(SP), INTENT(IN) :: a(:)
314  REAL(SP), INTENT(IN) :: b(:)
315  REAL(SP), INTENT(OUT) :: c(:)
316  INTEGER(INTG), INTENT(OUT) :: err
317  TYPE(varying_string), INTENT(OUT) :: error
318  !Local variables
319 
320  enters("CrossProductSP",err,error,*999)
321 
322  IF(SIZE(a,1)==SIZE(b,1)) THEN
323  IF(SIZE(c,1)==3) THEN
324  SELECT CASE(SIZE(a,1))
325  CASE(3)
326  c(1)=a(2)*b(3)-a(3)*b(2)
327  c(2)=a(3)*b(1)-a(1)*b(3)
328  c(3)=a(1)*b(2)-a(2)*b(1)
329  CASE DEFAULT
330  CALL flagerror("Invalid vector size.",err,error,*999)
331  END SELECT
332  ELSE
333  CALL flagerror("The vector c is not the correct size.",err,error,*999)
334  ENDIF
335  ELSE
336  CALL flagerror("The vectors a and b are not the same size.",err,error,*999)
337  ENDIF
338 
339  exits("CrossProductSP")
340  RETURN
341 999 errorsexits("CrossProductSP",err,error)
342  RETURN 1
343 
344  END SUBROUTINE crossproductsp
345 
346  !
347  !================================================================================================================================
348  !
349 
351  SUBROUTINE crossproductdp(a,b,c,err,error,*)
352 
353  !Argument variables
354  REAL(DP), INTENT(IN) :: a(:)
355  REAL(DP), INTENT(IN) :: b(:)
356  REAL(DP), INTENT(OUT) :: c(:)
357  INTEGER(INTG), INTENT(OUT) :: err
358  TYPE(varying_string), INTENT(OUT) :: error
359  !Local variables
360 
361  enters("CrossProductDP",err,error,*999)
362 
363  IF(SIZE(a,1)==SIZE(b,1)) THEN
364  IF(SIZE(c,1)==3) THEN
365  SELECT CASE(SIZE(a,1))
366  CASE(3)
367  c(1)=a(2)*b(3)-a(3)*b(2)
368  c(2)=a(3)*b(1)-a(1)*b(3)
369  c(3)=a(1)*b(2)-a(2)*b(1)
370  CASE DEFAULT
371  CALL flagerror("Invalid vector size.",err,error,*999)
372  END SELECT
373  ELSE
374  CALL flagerror("The vector C is not the correct size.",err,error,*999)
375  ENDIF
376  ELSE
377  CALL flagerror("The vectors A and B are not the same size.",err,error,*999)
378  ENDIF
379 
380  exits("CrossProductDP")
381  RETURN
382 999 errorsexits("CrossProductDP",err,error)
383  RETURN 1
384 
385  END SUBROUTINE crossproductdp
386 
387  !
388  !================================================================================================================================
389  !
390 
393  SUBROUTINE dcrossproductintg(n,a,b,c,da,db,dc,err,error,*)
394 
395  !Argument variables
396  INTEGER(INTG), INTENT(IN) :: n
397  INTEGER(INTG), INTENT(IN) :: a(:)
398  INTEGER(INTG), INTENT(IN) :: b(:)
399  INTEGER(INTG), INTENT(OUT) :: c(:)
400  INTEGER(INTG), INTENT(IN) :: da(:,:)
401  INTEGER(INTG), INTENT(IN) :: db(:,:)
402  INTEGER(INTG), INTENT(OUT) :: dc(:,:)
403  INTEGER(INTG), INTENT(OUT) :: err
404  TYPE(varying_string), INTENT(OUT) :: error
405  !Local variables
406  INTEGER(INTG) :: derivIdx
407 
408  enters("dCrossProductIntg",err,error,*999)
409 
410  CALL crossproduct(a,b,c,err,error,*999)
411  IF(SIZE(da,1)==SIZE(db,1).AND.SIZE(a,1)==SIZE(da,1).AND.SIZE(b,1)==SIZE(db,1)) THEN
412  IF(SIZE(da,2)==n.AND.SIZE(db,2)==n) THEN
413  IF(SIZE(c,1)==3) THEN
414  SELECT CASE(SIZE(a,1))
415  CASE(3)
416  DO derividx=1,n
417  dc(1,derividx)=da(2,derividx)*b(3)-da(3,derividx)*b(2)+a(2)*db(3,derividx)-a(3)*db(2,derividx)
418  dc(2,derividx)=da(3,derividx)*b(1)-da(1,derividx)*b(3)+a(3)*db(1,derividx)-a(1)*db(3,derividx)
419  dc(3,derividx)=da(1,derividx)*b(2)-da(2,derividx)*b(1)+a(1)*db(2,derividx)-a(2)*db(1,derividx)
420  ENDDO !derivIdx
421  CASE DEFAULT
422  CALL flagerror("Invalid vector size.",err,error,*999)
423  END SELECT
424  ELSE
425  CALL flagerror("The vector c is not the correct size.",err,error,*999)
426  ENDIF
427  ELSE
428  CALL flagerror("The number of derivative vectors is too small.",err,error,*999)
429  ENDIF
430  ELSE
431  CALL flagerror("The vectors for da and db are not the same size.",err,error,*999)
432  ENDIF
433 
434  exits("dCrossProductIntg")
435  RETURN
436 999 errorsexits("dCrossProductIntg",err,error)
437  RETURN 1
438 
439  END SUBROUTINE dcrossproductintg
440 
441  !
442  !================================================================================================================================
443  !
444 
447  SUBROUTINE dcrossproductsp(n,a,b,c,da,db,dc,err,error,*)
448 
449  !Argument variables
450  INTEGER(INTG), INTENT(IN) :: n
451  REAL(SP), INTENT(IN) :: a(:)
452  REAL(SP), INTENT(IN) :: b(:)
453  REAL(SP), INTENT(OUT) :: c(:)
454  REAL(SP), INTENT(IN) :: da(:,:)
455  REAL(SP), INTENT(IN) :: db(:,:)
456  REAL(SP), INTENT(OUT) :: dc(:,:)
457  INTEGER(INTG), INTENT(OUT) :: err
458  TYPE(varying_string), INTENT(OUT) :: error
459  !Local variables
460  INTEGER(INTG) :: derivIdx
461 
462  enters("dCrossProductSP",err,error,*999)
463 
464  CALL crossproduct(a,b,c,err,error,*999)
465  IF(SIZE(da,1)==SIZE(db,1).AND.SIZE(a,1)==SIZE(da,1).AND.SIZE(b,1)==SIZE(db,1)) THEN
466  IF(SIZE(da,2)==n.AND.SIZE(db,2)==n) THEN
467  IF(SIZE(c,1)==3) THEN
468  SELECT CASE(SIZE(a,1))
469  CASE(3)
470  DO derividx=1,n
471  dc(1,derividx)=da(2,derividx)*b(3)-da(3,derividx)*b(2)+a(2)*db(3,derividx)-a(3)*db(2,derividx)
472  dc(2,derividx)=da(3,derividx)*b(1)-da(1,derividx)*b(3)+a(3)*db(1,derividx)-a(1)*db(3,derividx)
473  dc(3,derividx)=da(1,derividx)*b(2)-da(2,derividx)*b(1)+a(1)*db(2,derividx)-a(2)*db(1,derividx)
474  ENDDO !derivIdx
475  CASE DEFAULT
476  CALL flagerror("Invalid vector size.",err,error,*999)
477  END SELECT
478  ELSE
479  CALL flagerror("The vector c is not the correct size.",err,error,*999)
480  ENDIF
481  ELSE
482  CALL flagerror("The number of derivative vectors is too small.",err,error,*999)
483  ENDIF
484  ELSE
485  CALL flagerror("The vectors for da and db are not the same size.",err,error,*999)
486  ENDIF
487 
488  exits("dCrossProductSP")
489  RETURN
490 999 errorsexits("dCrossProductSP",err,error)
491  RETURN 1
492 
493  END SUBROUTINE dcrossproductsp
494 
495  !
496  !================================================================================================================================
497  !
498 
501  SUBROUTINE dcrossproductdp(n,a,b,c,da,db,dc,err,error,*)
502 
503  !Argument variables
504  INTEGER(INTG), INTENT(IN) :: n
505  REAL(DP), INTENT(IN) :: a(:)
506  REAL(DP), INTENT(IN) :: b(:)
507  REAL(DP), INTENT(OUT) :: c(:)
508  REAL(DP), INTENT(IN) :: da(:,:)
509  REAL(DP), INTENT(IN) :: db(:,:)
510  REAL(DP), INTENT(OUT) :: dc(:,:)
511  INTEGER(INTG), INTENT(OUT) :: err
512  TYPE(varying_string), INTENT(OUT) :: error
513  !Local variables
514  INTEGER(INTG) :: derivIdx
515 
516  enters("dCrossProductDP",err,error,*999)
517 
518  CALL crossproduct(a,b,c,err,error,*999)
519  IF(SIZE(da,1)==SIZE(db,1).AND.SIZE(a,1)==SIZE(da,1).AND.SIZE(b,1)==SIZE(db,1)) THEN
520  IF(SIZE(da,2)==n.AND.SIZE(db,2)==n) THEN
521  IF(SIZE(c,1)==3) THEN
522  SELECT CASE(SIZE(a,1))
523  CASE(3)
524  DO derividx=1,n
525  dc(1,derividx)=da(2,derividx)*b(3)-da(3,derividx)*b(2)+a(2)*db(3,derividx)-a(3)*db(2,derividx)
526  dc(2,derividx)=da(3,derividx)*b(1)-da(1,derividx)*b(3)+a(3)*db(1,derividx)-a(1)*db(3,derividx)
527  dc(3,derividx)=da(1,derividx)*b(2)-da(2,derividx)*b(1)+a(1)*db(2,derividx)-a(2)*db(1,derividx)
528  ENDDO !derivIdx
529  CASE DEFAULT
530  CALL flagerror("Invalid vector size.",err,error,*999)
531  END SELECT
532  ELSE
533  CALL flagerror("The vector c is not the correct size.",err,error,*999)
534  ENDIF
535  ELSE
536  CALL flagerror("The number of derivative vectors is too small.",err,error,*999)
537  ENDIF
538  ELSE
539  CALL flagerror("The vectors for da and db are not the same size.",err,error,*999)
540  ENDIF
541 
542  exits("dCrossProductDP")
543  RETURN
544 999 errorsexits("dCrossProductDP",err,error)
545  RETURN 1
546 
547  END SUBROUTINE dcrossproductdp
548 
549  !
550  !================================================================================================================================
551  !
552 
554  SUBROUTINE matrixvectorproductsp(A,b,c,err,error,*)
556  !Argument variables
557  REAL(SP), INTENT(IN) :: A(:,:)
558  REAL(SP), INTENT(IN) :: b(:)
559  REAL(SP), INTENT(OUT) :: c(:)
560  INTEGER(INTG) :: err
561  TYPE(varying_string), INTENT(OUT) :: error
562 
563  enters("MatrixVectorProductSP",err,error,*999)
564 
565  IF(SIZE(a,2)==SIZE(b,1).AND.SIZE(a,1)==SIZE(c,1)) THEN
566  SELECT CASE(SIZE(a,1))
567  CASE(1)
568  c(1)=a(1,1)*b(1)
569  CASE(2)
570  c(1)=a(1,1)*b(1)+a(1,2)*b(2)
571  c(2)=a(2,1)*b(1)+a(2,2)*b(2)
572  CASE(3)
573  c(1)=a(1,1)*b(1)+a(1,2)*b(2)+a(1,3)*b(3)
574  c(2)=a(2,1)*b(1)+a(2,2)*b(2)+a(2,3)*b(3)
575  c(3)=a(3,1)*b(1)+a(3,2)*b(2)+a(3,3)*b(3)
576  CASE DEFAULT
577  CALL flagerror("Invalid matrix and/or vector size.",err,error,*999)
578  END SELECT
579  ELSE
580  CALL flagerror("Invalid matrix sizes.",err,error,*999)
581  ENDIF
582 
583  exits("MatrixVectorProductSP")
584  RETURN
585 999 errorsexits("MatrixVectorProductSP",err,error)
586  RETURN 1
587 
588  END SUBROUTINE matrixvectorproductsp
589 
590  !
591  !================================================================================================================================
592  !
593 
595  SUBROUTINE matrixvectorproductdp(A,b,c,err,error,*)
597  !Argument variables
598  REAL(DP), INTENT(IN) :: A(:,:)
599  REAL(DP), INTENT(IN) :: B(:)
600  REAL(DP), INTENT(OUT) :: C(:)
601  INTEGER(INTG) :: err
602  TYPE(varying_string), INTENT(OUT) :: error
603 
604  enters("MatrixVectorProductDP",err,error,*999)
605 
606  IF(SIZE(a,2)==SIZE(b,1).AND.SIZE(a,1)==SIZE(c,1)) THEN
607  SELECT CASE(SIZE(a,1))
608  CASE(1)
609  c(1)=a(1,1)*b(1)
610  CASE(2)
611  c(1)=a(1,1)*b(1)+a(1,2)*b(2)
612  c(2)=a(2,1)*b(1)+a(2,2)*b(2)
613  CASE(3)
614  c(1)=a(1,1)*b(1)+a(1,2)*b(2)+a(1,3)*b(3)
615  c(2)=a(2,1)*b(1)+a(2,2)*b(2)+a(2,3)*b(3)
616  c(3)=a(3,1)*b(1)+a(3,2)*b(2)+a(3,3)*b(3)
617  CASE DEFAULT
618  CALL flagerror("Invalid matrix and/or vector size.",err,error,*999)
619  END SELECT
620  ELSE
621  CALL flagerror("Invalid matrix sizes.",err,error,*999)
622  ENDIF
623 
624  exits("MatrixVectorProductDP")
625  RETURN
626 999 errorsexits("MatrixVectorProductDP",err,error)
627  RETURN 1
628 
629  END SUBROUTINE matrixvectorproductdp
630 
631  !
632  !================================================================================================================================
633  !
634 
636  SUBROUTINE matrixtransposevectorproductsp(A,b,c,err,error,*)
638  !Argument variables
639  REAL(SP), INTENT(IN) :: A(:,:)
640  REAL(SP), INTENT(IN) :: b(:)
641  REAL(SP), INTENT(OUT) :: c(:)
642  INTEGER(INTG) :: err
643  TYPE(varying_string), INTENT(OUT) :: error
644 
645  enters("MatrixTransposeVectorProductSP",err,error,*999)
646 
647  IF(SIZE(a,1)==SIZE(b,1).AND.SIZE(a,2)==SIZE(c,1)) THEN
648  SELECT CASE(SIZE(a,2))
649  CASE(1)
650  c(1)=a(1,1)*b(1)
651  CASE(2)
652  c(1)=a(1,1)*b(1)+a(2,1)*b(2)
653  c(2)=a(1,2)*b(1)+a(2,2)*b(2)
654  CASE(3)
655  c(1)=a(1,1)*b(1)+a(2,1)*b(2)+a(3,1)*b(3)
656  c(2)=a(1,2)*b(1)+a(2,2)*b(2)+a(3,2)*b(3)
657  c(3)=a(1,3)*b(1)+a(2,3)*b(2)+a(3,3)*b(3)
658  CASE DEFAULT
659  CALL flagerror("Invalid matrix and/or vector size.",err,error,*999)
660  END SELECT
661  ELSE
662  CALL flagerror("Invalid matrix sizes.",err,error,*999)
663  ENDIF
664 
665  exits("MatrixTransposeVectorProductSP")
666  RETURN
667  999 errorsexits("MatrixTransposeVectorProductSP",err,error)
668  RETURN 1
669 
670  END SUBROUTINE matrixtransposevectorproductsp
671 
672  !
673  !================================================================================================================================
674  !
675 
677  SUBROUTINE matrixtransposevectorproductdp(A,b,c,err,error,*)
679  !Argument variables
680  REAL(DP), INTENT(IN) :: A(:,:)
681  REAL(DP), INTENT(IN) :: b(:)
682  REAL(DP), INTENT(OUT) :: c(:)
683  INTEGER(INTG) :: err
684  TYPE(varying_string), INTENT(OUT) :: error
685 
686  enters("MatrixTransposeVectorProductDP",err,error,*999)
687 
688  IF(SIZE(a,1)==SIZE(b,1).AND.SIZE(a,2)==SIZE(c,1)) THEN
689  SELECT CASE(SIZE(a,2))
690  CASE(1)
691  c(1)=a(1,1)*b(1)
692  CASE(2)
693  c(1)=a(1,1)*b(1)+a(2,1)*b(2)
694  c(2)=a(1,2)*b(1)+a(2,2)*b(2)
695  CASE(3)
696  c(1)=a(1,1)*b(1)+a(2,1)*b(2)+a(3,1)*b(3)
697  c(2)=a(1,2)*b(1)+a(2,2)*b(2)+a(3,2)*b(3)
698  c(3)=a(1,3)*b(1)+a(2,3)*b(2)+a(3,3)*b(3)
699  CASE DEFAULT
700  CALL flagerror("Invalid matrix and/or vector size.",err,error,*999)
701  END SELECT
702  ELSE
703  CALL flagerror("Invalid matrix sizes.",err,error,*999)
704  ENDIF
705 
706  exits("MatrixTransposeVectorProductDP")
707  RETURN
708  999 errorsexits("MatrixTransposeVectorProductDP",err,error)
709  RETURN 1
710 
711  END SUBROUTINE matrixtransposevectorproductdp
712 
713  !
714  !================================================================================================================================
715  !
716 
718  FUNCTION determinantfullintg(A,err,error)
719 
720  !Argument variables
721  INTEGER(INTG), INTENT(IN) :: A(:,:)
722  INTEGER(INTG), INTENT(OUT) :: err
723  TYPE(varying_string), INTENT(OUT) :: error
724  !Function variable
725  INTEGER(INTG) :: DeterminantFullIntg
726 
727  enters("DeterminantFullIntg",err,error,*999)
728 
729  determinantfullintg=0
730 
731  IF(SIZE(a,1)==SIZE(a,2)) THEN
732  SELECT CASE(SIZE(a,1))
733  CASE(1)
734  determinantfullintg=a(1,1)
735  CASE(2)
736  determinantfullintg=a(1,1)*a(2,2)-a(2,1)*a(1,2)
737  CASE(3)
738  determinantfullintg=a(1,1)*a(2,2)*a(3,3)+a(1,2)*a(2,3)*a(3,1)+a(1,3)*a(2,1)*a(3,2)-a(1,1)*a(3,2)*a(2,3)- &
739  a(2,1)*a(1,2)*a(3,3)-a(3,1)*a(2,2)*a(1,3)
740  CASE DEFAULT
741  CALL flagerror("Matrix size not implemented.",err,error,*999)
742  END SELECT
743  ELSE
744  CALL flagerror("Matrix is not square.",err,error,*999)
745  ENDIF
746 
747  exits("DeterminantFullIntg")
748  RETURN
749 999 errorsexits("DeterminantFullIntg",err,error)
750  RETURN
751 
752  END FUNCTION determinantfullintg
753 
754  !
755  !================================================================================================================================
756  !
757 
759  FUNCTION determinantfullsp(A,err,error)
760 
761  !Argument variables
762  REAL(SP), INTENT(IN) :: A(:,:)
763  INTEGER(INTG), INTENT(OUT) :: err
764  TYPE(varying_string), INTENT(OUT) :: error
765  !Function variable
766  REAL(SP) :: DeterminantFullSP
767 
768  enters("DeterminantFullSP",err,error,*999)
769 
770  determinantfullsp=0.0_sp
771 
772  IF(SIZE(a,1)==SIZE(a,2)) THEN
773  SELECT CASE(SIZE(a,1))
774  CASE(1)
775  determinantfullsp=a(1,1)
776  CASE(2)
777  determinantfullsp=a(1,1)*a(2,2)-a(2,1)*a(1,2)
778  CASE(3)
779  determinantfullsp=a(1,1)*a(2,2)*a(3,3)+a(1,2)*a(2,3)*a(3,1)+a(1,3)*a(2,1)*a(3,2)-a(1,1)*a(3,2)*a(2,3)- &
780  a(2,1)*a(1,2)*a(3,3)-a(3,1)*a(2,2)*a(1,3)
781  CASE DEFAULT
782  CALL flagerror("Matrix size not implemented.",err,error,*999)
783  END SELECT
784  ELSE
785  CALL flagerror("Matrix is not square.",err,error,*999)
786  ENDIF
787 
788  exits("DeterminantFullSP")
789  RETURN
790 999 errorsexits("DeterminantFullSP",err,error)
791  RETURN
792 
793  END FUNCTION determinantfullsp
794 
795  !
796  !================================================================================================================================
797  !
798 
800  FUNCTION determinantfulldp(A,err,error)
801 
802  !Argument variables
803  REAL(DP), INTENT(IN) :: A(:,:)
804  INTEGER(INTG), INTENT(OUT) :: err
805  TYPE(varying_string), INTENT(OUT) :: error
806  !Function variable
807  REAL(DP) :: DeterminantFullDP
808 
809  enters("DeterminantFullDP",err,error,*999)
810 
811  determinantfulldp=0.0_dp
812 
813  IF(SIZE(a,1)==SIZE(a,2)) THEN
814  SELECT CASE(SIZE(a,1))
815  CASE(1)
816  determinantfulldp=a(1,1)
817  CASE(2)
818  determinantfulldp=a(1,1)*a(2,2)-a(2,1)*a(1,2)
819  CASE(3)
820  determinantfulldp=a(1,1)*a(2,2)*a(3,3)+a(1,2)*a(2,3)*a(3,1)+a(1,3)*a(2,1)*a(3,2)-a(1,1)*a(3,2)*a(2,3)- &
821  a(2,1)*a(1,2)*a(3,3)-a(3,1)*a(2,2)*a(1,3)
822  CASE DEFAULT
823  CALL flagerror("Matrix size not implemented.",err,error,*999)
824  END SELECT
825  ELSE
826  CALL flagerror("Matrix is not square.",err,error,*999)
827  ENDIF
828 
829  exits("DeterminantFullDP")
830  RETURN
831 999 errorsexits("DeterminantFullDP",err,error)
832  RETURN
833 
834  END FUNCTION determinantfulldp
835 
836  !
837  !================================================================================================================================
838  !
839 
841  PURE FUNCTION edpdp(x)
842 
843  !Argument variables
844  REAL(DP), INTENT(IN) :: x
845  !Function variable
846  REAL(DP) :: EdpDP
847  !Local variables
848  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
849  REAL(DP), PARAMETER :: a1=0.44325141463_dp
850  REAL(DP), PARAMETER :: a2=0.06260601220_dp
851  REAL(DP), PARAMETER :: a3=0.04757383546_dp
852  REAL(DP), PARAMETER :: a4=0.01736506451_dp
853  REAL(DP), PARAMETER :: b1=0.24998368310_dp
854  REAL(DP), PARAMETER :: b2=0.09200180037_dp
855  REAL(DP), PARAMETER :: b3=0.04069697526_dp
856  REAL(DP), PARAMETER :: b4=0.00526449639_dp
857  REAL(DP) :: term1,term2,x1
858 
859  x1=1.0_dp-x
860  term1=1.0_dp+(a1+(a2+(a3+a4*x1)*x1)*x1)*x1
861  term2=(b1+(b2+(b3+b4*x1)*x1)*x1)*x1
862  edpdp=term1+term2*log(1.0_dp/x1)
863 
864  RETURN
865  END FUNCTION edpdp
866 
867  !
868  !================================================================================================================================
869  !
870 
872  PURE FUNCTION edpsp(x)
873 
874  !Argument variables
875  REAL(SP), INTENT(IN) :: x
876  !Function variable
877  REAL(SP) :: EdpSP
878  !Local variables
879  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
880  REAL(SP), PARAMETER :: a1=0.44325141463_sp
881  REAL(SP), PARAMETER :: a2=0.06260601220_sp
882  REAL(SP), PARAMETER :: a3=0.04757383546_sp
883  REAL(SP), PARAMETER :: a4=0.01736506451_sp
884  REAL(SP), PARAMETER :: b1=0.24998368310_sp
885  REAL(SP), PARAMETER :: b2=0.09200180037_sp
886  REAL(SP), PARAMETER :: b3=0.04069697526_sp
887  REAL(SP), PARAMETER :: b4=0.00526449639_sp
888  REAL(SP) :: term1,term2,x1
889 
890  x1=1.0_sp-x
891  term1=1.0_sp+(a1+(a2+(a3+a4*x1)*x1)*x1)*x1
892  term2=(b1+(b2+(b3+b4*x1)*x1)*x1)*x1
893  edpsp=term1+term2*log(1.0_sp/x1)
894 
895  RETURN
896 
897  END FUNCTION edpsp
898 
899  !
900  !================================================================================================================================
901  !
902 
904  SUBROUTINE eigenvaluefullsp(A,eValues,err,error,*)
905 
906  !Argument variables
907  REAL(SP), INTENT(IN) :: A(:,:)
908  REAL(SP), INTENT(OUT) :: eValues(:)
909  INTEGER(INTG), INTENT(OUT) :: err
910  TYPE(varying_string), INTENT(OUT) :: error
911  !Local variables
912  INTEGER(INTG) :: i
913  REAL(SP) :: angle,b2,b3,c1,c2,d,q,q3,r,ri1,ri2,ri3,ri4,rq,temp,theta
914 
915  enters("EigenvalueFullSP",err,error,*999)
916 
917  IF(SIZE(a,1)==SIZE(a,2)) THEN
918  IF(SIZE(a,1)<=SIZE(evalues,1)) THEN
919  SELECT CASE(SIZE(a,1))
920  CASE(1)
921  evalues(1)=a(1,1)
922  CASE(2)
923  IF(abs(a(1,2))>zero_tolerance_sp) THEN
924  ri1=a(1,1)+a(2,2)
925  ri2=a(1,1)*a(2,2)-a(1,2)**2
926  b2=ri1/2.0_sp
927  c1=ri1*ri1
928  c2=4.0_sp*ri2
929  IF(c2>c1) CALL flagerror("Complex roots found in quadratic equation.",err,error,*999)
930  b3=sqrt(c1-c2)/2.0_sp
931  evalues(1)=b2+b3
932  evalues(2)=b2-b3
933  ELSE
934  evalues(1)=a(1,1)
935  evalues(2)=a(2,2)
936  ENDIF
937  IF(abs(evalues(2))>abs(evalues(1))) THEN
938  temp=evalues(1)
939  evalues(1)=evalues(2)
940  evalues(2)=temp
941  ENDIF
942  CASE(3)
943  ri1=a(1,1)+a(2,2)+a(3,3)
944  ri2=a(1,1)*a(2,2)+a(2,2)*a(3,3)+a(3,3)*a(1,1)-(a(1,2)**2+a(2,3)**2+a(3,1)**2)
945  ri3=determinant(a,err,error)
946  IF(err/=0) GOTO 999
947  ri4=ri1/3.0_sp
948  q=ri4*ri4-ri2/3.0_sp
949  r=ri4*(ri4*ri4-ri2/2.0_sp)+ri3/2.0_sp
950  q3=q*q*q
951  d=r*r-q3
952  IF(abs(d)>zero_tolerance_sp) CALL flagerror("Complex roots found in solution of cubic equation.",err,error,*999)
953  rq=sqrt(abs(q))
954  IF(abs(q)<zero_tolerance_sp) THEN
955  theta=0.0_sp
956  ELSE
957  theta=acos(r/sqrt(abs(q3)))/3.0_sp
958  ENDIF
959  angle=2.0_sp*REAL(pi,sp)/3.0_SP
960  evalues(1)=2.0_sp*rq*cos(theta)+ri4
961  evalues(2)=2.0_sp*rq*cos(theta+angle)+ri4
962  evalues(3)=2.0_sp*rq*cos(theta+2.0_sp*angle)+ri4
963  DO i=1,2
964  IF(abs(evalues(3))>abs(evalues(i))) THEN
965  temp=evalues(i)
966  evalues(i)=evalues(3)
967  evalues(3)=temp
968  ENDIF
969  ENDDO !i
970  CASE DEFAULT
971  CALL flagerror("Matrix size not implemented.",err,error,*999)
972  END SELECT
973  ELSE
974  CALL flagerror("Evalues is too small.",err,error,*999)
975  ENDIF
976  ELSE
977  CALL flagerror("Matrix is not square.",err,error,*999)
978  ENDIF
979 
980  exits("EigenvalueFullSP")
981  RETURN
982 999 errorsexits("EigenvalueFullSP",err,error)
983  RETURN 1
984 
985  END SUBROUTINE eigenvaluefullsp
986 
987  !
988  !================================================================================================================================
989  !
990 
992  SUBROUTINE eigenvaluefulldp(A,eValues,err,error,*)
993 
994  !Argument variables
995  REAL(DP), INTENT(IN) :: A(:,:)
996  REAL(DP), INTENT(OUT) :: eValues(:)
997  INTEGER(INTG), INTENT(OUT) :: err
998  TYPE(varying_string), INTENT(OUT) :: error
999  !Local variables
1000  INTEGER(INTG) :: i
1001  REAL(DP) :: angle,b2,b3,c1,c2,d,q,q3,r,ri1,ri2,ri3,ri4,rq,temp,theta
1002 
1003  enters("EigenvalueFullDP",err,error,*999)
1004 
1005  IF(SIZE(a,1)==SIZE(a,2)) THEN
1006  IF(SIZE(a,1)<= SIZE(evalues,1)) THEN
1007  SELECT CASE(SIZE(a,1))
1008  CASE(1)
1009  evalues(1)=a(1,1)
1010  CASE(2)
1011  IF(abs(a(1,2))>zero_tolerance_dp) THEN
1012  ri1=a(1,1)+a(2,2)
1013  ri2=a(1,1)*a(2,2)-a(1,2)**2
1014  b2=ri1/2.0_dp
1015  c1=ri1*ri1
1016  c2=4.0_dp*ri2
1017  IF(c2>c1) CALL flagerror("Complex roots found in quadratic equation.",err,error,*999)
1018  b3=sqrt(c1-c2)/2.0_dp
1019  evalues(1)=b2+b3
1020  evalues(2)=b2-b3
1021  ELSE
1022  evalues(1)=a(1,1)
1023  evalues(2)=a(2,2)
1024  ENDIF
1025  IF(abs(evalues(2))>abs(evalues(1))) THEN
1026  temp=evalues(1)
1027  evalues(1)=evalues(2)
1028  evalues(2)=temp
1029  ENDIF
1030  CASE(3)
1031  ri1=a(1,1)+a(2,2)+a(3,3)
1032  ri2=a(1,1)*a(2,2)+a(2,2)*a(3,3)+a(3,3)*a(1,1)-(a(1,2)**2+a(2,3)**2+a(3,1)**2)
1033  ri3=determinant(a,err,error)
1034  IF(err/=0) GOTO 999
1035  ri4=ri1/3.0_dp
1036  q=ri4*ri4-ri2/3.0_dp
1037  r=ri4*(ri4*ri4-ri2/2.0_dp)+ri3/2.0_dp
1038  q3=q*q*q
1039  d=r*r-q3
1040  IF(abs(d)>zero_tolerance_dp) CALL flagerror("Complex roots found in solution of cubic equation.",err,error,*999)
1041  rq=sqrt(abs(q))
1042  IF(abs(q)<zero_tolerance_dp) THEN
1043  theta=0.0_dp
1044  ELSE
1045  theta=acos(r/sqrt(abs(q3)))/3.0_dp
1046  ENDIF
1047  angle=2.0_dp*pi/3.0_dp
1048  evalues(1)=2.0_dp*rq*cos(theta)+ri4
1049  evalues(2)=2.0_dp*rq*cos(theta+angle)+ri4
1050  evalues(3)=2.0_dp*rq*cos(theta+2.0_dp*angle)+ri4
1051  DO i=1,2
1052  IF(abs(evalues(3))>abs(evalues(i))) THEN
1053  temp=evalues(i)
1054  evalues(i)=evalues(3)
1055  evalues(3)=temp
1056  ENDIF
1057  ENDDO !i
1058  CASE DEFAULT
1059  CALL flagerror("Matrix size not implemented.",err,error,*999)
1060  END SELECT
1061  ELSE
1062  CALL flagerror("Evalues is too small.",err,error,*999)
1063  ENDIF
1064  ELSE
1065  CALL flagerror("Matrix is not square.",err,error,*999)
1066  ENDIF
1067 
1068  exits("EigenvalueFullDP")
1069  RETURN
1070 999 errorsexits("EigenvalueFullDP",err,error)
1071  RETURN 1
1072 
1073  END SUBROUTINE eigenvaluefulldp
1074 
1075  !
1076  !================================================================================================================================
1077  !
1078 
1080  SUBROUTINE eigenvectorfullsp(A,eValue,eVector,err,error,*)
1082  !Argument variables
1083  REAL(SP), INTENT(IN) :: A(:,:)
1084  REAL(SP), INTENT(IN) :: eValue
1085  REAL(SP), INTENT(OUT) :: eVector(:)
1086  INTEGER(INTG), INTENT(OUT) :: err
1087  TYPE(varying_string), INTENT(OUT) :: error
1088  !Local variables
1089  INTEGER(INTG) :: i,i1,i2,i3,iCycle(3,3)
1090  REAL(SP) :: al,b(size(a,1)),sum,U(size(a,1),size(a,2)),x(size(a,1))
1091 
1092  DATA icycle /2,1,1,3,1,2,1,2,1/
1093 
1094  enters("EigenvectorFullSP",err,error,*999)
1095 
1096 !!THIS NEEDS TO BE CHECKED
1097 
1098  IF(SIZE(a,1)==SIZE(a,2)) THEN
1099  IF(SIZE(a,1)<=SIZE(evector,1)) THEN
1100  SELECT CASE(SIZE(a,1))
1101  CASE(1)
1102  evector(1)=1.0_sp
1103  CASE(2)
1104  IF(abs(a(1,2))>zero_tolerance_sp) THEN
1105  IF(abs(a(1,1)-evalue)>abs(a(2,2)-evalue)) THEN
1106  al=sqrt(a(1,2)**2+(a(1,1)-evalue)**2)
1107  evector(1)=a(1,2)/al
1108  evector(2)=(evalue-a(1,1))/al
1109  ELSE
1110  al=sqrt(a(1,2)**2+(a(2,2)-evalue)**2)
1111  evector(1)=(evalue-a(2,2))/al
1112  evector(2)=a(1,2)/al
1113  ENDIF
1114  ELSE IF(abs(evalue-a(1,1))<zero_tolerance_sp) THEN
1115  evector(1)=1.0_sp
1116  evector(2)=0.0_sp
1117  ELSE IF(abs(evalue-a(2,2))<zero_tolerance_sp) THEN
1118  evector(1)=0.0_sp
1119  evector(2)=1.0_dp
1120  ENDIF
1121  CASE(3)
1122  IF(abs(a(1,2))<zero_tolerance_sp.AND.abs(a(1,3))<zero_tolerance_sp.AND.abs(a(2,3))<zero_tolerance_sp) THEN
1123  evector=0.0_sp
1124  CALL flagerror("Zero matrix?? Eigenvectors undetermined.",err,error,*999)
1125  ELSE
1126  DO i=1,3
1127  u(i,:)=a(i,:)
1128  u(i,i)=u(i,i)-evalue
1129  ENDDO !i
1130  DO i=1,3
1131  x(i)=1.0_sp
1132  i1=icycle(i,1)
1133  i2=icycle(i,2)
1134  i3=icycle(i,3)
1135  b(1)=-1.0_sp*u(i1,i)
1136  b(2)=-1.0_sp*u(i2,i)
1137  CALL solvesmalllinearsystem(u(i1:i2:i3,i1:i2:i3),x,b,err,error,*999)
1138  sum=dot_product(u(i,:),x)
1139  IF(abs(sum)<zero_tolerance_sp) THEN
1140  evector=normalise(x,err,error)
1141  IF(err /= 0) GOTO 999
1142  ENDIF
1143  ENDDO !i
1144  ENDIF
1145  CASE DEFAULT
1146  CALL flagerror("Matrix size not implemented.",err,error,*999)
1147  END SELECT
1148  ELSE
1149  CALL flagerror("Evector is too small.",err,error,*999)
1150  ENDIF
1151  ELSE
1152  CALL flagerror("Matrix is not square.",err,error,*999)
1153  ENDIF
1154 
1155  exits("EigenvectorFullSP")
1156  RETURN
1157 999 errorsexits("EigenvectorFullSP",err,error)
1158  RETURN 1
1159 
1160  END SUBROUTINE eigenvectorfullsp
1161 
1162  !
1163  !================================================================================================================================
1164  !
1165 
1167  SUBROUTINE eigenvectorfulldp(A,eValue,eVector,err,error,*)
1169  !Argument variables
1170  REAL(DP), INTENT(IN) :: A(:,:)
1171  REAL(DP), INTENT(IN) :: eValue
1172  REAL(DP), INTENT(OUT) :: eVector(:)
1173  INTEGER(INTG), INTENT(OUT) :: err
1174  TYPE(varying_string), INTENT(OUT) :: error
1175  !Local variables
1176  INTEGER(INTG) :: i,i1,i2,i3,iCycle(3,3)
1177  REAL(DP) :: al,b(size(a,1)),sum,U(size(a,1),size(a,2)),x(size(a,1))
1178 
1179  DATA icycle /2,1,1,3,1,2,1,2,1/
1180 
1181  enters("EigenvectorFullDP",err,error,*999)
1182 
1183 !!THIS NEEDS TO BE CHECKED
1184 
1185  IF(SIZE(a,1)==SIZE(a,2)) THEN
1186  IF(SIZE(a,1)<=SIZE(evector,1)) THEN
1187  SELECT CASE(SIZE(a,1))
1188  CASE(1)
1189  evector(1)=1.0_dp
1190  CASE(2)
1191  IF(abs(a(1,2))>zero_tolerance_dp) THEN
1192  IF(abs(a(1,1)-evalue)>abs(a(2,2)-evalue)) THEN
1193  al=sqrt(a(1,2)**2+(a(1,1)-evalue)**2)
1194  evector(1)=a(1,2)/al
1195  evector(2)=(evalue-a(1,1))/al
1196  ELSE
1197  al=sqrt(a(1,2)**2+(a(2,2)-evalue)**2)
1198  evector(1)=(evalue-a(2,2))/al
1199  evector(2)=a(1,2)/al
1200  ENDIF
1201  ELSE IF(abs(evalue-a(1,1))<zero_tolerance_dp) THEN
1202  evector(1)=1.0_dp
1203  evector(2)=0.0_dp
1204  ELSE IF(abs(evalue-a(2,2))<zero_tolerance_dp) THEN
1205  evector(1)=0.0_dp
1206  evector(2)=1.0_dp
1207  ENDIF
1208  CASE(3)
1209  IF(abs(a(1,2))<zero_tolerance_dp.AND.abs(a(1,3))<zero_tolerance_dp.AND.abs(a(2,3))<zero_tolerance_dp) THEN
1210  evector=0.0_dp
1211  CALL flagerror("Zero matrix?? Eigenvectors undetermined.",err,error,*999)
1212  ELSE
1213  DO i=1,3
1214  u(i,:)=a(i,:)
1215  u(i,i)=u(i,i)-evalue
1216  ENDDO !i
1217  DO i=1,3
1218  x(i)=1.0_dp
1219  i1=icycle(i,1)
1220  i2=icycle(i,2)
1221  i3=icycle(i,3)
1222  b(1)=-1.0_dp*u(i1,i)
1223  b(2)=-1.0_dp*u(i2,i)
1224  CALL solvesmalllinearsystem(u(i1:i2:i3,i1:i2:i3),x,b,err,error,*999)
1225  sum=dot_product(u(i,:),x)
1226  IF(abs(sum)<zero_tolerance_dp) THEN
1227  evector=normalise(x,err,error)
1228  IF(err /= 0) GOTO 999
1229  ENDIF
1230  ENDDO !i
1231  ENDIF
1232  CASE DEFAULT
1233  CALL flagerror("Matrix size not implemented.",err,error,*999)
1234  END SELECT
1235  ELSE
1236  CALL flagerror("Evector is too small.",err,error,*999)
1237  ENDIF
1238  ELSE
1239  CALL flagerror("Matrix is not square.",err,error,*999)
1240  ENDIF
1241 
1242  exits("EigenvectorFullDP")
1243  RETURN
1244 999 errorsexits("EigenvectorFullDP",err,error)
1245  RETURN 1
1246 
1247  END SUBROUTINE eigenvectorfulldp
1248 
1249  !
1250  !================================================================================================================================
1251  !
1252 
1255  PURE FUNCTION i0dp(x)
1257  !Argument variables
1258  REAL(DP), INTENT(IN) :: x
1259  !Function variable
1260  REAL(DP) :: I0DP
1261  !Local variables
1262  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
1263  REAL(DP), PARAMETER :: a1=1.0_dp
1264  REAL(DP), PARAMETER :: a2=3.5156229_dp
1265  REAL(DP), PARAMETER :: a3=3.0899424_dp
1266  REAL(DP), PARAMETER :: a4=1.2067492_dp
1267  REAL(DP), PARAMETER :: a5=0.2659732_dp
1268  REAL(DP), PARAMETER :: a6=0.0360768_dp
1269  REAL(DP), PARAMETER :: a7=0.0045813_dp
1270  REAL(DP) :: t
1271 
1272  !Calculate I0(x) for x < 3.75
1273  t=x*x/(3.75_dp*3.75_dp)
1274  i0dp=a1+(a2+(a3+(a4+(a5+(a6+a7*t)*t)*t)*t)*t)*t
1275 
1276  RETURN
1277 
1278  END FUNCTION i0dp
1279 
1280  !
1281  !================================================================================================================================
1282  !
1283 
1286  PURE FUNCTION i0sp(x)
1288  !Argument variables
1289  REAL(SP), INTENT(IN) :: x
1290  !Function variable
1291  REAL(SP) :: I0SP
1292  !Local variables
1293  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
1294  REAL(SP), PARAMETER :: a1=1.0_sp
1295  REAL(SP), PARAMETER :: a2=3.5156229_sp
1296  REAL(SP), PARAMETER :: a3=3.0899424_sp
1297  REAL(SP), PARAMETER :: a4=1.2067492_sp
1298  REAL(SP), PARAMETER :: a5=0.2659732_sp
1299  REAL(SP), PARAMETER :: a6=0.0360768_sp
1300  REAL(SP), PARAMETER :: a7=0.0045813_sp
1301  REAL(SP) :: t
1302 
1303  !Calculate I0(x) for x < 3.75
1304  t=x*x/(3.75_sp*3.75_sp)
1305  i0sp=a1+(a2+(a3+(a4+(a5+(a6+a7*t)*t)*t)*t)*t)*t
1306 
1307  RETURN
1308 
1309  END FUNCTION i0sp
1310 
1311  !
1312  !================================================================================================================================
1313  !
1314 
1317  PURE FUNCTION i1dp(x)
1319  !Argument variables
1320  REAL(DP), INTENT(IN) :: x
1321  !Function variable
1322  REAL(DP) :: I1DP
1323  !Local variables
1324  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
1325  REAL(DP), PARAMETER :: a1=0.5_dp
1326  REAL(DP), PARAMETER :: a2=0.87890594_dp
1327  REAL(DP), PARAMETER :: a3=0.51498869_dp
1328  REAL(DP), PARAMETER :: a4=0.15084934_dp
1329  REAL(DP), PARAMETER :: a5=0.02658733_dp
1330  REAL(DP), PARAMETER :: a6=0.00301532_dp
1331  REAL(DP), PARAMETER :: a7=0.00032411_dp
1332  REAL(DP) :: t
1333 
1334  !Calculate I1(x)
1335  t=(x/3.75_dp)*(x/3.75_dp)
1336  i1dp=(a1+(a2+(a3+(a4+(a5+(a6+a7*t)*t)*t)*t)*t)*t)*x
1337 
1338  RETURN
1339 
1340  END FUNCTION i1dp
1341 
1342  !
1343  !================================================================================================================================
1344  !
1345 
1348  PURE FUNCTION i1sp(x)
1350  !Argument variables
1351  REAL(SP), INTENT(IN) :: x
1352  !Function variable
1353  REAL(SP) :: I1SP
1354  !Local variables
1355  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
1356  REAL(SP), PARAMETER :: a1=0.5_sp
1357  REAL(SP), PARAMETER :: a2=0.87890594_sp
1358  REAL(SP), PARAMETER :: a3=0.51498869_sp
1359  REAL(SP), PARAMETER :: a4=0.15084934_sp
1360  REAL(SP), PARAMETER :: a5=0.02658733_sp
1361  REAL(SP), PARAMETER :: a6=0.00301532_sp
1362  REAL(SP), PARAMETER :: a7=0.00032411_sp
1363  REAL(SP) :: t
1364 
1365  !Calculate I1(x)
1366  t=(x/3.75_sp)*(x/3.75_sp)
1367  i1sp=(a1+(a2+(a3+(a4+(a5+(a6+7*t)*t)*t)*t)*t)*t)*x
1368 
1369  RETURN
1370 
1371  END FUNCTION i1sp
1372 
1373  !
1374  !================================================================================================================================
1375  !
1376 
1378  SUBROUTINE identitymatrixsp(A,err,error,*)
1380  !Argument variables
1381  REAL(SP), INTENT(OUT) :: A(:,:)
1382  INTEGER(INTG), INTENT(OUT) :: err
1383  TYPE(varying_string), INTENT(OUT) :: error
1384  !Local variables
1385  INTEGER(INTG) :: i
1386 
1387  enters("IdentityMatrixSP",err,error,*999)
1388 
1389  IF(SIZE(a,1)==SIZE(a,2)) THEN
1390  SELECT CASE(SIZE(a,1))
1391  CASE(1)
1392  a(1,1)=1.0_sp
1393  CASE(2)
1394  a(1,1)=1.0_sp
1395  a(2,1)=0.0_sp
1396  a(1,2)=0.0_sp
1397  a(2,2)=1.0_sp
1398  CASE(3)
1399  a(1,1)=1.0_sp
1400  a(2,1)=0.0_sp
1401  a(3,1)=0.0_sp
1402  a(1,2)=0.0_sp
1403  a(2,2)=1.0_sp
1404  a(3,2)=0.0_sp
1405  a(1,3)=0.0_sp
1406  a(2,3)=0.0_sp
1407  a(3,3)=1.0_sp
1408  CASE DEFAULT
1409  a=0.0_dp
1410  DO i=1,SIZE(a,1)
1411  a(i,i)=1.0_sp
1412  ENDDO !i
1413  END SELECT
1414  ELSE
1415  CALL flagerror("Matrix A is not square.",err,error,*999)
1416  ENDIF
1417 
1418  exits("IdentityMatrixSP")
1419  RETURN
1420 999 errorsexits("IdentityMatrixSP",err,error)
1421  RETURN 1
1422 
1423  END SUBROUTINE identitymatrixsp
1424 
1425  !
1426  !================================================================================================================================
1427  !
1428 
1430  SUBROUTINE identitymatrixdp(A,err,error,*)
1432  !Argument variables
1433  REAL(DP), INTENT(OUT) :: A(:,:)
1434  INTEGER(INTG), INTENT(OUT) :: err
1435  TYPE(varying_string), INTENT(OUT) :: error
1436  !Local variables
1437  INTEGER(INTG) :: i
1438 
1439  enters("IdentityMatrixDP",err,error,*999)
1440 
1441  IF(SIZE(a,1)==SIZE(a,2)) THEN
1442  SELECT CASE(SIZE(a,1))
1443  CASE(1)
1444  a(1,1)=1.0_dp
1445  CASE(2)
1446  a(1,1)=1.0_dp
1447  a(2,1)=0.0_dp
1448  a(1,2)=0.0_dp
1449  a(2,2)=1.0_dp
1450  CASE(3)
1451  a(1,1)=1.0_dp
1452  a(2,1)=0.0_dp
1453  a(3,1)=0.0_dp
1454  a(1,2)=0.0_dp
1455  a(2,2)=1.0_dp
1456  a(3,2)=0.0_dp
1457  a(1,3)=0.0_dp
1458  a(2,3)=0.0_dp
1459  a(3,3)=1.0_dp
1460  CASE DEFAULT
1461  a=0.0_dp
1462  DO i=1,SIZE(a,1)
1463  a(i,i)=1.0_dp
1464  ENDDO !i
1465  END SELECT
1466  ELSE
1467  CALL flagerror("Matrix A is not square.",err,error,*999)
1468  ENDIF
1469 
1470  exits("IdentityMatrixDP")
1471  RETURN
1472 999 errorsexits("IdentityMatrixDP",err,error)
1473  RETURN 1
1474 
1475  END SUBROUTINE identitymatrixdp
1476 
1477  !
1478  !================================================================================================================================
1479  !
1480 
1482  SUBROUTINE invertfullsp(A,B,det,err,error,*)
1484  !Argument variables
1485  REAL(SP), INTENT(IN) :: A(:,:)
1486  REAL(SP), INTENT(OUT) :: B(:,:)
1487  REAL(SP), INTENT(OUT) :: det
1488  INTEGER(INTG), INTENT(OUT) :: err
1489  TYPE(varying_string), INTENT(OUT) :: error
1490  !Local variables
1491 
1492  enters("InvertFullSP",err,error,*999)
1493 
1494  IF(SIZE(a,1)==SIZE(a,2)) THEN
1495  IF(SIZE(b,1)==SIZE(a,1).AND.SIZE(b,2)==SIZE(a,2)) THEN
1496  SELECT CASE(SIZE(a,1))
1497  CASE(1)
1498  det=a(1,1)
1499  IF(abs(det)>zero_tolerance_sp) THEN
1500  b(1,1)=1.0_sp/a(1,1)
1501  ELSE
1502  CALL flagwarning("Matrix A is zero and cannot be inverted.",err,error,*999)
1503  b(1,1)=0.0_dp
1504  ENDIF
1505  CASE(2)
1506  det=a(1,1)*a(2,2)-a(1,2)*a(2,1)
1507  IF(abs(det)>zero_tolerance_sp) THEN
1508  b(1,1)=a(2,2)/det
1509  b(1,2)=-a(1,2)/det
1510  b(2,1)=-a(2,1)/det
1511  b(2,2)=a(1,1)/det
1512  ELSE
1513  CALL flagwarning("Zero Determinant for matrix A.",err,error,*999)
1514  b=0.0_dp
1515  ENDIF
1516  CASE(3)
1517  det=a(1,1)*a(2,2)*a(3,3)+a(1,2)*a(2,3)*a(3,1)+a(1,3)*a(2,1)*a(3,2)-a(1,1)*a(3,2)*a(2,3)-a(2,1)*a(1,2)*a(3,3)- &
1518  & a(3,1)*a(2,2)*a(1,3)
1519  IF(abs(det)>zero_tolerance_sp) THEN
1520  b(1,1)=(a(2,2)*a(3,3)-a(3,2)*a(2,3))/det
1521  b(2,1)=(a(2,3)*a(3,1)-a(3,3)*a(2,1))/det
1522  b(3,1)=(a(2,1)*a(3,2)-a(3,1)*a(2,2))/det
1523  b(1,2)=(a(3,2)*a(1,3)-a(1,2)*a(3,3))/det
1524  b(2,2)=(a(3,3)*a(1,1)-a(1,3)*a(3,1))/det
1525  b(3,2)=(a(3,1)*a(1,2)-a(1,1)*a(3,2))/det
1526  b(1,3)=(a(1,2)*a(2,3)-a(2,2)*a(1,3))/det
1527  b(2,3)=(a(1,3)*a(2,1)-a(2,3)*a(1,1))/det
1528  b(3,3)=(a(1,1)*a(2,2)-a(2,1)*a(1,2))/det
1529  ELSE
1530  CALL flagwarning("Zero Determinant for matrix A.",err,error,*999)
1531  b=0.0_dp
1532  ENDIF
1533  CASE DEFAULT
1534  CALL flagerror("Matrix size is not implemented.",err,error,*999)
1535  END SELECT
1536  ELSE
1537  CALL flagerror("Matrix B is not the same size as matrix A.",err,error,*999)
1538  ENDIF
1539  ELSE
1540  CALL flagerror("Matrix A is not square.",err,error,*999)
1541  ENDIF
1542 
1543  exits("InvertFullSP")
1544  RETURN
1545 999 errorsexits("InvertFullSP",err,error)
1546  RETURN 1
1547 
1548  END SUBROUTINE invertfullsp
1549 
1550  !
1551  !================================================================================================================================
1552  !
1553 
1555  SUBROUTINE invertfulldp(A,B,det,err,error,*)
1557  !Argument variables
1558  REAL(DP), INTENT(IN) :: A(:,:)
1559  REAL(DP), INTENT(OUT) :: B(:,:)
1560  REAL(DP), INTENT(OUT) :: det
1561  INTEGER(INTG), INTENT(OUT) :: err
1562  TYPE(varying_string), INTENT(OUT) :: error
1563  !Local variables
1564 
1565  enters("InvertFullDP",err,error,*999)
1566 
1567  IF(SIZE(a,1)==SIZE(a,2)) THEN
1568  IF(SIZE(b,1)==SIZE(a,1).AND.SIZE(b,2)==SIZE(a,2)) THEN
1569  SELECT CASE(SIZE(a,1))
1570  CASE(1)
1571  det=a(1,1)
1572  IF(abs(det)>zero_tolerance_dp) THEN
1573  b(1,1)=1.0_dp/a(1,1)
1574  ELSE
1575  CALL flagwarning("Matrix A is zero and cannot be inverted",err,error,*999)
1576  b(1,1)=0.0_dp
1577  ENDIF
1578  CASE(2)
1579  det=a(1,1)*a(2,2)-a(2,1)*a(1,2)
1580  IF(abs(det)>zero_tolerance_dp) THEN
1581  b(1,1)=a(2,2)/det
1582  b(1,2)=-a(1,2)/det
1583  b(2,1)=-a(2,1)/det
1584  b(2,2)=a(1,1)/det
1585  ELSE
1586  CALL flagwarning("Zero Determinant for matrix A.",err,error,*999)
1587  b=0.0_dp
1588  ENDIF
1589  CASE(3)
1590  det=a(1,1)*a(2,2)*a(3,3)+a(1,2)*a(2,3)*a(3,1)+a(1,3)*a(2,1)*a(3,2)-a(1,1)*a(3,2)*a(2,3)-a(2,1)*a(1,2)*a(3,3)- &
1591  & a(3,1)*a(2,2)*a(1,3)
1592  IF(abs(det)>zero_tolerance_dp) THEN
1593  b(1,1)=(a(2,2)*a(3,3)-a(3,2)*a(2,3))/det
1594  b(2,1)=(a(2,3)*a(3,1)-a(3,3)*a(2,1))/det
1595  b(3,1)=(a(2,1)*a(3,2)-a(3,1)*a(2,2))/det
1596  b(1,2)=(a(3,2)*a(1,3)-a(1,2)*a(3,3))/det
1597  b(2,2)=(a(3,3)*a(1,1)-a(1,3)*a(3,1))/det
1598  b(3,2)=(a(3,1)*a(1,2)-a(1,1)*a(3,2))/det
1599  b(1,3)=(a(1,2)*a(2,3)-a(2,2)*a(1,3))/det
1600  b(2,3)=(a(1,3)*a(2,1)-a(2,3)*a(1,1))/det
1601  b(3,3)=(a(1,1)*a(2,2)-a(2,1)*a(1,2))/det
1602  ELSE
1603  CALL flagwarning("Zero Determinant for matrix A.",err,error,*999)
1604  b=0.0_dp
1605  ENDIF
1606  CASE DEFAULT
1607  CALL flagerror("Matrix size is not implemented.",err,error,*999)
1608  END SELECT
1609  ELSE
1610  CALL flagerror("Matrix B is not the same size as matrix A.",err,error,*999)
1611  ENDIF
1612  ELSE
1613  CALL flagerror("Matrix A is not square.",err,error,*999)
1614  ENDIF
1615 
1616  exits("InvertFullDP")
1617  RETURN
1618 999 errorsexits("InvertFullDP",err,error)
1619  RETURN 1
1620 
1621  END SUBROUTINE invertfulldp
1622 
1623  !
1624  !================================================================================================================================
1625  !
1626 
1629  PURE FUNCTION k0dp(x)
1631  !Argument variables
1632  REAL(DP), INTENT(IN) :: x
1633  !Function variable
1634  REAL(DP) :: K0DP
1635  !Local variables
1636  REAL(DP) :: a1,a2,a3,a4,a5,a6,a7,t
1637 
1638  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
1639  !Calculate K0(x)
1640  IF(x<=2.0_dp) THEN
1641  t=x*x/4.0_dp
1642  a1=-0.57721566_dp
1643  a2=0.42278420_dp
1644  a3=0.23069756_dp
1645  a4=0.03488590_dp
1646  a5=0.00262698_dp
1647  a6=0.00010750_dp
1648  a7=0.00000740_dp
1649  k0dp=-log(x/2.0_dp)*i0(x)+(a1+(a2+(a3+(a4+(a5+(a6+a7*t)*t)*t)*t)*t)*t)
1650  ELSE
1651  IF(x>174.0_dp) THEN
1652  k0dp=0.0_dp
1653  ELSE
1654  t=2.0_dp/x
1655  a1=1.25331414_dp
1656  a2=-0.07832358_dp
1657  a3=0.02189568_dp
1658  a4=-0.01062446_dp
1659  a5=0.00587872_dp
1660  a6=-0.00251540_dp
1661  a7=0.00053208_dp
1662  k0dp=(a1+(a2+(a3+(a4+(a5+(a6+a7*t)*t)*t)*t)*t)*t)*exp(-x)/sqrt(x)
1663  ENDIF
1664  ENDIF
1665 
1666  RETURN
1667 
1668  END FUNCTION k0dp
1669 
1670  !
1671  !================================================================================================================================
1672  !
1673 
1676  PURE FUNCTION k0sp(x)
1678  !Argument variables
1679  REAL(SP), INTENT(IN) :: x
1680  !Function variable
1681  REAL(SP) :: K0SP
1682  !Local variables
1683  REAL(SP) :: a1,a2,a3,a4,a5,a6,a7,t
1684 
1685  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
1686  !Calculate K0(x)
1687  IF(x<=2.0_sp) THEN
1688  t=x*x/4.0_sp
1689  a1=-0.57721566_sp
1690  a2=0.42278420_sp
1691  a3=0.23069756_sp
1692  a4=0.03488590_sp
1693  a5=0.00262698_sp
1694  a6=0.00010750_sp
1695  a7=0.00000740_sp
1696  k0sp=-log(x/2.0_sp)*i0(x)+(a1+(a2+(a3+(a4+(a5+(a6+a7*t)*t)*t)*t)*t)*t)
1697  ELSE
1698  IF(x>174.0_sp) THEN
1699  k0sp=0.0_sp
1700  ELSE
1701  t=2.0_sp/x
1702  a1=1.25331414_sp
1703  a2=-0.07832358_sp
1704  a3=0.02189568_sp
1705  a4=-0.01062446_sp
1706  a5=0.00587872_sp
1707  a6=-0.00251540_sp
1708  a7=0.00053208_sp
1709  k0sp=(a1+(a2+(a3+(a4+(a5+(a6+a7*t)*t)*t)*t)*t)*t)*exp(-x)/sqrt(x)
1710  ENDIF
1711  ENDIF
1712 
1713  RETURN
1714 
1715  END FUNCTION k0sp
1716 
1717  !
1718  !================================================================================================================================
1719  !
1720 
1723  PURE FUNCTION k1dp(x)
1725  !Argument variables
1726  REAL(DP), INTENT(IN) :: x
1727  !Function variable
1728  REAL(DP) :: K1DP
1729  !Local variables
1730  REAL(DP) :: a1,a2,a3,a4,a5,a6,a7,a8,t
1731 
1732  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
1733  !Calculate K1(x)
1734  IF(x<=2.0_dp) THEN
1735  t=(x/2.0_dp)*(x/2.0_dp)
1736  a1=log(x/2.0_dp)*i1(x)
1737  a2=1.0_dp
1738  a3=0.15443144_dp
1739  a4=-0.67278579_dp
1740  a5=-0.18156897_dp
1741  a6=-0.01919402_dp
1742  a7=-0.00110404_dp
1743  a8=-0.00004686_dp
1744  k1dp=a1+a2/x+(a3+(a4+(a5+(a6+(a7+a8*t)*t)*t)*t)*t)*x/4.0_dp
1745  ELSE
1746  IF (x>174.0_dp) THEN
1747  k1dp=0.0_dp
1748  ELSE
1749  t=2.0_dp/x
1750  a1=1.25331414_dp
1751  a2=0.23498619_dp
1752  a3=-0.03655620_dp
1753  a4=0.01504268_dp
1754  a5=-0.00780355_dp
1755  a6=0.00325614_dp
1756  a7=-0.00068245_dp
1757  k1dp=(a1+(a2+(a3+(a4+(a5+(a6+a7*t)*t)*t)*t)*t)*t)*exp(-x)/sqrt(x)
1758  ENDIF
1759  ENDIF
1760 
1761  RETURN
1762 
1763  END FUNCTION k1dp
1764 
1765  !
1766  !================================================================================================================================
1767  !
1768 
1771  PURE FUNCTION k1sp(x)
1773  !Argument variables
1774  REAL(SP), INTENT(IN) :: x
1775  !Function variable
1776  REAL(SP) :: K1SP
1777  !Local variables
1778  REAL(SP) :: a1,a2,a3,a4,a5,a6,a7,a8,t
1779 
1780  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
1781  !Calculate K1(x)
1782  IF(x<=2.0_sp) THEN
1783  t=(x/2.0_sp)*(x/2.0_sp)
1784  a1=log(x/2.0_sp)*i1(x)
1785  a2=1.0_sp
1786  a3=0.15443144_sp
1787  a4=-0.67278579_sp
1788  a5=-0.18156897_sp
1789  a6=-0.01919402_sp
1790  a7=-0.00110404_sp
1791  a8=-0.00004686_sp
1792  k1sp=a1+a2/x+(a3+(a4+(a5+(a6+(a7+a8*t)*t)*t)*t)*t)*x/4.0_sp
1793  ELSE
1794  IF (x>174.0_sp) THEN
1795  k1sp=0.0_sp
1796  ELSE
1797  t=2.0_sp/x
1798  a1=1.25331414_sp
1799  a2=0.23498619_sp
1800  a3=-0.03655620_sp
1801  a4=0.01504268_sp
1802  a5=-0.00780355_sp
1803  a6=0.00325614_sp
1804  a7=-0.00068245_sp
1805  k1sp=(a1+(a2+(a3+(a4+(a5+(a6+a7*t)*t)*t)*t)*t)*t)*exp(-x)/sqrt(x)
1806  ENDIF
1807  ENDIF
1808 
1809  RETURN
1810 
1811  END FUNCTION k1sp
1812 
1813  !
1814  !================================================================================================================================
1815  !
1816 
1818  PURE FUNCTION kdpdp(x)
1820  !Argument variables
1821  REAL(DP), INTENT(IN) :: x
1822  !Function variable
1823  REAL(DP) :: KdpDP
1824  !Local variables
1825  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
1826  REAL(DP), PARAMETER :: a0=1.38629436112_dp
1827  REAL(DP), PARAMETER :: a1=0.09666344259_dp
1828  REAL(DP), PARAMETER :: a2=0.03590092383_dp
1829  REAL(DP), PARAMETER :: a3=0.03742563713_dp
1830  REAL(DP), PARAMETER :: a4=0.01451196212_dp
1831  REAL(DP), PARAMETER :: b0=0.5_dp
1832  REAL(DP), PARAMETER :: b1=0.12498593597_dp
1833  REAL(DP), PARAMETER :: b2=0.06880248576_dp
1834  REAL(DP), PARAMETER :: b3=0.03328355346_dp
1835  REAL(DP), PARAMETER :: b4=0.00441787012_dp
1836  REAL(DP) :: term1,term2,x1
1837 
1838  x1=1.0_dp-x
1839  term1=a0+(a1+(a2+(a3+a4*x)*x)*x)*x
1840  term2=b0+(b1+(b2+(b3+b4*x)*x)*x)*x
1841  kdpdp=term1+term2*log(1.0_dp/x)
1842 
1843  RETURN
1844 
1845  END FUNCTION kdpdp
1846 
1847  !
1848  !================================================================================================================================
1849  !
1850 
1852  PURE FUNCTION kdpsp(x)
1854  !Argument variables
1855  REAL(SP), INTENT(IN) :: x
1856  !Function variable
1857  REAL(SP) :: KdpSP
1858  !Local variables
1859  !!TODO:: CHECK PRECISION ON THESE CONSTANTS
1860  REAL(SP), PARAMETER :: a0=1.38629436112_sp
1861  REAL(SP), PARAMETER :: a1=0.09666344259_sp
1862  REAL(SP), PARAMETER :: a2=0.03590092383_sp
1863  REAL(SP), PARAMETER :: a3=0.03742563713_sp
1864  REAL(SP), PARAMETER :: a4=0.01451196212_sp
1865  REAL(SP), PARAMETER :: b0=0.5_sp
1866  REAL(SP), PARAMETER :: b1=0.12498593597_sp
1867  REAL(SP), PARAMETER :: b2=0.06880248576_sp
1868  REAL(SP), PARAMETER :: b3=0.03328355346_sp
1869  REAL(SP), PARAMETER :: b4=0.00441787012_sp
1870  REAL(SP) :: term1,term2,x1
1871 
1872  x1=1.0_sp-x
1873  term1=a0+(a1+(a2+(a3+a4*x)*x)*x)*x
1874  term2=b0+(b1+(b2+(b3+b4*x)*x)*x)*x
1875  kdpsp=term1+term2*log(1.0_sp/x)
1876 
1877  RETURN
1878 
1879  END FUNCTION kdpsp
1880 
1881  !
1882  !================================================================================================================================
1883  !
1884 
1886  PURE FUNCTION l2normsp(a)
1888  !Argument variables
1889  REAL(SP), INTENT(IN) :: a(:)
1890  !Function variable
1891  REAL(SP) :: L2NormSP
1892  !Local variables
1893  REAL(SP) :: asum
1894 
1895  asum=sum(a*a,1)
1896  l2normsp=sqrt(asum)
1897 
1898  RETURN
1899 
1900  END FUNCTION l2normsp
1901 
1902  !
1903  !================================================================================================================================
1904  !
1905 
1907  FUNCTION l2normdp(A)
1909  !Argument variables
1910  REAL(DP), INTENT(IN) :: a(:)
1911  !Function variable
1912  REAL(DP) :: L2NormDP
1913  !Local variables
1914  REAL(DP) :: asum
1915 
1916  asum=sum(a*a,1)
1917  l2normdp=sqrt(asum)
1918 
1919  RETURN
1920 
1921  END FUNCTION l2normdp
1922 
1923  !
1924  !================================================================================================================================
1925  !
1926 
1928  SUBROUTINE matrixproductsp(A,B,C,err,error,*)
1930  !Argument variables
1931  REAL(SP), INTENT(IN) :: A(:,:)
1932  REAL(SP), INTENT(IN) :: B(:,:)
1933  REAL(SP), INTENT(OUT) :: C(:,:)
1934  INTEGER(INTG), INTENT(OUT) :: err
1935  TYPE(varying_string), INTENT(OUT) :: error
1936  !Local variables
1937 
1938  enters("MatrixProductSP",err,error,*999)
1939 
1940  IF(SIZE(a,2)==SIZE(b,1).AND.SIZE(a,1)==SIZE(c,1).AND.SIZE(b,2)==SIZE(c,2)) THEN
1941  SELECT CASE(SIZE(a,1))
1942  CASE(1)
1943  c(1,1)=a(1,1)*b(1,1)
1944  CASE(2)
1945  c(1,1)=a(1,1)*b(1,1)+a(1,2)*b(2,1)
1946  c(1,2)=a(1,1)*b(1,2)+a(1,2)*b(2,2)
1947  c(2,1)=a(2,1)*b(1,1)+a(2,2)*b(2,1)
1948  c(2,2)=a(2,1)*b(1,2)+a(2,2)*b(2,2)
1949  CASE(3)
1950  c(1,1)=a(1,1)*b(1,1)+a(1,2)*b(2,1)+a(1,3)*b(3,1)
1951  c(1,2)=a(1,1)*b(1,2)+a(1,2)*b(2,2)+a(1,3)*b(3,2)
1952  c(1,3)=a(1,1)*b(1,3)+a(1,2)*b(2,3)+a(1,3)*b(3,3)
1953  c(2,1)=a(2,1)*b(1,1)+a(2,2)*b(2,1)+a(2,3)*b(3,1)
1954  c(2,2)=a(2,1)*b(1,2)+a(2,2)*b(2,2)+a(2,3)*b(3,2)
1955  c(2,3)=a(2,1)*b(1,3)+a(2,2)*b(2,3)+a(2,3)*b(3,3)
1956  c(3,1)=a(3,1)*b(1,1)+a(3,2)*b(2,1)+a(3,3)*b(3,1)
1957  c(3,2)=a(3,1)*b(1,2)+a(3,2)*b(2,2)+a(3,3)*b(3,2)
1958  c(3,3)=a(3,1)*b(1,3)+a(3,2)*b(2,3)+a(3,3)*b(3,3)
1959  CASE DEFAULT
1960  CALL flagerror("Invalid matrix size.",err,error,*999)
1961  END SELECT
1962  ELSE
1963  CALL flagerror("Invalid matrix sizes.",err,error,*999)
1964  ENDIF
1965 
1966  exits("MatrixProductSP")
1967  RETURN
1968 999 errorsexits("MatrixProductSP",err,error)
1969  RETURN 1
1970 
1971  END SUBROUTINE matrixproductsp
1972 
1973  !
1974  !================================================================================================================================
1975  !
1976 
1978  SUBROUTINE matrixproductdp(A,B,C,err,error,*)
1980  !Argument variables
1981  REAL(DP), INTENT(IN) :: A(:,:)
1982  REAL(DP), INTENT(IN) :: B(:,:)
1983  REAL(DP), INTENT(OUT) :: C(:,:)
1984  INTEGER(INTG), INTENT(OUT) :: err
1985  TYPE(varying_string), INTENT(OUT) :: error
1986  !Local variables
1987 
1988  enters("MatrixProductDP",err,error,*999)
1989 
1990  IF(SIZE(a,2)==SIZE(b,1).AND.SIZE(a,1)==SIZE(c,1).AND.SIZE(b,2)==SIZE(c,2)) THEN
1991  SELECT CASE(SIZE(a,1))
1992  CASE(1)
1993  c(1,1)=a(1,1)*b(1,1)
1994  CASE(2)
1995  c(1,1)=a(1,1)*b(1,1)+a(1,2)*b(2,1)
1996  c(1,2)=a(1,1)*b(1,2)+a(1,2)*b(2,2)
1997  c(2,1)=a(2,1)*b(1,1)+a(2,2)*b(2,1)
1998  c(2,2)=a(2,1)*b(1,2)+a(2,2)*b(2,2)
1999  CASE(3)
2000  c(1,1)=a(1,1)*b(1,1)+a(1,2)*b(2,1)+a(1,3)*b(3,1)
2001  c(1,2)=a(1,1)*b(1,2)+a(1,2)*b(2,2)+a(1,3)*b(3,2)
2002  c(1,3)=a(1,1)*b(1,3)+a(1,2)*b(2,3)+a(1,3)*b(3,3)
2003  c(2,1)=a(2,1)*b(1,1)+a(2,2)*b(2,1)+a(2,3)*b(3,1)
2004  c(2,2)=a(2,1)*b(1,2)+a(2,2)*b(2,2)+a(2,3)*b(3,2)
2005  c(2,3)=a(2,1)*b(1,3)+a(2,2)*b(2,3)+a(2,3)*b(3,3)
2006  c(3,1)=a(3,1)*b(1,1)+a(3,2)*b(2,1)+a(3,3)*b(3,1)
2007  c(3,2)=a(3,1)*b(1,2)+a(3,2)*b(2,2)+a(3,3)*b(3,2)
2008  c(3,3)=a(3,1)*b(1,3)+a(3,2)*b(2,3)+a(3,3)*b(3,3)
2009  CASE DEFAULT
2010  CALL flagerror("Invalid matrix size.",err,error,*999)
2011  END SELECT
2012  ELSE
2013  CALL flagerror("Invalid matrix sizes.",err,error,*999)
2014  ENDIF
2015 
2016  exits("MatrixProductDP")
2017  RETURN
2018 999 errorsexits("MatrixProductDP",err,error)
2019  RETURN 1
2020 
2021  END SUBROUTINE matrixproductdp
2022 
2023  !
2024  !================================================================================================================================
2025  !
2026 
2028  SUBROUTINE matrixtransposeproductsp(A,B,C,err,error,*)
2030  !Argument variables
2031  REAL(SP), INTENT(IN) :: A(:,:)
2032  REAL(SP), INTENT(IN) :: B(:,:)
2033  REAL(SP), INTENT(OUT) :: C(:,:)
2034  INTEGER(INTG), INTENT(OUT) :: err
2035  TYPE(varying_string), INTENT(OUT) :: error
2036  !Local variables
2037 
2038  enters("MatrixTransposeProductSP",err,error,*999)
2039 
2040  IF(SIZE(a,2)==SIZE(b,1).AND.SIZE(a,1)==SIZE(c,1).AND.SIZE(b,2)==SIZE(c,2)) THEN
2041  SELECT CASE(SIZE(a,1))
2042  CASE(1)
2043  c(1,1)=a(1,1)*b(1,1)
2044  CASE(2)
2045  c(1,1)=a(1,1)*b(1,1)+a(2,1)*b(2,1)
2046  c(1,2)=a(1,1)*b(1,2)+a(2,1)*b(2,2)
2047  c(2,1)=a(1,2)*b(1,1)+a(2,2)*b(2,1)
2048  c(2,2)=a(1,2)*b(1,2)+a(2,2)*b(2,2)
2049  CASE(3)
2050  c(1,1)=a(1,1)*b(1,1)+a(2,1)*b(2,1)+a(3,1)*b(3,1)
2051  c(1,2)=a(1,1)*b(1,2)+a(2,1)*b(2,2)+a(3,1)*b(3,2)
2052  c(1,3)=a(1,1)*b(1,3)+a(2,1)*b(2,3)+a(3,1)*b(3,3)
2053  c(2,1)=a(1,2)*b(1,1)+a(2,2)*b(2,1)+a(3,2)*b(3,1)
2054  c(2,2)=a(1,2)*b(1,2)+a(2,2)*b(2,2)+a(3,2)*b(3,2)
2055  c(2,3)=a(1,2)*b(1,3)+a(2,2)*b(2,3)+a(3,2)*b(3,3)
2056  c(3,1)=a(1,3)*b(1,1)+a(2,3)*b(2,1)+a(3,3)*b(3,1)
2057  c(3,2)=a(1,3)*b(1,2)+a(2,3)*b(2,2)+a(3,3)*b(3,2)
2058  c(3,3)=a(1,3)*b(1,3)+a(2,3)*b(2,3)+a(3,3)*b(3,3)
2059  CASE DEFAULT
2060  CALL flagerror("Invalid matrix size.",err,error,*999)
2061  END SELECT
2062  ELSE
2063  CALL flagerror("Invalid matrix sizes.",err,error,*999)
2064  ENDIF
2065 
2066  exits("MatrixTransposeProductSP")
2067  RETURN
2068 999 errorsexits("MatrixTransposeProductSP",err,error)
2069  RETURN 1
2070 
2071  END SUBROUTINE matrixtransposeproductsp
2072 
2073  !
2074  !================================================================================================================================
2075  !
2076 
2078  SUBROUTINE matrixtransposeproductdp(A,B,C,err,error,*)
2080  !Argument variables
2081  REAL(DP), INTENT(IN) :: A(:,:)
2082  REAL(DP), INTENT(IN) :: B(:,:)
2083  REAL(DP), INTENT(OUT) :: C(:,:)
2084  INTEGER(INTG), INTENT(OUT) :: err
2085  TYPE(varying_string), INTENT(OUT) :: error
2086  !Local variables
2087 
2088  enters("MatrixTransposeProductDP",err,error,*999)
2089 
2090  IF(SIZE(a,2)==SIZE(b,1).AND.SIZE(a,1)==SIZE(c,1).AND.SIZE(b,2)==SIZE(c,2)) THEN
2091  SELECT CASE(SIZE(a,1))
2092  CASE(1)
2093  c(1,1)=a(1,1)*b(1,1)
2094  CASE(2)
2095  c(1,1)=a(1,1)*b(1,1)+a(2,1)*b(2,1)
2096  c(1,2)=a(1,1)*b(1,2)+a(2,1)*b(2,2)
2097  c(2,1)=a(1,2)*b(1,1)+a(2,2)*b(2,1)
2098  c(2,2)=a(1,2)*b(1,2)+a(2,2)*b(2,2)
2099  CASE(3)
2100  c(1,1)=a(1,1)*b(1,1)+a(2,1)*b(2,1)+a(3,1)*b(3,1)
2101  c(1,2)=a(1,1)*b(1,2)+a(2,1)*b(2,2)+a(3,1)*b(3,2)
2102  c(1,3)=a(1,1)*b(1,3)+a(2,1)*b(2,3)+a(3,1)*b(3,3)
2103  c(2,1)=a(1,2)*b(1,1)+a(2,2)*b(2,1)+a(3,2)*b(3,1)
2104  c(2,2)=a(1,2)*b(1,2)+a(2,2)*b(2,2)+a(3,2)*b(3,2)
2105  c(2,3)=a(1,2)*b(1,3)+a(2,2)*b(2,3)+a(3,2)*b(3,3)
2106  c(3,1)=a(1,3)*b(1,1)+a(2,3)*b(2,1)+a(3,3)*b(3,1)
2107  c(3,2)=a(1,3)*b(1,2)+a(2,3)*b(2,2)+a(3,3)*b(3,2)
2108  c(3,3)=a(1,3)*b(1,3)+a(2,3)*b(2,3)+a(3,3)*b(3,3)
2109  CASE DEFAULT
2110  CALL flagerror("Invalid matrix size.",err,error,*999)
2111  END SELECT
2112  ELSE
2113  CALL flagerror("Invalid matrix sizes.",err,error,*999)
2114  ENDIF
2115 
2116  exits("MatrixTransposeProductDP")
2117  RETURN
2118 999 errorsexits("MatrixTransposeProductDP",err,error)
2119  RETURN 1
2120 
2121  END SUBROUTINE matrixtransposeproductdp
2122 
2123  !
2124  !================================================================================================================================
2125  !
2127  SUBROUTINE matrixproducttransposesp(A,B,C,err,error,*)
2129  !Argument variables
2130  REAL(SP), INTENT(IN) :: A(:,:)
2131  REAL(SP), INTENT(IN) :: B(:,:)
2132  REAL(SP), INTENT(OUT) :: C(:,:)
2133  INTEGER(INTG), INTENT(OUT) :: err
2134  TYPE(varying_string), INTENT(OUT) :: error
2135  !Local variables
2136 
2137  enters("MatrixProductTransposeSP",err,error,*999)
2138 
2139  IF(SIZE(a,2)==SIZE(b,2).AND.SIZE(a,1)==SIZE(c,1).AND.SIZE(b,1)==SIZE(c,2)) THEN
2140  SELECT CASE(SIZE(a,1))
2141  CASE(1)
2142  c(1,1)=a(1,1)*b(1,1)
2143  CASE(2)
2144  c(1,1)=a(1,1)*b(1,1)+a(1,2)*b(1,2)
2145  c(1,2)=a(1,1)*b(2,1)+a(1,2)*b(2,2)
2146  c(2,1)=a(2,1)*b(1,1)+a(2,2)*b(1,2)
2147  c(2,2)=a(2,1)*b(2,1)+a(2,2)*b(2,2)
2148  CASE(3)
2149  c(1,1)=a(1,1)*b(1,1)+a(1,2)*b(1,2)+a(1,3)*b(1,3)
2150  c(1,2)=a(1,1)*b(2,1)+a(1,2)*b(2,2)+a(1,3)*b(2,3)
2151  c(1,3)=a(1,1)*b(3,1)+a(1,2)*b(3,2)+a(1,3)*b(3,3)
2152  c(2,1)=a(2,1)*b(1,1)+a(2,2)*b(1,2)+a(2,3)*b(1,3)
2153  c(2,2)=a(2,1)*b(2,1)+a(2,2)*b(2,2)+a(2,3)*b(2,3)
2154  c(2,3)=a(2,1)*b(3,1)+a(2,2)*b(3,2)+a(2,3)*b(3,3)
2155  c(3,1)=a(3,1)*b(1,1)+a(3,2)*b(1,2)+a(3,3)*b(1,3)
2156  c(3,2)=a(3,1)*b(2,1)+a(3,2)*b(2,2)+a(3,3)*b(2,3)
2157  c(3,3)=a(3,1)*b(3,1)+a(3,2)*b(3,2)+a(3,3)*b(3,3)
2158  CASE DEFAULT
2159  CALL flagerror("Invalid matrix size.",err,error,*999)
2160  END SELECT
2161  ELSE
2162  CALL flagerror("Invalid matrix sizes.",err,error,*999)
2163  ENDIF
2164 
2165  exits("MatrixProductTransposeSP")
2166  RETURN
2167 999 errorsexits("MatrixProductTransposeSP",err,error)
2168  RETURN 1
2169 
2170  END SUBROUTINE matrixproducttransposesp
2171 
2172  !
2173  !================================================================================================================================
2174  !
2175 
2177  SUBROUTINE matrixproducttransposedp(A,B,C,err,error,*)
2179  !Argument variables
2180  REAL(DP), INTENT(IN) :: A(:,:)
2181  REAL(DP), INTENT(IN) :: B(:,:)
2182  REAL(DP), INTENT(OUT) :: C(:,:)
2183  INTEGER(INTG), INTENT(OUT) :: err
2184  TYPE(varying_string), INTENT(OUT) :: error
2185  !Local variables
2186 
2187  enters("MatrixProductTranposeDP",err,error,*999)
2188 
2189  IF(SIZE(a,2)==SIZE(b,2).AND.SIZE(a,1)==SIZE(c,1).AND.SIZE(b,1)==SIZE(c,2)) THEN
2190  SELECT CASE(SIZE(a,1))
2191  CASE(1)
2192  c(1,1)=a(1,1)*b(1,1)
2193  CASE(2)
2194  c(1,1)=a(1,1)*b(1,1)+a(1,2)*b(1,2)
2195  c(1,2)=a(1,1)*b(2,1)+a(1,2)*b(2,2)
2196  c(2,1)=a(2,1)*b(1,1)+a(2,2)*b(1,2)
2197  c(2,2)=a(2,1)*b(2,1)+a(2,2)*b(2,2)
2198  CASE(3)
2199  c(1,1)=a(1,1)*b(1,1)+a(1,2)*b(1,2)+a(1,3)*b(1,3)
2200  c(1,2)=a(1,1)*b(2,1)+a(1,2)*b(2,2)+a(1,3)*b(2,3)
2201  c(1,3)=a(1,1)*b(3,1)+a(1,2)*b(3,2)+a(1,3)*b(3,3)
2202  c(2,1)=a(2,1)*b(1,1)+a(2,2)*b(1,2)+a(2,3)*b(1,3)
2203  c(2,2)=a(2,1)*b(2,1)+a(2,2)*b(2,2)+a(2,3)*b(2,3)
2204  c(2,3)=a(2,1)*b(3,1)+a(2,2)*b(3,2)+a(2,3)*b(3,3)
2205  c(3,1)=a(3,1)*b(1,1)+a(3,2)*b(1,2)+a(3,3)*b(1,3)
2206  c(3,2)=a(3,1)*b(2,1)+a(3,2)*b(2,2)+a(3,3)*b(2,3)
2207  c(3,3)=a(3,1)*b(3,1)+a(3,2)*b(3,2)+a(3,3)*b(3,3)
2208  CASE DEFAULT
2209  CALL flagerror("Invalid matrix size.",err,error,*999)
2210  END SELECT
2211  ELSE
2212  CALL flagerror("Invalid matrix sizes.",err,error,*999)
2213  ENDIF
2214 
2215  exits("MatrixProductTransposeDP")
2216  RETURN
2217 999 errorsexits("MatrixProductTransposeDP",err,error)
2218  RETURN 1
2219 
2220  END SUBROUTINE matrixproducttransposedp
2221 
2222  !
2223  !================================================================================================================================
2224  !
2225 
2227  SUBROUTINE matrixtransposesp(A,AT,err,error,*)
2229  !Argument variables
2230  REAL(SP), INTENT(IN) :: A(:,:)
2231  REAL(SP), INTENT(OUT) :: AT(:,:)
2232  INTEGER(INTG), INTENT(OUT) :: err
2233  TYPE(varying_string), INTENT(OUT) :: error
2234  !Local variables
2235 
2236  enters("MatrixTransposeSP",err,error,*999)
2237 
2238  IF(SIZE(a,1)==SIZE(at,2).AND.SIZE(a,2)==SIZE(at,1)) THEN
2239  SELECT CASE(SIZE(a,1))
2240  CASE(1)
2241  at(1,1)=a(1,1)
2242  CASE(2)
2243  at(1,1)=a(1,1)
2244  at(1,2)=a(2,1)
2245  at(2,1)=a(1,2)
2246  at(2,2)=a(2,2)
2247  CASE(3)
2248  at(1,1)=a(1,1)
2249  at(1,2)=a(2,1)
2250  at(1,3)=a(3,1)
2251  at(2,1)=a(1,2)
2252  at(2,2)=a(2,2)
2253  at(2,3)=a(3,2)
2254  at(3,1)=a(1,3)
2255  at(3,2)=a(2,3)
2256  at(3,3)=a(3,3)
2257  CASE DEFAULT
2258  CALL flagerror("Invalid matrix size.",err,error,*999)
2259  END SELECT
2260  ELSE
2261  CALL flagerror("Invalid matrix size.",err,error,*999)
2262  ENDIF
2263 
2264  exits("MatrixTransposeSP")
2265  RETURN
2266 999 errorsexits("MatrixTransposeSP",err,error)
2267  RETURN 1
2268 
2269  END SUBROUTINE matrixtransposesp
2270 
2271  !
2272  !================================================================================================================================
2273  !
2274 
2276  SUBROUTINE matrixtransposedp(A,AT,err,error,*)
2278  !Argument variables
2279  REAL(DP), INTENT(IN) :: A(:,:)
2280  REAL(DP), INTENT(OUT) :: AT(:,:)
2281  INTEGER(INTG), INTENT(OUT) :: err
2282  TYPE(varying_string), INTENT(OUT) :: error
2283  !Local variables
2284 
2285  enters("MatrixTransposeDP",err,error,*999)
2286 
2287  IF(SIZE(a,1)==SIZE(at,2).AND.SIZE(a,2)==SIZE(at,1)) THEN
2288  SELECT CASE(SIZE(a,1))
2289  CASE(1)
2290  at(1,1)=a(1,1)
2291  CASE(2)
2292  at(1,1)=a(1,1)
2293  at(1,2)=a(2,1)
2294  at(2,1)=a(1,2)
2295  at(2,2)=a(2,2)
2296  CASE(3)
2297  at(1,1)=a(1,1)
2298  at(1,2)=a(2,1)
2299  at(1,3)=a(3,1)
2300  at(2,1)=a(1,2)
2301  at(2,2)=a(2,2)
2302  at(2,3)=a(3,2)
2303  at(3,1)=a(1,3)
2304  at(3,2)=a(2,3)
2305  at(3,3)=a(3,3)
2306  CASE DEFAULT
2307  CALL flagerror("Invalid matrix size.",err,error,*999)
2308  END SELECT
2309  ELSE
2310  CALL flagerror("Invalid matrix size.",err,error,*999)
2311  ENDIF
2312 
2313  exits("MatrixTransposeDP")
2314  RETURN
2315 999 errorsexits("MatrixTransposeDP",err,error)
2316  RETURN 1
2317 
2318  END SUBROUTINE matrixtransposedp
2319 
2320  !
2321  !================================================================================================================================
2322  !
2323 
2325  FUNCTION normalisesp(a,err,error)
2327  !Argument variables
2328  REAL(SP), INTENT(IN) :: a(:)
2329  INTEGER(INTG), INTENT(OUT) :: err
2330  TYPE(varying_string), INTENT(OUT) :: error
2331  !Function variable
2332  REAL(SP) :: NormaliseSP(size(a,1))
2333  !Local variables
2334  REAL(SP) :: length
2335 
2336  enters("",err,error,*999)
2337 
2338  length=l2norm(a)
2339  IF(abs(length)<zero_tolerance_sp) THEN
2340  normalisesp=a
2341  CALL flagerror("Length of the vector to normalise is zero.",err,error,*999)
2342  ELSE
2343  normalisesp=a/length
2344  ENDIF
2345 
2346  exits("NormaliseSP")
2347  RETURN
2348 999 errorsexits("NormaliseSP",err,error)
2349  RETURN
2350 
2351  END FUNCTION normalisesp
2352 
2353  !
2354  !================================================================================================================================
2355  !
2356 
2358  FUNCTION normalisedp(a,err,error)
2360  !Argument variables
2361  REAL(DP), INTENT(IN) :: a(:)
2362  INTEGER(INTG), INTENT(OUT) :: err
2363  TYPE(varying_string), INTENT(OUT) :: error
2364  !Function variable
2365  REAL(DP) :: NormaliseDP(size(a,1))
2366  !Local variables
2367  REAL(DP) :: length
2368 
2369  enters("NormaliseDP",err,error,*999)
2370 
2371  length=l2norm(a)
2372  IF(abs(length)<zero_tolerance_dp) THEN
2373  normalisedp=a
2374  CALL flagerror("Length of the vector to normalise is zero.",err,error,*999)
2375  ELSE
2376  normalisedp=a/length
2377  ENDIF
2378 
2379  exits("NormaliseDP")
2380  RETURN
2381 999 errorsexits("NormaliseDP",err,error)
2382  RETURN
2383 
2384  END FUNCTION normalisedp
2385 
2386  !
2387  !================================================================================================================================
2388  !
2389 
2391  SUBROUTINE normcrossproductsp(a,b,c,err,error,*)
2393  !Argument variables
2394  REAL(SP), INTENT(IN) :: a(:)
2395  REAL(SP), INTENT(IN) :: b(:)
2396  REAL(SP), INTENT(OUT) :: c(:)
2397  INTEGER(INTG), INTENT(OUT) :: err
2398  TYPE(varying_string), INTENT(OUT) :: error
2399  !Local variables
2400 
2401  enters("NormCrossProductSP",err,error,*999)
2402 
2403  CALL crossproduct(a,b,c,err,error,*999)
2404  c=normalise(c,err,error)
2405  IF(err/=0) GOTO 999
2406 
2407  exits("NormCrossProductSP")
2408  RETURN
2409 999 errorsexits("NormCrossProductSP",err,error)
2410  RETURN 1
2411 
2412  END SUBROUTINE normcrossproductsp
2413 
2414  !
2415  !================================================================================================================================
2416  !
2417 
2419  SUBROUTINE normcrossproductdp(a,b,c,err,error,*)
2421  !Argument variables
2422  REAL(DP), INTENT(IN) :: a(:)
2423  REAL(DP), INTENT(IN) :: b(:)
2424  REAL(DP), INTENT(OUT) :: c(:)
2425  INTEGER(INTG), INTENT(OUT) :: err
2426  TYPE(varying_string), INTENT(OUT) :: error
2427  !Local variables
2428 
2429  enters("NormCrossProductDP",err,error,*999)
2430 
2431  CALL crossproduct(a,b,c,err,error,*999)
2432  c=normalise(c,err,error)
2433  IF(err/=0) GOTO 999
2434 
2435  exits("NormCrossProductDP")
2436  RETURN
2437 999 errorsexits("NormCrossProductDP",err,error)
2438  RETURN 1
2439 
2440  END SUBROUTINE normcrossproductdp
2441 
2442  !
2443  !================================================================================================================================
2444  !
2445 
2447  SUBROUTINE solvesmalllinearsystemsp(A,x,b,err,error,*)
2449  !Argument variables
2450  REAL(SP), INTENT(IN) :: A(:,:)
2451  REAL(SP), INTENT(OUT) :: x(:)
2452  REAL(SP), INTENT(IN) :: b(:)
2453  INTEGER(INTG), INTENT(OUT) :: err
2454  TYPE(varying_string), INTENT(OUT) :: error
2455  !Local variables
2456  REAL(SP) :: AInv(size(a,1),size(a,2)),det
2457 
2458  enters("SolveSmallLinearSystemSP",err,error,*999)
2459 
2460  IF(SIZE(a,1)==SIZE(a,2)) THEN
2461  IF(SIZE(a,1)==SIZE(b,1)) THEN
2462  IF(SIZE(a,1)<=SIZE(x,1)) THEN
2463  SELECT CASE(SIZE(a,1))
2464  CASE(1:3)
2465  CALL invert(a,ainv,det,err,error,*999)
2466  x=matmul(ainv,b)
2467  CASE DEFAULT
2468  CALL flagerror("Matrix size not implemented.",err,error,*999)
2469  END SELECT
2470  ELSE
2471  CALL flagerror("x is too small.",err,error,*999)
2472  ENDIF
2473  ELSE
2474  CALL flagerror("Size of b is not the same as the number of rows in A.",err,error,*999)
2475  ENDIF
2476  ELSE
2477  CALL flagerror("Matrix is not square.",err,error,*999)
2478  ENDIF
2479 
2480  exits("SolveSmallLinearSystemSP")
2481  RETURN
2482 999 errorsexits("SolveSmallLinearSystemSP",err,error)
2483  RETURN 1
2484 
2485  END SUBROUTINE solvesmalllinearsystemsp
2486 
2487  !
2488  !================================================================================================================================
2489  !
2490 
2492  SUBROUTINE solvesmalllinearsystemdp(A,x,b,err,error,*)
2494  !Argument variables
2495  REAL(DP), INTENT(IN) :: A(:,:)
2496  REAL(DP), INTENT(OUT) :: x(:)
2497  REAL(DP), INTENT(IN) :: b(:)
2498  INTEGER(INTG), INTENT(OUT) :: err
2499  TYPE(varying_string), INTENT(OUT) :: error
2500  !Local variables
2501  REAL(DP) :: AInv(size(a,1),size(a,2)),det
2502 
2503  enters("SolveSmallLinearSystemDP",err,error,*999)
2504 
2505  IF(SIZE(a,1)==SIZE(a,2)) THEN
2506  IF(SIZE(a,1)==SIZE(b,1)) THEN
2507  IF(SIZE(a,1)<=SIZE(x,1)) THEN
2508  SELECT CASE(SIZE(a,1))
2509  CASE(1:3)
2510  CALL invert(a,ainv,det,err,error,*999)
2511  x=matmul(ainv,b)
2512  CASE DEFAULT
2513  CALL flagerror("Matrix size not implemented.",err,error,*999)
2514  END SELECT
2515  ELSE
2516  CALL flagerror("x is too small.",err,error,*999)
2517  ENDIF
2518  ELSE
2519  CALL flagerror("Size of b is not the same as the number of rows in A.",err,error,*999)
2520  ENDIF
2521  ELSE
2522  CALL flagerror("Matrix is not square.",err,error,*999)
2523  ENDIF
2524 
2525  exits("SolveSmallLinearSystemDP")
2526  RETURN
2527 999 errorsexits("SolveSmallLinearSystemDP",err,error)
2528  RETURN 1
2529 
2530  END SUBROUTINE solvesmalllinearsystemdp
2531 
2532  !
2533  !================================================================================================================================
2534  !
2535 
2537  FUNCTION cothsp(a)
2539  !Argument variables
2540  REAL(SP), INTENT(IN) :: a
2541  !Function variable
2542  REAL(SP) :: CothSP
2543 
2544  cothsp=(exp(a)+exp(-1.0_sp*a))/(exp(a)-exp(-1.0_sp*a))
2545 
2546  RETURN
2547 
2548  END FUNCTION cothsp
2549 
2550  !
2551  !================================================================================================================================
2552  !
2553 
2555  FUNCTION cothdp(a)
2557  !Argument variables
2558  REAL(DP), INTENT(IN) :: a
2559  !Function variable
2560  REAL(DP) :: CothDP
2561 
2562  cothdp=(exp(a)+exp(-1.0_dp*a))/(exp(a)-exp(-1.0_dp*a))
2563 
2564  RETURN
2565 
2566  END FUNCTION cothdp
2567 
2568  !
2569  !================================================================================================================================
2570  !
2571 
2574  SUBROUTINE spline_cubic_set (n, t, y, ibcbeg, ybcbeg, ibcend, ybcend, ypp, err, error, *)
2576  !Argument variables
2577  INTEGER(INTG), INTENT(IN) :: n
2578  REAL(DP), INTENT(IN) :: t(n)
2579  REAL(DP), INTENT(IN) :: y(n)
2580  INTEGER(INTG), INTENT(IN) :: ibcbeg
2581  REAL(DP), INTENT(IN) :: ybcbeg
2582  INTEGER(INTG), INTENT(IN) :: ibcend
2583  REAL(DP), INTENT(IN) :: ybcend
2584  REAL(DP), INTENT(OUT) :: ypp(n)
2585  INTEGER(INTG), INTENT(OUT) :: err
2586  TYPE(varying_string), INTENT(OUT) :: error
2587  !Local variables
2588  REAL(DP) :: diag(n)
2589  REAL(DP) :: sub(2:n)
2590  REAL(DP) :: sup(1:n-1)
2591  INTEGER(INTG) :: i
2592  TYPE(varying_string) :: localError
2593 
2594  enters("spline_cubic_set",err,error,*999)
2595 
2596  ! Sanity checks
2597  IF ( n <= 1 ) then
2598  localerror="spline interpolation requires at least 2 knots- user supplied "//trim(numbertovstring(n,"*",err,error))
2599  CALL flagerror(localerror,err,error,*999)
2600  ENDIF
2601  DO i = 1, n-1
2602  IF ( t(i) >= t(i+1) ) then
2603  localerror="Non-increasing knots supplied for cubic spline interpolation."
2604  CALL flagerror(localerror,err,error,*999)
2605  ENDIF
2606  ENDDO
2607 
2608  ! Set the first equation.
2609  IF ( ibcbeg == 0 ) then
2610  ypp(1) = 0.0e+00_dp
2611  diag(1) = 1.0e+00_dp
2612  sup(1) = -1.0e+00_dp
2613  ELSE IF ( ibcbeg == 1 ) then
2614  ypp(1) = ( y(2) - y(1) ) / ( t(2) - t(1) ) - ybcbeg
2615  diag(1) = ( t(2) - t(1) ) / 3.0e+00_dp
2616  sup(1) = ( t(2) - t(1) ) / 6.0e+00_dp
2617  ELSE IF ( ibcbeg == 2 ) then
2618  ypp(1) = ybcbeg
2619  diag(1) = 1.0e+00_dp
2620  sup(1) = 0.0e+00_dp
2621  ELSE
2622  localerror="The boundary flag IBCBEG must be 0, 1 or 2."
2623  CALL flagerror(localerror,err,error,*999)
2624  ENDIF
2625 
2626  ! Set the intermediate equations.
2627  DO i = 2, n-1
2628  ypp(i) = ( y(i+1) - y(i) ) / ( t(i+1) - t(i) ) &
2629  & - ( y(i) - y(i-1) ) / ( t(i) - t(i-1) )
2630  sub(i) = ( t(i) - t(i-1) ) / 6.0e+00_dp
2631  diag(i) = ( t(i+1) - t(i-1) ) / 3.0e+00_dp
2632  sup(i) = ( t(i+1) - t(i) ) / 6.0e+00_dp
2633  ENDDO
2634 
2635  ! Set the last equation.
2636  IF ( ibcend == 0 ) then
2637  ypp(n) = 0.0e+00_dp
2638  sub(n) = -1.0e+00_dp
2639  diag(n) = 1.0e+00_dp
2640  ELSE IF ( ibcend == 1 ) then
2641  ypp(n) = ybcend - ( y(n) - y(n-1) ) / ( t(n) - t(n-1) )
2642  sub(n) = ( t(n) - t(n-1) ) / 6.0e+00_dp
2643  diag(n) = ( t(n) - t(n-1) ) / 3.0e+00_dp
2644  ELSE IF ( ibcend == 2 ) then
2645  ypp(n) = ybcend
2646  sub(n) = 0.0e+00_dp
2647  diag(n) = 1.0e+00_dp
2648  ELSE
2649  localerror="The boundary flag IBCEND must be 0, 1 or 2."
2650  CALL flagerror(localerror,err,error,*999)
2651  ENDIF
2652 
2653  ! Special case:
2654  ! N = 2, IBCBEG = IBCEND = 0.
2655  IF ( n == 2 .and. ibcbeg == 0 .and. ibcend == 0 ) then
2656  ypp(1) = 0.0e+00_dp
2657  ypp(2) = 0.0e+00_dp
2658 
2659  ! Solve the linear system.
2660  ELSE
2661  CALL s3_fs ( sub, diag, sup, n, ypp, ypp, err, error, *999 )
2662  ENDIF
2663 
2664  exits("spline_cubic_set")
2665  RETURN
2666 999 errorsexits("spline_cubic_set",err,error)
2667  RETURN 1
2668 
2669  END SUBROUTINE spline_cubic_set
2670 
2671  !
2672  !================================================================================================================================
2673  !
2674 
2677  SUBROUTINE s3_fs ( a1, a2, a3, n, b, x, err, error, *)
2679  !Argument variables
2680  REAL(DP), INTENT(INOUT) :: a1(2:n)
2681  REAL(DP), INTENT(INOUT) :: a2(1:n)
2682  REAL(DP), INTENT(INOUT) :: a3(1:n-1)
2683  INTEGER(INTG), INTENT(IN) :: n
2684  REAL(DP), INTENT(INOUT) :: b(n)
2685  REAL(DP), INTENT(OUT) :: x(n)
2686  INTEGER(INTG), INTENT(OUT) :: err
2687  TYPE(varying_string), INTENT(OUT) :: error
2688  !Local variables
2689  INTEGER(INTG) :: i
2690  REAL(DP) :: xmult
2691  TYPE(varying_string) :: localError
2692 
2693  enters("s3_fs",err,error,*999)
2694 
2695  ! The diagonal entries can't be zero.
2696  DO i = 1, n
2697  IF ( abs(a2(i)) < zero_tolerance ) then
2698  localerror="Zero diagonal entry in tridiagonal linear system."
2699  CALL flagerror(localerror,err,error,*999)
2700  ENDIF
2701  ENDDO
2702 
2703  DO i = 2, n-1
2704  xmult = a1(i) / a2(i-1)
2705  a2(i) = a2(i) - xmult * a3(i-1)
2706  b(i) = b(i) - xmult * b(i-1)
2707  ENDDO
2708 
2709  xmult = a1(n) / a2(n-1)
2710  a2(n) = a2(n) - xmult * a3(n-1)
2711  x(n) = ( b(n) - xmult * b(n-1) ) / a2(n)
2712  DO i = n-1, 1, -1
2713  x(i) = ( b(i) - a3(i) * x(i+1) ) / a2(i)
2714  ENDDO
2715 
2716  exits("s3_fs")
2717  RETURN
2718 999 errorsexits("s3_fs",err,error)
2719  RETURN 1
2720 
2721  END SUBROUTINE s3_fs
2722 
2723  !
2724  !================================================================================================================================
2725  !
2726 
2729  SUBROUTINE spline_cubic_val (n, t, y, ypp, tval, yval, ypval, yppval, err, error, *)
2731  !Argument variables
2732  INTEGER(INTG), INTENT(IN) :: n
2733  REAL(DP), INTENT(IN) :: t(n)
2734  REAL(DP), INTENT(IN) :: y(n)
2735  REAL(DP), INTENT(IN) :: ypp(n)
2736  REAL(DP), INTENT(IN) :: tval
2737  REAL(DP), INTENT(OUT) :: yval
2738  REAL(DP), INTENT(OUT) :: ypval
2739  REAL(DP), INTENT(OUT) :: yppval
2740  INTEGER(INTG), INTENT(OUT) :: err
2741  TYPE(varying_string), INTENT(OUT) :: error
2742  !Local variables
2743  REAL(DP) :: dt
2744  REAL(DP) :: h
2745  INTEGER(INTG) :: i
2746  INTEGER(INTG) :: left
2747  INTEGER(INTG) :: right
2748  LOGICAL :: foundInterval
2749 
2750  enters("spline_cubic_val",err,error,*999)
2751 
2752  ! Determine the interval [T(LEFT), T(RIGHT)] that contains TVAL.
2753  ! Values below T(1) or above T(N) use extrapolation.
2754  foundinterval = .false.
2755  DO i = 2, n - 1
2756  IF ( tval < t(i) ) THEN
2757  foundinterval=.true.
2758  left = i - 1
2759  right = i
2760  EXIT
2761  ENDIF
2762  ENDDO
2763  IF (foundinterval .EQV. .false.) THEN
2764  left = n - 1
2765  right = n
2766  ENDIF
2767 
2768  ! Evaluate the polynomial.
2769  dt = tval - t(left)
2770  h = t(right) - t(left)
2771 
2772  yval = y(left) &
2773  & + dt * ( ( y(right) - y(left) ) / h &
2774  & - ( ypp(right) / 6.0e+00_dp + ypp(left) / 3.0e+00_dp ) * h &
2775  & + dt * ( 0.5e+00 * ypp(left) &
2776  & + dt * ( ( ypp(right) - ypp(left) ) / ( 6.0e+00_dp * h ) ) ) )
2777 
2778  ypval = ( y(right) - y(left) ) / h &
2779  & - ( ypp(right) / 6.0e+00_dp + ypp(left) / 3.0e+00_dp ) * h &
2780  & + dt * ( ypp(left) &
2781  & + dt * ( 0.5e+00_dp * ( ypp(right) - ypp(left) ) / h ) )
2782 
2783  yppval = ypp(left) + dt * ( ypp(right) - ypp(left) ) / h
2784 
2785  exits("spline_cubic_val")
2786  RETURN
2787 999 errorsexits("spline_cubic_val",err,error)
2788  RETURN 1
2789 
2790  END SUBROUTINE spline_cubic_val
2791 
2792  !
2793  !================================================================================================================================
2794  !
2795 
2796 END MODULE maths
2797 
Calculates the modified Bessel function of the first kind of order 0 using the approximation of Abrom...
Definition: maths.f90:119
subroutine, public enters(NAME, ERR, ERROR,)
Records the entry into the named procedure and initialises the error code.
pure real(dp) function k1dp(x)
Calculates the modified Bessel function of the second kind of order 1 using the approximation of Abro...
Definition: maths.f90:1724
Returns the inverse of a matrix.
Definition: maths.f90:131
pure real(sp) function i0sp(x)
Calculates the modified Bessel function of the first kind of order 0 using the approximation of Abrom...
Definition: maths.f90:1287
Returns the transpose of a matrix A in A^T.
Definition: maths.f90:191
real(sp) function, dimension(size(a, 1)) normalisesp(a, err, error)
Normalises a real single precision vector a.
Definition: maths.f90:2326
real(sp), parameter zero_tolerance_sp
The zero tolerance for single precision zero tests i.e., if(abs(x)>zero_tolerance) then...
Definition: constants.f90:75
Calculates the modified Bessel function of the second kind of order 0 using the approximation of Abro...
Definition: maths.f90:137
real(dp), parameter pi
The double precision value of pi.
Definition: constants.f90:57
subroutine normcrossproductsp(a, b, c, err, error,)
Calculates and returns the normalised vector cross-prouct of the single precision vectors a x b in c...
Definition: maths.f90:2392
pure real(dp) function edpdp(x)
Calculates the elliptic integral of the second kind - E(m), for a double precision argument...
Definition: maths.f90:842
real(dp) function determinantfulldp(A, err, error)
Returns the determinant of a full double precision matrix A.
Definition: maths.f90:801
subroutine eigenvectorfulldp(A, eValue, eVector, err, error,)
Returns the normalised eigenvector of a full double precision symmetric matrix A that corresponds to ...
Definition: maths.f90:1168
Solves a small linear system Ax=b.
Definition: maths.f90:245
real(dp) function cothdp(a)
Calculates double precision hyperbolic cotangent function.
Definition: maths.f90:2556
This module contains all string manipulation and transformation routines.
Definition: strings.f90:45
Flags a warning to the user.
subroutine matrixvectorproductsp(A, b, c, err, error,)
Calculates and returns the matrix-vector product of the single precision vector A*b in c...
Definition: maths.f90:555
Calculates and returns the matrix-vector-product A*b in the vector c.
Definition: maths.f90:209
Solves a small linear system Ax=b.
Definition: maths.f90:239
Calculates the the vector cross product of a x b in c and the n derivatives, dc, of the vector cross ...
Definition: maths.f90:87
pure real(sp) function kdpsp(x)
Calculates the elliptic integral of the first kind - K(m), for a single precision argument...
Definition: maths.f90:1853
subroutine, public spline_cubic_val(n, t, y, ypp, tval, yval, ypval, yppval, err, error,)
Evaluates a cubic spline at a specified point. First call spline_cubic_set to calculate derivatives a...
Definition: maths.f90:2730
subroutine dcrossproductdp(n, a, b, c, da, db, dc, err, error,)
Calculates the the vector cross product of a x b in c and the n derivatives, dc, of the vector cross ...
Definition: maths.f90:502
Normalises a vector.
Definition: maths.f90:221
pure real(dp) function i1dp(x)
Calculates the modified Bessel function of the first kind of order 1 using the approximation of Abrom...
Definition: maths.f90:1318
subroutine, public spline_cubic_set(n, t, y, ibcbeg, ybcbeg, ibcend, ybcend, ypp, err, error,)
Calculates second derivatives of a cubic spline function for a tabulated function y(x)...
Definition: maths.f90:2575
subroutine normcrossproductdp(a, b, c, err, error,)
Calculates and returns the normalised vector cross-prouct of the double precision vectors a x b in c...
Definition: maths.f90:2420
This module contains all mathematics support routines.
Definition: maths.f90:45
pure real(sp) function l2normsp(a)
Returns the L2-norm of the single precision vector a.
Definition: maths.f90:1887
Calculates the elliptic integral of the second kind - E(m).
Definition: maths.f90:101
This module provides an iso_varying_string module, conformant to the API specified in ISO/IEC 1539-2:...
pure real(sp) function i1sp(x)
Calculates the modified Bessel function of the first kind of order 1 using the approximation of Abrom...
Definition: maths.f90:1349
Calculates the elliptic integral of the first kind - K(m).
Definition: maths.f90:149
This module contains all program wide constants.
Definition: constants.f90:45
Calculates the normalised vector cross product of two vectors.
Definition: maths.f90:227
Calculates the vector cross product of two vectors.
Definition: maths.f90:66
subroutine dcrossproductintg(n, a, b, c, da, db, dc, err, error,)
Calculates the the vector cross product of a x b in c and the n derivatives, dc, of the vector cross ...
Definition: maths.f90:394
subroutine crossproductintg(a, b, c, err, error,)
Calculates and returns the vector cross-product of the integer vectors a x b in c.
Definition: maths.f90:270
Calculates and returns the matrix-product-transpose A*B^T in the matrix C.
Definition: maths.f90:185
subroutine invertfullsp(A, B, det, err, error,)
Inverts a full single precision matrix A to give matrix B and returns the determinant of A in det...
Definition: maths.f90:1483
Calculates the modified Bessel function of the first kind of order 1 using the approximation of Abrom...
Definition: maths.f90:125
subroutine crossproductsp(a, b, c, err, error,)
Calculates and returns the vector cross-product of the single precision vectors a x b in c...
Definition: maths.f90:311
Returns the eigenvectors of a matrix.
Definition: maths.f90:113
real(sp) function determinantfullsp(A, err, error)
Returns the determinant of a full single precision matrix A.
Definition: maths.f90:760
Calculates the normalised vector cross product of two vectors.
Definition: maths.f90:233
Calculates and returns the matrix-transpose vector-product A^T*b in the vector c. ...
Definition: maths.f90:215
subroutine, public exits(NAME)
Records the exit out of the named procedure.
real(dp), parameter zero_tolerance_dp
The zero tolerance for double precision zero tests i.e., if(abs(x)>zero_tolerance) then...
Definition: constants.f90:69
real(dp) function l2normdp(A)
Returns the L2-norm of the double precision vector a.
Definition: maths.f90:1908
Calculates the modified Bessel function of the second kind of order 1 using the approximation of Abro...
Definition: maths.f90:143
This module contains all the low-level base routines e.g., all debug, control, and low-level communic...
subroutine matrixtransposeproductdp(A, B, C, err, error,)
Calculates and returns the matrix-transpose product of the double precision matrix A^T*B in C for dou...
Definition: maths.f90:2079
pure real(sp) function edpsp(x)
Calculates the elliptic integral of the second kind - E(m), for a single precision argument...
Definition: maths.f90:873
subroutine solvesmalllinearsystemdp(A, x, b, err, error,)
Finds the solution to a small double precision linear system Ax=b.
Definition: maths.f90:2493
subroutine eigenvaluefullsp(A, eValues, err, error,)
Returns the eigenvalues of a full single precision matrix A.
Definition: maths.f90:905
Returns hyperbolic cotangent of argument.
Definition: maths.f90:251
subroutine matrixproducttransposedp(A, B, C, err, error,)
Calculates and returns the matrix-product-transpose of the double precision matrix A*B^T in C...
Definition: maths.f90:2178
subroutine matrixtransposedp(A, AT, err, error,)
Returns the transpose of a double precision matrix A in AT.
Definition: maths.f90:2277
Returns the transpose of a matrix A in A^T.
Definition: maths.f90:197
subroutine eigenvectorfullsp(A, eValue, eVector, err, error,)
Returns the normalised eigenvector of a full single precision symmetric matrix A that corresponds to ...
Definition: maths.f90:1081
integer, parameter sp
Single precision real kind.
Definition: kinds.f90:67
Calculates and returns the matrix-transpose product A^T*B in the matrix C.
Definition: maths.f90:179
subroutine matrixvectorproductdp(A, b, c, err, error,)
Calculates and returns the matrix-vector product of the double precision vectir A*b in c...
Definition: maths.f90:596
subroutine, public s3_fs(a1, a2, a3, n, b, x, err, error,)
S3_FS factors and solves a tridiagonal linear system. algorithm adapted from John Burkhardt&#39;s s3_fs r...
Definition: maths.f90:2678
pure real(dp) function i0dp(x)
Calculates the modified Bessel function of the first kind of order 0 using the approximation of Abrom...
Definition: maths.f90:1256
Calculates and returns the matrix-vector-product A*b in the vector c.
Definition: maths.f90:203
pure real(sp) function k0sp(x)
Calculates the modified Bessel function of the second kind of order 0 using the approximation of Abro...
Definition: maths.f90:1677
subroutine matrixtransposesp(A, AT, err, error,)
Returns the transpose of a single precision matrix A in AT.
Definition: maths.f90:2228
subroutine identitymatrixsp(A, err, error,)
Returns an identity matrix.
Definition: maths.f90:1379
integer(intg) function determinantfullintg(A, err, error)
Returns the determinant of a full integer matrix A.
Definition: maths.f90:719
Returns the determinant of a matrix.
Definition: maths.f90:94
subroutine invertfulldp(A, B, det, err, error,)
Inverts a full double precision matrix A to give matrix B and returns the determinant of A in det...
Definition: maths.f90:1556
subroutine matrixproductsp(A, B, C, err, error,)
Calculates and returns the matrix-product of the single precision matrix A*B in C for single precisio...
Definition: maths.f90:1929
real(dp) function, dimension(size(a, 1)) normalisedp(a, err, error)
Normalises a real double precision vector a.
Definition: maths.f90:2359
pure real(sp) function k1sp(x)
Calculates the modified Bessel function of the second kind of order 1 using the approximation of Abro...
Definition: maths.f90:1772
subroutine matrixtransposevectorproductdp(A, b, c, err, error,)
Calculates and returns the matrix-transpose vector product of the double precision vector A^T*b in c...
Definition: maths.f90:678
Calculates the vector cross product of two vectors.
Definition: maths.f90:73
subroutine eigenvaluefulldp(A, eValues, err, error,)
Returns the eigenvalues of a full double precision matrix A.
Definition: maths.f90:993
subroutine dcrossproductsp(n, a, b, c, da, db, dc, err, error,)
Calculates the the vector cross product of a x b in c and the n derivatives, dc, of the vector cross ...
Definition: maths.f90:448
subroutine crossproductdp(a, b, c, err, error,)
Calculates and returns the vector cross-product of the double precision vectors a x b in c...
Definition: maths.f90:352
Returns the identity matrix.
Definition: maths.f90:155
pure real(dp) function kdpdp(x)
Calculates the elliptic integral of the first kind - K(m), for a double precision argument...
Definition: maths.f90:1819
subroutine matrixproducttransposesp(A, B, C, err, error,)
Calculates and returns the matrix-product-transpose of the single precision matrix A*B^T in C for sin...
Definition: maths.f90:2128
subroutine identitymatrixdp(A, err, error,)
Returns an identity matrix.
Definition: maths.f90:1431
pure real(dp) function k0dp(x)
Calculates the modified Bessel function of the second kind of order 1 using the approximation of Abro...
Definition: maths.f90:1630
Calculates and returns the matrix-product A*B in the matrix C.
Definition: maths.f90:167
real(sp) function cothsp(a)
Calculates single precision hyperbolic cotangent function.
Definition: maths.f90:2538
Returns the L2 norm of a vector.
Definition: maths.f90:161
Returns the eigenvalues of a matrix.
Definition: maths.f90:107
Flags an error condition.
subroutine matrixtransposeproductsp(A, B, C, err, error,)
Calculates and returns the matrix-transpose product of the single precision matrix A^T*B in C for sin...
Definition: maths.f90:2029
subroutine matrixproductdp(A, B, C, err, error,)
Calculates and returns the matrix-product of the double precision matrix A*B in C.
Definition: maths.f90:1979
Calculates and returns the matrix-product A*B in the matrix C.
Definition: maths.f90:173
real(dp), parameter zero_tolerance
Definition: constants.f90:70
This module contains all kind definitions.
Definition: kinds.f90:45
Calculates the the vector cross product of A*B in C and the N derivatives, D_C, of the vector cross p...
Definition: maths.f90:80
subroutine solvesmalllinearsystemsp(A, x, b, err, error,)
Finds the solution to a small single precision linear system Ax=b.
Definition: maths.f90:2448
subroutine matrixtransposevectorproductsp(A, b, c, err, error,)
Calculates and returns the matrix-transpose vector product of the single precision vector A^T*b in c...
Definition: maths.f90:637