source: trunk/MESOSCALE/LMD_MM_MARS/SRC/PREP_MARS/create_readmeteo.F90 @ 134

Last change on this file since 134 was 11, checked in by aslmd, 14 years ago

spiga@svn-planeto:ajoute le modele meso-echelle martien

File size: 6.5 KB
Line 
1program create_readmeteo
2
3implicit none
4include "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
14INTEGER, PARAMETER :: MONTHS_PER_YEAR = 12
15INTEGER, PARAMETER :: mday(MONTHS_PER_YEAR)   &
16           = (/61,66,66,65,60,54,50,46,47,47,51,56/)
17
18INTEGER :: start_day,init,i,month,day
19INTEGER :: ierr,nid,nvarid
20INTEGER :: n,start,my,interval_subs,subs
21INTEGER :: start_hour,interval,hour,inc_hour
22INTEGER :: no_please
23INTEGER :: timedim,timelen
24
25REAL, DIMENSION(100) :: param
26REAL, DIMENSION(:), ALLOCATABLE :: time
27
28
29!
30! Init
31!
32interval = 0
33
34
35!
36! Open input NETCDF file
37!
38write(*,*) "Scanning netcdf file ..."
39ierr=NF_OPEN ("input_diagfi.nc",NF_NOWRITE,nid)
40IF (ierr.NE.NF_NOERR) THEN
41      write(*,*)'**** Please create a symbolic link called input_diagfi.nc'
42      CALL ABORT
43ENDIF
44
45ierr=NF_INQ_DIMID(nid,"Time",timedim)
46IF (ierr .NE. NF_NOERR) THEN
47    ierr=NF_INQ_DIMID(nid,"time",timedim)
48ENDIF
49ierr=NF_INQ_DIMLEN(nid,timedim,timelen)
50
51
52!
53! Get starting time
54!
55ALLOCATE(time(timelen))
56ierr = NF_INQ_VARID (nid, "Time",nvarid)
57IF (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
63ENDIF
64#ifdef NC_DOUBLE
65ierr = NF_GET_VAR_DOUBLE(nid, nvarid, time)
66#else
67ierr = NF_GET_VAR_REAL(nid, nvarid, time)
68#endif
69
70ierr = NF_INQ_VARID (nid,"controle",nvarid)
71IF (ierr .NE. NF_NOERR) THEN
72        PRINT *, "Error: Readmeteo <ps> not found"
73        stop
74ENDIF
75#ifdef NC_DOUBLE
76ierr = NF_GET_VAR_DOUBLE(nid, nvarid, param)
77#else
78ierr = NF_GET_VAR_REAL(nid, nvarid, param)
79#endif
80
81write(*,*) "Done."
82
83
84!
85! fill the include if no info can be found in the diagfi
86!
87include "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
92start_day=floor(param(4)+time(1))               
93start_hour=nint((param(4)-floor(param(4))+time(1))*24)  ! starting hour
94start_hour=MOD(start_hour,24)   
95IF (interval .eq. 0) interval=nint(time(1)*24)   ! interval between each time subscript
96
97
98PRINT *,'*****************'
99PRINT *,'GCM data file starts at sol ',start_day,'and hour',start_hour
100PRINT *,'GCM data interval is ',interval,'hours'
101
102CALL wrf_day(start_day,month,day)
103
104!
105! User defined parameters
106!
107write(*,*) "This will erase readmeteo.def file"
108write(*,*) "  NB: Default mode is to generate "
109write(*,*) "      a WPS-compatible file for each timestep "
110write(*,*) "      included in the diagfi "
111write(*,*) "Total number of generated files: ",timelen
112write(*,*) "Continue ? 0 if no, 1 if yes, 99 for settings"
113read(*,*) no_please
114if (no_please == 0) stop
115if (no_please == 1) then
116        my=2024
117        n=timelen
118        start=1
119        interval_subs=1
120else
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
137endif
138
139
140
141!
142! Info
143!
144PRINT *,'-------'
145PRINT *,'run readmeteo with the command line:'
146PRINT *,'readmeteo.exe < readmeteo.def'
147
148
149!
150! Generate readmeteo.def
151!
152OPEN(6,file='readmeteo.def',status='replace',form='formatted')
153! files
154IF (n < 10) THEN
155        write(6,fmt='(I1)') n
156ELSE IF (n < 100) THEN
157        write(6,fmt='(I2)') n
158ELSE
159        write(6,fmt='(I3)') n       
160END IF
161! subscript in GCM data file
162DO 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       
171END DO
172! WRF time reference
173hour=start_hour+(start-1)*interval
174inc_hour=interval*interval_subs
175IF (hour >= 24) day=day+INT(hour/24)
176hour=MOD(hour,24)
177IF (day > mday(month)) THEN
178      day=day-mday(month)
179      month=month+1
180END IF
181IF (month > MONTHS_PER_YEAR) THEN
182      my=my+1
183      month=1
184END IF
185DO 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'
203IF (hour+inc_hour >= 24) day=day+INT((hour+inc_hour)/24)
204hour=MOD(hour+inc_hour,24)
205IF (day > mday(month)) THEN
206        day=day-mday(month)
207        month=month+1
208END IF       
209IF (month > MONTHS_PER_YEAR) THEN
210        my=my+1
211        month=1
212END IF       
213END DO
214close(6)
215
216END
217
218
219!--------------------------------------------------
220!--------------------------------------------------
221
222SUBROUTINE wrf_day(gcm_day,wrf_month,day)
223
224IMPLICIT NONE
225
226INTEGER, INTENT(INOUT) :: gcm_day
227INTEGER, INTENT(OUT) :: wrf_month,day
228
229INTEGER :: init,i
230INTEGER, PARAMETER :: MONTHS_PER_YEAR = 12
231INTEGER, 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
238IF (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
242ENDIF
243
244
245
246init=gcm_day+1    !!+1 sinon on decale tout
247DO i=1,MONTHS_PER_YEAR
248        wrf_month=i
249        init=init-mday(i)
250        IF (init <= 0) EXIT
251END DO
252
253PRINT *,'corresponding WRF month is ',wrf_month
254day=init+mday(wrf_month)
255PRINT *,'corresponding WRF day is ',day
256PRINT *,'*****************'
257
258END
Note: See TracBrowser for help on using the repository browser.