Ignore:
Timestamp:
Jun 30, 2009, 2:07:41 PM (15 years ago)
Author:
ole
Message:

Merged numpy branch back into the trunk.

In ~/sandpit/anuga/anuga_core/source
svn merge -r 6246:HEAD ../../branches/numpy .

In ~/sandpit/anuga/anuga_validation
svn merge -r 6417:HEAD ../branches/numpy_anuga_validation .

In ~/sandpit/anuga/misc
svn merge -r 6809:HEAD ../branches/numpy_misc .

For all merges, I used numpy version where conflicts existed

The suites test_all.py (in source/anuga) and validate_all.py passed using Python2.5 with numpy on my Ubuntu Linux box.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/system_tools.py

    r7036 r7276  
    66import sys
    77import os
     8import string
    89import urllib
    910import urllib2
     
    2122
    2223    fid = open(filename, 'a')
    23     if verbose: s
     24    if verbose: print s
    2425    fid.write(s + '\n')
    2526    fid.close()
     
    239240            print 'Version info stored to %s' %filename
    240241
     242
    241243def safe_crc(string):
    242244    """64 bit safe crc computation.
    243245
    244        See Guido's 64 bit fix at http://bugs.python.org/issue1202           
     246    See http://docs.python.org/library/zlib.html#zlib.crc32:
     247
     248        To generate the same numeric value across all Python versions
     249        and platforms use crc32(data) & 0xffffffff.
    245250    """
    246251
    247252    from zlib import crc32
    248     import os
    249 
    250     x = crc32(string)
    251        
    252     if os.name == 'posix' and os.uname()[4] in ['x86_64', 'ia64']:
    253         crcval = x - ((x & 0x80000000) << 1)
    254     else:
    255         crcval = x
    256        
    257     return crcval
     253
     254    return crc32(string) & 0xffffffff
    258255
    259256
     
    304301    #    p1 = read_polygon(path)
    305302       
    306            
     303   
     304##
     305# @brief Split a string into 'clean' fields.
     306# @param str The string to process.
     307# @param delimiter The delimiter string to split 'line' with.
     308# @return A list of 'cleaned' field strings.
     309# @note Any fields that were initially zero length will be removed.
     310# @note If a field contains '\n' it isn't zero length.
     311def clean_line(str, delimiter):
     312    """Split string on given delimiter, remove whitespace from each field."""
     313
     314    return [x.strip() for x in str.strip().split(delimiter) if x != '']
     315
     316
     317################################################################################
     318# The following two functions are used to get around a problem with numpy and
     319# NetCDF files.  Previously, using Numeric, we could take a list of strings and
     320# convert to a Numeric array resulting in this:
     321#     Numeric.array(['abc', 'xy']) -> [['a', 'b', 'c'],
     322#                                      ['x', 'y', ' ']]
     323#
     324# However, under numpy we get:
     325#     numpy.array(['abc', 'xy']) -> ['abc',
     326#                                    'xy']
     327#
     328# And writing *strings* to a NetCDF file is problematic.
     329#
     330# The solution is to use these two routines to convert a 1-D list of strings
     331# to the 2-D list of chars form and back.  The 2-D form can be written to a
     332# NetCDF file as before.
     333#
     334# The other option, of inverting a list of tag strings into a dictionary with
     335# keys being the unique tag strings and the key value a list of indices of where
     336# the tag string was in the original list was rejected because:
     337#    1. It's a lot of work
     338#    2. We'd have to rewite the I/O code a bit (extra variables instead of one)
     339#    3. The code below is fast enough in an I/O scenario
     340################################################################################
     341
     342##
     343# @brief Convert 1-D list of strings to 2-D list of chars.
     344# @param l 1-dimensional list of strings.
     345# @return A 2-D list of 'characters' (1 char strings).
     346# @note No checking that we supply a 1-D list.
     347def string_to_char(l):
     348    '''Convert 1-D list of strings to 2-D list of chars.'''
     349
     350    if not l:
     351        return []
     352
     353    if l == ['']:
     354        l = [' ']
     355
     356    maxlen = reduce(max, map(len, l))
     357    ll = [x.ljust(maxlen) for x in l]
     358    result = []
     359    for s in ll:
     360        result.append([x for x in s])
     361    return result
     362
     363
     364##
     365# @brief Convert 2-D list of chars to 1-D list of strings.
     366# @param ll 2-dimensional list of 'characters' (1 char strings).
     367# @return A 1-dimensional list of strings.
     368# @note Each string has had right-end spaces removed.
     369def char_to_string(ll):
     370    '''Convert 2-D list of chars to 1-D list of strings.'''
     371
     372    return map(string.rstrip, [''.join(x) for x in ll])
     373
     374################################################################################
     375
    307376##
    308377# @brief Get list of variable names in a python expression string.
     
    396465    # Get auth info from user if still not supplied
    397466    if httpproxy is None or proxyuser is None or proxypass is None:
    398         print '-'*52
     467        print '-'*72
    399468        print ('You need to supply proxy authentication information.')
    400469        if httpproxy is None:
     
    410479        else:
    411480            print 'HTTP proxy password was supplied: %s' % '*'*len(proxyuser)
    412         print '-'*52
     481        print '-'*72
    413482
    414483    # the proxy URL cannot start with 'http://', we add that later
     
    482551# @param blocksize Size of data blocks to read.
    483552# @return A hex digest string (16 bytes).
    484 # @note Uses MD5 digest.
     553# @note Uses MD5 digest if hashlib not available.
    485554def get_file_hexdigest(filename, blocksize=1024*1024*10):
    486555    '''Get a hex digest of a file.'''
     
    501570    return m.hexdigest()
    502571
    503     fd = open(filename, 'r')
    504 
    505572
    506573##
     
    517584    fd.close()
    518585
     586
    519587##
    520588# @brief Function to return the length of a file.
Note: See TracChangeset for help on using the changeset viewer.