source: LMDZ6/branches/Amaury_dev/libf/dyn3dmem/wrgrads.f90 @ 5327

Last change on this file since 5327 was 5159, checked in by abarral, 3 months ago

Put dimensions.h and paramet.h into modules

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