-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcouple_io_oasis2.f
627 lines (583 loc) · 17.1 KB
/
couple_io_oasis2.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
#ifdef COUPLE
#ifdef OASIS2
SUBROUTINE coupled_flux(solar,non_solar,PminusE,kt)
IMPLICIT NONE
INTEGER nuout,nuerr
PARAMETER (nuout=6,nuerr=0)
c Include files for KPP
#include "parameter.inc"
#include "times.com"
#include "couple.com"
#include "location.com"
c Include files for OASIS2
#include "clim.h"
#include "oasis.h"
#include "param_cou.h"
#include "inc_cpl.h"
REAL solar(NPTS),non_solar(npts),PminusE(npts)
REAL*8 solar_in(NX_GLOBE,NY_GLOBE),
+ non_solar_in(NX_GLOBE,NY_GLOBE),
+ PminusE_in(NX_GLOBE,NY_GLOBE)
INTEGER kt,info,jf,ipoint,ix,jy
IF (cchan .EQ. 'CLIM') THEN
DO jf=1,jpflda2o1
IF (jf .eq. 1) CALL CLIM_Import (cl_read(jf), kt,
+ non_solar_in,info)
IF (jf .eq. 2) CALL CLIM_Import (cl_read(jf), kt,
+ solar_in,info)
IF (jf .eq. 3) CALL CLIM_Import (cl_read(jf), kt,
+ PminusE_in,info)
IF (info .NE. CLIM_Ok) THEN
WRITE(nuerr,*)'Error in reading ',cl_read(jf), jf
WRITE(nuerr,*)'Coupler timestep is ',kt
WRITE(nuerr,*)'CLIM error code is ',info
CALL halte ('STOP in coupled_flux')
ENDIF
ENDDO
ENDIF
DO jy=jfirst,jlast
DO ix=ifirst,ilast
c
c Debugging WRITE statements - uncomment if required
c NPK 2/11/09 - R3 (now commented by default)
c
c IF (ix .eq. ifirst+10 .and. jy .eq. jfirst+10) THEN
c WRITE(nuout,*)'At ',ifirst+10,',',jfirst+10,' solar_in=',
c + solar_in(ix,jy),' non_solar_in=',non_solar_in(ix,jy)
c + ,' PminusE_in=',PminusE_in(ix,jy)
c ENDIF
c
c Transform global fields (as received from atmosphere)
c to regional fields (as required for KPP)
c
ipoint=(jy-jfirst)*nx+(ix-ifirst)+1
solar(ipoint)=solar_in(ix,jy)
non_solar(ipoint)=non_solar_in(ix,jy)
PminusE(ipoint)=PminusE_in(ix,jy)
ENDDO
ENDDO
RETURN
END
SUBROUTINE coupled_stress(ustress,vstress,kt)
IMPLICIT NONE
INTEGER nuout,nuerr
PARAMETER (nuout=6,nuerr=0)
c Include files for KPP
#include "parameter.inc"
#include "times.com"
#include "couple.com"
#include "location.com"
REAL ustress(NPTS),vstress(npts)
INTEGER kt,info
REAL ustress_in(NX_GLOBE,NY_GLOBE),vstress_in(NX_GLOBE,NY_GLOBE)
c Include files for OASIS2
#include "clim.h"
#include "oasis.h"
#include "param_cou.h"
#include "inc_cpl.h"
INTEGER jf,ipoint,ix,jy,jf_in
IF (cchan .EQ. 'CLIM') THEN
DO jf=1,jpflda2o2
jf_in=jf+jpflda2o1
IF (jf .eq. 1) CALL CLIM_Import (cl_read(jf_in), kt,
+ ustress_in,info)
IF (jf .eq. 2) CALL CLIM_Import (cl_read(jf_in), kt,
+ vstress_in,info)
IF (info .NE. CLIM_Ok) THEN
WRITE(nuerr,*)'Error in reading ',cl_read(jf_in), jf
WRITE(nuerr,*)'Coupler timestep is ',kt
WRITE(nuerr,*)'CLIM error code is ',info
CALL halte ('STOP in coupled_stress')
ENDIF
ENDDO
ENDIF
c
c Transform global fields (as received from atmosphere)
c to regional fields (as required for KPP)
c
DO jy=jfirst,jlast
DO ix=ifirst,ilast
ipoint=(jy-jfirst)*nx+(ix-ifirst)+1
ustress(ipoint)=ustress_in(ix,jy)
vstress(ipoint)=vstress_in(ix,jy)
ENDDO
ENDDO
RETURN
END
SUBROUTINE coupled_out(X,kt,L_LAST)
c***********************************************************
c Routine to output the fields to the coupler
c Has to deal with regional coupling
c The way it is written one can only do regional coupling in
c the longitude direction IF (ifirst .NE. 1)
c***********************************************************
IMPLICIT NONE
INTEGER nuout,nuerr
PARAMETER (nuout=6,nuerr=0)
c Include files for KPP
#include "parameter.inc"
#include "constants.com"
#include "times.com"
#include "couple.com"
#include "location.com"
#include "ocn_advec.com"
REAL X(NPTS,NZP1,NSCLR)
INTEGER kt
c Include files for OASIS2
#include "clim.h"
#include "oasis.h"
#include "param_cou.h"
#include "inc_cpl.h"
INTEGER ix,jy,ipoint,ipoint_globe
REAL ICE_in(NX_GLOBE,NY_GLOBE,1)
REAL usf_in(NX_GLOBE,NY_GLOBE)
REAL vsf_in(NX_GLOBE,NY_GLOBE)
REAL SST(NX_GLOBE,NY_GLOBE)
REAL ICE(NX_GLOBE,NY_GLOBE)
REAL SST_in(NX_GLOBE,NY_GLOBE,1)
CHARACTER*8 file_name(jpmaxfld)
INTEGER max_file
INTEGER file_unit_max,file_unit(jpmaxfld)
INTEGER file_unit_field(jpmaxfld)
INTEGER icstep, info, jn, jf, ierror
LOGICAL L_TROUVE,L_LAST
COMMON /save_sstin/ SST_in,ICE_in,usf_in,vsf_in
c
c Use the coupling weight to modify the SSTs before passing
c back to the coupler.
c N.B. : We want to do this whether or not the user has specified
c coupling weights. Cplwght is automatically set IF (.NOT. L_CPLWGHT)
c NPK April 2008 - R1
c
WRITE(nuout,*) ' Entering loop to weight SSTs'
DO ix=1,NX_GLOBE
DO jy=1,NY_GLOBE
ipoint_globe = (jy-1)*NX_GLOBE+ix
IF (cplwght(ipoint_globe) .LT. -1e-10) THEN
c Point is outside the coupling domain; set to SST climatology
SST(ix,jy) = SST_in(ix,jy,1)
ELSE
c Point is inside the coupling domain; set to weighted value
ipoint=(jy-jfirst)*nx+(ix-ifirst)+1
SST(ix,jy) = X(ipoint,1,1)*cplwght(ipoint_globe) +
& SST_in(ix,jy,1)*(1-cplwght(ipoint_globe))
ENDIF
ice(ix,jy) = ice_in(ix,jy,1)
ENDDO
ENDDO
IF (L_OUTKELVIN) SST = SST+TK0
c
c This bit is taken almost directly from stpmco in the toymodel
c
WRITE(nuout,*) ' '
WRITE(nuout,*) 'stpcmo: sending fields to CPL with kt= ', kt
WRITE(nuout,*) ' '
IF (L_LAST) THEN
c
c -WRITE fields to binary files for coupler restart at last time step
c
c -initialisation
c
max_file=1
file_unit_max=99
c -keeps first file name
file_name(max_file)=cl_f_writ(max_file)
c -keeps first file unit
file_unit(max_file)=file_unit_max
c -decrements file unit maximum
file_unit_max=file_unit_max-1
c -keeps file unit for field
file_unit_field(1)=file_unit(max_file)
c
c -different files names counter
c
DO jf= 2, jpfldo2a
L_TROUVE=.false.
DO jn= 1, max_file
IF (.not. L_TROUVE) THEN
IF (cl_f_writ(jf).EQ.file_name(jn)) THEN
c keep file unit for field
file_unit_field(jf)=file_unit(jn)
L_TROUVE=.true.
END IF
END IF
END DO
IF (.not. L_TROUVE) then
c -increment the number of different files
max_file=max_file+1
c -keep file name
file_name(max_file)=cl_f_writ(jf)
c -keep file unit for file
file_unit(max_file)=file_unit_max
c -keep file unit for field
file_unit_field(jf)=file_unit(max_file)
c -decrement unit maximum number from 99 to 98, ...
file_unit_max=file_unit_max-1
END IF
END DO
c
DO jn=1, max_file
OPEN (file_unit(jn), FILE=file_name(jn),
& FORM='UNFORMATTED')
END DO
c
c WRITE fields to files
c
WRITE(nuout,*) 'KPP: Writing to output files in couple_io.f'
CALL FLUSH(nuout)
DO jf=1, jpfldo2a
IF (jf.eq.2)
$ CALL locwrite(cl_writ(jf),sst, NX_GLOBE*NY_GLOBE,
$ file_unit_field(jf), ierror, nuout)
IF (jf.eq.1)
$ CALL locwrite(cl_writ(jf),ice, NX_GLOBE*NY_GLOBE,
$ file_unit_field(jf), ierror, nuout)
IF (jf.eq.3)
$ CALL locwrite(cl_writ(jf),usf_in, NX_GLOBE*NY_GLOBE,
$ file_unit_field(jf), ierror, nuout)
IF (jf.eq.4)
$ CALL locwrite(cl_writ(jf),vsf_in, NX_GLOBE*NY_GLOBE,
$ file_unit_field(jf), ierror, nuout)
END DO
C
C -simulate a FLUSH
C
WRITE(nuout,*) 'KPP: Closing output files in couple_io.f'
CALL FLUSH(nuout)
DO jn=1, max_file
CLOSE (file_unit(jn))
END DO
c
c
c
IF(cchan.eq.'CLIM') THEN
c
c -inform PVM daemon, I have finished
c
WRITE(nuout,*) 'KPP: Calling CLIM_Quit'
CALL FLUSH(nuout)
CALL CLIM_Quit (CLIM_StopPvm, info)
IF (info .NE. CLIM_Ok) THEN
WRITE (6,*)
$ 'An error occured while leaving CLIM. Error = ',
$ info
ENDIF
END IF
RETURN
END IF
c
IF(cchan.eq.'CLIM') THEN
C
C -Give oceanic fields to Oasis
C
DO jn=1, jpfldo2a
IF (jn.eq.2) THEN
CALL CLIM_Export(cl_writ(jn), kt, sst, info)
ENDIF
IF (jn.eq.1) THEN
CALL CLIM_Export(cl_writ(jn), kt, ice, info)
ENDIF
IF (jn.eq.3) THEN
CALL CLIM_Export(cl_writ(jn), kt, usf_in, info)
ENDIF
IF (jn.eq.4) THEN
CALL CLIM_Export(cl_writ(jn), kt, vsf_in, info)
ENDIF
c
IF (info .NE. CLIM_Ok) THEN
WRITE (nuerr,*) 'STEP : Pb giving ',cl_writ(jn), ':',jn
WRITE (nuerr,*) ' at timestep = ', icstep,'kt = ',kt
WRITE (nuerr,*) 'Clim error code is = ',info
CALL halte('STOP in coupled_out ')
ENDIF
END DO
ENDIF
RETURN
END
SUBROUTINE locread ( cdfldn, pfield, kdimax, knulre, kflgre
$ , kout)
C****
C *****************************
C * OASIS ROUTINE - LEVEL 0 *
C * ------------- ------- *
C *****************************
C
C**** *locread* - Read binary field on unit knulre
C
C Purpose:
C -------
C Find string cdfldn on unit knulre and read array pfield
C
C** Interface:
C ---------
C *CALL* *locread (cdfldn, pfield, kdimax, knulre, kflgre, kout)*
C
C Input:
C -----
C cdfldn : character string locator
C kdimax : dimension of field to be read
C knulre : logical unit to be read
C kout : logical unit to write messages
C
C Output:
C ------
C pfield : field array (real 1D)
C kflgre : error status flag
C
C Reference:
C ---------
C See OASIS manual (1995)
C
C History:
C -------
C Version Programmer Date Description
C ------- ---------- ---- -----------
C 2.0 L. Terray 95/09/01 created
C
C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C
IMPLICIT CHARACTER(c)
IMPLICIT LOGICAL(l)
C
C* ---------------------------- Argument declarations -------------------
C
REAL pfield(kdimax)
CHARACTER*8 cdfldn
C
C* ---------------------------- Local declarations ----------------------
C
CHARACTER*8 clecfl
C
C* ---------------------------- Poema verses ----------------------------
C
C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C
C* 1. Initialization
C --------------
C
WRITE (UNIT = kout,FMT = 1001) knulre
C
C* Formats
C
1001 FORMAT('Locread : Read binary file connected to unit = ',I3)
C
C 2. Find field in file
C ------------------
C
REWIND knulre
200 CONTINUE
C* Find string
READ (UNIT = knulre, ERR = 200, END = 210) clecfl
IF (clecfl .NE. cdfldn) GO TO 200
C* Read associated field
READ (UNIT = knulre, ERR = 210, END = 210) pfield
C* Reading done and ok
kflgre = 0
GO TO 220
C* Problem in reading
210 kflgre = 1
220 CONTINUE
C
C
C* 3. End of routine
C --------------
C
WRITE (UNIT = kout,FMT = *) 'Locread : done'
c CALL FLUSH (kout) ! removed to compile on HCPX
RETURN
END
SUBROUTINE locwrite (cdfldn, pfield, kdimax, knulre, kflgre, kout)
IMPLICIT none
C****
C *****************************
C * OASIS ROUTINE - LEVEL 0 *
C * ------------- ------- *
C *****************************
C
C**** *locwrite* - Write binary field on unit knulre
C
C Purpose:
C -------
C Write string cdfldn and array pfield on unit knulre
C
C** Interface:
C ---------
C *CALL* *locwrite (cdfldn, pfield, kdimax, knulre, kflgre, kout)*
C
C Input:
C -----
C cdfldn : character string locator
C kdimax : dimension of field to be written
C knulre : logical unit to be written
C pfield : field array (real 1D)
C kout : logical unit to write messages
C
C Output:
C ------
C kflgre : error status flag
C
C Workspace:
C ---------
C None
C
C Externals:
C ---------
C None
C
C Reference:
C ---------
C See OASIS manual (1995)
C
C History:
C -------
C Version Programmer Date Description
C ------- ---------- ---- -----------
C 2.0 L. Terray 95/09/01 created
C
C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C
C
C* ---------------------------- Argument declarations -------------------
C
INTEGER kdimax, knulre, kflgre, kout
REAL pfield(kdimax)
CHARACTER*8 cdfldn
C
C* ---------------------------- Poema verses ----------------------------
C
C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C
C* 1. Initialization
C --------------
C
WRITE (UNIT = kout,FMT = 1001) knulre
C
C* Formats
C
1001 FORMAT(5X,' Write binary file connected to unit = ',I3)
C
C 2. Find field in file
C ------------------
C
C* Write string
WRITE (UNIT = knulre, ERR = 210) cdfldn
C* Write associated field
WRITE (UNIT = knulre, ERR = 210) pfield
C* Writing done and ok
kflgre = 0
GO TO 220
C* Problem in Writing
210 kflgre = 1
220 CONTINUE
C
C
C* 3. End of routine
C --------------
C
WRITE (UNIT = kout,FMT = *) 'Locwrite : done'
c CALL FLUSH (kout) ! removed to complile on HPCX
RETURN
END
SUBROUTINE halte (cdtext)
C****
C *****************************
C * OASIS ROUTINE - LEVEL C *
C * ------------- ------- *
C *****************************
C
C**** *halte* - Abort the program
C
C Purpose:
C -------
C Print an error message to standard output and abort the coupler
C
C** Interface:
C ---------
C *CALL* *halte (cdtext)*
C
C Input:
C -----
C cdtext : character string to be printed
C
C Output:
C ------
C None
C
C Workspace:
C ---------
C None
C
C Externals:
C ---------
C None
C
C Reference:
C ---------
C See OASIS 2.2 manual (1997)
C
C History:
C -------
C Version Programmer Date Description
C ------- ---------- ---- -----------
C 2.2 S. Valcke 97/11/18 created
C
C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C
C* ---------------------------- Argument declarations ----------------------
C
CHARACTER*(*) cdtext
C
C* ---------------------------- Local declarations ----------------------
C
CHARACTER cpbase
CHARACTER*10 cprpt, cpdots
CHARACTER*69 cline
PARAMETER ( cpbase = '-' )
PARAMETER ( cprpt = '* ===>>> :' )
PARAMETER ( cpdots = ' ------ ' )
C
C* ---------------------------- Poema verses ----------------------------
C
C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C
C* 1. Print text
C ----------
C
cline = ' '
ilen = len(cdtext)
DO 110 jl = 1, ilen
cline(jl:jl) = cpbase
110 CONTINUE
nulou=6
WRITE(UNIT = nulou,FMT='(/,A,X,A)') cpdots, cline
WRITE(UNIT = nulou,FMT='(/,A,X,A,/)') cprpt, cdtext
WRITE(UNIT = nulou,FMT='(A,X,A,/)')cpdots, cline
C
C
C* 2. FLUSH the coupler output
C ------------------------
C
c CALL FLUSH (nulou) ! removed to compile on HCPx
C
C
C* 3. Abort the coupler
C -----------------
C
CALL abort
RETURN
END
SUBROUTINE TWO_TO_ONE(twod,oned)
IMPLICIT NONE
#include "parameter.inc"
REAL twod(NX_GLOBE,NY_GLOBE),oned(NX_GLOBE*NY_GLOBE)
INTEGER*4 i,j,point
DO i=1,NX_GLOBE
DO j=1,NY_GLOBE
point = (i-1)*NY_GLOBE+j
oned(point) = twod(i,j)
END DO
END DO
RETURN
END
#endif /*OASIS2*/
#endif /*COUPLE*/