[524] | 1 | ! $Header$ |
---|
[5099] | 2 | |
---|
[5103] | 3 | subroutine wrgrads(if, nl, field, name, titlevar) |
---|
[5116] | 4 | USE lmdz_formcoord, ONLY: formcoord |
---|
[5128] | 5 | |
---|
| 6 | |
---|
[5113] | 7 | IMPLICIT NONE |
---|
[524] | 8 | |
---|
[5103] | 9 | ! Declarations |
---|
| 10 | ! if indice du fichier |
---|
| 11 | ! nl nombre de couches |
---|
| 12 | ! field champ |
---|
| 13 | ! name petit nom |
---|
| 14 | ! titlevar Titre |
---|
[524] | 15 | |
---|
[5134] | 16 | INCLUDE "gradsdef.h" |
---|
[524] | 17 | |
---|
[5103] | 18 | ! arguments |
---|
[5116] | 19 | INTEGER :: if, nl |
---|
| 20 | REAL :: field(imx * jmx * lmx) |
---|
[1025] | 21 | |
---|
[5117] | 22 | INTEGER, parameter :: wp = selected_real_kind(p = 6, r = 36) |
---|
[5103] | 23 | real(wp) field4(imx * jmx * lmx) |
---|
[1025] | 24 | |
---|
[5116] | 25 | CHARACTER(LEN = 10) :: name, file |
---|
| 26 | CHARACTER(LEN = 10) :: titlevar |
---|
[524] | 27 | |
---|
[5103] | 28 | ! local |
---|
[524] | 29 | |
---|
[5116] | 30 | INTEGER :: im, jm, lm, i, j, l, iv, iii, iji, iif, ijf |
---|
[524] | 31 | |
---|
[5117] | 32 | LOGICAL :: writectl |
---|
[524] | 33 | |
---|
[5117] | 34 | writectl = .FALSE. |
---|
[524] | 35 | |
---|
[5103] | 36 | ! print*,if,iid(if),jid(if),ifd(if),jfd(if) |
---|
| 37 | iii = iid(if) |
---|
| 38 | iji = jid(if) |
---|
| 39 | iif = ifd(if) |
---|
| 40 | ijf = jfd(if) |
---|
| 41 | im = iif - iii + 1 |
---|
| 42 | jm = ijf - iji + 1 |
---|
| 43 | lm = lmd(if) |
---|
[524] | 44 | |
---|
[5103] | 45 | ! print*,'im,jm,lm,name,firsttime(if)' |
---|
| 46 | ! print*,im,jm,lm,name,firsttime(if) |
---|
[524] | 47 | |
---|
[5116] | 48 | IF(firsttime(if)) THEN |
---|
| 49 | IF(name==var(1, if)) THEN |
---|
[5117] | 50 | firsttime(if) = .FALSE. |
---|
[5103] | 51 | ivar(if) = 1 |
---|
| 52 | print*, 'fin de l initialiation de l ecriture du fichier' |
---|
| 53 | print*, file |
---|
| 54 | print*, 'fichier no: ', if |
---|
| 55 | print*, 'unit ', unit(if) |
---|
| 56 | print*, 'nvar ', nvar(if) |
---|
| 57 | print*, 'vars ', (var(iv, if), iv = 1, nvar(if)) |
---|
| 58 | else |
---|
| 59 | ivar(if) = ivar(if) + 1 |
---|
| 60 | nvar(if) = ivar(if) |
---|
| 61 | var(ivar(if), if) = name |
---|
| 62 | tvar(ivar(if), if) = trim(titlevar) |
---|
| 63 | nld(ivar(if), if) = nl |
---|
| 64 | ! print*,'initialisation ecriture de ',var(ivar(if),if) |
---|
| 65 | ! print*,'if ivar(if) nld ',if,ivar(if),nld(ivar(if),if) |
---|
| 66 | endif |
---|
[5117] | 67 | writectl = .TRUE. |
---|
[5103] | 68 | itime(if) = 1 |
---|
| 69 | else |
---|
| 70 | ivar(if) = mod(ivar(if), nvar(if)) + 1 |
---|
[5117] | 71 | IF (ivar(if)==nvar(if)) THEN |
---|
| 72 | writectl = .TRUE. |
---|
[5103] | 73 | itime(if) = itime(if) + 1 |
---|
| 74 | endif |
---|
[524] | 75 | |
---|
[5116] | 76 | IF(var(ivar(if), if)/=name) THEN |
---|
[5103] | 77 | print*, 'Il faut stoker la meme succession de champs a chaque' |
---|
| 78 | print*, 'pas de temps' |
---|
| 79 | print*, 'fichier no: ', if |
---|
| 80 | print*, 'unit ', unit(if) |
---|
| 81 | print*, 'nvar ', nvar(if) |
---|
| 82 | print*, 'vars ', (var(iv, if), iv = 1, nvar(if)) |
---|
| 83 | CALL abort_gcm("wrgrads", "problem", 1) |
---|
| 84 | endif |
---|
[5117] | 85 | ENDIF |
---|
[524] | 86 | |
---|
[5103] | 87 | ! print*,'ivar(if),nvar(if),var(ivar(if),if),writectl' |
---|
| 88 | ! print*,ivar(if),nvar(if),var(ivar(if),if),writectl |
---|
| 89 | field4(1:imd(if) * jmd(if) * nl) = field(1:imd(if) * jmd(if) * nl) |
---|
| 90 | do l = 1, nl |
---|
| 91 | irec(if) = irec(if) + 1 |
---|
| 92 | ! print*,'Ecrit rec=',irec(if),iii,iif,iji,ijf, |
---|
| 93 | ! s (l-1)*imd(if)*jmd(if)+(iji-1)*imd(if)+iii |
---|
| 94 | ! s ,(l-1)*imd(if)*jmd(if)+(ijf-1)*imd(if)+iif |
---|
[5116] | 95 | WRITE(unit(if) + 1, rec = irec(if)) & |
---|
[5103] | 96 | ((field4((l - 1) * imd(if) * jmd(if) + (j - 1) * imd(if) + i) & |
---|
| 97 | , i = iii, iif), j = iji, ijf) |
---|
| 98 | enddo |
---|
[5117] | 99 | IF (writectl) THEN |
---|
[5103] | 100 | file = fichier(if) |
---|
| 101 | ! WARNING! on reecrase le fichier .ctl a chaque ecriture |
---|
| 102 | open(unit(if), file = trim(file) // '.ctl' & |
---|
| 103 | , form = 'formatted', status = 'unknown') |
---|
[5116] | 104 | WRITE(unit(if), '(a5,1x,a40)') & |
---|
[5103] | 105 | 'DSET ', '^' // trim(file) // '.dat' |
---|
[524] | 106 | |
---|
[5116] | 107 | WRITE(unit(if), '(a12)') 'UNDEF 1.0E30' |
---|
| 108 | WRITE(unit(if), '(a5,1x,a40)') 'TITLE ', title(if) |
---|
[5117] | 109 | CALL formcoord(unit(if), im, xd(iii, if), 1., .FALSE., 'XDEF') |
---|
| 110 | CALL formcoord(unit(if), jm, yd(iji, if), 1., .TRUE., 'YDEF') |
---|
| 111 | CALL formcoord(unit(if), lm, zd(1, if), 1., .FALSE., 'ZDEF') |
---|
[5116] | 112 | WRITE(unit(if), '(a4,i10,a30)') & |
---|
[5103] | 113 | 'TDEF ', itime(if), ' LINEAR 02JAN1987 1MO ' |
---|
[5116] | 114 | WRITE(unit(if), '(a4,2x,i5)') 'VARS', nvar(if) |
---|
[5103] | 115 | do iv = 1, nvar(if) |
---|
| 116 | ! print*,'if,var(iv,if),nld(iv,if),nld(iv,if)-1/nld(iv,if)' |
---|
| 117 | ! print*,if,var(iv,if),nld(iv,if),nld(iv,if)-1/nld(iv,if) |
---|
[5116] | 118 | WRITE(unit(if), 1000) var(iv, if), nld(iv, if) - 1 / nld(iv, if) & |
---|
[5103] | 119 | , 99, tvar(iv, if) |
---|
| 120 | enddo |
---|
[5116] | 121 | WRITE(unit(if), '(a7)') 'ENDVARS' |
---|
[5103] | 122 | ! |
---|
| 123 | 1000 format(a5, 3x, i4, i3, 1x, a39) |
---|
[524] | 124 | |
---|
[5103] | 125 | close(unit(if)) |
---|
[524] | 126 | |
---|
[5117] | 127 | ENDIF ! writectl |
---|
[524] | 128 | |
---|
[5103] | 129 | END SUBROUTINE wrgrads |
---|
[524] | 130 | |
---|