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

Last change on this file since 5133 was 5128, checked in by abarral, 5 months ago

Correct bug in vlspltqs_loc.f90 from r2270 where we call SSUM with incorrect arguments.
Merge the three different versions of abort_gcm into one
Fix seq, para 3D compilation broken from r5107 onwards
(lint) usual + Remove uneeded fixed-form continuations

  • 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.6 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  CHARACTER(LEN = 10) :: name, file
22  CHARACTER(LEN = 10) :: titlevar
23
24  !   local
25
26  INTEGER :: im, jm, lm, i, j, l, iv, iii, iji, iif, ijf
27
28  LOGICAL :: writectl
29
30  writectl = .FALSE.
31
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)
40
41  PRINT*, 'im,jm,lm,name,firsttime(if)'
42  PRINT*, im, jm, lm, name, firsttime(if)
43
44  IF(firsttime(if)) THEN
45    IF(name==var(1, if)) THEN
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
67    IF (ivar(if)==nvar(if)) THEN
68      writectl = .TRUE.
69      itime(if) = itime(if) + 1
70    endif
71
72    IF(var(ivar(if), if)/=name) THEN
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
81  ENDIF
82
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
90    WRITE(unit(if) + 1, rec = irec(if)) &
91            ((field((l - 1) * imd(if) * jmd(if) + (j - 1) * imd(if) + i) &
92                    , i = iii, iif), j = iji, ijf)
93  enddo
94  IF (writectl) THEN
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')
99    WRITE(unit(if), '(a5,1x,a40)') &
100            'DSET ', '^' // trim(file) // '.dat'
101
102    WRITE(unit(if), '(a12)') 'UNDEF 1.0E30'
103    WRITE(unit(if), '(a5,1x,a40)') 'TITLE ', title(if)
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')
107    WRITE(unit(if), '(a4,i10,a30)') &
108            'TDEF ', itime(if), ' LINEAR 02JAN1987 1MO '
109    WRITE(unit(if), '(a4,2x,i5)') 'VARS', nvar(if)
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)
113      WRITE(unit(if), 1000) var(iv, if), nld(iv, if) - 1 / nld(iv, if) &
114              , 99, tvar(iv, if)
115    enddo
116    WRITE(unit(if), '(a7)') 'ENDVARS'
117    !
118    1000   format(a5, 3x, i4, i3, 1x, a39)
119
120    close(unit(if))
121
122  ENDIF ! writectl
123
124END SUBROUTINE wrgrads
125
Note: See TracBrowser for help on using the repository browser.