[11] | 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 |
---|
[452] | 158 | ELSE IF (n < 1000) THEN |
---|
| 159 | write(6,fmt='(I3)') n |
---|
[11] | 160 | ELSE |
---|
[452] | 161 | write(6,fmt='(I4)') n |
---|
[11] | 162 | END IF |
---|
| 163 | ! subscript in GCM data file |
---|
| 164 | DO 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 |
---|
| 175 | END DO |
---|
| 176 | ! WRF time reference |
---|
| 177 | hour=start_hour+(start-1)*interval |
---|
| 178 | inc_hour=interval*interval_subs |
---|
| 179 | IF (hour >= 24) day=day+INT(hour/24) |
---|
| 180 | hour=MOD(hour,24) |
---|
| 181 | IF (day > mday(month)) THEN |
---|
| 182 | day=day-mday(month) |
---|
| 183 | month=month+1 |
---|
| 184 | END IF |
---|
| 185 | IF (month > MONTHS_PER_YEAR) THEN |
---|
| 186 | my=my+1 |
---|
| 187 | month=1 |
---|
| 188 | END IF |
---|
| 189 | DO 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' |
---|
| 207 | IF (hour+inc_hour >= 24) day=day+INT((hour+inc_hour)/24) |
---|
| 208 | hour=MOD(hour+inc_hour,24) |
---|
| 209 | IF (day > mday(month)) THEN |
---|
| 210 | day=day-mday(month) |
---|
| 211 | month=month+1 |
---|
| 212 | END IF |
---|
| 213 | IF (month > MONTHS_PER_YEAR) THEN |
---|
| 214 | my=my+1 |
---|
| 215 | month=1 |
---|
| 216 | END IF |
---|
| 217 | END DO |
---|
| 218 | close(6) |
---|
| 219 | |
---|
| 220 | END |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | !-------------------------------------------------- |
---|
| 224 | !-------------------------------------------------- |
---|
| 225 | |
---|
| 226 | SUBROUTINE wrf_day(gcm_day,wrf_month,day) |
---|
| 227 | |
---|
| 228 | IMPLICIT NONE |
---|
| 229 | |
---|
| 230 | INTEGER, INTENT(INOUT) :: gcm_day |
---|
| 231 | INTEGER, INTENT(OUT) :: wrf_month,day |
---|
| 232 | |
---|
| 233 | INTEGER :: init,i |
---|
| 234 | INTEGER, PARAMETER :: MONTHS_PER_YEAR = 12 |
---|
| 235 | INTEGER, 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 | |
---|
| 242 | IF (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 |
---|
| 246 | ENDIF |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | init=gcm_day+1 !!+1 sinon on decale tout |
---|
| 251 | DO i=1,MONTHS_PER_YEAR |
---|
| 252 | wrf_month=i |
---|
| 253 | init=init-mday(i) |
---|
| 254 | IF (init <= 0) EXIT |
---|
| 255 | END DO |
---|
| 256 | |
---|
| 257 | PRINT *,'corresponding WRF month is ',wrf_month |
---|
| 258 | day=init+mday(wrf_month) |
---|
| 259 | PRINT *,'corresponding WRF day is ',day |
---|
| 260 | PRINT *,'*****************' |
---|
| 261 | |
---|
| 262 | END |
---|