source: LMDZ6/branches/Amaury_dev/libf/dyn3d/wrgrads.f90 @ 5136

Last change on this file since 5136 was 5134, checked in by abarral, 5 months ago

Replace academic.h, alpale.h, comdissip.h, comdissipn.h, comdissnew.h by modules
Remove unused clesph0.h

  • 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
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1! $Header$
2
3subroutine wrgrads(if, nl, field, name, titlevar)
4  USE lmdz_formcoord, ONLY: formcoord
5
6
7  IMPLICIT NONE
8
9  !   Declarations
10  !    if indice du fichier
11  !    nl nombre de couches
12  !    field   champ
13  !    name    petit nom
14  !    titlevar   Titre
15
16  INCLUDE "gradsdef.h"
17
18  !   arguments
19  INTEGER :: if, nl
20  REAL :: field(imx * jmx * lmx)
21
22  INTEGER, parameter :: wp = selected_real_kind(p = 6, r = 36)
23  real(wp) field4(imx * jmx * lmx)
24
25  CHARACTER(LEN = 10) :: name, file
26  CHARACTER(LEN = 10) :: titlevar
27
28  !   local
29
30  INTEGER :: im, jm, lm, i, j, l, iv, iii, iji, iif, ijf
31
32  LOGICAL :: writectl
33
34  writectl = .FALSE.
35
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)
44
45  ! print*,'im,jm,lm,name,firsttime(if)'
46  ! print*,im,jm,lm,name,firsttime(if)
47
48  IF(firsttime(if)) THEN
49    IF(name==var(1, if)) THEN
50      firsttime(if) = .FALSE.
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
67    writectl = .TRUE.
68    itime(if) = 1
69  else
70    ivar(if) = mod(ivar(if), nvar(if)) + 1
71    IF (ivar(if)==nvar(if)) THEN
72      writectl = .TRUE.
73      itime(if) = itime(if) + 1
74    endif
75
76    IF(var(ivar(if), if)/=name) THEN
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
85  ENDIF
86
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
95    WRITE(unit(if) + 1, rec = irec(if)) &
96            ((field4((l - 1) * imd(if) * jmd(if) + (j - 1) * imd(if) + i) &
97                    , i = iii, iif), j = iji, ijf)
98  enddo
99  IF (writectl) THEN
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')
104    WRITE(unit(if), '(a5,1x,a40)') &
105            'DSET ', '^' // trim(file) // '.dat'
106
107    WRITE(unit(if), '(a12)') 'UNDEF 1.0E30'
108    WRITE(unit(if), '(a5,1x,a40)') 'TITLE ', title(if)
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')
112    WRITE(unit(if), '(a4,i10,a30)') &
113            'TDEF ', itime(if), ' LINEAR 02JAN1987 1MO '
114    WRITE(unit(if), '(a4,2x,i5)') 'VARS', nvar(if)
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)
118      WRITE(unit(if), 1000) var(iv, if), nld(iv, if) - 1 / nld(iv, if) &
119              , 99, tvar(iv, if)
120    enddo
121    WRITE(unit(if), '(a7)') 'ENDVARS'
122    !
123    1000   format(a5, 3x, i4, i3, 1x, a39)
124
125    close(unit(if))
126
127  ENDIF ! writectl
128
129END SUBROUTINE wrgrads
130
Note: See TracBrowser for help on using the repository browser.