<s> from numpy . random . mtrand import uniform <EOL> import netCDF4 <EOL> from timeit import Timer <EOL> import os , sys <EOL> n1dim = <NUM_LIT:30> <EOL> n2dim = <NUM_LIT:15> <EOL> n3dim = <NUM_LIT> <EOL> n4dim = <NUM_LIT> <EOL> ntrials = <NUM_LIT:10> <EOL> sys . stdout . write ( '<STR_LIT>' % ( n1dim , n2dim , n3dim , n4dim ) ) <EOL> array = uniform ( size = ( n1dim , n2dim , n3dim , n4dim ) ) <EOL> def write_netcdf ( filename , zlib = False , least_significant_digit = None , format = '<STR_LIT>' ) : <EOL> file = netCDF4 . Dataset ( filename , '<STR_LIT:w>' , format = format ) <EOL> file . createDimension ( '<STR_LIT>' , n1dim ) <EOL> file . createDimension ( '<STR_LIT>' , n2dim ) <EOL> file . createDimension ( '<STR_LIT>' , n3dim ) <EOL> file . createDimension ( '<STR_LIT>' , n4dim ) <EOL> foo = file . createVariable ( '<STR_LIT:data>' , '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , zlib = zlib , least_significant_digit = least_significant_digit ) <EOL> foo [ : ] = array <EOL> file . close ( ) <EOL> def read_netcdf ( filename ) : <EOL> file = netCDF4 . Dataset ( filename ) <EOL> data = file . variables [ '<STR_LIT:data>' ] [ : ] <EOL> file . close ( ) <EOL> for format in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> sys . stdout . write ( '<STR_LIT>' % format ) <EOL> t = Timer ( "<STR_LIT>" % format , "<STR_LIT>" ) <EOL> sys . stdout . write ( '<STR_LIT>' % repr ( sum ( t . repeat ( ntrials , <NUM_LIT:1> ) ) / ntrials ) ) <EOL> t = Timer ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> sys . stdout . write ( '<STR_LIT>' % <EOL> repr ( sum ( t . repeat ( ntrials , <NUM_LIT:1> ) ) / ntrials ) ) </s>
