1 | MODULE module_generic |
---|
2 | ! Module with generic functions |
---|
3 | ! Index1DArrayR: Function to provide the first index of a given value inside a 1D real array |
---|
4 | ! Index2DArrayR: Function to provide the first index of a given value inside a 2D real array |
---|
5 | ! ErrWarnMsg: Function to print error/warning message |
---|
6 | |
---|
7 | INTEGER, PARAMETER :: r_k = KIND(1.d0) |
---|
8 | ! Fill value at 64 bits |
---|
9 | REAL(r_k) :: fillval64 = 1.e20 |
---|
10 | |
---|
11 | CONTAINS |
---|
12 | |
---|
13 | INTEGER FUNCTION Index1DArrayR(array1D, d1, val) |
---|
14 | ! Function to provide the first index of a given value inside a 1D real array |
---|
15 | |
---|
16 | IMPLICIT NONE |
---|
17 | |
---|
18 | INTEGER, PARAMETER :: r_k = KIND(1.d0) |
---|
19 | INTEGER, INTENT(in) :: d1 |
---|
20 | REAL(r_k), INTENT(in) :: val |
---|
21 | REAL(r_k), DIMENSION(d1), INTENT(in) :: array1D |
---|
22 | |
---|
23 | ! Local |
---|
24 | INTEGER :: i |
---|
25 | CHARACTER(LEN=50) :: fname |
---|
26 | |
---|
27 | fname = 'Index1DArrayR' |
---|
28 | |
---|
29 | Index1DArrayR = -1 |
---|
30 | |
---|
31 | DO i=1,d1 |
---|
32 | IF (array1d(i) == val) THEN |
---|
33 | Index1DArrayR = i |
---|
34 | EXIT |
---|
35 | END IF |
---|
36 | END DO |
---|
37 | |
---|
38 | END FUNCTION Index1DArrayR |
---|
39 | |
---|
40 | FUNCTION Index2DArrayR(array2D, d1, d2, val) |
---|
41 | ! Function to provide the first index of a given value inside a 2D real array |
---|
42 | |
---|
43 | IMPLICIT NONE |
---|
44 | |
---|
45 | INTEGER, PARAMETER :: r_k = KIND(1.d0) |
---|
46 | INTEGER, INTENT(in) :: d1, d2 |
---|
47 | REAL(r_k), INTENT(in) :: val |
---|
48 | REAL(r_k), DIMENSION(d1,d2), INTENT(in) :: array2D |
---|
49 | INTEGER, DIMENSION(2) :: Index2DArrayR |
---|
50 | |
---|
51 | ! Local |
---|
52 | INTEGER :: i, j |
---|
53 | CHARACTER(LEN=50) :: fname |
---|
54 | |
---|
55 | fname = 'Index2DArrayR' |
---|
56 | |
---|
57 | Index2DArrayR = -1 |
---|
58 | |
---|
59 | DO i=1,d1 |
---|
60 | DO j=1,d2 |
---|
61 | IF (array2d(i,j) == val) THEN |
---|
62 | Index2DArrayR(1) = i |
---|
63 | Index2DArrayR(2) = j |
---|
64 | EXIT |
---|
65 | END IF |
---|
66 | END DO |
---|
67 | END DO |
---|
68 | |
---|
69 | END FUNCTION Index2DArrayR |
---|
70 | |
---|
71 | CHARACTER(LEN=50) FUNCTION ErrWarnMsg(msg) |
---|
72 | ! Function to print error/warning message |
---|
73 | |
---|
74 | IMPLICIT NONE |
---|
75 | |
---|
76 | CHARACTER(LEN=3), INTENT(in) :: msg |
---|
77 | ! Local |
---|
78 | CHARACTER(LEN=50) :: fname |
---|
79 | |
---|
80 | fname = 'ErrWarnMsg' |
---|
81 | |
---|
82 | IF (msg == 'err') THEN |
---|
83 | ErrWarnMsg = 'ERROR -- error -- ERROR -- error' |
---|
84 | ELSE IF (msg == 'wrn') THEN |
---|
85 | ErrWarnMsg = 'WARNING -- warning -- WARNING -- warning' |
---|
86 | ELSE |
---|
87 | PRINT *,'ERROR -- error -- ERROR -- error' |
---|
88 | PRINT *,' ' // TRIM(fname) // ": '" // TRIM(msg) // "' does not exist!!" |
---|
89 | STOP |
---|
90 | END IF |
---|
91 | END FUNCTION ErrWarnMsg |
---|
92 | |
---|
93 | END MODULE module_generic |
---|