1 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/write_field.F,v 1.3 1998/05/21 18:30:08 cnh Exp $ |
2 |
|
3 |
#include "CPP_EEOPTIONS.h" |
4 |
|
5 |
SUBROUTINE WRITE_FIELD_XYZR8( |
6 |
O fld, |
7 |
I filNam, filFmt, myThid ) |
8 |
C /==========================================================\ |
9 |
C | SUBROUTINE WRITE_FIELD_XYZR8 | |
10 |
C | o Writes out a three-dimensional model array | |
11 |
C |==========================================================| |
12 |
C | Routine that controls the writing of external datasets | |
13 |
C | into the model. In a multi-threaded and/or MPI world | |
14 |
C | this can be a non-trivial exercise. Here we use the | |
15 |
C | following approach: | |
16 |
C | Thread 1. writes data for the process domain i.e. all | |
17 |
C | threads into a buffer. This thread then writes out | |
18 |
C | the data for process. | |
19 |
C | By default output files are written split and have to be | |
20 |
C | merged in a post-processing stage - YUK! | |
21 |
C \==========================================================/ |
22 |
|
23 |
C == GLobal variables == |
24 |
#include "SIZE.h" |
25 |
#include "EEPARAMS.h" |
26 |
#include "EESUPPORT.h" |
27 |
#include "EEIO.h" |
28 |
|
29 |
C == Routine arguments == |
30 |
C fld - Array into which data will be written. |
31 |
C filNam - Name of file to read. |
32 |
C filFmt - Format to use to read the file. |
33 |
C myNz - No. vertical layers for array fld. |
34 |
C myThid - Thread number for this instance of the routine. |
35 |
REAL fld(1-OLx:sNx+OLx,1-OLy:sNy+OLy,1:Nr,nSx, nSy ) |
36 |
CHARACTER*(*) filNam |
37 |
CHARACTER*(*) filFmt |
38 |
INTEGER myThid |
39 |
|
40 |
C == Local variables == |
41 |
C msgBuf - Variable for writing error messages |
42 |
C I,J,K, bi,bj - Loop counters |
43 |
C dUnit - Unit number for file I/O |
44 |
C ioStatus - I/O error code |
45 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
46 |
INTEGER I |
47 |
INTEGER J |
48 |
INTEGER K |
49 |
INTEGER bi |
50 |
INTEGER bj |
51 |
INTEGER iG, jG |
52 |
INTEGER dUnit |
53 |
INTEGER ioStatus |
54 |
C |
55 |
dUnit = 42 |
56 |
|
57 |
C-- Open the file |
58 |
C Note: The error trapping here is inelegant. There is no |
59 |
C easy way to tell other threads and/or MPI processes that |
60 |
C there was an error. Here we simply STOP if there is an error. |
61 |
C Under a multi-threaded mode this will halt all the threads. |
62 |
C Under MPI the other processes may die or they may just hang! |
63 |
_BEGIN_MASTER(myThid) |
64 |
OPEN(dUnit,FILE=filNam,FORM='unformatted',STATUS='old', |
65 |
& IOSTAT=ioStatus) |
66 |
IF ( ioStatus .GT. 0 ) THEN |
67 |
WRITE(msgBuf,'(A)') |
68 |
& 'S/R READ_FIELD_XYZR8' |
69 |
CALL PRINT_ERROR( msgBuf , myThid) |
70 |
WRITE(msgBuf,'(A)') |
71 |
& 'Open for read failed for' |
72 |
CALL PRINT_ERROR( msgBuf , myThid) |
73 |
WRITE(msgBuf,'(A,A50)') |
74 |
& 'file ',filNam |
75 |
CALL PRINT_ERROR( msgBuf , myThid) |
76 |
STOP 'ABNORMAL END: S/R READ_FIELD_XYZR8' |
77 |
ENDIF |
78 |
_END_MASTER(myThid) |
79 |
|
80 |
DO K = 1, Nr |
81 |
C-- Read data from file one XY layer at a time |
82 |
_BEGIN_MASTER(myThid) |
83 |
C READ ... |
84 |
DO J=1,Ny |
85 |
DO I=1,Nx |
86 |
IF ( filNam(1:1) .EQ. 'u' ) THEN |
87 |
IO_tmpXY_R8(I,J) = 0.0 _d 0 |
88 |
IF ( J .GT. 15 .AND. J .LT. 24 ) |
89 |
& IO_tmpXY_R8(I,J) = 0.1 _d 0 |
90 |
ELSEIF ( filNam(1:1) .EQ. 'v' ) THEN |
91 |
IO_tmpXY_R8(I,J) = 0.0 _d 0 |
92 |
ELSE |
93 |
IO_tmpXY_R8(I,J) = 0.0 _d 0 |
94 |
ENDIF |
95 |
ENDDO |
96 |
ENDDO |
97 |
_END_MASTER(myThid) |
98 |
_BARRIER |
99 |
C-- Copy data into per thread data structures |
100 |
DO bj=myByLo(myThid),myByHi(myThid) |
101 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
102 |
DO j=1,sNy |
103 |
DO i=1,sNx |
104 |
iG = myXGlobalLo+(bi-1)*sNx+I-1 |
105 |
jG = myYGlobalLo+(bj-1)*sNy+J-1 |
106 |
fld(i,j,k,bi,bj) = IO_tmpXY_R8(iG,jG) |
107 |
ENDDO |
108 |
ENDDO |
109 |
ENDDO |
110 |
ENDDO |
111 |
_BARRIER |
112 |
ENDDO |
113 |
C |
114 |
_EXCH_XYZ_R8(fld, myThid ) |
115 |
C |
116 |
RETURN |
117 |
END |