-
Notifications
You must be signed in to change notification settings - Fork 0
/
mergemeta.py
executable file
·71 lines (64 loc) · 1.78 KB
/
mergemeta.py
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
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
######################## -*- coding: utf-8 -*-
"""Usage: mergemeta.py
Simple script to join tiled mds data
- remove adjoint tape files
- requires rdmds and wrmds from MITgcmutils
"""
import sys, os
from getopt import gnu_getopt as getopt
import glob
from MITgcmutils import rdmds, wrmds
# # parse command-line arguments
# try:
# optlist,args = getopt(sys.argv[1:], ':', ['verbose'])
# assert len(args) > 0
# except (AssertionError):
# sys.exit(__doc__)
files = glob.glob('*.001.001.meta')
# files=[]
# if len(args)<2:
# from glob import glob
# for infile in glob(args[0]):
# files.append(infile)
# else:
# files=args
for f in files:
f0 = f.split('.')
fn=''
try:
myitr = int(f0[-4])
for f00 in f0[:-4]:
fn = fn+f00+'.'
except:
myitr = -1
for f00 in f0[:-3]:
fn = fn+f00+'.'
fn = fn[:-1]
print(fn)
if myitr < 0:
if fn[:4]!='tape':
fld = rdmds(fn,returnmeta=True)
wrmds(fn,fld[0],
dataprec = fld[2]['dataprec'][0],
ndims = fld[2]['ndims'][0],
nrecords = fld[2]['nrecords'][0],
dimlist=fld[2]['dimlist']
)
flist = glob.glob(fn+'.???.???.??ta')
else:
flist = glob.glob(fn+'.???.???.??ta')
else:
fld = rdmds(fn,myitr,returnmeta=True)
wrmds(fn,fld[0],
itr=myitr,
dataprec = fld[2]['dataprec'][0],
ndims = fld[2]['ndims'][0],
nrecords = fld[2]['nrecords'][0],
dimlist=fld[2]['dimlist']
)
flist = glob.glob(fn+'.'+f0[-4]+'.???.???.??ta')
# delete tiled files
for fl in flist:
os.remove(fl)