source: CPL/oasis3/trunk/src/mod/oasis3/src/correct.f @ 1677

Last change on this file since 1677 was 1677, checked in by aclsce, 12 years ago

Imported oasis3 (tag ipslcm5a) from cvs server to svn server (igcmg project).

File size: 5.5 KB
Line 
1      SUBROUTINE correct (pfild, ksize, pmcoef, kaux, pacoef, pwork,
2     $                    kunit, cdfic, cdfld)
3C****
4C               *****************************
5C               * OASIS ROUTINE  -  LEVEL 3 *
6C               * -------------     ------- *
7C               *****************************
8C
9C**** *correct* - Flux correction routine
10C
11C     Purpose:
12C     -------
13C     Use external data to modify coupling fields
14C
15C**   Interface:
16C     ---------
17C       *CALL*  *correct (pfild, ksize, pmcoef, kaux, pacoef, pwork,
18C                         kunit, cdfic, cdfld)*
19C
20C     Input:
21C     -----
22C                pfild  : field on source grid (real 1D)
23C                ksize  : size of field array (integer)
24C                pmcoef : main field coefficient (real)
25C                kaux   : number of auxilary fields (integer)
26C                pacoef : auxilary field coefficients (real 1D)
27C                pwork  : temporary array to read auxilary fields (real 1D)
28C                kunit  : logical unit numbers for data files (INTEGER 1D)
29C                cdfic  : filenames for external data (character 1D)
30C                cdfld  : auxilary field names (character 1D) 
31C
32C     Output:
33C     ------
34C                pfild  : corrected field on source grid  (real 1D)
35C
36C     Workspace:
37C     ---------
38C     None
39C
40C     Externals:
41C     ---------
42C     None
43C
44C     Reference:
45C     ---------
46C     See OASIS manual (1995)
47C
48C     History:
49C     -------
50C       Version   Programmer     Date      Description
51C       -------   ----------     ----      ----------- 
52C       2.0       L. Terray      95/10/01  created
53C       2.3       S. Valcke      99/04/30  added: printing levels
54C
55C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56C
57C* ---------------------------- Include files ---------------------------
58C
59      USE mod_kinds_oasis
60      USE mod_unit
61      USE mod_printing
62C
63C* ---------------------------- Argument declarations -------------------
64C
65      REAL (kind=ip_realwp_p) pfild(ksize), pwork(ksize), pacoef(kaux)
66      INTEGER (kind=ip_intwp_p) kunit(kaux)
67      CHARACTER*8 cdfic(kaux), cdfld(kaux)
68C
69C* ---------------------------- Local declarations ----------------------
70C
71      CHARACTER*8 clfic
72C
73C* ---------------------------- Poema verses ----------------------------
74C
75C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76C
77C*    1. Initialization
78C        --------------
79C
80      IF (nlogprt .GE. 2) THEN
81          WRITE (UNIT = nulou,FMT = *) ' '
82          WRITE (UNIT = nulou,FMT = *) ' '
83          WRITE (UNIT = nulou,FMT = *) 
84     $    '           ROUTINE correct  -  Level 3'
85          WRITE (UNIT = nulou,FMT = *) 
86     $    '           ***************     *******'
87          WRITE (UNIT = nulou,FMT = *) ' '
88          WRITE (UNIT = nulou,FMT = *) 
89     $    ' Flux correction with external data'
90          WRITE (UNIT = nulou,FMT = *) ' '
91          WRITE (UNIT = nulou,FMT = *) ' '
92      ENDIF
93C
94C* initialize error flag for I/O routine
95C
96      iflag = 0
97C
98C
99C*    2. Multiply main field by its coefficient
100C        --------------------------------------
101C
102      DO 210 ji = 1, ksize
103        pfild(ji) = pfild(ji) * pmcoef
104 210  CONTINUE
105C
106C
107C*    3. Read external data and add it to main field
108C        -------------------------------------------
109C
110C* Loop on additional fields
111C
112      DO 310 ji = 1, kaux
113C
114C* Flush data files
115C
116        iunit = kunit(ji)
117        clfic = cdfic(ji)
118        CLOSE(UNIT = iunit, ERR = 3010, IOSTAT = ios)
119        WRITE(UNIT = nulou, FMT = 3100) iunit, clfic
120 3010   CONTINUE
121        IF (ios .NE. 0) THEN
122            CALL prtout('WARNING: problem in closing unit',
123     $          iunit, 1)
124            CALL prtout('Error message number is = ', ios, 1)
125            CALL HALTE('STOP in correct')
126        ENDIF
127        OPEN(UNIT=iunit,FILE=clfic,FORM='UNFORMATTED',
128     $      STATUS='UNKNOWN',ERR = 3020, IOSTAT = ios)
129        WRITE(UNIT = nulou, FMT = 3200) iunit, clfic
130 3020   CONTINUE
131        IF (ios .NE. 0) THEN
132            CALL prtout('WARNING: problem in connecting unit',
133     $          iunit, 1)
134            CALL prtout('Error message number is = ', ios, 1)
135            CALL HALTE('STOP in correct')
136        ENDIF
137C
138C* Reading of the auxilary fields
139C
140        CALL locread (cdfld(ji), pwork, ksize, kunit(ji), iflag)
141C
142C* Checking
143C
144        IF (iflag .NE. 0) THEN
145            CALL prcout
146     $          ('WARNING: problem in reading field',
147     $          cdfld(ji), 1)
148            CALL prtout
149     $          ('Error reading logical unit', kunit(ji), 1)
150            CALL prcout
151     $          ('It is connected to file',cdfic(ji),1)
152            WRITE(UNIT = nulou,FMT = *) 
153     $          ' If very first iteration and parallel simulation '
154            WRITE(UNIT = nulou,FMT = *)
155     $          ' or sequential one starting with atmosphere '
156            WRITE(UNIT = nulou,FMT = *)
157     $          ' No file present !! It is normal !! '
158
159        ENDIF
160C
161C* Add to original field
162C
163        DO 320 jj = 1, ksize
164          pfild(jj) = pfild(jj) + pacoef(ji) * pwork(jj)
165 320    CONTINUE
166 310  CONTINUE
167C
168C* Formats
169C
170 3100 FORMAT(/,5X,' Unit ',I2,' has been disconnected from file ',A8)
171 3200 FORMAT(/,5X,' Unit ',I2,' has been reconnected to file ',A8) 
172C
173C
174C*    4. End of routine
175C        --------------
176C
177      IF (nlogprt .GE. 2) THEN
178          WRITE (UNIT = nulou,FMT = *) ' '
179          WRITE (UNIT = nulou,FMT = *) 
180     $    '          --------- End of routine correct ---------'
181          CALL FLUSH (nulou)
182      ENDIF
183      RETURN
184      END
Note: See TracBrowser for help on using the repository browser.