[135] | 1 | subroutine inistats(ierr) |
---|
| 2 | |
---|
[1529] | 3 | use statto_mod, only: istats,istime |
---|
[965] | 4 | use mod_phys_lmdz_para, only : is_master |
---|
[1621] | 5 | USE vertical_layers_mod, ONLY: ap,bp,aps,bps,preff, |
---|
| 6 | & pseudoalt,presnivs |
---|
| 7 | USE nrtype, ONLY: pi |
---|
[1529] | 8 | USE time_phylmdz_mod, ONLY: daysec,dtphys |
---|
| 9 | USE regular_lonlat_mod, ONLY: lon_reg, lat_reg |
---|
| 10 | USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev |
---|
[135] | 11 | implicit none |
---|
| 12 | |
---|
[1529] | 13 | include "netcdf.inc" |
---|
[135] | 14 | |
---|
| 15 | integer,intent(out) :: ierr |
---|
| 16 | integer :: nid |
---|
| 17 | integer :: l,nsteppd |
---|
[1529] | 18 | real, dimension(nbp_lev) :: sig_s |
---|
[1531] | 19 | real,allocatable :: lon_reg_ext(:) ! extended longitudes |
---|
[135] | 20 | integer :: idim_lat,idim_lon,idim_llm,idim_llmp1,idim_time |
---|
| 21 | real, dimension(istime) :: lt |
---|
| 22 | integer :: nvarid |
---|
| 23 | |
---|
[1531] | 24 | |
---|
| 25 | IF (nbp_lon*nbp_lat==1) THEN |
---|
| 26 | ! 1D model |
---|
| 27 | ALLOCATE(lon_reg_ext(1)) |
---|
| 28 | ELSE |
---|
| 29 | ! 3D model |
---|
| 30 | ALLOCATE(lon_reg_ext(nbp_lon+1)) |
---|
| 31 | ENDIF |
---|
| 32 | |
---|
[135] | 33 | write (*,*) |
---|
| 34 | write (*,*) ' || STATS ||' |
---|
| 35 | write (*,*) |
---|
| 36 | write (*,*) 'daysec',daysec |
---|
| 37 | write (*,*) 'dtphys',dtphys |
---|
| 38 | nsteppd=nint(daysec/dtphys) |
---|
| 39 | write (*,*) 'nsteppd=',nsteppd |
---|
| 40 | if (abs(float(nsteppd)-daysec/dtphys).gt.1.e-8*daysec) |
---|
[1216] | 41 | & stop'Dans Instat: 1jour .ne. n pas physiques' |
---|
[135] | 42 | |
---|
| 43 | if(mod(nsteppd,istime).ne.0) |
---|
[1216] | 44 | & stop'Dans Instat: 1jour .ne. n*istime pas physiques' |
---|
[135] | 45 | |
---|
| 46 | istats=nsteppd/istime |
---|
| 47 | write (*,*) 'istats=',istats |
---|
| 48 | write (*,*) 'Storing ',istime,'times per day' |
---|
| 49 | write (*,*) 'thus every ',istats,'physical timestep ' |
---|
| 50 | write (*,*) |
---|
| 51 | |
---|
[1529] | 52 | do l= 1, nbp_lev |
---|
[135] | 53 | sig_s(l)=((ap(l)+ap(l+1))/preff+bp(l)+bp(l+1))/2. |
---|
| 54 | pseudoalt(l)=-10.*log(presnivs(l)/preff) |
---|
| 55 | enddo |
---|
[1529] | 56 | |
---|
| 57 | lon_reg_ext(1:nbp_lon)=lon_reg(1:nbp_lon) |
---|
[1531] | 58 | IF (nbp_lon*nbp_lat/=1) THEN |
---|
| 59 | ! In 3D, add extra redundant point (180 degrees, |
---|
| 60 | ! since lon_reg starts at -180) |
---|
| 61 | lon_reg_ext(nbp_lon+1)=-lon_reg_ext(1) |
---|
| 62 | ENDIF |
---|
[135] | 63 | |
---|
[965] | 64 | if (is_master) then |
---|
| 65 | ! only the master needs do this |
---|
| 66 | |
---|
[1216] | 67 | ierr = NF_CREATE("stats.nc",IOR(NF_CLOBBER,NF_64BIT_OFFSET),nid) |
---|
[135] | 68 | if (ierr.ne.NF_NOERR) then |
---|
| 69 | write (*,*) NF_STRERROR(ierr) |
---|
| 70 | stop "" |
---|
| 71 | endif |
---|
| 72 | |
---|
[1529] | 73 | ierr = NF_DEF_DIM (nid, "latitude", nbp_lat, idim_lat) |
---|
[1531] | 74 | IF (nbp_lon*nbp_lat==1) THEN |
---|
| 75 | ierr = NF_DEF_DIM (nid, "longitude", 1, idim_lon) |
---|
| 76 | ELSE |
---|
| 77 | ierr = NF_DEF_DIM (nid, "longitude", nbp_lon+1, idim_lon) |
---|
| 78 | ENDIF |
---|
[1529] | 79 | ierr = NF_DEF_DIM (nid, "altitude", nbp_lev, idim_llm) |
---|
| 80 | ierr = NF_DEF_DIM (nid, "llmp1", nbp_lev+1, idim_llmp1) |
---|
[135] | 81 | ierr = NF_DEF_DIM (nid, "Time", NF_UNLIMITED, idim_time) |
---|
| 82 | |
---|
| 83 | ierr = NF_ENDDEF(nid) |
---|
[1216] | 84 | call def_var_stats(nid,"Time","Time", |
---|
| 85 | & "days since 0000-00-0 00:00:00",1, |
---|
| 86 | & idim_time,nvarid,ierr) |
---|
[135] | 87 | ! Time is initialised later by mkstats subroutine |
---|
| 88 | |
---|
[1216] | 89 | call def_var_stats(nid,"latitude","latitude", |
---|
| 90 | & "degrees_north",1,idim_lat,nvarid,ierr) |
---|
[135] | 91 | #ifdef NC_DOUBLE |
---|
[1529] | 92 | ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,lat_reg/pi*180) |
---|
[135] | 93 | #else |
---|
[1529] | 94 | ierr = NF_PUT_VAR_REAL (nid,nvarid,lat_reg/pi*180) |
---|
[135] | 95 | #endif |
---|
[1216] | 96 | call def_var_stats(nid,"longitude","East longitude", |
---|
| 97 | & "degrees_east",1,idim_lon,nvarid,ierr) |
---|
[135] | 98 | #ifdef NC_DOUBLE |
---|
[1529] | 99 | ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,lon_reg_ext/pi*180) |
---|
[135] | 100 | #else |
---|
[1529] | 101 | ierr = NF_PUT_VAR_REAL (nid,nvarid,lon_reg_ext/pi*180) |
---|
[135] | 102 | #endif |
---|
| 103 | |
---|
| 104 | ! Niveaux verticaux, aps et bps |
---|
| 105 | ierr = NF_REDEF (nid) |
---|
| 106 | #ifdef NC_DOUBLE |
---|
| 107 | ierr = NF_DEF_VAR (nid,"altitude", NF_DOUBLE, 1,idim_llm,nvarid) |
---|
| 108 | #else |
---|
| 109 | ierr = NF_DEF_VAR (nid,"altitude", NF_FLOAT, 1,idim_llm,nvarid) |
---|
| 110 | #endif |
---|
| 111 | ierr = NF_PUT_ATT_TEXT (nid,nvarid,"long_name",8,"altitude") |
---|
| 112 | ierr = NF_PUT_ATT_TEXT (nid,nvarid,'units',2,"km") |
---|
| 113 | ierr = NF_PUT_ATT_TEXT (nid,nvarid,'positive',2,"up") |
---|
| 114 | ierr = NF_ENDDEF(nid) |
---|
| 115 | #ifdef NC_DOUBLE |
---|
| 116 | ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,pseudoalt) |
---|
| 117 | #else |
---|
| 118 | ierr = NF_PUT_VAR_REAL (nid,nvarid,pseudoalt) |
---|
| 119 | #endif |
---|
[1216] | 120 | call def_var_stats(nid,"aps","hybrid pressure at midlayers" |
---|
| 121 | & ," ",1,idim_llm,nvarid,ierr) |
---|
[135] | 122 | #ifdef NC_DOUBLE |
---|
| 123 | ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,aps) |
---|
| 124 | #else |
---|
| 125 | ierr = NF_PUT_VAR_REAL (nid,nvarid,aps) |
---|
| 126 | #endif |
---|
| 127 | |
---|
[1216] | 128 | call def_var_stats(nid,"bps","hybrid sigma at midlayers" |
---|
| 129 | & ," ",1,idim_llm,nvarid,ierr) |
---|
[135] | 130 | #ifdef NC_DOUBLE |
---|
| 131 | ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,bps) |
---|
| 132 | #else |
---|
| 133 | ierr = NF_PUT_VAR_REAL (nid,nvarid,bps) |
---|
| 134 | #endif |
---|
| 135 | |
---|
| 136 | ierr=NF_CLOSE(nid) |
---|
| 137 | |
---|
[965] | 138 | endif ! of if (is_master) |
---|
[1216] | 139 | end subroutine inistats |
---|
| 140 | |
---|