code: def pockettopo2compass(txtfilename, exclude_splays=False, calculate_lrud=False):
      
      print 'Converting PocketTopo data file %s ...' % txtfilename
  
      # Read our PocketTopo .TXT file, averaging triple-shots in the process
      infile = pockettopo.TxtFile.read(txtfilename, merge_duplicate_shots=True)
  
      cave_name = os.path.basename(txtfilename).rsplit('.', 1)[0].replace('_', ' ')
      outfilename = txtfilename.rsplit('.', 1)[0] + '.DAT'
  
      # Create the Compass DatFile in memory and start building, we'll write to file when done
      outfile = compass.DatFile(cave_name)
  
      for insurvey in infile:
          # Our Compass and PocketTopo Surveys are very similar...
          outsurvey = compass.Survey(
              insurvey.name, insurvey.date, comment=insurvey.comment, cave_name=cave_name, declination=insurvey.declination
          )
          outsurvey.length_units = 'M'
          outsurvey.passage_units = 'M'
          
          for inshot in insurvey:
              if inshot.is_splay and exclude_splays:
                  continue  # skip
  
              # ...but the Shot data fields require some tweaking, see `shot2shot()` for details
              outshot = shot2shot(insurvey, inshot, calculate_lrud)
              outsurvey.add_shot(outshot)
  
          outfile.add_survey(outsurvey)
  
          # DEBUG
          #for station, splays in list(insurvey.splays.items()):
          #    print 'sta %s has %d splays' % (station, len(splays))
  
      # Finally all built, dump the whole DatFile/Surveys/Shots structure to file
      outfile.write(outfilename)
      print 'Wrote Compass data file %s .' % outfilename
docs: Main function which converts a PocketTopo .TXT file to a Compass .DAT file