Package ais :: Module ais_names
[hide private]
[frames] | no frames]

Source Code for Module ais.ais_names

 1  #!/usr/bin/env python 
 2   
 3  __version__ = '$Revision: 4791 $'.split()[1] 
 4  __date__ = '$Date: 2007-01-02 $'.split()[1] 
 5  __author__ = 'xmlbinmsg' 
 6   
 7  __doc__=''' 
 8   
 9  Get the name and mmsi (User ID) for each msg 5 identification message. 
10   
11  This program requires that the nmea strings be sorted such that the 
12  2nd part of the message comes directly after the first.  You can do 
13  this by grepping for the USCG N-AIS station name.  This will prevent 
14  interleaving of msg 5 nmea strings. 
15   
16  @requires: U{epydoc<http://epydoc.sourceforge.net/>} > 3.0alpha3 
17   
18  @author: '''+__author__+''' 
19  @version: ''' + __version__ +''' 
20  @var __date__: Date of last svn commit 
21  @undocumented: __version__ __author__ __doc__ parser 
22  @status: under development 
23  @license: GPL 
24  ''' 
25   
26  import sys, os 
27   
28  import binary, ais_msg_5, aisstring 
29  #from BitVector import BitVector 
30   
31 -def getNameMMSI(logfile,outfile):
32 for line in logfile: #file('5.ais'): 33 fields = line.split(',')[:6] 34 if '1'!=fields[2]: # Must be the start of a sequence 35 continue 36 if len(fields[5])<39: continue 37 bv = binary.ais6tobitvec(fields[5][:39]) # Hacked for speed 38 39 mmsi = ais_msg_5.decodeUserID(bv) 40 name = aisstring.unpad(ais_msg_5.decodename(bv)) 41 outfile.write(str(mmsi)+' '+str(name)+'\n')
42 43 if __name__=='__main__': 44 from optparse import OptionParser 45 parser = OptionParser(usage="%prog [options] logfile1 [logfile2 logfile3 ...] ", version="%prog "+__version__) 46 parser.add_option('-o','--output',dest='outputFileName',default=None, 47 help='Name of the python file to write [default: stdout]') 48 49 (options,args) = parser.parse_args() 50 51 outfile = sys.stdout 52 if None!=options.outputFileName: 53 print 'outfilename=',options.outputFileName 54 outfile = file(options.outputFileName,'w') 55 if 0==len(args): 56 getNameMMSI(sys.stdin,outfile) 57 else: 58 for filename in args: 59 getNameMMSI(file(filename),outfile) 60