1 |
C $Header: /u/gcmpack/models/MITgcmUV/pkg/mdsio/mdsio_writemeta.F,v 1.1 2001/03/06 15:28:54 adcroft Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "MDSIO_OPTIONS.h" |
5 |
|
6 |
subroutine MDSWRITEMETA( |
7 |
I mFileName, |
8 |
I dFileName, |
9 |
I filePrec, |
10 |
I ndims, |
11 |
I dimList, |
12 |
I nrecords, |
13 |
I myIter, |
14 |
I mythid ) |
15 |
|
16 |
C IN: |
17 |
C mFileName string - complete name of meta-file |
18 |
C dFileName string - complete name of data-file |
19 |
C ndims integer - number of dimensions |
20 |
C dimList integer - array of dimensions, etc. |
21 |
C nrecords integer - record number |
22 |
C myIter integer - time-step number |
23 |
C mythid integer - thread id |
24 |
C OUT: |
25 |
C |
26 |
C Created: 03/20/99 adcroft@mit.edu |
27 |
|
28 |
implicit none |
29 |
C Arguments |
30 |
character*(*) mFileName |
31 |
character*(*) dFileName |
32 |
integer filePrec |
33 |
integer ndims |
34 |
integer dimList(3,ndims) |
35 |
integer nrecords |
36 |
integer myIter |
37 |
integer mythid |
38 |
|
39 |
C Global variables / common blocks |
40 |
#include "SIZE.h" |
41 |
#include "EEPARAMS.h" |
42 |
#include "PARAMS.h" |
43 |
|
44 |
C Functions |
45 |
|
46 |
C Local |
47 |
integer i,ii,mUnit |
48 |
logical ex |
49 |
character*(max_len_mbuf) msgbuf |
50 |
C ------------------------------------------------------------------ |
51 |
|
52 |
C We should *read* the met-file if it exists to check |
53 |
C that the information we are writing is consistent |
54 |
C with the current contents |
55 |
inquire( file=mFileName, exist=ex ) |
56 |
C However, it is bloody difficult to parse files |
57 |
C in fortran so someone else can do this. |
58 |
C For now, we will assume everything is ok |
59 |
C and that the last record is written to the |
60 |
C last consecutive record in the file. |
61 |
|
62 |
C Assign a free unit number as the I/O channel for this subroutine |
63 |
call MDSFINDUNIT( mUnit, mythid ) |
64 |
|
65 |
C Open meta-file |
66 |
open( mUnit, file=mFileName, status='unknown', |
67 |
& form='formatted' ) |
68 |
|
69 |
C Write the number of dimensions |
70 |
write(mUnit,'(x,a,i3,a)') 'nDims = [ ',ndims,' ];' |
71 |
|
72 |
C For each dimension, write the following: |
73 |
C 1 global size (ie. the size of the global dimension of all files) |
74 |
C 2 global start (ie. the global position of the start of this file) |
75 |
C 3 global end (ie. the global position of the end of this file) |
76 |
|
77 |
write(mUnit,'(x,a)') 'dimList = [' |
78 |
do ii=1,ndims |
79 |
if (ii.lt.ndims) then |
80 |
write(mUnit,'(10x,3(i5,","))') (dimList(i,ii),i=1,3) |
81 |
else |
82 |
write(mUnit,'(10x,i5,",",i5,",",i5)') (dimList(i,ii),i=1,3) |
83 |
endif |
84 |
enddo |
85 |
write(mUnit,'(10x,a)') '];' |
86 |
|
87 |
C Record the precision of the file |
88 |
if (filePrec .EQ. precFloat32) then |
89 |
write(mUnit,'(x,a)') "format = [ 'float32' ];" |
90 |
elseif (filePrec .EQ. precFloat64) then |
91 |
write(mUnit,'(x,a)') "format = [ 'float64' ];" |
92 |
else |
93 |
write(msgbuf,'(a)') |
94 |
& ' MDSWRITEMETA: invalid filePrec' |
95 |
call print_error( msgbuf, mythid ) |
96 |
stop 'ABNORMAL END: S/R MDSWRITEMETA' |
97 |
endif |
98 |
|
99 |
C Record the current record number |
100 |
C This is a proxy for the actual number of records in the file. |
101 |
C If we could read the file then we could do this properly. |
102 |
write(mUnit,'(x,a,i5,a)') 'nrecords = [ ',nrecords,' ];' |
103 |
|
104 |
C Record the file-name for the binary data |
105 |
Cveto ii=ILNBLNK( dFileName ) |
106 |
Cveto write(mUnit,'(x,3a)') 'binarydatafile = [ ',dFileName(1:ii),' ];' |
107 |
|
108 |
C Write the integer time (integer iteration number) for later record |
109 |
C keeping. If the timestep number is less than 0 then we assume |
110 |
C that the information is superfluous and do not write it. |
111 |
if (myIter .ge. 0) |
112 |
& write(mUnit,'(x,a,i10,a)') 'timeStepNumber = [ ',myIter,' ];' |
113 |
|
114 |
C Close meta-file |
115 |
close(mUnit) |
116 |
|
117 |
C ------------------------------------------------------------------ |
118 |
return |
119 |
end |