#! /usr/bin/env python #======================================================================================================= # Check fldr and tracf in trace header parameters extracted from raw SU file # These error reported: # - Duplicate or missing fldr # - Duplicate or missing tracf # # USAGE: check_fldr-tracf FileName # # Input: # File with plain text, two colums # 1st column = fldr # 2nd column = tracf # Example, assuming no of channels = 240 # 53 1 # 53 2 # .. # 53 240 # 54 1 # # Output: # Report/error file. Name as input file, added extension '.report' # # University of Bergen, Dept. of Earth Science # Revision history: # # Rev Date By Description # ----------------------------------------------------------- # 0.1 30 Jan 2006 OM Initial version # 0.2 3 Feb 2006 OM Do not bail out on Missing fldr(s). This is a legal error conditions; # it means the recording system missed a recording no (e.g. line31/svalex2005) #==================================================================================================== from sys import * from string import * from getopt import * StreamerChannels = 240 File = argv[1] ReportFile = File + '.report' inp_file = open(File) rpt_file = open(ReportFile, 'w') print '*' * 100 print 'Checking fldr and tracf extracted from SU file trace headers.' print 'Looking for duplicate and missing fldr and tracf.' print 'Program will halt if errors are detected. You must sort out problems before you continue.' print '*' * 100 rpt_file.write('# Checking fldr and tracf extracted from SU file trace headers.\n') rpt_file.write('# Input file name: '+ File+'\n') rpt_file.write('# Checking for duplicate and missing fldr and tracf\n') lines = inp_file.readlines() LN = 0 last_fldr = 0 def ShutDown(): rpt_file.write('fldr='+fldr+': Last fldr found\n') print 'fldr='+fldr+': Last fldr found' print 'No of traces:', str(LN) inp_file.close() rpt_file.close() exit(0) Loop = True while Loop: try: s = lines[LN].split() fldr = s[0] if last_fldr == 0: rpt_file.write('fldr='+fldr+': First fldr found\n') print 'fldr='+fldr+': First fldr found' last_fldr = int(fldr)-1 if (int(fldr) == last_fldr): rpt_file.write('fldr='+fldr+': Duplicate fldr ---- Error\n') print 'Duplicate fldr - exit' Loop = False if (int(fldr) < last_fldr): rpt_file.write('fldr='+fldr+': Duplicate fldrs ---- Error\n') print 'Duplicate fldrs - exit' Loop = False if ((int(fldr)- last_fldr) == 2): rpt_file.write('fldr='+fldr+': Missing fldr\n') print 'fldr='+fldr+': Missing fldr' if ((int(fldr)- last_fldr) > 2): rpt_file.write('fldr='+fldr+': Missing fldrs\n') print 'fldr='+fldr+': Missing fldrs' for k in range(1,StreamerChannels+1): # Now read 240 lines; fldr should be constant t = lines[LN].split() LN += 1 if t[0] <> fldr: print 'Line ' + str(LN) + ', fldr=' + fldr + ': Error - missing/duplicate fldr - check' rpt_file.write('Line ' + str(LN) + ', fldr=' + fldr + ': Error - missing/duplicate fldr - check\n') Loop = False if int(t[1]) <> k: print 'Line ' + str(LN) + ', fldr=' + fldr + ': Error - missing/duplicate channel - check' rpt_file.write('Line ' + str(LN) + ', fldr=' + fldr + ': Error - missing/duplicate channel - check\n') Loop = False last_fldr = int(fldr) except: #print '---- Exception ...' Loop = False ShutDown() exit(0)