jhylands

Counter

Sep 29th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1. #imports for program to work
  2.  
  3. #increases functionality with directories
  4. import glob
  5. #manipulate different runtime environments
  6. import sys
  7. #provides expression patterns (something to do with strings)
  8. import re
  9. #working with files and other operating system functions
  10. import os
  11. #binary data to python strings/numbers
  12. import struct
  13. #access to mathematical functions
  14. import math
  15. #html functionality
  16. import cgi
  17. #exception handling (catches and reports back)
  18. import cgitb
  19. #file writing
  20. import itertools
  21.  
  22. files = ["raw.txt"]
  23.  
  24. #=================================================================
  25.  
  26. if __name__ == "__main__":
  27.     # Program starts here
  28.    
  29.     #test program starts
  30.     print "This works."
  31.    
  32.     #create output file
  33.     outputFile = open('HitOut.txt', "w")
  34.     #save name
  35.     pathname = "raw.txt"
  36.     print pathname
  37.     #read file and save to 'text'
  38.     f = open(pathname, 'r')
  39.     text = f.read()
  40.     f.close()
  41.     #list hits
  42.     hits = []
  43.     #saves rows
  44.     rows = text.splitlines()
  45.  
  46.     #properties for hits
  47.     x_list = []
  48.     y_list = []
  49.     used = []
  50.    
  51.     #i is row ID
  52.     i = 0
  53.     #couner for ID
  54.     count = 0
  55.     #loops through all rows
  56.     for row in rows:
  57.         #print i, row
  58.         vals = row.split(' ')
  59.         #j is column ID
  60.         j = 0
  61.         #loops through all values
  62.         for val in vals:
  63.             #if holds val other than 0
  64.             if val != '0':
  65.                 #saves location and val
  66.                 hit = '#' + repr(count) + '#' + repr(i) + ':' + repr(j) + ':' + repr(val)
  67.                 x_list.append(i)
  68.                 y_list.append(j)
  69.                 used.append('no')
  70.                 hits.append(hit)
  71.                 count += 1
  72.         #print i,j, val
  73.         #increase coords
  74.             j += 1
  75.         i += 1
  76.  
  77.     #count for writing all hits
  78.     n = 0
  79.     m = len(hits)
  80.     m += 1
  81.  
  82.     #loops through all hits and writes
  83.     while (n < m-1):
  84.         outputFile.write(hits[n])
  85.         n += 1
  86.  
  87.     #close file
  88.     outputFile.close()
  89.    
  90.     #=================================================================================
  91.     ##Clusters
  92.    
  93.     #create output file for clusters
  94.     outputFile = open('Cluster_ID.txt', "w")
  95.  
  96.     #var for loop
  97.     count2 = 0
  98.     count3 = 0
  99.     x = 0
  100.     y = 0
  101.  
  102.     #clusters
  103.     cluster = []
  104.     identify = []
  105.     new = 0
  106.  
  107.     #loops for each hit to identify clusters
  108.     while count2 < count + 1
  109.         #check not already in cluster
  110.         if used[count2] = 'no'
  111.         cluster.append(new)
  112.         identify.append(count2)
  113.             #compares all hits against
  114.             while count3 < count + 1
  115.                 #skips current selection
  116.                 if count3 != count2
  117.                
  118.                    
  119.             count3 += 1
  120.         count2 += 1
  121.         count3 = 0
Advertisement
Add Comment
Please, Sign In to add comment