From ddf14f013408ad034867f8d7a835fd363ab816d5 Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: Tue, 10 Jan 2017 15:59:10 +0100
Subject: [PATCH] Update ExtractData script

---
 opi/Scripts/ExtracData.py | 43 ++++++++++++++++-----------------------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/opi/Scripts/ExtracData.py b/opi/Scripts/ExtracData.py
index c3ea07a..3f59b9f 100644
--- a/opi/Scripts/ExtracData.py
+++ b/opi/Scripts/ExtracData.py
@@ -1,11 +1,6 @@
 from org.csstudio.opibuilder.scriptUtil import PVUtil
 from os.path import expanduser
-
-#! /usr/bin/env python
-#from org.csstudio.opibuilder.scriptUtil import PVUtil
 import struct
-#import matplotlib.pyplot as plt
-#import urllib2
 import json
 from random import betavariate
 import math
@@ -54,21 +49,21 @@ PlotFile.write("fichier  emittance: X\n")
 PlotFile.write("HT ion (kV) : %d\n"%(Energie))
 PlotFile.write("frequence (Hz) : %d\n"%(Frequence))
 PlotFile.write("N points temps : 1\n")
-PlotFile.write("pas de position (mm) : %d\n"%(PasMM))
+PlotFile.write("pas de position (mm) : %f\n"%(PasMM))
 PlotFile.write("N points  position (mm) : %i\n"%(NbPos))
 PlotFile.write("N points angle (mrad) : %i\n"%(NbAngle))
  
 ## POSITION
 PlotFile.write("vecteur positions (mm) : ")
 for value in range(0,NbPos):
-     PlotFile.write("%d "%tabPos[value]);
+     PlotFile.write("%.2f "%tabPos[value]);
      value=value+1
 
 ## ANGLES
 PlotFile.write("\nvecteur angles (mrad) : ")
 indAngle=0
 for value in range(0,NbAngle):
-    PlotFile.write("%f "%tabAng[indAngle]);
+    PlotFile.write("%.2f "%tabAng[indAngle]);
     indAngle=indAngle+NbPos
 
 PlotFile.write("\ntype d'ion : PROTON...")      
@@ -76,10 +71,10 @@ PlotFile.write("\ncolonnes de 1 a 4 : indice de temps / indice position / indice
 
 ## POSITION/ANGLE/INTENSITY
 indCurrent=NbPos-1
-indPos=NbPos-1
+indPos=NbPos
 for valuePos in range(0,NbPos):
     for valueAngle in range(0,NbAngle):
-            PlotFile.write("0\t%i\t%i\t%f\n" %(valuePos,valueAngle,tabCurr[indCurrent]));
+            PlotFile.write("0\t%i\t%i\t%.4f\n" %(valuePos,valueAngle,tabCurr[indCurrent]));
             indCurrent=indCurrent+NbPos
     indPos=indPos-1
     indCurrent=indPos
@@ -92,21 +87,19 @@ PlotFile.close()
 ###################################################################################
 
 #### OPEN FILE
-#PlotFile = open('/home/catane/data/'+NameFile+"-avg.txt", 'w+')
+PlotFile = open(home+'/data/emit/averageDataEmit/'+"avg-"+NameFile, 'w+')
 
 ## POSITION/ANGLE/INTENSITY
-#indTab=NbPos-1
-#indPos=NbPos-1
-
-##for valuePos in tabPos:
-#    for valueAngle in range(0,NbAngle):
-            #PlotFile.write("0\t%d\t%d\t%d\n" %(valuePos[indPos],valueAngle[indAngle],tabCurr[indCurrent]));
-#            PlotFile.write("%d\t%d\t%d\n" %(valuePos,tabAng[indTab],tabCurr[indTab]));
-
-            #indCurrent=indCurrent+NbPos
-##           indTab=indTab+NbPos         
-#    indPos=indPos-1
-    #indCurrent=indPos
-#    indTab=indPos
+indAngle=NbPos-1
+indCurrent=NbPos-1
+indPos=NbPos
+for valuePos in range(0,(NbPos)):	
+	for valueAngle in range(0,NbAngle):
+    		PlotFile.write("\n%.2f\t\t%.2f\t\t%.4f\n " %(tabPos[valuePos],tabAng[indAngle],tabCurr[indCurrent]));
+    		indAngle=indAngle+NbPos
+    		indCurrent=indCurrent+NbPos		
+	indPos=indPos-1
+	indAngle=indPos
+	indCurrent=indPos
 
-#PlotFile.close()
+PlotFile.close()
-- 
GitLab