[1980] | 1 | subroutine iotd_ecrit(nom,llm,titre,unite,px) |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | !======================================================================= |
---|
| 5 | ! |
---|
| 6 | ! Auteur: F. Hourdin |
---|
| 7 | ! ------- |
---|
| 8 | ! |
---|
| 9 | ! Objet: |
---|
| 10 | ! ------ |
---|
| 11 | ! Light interface for netcdf outputs. can be used outside LMDZ |
---|
| 12 | ! |
---|
| 13 | !======================================================================= |
---|
| 14 | !----------------------------------------------------------------------- |
---|
| 15 | ! ---------- |
---|
| 16 | ! nom : nom de la variable a sortir (chaine de caracteres) |
---|
| 17 | ! llm : nombre de couches |
---|
| 18 | ! titre: titre de la variable (chaine de caracteres) |
---|
| 19 | ! unite : unite de la variable (chaine de caracteres) |
---|
| 20 | ! px : variable a sortir |
---|
| 21 | ! |
---|
| 22 | !================================================================= |
---|
| 23 | |
---|
[5270] | 24 | USE netcdf, ONLY: nf90_put_var, nf90_inq_varid, nf90_enddef, nf90_redef, nf90_sync, nf90_noerr, & |
---|
| 25 | nf90_float, nf90_def_var |
---|
[5291] | 26 | USE iotd_mod_h |
---|
[1980] | 27 | implicit none |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | ! Arguments on input: |
---|
| 31 | integer llm |
---|
| 32 | character (len=*) :: nom,titre,unite |
---|
| 33 | integer imjmax |
---|
| 34 | parameter (imjmax=100000) |
---|
| 35 | real px(imjmax*llm) |
---|
| 36 | |
---|
| 37 | ! Local variables: |
---|
| 38 | |
---|
| 39 | real*4 date |
---|
| 40 | real*4 zx(imjmax*llm) |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | integer ierr,ndim,dim_cc(4) |
---|
| 44 | integer iq |
---|
| 45 | integer i,j,l |
---|
| 46 | |
---|
| 47 | integer zitau |
---|
| 48 | character firstnom*20 |
---|
| 49 | SAVE firstnom |
---|
| 50 | SAVE zitau |
---|
| 51 | SAVE date |
---|
| 52 | data firstnom /'1234567890'/ |
---|
| 53 | data zitau /0/ |
---|
| 54 | |
---|
| 55 | ! Ajouts |
---|
| 56 | integer, save :: ntime=0 |
---|
| 57 | integer :: idim,varid |
---|
| 58 | character (len =50):: fichnom |
---|
| 59 | integer, dimension(4) :: id |
---|
| 60 | integer, dimension(4) :: edges,corner |
---|
| 61 | |
---|
| 62 | |
---|
[3978] | 63 | |
---|
| 64 | if (n_names_iotd_def>0 .and..not.any(names_iotd_def==nom)) return |
---|
[1980] | 65 | !*************************************************************** |
---|
| 66 | ! Initialisation of 'firstnom' and create/open the "diagfi.nc" NetCDF file |
---|
| 67 | ! ------------------------------------------------------------------------ |
---|
| 68 | ! (Au tout premier appel de la subroutine durant le run.) |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | !-------------------------------------------------------- |
---|
| 72 | ! Write the variables to output file if it's time to do so |
---|
| 73 | !-------------------------------------------------------- |
---|
| 74 | |
---|
| 75 | |
---|
[3977] | 76 | ! Compute/write/extend 'time' coordinate (date given in days) |
---|
[1980] | 77 | ! (done every "first call" (at given time level) to writediagfi) |
---|
| 78 | ! Note: date is incremented as 1 step ahead of physics time |
---|
| 79 | !-------------------------------------------------------- |
---|
| 80 | |
---|
| 81 | zx(1:imax*jmax*llm)=px(1:imax*jmax*llm) |
---|
| 82 | if (firstnom =='1234567890') then |
---|
| 83 | firstnom=nom |
---|
| 84 | endif |
---|
| 85 | |
---|
[3977] | 86 | !print*,'nom ',nom,firstnom |
---|
[1980] | 87 | |
---|
| 88 | !! Quand on tombe sur la premiere variable on ajoute un pas de temps |
---|
[5084] | 89 | if (nom.eq.firstnom) then |
---|
[1980] | 90 | ! We have identified a "first call" (at given date) |
---|
| 91 | |
---|
| 92 | ntime=ntime+1 ! increment # of stored time steps |
---|
| 93 | |
---|
| 94 | !! print*,'ntime ',ntime |
---|
[3977] | 95 | date=iotd_t0+ntime*iotd_ts |
---|
[3978] | 96 | !print*,'iotd_ecrit ',iotd_ts,ntime, date |
---|
[1980] | 97 | ! date= float (zitau +1)/float (day_step) |
---|
| 98 | |
---|
| 99 | ! compute corresponding date (in days and fractions thereof) |
---|
[3977] | 100 | ! Get NetCDF ID of 'time' variable |
---|
[1980] | 101 | |
---|
[5270] | 102 | ierr=nf90_sync(nid) |
---|
[1980] | 103 | |
---|
[5270] | 104 | ierr= nf90_inq_varid(nid,"time",varid) |
---|
[3977] | 105 | ! Write (append) the new date to the 'time' array |
---|
[1980] | 106 | |
---|
| 107 | |
---|
[4259] | 108 | ierr= NF90_PUT_VAR(nid,varid,date,[ntime]) |
---|
[1980] | 109 | |
---|
| 110 | ! print*,'date ',date,ierr,nid |
---|
| 111 | ! print*,'IOTD Date ,varid,nid,ntime,date',varid,nid,ntime,date |
---|
| 112 | |
---|
[5270] | 113 | if (ierr.ne.nf90_noerr) then |
---|
[1980] | 114 | write(*,*) "***** PUT_VAR matter in writediagfi_nc" |
---|
| 115 | write(*,*) "***** with time" |
---|
| 116 | write(*,*) 'ierr=', ierr |
---|
| 117 | endif |
---|
| 118 | |
---|
| 119 | ! write(6,*)'WRITEDIAGFI: date= ', date |
---|
| 120 | end if ! of if (nom.eq.firstnom) |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | !Case of a 3D variable |
---|
| 124 | !--------------------- |
---|
[5450] | 125 | if (llm==lmax) then |
---|
[1980] | 126 | ndim=4 |
---|
| 127 | corner(1)=1 |
---|
| 128 | corner(2)=1 |
---|
| 129 | corner(3)=1 |
---|
| 130 | corner(4)=ntime |
---|
| 131 | edges(1)=imax |
---|
| 132 | edges(2)=jmax |
---|
| 133 | edges(3)=llm |
---|
| 134 | edges(4)=1 |
---|
| 135 | dim_cc=dim_coord |
---|
| 136 | |
---|
| 137 | !Case of a 2D variable |
---|
| 138 | !--------------------- |
---|
| 139 | |
---|
| 140 | else if (llm==1) then |
---|
| 141 | ndim=3 |
---|
| 142 | corner(1)=1 |
---|
| 143 | corner(2)=1 |
---|
| 144 | corner(3)=ntime |
---|
| 145 | corner(4)=1 |
---|
| 146 | edges(1)=imax |
---|
| 147 | edges(2)=jmax |
---|
| 148 | edges(3)=1 |
---|
| 149 | edges(4)=1 |
---|
| 150 | dim_cc(1:2)=dim_coord(1:2) |
---|
| 151 | dim_cc(3)=dim_coord(4) |
---|
| 152 | |
---|
| 153 | endif ! of if llm=1 ou llm |
---|
| 154 | |
---|
| 155 | ! AU premier pas de temps, on crée les variables |
---|
| 156 | !----------------------------------------------- |
---|
| 157 | |
---|
| 158 | if (ntime==1) then |
---|
[5270] | 159 | ierr = nf90_redef (nid) |
---|
[5450] | 160 | ierr = nf90_def_var(nid,nom,nf90_float,dim_cc(1:ndim),varid) |
---|
[3978] | 161 | !print*,'DEF ',nom,nid,varid |
---|
[5270] | 162 | ierr = nf90_enddef(nid) |
---|
[1980] | 163 | else |
---|
[5270] | 164 | ierr= nf90_inq_varid(nid,nom,varid) |
---|
[3978] | 165 | !print*,'INQ ',nom,nid,varid |
---|
[1980] | 166 | ! Commandes pour recuperer automatiquement les coordonnees |
---|
[5270] | 167 | ! ierr= nf90_inq_dimid(nid,"longitude",id(1)) |
---|
[1980] | 168 | endif |
---|
| 169 | |
---|
| 170 | |
---|
[4259] | 171 | ierr= NF90_PUT_VAR(nid,varid,zx,corner,edges) |
---|
[1980] | 172 | |
---|
[5270] | 173 | if (ierr.ne.nf90_noerr) then |
---|
[1980] | 174 | write(*,*) "***** PUT_VAR problem in writediagfi" |
---|
| 175 | write(*,*) "***** with ",nom |
---|
| 176 | write(*,*) 'ierr=', ierr |
---|
| 177 | endif |
---|
| 178 | |
---|
| 179 | |
---|
[5390] | 180 | end subroutine iotd_ecrit |
---|