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