1 |
jmc |
1.2 |
C $Header: /u/gcmpack/MITgcm/pkg/aim_v23/aim_write_phys.F,v 1.1 2006/08/04 22:27:46 jmc Exp $ |
2 |
jmc |
1.1 |
C $Name: $ |
3 |
|
|
|
4 |
|
|
#include "AIM_OPTIONS.h" |
5 |
|
|
|
6 |
|
|
CBOP |
7 |
|
|
C !ROUTINE: AIM_WRITE_PHYS |
8 |
|
|
C !INTERFACE: |
9 |
|
|
SUBROUTINE AIM_WRITE_PHYS( |
10 |
|
|
I pref, suff, nNr, field, |
11 |
|
|
I kLev, bi, bj, iRec, myIter, myThid ) |
12 |
|
|
C !DESCRIPTION: \bv |
13 |
|
|
C *==========================================================* |
14 |
|
|
C | SUBROUTINE AIM_WRITE_PHYS |
15 |
|
|
C | o Write variable from AIM physics common block |
16 |
|
|
C | (=> no overlap & nThreads) and reverse K index. |
17 |
|
|
C *==========================================================* |
18 |
|
|
C | Note: assume symetry in tiles per thread treatment |
19 |
|
|
C *==========================================================* |
20 |
|
|
C !USES |
21 |
|
|
IMPLICIT NONE |
22 |
|
|
|
23 |
|
|
C == Global variables === |
24 |
|
|
#include "AIM_SIZE.h" |
25 |
|
|
|
26 |
|
|
#include "EEPARAMS.h" |
27 |
|
|
c #include "PARAMS.h" |
28 |
|
|
|
29 |
|
|
C !INPUT/OUTPUT PARAMETERS: |
30 |
|
|
C == Routine arguments == |
31 |
|
|
C pref :: Prefix of the output file name |
32 |
|
|
C suff :: Suffix of the output file name |
33 |
|
|
C nNr :: 3rd dim. of the input field |
34 |
|
|
C field :: Field (from aim-physics) to write |
35 |
|
|
C kLev :: level index to write (0 = write all levels) |
36 |
|
|
C bi,bj :: Tile index |
37 |
|
|
C iRec :: reccord number in the output file |
38 |
|
|
C myIter :: Current iteration number in simulation |
39 |
jmc |
1.2 |
C myThid :: my Thread Id number |
40 |
jmc |
1.1 |
CHARACTER*(*) pref, suff |
41 |
|
|
INTEGER nNr |
42 |
|
|
_RL field(sNx,sNy,nNr,MAX_NO_THREADS) |
43 |
|
|
INTEGER kLev, bi, bj, iRec, myIter, myThid |
44 |
|
|
|
45 |
|
|
#ifdef ALLOW_AIM |
46 |
|
|
|
47 |
|
|
C Functions |
48 |
|
|
INTEGER ILNBLNK |
49 |
|
|
EXTERNAL ILNBLNK |
50 |
|
|
|
51 |
|
|
C !LOCAL VARIABLES: |
52 |
|
|
CHARACTER*(MAX_LEN_MBUF) msgBuf |
53 |
|
|
_RL tmpFld(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
54 |
|
|
INTEGER iL |
55 |
|
|
INTEGER i, j, k, Katm, nLoc |
56 |
|
|
INTEGER ith, biLoc, bjLoc |
57 |
|
|
CEOP |
58 |
|
|
|
59 |
|
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
60 |
|
|
|
61 |
|
|
#ifdef LOCBIN_IO_THREAD_SAFE |
62 |
|
|
C- safe for any thread to do IO |
63 |
|
|
ith = myThid |
64 |
|
|
biLoc = bi |
65 |
|
|
bjLoc = bj |
66 |
|
|
#else /* LOCBIN_IO_THREAD_SAFE */ |
67 |
|
|
C- master-thread does IO for all threads |
68 |
|
|
_BARRIER |
69 |
|
|
_BEGIN_MASTER( myThid ) |
70 |
|
|
DO ith=1,nThreads |
71 |
|
|
biLoc = bi + myBxLo(ith) - 1 |
72 |
|
|
bjLoc = bj + myByLo(ith) - 1 |
73 |
|
|
#endif /* LOCBIN_IO_THREAD_SAFE */ |
74 |
|
|
|
75 |
|
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
76 |
|
|
|
77 |
|
|
C-- Check for argument list consistency |
78 |
|
|
IF ( nNr.LT.1 .OR. nNr.GT.Nr ) THEN |
79 |
|
|
iL = ILNBLNK( pref ) |
80 |
|
|
WRITE(msgBuf,'(A,I10,A,2I5,A,I4,2A)') |
81 |
|
|
& 'AIM_WRITE_PHYS (it=', myIter, ' bi,bj=', bi,bj, |
82 |
|
|
& ' iRec=', iRec, ' ): try to write: ', pref(1:iL) |
83 |
|
|
CALL PRINT_ERROR( msgBuf, myThid ) |
84 |
|
|
WRITE(msgBuf,'(A,I4,A,I4)') |
85 |
|
|
& 'AIM_WRITE_PHYS: 3rd dim.(field)=',nNr,' has to be <',Nr |
86 |
|
|
CALL PRINT_ERROR( msgBuf , myThid) |
87 |
|
|
STOP 'ABNORMAL END: S/R AIM_WRITE_PHYS' |
88 |
|
|
ELSEIF ( kLev.NE.0 .AND. kLev.GT.nNr ) THEN |
89 |
|
|
iL = ILNBLNK( pref ) |
90 |
|
|
WRITE(msgBuf,'(A,I10,A,2I5,A,I4,2A)') |
91 |
|
|
& 'AIM_WRITE_PHYS (it=', myIter, ' bi,bj=', bi,bj, |
92 |
|
|
& ' iRec=', iRec, ' ): try to write: ', pref(1:iL) |
93 |
|
|
CALL PRINT_ERROR( msgBuf, myThid ) |
94 |
|
|
WRITE(msgBuf,'(A,I4,A,I4)') |
95 |
|
|
& 'AIM_WRITE_PHYS: kLev=', kLev, |
96 |
|
|
& ' out of bounds (dim=', nNr,' )' |
97 |
|
|
CALL PRINT_ERROR( msgBuf , myThid) |
98 |
|
|
STOP 'ABNORMAL END: S/R AIM_WRITE_PHYS' |
99 |
|
|
ENDIF |
100 |
|
|
|
101 |
|
|
C-- Copy the input field into tempo. array: |
102 |
|
|
nLoc = nNr |
103 |
|
|
IF ( kLev.GE.1 .AND. kLev.LE.nNr ) THEN |
104 |
|
|
nLoc = 1 |
105 |
|
|
DO j=1,sNy |
106 |
|
|
DO i=1,sNx |
107 |
|
|
tmpFld(i,j,1) = field(i,j,kLev,ith) |
108 |
|
|
ENDDO |
109 |
|
|
ENDDO |
110 |
|
|
ELSEIF (nNr.EQ.Nr) THEN |
111 |
|
|
C- Reverse K index: |
112 |
|
|
DO k=1,Nr |
113 |
|
|
Katm = _KD2KA( k ) |
114 |
|
|
DO j=1,sNy |
115 |
|
|
DO i=1,sNx |
116 |
|
|
tmpFld(i,j,k) = field(i,j,Katm,ith) |
117 |
|
|
ENDDO |
118 |
|
|
ENDDO |
119 |
|
|
ENDDO |
120 |
|
|
ELSE |
121 |
|
|
C- Do simple copy |
122 |
|
|
DO k=1,nNr |
123 |
|
|
DO j=1,sNy |
124 |
|
|
DO i=1,sNx |
125 |
|
|
tmpFld(i,j,k) = field(i,j,k,ith) |
126 |
|
|
ENDDO |
127 |
|
|
ENDDO |
128 |
|
|
ENDDO |
129 |
|
|
ENDIF |
130 |
|
|
|
131 |
jmc |
1.2 |
C-- Write to file: note: call with myThArg=0 => single thread job |
132 |
jmc |
1.1 |
CALL WRITE_LOCAL_RL( pref, suff, nLoc, tmpFld, |
133 |
jmc |
1.2 |
& biLoc, bjLoc, iRec, myIter, 0 ) |
134 |
jmc |
1.1 |
|
135 |
|
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
136 |
|
|
|
137 |
|
|
#ifndef LOCBIN_IO_THREAD_SAFE |
138 |
|
|
ENDDO |
139 |
|
|
_END_MASTER( myThid ) |
140 |
|
|
_BARRIER |
141 |
|
|
#endif /* ndef LOCBIN_IO_THREAD_SAFE */ |
142 |
|
|
|
143 |
|
|
#endif /* ALLOW_AIM */ |
144 |
|
|
RETURN |
145 |
|
|
END |