xdenisx

SCAN INVARIANTS VALUES FROM res FILES

Mar 6th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.85 KB | None | 0 0
  1. # -*- coding: utf-8
  2.  
  3. ########################################################################
  4. #############SCAN INVARIANTS VALUES FROM res FILES#######################
  5. ########################################################################
  6.  
  7. #2012-03-06 - Ugol ellipsa added
  8.  
  9. import os, glob
  10. import re
  11.  
  12. season = 'winter'
  13. year1 = '2007'
  14. year2 = '2007'
  15.  
  16. path = './rean_res/res/*-*'
  17.  
  18. dirs = glob.glob(path)
  19. dirs.sort()
  20.  
  21. propusk = 999.0
  22.  
  23. # I1 for IFREMER
  24. i1_sat_file_path = './calc/calc_rean/i1/i1_ifr_' + season + '_' + year1 + '_' + year2
  25. i1_sat_file = open(i1_sat_file_path, 'w')
  26. # L1 L2 XI UST for IFREMER
  27. L1_sat_file_path = './calc/calc_rean/l1/l1_ifr_' + season + '_' + year1 + '_' + year2
  28. L1_sat_file = open(L1_sat_file_path, 'w')
  29. L2_sat_file_path = './calc/calc_rean/l2/l2_ifr_' + season + '_' + year1 + '_' + year2
  30. L2_sat_file = open(L2_sat_file_path, 'w')
  31. XI_sat_file_path = './calc/calc_rean/xi/xi_ifr_' + season + '_' + year1 + '_' + year2
  32. XI_sat_file = open(XI_sat_file_path, 'w')
  33. UST_sat_file_path = './calc/calc_rean/ust/ust_ifr_' + season + '_' + year1 + '_' + year2
  34. UST_sat_file = open(UST_sat_file_path, 'w')
  35. #Math. expectation, ALPHA, ugol_ellipsa IFREMER
  36. ME_sat_file_path = './calc/calc_rean/me/me_ifr_' + season + '_' + year1 + '_' + year2
  37. ME_sat_file = open(ME_sat_file_path, 'w')
  38. ALPHA_sat_file_path = './calc/calc_rean/alpha/alpha_ifr_' + season + '_' + year1 + '_' + year2
  39. ALPHA_sat_file = open(ALPHA_sat_file_path, 'w')
  40. ugol_ellipsa_sat_file_path = './calc/calc_rean/ugol_ellipsa/ugol_ellipsa_ifr_' + season + '_' + year1 + '_' + year2
  41. ugol_ellipsa_sat_file = open(ugol_ellipsa_sat_file_path, 'w')
  42.  
  43.  
  44. # I1 for TOPAZ
  45. i1_topaz_file_path = './calc/calc_rean/i1/i1_topaz_' + season + '_' + year1 + '_' + year2
  46. i1_topaz_file = open(i1_topaz_file_path, 'w')
  47. # L1 L2 XI UST for TOPAZ
  48. L1_topaz_file_path = './calc/calc_rean/l1/l1_topaz_' + season + '_' + year1 + '_' + year2
  49. L1_topaz_file = open(L1_topaz_file_path, 'w')
  50. L2_topaz_file_path = './calc/calc_rean/l2/l2_topaz_' + season + '_' + year1 + '_' + year2
  51. L2_topaz_file = open(L2_topaz_file_path, 'w')
  52. XI_topaz_file_path = './calc/calc_rean/xi/xi_topaz_' + season + '_' + year1 + '_' + year2
  53. XI_topaz_file = open(XI_topaz_file_path, 'w')
  54. UST_topaz_file_path = './calc/calc_rean/ust/ust_topaz_' + season + '_' + year1 + '_' + year2
  55. UST_topaz_file = open(UST_topaz_file_path, 'w')
  56.  
  57. #Math. expectation,ALPHA, ugol ellipsa TOPAZ
  58. ME_topaz_file_path = './calc/calc_rean/me/me_topaz_' + season + '_' + year1 + '_' + year2
  59. ME_topaz_file = open(ME_topaz_file_path, 'w')
  60. ALPHA_topaz_file_path = './calc/calc_rean/alpha/alpha_topaz_' + season + '_' + year1 + '_' + year2
  61. ALPHA_topaz_file = open(ALPHA_topaz_file_path, 'w')
  62. ugol_ellipsa_topaz_file_path = './calc/calc_rean/ugol_ellipsa/ugol_ellipsa_topaz_' + season + '_' + year1 + '_' + year2
  63. ugol_ellipsa_topaz_file = open(ugol_ellipsa_topaz_file_path, 'w')
  64.  
  65.  
  66. for filename in dirs:
  67.   print filename
  68.   iFile = open(filename, 'r')
  69.   lines = iFile.readlines()
  70.   #Longitude and Latitude from file name
  71.   temp = re.split(r"/", filename)
  72.   lat_lon = temp[-1]
  73.   temp = re.split(r"-", lat_lon)
  74.   lat = temp[1]
  75.   lon = temp[0]
  76.   print "lat-> ", lat
  77.   print "lon-> ", lon
  78.   if (len(lines))>67:
  79.    i1_line_ifr = lines[12]
  80.    ugol_ellipsa_line_ifr = lines[10]
  81.    #Ifremer
  82.    ff=re.split(r"=?L1", i1_line_ifr)
  83.    ff=re.split(r"=", ff[0])
  84.    i1 = float(ff[1])
  85.    print "I1 IFREMER -> ", i1
  86.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(i1))
  87.    #2File
  88.    i1_sat_file.write(str2File)
  89.    
  90.    #L1 sat
  91.    gg=re.split('=?L1=',i1_line_ifr)
  92.    gg = re.split(r'L2',gg[1])
  93.    L1 = float(gg[0])
  94.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(L1))
  95.    L1_sat_file.write(str2File)
  96.    
  97.    #L2 sat
  98.    gg=re.split('=?L2=',i1_line_ifr)
  99.    gg=re.split('\xd5',gg[1])
  100.    L2 = float(gg[0])
  101.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(L2))
  102.    L2_sat_file.write(str2File)
  103.    
  104.    #ugol ellipsa sat
  105.    gg=re.split(r'alfa=',ugol_ellipsa_line_ifr)
  106.    ugol_ellipsa_sat = gg[-1]
  107.    if int(ugol_ellipsa_sat)<0:
  108.     ugol_ellipsa_sat = int(ugol_ellipsa_sat) + 180
  109.    str2File = '%7.3f %7.3f %7d\n' % (float(lat), float(lon), int(ugol_ellipsa_sat))
  110.    ugol_ellipsa_sat_file.write(str2File)
  111.    
  112.    #XI sat
  113.    gg=re.split(r'\xd3',i1_line_ifr)
  114.    gg=re.split(r'\xc8=',gg[0])
  115.    XI = float(gg[-1])
  116.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(XI))
  117.    XI_sat_file.write(str2File)
  118.    
  119.    #UST sat
  120.    gg=re.split(r'\xd3',i1_line_ifr)
  121.    gg=re.split(r'\xdc=',gg[1])
  122.    UST = float(gg[1])
  123.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(UST))
  124.    UST_sat_file.write(str2File)
  125.    
  126.    #Mathematical expectation SAT
  127.    me_line_ifr = lines[7]
  128.    gg=re.split(r'\xd0:',me_line_ifr)
  129.    a=re.compile('[\w.]+')
  130.    ME_sat = float(a.findall(gg[1])[0])
  131.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(ME_sat))
  132.    ME_sat_file.write(str2File)
  133.    ALPHA_sat = float(a.findall(gg[1])[1])
  134.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(ALPHA_sat))
  135.    ALPHA_sat_file.write(str2File)
  136.    print '\n IFREMER Math. expectation -> ' + str(ME_sat) + '  alpha -> ', str(ALPHA_sat) + '\n'
  137.    
  138.    i1_line_topaz = lines[22]
  139.    ugol_ellipsa_line_topaz = lines[20]
  140.    #TOPAZ
  141.    ff=re.split(r"=?L1", i1_line_topaz)
  142.    ff=re.split(r"=", ff[0])
  143.    i1 = float(ff[1])
  144.    print "I1 TOPAZ -> ", i1
  145.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(i1))
  146.    #2File
  147.    i1_topaz_file.write(str2File)
  148.    
  149.    rr = re.split('\s',i1_line_topaz)
  150.    
  151.    #L1 TOPAZ
  152.    gg=re.split('=?L1=',i1_line_topaz)
  153.    gg = re.split(r'L2',gg[1])
  154.    L1 = float(gg[0])
  155.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(L1))
  156.    L1_topaz_file.write(str2File)
  157.    
  158.    #L2 TOPAZ
  159.    gg=re.split('=?L2=',i1_line_topaz)
  160.    gg=re.split('\xd5',gg[1])
  161.    L2 = float(gg[0])
  162.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(L2))
  163.    L2_topaz_file.write(str2File)
  164.    
  165.    #ugol ellipsa TOPAZ
  166.    gg=re.split(r'alfa=',ugol_ellipsa_line_topaz)
  167.    ugol_ellipsa_topaz = gg[-1]
  168.    if int(ugol_ellipsa_topaz)<0:
  169.     ugol_ellipsa_topaz = int(ugol_ellipsa_topaz) + 180
  170.    str2File = '%7.3f %7.3f %7d\n' % (float(lat), float(lon), int(ugol_ellipsa_topaz))
  171.    ugol_ellipsa_topaz_file.write(str2File)
  172.    
  173.    #XI TOPAZ
  174.    gg=re.split(r'\xd3',i1_line_topaz)
  175.    gg=re.split(r'\xc8=',gg[0])
  176.    XI = float(gg[-1])
  177.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(XI))
  178.    XI_topaz_file.write(str2File)
  179.    
  180.    #UST sat
  181.    gg=re.split(r'\xd3',i1_line_topaz)
  182.    gg=re.split(r'\xdc=',gg[1])
  183.    UST = float(gg[1])
  184.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(UST))
  185.    UST_topaz_file.write(str2File)
  186.    
  187.    #Mathematical expectation TOPAZ
  188.    me_line_topaz = lines[17]
  189.    gg=re.split(r'\xd0:',me_line_topaz)
  190.    a=re.compile('[\w.]+')
  191.    ME_topaz = float(a.findall(gg[1])[0])
  192.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(ME_topaz))
  193.    ME_topaz_file.write(str2File)
  194.    ALPHA_topaz = float(a.findall(gg[1])[1])
  195.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), float(ALPHA_topaz))
  196.    ALPHA_topaz_file.write(str2File)
  197.    print '\n TOPAZ Math. expectation -> ' + str(ME_topaz) + '  alpha -> ', str(ALPHA_topaz) + '\n'
  198.    
  199.   else:
  200.    str2File = '%7.3f %7.3f %7.1f\n' % (float(lat), float(lon), propusk)
  201.    #Пока ничего не пишем (999)
  202.    #i1_sat_file.write(str2File)
  203.    #i1_topaz_file.write(str2File)
  204.  
  205. i1_sat_file.close()
  206. i1_topaz_file.close()
  207. L1_topaz_file.close()
  208. L1_sat_file.close()
  209. L2_topaz_file.close()
  210. L2_sat_file.close()
  211. XI_topaz_file.close()
  212. XI_sat_file.close()
  213. UST_topaz_file.close()
  214. UST_sat_file.close()
  215. ME_topaz_file.close()
  216. ME_sat_file.close()
  217. ALPHA_topaz_file.close()
  218. ALPHA_sat_file.close()
  219. ugol_ellipsa_topaz_file.close()
  220. ugol_ellipsa_sat_file.close()
Advertisement
Add Comment
Please, Sign In to add comment