[816] | 1 | program stability |
---|
| 2 | |
---|
| 3 | ! SL 12/2009: |
---|
| 4 | ! This program reads 4D (lon-lat-alt-time) fields recast in log P coordinates |
---|
| 5 | ! |
---|
| 6 | ! it computes: |
---|
| 7 | ! stab -- 4D -- stability |
---|
| 8 | ! Ri -- 4D -- Richardson number |
---|
| 9 | ! deqc -- 3D -- distance to cyclostrophic equilibrium |
---|
| 10 | ! |
---|
| 11 | ! Minimal requirements and dependencies: |
---|
| 12 | ! The dataset must include the following data: |
---|
| 13 | ! - surface pressure and surface geopotential |
---|
| 14 | ! - atmospheric temperature |
---|
| 15 | ! - zonal and meridional winds |
---|
| 16 | ! - altitude above areoid |
---|
| 17 | |
---|
| 18 | implicit none |
---|
| 19 | |
---|
| 20 | include "netcdf.inc" ! NetCDF definitions |
---|
| 21 | |
---|
| 22 | character (len=128) :: infile ! input file name (name_P.nc) |
---|
| 23 | character (len=128) :: outfile ! output file name |
---|
| 24 | |
---|
| 25 | character (len=64) :: text ! to store some text |
---|
| 26 | integer infid ! NetCDF input file ID |
---|
| 27 | integer outfid ! NetCDF output file ID |
---|
| 28 | integer lon_dimid,lat_dimid,alt_dimid,time_dimid ! NetCDF dimension IDs |
---|
| 29 | integer lon_varid,lat_varid,alt_varid,time_varid |
---|
| 30 | integer,dimension(3) :: datashape3d ! shape of 3D datasets |
---|
| 31 | integer,dimension(4) :: datashape4d ! shape of 4D datasets |
---|
| 32 | |
---|
[1454] | 33 | real :: miss_val ! special "missing value" to specify missing data |
---|
| 34 | real,parameter :: miss_val_def=-9.99e+33 ! default value for "missing value" |
---|
[816] | 35 | real :: pi |
---|
| 36 | real,dimension(:),allocatable :: lon ! longitude |
---|
| 37 | integer lonlength ! # of grid points along longitude |
---|
| 38 | real,dimension(:),allocatable :: lat ! latitude |
---|
[1454] | 39 | real,dimension(:),allocatable :: coslat ! cos of latitude |
---|
[816] | 40 | integer latlength ! # of grid points along latitude |
---|
| 41 | real,dimension(:),allocatable :: plev ! Pressure levels (Pa) |
---|
| 42 | integer altlength ! # of grid point along altitude (of input datasets) |
---|
| 43 | real,dimension(:),allocatable :: time ! time |
---|
| 44 | integer timelength ! # of points along time |
---|
| 45 | real,dimension(:,:,:),allocatable :: ps ! surface pressure |
---|
| 46 | real,dimension(:,:,:,:),allocatable :: temp ! atmospheric temperature |
---|
| 47 | real,dimension(:,:,:,:),allocatable :: vitu ! zonal wind (in m/s) |
---|
| 48 | real,dimension(:,:,:,:),allocatable :: vitv ! meridional wind (in m/s) |
---|
| 49 | real,dimension(:,:,:,:),allocatable :: za ! above areoid levels (m) |
---|
| 50 | |
---|
| 51 | !!! output variables |
---|
| 52 | real,dimension(:,:,:,:),allocatable :: stab ! stability (K/km) |
---|
| 53 | real,dimension(:,:,:,:),allocatable :: Ri ! Richardson number |
---|
| 54 | real,dimension(:,:,:),allocatable :: deqc ! distance to cyclostrophic equilibrium |
---|
| 55 | |
---|
| 56 | ! variables prepared for computation (4D) |
---|
| 57 | real,dimension(:,:,:,:),allocatable :: rayon ! distance to center (m) |
---|
| 58 | real,dimension(:,:,:,:),allocatable :: grav ! gravity field (m s-2) |
---|
| 59 | real,dimension(:,:,:,:),allocatable :: dmass ! mass in cell (kg) |
---|
| 60 | |
---|
| 61 | ! variables prepared for computation inside timeloop |
---|
| 62 | real,dimension(:,:,:),allocatable :: t3d ! temp |
---|
| 63 | real,dimension(:,:,:),allocatable :: u3d ! zonal wind |
---|
| 64 | real,dimension(:,:,:),allocatable :: v3d ! merid wind |
---|
| 65 | ! variables obtained from computation inside timeloop |
---|
| 66 | real,dimension(:,:,:),allocatable :: stab3d ! stability (K/km) |
---|
| 67 | real,dimension(:,:,:),allocatable :: Ri3d ! Richardson number |
---|
| 68 | real,dimension(:,:),allocatable :: deqc2d ! distance to cyclostrophic equilibrium |
---|
| 69 | |
---|
| 70 | real,dimension(:,:),allocatable :: t2d ! temp |
---|
| 71 | real,dimension(:,:),allocatable :: u2d ! zonal wind |
---|
| 72 | real,dimension(:,:),allocatable :: v2d ! merid wind |
---|
| 73 | real,dimension(:,:),allocatable :: dtsdp ! d(temp)/d(plev) |
---|
| 74 | real,dimension(:,:),allocatable :: dusdp ! du/d(plev) |
---|
| 75 | real,dimension(:,:),allocatable :: dvsdp ! dv/d(plev) |
---|
| 76 | |
---|
| 77 | integer ierr,ierr1,ierr2 ! NetCDF routines return codes |
---|
| 78 | integer i,j,ilon,ilat,ilev,itim ! for loops |
---|
| 79 | logical :: lmdflag |
---|
| 80 | |
---|
| 81 | real :: deltalat,deltalon ! lat and lon intervals in radians |
---|
| 82 | real :: fac1,ecden,ecnum ! for cyclo eq. |
---|
| 83 | |
---|
| 84 | real :: cpdet |
---|
| 85 | |
---|
| 86 | include "planet.h" |
---|
| 87 | |
---|
| 88 | !=============================================================================== |
---|
| 89 | ! 1. Input parameters |
---|
| 90 | !=============================================================================== |
---|
| 91 | |
---|
| 92 | pi = 2.*asin(1.) |
---|
[1454] | 93 | miss_val = miss_val_def |
---|
[816] | 94 | |
---|
| 95 | write(*,*) "" |
---|
| 96 | write(*,*) "You are working on the atmosphere of ",planet |
---|
| 97 | |
---|
| 98 | !=============================================================================== |
---|
| 99 | ! 1.1 Input file |
---|
| 100 | !=============================================================================== |
---|
| 101 | |
---|
| 102 | write(*,*) "" |
---|
| 103 | write(*,*) "Program valid for files with pressure axis (*_P.nc)" |
---|
| 104 | write(*,*) "Enter input file name:" |
---|
| 105 | |
---|
| 106 | read(*,'(a128)') infile |
---|
| 107 | write(*,*) "" |
---|
| 108 | |
---|
| 109 | ! open input file |
---|
| 110 | |
---|
| 111 | ierr = NF_OPEN(infile,NF_NOWRITE,infid) |
---|
| 112 | if (ierr.ne.NF_NOERR) then |
---|
| 113 | write(*,*) 'ERROR: Pb opening file ',trim(infile) |
---|
| 114 | stop "" |
---|
| 115 | endif |
---|
| 116 | |
---|
| 117 | !=============================================================================== |
---|
| 118 | ! 1.2 Get grids in lon,lat,alt(pressure),time |
---|
| 119 | !=============================================================================== |
---|
| 120 | |
---|
| 121 | call get_iddim(infid,lat_varid,latlength,lon_varid,lonlength,& |
---|
| 122 | alt_varid,altlength,time_varid,timelength,lmdflag ) |
---|
| 123 | |
---|
| 124 | allocate(lon(lonlength)) |
---|
| 125 | ierr=NF_GET_VAR_REAL(infid,lon_varid,lon) |
---|
| 126 | if (ierr.ne.NF_NOERR) stop "Error: Failed reading longitude" |
---|
| 127 | |
---|
| 128 | allocate(lat(latlength)) |
---|
| 129 | ierr=NF_GET_VAR_REAL(infid,lat_varid,lat) |
---|
| 130 | if (ierr.ne.NF_NOERR) stop "Error: Failed reading lat" |
---|
| 131 | |
---|
[1454] | 132 | allocate(coslat(latlength)) |
---|
| 133 | ! Beware of rounding problems at poles... |
---|
| 134 | coslat(:) = max(0.,cos(lat(:)*pi/180.)) |
---|
[816] | 135 | |
---|
| 136 | ! Lat, lon pressure intervals |
---|
[1454] | 137 | deltalat = abs(lat(2)-lat(1))*pi/180. |
---|
[816] | 138 | deltalon = abs(lon(2)-lon(1))*pi/180. |
---|
| 139 | |
---|
| 140 | allocate(plev(altlength)) |
---|
| 141 | ierr=NF_GET_VAR_REAL(infid,alt_varid,plev) |
---|
| 142 | if (ierr.ne.NF_NOERR) stop "Error: Failed reading altitude (ie pressure levels)" |
---|
| 143 | |
---|
| 144 | allocate(time(timelength)) |
---|
| 145 | ierr=NF_GET_VAR_REAL(infid,time_varid,time) |
---|
| 146 | if (ierr.ne.NF_NOERR) stop "Error: Failed reading time" |
---|
| 147 | |
---|
| 148 | !=============================================================================== |
---|
| 149 | ! 1.3 Get output file name |
---|
| 150 | !=============================================================================== |
---|
| 151 | write(*,*) "" |
---|
| 152 | !write(*,*) "Enter output file name" |
---|
| 153 | !read(*,*) outfile |
---|
| 154 | outfile=infile(1:len_trim(infile)-3)//"_STA.nc" |
---|
| 155 | write(*,*) "Output file name is: "//trim(outfile) |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | !=============================================================================== |
---|
| 160 | ! 2.1 Store needed fields |
---|
| 161 | !=============================================================================== |
---|
| 162 | |
---|
| 163 | !=============================================================================== |
---|
| 164 | ! 2.1.1 Surface pressure |
---|
| 165 | !=============================================================================== |
---|
| 166 | allocate(ps(lonlength,latlength,timelength)) |
---|
| 167 | |
---|
| 168 | text="ps" |
---|
| 169 | call get_var3d(infid,lonlength,latlength,timelength,text,ps,ierr1,ierr2) |
---|
| 170 | if (ierr1.ne.NF_NOERR) then |
---|
| 171 | write(*,*) " looking for psol instead... " |
---|
| 172 | text="psol" |
---|
| 173 | call get_var3d(infid,lonlength,latlength,timelength,text,ps,ierr1,ierr2) |
---|
| 174 | if (ierr1.ne.NF_NOERR) stop "Error: Failed to get psol ID" |
---|
| 175 | endif |
---|
| 176 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading surface pressure" |
---|
| 177 | |
---|
| 178 | !=============================================================================== |
---|
| 179 | ! 2.1.2 Atmospheric temperature |
---|
| 180 | !=============================================================================== |
---|
| 181 | allocate(temp(lonlength,latlength,altlength,timelength)) |
---|
| 182 | |
---|
| 183 | text="temp" |
---|
[1454] | 184 | call get_var4d(infid,lonlength,latlength,altlength,timelength,text,temp,miss_val,ierr1,ierr2) |
---|
[816] | 185 | if (ierr1.ne.NF_NOERR) then |
---|
| 186 | write(*,*) " looking for t instead... " |
---|
| 187 | text="t" |
---|
[1454] | 188 | call get_var4d(infid,lonlength,latlength,altlength,timelength,text,temp,miss_val,ierr1,ierr2) |
---|
[816] | 189 | if (ierr1.ne.NF_NOERR) stop "Error: Failed to get temperature ID" |
---|
| 190 | endif |
---|
| 191 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading temperature" |
---|
| 192 | |
---|
| 193 | !=============================================================================== |
---|
| 194 | ! 2.1.3 Winds |
---|
| 195 | !=============================================================================== |
---|
| 196 | allocate(vitu(lonlength,latlength,altlength,timelength)) |
---|
| 197 | allocate(vitv(lonlength,latlength,altlength,timelength)) |
---|
| 198 | |
---|
| 199 | ! zonal wind vitu (in m/s) |
---|
| 200 | text="vitu" |
---|
[1454] | 201 | call get_var4d(infid,lonlength,latlength,altlength,timelength,text,vitu,miss_val,ierr1,ierr2) |
---|
[816] | 202 | if (ierr1.ne.NF_NOERR) stop "Error: Failed to get vitu ID" |
---|
| 203 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading zonal wind" |
---|
| 204 | |
---|
| 205 | ! meridional wind vitv (in m/s) |
---|
| 206 | text="vitv" |
---|
[1454] | 207 | call get_var4d(infid,lonlength,latlength,altlength,timelength,text,vitv,miss_val,ierr1,ierr2) |
---|
[816] | 208 | if (ierr1.ne.NF_NOERR) stop "Error: Failed to get vitv ID" |
---|
| 209 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading meridional wind" |
---|
| 210 | |
---|
| 211 | !=============================================================================== |
---|
| 212 | ! 2.1.4 Altitude above areoide |
---|
| 213 | !=============================================================================== |
---|
| 214 | ! Only needed if g(z) on Titan... |
---|
| 215 | |
---|
| 216 | ! allocate(za(lonlength,latlength,altlength,timelength)) |
---|
| 217 | |
---|
| 218 | ! text="zareoid" |
---|
[1454] | 219 | ! call get_var4d(infid,lonlength,latlength,altlength,timelength,text,za,miss_val,ierr1,ierr2) |
---|
[816] | 220 | ! if (ierr1.ne.NF_NOERR) stop "Error: Failed to get za ID" |
---|
| 221 | ! if (ierr2.ne.NF_NOERR) stop "Error: Failed reading zareoid" |
---|
| 222 | |
---|
| 223 | !=============================================================================== |
---|
| 224 | !!! Allocations before timeloop |
---|
| 225 | !=============================================================================== |
---|
| 226 | |
---|
| 227 | ! latlength correspond a jjm+1 |
---|
| 228 | ! mais lonlength correspond a iim |
---|
| 229 | ! pour boucler en longitude, on a besoin du point iim+1 (= 1) |
---|
| 230 | |
---|
| 231 | allocate(rayon(lonlength+1,latlength,altlength,timelength)) |
---|
| 232 | allocate(grav(lonlength+1,latlength,altlength,timelength)) |
---|
| 233 | allocate(dmass(lonlength+1,latlength,altlength,timelength)) |
---|
| 234 | |
---|
| 235 | allocate(t3d(lonlength+1,latlength,altlength)) |
---|
| 236 | allocate(u3d(lonlength+1,latlength,altlength)) |
---|
| 237 | allocate(v3d(lonlength+1,latlength,altlength)) |
---|
| 238 | |
---|
| 239 | allocate(t2d(latlength,altlength)) |
---|
| 240 | allocate(u2d(latlength,altlength)) |
---|
| 241 | allocate(v2d(latlength,altlength)) |
---|
| 242 | allocate(dtsdp(latlength,altlength)) |
---|
| 243 | allocate(dusdp(latlength,altlength)) |
---|
| 244 | allocate(dvsdp(latlength,altlength)) |
---|
| 245 | |
---|
| 246 | allocate(stab(lonlength,latlength,altlength,timelength)) |
---|
| 247 | allocate(Ri(lonlength,latlength,altlength,timelength)) |
---|
| 248 | allocate(deqc(latlength,altlength,timelength)) |
---|
| 249 | |
---|
| 250 | allocate(stab3d(lonlength+1,latlength,altlength)) |
---|
| 251 | allocate(Ri3d(lonlength+1,latlength,altlength)) |
---|
| 252 | allocate(deqc2d(latlength,altlength)) |
---|
| 253 | |
---|
| 254 | !=============================================================================== |
---|
| 255 | ! 2.2.2 Mass in cells |
---|
| 256 | !=============================================================================== |
---|
| 257 | |
---|
| 258 | do itim=1,timelength |
---|
| 259 | do ilon=1,lonlength |
---|
| 260 | do ilat=1,latlength |
---|
| 261 | do ilev=1,altlength |
---|
| 262 | ! Need to be consistent with GCM computations |
---|
| 263 | ! if (za(ilon,ilat,ilev,itim).ne.miss_val) then |
---|
| 264 | rayon(ilon,ilat,ilev,itim) = a0 |
---|
| 265 | ! rayon(ilon,ilat,ilev,itim) = za(ilon,ilat,ilev,itim) + a0 |
---|
| 266 | grav(ilon,ilat,ilev,itim) = g0*a0*a0 & |
---|
| 267 | /(rayon(ilon,ilat,ilev,itim)*rayon(ilon,ilat,ilev,itim)) |
---|
| 268 | ! else |
---|
| 269 | ! rayon(ilon,ilat,ilev,itim) = miss_val |
---|
| 270 | ! grav(ilon,ilat,ilev,itim) = miss_val |
---|
| 271 | ! endif |
---|
| 272 | enddo |
---|
| 273 | enddo |
---|
| 274 | enddo |
---|
| 275 | enddo ! timelength |
---|
| 276 | |
---|
| 277 | rayon(lonlength+1,:,:,:) = rayon(1,:,:,:) |
---|
| 278 | grav(lonlength+1,:,:,:) = grav(1,:,:,:) |
---|
| 279 | |
---|
[1454] | 280 | call cellmass(infid,latlength,lonlength+1,altlength,timelength,lmdflag, & |
---|
| 281 | miss_val,deltalon,deltalat,coslat,plev,ps,grav,rayon, & |
---|
[816] | 282 | dmass ) |
---|
| 283 | |
---|
| 284 | !=============================================================================== |
---|
| 285 | !!! GLOBAL TIME LOOP !!! |
---|
| 286 | !=============================================================================== |
---|
| 287 | do itim=1,timelength |
---|
| 288 | |
---|
| 289 | !=============================================================================== |
---|
| 290 | ! 2.2 Computations |
---|
| 291 | !=============================================================================== |
---|
| 292 | |
---|
| 293 | !=============================================================================== |
---|
| 294 | ! 2.2.3 Init of 3D variables |
---|
| 295 | !=============================================================================== |
---|
| 296 | |
---|
| 297 | do ilon=1,lonlength |
---|
| 298 | do ilat=1,latlength |
---|
| 299 | do ilev=1,altlength |
---|
| 300 | t3d(ilon,ilat,ilev) = temp(ilon,ilat,ilev,itim) |
---|
| 301 | u3d(ilon,ilat,ilev) = vitu(ilon,ilat,ilev,itim) |
---|
| 302 | v3d(ilon,ilat,ilev) = vitv(ilon,ilat,ilev,itim) |
---|
| 303 | enddo |
---|
| 304 | enddo |
---|
| 305 | enddo |
---|
| 306 | |
---|
| 307 | t3d(lonlength+1,:,:) = t3d(1,:,:) |
---|
| 308 | u3d(lonlength+1,:,:) = u3d(1,:,:) |
---|
| 309 | v3d(lonlength+1,:,:) = v3d(1,:,:) |
---|
| 310 | |
---|
| 311 | !=============================================================================== |
---|
| 312 | ! 2.2.4 Stability |
---|
| 313 | !=============================================================================== |
---|
| 314 | |
---|
| 315 | do ilon=1,lonlength+1 |
---|
| 316 | t2d(:,:) = t3d(ilon,:,:) |
---|
| 317 | call dx_dp(latlength,altlength,miss_val,plev,t2d,dtsdp) |
---|
| 318 | do ilat=1,latlength |
---|
| 319 | do ilev=1,altlength |
---|
| 320 | if ((grav(ilon,ilat,ilev,itim).ne.miss_val).and. & |
---|
| 321 | ( t3d(ilon,ilat,ilev).ne.miss_val) ) then |
---|
| 322 | stab3d(ilon,ilat,ilev) = grav(ilon,ilat,ilev,itim)* & |
---|
| 323 | ( 1./cpdet(t2d(ilat,ilev)) & |
---|
| 324 | - plev(ilev)*dtsdp(ilat,ilev)/(R0*t2d(ilat,ilev)) ) |
---|
| 325 | stab3d(ilon,ilat,ilev) = stab3d(ilon,ilat,ilev)*1000. ! passage en K/km |
---|
| 326 | else |
---|
| 327 | stab3d(ilon,ilat,ilev) = miss_val |
---|
| 328 | endif |
---|
| 329 | enddo |
---|
| 330 | enddo |
---|
| 331 | enddo |
---|
| 332 | |
---|
| 333 | !=============================================================================== |
---|
| 334 | ! 2.2.5 Richardson number |
---|
| 335 | !=============================================================================== |
---|
| 336 | |
---|
| 337 | do ilon=1,lonlength+1 |
---|
| 338 | u2d(:,:) = u3d(ilon,:,:) |
---|
| 339 | v2d(:,:) = v3d(ilon,:,:) |
---|
| 340 | call dx_dp(latlength,altlength,miss_val,plev,u2d,dusdp) |
---|
| 341 | call dx_dp(latlength,altlength,miss_val,plev,v2d,dvsdp) |
---|
| 342 | do ilat=1,latlength |
---|
| 343 | do ilev=1,altlength |
---|
| 344 | if ((grav(ilon,ilat,ilev,itim).ne.miss_val).and. & |
---|
| 345 | ( u3d(ilon,ilat,ilev).ne.miss_val).and. & |
---|
| 346 | ( v3d(ilon,ilat,ilev).ne.miss_val).and. & |
---|
| 347 | ( t3d(ilon,ilat,ilev).ne.miss_val) ) then |
---|
| 348 | Ri3d(ilon,ilat,ilev) = & ! attention, transfo a cause de du/dp au lieu de du/dz |
---|
| 349 | stab3d(ilon,ilat,ilev)*t3d(ilon,ilat,ilev)*R0*R0 & |
---|
| 350 | / (grav(ilon,ilat,ilev,itim)*plev(ilev)*plev(ilev)) & |
---|
| 351 | / (dusdp(ilat,ilev)*dusdp(ilat,ilev)+dvsdp(ilat,ilev)*dvsdp(ilat,ilev)) |
---|
| 352 | else |
---|
| 353 | Ri3d(ilon,ilat,ilev) = miss_val |
---|
| 354 | endif |
---|
| 355 | enddo |
---|
| 356 | enddo |
---|
| 357 | enddo |
---|
| 358 | |
---|
| 359 | !=============================================================================== |
---|
| 360 | ! 2.2.6 Distance to cyclostrophic equilibrium |
---|
| 361 | !=============================================================================== |
---|
| 362 | |
---|
| 363 | call moyzon(lonlength,latlength,altlength,miss_val,u3d,u2d) |
---|
| 364 | call moyzon(lonlength,latlength,altlength,miss_val,t3d,t2d) |
---|
| 365 | call dx_dp(latlength,altlength,miss_val,plev,u2d,dusdp) |
---|
| 366 | |
---|
| 367 | do ilat=2,latlength-1 |
---|
[1454] | 368 | if (tan(lat(ilat)*pi/180.).ne.0.) then |
---|
| 369 | fac1 = R0/tan(lat(ilat)*pi/180.) |
---|
[816] | 370 | else |
---|
| 371 | fac1 = miss_val |
---|
| 372 | endif |
---|
| 373 | do ilev=1,altlength |
---|
| 374 | if ((dusdp(ilat,ilev).ne.miss_val).and. & |
---|
| 375 | ( u2d(ilat,ilev).ne.miss_val).and. & |
---|
| 376 | ( fac1.ne.miss_val).and. & |
---|
| 377 | ( t2d(ilat,ilev).ne.miss_val) ) then |
---|
| 378 | ecden = dusdp(ilat,ilev)*(2.*u2d(ilat,ilev)*plev(ilev)) |
---|
| 379 | ecnum = ((t2d(ilat+1,ilev)-t2d(ilat-1,ilev))/(2.*deltalat)*fac1-ecden)*100. |
---|
| 380 | deqc2d(ilat,ilev) = ecnum/ecden |
---|
| 381 | else |
---|
| 382 | deqc2d(ilat,ilev) = miss_val |
---|
| 383 | endif |
---|
| 384 | enddo |
---|
| 385 | enddo |
---|
| 386 | do ilev=1,altlength |
---|
| 387 | deqc2d(1,ilev) = miss_val |
---|
| 388 | deqc2d(latlength,ilev) = miss_val |
---|
| 389 | enddo |
---|
| 390 | |
---|
| 391 | !=============================================================================== |
---|
| 392 | ! 2.2.7 Building 3D+time variables |
---|
| 393 | !=============================================================================== |
---|
| 394 | |
---|
| 395 | deqc(:,:,itim) = deqc2d(:,:) |
---|
| 396 | stab(:,:,:,itim) = stab3d(1:lonlength,:,:) |
---|
| 397 | Ri(:,:,:,itim) = Ri3d(1:lonlength,:,:) |
---|
| 398 | |
---|
| 399 | |
---|
| 400 | enddo ! timelength |
---|
| 401 | !=============================================================================== |
---|
| 402 | !!! END GLOBAL TIME LOOP !!! |
---|
| 403 | !=============================================================================== |
---|
| 404 | |
---|
| 405 | print*,"End of computations" |
---|
| 406 | |
---|
| 407 | !=============================================================================== |
---|
| 408 | ! 3. Create output file |
---|
| 409 | !=============================================================================== |
---|
| 410 | |
---|
| 411 | ! Create output file |
---|
| 412 | ierr=NF_CREATE(outfile,NF_CLOBBER,outfid) |
---|
| 413 | if (ierr.ne.NF_NOERR) then |
---|
| 414 | write(*,*)"Error: could not create file ",outfile |
---|
| 415 | stop |
---|
| 416 | endif |
---|
| 417 | |
---|
| 418 | !=============================================================================== |
---|
| 419 | ! 3.1. Define and write dimensions |
---|
| 420 | !=============================================================================== |
---|
| 421 | |
---|
| 422 | call write_dim(outfid,lonlength,latlength,altlength,timelength, & |
---|
| 423 | lon,lat,plev,time,lon_dimid,lat_dimid,alt_dimid,time_dimid) |
---|
| 424 | |
---|
| 425 | !=============================================================================== |
---|
| 426 | ! 3.2. Define and write variables |
---|
| 427 | !=============================================================================== |
---|
| 428 | |
---|
| 429 | ! 3D Variables |
---|
| 430 | |
---|
| 431 | datashape3d(1)=lat_dimid |
---|
| 432 | datashape3d(2)=alt_dimid |
---|
| 433 | datashape3d(3)=time_dimid |
---|
| 434 | |
---|
| 435 | call write_var3d(outfid,datashape3d,latlength,altlength,timelength,& |
---|
| 436 | "deqc ", "Distance to cyclo eq","per cent ",miss_val,& |
---|
| 437 | deqc ) |
---|
| 438 | |
---|
| 439 | ! 4D Variables |
---|
| 440 | |
---|
| 441 | datashape4d(1)=lon_dimid |
---|
| 442 | datashape4d(2)=lat_dimid |
---|
| 443 | datashape4d(3)=alt_dimid |
---|
| 444 | datashape4d(4)=time_dimid |
---|
| 445 | |
---|
| 446 | call write_var4d(outfid,datashape4d,lonlength,latlength,altlength,timelength,& |
---|
| 447 | "stab ", "Stability ","K/km ",miss_val,& |
---|
| 448 | stab ) |
---|
| 449 | |
---|
| 450 | call write_var4d(outfid,datashape4d,lonlength,latlength,altlength,timelength,& |
---|
| 451 | "Ri ", "Richardson number "," ",miss_val,& |
---|
| 452 | Ri ) |
---|
| 453 | |
---|
| 454 | |
---|
| 455 | !!!! Close output file |
---|
| 456 | ierr=NF_CLOSE(outfid) |
---|
| 457 | if (ierr.ne.NF_NOERR) then |
---|
| 458 | write(*,*) 'Error, failed to close output file ',outfile |
---|
| 459 | endif |
---|
| 460 | |
---|
| 461 | |
---|
| 462 | end program |
---|