New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
diadimg.F90 in trunk/NEMO/OPA_SRC/DIA – NEMO

source: trunk/NEMO/OPA_SRC/DIA/diadimg.F90 @ 1685

Last change on this file since 1685 was 1685, checked in by smasson, 15 years ago

cleaning of logical units (use, flush and close), see ticket:570

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.8 KB
Line 
1MODULE diadimg
2   !!======================================================================
3   !!                     ***  MODULE  diadimg  ***
4   !! Ocean diagnostics :  write ocean output files in dimg direct access format (mpp)
5   !!=====================================================================
6# if defined key_dimgout
7   !!----------------------------------------------------------------------
8   !! * Modules used
9   USE oce             ! ocean dynamics and tracers
10   USE dom_oce         ! ocean space and time domain
11   USE in_out_manager  ! I/O manager
12   USE daymod          ! calendar
13
14   IMPLICIT NONE
15   PRIVATE
16
17   !! * Accessibility
18   PUBLIC dia_wri_dimg            ! called by trd_mld (eg)
19
20   !! * Substitutions
21#  include "domzgr_substitute.h90"
22   !!----------------------------------------------------------------------
23   !!   OPA 9.0 , LOCEAN-IPSL (2005)
24   !! $Id$
25   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
26   !!----------------------------------------------------------------------
27
28CONTAINS
29
30  SUBROUTINE dia_wri_dimg(cd_name, cd_text, ptab, klev, cd_type , ksubi )
31    !!-------------------------------------------------------------------------
32    !!        *** ROUTINE dia_wri_dimg ***
33    !!
34    !! ** Purpose : write ptab in the dimg file cd_name, with comment cd_text.
35    !!       ptab has klev x 2D fields
36    !!
37    !! ** Action :
38    !!       Define header variables from the config parameters
39    !!       Open the dimg file on unit inum = 14 ( IEEE I4R4 file )
40    !!       Write header on record 1
41    !!       Write ptab on the following klev records
42    !!
43    !! History :
44    !!   03-12 (J.M. Molines ) : Original. Replace ctl_opn, writn2d
45    !!---------------------------------------------------------------------------
46    !! * Arguments
47    CHARACTER(len=*),INTENT(in) ::   &
48         &                            cd_name,  &  ! dimg file name
49         &                            cd_text      ! comment to write on record #1
50    INTEGER, INTENT(in) ::            klev         ! number of level in ptab to write
51    REAL(wp),INTENT(in), DIMENSION(:,:,:) :: ptab  ! 3D array to write
52    CHARACTER(LEN=1),INTENT(in) ::    cd_type      ! either 'T', 'W' or '2' , depending on the vertical
53    !                                              ! grid for ptab. 2 stands for 2D file
54    INTEGER, INTENT(in), OPTIONAL, DIMENSION(klev) :: ksubi 
55
56    !! * Local declarations
57    INTEGER :: jk, jn           ! dummy loop indices
58    INTEGER :: irecl4,             &    ! record length in bytes
59         &       inum,             &    ! logical unit
60         &       irec                   ! current record to be written
61    REAL(sp)                    :: zdx,zdy,zspval,zwest,ztimm
62    REAL(sp)                    :: zsouth
63    REAL(sp),DIMENSION(jpi,jpj) :: z42d        ! 2d temporary workspace (sp)
64    REAL(sp),DIMENSION(jpk)     :: z4dep       ! vertical level (sp)
65
66    CHARACTER(LEN=80) :: clname                ! name of file in case of dimgnnn
67    CHARACTER(LEN=4) :: clver='@!01'           ! dimg string identifier
68    !!---------------------------------------------------------------------------
69
70    !! * Initialisations
71
72    irecl4 = MAX(jpi*jpj*sp , 84+18*sp + (jpk+8)*jpnij*sp  )
73
74    zspval=0.0_sp    ! special values on land
75    !  the 'numerical' grid is described. The geographical one is in a grid file
76    zdx=1._sp
77    zdy=1._sp
78    zsouth=njmpp * 1._sp
79    zwest=nimpp * 1._sp
80    !  time in days since the historical begining of the run (nit000 = 0 )
81    ztimm=adatrj
82
83    SELECT CASE ( cd_type )
84
85    CASE ( 'T')
86       z4dep(:)=gdept_0(:)
87
88    CASE ( 'W' )
89       z4dep(:)=gdepw_0(:)
90
91    CASE ( '2' )
92       z4dep(1:klev) =(/(jk, jk=1,klev)/)
93
94    CASE ( 'I' )
95       z4dep(1:klev) = ksubi(1:klev)
96
97    CASE DEFAULT
98       IF(lwp) WRITE(numout,*) ' E R R O R : bad cd_type in dia_wri_dimg '
99       STOP 'dia_wri_dimg'
100
101    END SELECT
102
103    IF ( ln_dimgnnn  ) THEN
104       WRITE(clname,'(a,a,i3.3)') TRIM(cd_name),'.',narea
105       CALL ctl_opn( inum, clname, 'REPLACE', 'UNFORMATTED', 'DIRECT', irecl4, numout, lwp )
106       WRITE(inum,REC=1 ) clver, cd_text, irecl4, &
107            &     jpi,jpj, klev, 1 , 1 ,            &
108            &     zwest, zsouth, zdx, zdy, zspval,  &
109            &     z4dep(1:klev),                    &
110            &     ztimm,                            &
111            &     narea, jpnij,jpiglo,jpjglo,jpizoom, jpjzoom,    &    ! extension to dimg for mpp output
112            &     nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt  !
113
114       !! * Write klev levels
115       IF ( cd_type == 'I' ) THEN
116
117          DO jk = 1, klev
118             irec =1 + jk
119             z42d(:,:) = ptab(:,:,ksubi(jk))
120             WRITE(inum,REC=irec)  z42d(:,:)
121          END DO
122       ELSE
123          DO jk = 1, klev
124             irec =1 + jk
125             z42d(:,:) = ptab(:,:,jk)
126             WRITE(inum,REC=irec)  z42d(:,:)
127          END DO
128       ENDIF
129    ELSE
130       !! Standard dimgproc (1 file per variable, all procs. write to this file )
131       !! * Open file
132       CALL ctl_opn( inum, cd_name, 'REPLACE', 'UNFORMATTED', 'DIRECT', irecl4, numout, lwp )
133
134       !! * Write header on record #1
135       IF(lwp) WRITE(inum,REC=1 ) clver, cd_text, irecl4, &
136            &     jpi,jpj, klev*jpnij, 1 , 1 ,            &
137            &     zwest, zsouth, zdx, zdy, zspval,  &
138            &     (z4dep(1:klev),jn=1,jpnij),       &
139            &     ztimm,                            &
140            &     narea, jpnij,jpiglo,jpjglo,jpizoom, jpjzoom,    &    ! extension to dimg for mpp output
141            &     nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt  !
142
143       !! * Write klev levels
144       IF ( cd_type == 'I' ) THEN
145
146          DO jk = 1, klev
147             irec =1 + klev * (narea -1) + jk
148             z42d(:,:) = ptab(:,:,ksubi(jk))
149             WRITE(inum,REC=irec)  z42d(:,:)
150          END DO
151       ELSE
152          DO jk = 1, klev
153             irec =1 + klev * (narea -1) + jk
154             z42d(:,:) = ptab(:,:,jk)
155             WRITE(inum,REC=irec)  z42d(:,:)
156          END DO
157       ENDIF
158    ENDIF
159
160    !! * Close the file
161    CLOSE(inum)
162
163  END SUBROUTINE dia_wri_dimg
164
165#  else
166   !!----------------------------------------------------------------------
167   !!   Default option :                                       Empty module
168   !!----------------------------------------------------------------------
169CONTAINS
170
171   SUBROUTINE dia_wri_dimg( cd_name, cd_exper, ptab, klev, cd_type )
172      REAL, DIMENSION(:,:,:) :: ptab
173      INTEGER :: klev
174      CHARACTER(LEN=80) :: cd_name, cd_exper,cd_type
175      WRITE(*,*) ' This print must never occur ', cd_name, cd_exper,ptab, klev, cd_type
176      WRITE(*,*) ' this routine is here just for compilation '
177   END SUBROUTINE dia_wri_dimg
178# endif
179   !!======================================================================
180END MODULE diadimg
Note: See TracBrowser for help on using the repository browser.