1 #!/usr/bin/env python
 2 
 3 """Split a file in two using the 1st column depth."""
 4 
 5 #     Copyright (C) 2004  Kurt Schwehr
 6 
 7 
 8 #     This program is free software; you can redistribute it and/or modify
 9 #     it under the terms of the GNU General Public License as published by
10 #     the Free Software Foundation; either version 2 of the License, or
11 #     (at your option) any later version.
12 
13 #     This program is distributed in the hope that it will be useful,
14 #     but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #     GNU General Public License for more details.
17 
18 #     You should have received a copy of the GNU General Public License
19 #     along with this program; if not, write to the Free Software
20 #     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 
22 
23 
24 import os, os.path, string, sys
25 import re # Regular expressions
26 if (5 != len(sys.argv)):
27     print len(sys.argv)
28     print sys.argv
29     print '\n   ERROR:  invalid number of arguments'
30     print "   USAGE: ",sys.argv[0], " depth in.dat out-low.dat out-high.dat"
31     sys.exit(1)
32 
33 i=1
34 depth=float(sys.argv[i]); i=i+1
35 inFileName=sys.argv[i]; i=i+1
36 outFileName1=sys.argv[i]; i=i+1
37 outFileName2=sys.argv[i]; i=i+1
38 
39 if (1 == os.access(outFileName1,os.F_OK)):
40     print "ERROR: output file exists.  do not want to over write!!"
41     print "  ", outFileName1
42     sys.exit(1)
43 
44 if (1 == os.access(outFileName2,os.F_OK)):
45     print "ERROR: output file exists.  do not want to over write!!"
46     print "  ", outFileName2
47     sys.exit(1)
48 
49 infile = open(inFileName,"r");
50 outfile1 = open(outFileName1,"w");
51 outfile2 = open(outFileName2,"w");
52 
53 for line in infile.xreadlines():
54     s = line.split()
55     d = float(s[0])
56     if (d<depth):
57         outfile1.write (line)
58     else:
59         outfile2.write (line)
60             


syntax highlighted by Code2HTML, v. 0.9.1