1 | program create_readmeteo |
---|
2 | |
---|
3 | implicit none |
---|
4 | include "netcdf.inc" |
---|
5 | |
---|
6 | !------------------------------------------------------------------------! |
---|
7 | ! create_readmeteo generates the file 'readmeteo.def' ! |
---|
8 | ! ... must be run prior to readmeteo ! |
---|
9 | ! ... the user will be asked a few questions ! |
---|
10 | ! ! |
---|
11 | ! A. Spiga - 01/08/2007 ! |
---|
12 | !------------------------------------------------------------------------! |
---|
13 | |
---|
14 | INTEGER, PARAMETER :: MONTHS_PER_YEAR = 12 |
---|
15 | INTEGER, PARAMETER :: mday(MONTHS_PER_YEAR) & |
---|
16 | = (/61,66,66,65,60,54,50,46,47,47,51,56/) |
---|
17 | |
---|
18 | INTEGER :: start_day,init,i,month,day |
---|
19 | INTEGER :: ierr,nid,nvarid |
---|
20 | INTEGER :: n,start,my,interval_subs,subs |
---|
21 | INTEGER :: start_hour,interval,hour,inc_hour |
---|
22 | INTEGER :: no_please |
---|
23 | INTEGER :: timedim,timelen |
---|
24 | |
---|
25 | REAL, DIMENSION(100) :: param |
---|
26 | REAL, DIMENSION(:), ALLOCATABLE :: time |
---|
27 | |
---|
28 | |
---|
29 | ! |
---|
30 | ! Init |
---|
31 | ! |
---|
32 | interval = 0 |
---|
33 | |
---|
34 | |
---|
35 | ! |
---|
36 | ! Open input NETCDF file |
---|
37 | ! |
---|
38 | write(*,*) "Scanning netcdf file ..." |
---|
39 | ierr=NF_OPEN ("input_diagfi.nc",NF_NOWRITE,nid) |
---|
40 | IF (ierr.NE.NF_NOERR) THEN |
---|
41 | write(*,*)'**** Please create a symbolic link called input_diagfi.nc' |
---|
42 | CALL ABORT |
---|
43 | ENDIF |
---|
44 | |
---|
45 | ierr=NF_INQ_DIMID(nid,"Time",timedim) |
---|
46 | IF (ierr .NE. NF_NOERR) THEN |
---|
47 | ierr=NF_INQ_DIMID(nid,"time",timedim) |
---|
48 | ENDIF |
---|
49 | ierr=NF_INQ_DIMLEN(nid,timedim,timelen) |
---|
50 | |
---|
51 | |
---|
52 | ! |
---|
53 | ! Get starting time |
---|
54 | ! |
---|
55 | ALLOCATE(time(timelen)) |
---|
56 | ierr = NF_INQ_VARID (nid, "Time",nvarid) |
---|
57 | IF (ierr .NE. NF_NOERR) THEN |
---|
58 | ierr = NF_INQ_VARID (nid, "time",nvarid) |
---|
59 | IF (ierr .NE. NF_NOERR) THEN |
---|
60 | PRINT *, "Error: Readmeteo <Time> not found" |
---|
61 | stop |
---|
62 | ENDIF |
---|
63 | ENDIF |
---|
64 | #ifdef NC_DOUBLE |
---|
65 | ierr = NF_GET_VAR_DOUBLE(nid, nvarid, time) |
---|
66 | #else |
---|
67 | ierr = NF_GET_VAR_REAL(nid, nvarid, time) |
---|
68 | #endif |
---|
69 | |
---|
70 | ierr = NF_INQ_VARID (nid,"controle",nvarid) |
---|
71 | IF (ierr .NE. NF_NOERR) THEN |
---|
72 | PRINT *, "Error: Readmeteo <ps> not found" |
---|
73 | stop |
---|
74 | ENDIF |
---|
75 | #ifdef NC_DOUBLE |
---|
76 | ierr = NF_GET_VAR_DOUBLE(nid, nvarid, param) |
---|
77 | #else |
---|
78 | ierr = NF_GET_VAR_REAL(nid, nvarid, param) |
---|
79 | #endif |
---|
80 | |
---|
81 | write(*,*) "Done." |
---|
82 | |
---|
83 | |
---|
84 | ! |
---|
85 | ! fill the include if no info can be found in the diagfi |
---|
86 | ! |
---|
87 | include "fix_no_info.inc" |
---|
88 | |
---|
89 | |
---|
90 | ! beware, param(4) is the day reference of start and startfi |
---|
91 | ! ...have to add time(1) to get the real starting date in diagfi |
---|
92 | start_day=floor(param(4)+time(1)) |
---|
93 | start_hour=nint((param(4)-floor(param(4))+time(1))*24) ! starting hour |
---|
94 | start_hour=MOD(start_hour,24) |
---|
95 | IF (interval .eq. 0) interval=nint(time(1)*24) ! interval between each time subscript |
---|
96 | |
---|
97 | |
---|
98 | PRINT *,'*****************' |
---|
99 | PRINT *,'GCM data file starts at sol ',start_day,'and hour',start_hour |
---|
100 | PRINT *,'GCM data interval is ',interval,'hours' |
---|
101 | |
---|
102 | CALL wrf_day(start_day,month,day) |
---|
103 | |
---|
104 | ! |
---|
105 | ! User defined parameters |
---|
106 | ! |
---|
107 | write(*,*) "This will erase readmeteo.def file" |
---|
108 | write(*,*) " NB: Default mode is to generate " |
---|
109 | write(*,*) " a WPS-compatible file for each timestep " |
---|
110 | write(*,*) " included in the diagfi " |
---|
111 | write(*,*) "Total number of generated files: ",timelen |
---|
112 | write(*,*) "Continue ? 0 if no, 1 if yes, 99 for settings" |
---|
113 | read(*,*) no_please |
---|
114 | if (no_please == 0) stop |
---|
115 | if (no_please == 1) then |
---|
116 | my=2024 |
---|
117 | n=timelen |
---|
118 | start=1 |
---|
119 | interval_subs=1 |
---|
120 | else |
---|
121 | write(*,*) "-- GCM data file information --" |
---|
122 | write(*,*) "Starting Martian year ? ex: 24,25,26..." |
---|
123 | read(*,*) my |
---|
124 | my=2000+my |
---|
125 | write(*,*) "-- WRF data file information --" |
---|
126 | write(*,*) "How many files do you want to create ? at least 2, max is",timelen |
---|
127 | read(*,*) n |
---|
128 | IF (n == timelen) THEN |
---|
129 | start=1 |
---|
130 | interval_subs=1 |
---|
131 | ELSE |
---|
132 | write(*,*) "Time subscript you want to begin with (first is 1) ? max is",timelen-n+1 |
---|
133 | read(*,*) start |
---|
134 | write(*,*) "Time subscript interval you want to get ? no more than",(timelen-start+1)/n |
---|
135 | read(*,*) interval_subs |
---|
136 | END IF |
---|
137 | endif |
---|
138 | |
---|
139 | |
---|
140 | |
---|
141 | ! |
---|
142 | ! Info |
---|
143 | ! |
---|
144 | PRINT *,'-------' |
---|
145 | PRINT *,'run readmeteo with the command line:' |
---|
146 | PRINT *,'readmeteo.exe < readmeteo.def' |
---|
147 | |
---|
148 | |
---|
149 | ! |
---|
150 | ! Generate readmeteo.def |
---|
151 | ! |
---|
152 | OPEN(6,file='readmeteo.def',status='replace',form='formatted') |
---|
153 | ! files |
---|
154 | IF (n < 10) THEN |
---|
155 | write(6,fmt='(I1)') n |
---|
156 | ELSE IF (n < 100) THEN |
---|
157 | write(6,fmt='(I2)') n |
---|
158 | ELSE |
---|
159 | write(6,fmt='(I3)') n |
---|
160 | END IF |
---|
161 | ! subscript in GCM data file |
---|
162 | DO i=1,n |
---|
163 | subs=start+(i-1)*interval_subs |
---|
164 | IF (subs < 10) THEN |
---|
165 | write(6,fmt='(I1)') subs |
---|
166 | ELSE IF (subs < 100) THEN |
---|
167 | write(6,fmt='(I2)') subs |
---|
168 | ELSE |
---|
169 | write(6,fmt='(I3)') subs |
---|
170 | END IF |
---|
171 | END DO |
---|
172 | ! WRF time reference |
---|
173 | hour=start_hour+(start-1)*interval |
---|
174 | inc_hour=interval*interval_subs |
---|
175 | IF (hour >= 24) day=day+INT(hour/24) |
---|
176 | hour=MOD(hour,24) |
---|
177 | IF (day > mday(month)) THEN |
---|
178 | day=day-mday(month) |
---|
179 | month=month+1 |
---|
180 | END IF |
---|
181 | IF (month > MONTHS_PER_YEAR) THEN |
---|
182 | my=my+1 |
---|
183 | month=1 |
---|
184 | END IF |
---|
185 | DO i=1,n |
---|
186 | write(6,fmt='(I4)') my |
---|
187 | IF (month < 10) THEN |
---|
188 | write(6,fmt='(I1,I1)') 0,month |
---|
189 | ELSE |
---|
190 | write(6,fmt='(I2)') month |
---|
191 | END IF |
---|
192 | IF (day < 10) THEN |
---|
193 | write(6,fmt='(I1,I1)') 0,day |
---|
194 | ELSE |
---|
195 | write(6,fmt='(I2)') day |
---|
196 | END IF |
---|
197 | IF (hour < 10) THEN |
---|
198 | write(6,fmt='(I1,I1)') 0,hour |
---|
199 | ELSE |
---|
200 | write(6,fmt='(I2)') hour |
---|
201 | END IF |
---|
202 | write(6,fmt='(A1)') 'y' |
---|
203 | IF (hour+inc_hour >= 24) day=day+INT((hour+inc_hour)/24) |
---|
204 | hour=MOD(hour+inc_hour,24) |
---|
205 | IF (day > mday(month)) THEN |
---|
206 | day=day-mday(month) |
---|
207 | month=month+1 |
---|
208 | END IF |
---|
209 | IF (month > MONTHS_PER_YEAR) THEN |
---|
210 | my=my+1 |
---|
211 | month=1 |
---|
212 | END IF |
---|
213 | END DO |
---|
214 | close(6) |
---|
215 | |
---|
216 | END |
---|
217 | |
---|
218 | |
---|
219 | !-------------------------------------------------- |
---|
220 | !-------------------------------------------------- |
---|
221 | |
---|
222 | SUBROUTINE wrf_day(gcm_day,wrf_month,day) |
---|
223 | |
---|
224 | IMPLICIT NONE |
---|
225 | |
---|
226 | INTEGER, INTENT(INOUT) :: gcm_day |
---|
227 | INTEGER, INTENT(OUT) :: wrf_month,day |
---|
228 | |
---|
229 | INTEGER :: init,i |
---|
230 | INTEGER, PARAMETER :: MONTHS_PER_YEAR = 12 |
---|
231 | INTEGER, PARAMETER :: mday(MONTHS_PER_YEAR) & |
---|
232 | = (/61,66,66,65,60,54,50,46,47,47,51,56/) |
---|
233 | |
---|
234 | ! |
---|
235 | ! Find WRF month and day |
---|
236 | ! |
---|
237 | |
---|
238 | IF (gcm_day >= 669) THEN !! gcm_day commence au jour 0 |
---|
239 | PRINT *,'out of bounds ! martian year is 669 sols !' |
---|
240 | gcm_day=MOD(gcm_day,669) |
---|
241 | !STOP |
---|
242 | ENDIF |
---|
243 | |
---|
244 | |
---|
245 | |
---|
246 | init=gcm_day+1 !!+1 sinon on decale tout |
---|
247 | DO i=1,MONTHS_PER_YEAR |
---|
248 | wrf_month=i |
---|
249 | init=init-mday(i) |
---|
250 | IF (init <= 0) EXIT |
---|
251 | END DO |
---|
252 | |
---|
253 | PRINT *,'corresponding WRF month is ',wrf_month |
---|
254 | day=init+mday(wrf_month) |
---|
255 | PRINT *,'corresponding WRF day is ',day |
---|
256 | PRINT *,'*****************' |
---|
257 | |
---|
258 | END |
---|