This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
2009-02-09 23:12:39 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from laydi import dataset
|
|
|
|
from getopt import getopt
|
|
|
|
|
|
|
|
def read_options():
|
|
|
|
short_opts = ""
|
|
|
|
long_opts = []
|
|
|
|
|
|
|
|
options, params = getopt(sys.argv[1:], short_opts, long_opts)
|
|
|
|
|
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
def write_csv(fd, ds):
|
|
|
|
rowdim, coldim = ds.get_dim_name()
|
2009-02-28 16:38:29 +01:00
|
|
|
rowids = ds.get_identifiers(rowdim, sorted=True)
|
|
|
|
colids = ds.get_identifiers(coldim, sorted=True)
|
2009-02-09 23:12:39 +01:00
|
|
|
x = ds.asarray()
|
|
|
|
|
|
|
|
## Print ID row
|
|
|
|
print >> fd, rowdim,
|
|
|
|
for id in colids:
|
|
|
|
print >> fd, id,
|
|
|
|
print >> fd
|
|
|
|
|
|
|
|
## Print column IDs and data
|
|
|
|
for i, row in enumerate(rowids):
|
|
|
|
print >> fd, row,
|
|
|
|
for j in range(len(colids)):
|
|
|
|
print >> fd, x[i,j],
|
|
|
|
print >> fd
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
params = read_options()
|
|
|
|
input_fn = params[0]
|
|
|
|
|
|
|
|
if len(params) == 2:
|
|
|
|
output_fn = params[1]
|
|
|
|
else:
|
|
|
|
name, ext = input_fn.rsplit('.', 1)
|
|
|
|
output_fn = name + '.csv'
|
|
|
|
|
|
|
|
ds = dataset.read_ftsv(input_fn)
|
|
|
|
output_fd = open(output_fn, 'w')
|
|
|
|
write_csv(output_fd, ds)
|
|
|
|
output_fd.close()
|
|
|
|
|