1 | #!/bin/bash |
---|
2 | # |
---|
3 | set -u |
---|
4 | #set -xv |
---|
5 | # |
---|
6 | # for on each file containing a call to work alloc (exept BDY files that are too complicated...) |
---|
7 | #for i in $( ack -il "^ *call *wrk_alloc *\(" | grep -v BDY ) |
---|
8 | for i in $( egrep -iRl "^ *call *wrk_alloc *\(" * | grep "90$" | grep -v BDY ) |
---|
9 | do |
---|
10 | # create a temporary file that will be easier to process... |
---|
11 | sed -e "s/dimension/DIMENSION/" -e "s/pointer/POINTER/" $i > tmp$$ |
---|
12 | # replace "dimension(...), pointer" to "pointer, dimension(...)" |
---|
13 | sed -e "s/, *DIMENSION *(\([^)]*\)) *, *POINTER/, POINTER, DIMENSION(\1)/" tmp$$ > tmp2$$ |
---|
14 | mv tmp2$$ tmp$$ |
---|
15 | # remove all comments in $i |
---|
16 | sed -e "s/\!.*//" tmp$$ > tmp2$$ |
---|
17 | mv tmp2$$ tmp$$ |
---|
18 | # numbers of the lines defining the beginning and the end of each subroutine or functions |
---|
19 | n1=$( egrep -ic "(^ *subroutine *[0-9a-zA-Z_]|function *[0-9a-zA-Z_][0-9a-zA-Z_]* *\(.*\))" tmp$$ ) |
---|
20 | n2=$( egrep -ic "(^ *end *subroutine|^ *end *function)" tmp$$ ) |
---|
21 | if [ $n1 -ne $n2 ] |
---|
22 | then |
---|
23 | echo "error with the definition of subroutine/function blocks in $i" |
---|
24 | exit |
---|
25 | fi |
---|
26 | linesbegin=$( egrep -in "(^ *subroutine *[0-9a-zA-Z_]|function *[0-9a-zA-Z_][0-9a-zA-Z_]* *\(.*\))" tmp$$ | sed -e "s/:.*//" ) |
---|
27 | linesend=$( egrep -in "(^ *end *subroutine|^ *end *function)" tmp$$ | sed -e "s/:.*//" | sort -rn ) |
---|
28 | # |
---|
29 | # number of the lines containing wrk_alloc |
---|
30 | cnt=$( grep -ci "^ *call *wrk_alloc *(" tmp$$ ) |
---|
31 | # for each of these lines |
---|
32 | ll=1 |
---|
33 | while [ $ll -le $cnt ] |
---|
34 | do |
---|
35 | # get the line with its number |
---|
36 | line=$( grep -in "^ *call *wrk_alloc *(" tmp$$ | sed -n ${ll}p | sed -e "s/\!.*//" ) |
---|
37 | # get its number |
---|
38 | lline=$( echo $line | sed -e "s/:.*//" ) |
---|
39 | # keep only the arument of wrk_alloc between () |
---|
40 | line=$( echo $line | sed -e "s/[^(]*\((.*)\).*/\1/" | sed -e "s/, *k[ijkl]start *=[^,]*,/,/" | sed -e "s/, *k[ijkl]start *=.*)/ )/" ) |
---|
41 | # find in which subroutine or function is located this call to wrk_alloc: l1 beginning l2: end |
---|
42 | for lll in $linesbegin |
---|
43 | do |
---|
44 | [ $lline -gt $lll ] && l1=$lll |
---|
45 | done |
---|
46 | for lll in $linesend |
---|
47 | do |
---|
48 | [ $lline -lt $lll ] && l2=$lll |
---|
49 | done |
---|
50 | if [ $l2 -le $l1 ] |
---|
51 | then |
---|
52 | echo "error in $i in the indentification subroutine/function block containing line $lline" |
---|
53 | exit |
---|
54 | fi |
---|
55 | # get the last argument of the call to wrk_alloc (between the last "," and ")" |
---|
56 | lw=$( echo $line | sed -e "s/.*,\(.*\)).*/\1/" | sed -e "s/ *//g" ) |
---|
57 | # get the line containing the definition of this argument and from it get the number of dimension of the argument |
---|
58 | tst=$( sed -n ${l1},${l2}p tmp$$ | grep -i "POINTER *, *DIMENSION *(.*) *::.*"${lw} | egrep -ic "[^0-9a-zA-Z_]("${lw}" *$|"${lw}" *,)" ) |
---|
59 | if [ $tst -ne 1 ] |
---|
60 | then |
---|
61 | echo "error with ${lw} definition in $i" |
---|
62 | exit |
---|
63 | fi |
---|
64 | dimsz=$( sed -n ${l1},${l2}p tmp$$ | grep -i "POINTER *, *DIMENSION *(.*) *::.*"${lw} | egrep -i "[^0-9a-zA-Z_]("${lw}" *$|"${lw}" *,)" | sed -e "s/.*POINTER *, *DIMENSION *(\(.*\)) *::.*/\1/" | sed -e "s/ //g" | wc -c ) |
---|
65 | dimsz=$(( $dimsz / 2 )) |
---|
66 | # get the number of variables concerned by the call to wrk_alloc (keep anly the , and count them) |
---|
67 | nvar=$( echo $line | sed -e "s/[^,]//g" | wc -c ) |
---|
68 | nvar=$(( $nvar - $dimsz )) |
---|
69 | # get the définition of the size of the dimensions from the call to wrk_alloc |
---|
70 | case $dimsz in |
---|
71 | 1) dim=$( echo $line | sed -e "s/( *\([^,]*\),.*)/\1/" | sed -e "s/ //g" ) ;; # keep between ( and the 1st , |
---|
72 | 2) dim=$( echo $line | sed -e "s/( *\([^,]*,[^,]*\),.*)/\1/" | sed -e "s/ //g" ) ;; # keep between ( and the 2nd , |
---|
73 | 3) dim=$( echo $line | sed -e "s/( *\([^,]*,[^,]*,[^,]*\),.*)/\1/" | sed -e "s/ //g" ) ;; # keep between ( and the 3rd , |
---|
74 | 4) dim=$( echo $line | sed -e "s/( *\([^,]*,[^,]*,[^,]*,[^,]*\),.*)/\1/" | sed -e "s/ //g" ) ;; # keep between ( and the 4th , |
---|
75 | *) echo "error with the number of dimensions of $lw in $i"; exit ;; |
---|
76 | esac |
---|
77 | # for each variable, change its definition... |
---|
78 | nn=1 |
---|
79 | var=$lw # start from the last argument |
---|
80 | while [ $nn -le $nvar ] |
---|
81 | do |
---|
82 | # get the line where this variable is defined. |
---|
83 | tst=$( sed -n ${l1},${l2}p tmp$$ | grep -ni "POINTER *, *DIMENSION *(.*) *::.*"${var} | egrep -ic "[^0-9a-zA-Z_]("${var}" *$|"${var}" *,)" ) |
---|
84 | if [ $tst -ne 1 ] |
---|
85 | then |
---|
86 | echo "error with ${lw} definition in $i" |
---|
87 | exit |
---|
88 | fi |
---|
89 | # get the line number where the variable is defined |
---|
90 | lvar=$( sed -n ${l1},${l2}p tmp$$ | grep -ni "POINTER *, *DIMENSION *(.*) *::.*"${var} | egrep -i "[^0-9a-zA-Z_]("${var}" *$|"${var}" *,)" | sed -e "s/:.*//" ) |
---|
91 | lvar=$(( $lvar + $l1 - 1 )) |
---|
92 | # get the dimension definition and compare it to ${dim} |
---|
93 | dim2=$( sed -n -e "${lvar}p" $i | sed -e "s/dimension/DIMENSION/" -e "s/\!.*//" | sed -e "s/.*, *DIMENSION *(\(.*\)).*/\1/" | sed -e "s/ //g" ) |
---|
94 | if [ $( echo $dim2 | wc -c ) -ne $(( $dimsz * 2 )) ] |
---|
95 | then |
---|
96 | if [ "$dim2" != "$dim" ] |
---|
97 | then |
---|
98 | echo "problem in $i in the defininition of variable $var: its size is $dim but we have $dim2" |
---|
99 | sed -n -e "${lvar}p" $i |
---|
100 | exit |
---|
101 | fi |
---|
102 | fi |
---|
103 | # remove pointer |
---|
104 | sed -e "${lvar}s/pointer/POINTER/" $i | sed -e "${lvar}s/, *POINTER *,/,/" | sed -e "${lvar}s/, *POINTER */ /" > tmp2$$ |
---|
105 | mv tmp2$$ $i |
---|
106 | # redefine the dimensions |
---|
107 | case $dimsz in |
---|
108 | 1) sed -e "${lvar}s/\(DIMENSION *(\) *: *)/\1${dim})/" $i > tmp2$$ ;; |
---|
109 | 2) sed -e "${lvar}s/\(DIMENSION *(\) *: *, *: *)/\1${dim})/" $i > tmp2$$ ;; |
---|
110 | 3) sed -e "${lvar}s/\(DIMENSION *(\) *: *, *: *, *: *)/\1${dim})/" $i > tmp2$$ ;; |
---|
111 | 4) sed -e "${lvar}s/\(DIMENSION *(\) *: *, *: *, *: *, *: *)/\1${dim})/" $i > tmp2$$ ;; |
---|
112 | esac |
---|
113 | mv tmp2$$ $i |
---|
114 | |
---|
115 | # define the next variable (previous argument) |
---|
116 | var=$( echo $line | sed -e "s/.*,\(.*\), *[^0-9a-zA-Z_]*${var}[^0-9a-zA-Z_]*[,)].*/\1/" | sed -e "s/ *//g" ) |
---|
117 | nn=$(( $nn + 1 )) |
---|
118 | done |
---|
119 | |
---|
120 | ll=$(( $ll + 1 )) |
---|
121 | done |
---|
122 | #delete wrk_alloc line |
---|
123 | sed -e "/call *wrk_alloc *(/d" -e "/CALL *wrk_alloc *(/d" \ |
---|
124 | -e "/call *wrk_dealloc *(/d" -e "/CALL *wrk_dealloc *(/d" \ |
---|
125 | -e "/USE wrk_nemo/d" -e "/use wrk_nemo/d" $i > tmp$$ |
---|
126 | mv tmp$$ $i |
---|
127 | |
---|
128 | echo $i done |
---|
129 | done |
---|
130 | # |
---|
131 | # some specific changes... |
---|
132 | # |
---|
133 | # OPA_SRC/SBC/albedo.F90 |
---|
134 | sed -e "s/DIMENSION(jpi,jpj,ijpl)/DIMENSION(jpi,jpj,SIZE(pt_ice,3))/" OPA_SRC/SBC/albedo.F90 > tmp$$ |
---|
135 | mv tmp$$ OPA_SRC/SBC/albedo.F90 |
---|
136 | # LIM_SRC_2/limrhg_2.F90 |
---|
137 | sed -e "s/DIMENSION(jpi,jpj+2)/DIMENSION(jpi,0:jpj+1)/" LIM_SRC_2/limrhg_2.F90 > tmp$$ |
---|
138 | mv tmp$$ LIM_SRC_2/limrhg_2.F90 |
---|
139 | # LIM_SRC_3/limitd_me.F90 |
---|
140 | sed -e "s/DIMENSION(jpi,jpj,jpl+2)/DIMENSION(jpi,jpj,-1:jpl)/" LIM_SRC_3/limitd_me.F90 > tmp$$ |
---|
141 | mv tmp$$ LIM_SRC_3/limitd_me.F90 |
---|
142 | # LIM_SRC_3/limitd_th.F90 |
---|
143 | sed -e "s/DIMENSION(jpi,jpj,jpl+1)/DIMENSION(jpi,jpj,0:jpl)/" LIM_SRC_3/limitd_th.F90 > tmp$$ |
---|
144 | mv tmp$$ LIM_SRC_3/limitd_th.F90 |
---|
145 | # LIM_SRC_3/limthd_dif.F90 |
---|
146 | sed -e "s/DIMENSION(kiut,nlay_i+1)/DIMENSION(kiut,0:nlay_i)/" \ |
---|
147 | -e "s/DIMENSION(kiut,nlay_s+1)/DIMENSION(kiut,0:nlay_s)/" LIM_SRC_3/limthd_dif.F90 > tmp$$ |
---|
148 | mv tmp$$ LIM_SRC_3/limthd_dif.F90 |
---|
149 | # LIM_SRC_3/limthd_ent.F90 |
---|
150 | sed -e "s/DIMENSION(jpij,jkmax+4)/DIMENSION(jpij,0:jkmax+3)/" \ |
---|
151 | -e "s/DIMENSION(jkmax+4,jkmax+4)/DIMENSION(0:jkmax+3,0:jkmax+3)/" LIM_SRC_3/limthd_ent.F90 > tmp$$ |
---|
152 | mv tmp$$ LIM_SRC_3/limthd_ent.F90 |
---|
153 | # OPA_SRC/DYN/divcur.F90 |
---|
154 | sed -e "s/DIMENSION(jpi+4,jpj)/DIMENSION(-1:jpi+2,jpj)/" OPA_SRC/DYN/divcur.F90 > tmp$$ |
---|
155 | mv tmp$$ OPA_SRC/DYN/divcur.F90 |
---|
156 | # OPA_SRC/LDF/ldfslp.F90 |
---|
157 | sed -e "s/DIMENSION(jpi,jpj,jpk,2)/DIMENSION(jpi,jpj,jpk,0:1)/" \ |
---|
158 | -e "s/DIMENSION(jpi,jpj,2,2)/DIMENSION(jpi,jpj,0:1,0:1)/" OPA_SRC/LDF/ldfslp.F90 > tmp$$ |
---|
159 | mv tmp$$ OPA_SRC/LDF/ldfslp.F90 |
---|
160 | # OPA_SRC/ZDF/zdfkpp.F90 |
---|
161 | sed -e "s/DIMENSION(jpi,3) *::* zmoek/DIMENSION(jpi,0:2) :: zmoek/" OPA_SRC/ZDF/zdfkpp.F90 > tmp$$ |
---|
162 | mv tmp$$ OPA_SRC/ZDF/zdfkpp.F90 |
---|
163 | |
---|
164 | # link for limrhg.F90... |
---|
165 | cd LIM_SRC_2 |
---|
166 | ln -sf ../LIM_SRC_3/limrhg.F90 . |
---|