! $Header$ subroutine wrgrads(if, nl, field, name, titlevar) USE lmdz_formcoord, ONLY: formcoord IMPLICIT NONE ! Declarations ! if indice du fichier ! nl nombre de couches ! field champ ! name petit nom ! titlevar Titre INCLUDE "gradsdef.h" ! arguments INTEGER :: if, nl REAL :: field(imx * jmx * lmx) INTEGER, parameter :: wp = selected_real_kind(p = 6, r = 36) real(wp) field4(imx * jmx * lmx) CHARACTER(LEN = 10) :: name, file CHARACTER(LEN = 10) :: titlevar ! local INTEGER :: im, jm, lm, i, j, l, iv, iii, iji, iif, ijf LOGICAL :: writectl writectl = .FALSE. ! print*,if,iid(if),jid(if),ifd(if),jfd(if) iii = iid(if) iji = jid(if) iif = ifd(if) ijf = jfd(if) im = iif - iii + 1 jm = ijf - iji + 1 lm = lmd(if) ! print*,'im,jm,lm,name,firsttime(if)' ! print*,im,jm,lm,name,firsttime(if) IF(firsttime(if)) THEN IF(name==var(1, if)) THEN firsttime(if) = .FALSE. ivar(if) = 1 print*, 'fin de l initialiation de l ecriture du fichier' print*, file print*, 'fichier no: ', if print*, 'unit ', unit(if) print*, 'nvar ', nvar(if) print*, 'vars ', (var(iv, if), iv = 1, nvar(if)) else ivar(if) = ivar(if) + 1 nvar(if) = ivar(if) var(ivar(if), if) = name tvar(ivar(if), if) = trim(titlevar) nld(ivar(if), if) = nl ! print*,'initialisation ecriture de ',var(ivar(if),if) ! print*,'if ivar(if) nld ',if,ivar(if),nld(ivar(if),if) endif writectl = .TRUE. itime(if) = 1 else ivar(if) = mod(ivar(if), nvar(if)) + 1 IF (ivar(if)==nvar(if)) THEN writectl = .TRUE. itime(if) = itime(if) + 1 endif IF(var(ivar(if), if)/=name) THEN print*, 'Il faut stoker la meme succession de champs a chaque' print*, 'pas de temps' print*, 'fichier no: ', if print*, 'unit ', unit(if) print*, 'nvar ', nvar(if) print*, 'vars ', (var(iv, if), iv = 1, nvar(if)) CALL abort_gcm("wrgrads", "problem", 1) endif ENDIF ! print*,'ivar(if),nvar(if),var(ivar(if),if),writectl' ! print*,ivar(if),nvar(if),var(ivar(if),if),writectl field4(1:imd(if) * jmd(if) * nl) = field(1:imd(if) * jmd(if) * nl) do l = 1, nl irec(if) = irec(if) + 1 ! print*,'Ecrit rec=',irec(if),iii,iif,iji,ijf, ! s (l-1)*imd(if)*jmd(if)+(iji-1)*imd(if)+iii ! s ,(l-1)*imd(if)*jmd(if)+(ijf-1)*imd(if)+iif WRITE(unit(if) + 1, rec = irec(if)) & ((field4((l - 1) * imd(if) * jmd(if) + (j - 1) * imd(if) + i) & , i = iii, iif), j = iji, ijf) enddo IF (writectl) THEN file = fichier(if) ! WARNING! on reecrase le fichier .ctl a chaque ecriture open(unit(if), file = trim(file) // '.ctl' & , form = 'formatted', status = 'unknown') WRITE(unit(if), '(a5,1x,a40)') & 'DSET ', '^' // trim(file) // '.dat' WRITE(unit(if), '(a12)') 'UNDEF 1.0E30' WRITE(unit(if), '(a5,1x,a40)') 'TITLE ', title(if) CALL formcoord(unit(if), im, xd(iii, if), 1., .FALSE., 'XDEF') CALL formcoord(unit(if), jm, yd(iji, if), 1., .TRUE., 'YDEF') CALL formcoord(unit(if), lm, zd(1, if), 1., .FALSE., 'ZDEF') WRITE(unit(if), '(a4,i10,a30)') & 'TDEF ', itime(if), ' LINEAR 02JAN1987 1MO ' WRITE(unit(if), '(a4,2x,i5)') 'VARS', nvar(if) do iv = 1, nvar(if) ! print*,'if,var(iv,if),nld(iv,if),nld(iv,if)-1/nld(iv,if)' ! print*,if,var(iv,if),nld(iv,if),nld(iv,if)-1/nld(iv,if) WRITE(unit(if), 1000) var(iv, if), nld(iv, if) - 1 / nld(iv, if) & , 99, tvar(iv, if) enddo WRITE(unit(if), '(a7)') 'ENDVARS' ! 1000 format(a5, 3x, i4, i3, 1x, a39) close(unit(if)) ENDIF ! writectl END SUBROUTINE wrgrads