#!/usr/bin/python # ''' ************************************************************************* PRE-PROCESSING OF GRAVITY DATA EXTRACT AND RE-FORMAT DATA FROM NAVLOG FILE Example input line: 20:50:57 08.08.2008, 610251.9206,8254559.5161, 074°21.041857', 018°39.827384', 46.6300, 10102.0200, 0.0000 Example desired output line: 08.08.2008 20:50:57 074 21.041857' 018 39.827384' 46.6300 10102.0200 0.0000 Program version: ------------------------------------------ Ver. Date By Description ------------------------------------------ 0.1 27 Oct 2009 O.M. Initial version Dept. of Earth Science University of Bergen Norway ************************************************************************* ''' from string import split, replace from sys import argv, exit # Give name of input file on command line # What you write on command line is available in "argv" array # First verify that file name is present; in that case "argv" contains # two elements - the name of the script itself in first posistion, # and the name of the input data file in the second position. if len(argv) <> 2: print "Need name of input file as argument" exit(-1) FileName = argv[1] # Now get second element (arrays start indexing from zero) f = open(FileName) # Open input file. #-- Loop over all lines in input file for line in f: # Loop over all lines in input file. if line[0].isdigit(): # First ensure line starts with digit - get rid of comments that way #print line, line = line.replace(',','') # Get rid of all ',' characters by replacing them with '' (nothing) s = line.split() # s will be an array holding all individual items on line date = s[1] # no parameter to split method, so whitespace used as element separator time = s[0] lat = s[3] lon = s[4] depth = s[5] gravity = s[6] magnetometer = s[7] #print '------------' #print line, #---- We need to split lat/long on the degree symbol, which has ASCII code 0xb0 #---- (used Midnight Commander on Linux box to examine content of file as hex characters) print date, time, \ lat.split(chr(0xb0))[0], lat.split(chr(0xb0))[1], \ lon.split(chr(0xb0))[0], lon.split(chr(0xb0))[1], \ depth, gravity, magnetometer #---- Note that "\" is line continuation character f.close()