1 | #! /bin/bash |
---|
2 | # |
---|
3 | # This is a script to generate FORTRAN code from registry |
---|
4 | # |
---|
5 | # A. Spiga - 17/03/08 |
---|
6 | # |
---|
7 | |
---|
8 | |
---|
9 | # |
---|
10 | # |
---|
11 | # |
---|
12 | echo AUTOMATIC FILE GENERATION |
---|
13 | grep '#SAVEMARS2' Registry.EM | grep 'rh' > fromregistry2 |
---|
14 | grep '#SAVEMARS3' Registry.EM | grep 'rh' > fromregistry3 |
---|
15 | yeah2=$(awk 'END {print NR}' fromregistry2) |
---|
16 | yeah3=$(awk 'END {print NR}' fromregistry3) |
---|
17 | echo save ${yeah2} 2D arrays |
---|
18 | echo save ${yeah3} 3D arrays |
---|
19 | |
---|
20 | |
---|
21 | # |
---|
22 | # |
---|
23 | # |
---|
24 | \rm wrf_output_2d.h 2> /dev/null |
---|
25 | touch wrf_output_2d.h |
---|
26 | |
---|
27 | echo '!-------------------' >> test_include |
---|
28 | echo '! INCLUDE 'wrf_output_2d.h'' >> test_include |
---|
29 | echo '!-------------------' >> test_include |
---|
30 | if [ ${yeah2} -ne 0 ] |
---|
31 | then |
---|
32 | awk '{print " INTEGER, PARAMETER :: ind_"$3" = " NR}' fromregistry2 >> test_include |
---|
33 | awk 'END {print " INTEGER, PARAMETER :: n2d = " NR}' fromregistry2 >> test_include |
---|
34 | mv test_include wrf_output_2d.h |
---|
35 | else |
---|
36 | echo ' INTEGER, PARAMETER :: n2d = 1' >> test_include |
---|
37 | mv test_include wrf_output_2d.h |
---|
38 | fi |
---|
39 | |
---|
40 | \rm wrf_output_3d.h 2> /dev/null |
---|
41 | touch wrf_output_3d.h |
---|
42 | |
---|
43 | echo '!-------------------' >> test_include |
---|
44 | echo '! INCLUDE 'wrf_output_3d.h'' >> test_include |
---|
45 | echo '!-------------------' >> test_include |
---|
46 | if [ ${yeah3} -ne 0 ] |
---|
47 | then |
---|
48 | awk '{print " INTEGER, PARAMETER :: ind_"$3" = " NR}' fromregistry3 >> test_include |
---|
49 | awk 'END {print " INTEGER, PARAMETER :: n3d = " NR}' fromregistry3 >> test_include |
---|
50 | mv test_include wrf_output_3d.h |
---|
51 | else |
---|
52 | echo ' INTEGER, PARAMETER :: n3d = 1' >> test_include |
---|
53 | mv test_include wrf_output_3d.h |
---|
54 | fi |
---|
55 | |
---|
56 | |
---|
57 | # |
---|
58 | # |
---|
59 | # |
---|
60 | \rm fill_save_2d.F90 2> /dev/null |
---|
61 | #if [ ${yeah2} -ne 0 ] |
---|
62 | #then |
---|
63 | echo 'SUBROUTINE fill_save_2d( &' >> test_subroutine |
---|
64 | awk '{print $NF ",&"}' fromregistry2 >> test_subroutine |
---|
65 | echo 'ngrid,&' >> test_subroutine |
---|
66 | echo 'output_tab2d)' >> test_subroutine |
---|
67 | echo ' ' >> test_subroutine |
---|
68 | echo 'IMPLICIT NONE' >> test_subroutine |
---|
69 | echo ' ' >> test_subroutine |
---|
70 | echo 'include "wrf_output_2d.h"' >> test_subroutine |
---|
71 | #echo 'include "dimension.h"' >> test_subroutine |
---|
72 | echo ' ' >> test_subroutine |
---|
73 | echo 'INTEGER :: ngrid' >> test_subroutine |
---|
74 | awk '{print "REAL, DIMENSION(ngrid) :: " $NF}' fromregistry2 >> test_subroutine |
---|
75 | echo 'REAL, DIMENSION(ngrid,n2d) :: output_tab2d' >> test_subroutine |
---|
76 | echo ' ' >> test_subroutine |
---|
77 | awk '{print "output_tab2d(:,ind_"$3")="$NF"(:)"}' fromregistry2 >> test_subroutine |
---|
78 | echo ' ' >> test_subroutine |
---|
79 | echo 'END SUBROUTINE fill_save_2d' >> test_subroutine |
---|
80 | mv test_subroutine fill_save_2d.F90 |
---|
81 | #fi |
---|
82 | |
---|
83 | \rm fill_save_3d.F90 2> /dev/null |
---|
84 | #if [ ${yeah3} -ne 0 ] |
---|
85 | #then |
---|
86 | echo 'SUBROUTINE fill_save_3d( &' >> test_subroutine |
---|
87 | awk '{print $NF ",&"}' fromregistry3 >> test_subroutine |
---|
88 | echo 'ngrid,&' >> test_subroutine |
---|
89 | echo 'nlayer,&' >> test_subroutine |
---|
90 | echo 'output_tab3d)' >> test_subroutine |
---|
91 | echo ' ' >> test_subroutine |
---|
92 | echo 'IMPLICIT NONE' >> test_subroutine |
---|
93 | echo ' ' >> test_subroutine |
---|
94 | echo 'include "wrf_output_3d.h"' >> test_subroutine |
---|
95 | #echo 'include "dimension.h"' >> test_subroutine |
---|
96 | echo ' ' >> test_subroutine |
---|
97 | echo 'INTEGER :: ngrid' >> test_subroutine |
---|
98 | echo 'INTEGER :: nlayer' >> test_subroutine |
---|
99 | awk '{print "REAL, DIMENSION(ngrid,nlayer) :: " $NF}' fromregistry3 >> test_subroutine |
---|
100 | echo 'REAL, DIMENSION(ngrid,nlayer,n3d) :: output_tab3d' >> test_subroutine |
---|
101 | echo ' ' >> test_subroutine |
---|
102 | awk '{print "output_tab3d(:,:,ind_"$3")="$NF"(:,:)"}' fromregistry3 >> test_subroutine |
---|
103 | echo ' ' >> test_subroutine |
---|
104 | echo 'END SUBROUTINE fill_save_3d' >> test_subroutine |
---|
105 | mv test_subroutine fill_save_3d.F90 |
---|
106 | #fi |
---|
107 | |
---|
108 | |
---|
109 | # |
---|
110 | # |
---|
111 | # |
---|
112 | \rm fill_save.inc 2> /dev/null |
---|
113 | |
---|
114 | #if [ ${yeah2} -ne 0 ] |
---|
115 | #then |
---|
116 | echo ' CALL fill_save_2d(' >> fill_save.inc |
---|
117 | awk '{print " . "$NF ","}' fromregistry2 >> fill_save.inc |
---|
118 | echo ' . ngrid,' >> fill_save.inc |
---|
119 | echo ' . output_tab2d)' >> fill_save.inc |
---|
120 | #fi |
---|
121 | |
---|
122 | #if [ ${yeah3} -ne 0 ] |
---|
123 | #then |
---|
124 | echo ' CALL fill_save_3d(' >> fill_save.inc |
---|
125 | awk '{print " . "$NF ","}' fromregistry3 >> fill_save.inc |
---|
126 | echo ' . ngrid,' >> fill_save.inc |
---|
127 | echo ' . nlayer,' >> fill_save.inc |
---|
128 | echo ' . output_tab3d)' >> fill_save.inc |
---|
129 | #fi |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | # |
---|
134 | # |
---|
135 | # |
---|
136 | \rm module_lmd_driver_output1.inc 2> /dev/null |
---|
137 | touch module_lmd_driver_output1.inc |
---|
138 | \rm module_lmd_driver_output2.inc 2> /dev/null |
---|
139 | touch module_lmd_driver_output2.inc |
---|
140 | \rm module_lmd_driver_output3.inc 2> /dev/null |
---|
141 | touch module_lmd_driver_output3.inc |
---|
142 | |
---|
143 | echo 'REAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: &' >> module_lmd_driver_output2.inc |
---|
144 | |
---|
145 | if [ ${yeah2} -ne 0 ] |
---|
146 | then |
---|
147 | awk '{print " " $3 ",&"}' fromregistry2 >> module_lmd_driver_output1.inc |
---|
148 | #more module_lmd_driver_output1.inc >> module_lmd_driver_output2.inc |
---|
149 | cat module_lmd_driver_output1.inc >> module_lmd_driver_output2.inc |
---|
150 | awk '{print $3"(i,j) = output_tab2d(subs,ind_"$3")"}' fromregistry2 >> module_lmd_driver_output3.inc |
---|
151 | fi |
---|
152 | |
---|
153 | echo ' PSFC,TSK' >> module_lmd_driver_output2.inc |
---|
154 | echo 'REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(OUT) :: &' >> module_lmd_driver_output2.inc |
---|
155 | |
---|
156 | if [ ${yeah3} -ne 0 ] |
---|
157 | then |
---|
158 | awk '{print " " $3 ",&"}' fromregistry3 >> module_lmd_driver_output1.inc |
---|
159 | awk '{print " " $3 ",&"}' fromregistry3 >> module_lmd_driver_output2.inc |
---|
160 | echo 'DO k = kps,kpe' >> module_lmd_driver_output3.inc |
---|
161 | awk '{print $3"(i,k,j) = output_tab3d(subs,k,ind_"$3")"}' fromregistry3 >> module_lmd_driver_output3.inc |
---|
162 | echo 'ENDDO' >> module_lmd_driver_output3.inc |
---|
163 | fi |
---|
164 | |
---|
165 | echo ' RTHBLTEN,RUBLTEN,RVBLTEN' >> module_lmd_driver_output2.inc |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | # |
---|
170 | # |
---|
171 | # |
---|
172 | \rm module_lmd_driver_output4.inc 2> /dev/null |
---|
173 | touch module_lmd_driver_output4.inc |
---|
174 | awk '{print " & ,"$3"=grid%"$3" &"}' fromregistry2 >> module_lmd_driver_output4.inc |
---|
175 | awk '{print " & ,"$3"=grid%"$3" &"}' fromregistry3 >> module_lmd_driver_output4.inc |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | # |
---|
180 | # |
---|
181 | # |
---|
182 | \rm fromregistry2 |
---|
183 | \rm fromregistry3 |
---|
184 | mv module_lmd_driver_output?.inc ../inc/ |
---|
185 | \rm ../mars_lmd/libf/phymars/fill_save_?d.F90 2> /dev/null |
---|
186 | \rm ../mars_lmd/libf/phymars/wrf_output_?d.h 2> /dev/null |
---|
187 | mv fill_save.inc fill_save_?d.F90 wrf_output_?d.h ../mars_lmd/libf/phymars/ |
---|
188 | |
---|
189 | # |
---|
190 | # |
---|
191 | # |
---|
192 | echo END of AUTOMATIC FILE GENERATION |
---|
193 | echo I guess you modified 'Registry.EM' ... |
---|
194 | echo ... so remove the file 'Registry' and recompile the model |
---|