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