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

Last change on this file was 1732, checked in by aslmd, 7 years ago

MESOSCALE. restored PREP_MARS to r1723 before readmeteo.F90 and create_readmeteo.F90 were deleted -- and history lost

File size: 6.6 KB
RevLine 
[11]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
[452]158ELSE IF (n < 1000) THEN
159        write(6,fmt='(I3)') n
[11]160ELSE
[452]161        write(6,fmt='(I4)') n       
[11]162END IF
163! subscript in GCM data file
164DO i=1,n
165        subs=start+(i-1)*interval_subs
166        IF (subs < 10) THEN
167                write(6,fmt='(I1)') subs
168        ELSE IF (subs < 100) THEN
169                write(6,fmt='(I2)') subs
[452]170        ELSE IF (subs < 1000) THEN
171                write(6,fmt='(I3)') subs
[11]172        ELSE
[452]173                write(6,fmt='(I4)') subs   
[11]174        END IF       
175END DO
176! WRF time reference
177hour=start_hour+(start-1)*interval
178inc_hour=interval*interval_subs
179IF (hour >= 24) day=day+INT(hour/24)
180hour=MOD(hour,24)
181IF (day > mday(month)) THEN
182      day=day-mday(month)
183      month=month+1
184END IF
185IF (month > MONTHS_PER_YEAR) THEN
186      my=my+1
187      month=1
188END IF
189DO i=1,n
190        write(6,fmt='(I4)') my
191        IF (month < 10) THEN
192                write(6,fmt='(I1,I1)') 0,month
193        ELSE
194                write(6,fmt='(I2)') month
195        END IF 
196        IF (day < 10) THEN
197                write(6,fmt='(I1,I1)') 0,day
198        ELSE
199                write(6,fmt='(I2)') day
200        END IF
201        IF (hour < 10) THEN
202                write(6,fmt='(I1,I1)') 0,hour
203        ELSE
204                write(6,fmt='(I2)') hour
205        END IF
206        write(6,fmt='(A1)') 'y'
207IF (hour+inc_hour >= 24) day=day+INT((hour+inc_hour)/24)
208hour=MOD(hour+inc_hour,24)
209IF (day > mday(month)) THEN
210        day=day-mday(month)
211        month=month+1
212END IF       
213IF (month > MONTHS_PER_YEAR) THEN
214        my=my+1
215        month=1
216END IF       
217END DO
218close(6)
219
220END
221
222
223!--------------------------------------------------
224!--------------------------------------------------
225
226SUBROUTINE wrf_day(gcm_day,wrf_month,day)
227
228IMPLICIT NONE
229
230INTEGER, INTENT(INOUT) :: gcm_day
231INTEGER, INTENT(OUT) :: wrf_month,day
232
233INTEGER :: init,i
234INTEGER, PARAMETER :: MONTHS_PER_YEAR = 12
235INTEGER, PARAMETER :: mday(MONTHS_PER_YEAR)   &
236           = (/61,66,66,65,60,54,50,46,47,47,51,56/)
237
238!
239! Find WRF month and day
240!
241
242IF (gcm_day >= 669) THEN    !! gcm_day commence au jour 0
243        PRINT *,'out of bounds ! martian year is 669 sols !'
244        gcm_day=MOD(gcm_day,669)
245        !STOP
246ENDIF
247
248
249
250init=gcm_day+1    !!+1 sinon on decale tout
251DO i=1,MONTHS_PER_YEAR
252        wrf_month=i
253        init=init-mday(i)
254        IF (init <= 0) EXIT
255END DO
256
257PRINT *,'corresponding WRF month is ',wrf_month
258day=init+mday(wrf_month)
259PRINT *,'corresponding WRF day is ',day
260PRINT *,'*****************'
261
262END
Note: See TracBrowser for help on using the repository browser.