source: inundation/ga/storm_surge/pmesh/scripts/csv2xya.py @ 349

Last change on this file since 349 was 349, checked in by duncan, 20 years ago

adding pmesh

File size: 872 bytes
Line 
1#!/usr/bin/python
2"""
3Convert a .cvs file from gis to a xya file, for pmesh.
4(removes the 1st column in a cvs file and renames it from .cvs to .xya)
5"""
6import os, sys
7
8usage = "usage: %s input_file_name.csv" %         os.path.basename(sys.argv[0])
9
10if (len(sys.argv)< 2) or not (sys.argv[1][-4:]== ".csv"):
11    print usage
12else:
13    read_file_name = sys.argv[1]
14    write_file_name = read_file_name[:-4] + ".xya"
15    file_obj = open(read_file_name)
16    lines = file_obj.readlines()
17    file_obj.close()
18
19   
20    fd = open(write_file_name,'w')
21    for line in lines:
22        elements = line.split(',')
23        elements.pop(0) # remove the 1st column
24        if len(elements) > 0: #if there is a 2nd column, write it
25            fd.write(elements.pop(0))
26        for element in elements:
27            fd.write(',')
28            fd.write(element)
Note: See TracBrowser for help on using the repository browser.