source: CPL/oasis3/trunk/src/mod/oasis3/src/preproc.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: 11.6 KB
Line 
1      SUBROUTINE preproc (kindex, kfield)
2      USE mod_kinds_oasis
3C****
4C               *****************************
5C               * OASIS ROUTINE  -  LEVEL 1 *
6C               * -------------     ------- *
7C               *****************************
8C
9C**** *preproc* - preprocess routine
10C
11C
12C     Purpose:
13C     -------
14C     Do the field preprocessing
15C
16C**   Interface:
17C     ---------
18C       *CALL*  *preproc (kindex, kfield)*
19C
20C     Input:
21C     -----
22C                kindex : field identificator array (integer 1D)
23C                kfield : number of fields for current iteration (integer)
24C
25C     Output:
26C     ------
27C     None
28C
29C     Workspace:
30C     ---------
31C                zcocoef : additional field coefficients for correct (real 1D)
32C                inip    : array for reduced grid data for redglo (integer 1D)
33C                clcofld : additional field names for correct (character 1D)
34C                clcofic : array to handle data file names (character 1D)
35C                iunit   : array to handle I/O units of data files (integer 1D)
36C
37C     Externals:
38C     ---------
39C     correct, extrap, extraw, invert, masq, redglo, chkfld
40C
41C     Reference:
42C     ---------
43C     See OASIS manual (1998)
44C
45C     History:
46C     -------
47C       Version   Programmer     Date      Description
48C       -------   ----------     ----      ----------- 
49C       2.0       L. Terray      95/09/01  created
50C       2.1       L. Terray      96/09/25  modified: Call to chkfld
51C       2.2       L. Terray      97/12/16  Added: new extrapolation
52C                                          and change call to extrap
53C       2.3       L. Terray      99/03/01  modified: call to extrap
54C       2.3       S. Valcke      99/03/16  modified for T213 and T319
55C       2.3       S. Valcke      99/03/16  modified for T213 and T319
56C       2.3       S. Valcke      99/03/26  changed troncature for number of 
57C                                          latitude between equator and pole
58C       2.3       S. Valcke      99/03/30  changed arguments in CALL to extrap
59C       2.3       S. Valcke      99/04/30  added: printing levels
60C       2.3       L. Terray      99/09/15  changed periodicity variables
61C       2.5       S. Valcke      00/09/05  Changed iintflx for itinpflx 
62C
63C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64C
65C* -----------------Include files and USE of modules---------------------------
66C
67      USE mod_parameter
68      USE mod_string
69      USE mod_analysis
70      USE mod_memory
71      USE mod_extrapol
72      USE mod_unit
73      USE mod_gauss
74      USE mod_label
75      USE mod_printing
76C
77C* ---------------------------- Argument declarations -------------------
78C
79      INTEGER (kind=ip_intwp_p) kindex(kfield)
80C
81C* ---------------------------- Local declarations ----------------------
82C
83      INTEGER (kind=ip_intwp_p) inip(320)
84      INTEGER (kind=ip_intwp_p), DIMENSION(:), ALLOCATABLE :: iunit
85      REAL (kind=ip_realwp_p),DIMENSION(:), ALLOCATABLE :: zcocoef
86      CHARACTER*8 clxordbf, clyordbf, clextmet, clname, clmsk, clper
87      CHARACTER*8 clfic, clstrg
88      CHARACTER(len=8), DIMENSION(:), ALLOCATABLE :: clcofic, clcofld
89      CHARACTER*32 clabel
90C
91C* ---------------------------- Poema verses ----------------------------
92C
93C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94C
95C*    1. Initialization and allocation of local arrays
96C        ---------------------------------------------
97C
98      IF (nlogprt .GE. 1) THEN
99          WRITE (UNIT = nulou,FMT = *) ' '
100          WRITE (UNIT = nulou,FMT = *) ' '
101          WRITE (UNIT = nulou,FMT = *) 
102     $    '           ROUTINE preproc  -  Level 1'
103          WRITE (UNIT = nulou,FMT = *) 
104     $    '           ***************     *******'
105          WRITE (UNIT = nulou,FMT = *) ' '
106          WRITE (UNIT = nulou,FMT = *) 
107     $    ' Preprocessing of coupling fields'
108          WRITE (UNIT = nulou,FMT = *) ' '
109          WRITE (UNIT = nulou,FMT = *) ' '
110      ENDIF
111C
112      ALLOCATE (iunit(ig_maxcomb),stat=il_err)
113      IF (il_err.NE.0) CALL prtout ('Error in "iunit" allocation of
114     $    cookart ',il_err,1)
115      ALLOCATE (zcocoef(ig_maxcomb),stat=il_err)
116      IF (il_err.NE.0) CALL prtout ('Error in "zcocoef" allocation of
117     $    cookart ',il_err,1)
118      ALLOCATE (clcofic(ig_maxcomb),stat=il_err)
119      IF (il_err.NE.0) CALL prtout ('Error in "clcofic" allocation of
120     $    cookart ',il_err,1)
121      ALLOCATE (clcofld(ig_maxcomb),stat=il_err)
122      IF (il_err.NE.0) CALL prtout ('Error in "clcofld" allocation of
123     $    cookart ',il_err,1)
124      iunit(:)=0
125      zcocoef(:)=0
126      clcofic(:)=' '
127      clcofld(:)=' '
128C
129C* Zeroes work array
130C
131      CALL szero (work,ig_work)
132      CALL izero (nwork,ig_nwork)
133C
134C
135C*    2. Do the job
136C        ----------
137!$omp parallel do default (shared)
138!$omp+ private (ja,jf,ji,jc)
139!$omp+ private (ifield,clname,ilataf)
140!$omp+ private (clabel,clextmet,ineibor)
141!$omp+ private (ipdeb,ilatbf,ilonbf)
142!$omp+ private (iadrold,iadrold_grid,isizold)
143!$omp+ private (clfic,ilun,clper)
144!$omp+ private (clstrg,ilabel)
145!$omp+ private (iloc,clintmet,clgrdtyp,clfldtyp)
146!$omp+ private (icofld)
147!$omp+ private (clfilfic,itinpflx,zfldcoef)
148!$omp+ private (iper,itronca,clmsk,iredu)
149!$omp+ private (zmskval,clxordbf,clyordbf)
150
151C
152      DO 210 jf = 1, kfield
153C
154C* Assign local variables
155C
156        ifield = kindex(jf)
157        ilabel = numlab(ifield)
158        clname = cnaminp(ifield)
159        clabel = cfldlab(ilabel)
160        iadrold = nadrold(ifield)
161        iadrold_grid = nadrold_grid(ifield)
162        isizold = nsizold(ifield)
163        ilonbf = nlonbf(ifield)
164        ilatbf = nlatbf(ifield)
165        itinpflx = ntinpflx(ifield)
166C
167C* Print field name
168C
169        IF (nlogprt .GE. 1) THEN
170            CALL prcout('Treatment of field :', clname, 2)
171        ENDIF
172C
173C* - Do preprocessing analysis
174C
175        DO 220 ja = 1, ig_ntrans(ifield)
176          IF (canal(ja,ifield) .EQ. 'MASK') THEN
177C
178C* --->>> Mask
179C
180              zmskval = amskval(ifield)
181!$omp critical
182              CALL masq (fldold(iadrold), isizold, zmskval,
183     $                   mskold(iadrold_grid))
184!$omp end critical
185C
186C* --->>> Invert
187C
188            ELSE IF (canal(ja,ifield) .EQ. 'INVERT') THEN
189              clxordbf = cxordbf(ifield)
190              clyordbf = cyordbf(ifield)
191              CALL invert (fldold(iadrold), ilonbf,
192     $                     ilatbf, clxordbf, clyordbf)
193C
194C* --->>> Checkin: perform basic checks on input field
195C
196            ELSE IF (canal(ja,ifield) .EQ. 'CHECKIN') THEN
197              CALL chkfld(clname, clabel, 
198     $            fldold(iadrold), mskold(iadrold_grid), 
199     $              surold(iadrold_grid),
200     $            isizold, ilonbf, itinpflx)
201C
202C* --->>> Flux correction
203C
204            ELSE IF (canal(ja,ifield) .EQ. 'CORRECT') THEN
205C
206C* Assign local variables to main field coefficient
207C
208              zfldcoef = afldcoef(ifield)
209C
210C* Get loop index to read additional fields, coefficients, filenames
211C  and related logical units
212C
213              icofld = ncofld(ifield)
214              DO 230 jc = 1, icofld
215                clcofld(jc) = ccofld(jc,ifield)
216                zcocoef(jc) = acocoef(jc,ifield)
217                clcofic(jc) = ccofic(jc,ifield)
218                iunit(jc)   = nludat(jc,ifield)
219 230          CONTINUE
220C
221C* Zero work array
222C
223              CALL szero (work, ig_work)
224C
225C* Do the job
226C 
227              CALL correct (fldold(iadrold), isizold,
228     $                      zfldcoef, icofld, zcocoef(1),
229     $                      work(1), iunit(1), clcofic(1), 
230     $                      clcofld(1))
231C
232C* --->>> Extrap
233C
234            ELSE IF (canal(ja,ifield) .EQ. 'EXTRAP') THEN
235              clextmet = cextmet(ifield)
236              ineibor = neighbor(ifield)
237C
238C* 8-nearest neighbors extrapolation
239C
240              IF (clextmet .EQ. 'NINENN') THEN
241                  zmskval = amskval(ifield)
242                  clper = csper(ifield)
243                  iper = nosper(ifield)
244C
245C* Zero work array
246C
247                  CALL szero (work, ig_work)
248C
249C* Do it now
250C
251#ifdef key_openmp
252                  niwtn=0
253#endif
254!$omp critical
255                  CALL extrap (fldold(iadrold), zmskval, work(1),
256     $                         mskold(iadrold_grid), ilonbf, ilatbf, 
257     $                         ineibor, clextmet, clper, iper, 
258     $                         niwtn(ifield), nninnfl(ifield))
259C
260!$omp end critical
261C* N-weighted neighbors extrapolation
262C
263              ELSE IF (clextmet .EQ. 'WEIGHT') THEN
264                  clfic = cgrdext(ifield)
265                  ilun  = nluext(ifield)
266                  iloc  = nextfl(ifield)
267                  clstrg = cficbf(ifield)//cficbf(ifield)
268                  ipdeb = (nextfl(ifield)-1)*ig_maxext*ig_maxgrd+1
269C
270C* Do it now
271C
272                  CALL extraw (fldold(iadrold), mskold(iadrold_grid),
273     $                isizold, clfic, ilun, clstrg, iloc, 
274     $                aextra(ipdeb), nextra(ipdeb), ineibor,
275     $                lextra(ifield))
276              ENDIF
277              lextrapdone(ifield) = .true.
278C
279C* --->>> Redglo
280C
281            ELSE IF (canal(ja,ifield) .EQ. 'REDGLO') THEN
282              itronca = ntronca(ifield)
283              clmsk = cmskrd(ifield)
284              zmskval = amskred
285C
286C* get number of longitudes by latitude circle and total number of points
287C  reduced grid
288C
289C* Zero work array
290C
291              CALL szero (work, ig_work)
292              CALL izero (nwork, ig_nwork)
293              CALL izero (inip, 320)
294              IF (itronca .EQ. 16) THEN
295                  DO 240 ji = 1, itronca
296                    inip(ji) = ninip16(ji)
297 240              CONTINUE
298                  iredu = nredu16
299                ELSE IF (itronca .EQ. 24)  THEN
300                  DO 250 ji = 1, itronca
301                    inip(ji) = ninip24(ji)
302 250              CONTINUE
303                  iredu = nredu24
304                ELSE IF (itronca .EQ. 32)  THEN
305                  DO 260 ji = 1, itronca
306                    inip(ji) = ninip32(ji)
307 260              CONTINUE
308                  iredu = nredu32
309                ELSE IF (itronca .EQ. 48)  THEN
310                  DO 270 ji = 1, itronca
311                    inip(ji) = ninip48(ji)
312 270              CONTINUE
313                   iredu = nredu48   
314                ELSE IF (itronca .EQ. 80)  THEN
315                  DO 280 ji = 1, itronca 
316                    inip(ji) = ninip80(ji)
317 280              CONTINUE
318                  iredu = nredu80
319                ELSE IF (itronca .EQ. 160)  THEN
320                  DO 285 ji = 1, itronca
321                    inip(ji) = ninip160(ji)
322 285              CONTINUE
323                  iredu = nredu160
324                ELSE
325                  CALL prtout
326     $          ('WARNING!!! Oasis cannot treat this grid with 2*NO
327     $          latitude lines with NO = ', itronca, 2)
328                  CALL prtout
329     $                ('Implement data for NO =', itronca, 2)
330                  CALL HALTE('STOP in preproc')
331              ENDIF
332              DO 290 ji = ilatbf/2 + 1, ilatbf
333                inip(ji) = inip(ilatbf - ji + 1)
334 290          CONTINUE
335              CALL redglo (fldold(iadrold), work(1), iredu, inip,
336     $                     ilonbf, ilatbf, nwork(1), nwork(1+iredu),
337     $                     itronca, zmskval, clmsk)
338            ELSE
339              CONTINUE
340          END IF
341 220      CONTINUE
342 210    CONTINUE
343C
344C
345C*    3. Deallocation and end of routine
346C        -------------------------------
347C
348        DEALLOCATE(iunit)
349        DEALLOCATE(zcocoef)
350        DEALLOCATE(clcofic)
351        DEALLOCATE(clcofld)
352C
353      IF (nlogprt .GE. 1) THEN
354          WRITE (UNIT = nulou,FMT = *) ' '
355          WRITE (UNIT = nulou,FMT = *) 
356     $    '          --------- End of routine preproc ---------'
357          CALL FLUSH (nulou)
358      ENDIF
359      RETURN
360      END
Note: See TracBrowser for help on using the repository browser.