Ignore:
Timestamp:
Apr 26, 2009, 5:35:16 PM (16 years ago)
Author:
rwilson
Message:

Patong beach validation changes plus back-merge changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • misc/tools/write_large_files/rwi_big_file.py

    r6739 r6906  
    88# that is checked when the file is read.
    99#
    10 # So, element E of slice S ov variable V has the float value:
    11 #     V*1000 + S . E*1.0e-1
     10# So, for variable V (numbering from 0), slice S (starting from 0), element
     11# E will range from 0 to 10**6-1, and the element value will be:
     12#     S*100 + V + E*1.0E-6
    1213# which will look like:
    13 #     VVVSSSS.0EEEEEE
     14#     SSSSVV.EEEEEE
     15# This implies that the maximum number of variables written is 100 (0 to 99).
    1416################################################################################
    1517
     
    2830
    2931# array slice definitions
    30 XDIM = 1024*1024
     32XDIM = 1000*1000
    3133SLICE_SIZE = XDIM*8     # 8 bytes / float
    3234MBYTE = 1024*1024
     
    4749
    4850# mask for variable names
    49 VarnameMask = 'var_%04d'
     51VarnameMask = 'var_%02d'
    5052
    5153
     
    8789
    8890            # create expected slice array
    89             slice_array = slice_array_mask*slice_number + var_num*1000
    90             for x in xrange(XDIM):
    91                 slice_array[x] += x*1.0e-7
     91            slice_array = slice_array_mask*slice_number*100 + var_num
     92            slice_array += ElementIndexArray
    9293
    9394            if Verbose:
    9495                print ('File %s, variable %s, reading slice %d: '
    9596                       'var=%.1fMiB, file=%.1fMiB' %
    96                        (filename, varname, slice_number, float(var_bytes_read)/MBYTE,
     97                       (filename, varname, slice_number,
     98                        float(var_bytes_read)/MBYTE,
    9799                        float(file_bytes_read)/MBYTE))
    98100
    99101            var_array = fid.variables[varname][slice_number,:]
    100             if var_array != slice_array:
    101                 result = False
    102                 if Verbose:
    103                     print 'Read variable %s, slice %d: got unexpected value' % \
    104                           (varname, slice_number)
    105                     for x in xrange(XDIM):
    106                         if var_array[x] != slice_array[x]:
    107                             print 'Got %f, expected %f' % (var_array[x], slice_array[x])
    108                     sys.exit(0)
     102            if not num.allclose(var_array, slice_array):
     103##            if num.any(var_array != slice_array):
    109104                print 'Read variable %s, slice %d: got unexpected value' % \
    110105                      (varname, slice_number)
    111106                for x in xrange(XDIM):
    112107                    if var_array[x] != slice_array[x]:
    113                         print 'Got %f, expected %f' % (var_array[x], slice_array[x])
    114                         sys.exit(0)
     108                        print 'Index %d, got %f, expected %f' % \
     109                              (x, var_array[x], slice_array[x])
     110                        return False
    115111
    116112            slice_number += 1
     
    127123               (stop_file_read - start_file_read))
    128124
    129     return result
     125    return True
    130126
    131127
     
    168164
    169165            # create unique slice array
    170             slice_array = slice_array_mask*slice_number + var_num*1000
    171             for x in xrange(XDIM):
    172                 slice_array[x] += x*1.0e-7
     166            slice_array = slice_array_mask*slice_number*100 + var_num
     167            slice_array += ElementIndexArray
    173168
    174169            fid.variables[varname][slice_number,:] = slice_array
     
    188183
    189184        slice_number += 1
     185
     186    fid.close()
    190187
    191188    if TimeFileWrite:
     
    209206    print "  and <numvars> is the number of variables of the above size"
    210207    print "                    to write.  If not supplied, 1 is assumed."
     208    print "                    There can be at most 100 variables."
    211209    print "  and <opts>    is zero or more of:"
    212210    print "                    -c s    close & open the output file after"
     
    222220def main(argv=None):
    223221    global TimeFileWrite, TimeFileRead, CloseAfterSlice, Verbose
     222    global ElementIndexArray
    224223
    225224    if argv is None:
     
    264263
    265264    var_size = args[0][:-1]
    266     modifier =args[0][-1]
     265    modifier = args[0][-1]
    267266
    268267    if modifier in '0123456789':
     
    285284            usage()
    286285
     286    if num_vars > 100:
     287        usage()
     288
     289    # initialize the global element index array which contains
     290    # 0.EEEEEE in each element.
     291    ElementIndexArray = num.ndarray((XDIM,), 'd')
     292    for x in xrange(XDIM):
     293        ElementIndexArray[x] = x*1.0e-6
     294   
    287295    # write the required file
    288296    filename = write_file(var_size, num_vars)
     
    293301        return 10
    294302
    295     print 'Read/write of NectCDF file was correct'
     303#    print 'Read/write of NectCDF file was correct'
    296304    return 0
    297305
Note: See TracChangeset for help on using the changeset viewer.