[cig-commits] r6510 - mc/3D/CitcomS/trunk/visual
tan2 at geodynamics.org
tan2 at geodynamics.org
Thu Apr 5 15:21:46 PDT 2007
Author: tan2
Date: 2007-04-05 15:21:46 -0700 (Thu, 05 Apr 2007)
New Revision: 6510
Added:
mc/3D/CitcomS/trunk/visual/dxgeneral.py
mc/3D/CitcomS/trunk/visual/pasteCitcomData.py
Removed:
mc/3D/CitcomS/trunk/visual/batchpaste.sh
mc/3D/CitcomS/trunk/visual/dxgeneral.sh
mc/3D/CitcomS/trunk/visual/execpaste.py
mc/3D/CitcomS/trunk/visual/pasteCitcomData.sh
Modified:
mc/3D/CitcomS/trunk/visual/Makefile.am
mc/3D/CitcomS/trunk/visual/autocombine.py
mc/3D/CitcomS/trunk/visual/batchcombine.py
mc/3D/CitcomS/trunk/visual/combine.py
Log:
Adding the ability to combine optional fields to the post-processing scripts.
autocombine.py will read the parameter 'output_optional' from the cfg file and
combine the optional fields (can be pressure, stress, comp_nd, or a combination
of the three) into a file. The file is named similar to the cap file, with
'cap' replaced by 'opt'. A .general file is also created, which describes the
content, shape, and structure of the opt file.
Modified: mc/3D/CitcomS/trunk/visual/Makefile.am
===================================================================
--- mc/3D/CitcomS/trunk/visual/Makefile.am 2007-04-05 21:54:55 UTC (rev 6509)
+++ mc/3D/CitcomS/trunk/visual/Makefile.am 2007-04-05 22:21:46 UTC (rev 6510)
@@ -35,15 +35,13 @@
mayavi2_citcoms_display.py \
autocombine.py \
batchcombine.py \
- batchpaste.sh \
batchsurf.py \
citcoms_datadir \
combine.py \
combinesurf.py \
- dxgeneral.sh \
+ dxgeneral.py \
dxgeneralsurf.sh \
estimate_size.py \
- execpaste.py \
getcoord.sh \
getlog.sh \
getsurf.sh \
@@ -51,7 +49,7 @@
miff2avi \
miff2mpg \
parser.py \
- pasteCitcomData.sh \
+ pasteCitcomData.py \
plot_annulus.py \
plot_layer.py \
zslice.py
Modified: mc/3D/CitcomS/trunk/visual/autocombine.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/autocombine.py 2007-04-05 21:54:55 UTC (rev 6509)
+++ mc/3D/CitcomS/trunk/visual/autocombine.py 2007-04-05 22:21:46 UTC (rev 6510)
@@ -33,6 +33,7 @@
# default values for CitcomS input
defaults = {'output_format': 'ascii',
+ 'output_optional': 'surf,botm',
'nprocx': 1,
'nprocy': 1,
'nprocz': 1,
@@ -40,6 +41,24 @@
'nodey': 9,
'nodez': 9}
+
+
+def normalize_optional(output_optional):
+ fields = []
+
+ for opt in output_optional.split(','):
+ ## remove the leading/trailing whitespaces
+ opt = opt.strip()
+
+ ## retain fields that are node-based
+ if opt in ('pressure', 'stress', 'comp_nd'):
+ fields.append(opt)
+
+
+ return ','.join(fields)
+
+
+
if __name__ == '__main__':
import sys
@@ -67,6 +86,9 @@
"(output_format=%s)" % output_format
sys.exit(1)
+ output_optional = parser.getstr('output_optional')
+ optional_fields = normalize_optional(output_optional)
+
nodex = parser.getint('nodex')
nodey = parser.getint('nodey')
nodez = parser.getint('nodez')
@@ -76,12 +98,13 @@
nprocz = parser.getint('nprocz')
totalnodes = nprocx * nprocy * nprocz * ncap
- nodelist = bc.machinefile2nodes(machinefile, totalnodes)
+ nodelist = bc.machinefile2nodelist(machinefile, totalnodes)
for timestep in timesteps:
- bc.combine(nodelist, datadir, datafile, timestep,
- nodex, nodey, nodez,
- ncap, nprocx, nprocy, nprocz)
+ bc.batchcombine(nodelist, datadir, datafile, timestep,
+ nodex, nodey, nodez,
+ ncap, nprocx, nprocy, nprocz,
+ optional_fields)
Modified: mc/3D/CitcomS/trunk/visual/batchcombine.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/batchcombine.py 2007-04-05 21:54:55 UTC (rev 6509)
+++ mc/3D/CitcomS/trunk/visual/batchcombine.py 2007-04-05 22:21:46 UTC (rev 6510)
@@ -35,7 +35,17 @@
def machinefile2nodes(machinefile, totalnodes):
+ nodelist = machinefile2nodelist(machinefile, totalnodes)
+ nodes = nodelist2nodes(nodelist)
+ return nodes
+
+
+def machinefile2nodelist(machinefile, totalnodes):
+ '''Read the machinefile to get a list of machine names. If machinefile
+ is not readable, treat it as a string containing the machine names.
+ Return the list of machine names. The length of the list is totalnodes.
+ '''
try:
nodelist = file(machinefile).readlines()
except IOError:
@@ -51,40 +61,80 @@
else:
raise ValueError, 'incorrect machinefile size'
+ return nodelist
+
+
+
+def nodelist2nodes(nodelist):
# generate a string of machine names
- nodes = ''
- for node in nodelist:
- nodes += '%s ' % node.strip()
+ nodes = ' '.join([x.strip() for x in nodelist])
return nodes
-def combine(nodes, datadir, datafile, timestep, nodex, nodey, nodez,
- ncap, nprocx, nprocy, nprocz):
+def batchpaste(datadir, datafile, opts, timestep, nodes):
+ from socket import gethostname
+ hostname = gethostname()
+
import os
+ cwd = os.getcwd()
+ for rank, node in enumerate(nodes):
+ if node == 'localhost' or node == hostname:
+ # local paste
+ import pasteCitcomData
+ pasteCitcomData.run(datadir, datafile, opts, rank, timestep, cwd)
+
+ else:
+ # remote paste
+
+ # replace 'rsh' with 'ssh' if necessary
+ remote_shell = 'rsh'
+
+ cmd = '%(remote_shell)s %(node)s pasteCitcomData.py %(datadir)s %(datafile)s %(opts)s %(rank)d %(timestep)d %(cwd)s' % vars()
+ os.system(cmd)
+
+ return
+
+
+
+def batchcombine(nodes, datadir, datafile, timestep, nodex, nodey, nodez,
+ ncap, nprocx, nprocy, nprocz, optional_fields):
# paste
- cmd = 'batchpaste.sh %(datadir)s %(datafile)s %(timestep)d %(nodes)s' \
- % vars()
- print cmd
- os.system(cmd)
+ opts0 = 'coord,velo,visc'
+ opts1 = optional_fields
+ batchpaste(datadir, datafile, opts0, timestep, nodes)
+ batchpaste(datadir, datafile, opts1, timestep, nodes)
+
# combine
- cmd = 'combine.py %(datafile)s %(timestep)d %(nodex)d %(nodey)d %(nodez)d %(ncap)d %(nprocx)d %(nprocy)d %(nprocz)d' % vars()
- print cmd
- os.system(cmd)
+ import combine
+ combine.combine(datafile, opts0, timestep, nodex, nodey, nodez,
+ ncap, nprocx, nprocy, nprocz)
+ combine.combine(datafile, opts1, timestep, nodex, nodey, nodez,
+ ncap, nprocx, nprocy, nprocz)
- # delete
- cmd = 'rm %(datafile)s.[0-9]*.%(timestep)d' % vars()
- print cmd
- os.system(cmd)
+ # delete pasted files
+ import glob
+ filenames = glob.glob('%(datafile)s.*.%(timestep)d.pasted' % vars())
+ import os
+ for filename in filenames:
+ os.remove(filename)
+
+
# create .general file
- cmd = 'dxgeneral.sh %(datafile)s.cap*.%(timestep)d' % vars()
- print cmd
- os.system(cmd)
+ import dxgeneral
+ combined_files0 = []
+ combined_files1 = []
+ for cap in range(ncap):
+ combined_files0.append('%(datafile)s.cap%(cap)02d.%(timestep)d' % vars())
+ combined_files1.append('%(datafile)s.opt%(cap)02d.%(timestep)d' % vars())
+ dxgeneral.write(opts0, combined_files0)
+ dxgeneral.write(opts1, combined_files1)
+
return
@@ -110,10 +160,10 @@
nprocz = int(sys.argv[11])
totalnodes = nprocx * nprocy * nprocz * ncap
- nodelist = machinefile2nodes(machinefile, totalnodes)
+ nodelist = machinefile2nodelist(machinefile, totalnodes)
- combine(nodelist, datadir, datafile, timestep, nodex, nodey, nodez,
- ncap, nprocx, nprocy, nprocz)
+ batchcombine(nodelist, datadir, datafile, timestep, nodex, nodey, nodez,
+ ncap, nprocx, nprocy, nprocz)
Deleted: mc/3D/CitcomS/trunk/visual/batchpaste.sh
===================================================================
--- mc/3D/CitcomS/trunk/visual/batchpaste.sh 2007-04-05 21:54:55 UTC (rev 6509)
+++ mc/3D/CitcomS/trunk/visual/batchpaste.sh 2007-04-05 22:21:46 UTC (rev 6510)
@@ -1,62 +0,0 @@
-#!/bin/sh
-#
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#
-#<LicenseText>
-#
-# CitcomS.py by Eh Tan, Eun-seo Choi, and Pururav Thoutireddy.
-# Copyright (C) 2002-2005, California Institute of Technology.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-#</LicenseText>
-#
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#
-# Run 'pasteCitcomData.sh' in a batch process
-#
-# Requirement: 1) current working directory must be mounted on master_ip too.
-# 2) the list of ip has the same order as the MPI machinefile
-
-if [ -z $4 ]; then
- echo "Usage:" `basename $0` datadir datafile timestep ip1 [ip2 ... ]
- exit
-fi
-
-paste_exe=`which execpaste.py`
-cwd=`pwd`
-datadir=$1
-datafile=$2
-timestep=$3
-rank=0
-
-while [ x"$4" != "x" ]
-do
- cmd_paste="$paste_exe $datadir $datafile $rank $timestep $cwd"
- if [ x"$4" = x"$HOSTNAME" -o $4 = "localhost" ]; then
- $cmd_paste
- else
- rsh $4 "$cmd_paste"
- fi
-
- shift
- rank=$(($rank+1))
-done
-
-
-# version
-# $Id$
-
-# End of file
Modified: mc/3D/CitcomS/trunk/visual/combine.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/combine.py 2007-04-05 21:54:55 UTC (rev 6509)
+++ mc/3D/CitcomS/trunk/visual/combine.py 2007-04-05 22:21:46 UTC (rev 6510)
@@ -35,26 +35,38 @@
class Combine(object):
- def __init__(self, grid):
+ def __init__(self, nodex, nodey, nodez, nprocx, nprocy, nprocz):
+ self.nodex = nodex
+ self.nodey = nodey
+ self.nodez = nodez
+
+ self.nprocx = nprocx
+ self.nprocy = nprocy
+ self.nprocz = nprocz
+
# data storage
- self.saved = range(grid['nox'] * grid['noy'] * grid['noz'])
+ self.saved = range(nodex * nodey * nodez)
return
- def readData(self, filename):
+ def readData(self, filename, headlines=1):
fp = file(filename, 'r')
- header = fp.readline()
- #print header
+
+ # discard the header
+ for i in range(headlines):
+ header = fp.readline()
+ #print header
+
return fp.readlines()
- def join(self, data, me, grid, cap):
+ def join(self, data, me):
# processor geometry
- nprocx = int(cap['nprocx'])
- nprocy = int(cap['nprocy'])
- nprocz = int(cap['nprocz'])
+ nprocx = self.nprocx
+ nprocy = self.nprocy
+ nprocz = self.nprocz
mylocz = me % nprocz
mylocx = ((me - mylocz) / nprocz) % nprocx
@@ -62,26 +74,26 @@
#print me, mylocx, mylocy, mylocz
# mesh geometry
- nox = int(grid['nox'])
- noy = int(grid['noy'])
- noz = int(grid['noz'])
+ nodex = self.nodex
+ nodey = self.nodey
+ nodez = self.nodez
- mynox = 1 + (nox-1)/nprocx
- mynoy = 1 + (noy-1)/nprocy
- mynoz = 1 + (noz-1)/nprocz
+ mynodex = 1 + (nodex-1)/nprocx
+ mynodey = 1 + (nodey-1)/nprocy
+ mynodez = 1 + (nodez-1)/nprocz
- if not len(data) == mynox * mynoy * mynoz:
- raise ValueError, "data size"
+ if not len(data) == mynodex * mynodey * mynodez:
+ raise ValueError, "incorrect data size"
- mynxs = (mynox - 1) * mylocx
- mynys = (mynoy - 1) * mylocy
- mynzs = (mynoz - 1) * mylocz
+ mynxs = (mynodex - 1) * mylocx
+ mynys = (mynodey - 1) * mylocy
+ mynzs = (mynodez - 1) * mylocz
n = 0
- for i in range(mynys, mynys+mynoy):
- for j in range(mynxs, mynxs + mynox):
- for k in range(mynzs, mynzs + mynoz):
- m = k + j * noz + i * nox * noz
+ for i in range(mynys, mynys+mynodey):
+ for j in range(mynxs, mynxs + mynodex):
+ for k in range(mynzs, mynzs + mynodez):
+ m = k + j * nodez + i * nodex * nodez
self.saved[m] = data[n]
n += 1
@@ -89,9 +101,9 @@
- def write(self, filename, grid):
+ def write(self, filename):
fp = file(filename, 'w')
- header = '%d x %d x %d\n' % (grid['nox'], grid['noy'], grid['noz'])
+ header = '%d x %d x %d\n' % (self.nodex, self.nodey, self.nodez)
#print header
fp.write(header)
fp.writelines(self.saved)
@@ -99,6 +111,30 @@
+##############################################
+
+
+def combine(prefix, opts, step, nodex, nodey, nodez,
+ ncap, nprocx, nprocy, nprocz):
+ nproc_per_cap = nprocx * nprocy * nprocz
+ for i in range(ncap):
+ cb = Combine(nodex, nodey, nodez, nprocx, nprocy, nprocz)
+ for n in range(i * nproc_per_cap, (i+1) * nproc_per_cap):
+ filename = '%s.%s.%d.%d.pasted' % (prefix, opts, n, step)
+ print 'reading', filename
+ data = cb.readData(filename, 0)
+ cb.join(data, n)
+
+ if opts == 'coord,velo,visc':
+ filename = '%s.cap%02d.%d' % (prefix, i, step)
+ else:
+ filename = '%s.opt%02d.%d' % (prefix, i, step)
+
+ print 'writing', filename
+ cb.write(filename)
+
+
+
if __name__ == '__main__':
import sys
@@ -110,31 +146,19 @@
prefix = sys.argv[1]
step = int(sys.argv[2])
- grid = {}
- grid['nox'] = int(sys.argv[3])
- grid['noy'] = int(sys.argv[4])
- grid['noz'] = int(sys.argv[5])
+ nodex = int(sys.argv[3])
+ nodey = int(sys.argv[4])
+ nodez = int(sys.argv[5])
ncap = int(sys.argv[6])
- cap = {}
- cap['nprocx'] = int(sys.argv[7])
- cap['nprocy'] = int(sys.argv[8])
- cap['nprocz'] = int(sys.argv[9])
+ nprocx = int(sys.argv[7])
+ nprocy = int(sys.argv[8])
+ nprocz = int(sys.argv[9])
- nproc_per_cap = cap['nprocx'] * cap['nprocy'] * cap['nprocz']
- for i in range(ncap):
- cb = Combine(grid)
- for n in range(i * nproc_per_cap, (i+1) * nproc_per_cap):
- filename = '%s.%d.%d' % (prefix, n, step)
- print 'reading', filename
- data = cb.readData(filename)
- cb.join(data, n, grid, cap)
+ combine(prefix, step, nodex, nodey, nodez,
+ ncap, nprocx, nprocy, nprocz)
- filename = '%s.cap%02d.%d' % (prefix, i, step)
- print 'writing', filename
- cb.write(filename, grid)
-
# version
# $Id$
Added: mc/3D/CitcomS/trunk/visual/dxgeneral.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/dxgeneral.py 2007-04-05 21:54:55 UTC (rev 6509)
+++ mc/3D/CitcomS/trunk/visual/dxgeneral.py 2007-04-05 22:21:46 UTC (rev 6510)
@@ -0,0 +1,137 @@
+#!/usr/bin/env python
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#<LicenseText>
+#
+# CitcomS.py by Eh Tan, Eun-seo Choi, and Pururav Thoutireddy.
+# Copyright (C) 2002-2005, California Institute of Technology.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#</LicenseText>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+
+'''Create OpenDX .general file for combined Citcom Data
+
+ Usage: dxgeneral.py combined_fields file1 [file2 [...]]
+'''
+
+import os, sys
+
+
+def write(opts, filenames):
+
+ for filename in filenames:
+ if not os.path.exists(filename):
+ print 'file "%s" does not exist' % filename
+ sys.exit(1)
+
+ shape = get_shape(filename)
+
+ outfile = filename + '.general'
+ f = open(outfile, 'w')
+
+ try:
+ write_general_file(f, filename, opts, shape)
+ finally:
+ f.close()
+
+ return
+
+
+
+def get_shape(filename):
+
+ # the first line of the file contains the shape information
+ header = open(filename).readline()
+ shape = tuple([int(x) for x in header.split('x')])
+
+ return shape
+
+
+
+def write_general_file(f, filename, opts, shape):
+
+ template = '''file = %(filename)s
+grid = %(shape_str)s
+format = ascii
+interleaving = field
+majority = row
+header = lines 1
+field = %(opt_field_str)s
+structure = %(opt_struct_str)s
+type = %(opt_type_str)s
+
+end
+'''
+
+ # mapping from opt name to field name
+ field = {'comp_nd': 'composition',
+ 'coord': 'locations',
+ 'pressure': 'pressure',
+ 'stress': 'stress',
+ 'velo': 'velocity, temperature',
+ 'visc': 'viscosity'}
+
+ # mapping from opt name to data structure
+ struct = {'comp_nd': 'scalar',
+ 'coord': '3-vector',
+ 'pressure': 'scalar',
+ 'stress': '6-vector',
+ 'velo': '3-vector, scalar',
+ 'visc': 'scalar'}
+
+ # mapping from opt name to data type
+ type = {'comp_nd': 'float',
+ 'coord': 'float',
+ 'pressure': 'float',
+ 'stress': 'float',
+ 'velo': 'float, float',
+ 'visc': 'float'}
+
+ opt_field = []
+ opt_struct = []
+ opt_type = []
+ for opt in opts.split(','):
+ opt_field.append(field[opt])
+ opt_struct.append(struct[opt])
+ opt_type.append(type[opt])
+
+ shape_str = ' x '.join([str(x) for x in shape])
+ opt_field_str = ', '.join(opt_field)
+ opt_struct_str = ', '.join(opt_struct)
+ opt_type_str = ', '.join(opt_type)
+
+ f.write(template % vars())
+ return
+
+
+
+if __name__ == '__main__':
+
+ if len(sys.argv) < 3:
+ print __doc__
+ sys.exit(1)
+
+ opts = sys.argv[1]
+ filenames = sys.argv[2:]
+
+ write(opts, filenames)
+
+
+# End of file
Property changes on: mc/3D/CitcomS/trunk/visual/dxgeneral.py
___________________________________________________________________
Name: svn:executable
+ *
Deleted: mc/3D/CitcomS/trunk/visual/dxgeneral.sh
===================================================================
--- mc/3D/CitcomS/trunk/visual/dxgeneral.sh 2007-04-05 21:54:55 UTC (rev 6509)
+++ mc/3D/CitcomS/trunk/visual/dxgeneral.sh 2007-04-05 22:21:46 UTC (rev 6510)
@@ -1,66 +0,0 @@
-#!/bin/sh
-#
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#
-#<LicenseText>
-#
-# CitcomS.py by Eh Tan, Eun-seo Choi, and Pururav Thoutireddy.
-# Copyright (C) 2002-2005, California Institute of Technology.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-#</LicenseText>
-#
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#
-# Create OpenDX .general file for combined Citcom Data
-#
-
-if [ -z $1 ]; then
- echo " usage:" `basename $0` file1 [file2 ...]
- exit
-fi
-
-
-for i; do
-
- if [ ! -f $i ]; then
- echo file \'$1\' not exist
- exit
- fi
-
- echo processing $i ...
- output=$i.general
- grid=`head -n 1 $i | awk '{print $3, $2, $1, $4, $5}'`
-
- echo file = $i > $output
- echo grid = $grid >> $output
- echo format = ascii >> $output
- echo interleaving = field >> $output
- echo majority = row >> $output
- echo header = lines 1 >> $output
- echo field = locations, velocity, temperature, viscosity >> $output
- echo structure = 3-vector, 3-vector, scalar, scalar >> $output
- echo type = float, float, float, float >> $output
- echo >> $output
- echo end >> $output
-
-done
-
-
-# version
-# $Id$
-
-# End of file
Deleted: mc/3D/CitcomS/trunk/visual/execpaste.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/execpaste.py 2007-04-05 21:54:55 UTC (rev 6509)
+++ mc/3D/CitcomS/trunk/visual/execpaste.py 2007-04-05 22:21:46 UTC (rev 6510)
@@ -1,90 +0,0 @@
-#!/usr/bin/env python
-#
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#
-#<LicenseText>
-#
-# CitcomS.py by Eh Tan
-# Copyright (C) 2006, California Institute of Technology.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-#</LicenseText>
-#
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#
-
-"""Execute pasteCitcomData.sh to retrieve the pasted data
-
-Usage: execpaste.py datadir datafile processor_rank timestep save_dir
-
-datadir: same input parameter for CitcomS
-datafile: same input parameter for CitcomS
-processor_rank: MPI rank of current processor
-timestep: timestep to retrieve
-save_dir: which directory to save the retrieved data
-"""
-
-import sys
-
-if len(sys.argv) != 6:
- print __doc__
- sys.exit()
-
-datadir = sys.argv[1]
-datafile = sys.argv[2]
-rank = sys.argv[3]
-timestep = sys.argv[4]
-save_dir = sys.argv[5]
-
-import os
-paste_exe = "pasteCitcomData.sh"
-
-
-## expand datadir
-s = "%HOSTNAME"
-try:
- datadir.index(s)
-except: pass
-else:
- from socket import gethostname
- datadir = datadir.replace(s, gethostname())
-
-s = "%RANK"
-try:
- datadir.index(s)
-except: pass
-else:
- datadir = datadir.replace(s, rank)
-
-if datadir == "%DATADIR":
- fp = os.popen("citcoms_datadir", "r")
- datadir = fp.readline().strip()
- fp.close()
-
-
-## run paste_exe and copy the pasted data to save_dir
-os.chdir(datadir)
-cmd = """
-%(paste_exe)s %(datafile)s %(rank)s %(timestep)s && \
-cp %(datafile)s.%(rank)s.%(timestep)s %(save_dir)s
-""" % vars()
-os.system(cmd)
-
-
-# version
-# $Id$
-
-# End of file
Added: mc/3D/CitcomS/trunk/visual/pasteCitcomData.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/pasteCitcomData.py 2007-04-05 21:54:55 UTC (rev 6509)
+++ mc/3D/CitcomS/trunk/visual/pasteCitcomData.py 2007-04-05 22:21:46 UTC (rev 6510)
@@ -0,0 +1,171 @@
+#!/usr/bin/env python
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#<LicenseText>
+#
+# CitcomS.py by Eh Tan, Eun-seo Choi, and Pururav Thoutireddy.
+# Copyright (C) 2007, California Institute of Technology.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#</LicenseText>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+
+'''
+Paste CitcomS data together
+
+ Usage: pasteCitcomData.py datadir datafile infix1,infix2[,...] rank step save_dir
+
+datadir: directory of the output files
+datafile: prefix of the output files
+infix1, infix2, ...: the infix to be pasted (e.g.: coord, velo)
+rank: MPI rank of the output
+step: time step of the output
+save_dir: directory for the pasted file
+'''
+
+
+def run(datadir, datafile, opts, rank, step, save_dir):
+
+ outfile = '%s/%s.%s.%d.%d.pasted' % (save_dir, datafile, opts, rank, step)
+ f = open(outfile, 'w')
+
+ try:
+ paste(datadir, datafile, opts, rank, step, f)
+ finally:
+ f.close()
+
+ return
+
+
+
+def paste(datadir, datafile, opts, rank, step, stream=None):
+ if stream is None:
+ import sys
+ stream = sys.stdout
+
+ files = []
+ for infix in opts.split(','):
+ f = open_file(datadir, datafile, infix, rank, step)
+ strip_headerlines(f, infix)
+ files.append(f)
+
+ paste_files_and_write(stream, *files)
+ return
+
+
+
+def expand_datadir(datadir):
+ '''Expand the special strings in datadir
+ '''
+
+ ##
+ s = "%HOSTNAME"
+ try:
+ datadir.index(s)
+ except: pass
+ else:
+ from socket import gethostname
+ datadir = datadir.replace(s, gethostname())
+
+ ##
+ s = "%RANK"
+ try:
+ datadir.index(s)
+ except: pass
+ else:
+ datadir = datadir.replace(s, rank)
+
+ ##
+ if datadir == "%DATADIR":
+ fp = os.popen("citcoms_datadir", "r")
+ datadir = fp.readline().strip()
+ fp.close()
+
+ return datadir
+
+
+
+def open_file(datadir, datafile, infix, rank, step):
+
+ if infix == 'coord':
+ filename = '%s/%s.%s.%d' % (datadir, datafile, infix, rank)
+ else:
+ filename = '%s/%s.%s.%d.%d' % (datadir, datafile, infix, rank, step)
+
+ f = open(filename, 'r')
+ return f
+
+
+
+def strip_headerlines(f, infix):
+ '''Remove the header lines from f
+ '''
+
+ # how many header lines for each infix
+ headers = {'coord': 1,
+ 'botm': 1,
+ 'comp_nd': 1,
+ 'pressure': 2,
+ 'stress': 2,
+ 'surf': 1,
+ 'velo': 2,
+ 'visc': 1}
+
+ nlines = headers[infix]
+ for i in range(nlines):
+ f.readline()
+
+ return
+
+
+
+def paste_files_and_write(stream, *files):
+ # zip all file iterators in one
+ from itertools import izip
+ lines = izip(*files)
+
+ # read all files simulataneously
+ for line in lines:
+ line = ' '.join([x.strip() for x in line]) + '\n'
+ stream.write(line)
+
+ return
+
+
+
+if __name__ == '__main__':
+
+ import sys
+
+ if len(sys.argv) < 6:
+ print __doc__
+ sys.exit()
+
+
+ datadir = expand_datadir(sys.argv[1])
+ datafile = sys.argv[2]
+ opts = sys.argv[3]
+ rank = int(sys.argv[4])
+ step = int(sys.argv[5])
+ save_dir = sys.argv[6]
+
+ run(datadir, datafile, opts, rank, step, save_dir)
+
+
+# End of file
Property changes on: mc/3D/CitcomS/trunk/visual/pasteCitcomData.py
___________________________________________________________________
Name: svn:executable
+ *
Deleted: mc/3D/CitcomS/trunk/visual/pasteCitcomData.sh
===================================================================
--- mc/3D/CitcomS/trunk/visual/pasteCitcomData.sh 2007-04-05 21:54:55 UTC (rev 6509)
+++ mc/3D/CitcomS/trunk/visual/pasteCitcomData.sh 2007-04-05 22:21:46 UTC (rev 6510)
@@ -1,53 +0,0 @@
-#!/bin/sh
-#
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#
-#<LicenseText>
-#
-# CitcomS.py by Eh Tan, Eun-seo Choi, and Pururav Thoutireddy.
-# Copyright (C) 2002-2005, California Institute of Technology.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-#</LicenseText>
-#
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#
-# Gather Citcom data (coordinate, velocity, temperature, viscosity) of current
-# processor into a single file.
-
-if [ -z $3 ]; then
- echo " usage:" `basename $0` datafile processor_rank timestep
- exit
-fi
-
-datafile=$1
-rank=$2
-step=$3
-
-line=`cat $datafile.velo.$rank.$step | wc -l`
-#echo $line
-line=$(($line - 1))
-#echo $line
-
-tail -n $line $datafile.velo.$rank.$step \
- | paste -d' ' $datafile.coord.$rank - $datafile.visc.$rank.$step \
- > $datafile.$rank.$step
-
-
-# version
-# $Id$
-
-# End of file
More information about the cig-commits
mailing list