-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtemplate2model.py
executable file
·36 lines (30 loc) · 1.05 KB
/
template2model.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""Replace mpas and MPAS in templace ModelX
Example:
$ template2model.py mom5cice5 MOM5CICE55'
will replace mpas with mom5cice5 and MPAS with MOM5CICE5
Todo:
*
"""
import glob
import sys
if __name__ == '__main__':
print sys.argv[0],': Replaces mpas and MPAS with user defined strings in *.*'
try:
namespace=sys.argv[1] # Replacement for mpas
NAMESPACE=sys.argv[2] # Replacement for MPAS
# wildc=sys.argv[3] # Wild card (*.cc, *.f90, ...)
except:
print 'Usage example: template2model.py mom5cice5 MOM5CICE5 *.c'
sys.exit("Error: Wrong arguments")
flist=glob.glob("*.*")
for fname in flist:
print fname
if (fname!=sys.argv[0]):
with open(fname, 'r') as file :
filedata = file.read()
filedata = filedata.replace('mpas', namespace)
filedata = filedata.replace('MPAS', NAMESPACE)
with open(fname, 'w') as file:
file.write(filedata)