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