hWriteFileBinary(vec, filename)
Dump a single vector to a file in binary format (machine dependent).
Parameters
vec Output data vector. filename Filename (including path if necessary) to write file to.
Usage
vec.writefilebinary(filename) -> dumps vector to file
See also
hReadFileBinary(), hWriteFileBinary(), hWriteFileBinaryAppend()
Example
>>> v=Vector(float,10,fill=3.0)
>>> hWriteFileBinary(v,'test.dat')
>>> x=Vector(float,10,fill=1.0)
>>> hReadFileBinary(x,'test.dat')
>>> x
Vector(float, 10, [3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0])
hWriteFileBinary(vec, filename, start)
Dump a single vector to a file in binary format (machine dependent).
Parameters
vec Output data vector. filename Filename (including path if necessary) to write file to. start Start writing at element ‘start’ (zero-based index), the data block length to write is determined by the vector length.
Description
Attention: if a file exists already and a start value is specified, then it will not be overwritten, but the data will be written into the location asked by start. This can be dangerous if one writes a smaller file (e.g. with start=0) to a pre-existing older and larger file because then the ‘new’ file will contain the rest of the old file.
Usage
vec.writedump(filename,start) -> writes binary vector data at location start in the file
See also
hReadFileBinary(), hWriteFileBinary(), hWriteFileBinaryAppend()
Example
>>> v=Vector(float,10,fill=3.0)
>>> hWriteFileBinary(v,'test.dat',0)
>>> v.fill(2.0)
>>> hWriteFileBinary(v,'test.dat',5)
>>> x=Vector(float,15,fill=1.0)
>>> hReadFileBinary(x,'test.dat')
>>> x
Vector(float, 15, [3.0, 3.0, 3.0, 3.0, 3.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0])
hWriteFileBinaryAppend(vec, filename)
Dump a single vector and append it to the end of a file in binary format (machine dependent).
Parameters
vec Output data vector. filename Filename (including path if necessary) to write file to.
Usage
vec.writefilebinaryappend(filename,true) -> appends binary vector data to end of file
See also
hReadFileBinary(), hWriteFileBinary(), hWriteFileBinaryAppend()
Example
>>> v=Vector(float,10,fill=3.0)
>>> hWriteFileBinary(v,'test.dat')
>>> v.fill(2.0)
>>> hWriteFileBinaryAppend(v,'test.dat')
>>> x=Vector(float,20,fill=1.0)
>>> hReadFileBinary(x,'test.dat')
>>> x
Vec(float,20)=[3.0,3.0,3.0,3.0,3.0,...,2.0,2.0]
hWriteFileBinary(vec, filename)
Dump a single vector to a file in binary format (machine dependent).
Parameters
vec Output data vector. filename Filename (including path if necessary) to write file to.
Usage
vec.writefilebinary(filename) -> dumps vector to file
See also
hReadFileBinary(), hWriteFileBinary(), hWriteFileBinaryAppend()
Example
>>> v=Vector(float,10,fill=3.0)
>>> hWriteFileBinary(v,'test.dat')
>>> x=Vector(float,10,fill=1.0)
>>> hReadFileBinary(x,'test.dat')
>>> x
Vector(float, 10, [3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0])
hWriteFileBinary(vec, filename, start)
Dump a single vector to a file in binary format (machine dependent).
Parameters
vec Output data vector. filename Filename (including path if necessary) to write file to. start Start writing at element ‘start’ (zero-based index), the data block length to write is determined by the vector length.
Description
Attention: if a file exists already and a start value is specified, then it will not be overwritten, but the data will be written into the location asked by start. This can be dangerous if one writes a smaller file (e.g. with start=0) to a pre-existing older and larger file because then the ‘new’ file will contain the rest of the old file.
Usage
vec.writedump(filename,start) -> writes binary vector data at location start in the file
See also
hReadFileBinary(), hWriteFileBinary(), hWriteFileBinaryAppend()
Example
>>> v=Vector(float,10,fill=3.0)
>>> hWriteFileBinary(v,'test.dat',0)
>>> v.fill(2.0)
>>> hWriteFileBinary(v,'test.dat',5)
>>> x=Vector(float,15,fill=1.0)
>>> hReadFileBinary(x,'test.dat')
>>> x
Vector(float, 15, [3.0, 3.0, 3.0, 3.0, 3.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0])
hReadFileBinary(vec, filename, start)
Read a section (block) of a single vector from a file which was dumped in (machine-dependent) binary format.
Parameters
vec Input data vector. filename Filename (including path if necessary) to read data from. The vector needs to have the length corresponding to the file size. start Start reading at element ‘start’ (zero-based index), the data block length to read is determined by the vector length.
Usage
vec.readdump(filename,start) -> reads a specfic block from file starting at element start (blocklength determined by ``len(vec)).``
See also
hReadFileBinary(), hWriteFileBinary(), hWriteFileBinaryAppend(), hWriteFileText(), hReadFileText()
Example
>>> x=hArray(range(20))
>>> x.writefilebinary('test.dat')
>>> v=hArray(int,10)
>>> v.readfilebinary('test.dat',0)
>>> v.pprint()
[0,1,2,3,4,5,6,7,8,9]
#Now read the third block (of length 3) into the first part of the vector
>>> v[0:3].readfilebinary('test.dat',2*3)
>>> v.pprint()
[6,7,8,3,4,5,6,7,8,9]
hReadFileBinary(vec, filename)
Read a single vector from a file which was dumped in (machine-dependent) binary format
Parameters
vec Input data vector. filename Filename (including path if necessary) to read data from. The vector needs to have the length corresponding to the file size.
Usage
vec.readdump(filename) -> reads dumped vector from file
See also
hReadFileBinary(), hWriteFileBinary(), hWriteFileBinaryAppend(), hWriteFileText(), hReadFileText()
Example
>>> v=Vector(float,10,fill=3.0)
>>> hWriteFileBinary(v,'test.dat')
>>> x=Vector(float,10,fill=1.0)
>>> hReadFileBinary(x,'test.dat')
>>> x
Vec(float,10)=[3.0,3.0,3.0,3.0,3.0,...]
hOffsetReadFileBinary(vec, filename, start)
Read a section (block) of a single vector from a file which was dumped in (machine-dependent) binary format with offsets.
Parameters
vec Input data vector. filename Filename (including path if necessary) to read data from. The vector needs to have the length corresponding to the file size. start Start reading at element ‘start’ (zero-based index), the data block length to read is determined by the vector length.
Example
>>> v=hArray(range(100))
>>> hWriteFileBinary(v, 'test.dat')
>>> n=hArray(int, 10)
>>> i=hArray(range(0,20,2))
>>> n
hArray(int, [10L], fill=[0,0,0,0,0,0,0,0,0,0]) # len=10 slice=[0:10])
>>> hOffsetReadFileBinary(n, 'test.dat', i)
>>> n
hArray(int, [10L], fill=[0,2,4,6,8,10,12,14,16,18]) # len=10 slice=[0:10])
hReadFileBinary(vec, filename, start)
Read a section (block) of a single vector from a file which was dumped in (machine-dependent) binary format.
Parameters
vec Input data vector. filename Filename (including path if necessary) to read data from. The vector needs to have the length corresponding to the file size. start Start reading at element ‘start’ (zero-based index), the data block length to read is determined by the vector length.
Usage
vec.readdump(filename,start) -> reads a specfic block from file starting at element start (blocklength determined by ``len(vec)).``
See also
hReadFileBinary(), hWriteFileBinary(), hWriteFileBinaryAppend(), hWriteFileText(), hReadFileText()
Example
>>> x=hArray(range(20))
>>> x.writefilebinary('test.dat')
>>> v=hArray(int,10)
>>> v.readfilebinary('test.dat',0)
>>> v.pprint()
[0,1,2,3,4,5,6,7,8,9]
#Now read the third block (of length 3) into the first part of the vector
>>> v[0:3].readfilebinary('test.dat',2*3)
>>> v.pprint()
[6,7,8,3,4,5,6,7,8,9]
hReadFileBinary(vec, filename)
Read a single vector from a file which was dumped in (machine-dependent) binary format
Parameters
vec Input data vector. filename Filename (including path if necessary) to read data from. The vector needs to have the length corresponding to the file size.
Usage
vec.readdump(filename) -> reads dumped vector from file
See also
hReadFileBinary(), hWriteFileBinary(), hWriteFileBinaryAppend(), hWriteFileText(), hReadFileText()
Example
>>> v=Vector(float,10,fill=3.0)
>>> hWriteFileBinary(v,'test.dat')
>>> x=Vector(float,10,fill=1.0)
>>> hReadFileBinary(x,'test.dat')
>>> x
Vec(float,10)=[3.0,3.0,3.0,3.0,3.0,...]
hReadFileText(vec, filename, skiprows, columns, nrows)
Read columns of data from a file in text (ASCII) form into an array
Parameters
vec Input data vector. filename Filename (including path if necessary) to read data from. skiprows The number of rows to skip before reading the data. columns An array with a list of column numbers (starting at zero) from which to read data into the array. Read all if empty. nrows The number of rows to read. If equal to -1 read all.
Usage
vec.readtexttable(filename,skiprows,columns,nrows) -> reads a number of columns into the vector vec
See also
hReadFileBinary(), hWriteFileBinary(), hWriteFileBinaryAppend(), hWriteFileText(), hReadFileText()
Example
>>> from pycrtools import *
>>> vec=Vector(float,24*3)
>>> hReadFileText(vec, 'AERAcoordinates-1.txt', 4, Vector([5,3,7]),10)
# This will skip the first 4 rows and then read 10 rows where columns
# 5,3,&7 will be read into the vector vec. The ordering will be [l0.c5,
# l0.c3, l0.c7, l1.c5, l1.c3, l1.c7, ..., l9.c7] (where l and c stand
# for row and column respectively)
hWriteFileText(vec, filename, header, ncolumns, nrows, append)
Write columns of data in an array to a (ASCII) text file.
Parameters
vec Output data vector. filename Filename (including path if necessary) to write data to. header The header to preceed the table, e.g. a description of the columns. ncolumns The number of columns in the table. nrows The number of rows to write. If equal to -1 write all. append If true append data to the file, rather than overwrite it.
Usage
vec.writetexttable(filename,header,ncolumns,nrows) -> write vec as table into filename
See also
hReadFileBinary(), hWriteFileBinary(), hWriteFileBinaryAppend(), hWriteFileText(), hReadFileText()
Example
>>> vec=Vector(float,24*3,fill=range(24*3))
>>> vec.writetexttable('table.dat','# col1, col2, col3', 3, 24,False)