Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision f23ffbf5bd19153f4c488496073a4629d024379a authored by Leif Strand on 18 September 2007, 01:52:50 UTC, committed by Leif Strand on 18 September 2007, 01:52:50 UTC
Fix for Issue129: "CitcomS configured without exchanger still links
with -lExchanger".  Also, use CIT_HEADER_MPI so that configuring
--with-exchanger using MPICH2 works (see Issue14 and Issue57).

1 parent a2fd2a4
  • Files
  • Changes
  • 5c39847
  • /
  • visual
  • /
  • h5tocap.py
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:f23ffbf5bd19153f4c488496073a4629d024379a
directory badge Iframe embedding
swh:1:dir:ab00242265df3e222dbfb5a8d0d52fd14d760b68
content badge Iframe embedding
swh:1:cnt:660fc4239a120d40168c9a4d5973da258cedc4ed
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
h5tocap.py
#!/usr/bin/env python
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#<LicenseText>
#
# CitcomS.py by Eh Tan
# Copyright (C) 2002-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>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

'''
Convert the CitcomS HDF5 output file to ASCII file(s), with the format of the
combined cap files

usage: h5tocap.py modelname step1 [step2 [...] ]
'''

import sys


### check whether 'PyTables' is importable
try:
    import tables
except ImportError, exc:
    print "Import Error:", exc
    print """
This script needs the 'PyTables' extension package.
Please install the package before running the script, or you can use the
'h5tocap' program."""
    sys.exit(1)


def convert(h5fid, prefix, step):
    # this file contains time-independent data, e.g., coordinates
    root = h5fid.root

    # get attribute 'caps' (# of caps) in the input group
    caps = int(root.input._v_attrs.caps)

    # this file contains time-depedent data, e.g., velocity, temperature
    h5file2 = '%s.%d.h5' % (prefix, step)
    fid2 = tables.openFile(h5file2, 'r')
    root2 = fid2.root

    try:
        # loop through all the caps
        for cap in range(caps):
            x = root.coord[cap, :]
            v = root2.velocity[cap, :]
            t = root2.temperature[cap, :]
            visc = root2.viscosity[cap, :]

            outputfile = '%s.cap%02d.%d' % (prefix, cap, step)

            print 'writing to', outputfile, '...'
            output(outputfile, x, v, t, visc)
    finally:
        fid2.close()

    return



def output(outputfile, x, v, t, visc):
    out = file(outputfile, 'w')
    try:
        # write header (shape of the arrays)
        nx, ny, nz = t.shape[:3]
        header = '%d x %d x %d\n' % (nx, ny, nz)
        out.write(header)

        # write data
        format = '%.6e '*7 + '%.6e\n'
        for j in range(ny):
            for i in range(nx):
                for k in range(nz):
                    #n = k + i*nz + j*nz*nx
                    xx = x[i, j, k, :]
                    vv = v[i, j, k, :]
                    tt = t[i, j, k]
                    hh = visc[i, j, k]
                    line = format % (
                        xx[0], xx[1], xx[2],
                        vv[0], vv[1], vv[2],
                        tt, hh )
                    out.write(line)

    finally:
        out.close()

    return



if __name__ == '__main__':
    import sys, os.path

    if len(sys.argv) < 3:
        print __doc__
        sys.exit(1)


    modelname = sys.argv[1]
    steps = [ int(x) for x in sys.argv[2:] ]

    h5file = modelname + '.h5'
    fid = tables.openFile(h5file, 'r')
    try:
        for step in steps:
            try:
                convert(fid, modelname, step)
            except ValueError, exc:
                print "Error: ", exc
    finally:
        fid.close()


# version
# $Id$

# End of file
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top