| 1 | c======================================================================= |
|---|
| 2 | PROGRAM start2archive |
|---|
| 3 | c======================================================================= |
|---|
| 4 | c |
|---|
| 5 | c |
|---|
| 6 | c Date: 01/1997 |
|---|
| 7 | c ---- |
|---|
| 8 | c |
|---|
| 9 | c |
|---|
| 10 | c Objet: Passage des fichiers netcdf d'etat initial "start" et |
|---|
| 11 | c ----- "startfi" a un fichier netcdf unique "start_archive" |
|---|
| 12 | c |
|---|
| 13 | c "start_archive" est une banque d'etats initiaux: |
|---|
| 14 | c On peut stocker plusieurs etats initiaux dans un meme fichier "start_archive" |
|---|
| 15 | c (Veiller dans ce cas avoir un day_ini different pour chacun des start) |
|---|
| 16 | c |
|---|
| 17 | c |
|---|
| 18 | c |
|---|
| 19 | c======================================================================= |
|---|
| 20 | |
|---|
| 21 | implicit none |
|---|
| 22 | |
|---|
| 23 | #include "dimensions.h" |
|---|
| 24 | #include "paramet.h" |
|---|
| 25 | #include "comconst.h" |
|---|
| 26 | #include "comdissip.h" |
|---|
| 27 | #include "comvert.h" |
|---|
| 28 | #include "comgeom.h" |
|---|
| 29 | #include "logic.h" |
|---|
| 30 | #include "temps.h" |
|---|
| 31 | #include "control.h" |
|---|
| 32 | #include "ener.h" |
|---|
| 33 | #include "description.h" |
|---|
| 34 | |
|---|
| 35 | #include "dimphys.h" |
|---|
| 36 | #include "comsoil.h" |
|---|
| 37 | #include"advtrac.h" |
|---|
| 38 | #include "netcdf.inc" |
|---|
| 39 | |
|---|
| 40 | c----------------------------------------------------------------------- |
|---|
| 41 | c Declarations |
|---|
| 42 | c----------------------------------------------------------------------- |
|---|
| 43 | |
|---|
| 44 | c variables dynamiques du GCM |
|---|
| 45 | c ----------------------------- |
|---|
| 46 | REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants |
|---|
| 47 | REAL teta(ip1jmp1,llm) ! temperature potentielle |
|---|
| 48 | REAL q(ip1jmp1,llm,nqmx) ! champs advectes |
|---|
| 49 | REAL pks(ip1jmp1) ! exner (f pour filtre) |
|---|
| 50 | REAL pk(ip1jmp1,llm) |
|---|
| 51 | REAL pkf(ip1jmp1,llm) |
|---|
| 52 | REAL beta(iip1,jjp1,llm) |
|---|
| 53 | REAL phis(ip1jmp1) ! geopotentiel au sol |
|---|
| 54 | REAL masse(ip1jmp1,llm) ! masse de l'atmosphere |
|---|
| 55 | REAL ps(ip1jmp1) ! pression au sol |
|---|
| 56 | REAL p3d(iip1, jjp1, llm+1) ! pression aux interfaces |
|---|
| 57 | |
|---|
| 58 | c Variable Physiques (grille physique) |
|---|
| 59 | c ------------------------------------ |
|---|
| 60 | REAL tsurf(ngridmx) ! Surface temperature |
|---|
| 61 | REAL tsoil(ngridmx,nsoilmx) ! Soil temperature |
|---|
| 62 | REAL co2ice(ngridmx) ! CO2 ice layer |
|---|
| 63 | REAL q2(ngridmx,nlayermx+1),qsurf(ngridmx,nqmx) |
|---|
| 64 | REAL emis(ngridmx) |
|---|
| 65 | INTEGER start,length |
|---|
| 66 | PARAMETER (length = 100) |
|---|
| 67 | REAL tab_cntrl_fi(length) ! tableau des parametres de startfi |
|---|
| 68 | INTEGER*4 day_ini_fi |
|---|
| 69 | |
|---|
| 70 | c Variable naturelle / grille scalaire |
|---|
| 71 | c ------------------------------------ |
|---|
| 72 | REAL T(ip1jmp1,llm),us(ip1jmp1,llm),vs(ip1jmp1,llm) |
|---|
| 73 | REAL tsurfS(ip1jmp1) |
|---|
| 74 | REAL tsoilS(ip1jmp1,nsoilmx) |
|---|
| 75 | REAL ithS(ip1jmp1,nsoilmx) ! Soil Thermal Inertia |
|---|
| 76 | REAL co2iceS(ip1jmp1) |
|---|
| 77 | REAL q2S(ip1jmp1,llm+1),qsurfS(ip1jmp1,nqmx) |
|---|
| 78 | REAL emisS(ip1jmp1) |
|---|
| 79 | |
|---|
| 80 | c Variables intermediaires : vent naturel, mais pas coord scalaire |
|---|
| 81 | c---------------------------------------------------------------- |
|---|
| 82 | REAL vn(ip1jm,llm),un(ip1jmp1,llm) |
|---|
| 83 | |
|---|
| 84 | c Autres variables |
|---|
| 85 | c ----------------- |
|---|
| 86 | LOGICAL startdrs |
|---|
| 87 | INTEGER Lmodif |
|---|
| 88 | |
|---|
| 89 | REAL ptotal, co2icetotal |
|---|
| 90 | REAL timedyn,timefi !fraction du jour dans start, startfi |
|---|
| 91 | REAL date |
|---|
| 92 | |
|---|
| 93 | CHARACTER*2 str2 |
|---|
| 94 | CHARACTER*80 fichier |
|---|
| 95 | data fichier /'startfi'/ |
|---|
| 96 | |
|---|
| 97 | INTEGER ij, l,i,j,isoil,iq |
|---|
| 98 | character*80 fichnom |
|---|
| 99 | integer :: ierr,ntime |
|---|
| 100 | integer :: nq,numvanle |
|---|
| 101 | character(len=30) :: txt ! to store some text |
|---|
| 102 | |
|---|
| 103 | c Netcdf |
|---|
| 104 | c------- |
|---|
| 105 | integer varid,dimid,timelen |
|---|
| 106 | INTEGER nid,nid1 |
|---|
| 107 | |
|---|
| 108 | c----------------------------------------------------------------------- |
|---|
| 109 | c Initialisations |
|---|
| 110 | c----------------------------------------------------------------------- |
|---|
| 111 | |
|---|
| 112 | grireg = .TRUE. |
|---|
| 113 | |
|---|
| 114 | c======================================================================= |
|---|
| 115 | c Lecture des donnees |
|---|
| 116 | c======================================================================= |
|---|
| 117 | ! Load tracer names: |
|---|
| 118 | call iniadvtrac(nq,numvanle) |
|---|
| 119 | |
|---|
| 120 | fichnom = 'start.nc' |
|---|
| 121 | CALL dynetat0(fichnom,nqmx,vcov,ucov,teta,q,masse, |
|---|
| 122 | . ps,phis,timedyn) |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | fichnom = 'startfi.nc' |
|---|
| 126 | Lmodif=0 |
|---|
| 127 | |
|---|
| 128 | CALL phyetat0 (fichnom,0,Lmodif,nsoilmx,nqmx,day_ini_fi,timefi, |
|---|
| 129 | . tsurf,tsoil,emis,q2,qsurf,co2ice) |
|---|
| 130 | |
|---|
| 131 | ierr = NF_OPEN (fichnom, NF_NOWRITE,nid1) |
|---|
| 132 | IF (ierr.NE.NF_NOERR) THEN |
|---|
| 133 | write(6,*)' Pb d''ouverture du fichier'//fichnom |
|---|
| 134 | CALL ABORT |
|---|
| 135 | ENDIF |
|---|
| 136 | |
|---|
| 137 | ierr = NF_INQ_VARID (nid1, "controle", varid) |
|---|
| 138 | IF (ierr .NE. NF_NOERR) THEN |
|---|
| 139 | PRINT*, "start2archive: Le champ <controle> est absent" |
|---|
| 140 | CALL abort |
|---|
| 141 | ENDIF |
|---|
| 142 | #ifdef NC_DOUBLE |
|---|
| 143 | ierr = NF_GET_VAR_DOUBLE(nid1, varid, tab_cntrl_fi) |
|---|
| 144 | #else |
|---|
| 145 | ierr = NF_GET_VAR_REAL(nid1, varid, tab_cntrl_fi) |
|---|
| 146 | #endif |
|---|
| 147 | IF (ierr .NE. NF_NOERR) THEN |
|---|
| 148 | PRINT*, "start2archive: Lecture echoue pour <controle>" |
|---|
| 149 | CALL abort |
|---|
| 150 | ENDIF |
|---|
| 151 | |
|---|
| 152 | ierr = NF_CLOSE(nid1) |
|---|
| 153 | |
|---|
| 154 | c----------------------------------------------------------------------- |
|---|
| 155 | c Controle de la synchro |
|---|
| 156 | c----------------------------------------------------------------------- |
|---|
| 157 | !mars a voir if ((day_ini_fi.ne.day_ini).or.(abs(timefi-timedyn).gt.1.e-10)) |
|---|
| 158 | if ((day_ini_fi.ne.day_ini)) |
|---|
| 159 | & stop ' Probleme de Synchro entre start et startfi !!!' |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | c ***************************************************************** |
|---|
| 163 | c Option : Reinitialisation des dates dans la premieres annees : |
|---|
| 164 | do while (day_ini.ge.669) |
|---|
| 165 | day_ini=day_ini-669 |
|---|
| 166 | enddo |
|---|
| 167 | c ***************************************************************** |
|---|
| 168 | |
|---|
| 169 | c----------------------------------------------------------------------- |
|---|
| 170 | c Initialisations |
|---|
| 171 | c----------------------------------------------------------------------- |
|---|
| 172 | |
|---|
| 173 | CALL defrun_new(99, .FALSE. ) |
|---|
| 174 | call iniconst |
|---|
| 175 | call inigeom |
|---|
| 176 | call inifilr |
|---|
| 177 | CALL pression(ip1jmp1, ap, bp, ps, p3d) |
|---|
| 178 | call exner_hyb(ip1jmp1, ps, p3d, beta, pks, pk, pkf) |
|---|
| 179 | |
|---|
| 180 | c======================================================================= |
|---|
| 181 | c Transformation EN VARIABLE NATURELLE / GRILLE SCALAIRE si necessaire |
|---|
| 182 | c======================================================================= |
|---|
| 183 | c Les variables modeles dependent de la resolution. Il faut donc |
|---|
| 184 | c eliminer les facteurs responsables de cette dependance |
|---|
| 185 | c (pour utiliser newstart) |
|---|
| 186 | c======================================================================= |
|---|
| 187 | |
|---|
| 188 | c----------------------------------------------------------------------- |
|---|
| 189 | c Vent (depend de la resolution horizontale) |
|---|
| 190 | c----------------------------------------------------------------------- |
|---|
| 191 | c |
|---|
| 192 | c ucov --> un et vcov --> vn |
|---|
| 193 | c un --> us et vn --> vs |
|---|
| 194 | c |
|---|
| 195 | c----------------------------------------------------------------------- |
|---|
| 196 | |
|---|
| 197 | call covnat(llm,ucov, vcov, un, vn) |
|---|
| 198 | call wind_scal(un,vn,us,vs) |
|---|
| 199 | |
|---|
| 200 | c----------------------------------------------------------------------- |
|---|
| 201 | c Temperature (depend de la resolution verticale => de "sigma.def") |
|---|
| 202 | c----------------------------------------------------------------------- |
|---|
| 203 | c |
|---|
| 204 | c h --> T |
|---|
| 205 | c |
|---|
| 206 | c----------------------------------------------------------------------- |
|---|
| 207 | |
|---|
| 208 | DO l=1,llm |
|---|
| 209 | DO ij=1,ip1jmp1 |
|---|
| 210 | T(ij,l)=teta(ij,l)*pk(ij,l)/cpp !mars deduit de l'equation dans newstart |
|---|
| 211 | ENDDO |
|---|
| 212 | ENDDO |
|---|
| 213 | |
|---|
| 214 | c----------------------------------------------------------------------- |
|---|
| 215 | c Variable physique |
|---|
| 216 | c----------------------------------------------------------------------- |
|---|
| 217 | c |
|---|
| 218 | c tsurf --> tsurfS |
|---|
| 219 | c co2ice --> co2iceS |
|---|
| 220 | c tsoil --> tsoilS |
|---|
| 221 | c emis --> emisS |
|---|
| 222 | c q2 --> q2S |
|---|
| 223 | c qsurf --> qsurfS |
|---|
| 224 | c |
|---|
| 225 | c----------------------------------------------------------------------- |
|---|
| 226 | |
|---|
| 227 | call gr_fi_dyn(1,ngridmx,iip1,jjp1,tsurf,tsurfS) |
|---|
| 228 | call gr_fi_dyn(1,ngridmx,iip1,jjp1,co2ice,co2iceS) |
|---|
| 229 | call gr_fi_dyn(nsoilmx,ngridmx,iip1,jjp1,tsoil,tsoilS) |
|---|
| 230 | ! Note: thermal inertia "inertiedat" is in comsoil.h |
|---|
| 231 | call gr_fi_dyn(nsoilmx,ngridmx,iip1,jjp1,inertiedat,ithS) |
|---|
| 232 | call gr_fi_dyn(1,ngridmx,iip1,jjp1,emis,emisS) |
|---|
| 233 | call gr_fi_dyn(llm+1,ngridmx,iip1,jjp1,q2,q2S) |
|---|
| 234 | call gr_fi_dyn(nqmx,ngridmx,iip1,jjp1,qsurf,qsurfS) |
|---|
| 235 | |
|---|
| 236 | c======================================================================= |
|---|
| 237 | c Info pour controler |
|---|
| 238 | c======================================================================= |
|---|
| 239 | |
|---|
| 240 | ptotal = 0. |
|---|
| 241 | co2icetotal = 0. |
|---|
| 242 | DO j=1,jjp1 |
|---|
| 243 | DO i=1,iim |
|---|
| 244 | ptotal=ptotal+aire(i+(iim+1)*(j-1))*ps(i+(iim+1)*(j-1))/g |
|---|
| 245 | co2icetotal = co2icetotal + |
|---|
| 246 | & co2iceS(i+(iim+1)*(j-1))*aire(i+(iim+1)*(j-1)) |
|---|
| 247 | ENDDO |
|---|
| 248 | ENDDO |
|---|
| 249 | write(*,*)'Ancienne grille : masse de l''atm :',ptotal |
|---|
| 250 | write(*,*)'Ancienne grille : masse de la glace CO2 :',co2icetotal |
|---|
| 251 | |
|---|
| 252 | c----------------------------------------------------------------------- |
|---|
| 253 | c Passage de "ptotal" et "co2icetotal" par tab_cntrl_fi |
|---|
| 254 | c----------------------------------------------------------------------- |
|---|
| 255 | |
|---|
| 256 | tab_cntrl_fi(49) = ptotal |
|---|
| 257 | tab_cntrl_fi(50) = co2icetotal |
|---|
| 258 | |
|---|
| 259 | c======================================================================= |
|---|
| 260 | c Ecriture dans le fichier "start_archive" |
|---|
| 261 | c======================================================================= |
|---|
| 262 | |
|---|
| 263 | c----------------------------------------------------------------------- |
|---|
| 264 | c Ouverture de "start_archive" |
|---|
| 265 | c----------------------------------------------------------------------- |
|---|
| 266 | |
|---|
| 267 | ierr = NF_OPEN ('start_archive.nc', NF_WRITE,nid) |
|---|
| 268 | |
|---|
| 269 | c----------------------------------------------------------------------- |
|---|
| 270 | c si "start_archive" n'existe pas: |
|---|
| 271 | c 1_ ouverture |
|---|
| 272 | c 2_ creation de l'entete dynamique ("ini_archive") |
|---|
| 273 | c----------------------------------------------------------------------- |
|---|
| 274 | c ini_archive: |
|---|
| 275 | c On met dans l'entete le tab_cntrl dynamique (1 a 16) |
|---|
| 276 | c On y ajoute les valeurs du tab_cntrl_fi (a partir de 51) |
|---|
| 277 | c En plus les deux valeurs ptotal et co2icetotal (99 et 100) |
|---|
| 278 | c----------------------------------------------------------------------- |
|---|
| 279 | |
|---|
| 280 | if (ierr.ne.NF_NOERR) then |
|---|
| 281 | write(*,*)'OK, Could not open file "start_archive.nc"' |
|---|
| 282 | write(*,*)'So let s create a new "start_archive"' |
|---|
| 283 | ierr = NF_CREATE('start_archive.nc', NF_CLOBBER, nid) |
|---|
| 284 | call ini_archive(nid,day_ini,phis,ithS,tab_cntrl_fi) |
|---|
| 285 | endif |
|---|
| 286 | |
|---|
| 287 | c----------------------------------------------------------------------- |
|---|
| 288 | c Ecriture de la coordonnee temps (date en jours) |
|---|
| 289 | c----------------------------------------------------------------------- |
|---|
| 290 | |
|---|
| 291 | date = day_ini |
|---|
| 292 | ierr= NF_INQ_VARID(nid,"Time",varid) |
|---|
| 293 | ierr= NF_INQ_DIMID(nid,"Time",dimid) |
|---|
| 294 | ierr= NF_INQ_DIMLEN(nid,dimid,timelen) |
|---|
| 295 | ntime=timelen+1 |
|---|
| 296 | |
|---|
| 297 | write(*,*) "******************" |
|---|
| 298 | write(*,*) "ntime",ntime |
|---|
| 299 | write(*,*) "******************" |
|---|
| 300 | #ifdef NC_DOUBLE |
|---|
| 301 | ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date) |
|---|
| 302 | #else |
|---|
| 303 | ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date) |
|---|
| 304 | #endif |
|---|
| 305 | if (ierr.ne.NF_NOERR) then |
|---|
| 306 | write(*,*) "time matter ",NF_STRERROR(ierr) |
|---|
| 307 | stop |
|---|
| 308 | endif |
|---|
| 309 | |
|---|
| 310 | c----------------------------------------------------------------------- |
|---|
| 311 | c Ecriture des champs (co2ice,emis,ps,Tsurf,T,u,v,q2,q,qsurf) |
|---|
| 312 | c----------------------------------------------------------------------- |
|---|
| 313 | c ATTENTION: q2 a une couche de plus!!!! |
|---|
| 314 | c Pour creer un fichier netcdf lisible par grads, |
|---|
| 315 | c On passe donc une des couches de q2 a part |
|---|
| 316 | c comme une variable 2D (la couche au sol: "q2surf") |
|---|
| 317 | c Les lmm autres couches sont nommees "q2atm" (3D) |
|---|
| 318 | c----------------------------------------------------------------------- |
|---|
| 319 | |
|---|
| 320 | call write_archive(nid,ntime,'co2ice','couche de glace co2', |
|---|
| 321 | & 'kg/m2',2,co2iceS) |
|---|
| 322 | call write_archive(nid,ntime,'emis','grd emis',' ',2,emisS) |
|---|
| 323 | call write_archive(nid,ntime,'ps','Psurf','Pa',2,ps) |
|---|
| 324 | call write_archive(nid,ntime,'tsurf','surf T','K',2,tsurfS) |
|---|
| 325 | call write_archive(nid,ntime,'temp','temperature','K',3,t) |
|---|
| 326 | call write_archive(nid,ntime,'u','Vent zonal','m.s-1',3,us) |
|---|
| 327 | call write_archive(nid,ntime,'v','Vent merid','m.s-1',3,vs) |
|---|
| 328 | call write_archive(nid,ntime,'q2surf','wind variance','m2.s-2',2, |
|---|
| 329 | . q2S) |
|---|
| 330 | call write_archive(nid,ntime,'q2atm','wind variance','m2.s-2',3, |
|---|
| 331 | . q2S(1,2)) |
|---|
| 332 | |
|---|
| 333 | c----------------------------------------------------------------------- |
|---|
| 334 | c Ecriture du champs q ( q[1,nqmx] ) |
|---|
| 335 | c----------------------------------------------------------------------- |
|---|
| 336 | do iq=1,nqmx |
|---|
| 337 | c write(str2,'(i2.2)') iq |
|---|
| 338 | c call write_archive(nid,ntime,'q'//str2,'tracer','kg/kg', |
|---|
| 339 | c . 3,q(1,1,iq)) |
|---|
| 340 | call write_archive(nid,ntime,tnom(iq),'tracer','kg/kg', |
|---|
| 341 | & 3,q(1,1,iq)) |
|---|
| 342 | end do |
|---|
| 343 | c----------------------------------------------------------------------- |
|---|
| 344 | c Ecriture du champs qsurf ( qsurf[1,nqmx] ) |
|---|
| 345 | c----------------------------------------------------------------------- |
|---|
| 346 | do iq=1,nqmx |
|---|
| 347 | c write(str2,'(i2.2)') iq |
|---|
| 348 | c call write_archive(nid,ntime,'qsurf'//str2,'Tracer on surface', |
|---|
| 349 | c $ 'kg.m-2',2,qsurfS(1,iq)) |
|---|
| 350 | txt=trim(tnom(iq))//"_surf" |
|---|
| 351 | call write_archive(nid,ntime,txt,'Tracer on surface', |
|---|
| 352 | & 'kg.m-2',2,qsurfS(1,iq)) |
|---|
| 353 | enddo |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | c----------------------------------------------------------------------- |
|---|
| 357 | c Ecriture du champs tsoil ( Tg[1,10] ) |
|---|
| 358 | c----------------------------------------------------------------------- |
|---|
| 359 | c "tsoil" Temperature au sol definie dans 10 couches dans le sol |
|---|
| 360 | c Les 10 couches sont lues comme 10 champs |
|---|
| 361 | c nommees Tg[1,10] |
|---|
| 362 | |
|---|
| 363 | c do isoil=1,nsoilmx |
|---|
| 364 | c write(str2,'(i2.2)') isoil |
|---|
| 365 | c call write_archive(nid,ntime,'Tg'//str2,'Ground Temperature ', |
|---|
| 366 | c . 'K',2,tsoilS(1,isoil)) |
|---|
| 367 | c enddo |
|---|
| 368 | |
|---|
| 369 | ! Write soil temperatures tsoil |
|---|
| 370 | call write_archive(nid,ntime,'tsoil','Soil temperature', |
|---|
| 371 | & 'K',-3,tsoilS) |
|---|
| 372 | |
|---|
| 373 | ! Write soil thermal inertia |
|---|
| 374 | call write_archive(nid,ntime,'inertiedat', |
|---|
| 375 | & 'Soil thermal inertia', |
|---|
| 376 | & 'J.s-1/2.m-2.K-1',-3,ithS) |
|---|
| 377 | |
|---|
| 378 | ! Write (0D) volumetric heat capacity (stored in comsoil.h) |
|---|
| 379 | ! call write_archive(nid,ntime,'volcapa', |
|---|
| 380 | ! & 'Soil volumetric heat capacity', |
|---|
| 381 | ! & 'J.m-3.K-1',0,volcapa) |
|---|
| 382 | ! Note: no need to write volcapa, it is stored in "controle" table |
|---|
| 383 | |
|---|
| 384 | ierr=NF_CLOSE(nid) |
|---|
| 385 | c----------------------------------------------------------------------- |
|---|
| 386 | c Fin |
|---|
| 387 | c----------------------------------------------------------------------- |
|---|
| 388 | |
|---|
| 389 | end |
|---|