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