#!/usr/bin/env python
"""
File format converter.
The script converts csv file to netcdf format.

Limitations:
1) only for small csv files
2) csv files without header - csv module is not used!

"""

import sys
import os.path
import csv
import pupynere


def update_name(old_name):
    new = old_name.split('.')
    new[-1] = 'nc'
    return '.'.join(new)


def csv_to_nc(csvfl):
    """
    Transforms csv file into netcdf format.

    :Args:
      - csvfl cvs data file, example: data.csv

    :Returns:
      - netcdf file, example: data.nc
    """

    with open(sys.argv[1], 'r') as f:
        ll = [l.strip().split(',') for l in 
              f.readlines() if not l.startswith('#')]

    vv = zip(*[map(float, l) for l in ll])

    transformed_file = update_name(sys.argv[1])
    nc = pupynere.netcdf_file(transformed_file, 'w')

    nc.createDimension('dim', None)

    for i, item in enumerate(vv):
       nc.createVariable('var_%02d' % i, 'd', ('dim',))[:] = vv[i]
    return 0


if __name__ == "__main__":
    import sys
    if len(sys.argv) < 2:
        print("Usage: nc.py csvfile")
        raise SystemExit(1)

    if not os.path.exists(sys.argv[1]):
        print("Error: csvdata file {0} not found".format(sys.argv[1]))
        raise SystemExit(1)

    csv_to_nc(sys.argv[1])
   

@@ -94,104 +94,8 @@
 t.%0A%0A
-Limitations:%0A1) only for small csv files%0A2) csv files without header - csv module is not used!%0A%0A
 %22%22%22%0A
@@ -253,16 +253,176 @@
 (new)%0A%0A%0A
+def read_file(fl):%0A    with open(fl, 'r') as f:%0A        for line in f:%0A            if not line.startswith('#'):%0A                yield line.strip().split(',')%0A%0A%0A
 def csv_
@@ -612,146 +612,8 @@
 %22%22%0A%0A
-    with open(sys.argv%5B1%5D, 'r') as f:%0A        ll = %5Bl.strip().split(',') for l in %0A              f.readlines() if not l.startswith('#')%5D%0A%0A
     
@@ -650,10 +650,24 @@
  in 
-ll
+read_file(csvfl)
 %5D)%0A%0A
@@ -701,27 +701,21 @@
 te_name(
-sys.argv%5B1%5D
+csvfl
 )%0A    nc
@@ -991,21 +991,32 @@
         
-print
+sys.stderr.write
 (%22Usage:
@@ -1029,16 +1029,18 @@
  csvfile
+%5Cn
 %22)%0A     
@@ -1115,13 +1115,24 @@
     
-print
+sys.stderr.write
 (%22Er
@@ -1162,16 +1162,18 @@
 ot found
+%5Cn
 %22.format

Add generator for reading csv file, update docstrings