[chronojump] Encoder call cleaner



commit 38760a9fa34d8f02ef0fc90d139bdda1c7fe7555
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Jan 28 18:47:17 2013 +0100

    Encoder call cleaner

 src/gui/encoder.cs |   16 +++---
 src/util.cs        |  142 +++++++++++++++++++++++++++++----------------------
 2 files changed, 89 insertions(+), 69 deletions(-)
---
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 34b0daf..a0beba3 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -230,10 +230,10 @@ public partial class ChronoJumpWindow
 				Util.GetEncoderDataTempFileName(), "", ep);				
 
 		//title to sen to python software has to be without spaces
-		Util.RunEncoder(Constants.EncoderScriptCapture, 
+		Util.RunEncoderCapture(Constants.EncoderScriptCapture, 
 				Util.ChangeSpaceForUnderscore(currentPerson.Name) + "----" + 
 				Util.ChangeSpaceForUnderscore(exerciseNameShown) + "----(" + findMass(true) + "Kg)",
-				es, true);
+				es);
 
 		encoderTimeStamp = UtilDate.ToFile(DateTime.Now);
 		encoderSignalUniqueID = "-1"; //mark to know that there's no ID for this until it's saved on database
@@ -319,11 +319,11 @@ public partial class ChronoJumpWindow
 				Util.GetEncoderStatusTempFileName(),
 				ep);
 		
-		Util.RunEncoder(Constants.EncoderScriptGraph, 
+		Util.RunEncoderGraph(Constants.EncoderScriptGraph, 
 				Util.ChangeSpaceForUnderscore(currentPerson.Name) + "-" + 
 				Util.ChangeSpaceForUnderscore(UtilGtk.ComboGetActive(combo_encoder_exercise)) + 
 				"-(" + findMass(true) + "Kg)",
-				es,false);
+				es);
 
 		//store this to show 1,2,3,4,... or 1e,1c,2e,2c,... in RenderN
 		//if is not stored, it can change when changed eccon radiobutton on cursor is in treeview
@@ -509,11 +509,11 @@ public partial class ChronoJumpWindow
 				Util.GetEncoderGraphTempFileName(),
 				Util.GetEncoderExportTempFileName(), "NULL", ep);
 
-		Util.RunEncoder(Constants.EncoderScriptGraph, 
+		Util.RunEncoderGraph(Constants.EncoderScriptGraph, 
 				Util.ChangeSpaceForUnderscore(currentPerson.Name) + "-" + 
 				Util.ChangeSpaceForUnderscore(UtilGtk.ComboGetActive(combo_encoder_exercise)) + 
 					"-(" + findMass(true) + "Kg)",
-				encoderStruct, false);
+				encoderStruct);
 
 		encoder_pulsebar_capture.Text = string.Format(Catalog.GetString(
 					"Exported to {0}."), Util.GetEncoderExportTempFileName());
@@ -868,9 +868,9 @@ public partial class ChronoJumpWindow
 		//if(radiobutton_encoder_analyze_data_user_curves.Active)
 		//	massString = "";
 
-		Util.RunEncoder(Constants.EncoderScriptGraph, 
+		Util.RunEncoderGraph(Constants.EncoderScriptGraph, 
 				Util.ChangeSpaceForUnderscore(currentPerson.Name) + "-" + 
-				Util.ChangeSpaceForUnderscore(UtilGtk.ComboGetActive(combo_encoder_exercise)), encoderStruct, false);
+				Util.ChangeSpaceForUnderscore(UtilGtk.ComboGetActive(combo_encoder_exercise)), encoderStruct);
 	}
 	
 	private void on_radiobutton_encoder_analyze_data_current_signal_toggled (object obj, EventArgs args) {
diff --git a/src/util.cs b/src/util.cs
index 3640ca9..6c615ad 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1046,17 +1046,12 @@ public class Util
 		}
 	}
 
-	
-	//python program
-	//script can be:
-	//python script to capture
-	//or 
-	//R script to make graph
-	public static void RunEncoder(string script, string title, EncoderStruct es, bool capture) {
+	public static void RunEncoderCapture(string script, string title, EncoderStruct es) {
 		CancelRScript = false;
 
 		ProcessStartInfo pinfo;
 	        Process p;
+		//Old comment:
 		//If output file is not given, R will try to write in the running folder
 		//in which we may haven't got permissions
 		
@@ -1064,72 +1059,96 @@ public class Util
 		pinfo = new ProcessStartInfo();
 
 		string outputFileCheck = "";
-		if(capture) {
-			pBin="python";
-
-			//currently we are not using useTerminal. It was originally to encoder capture with text and graph
-			/*
-			bool useTerminal = false;
-			if(useTerminal)
-				pBin="xterm";
-			*/
+			
+		pBin="python";
 
-			if (IsWindows())
-				pBin=System.IO.Path.Combine(GetPrefixDir(), "bin/python.exe");
+		//currently we are not using useTerminal. It was originally to encoder capture with text and graph
+		/*
+		   bool useTerminal = false;
+		   if(useTerminal)
+		   pBin="xterm";
+		   */
 
-			/*
-			if(useTerminal) {
-				//currentl we are not using this
-				pinfo.Arguments = "-bg white -fg black -hold -geometry 72x34+100+40 -fn *-fixed-*-*-*-20-* -e \"python " + 
-				script + " " + es.OutputData1 + " " + es.Ep.ToString1() + "\"";
-			} else 
-			*/
-			pinfo.Arguments = script + " " + title + " " + es.OutputData1 + " " + es.Ep.ToString1();
+		if (IsWindows())
+			pBin=System.IO.Path.Combine(GetPrefixDir(), "bin/python.exe");
 
-			outputFileCheck = es.OutputData1;
-		} else {
-			pBin="Rscript";
-			if (IsWindows())
-				pBin=System.IO.Path.Combine(GetPrefixDir(), "bin/R.exe");
+		/*
+		   if(useTerminal) {
+		//currentl we are not using this
+		pinfo.Arguments = "-bg white -fg black -hold -geometry 72x34+100+40 -fn *-fixed-*-*-*-20-* -e \"python " + 
+		script + " " + es.OutputData1 + " " + es.Ep.ToString1() + "\"";
+		} else 
+		*/
+		pinfo.Arguments = script + " " + title + " " + es.OutputData1 + " " + es.Ep.ToString1();
 
-			/*
-			//--- way A. passing options to a file
-			string scriptOptions = es.InputData + "\n" + 
-				es.OutputGraph + "\n" + es.OutputData1 + "\n" + es.OutputData2 + "\n" + 
-				es.Ep.ToString2("\n") + "\n" + title + "\n";
-
-			TextWriter writer = File.CreateText("/tmp/Roptions.txt");
-			writer.Write(scriptOptions);
-			writer.Flush();
-			((IDisposable)writer).Dispose();
-
-			pinfo.Arguments = script + " " + "/tmp/Roptions.txt";
-			//pinfo.Arguments ="CMD BATCH --no-save '--args=/tmp/Roptions.txt' " + script + " " + "/tmp/error.txt";
-			*/
-			//--- way B. put options as arguments
-			string argumentOptions = es.InputData + " " + 
-				es.OutputGraph + " " + es.OutputData1 + " " + es.OutputData2 + " " + 
-				es.Ep.ToString2(" ") + " " + title;
-			pinfo.Arguments = script + " " + argumentOptions;
-
-			//curves does first graph and then csv curves. 
-			//Wait until this to update encoder gui (if don't wait then treeview will be outdated)
-			if(es.Ep.Analysis == "curves" || es.Ep.Analysis == "exportCSV")
-				outputFileCheck = es.OutputData1; 
-			else
-				outputFileCheck = es.OutputGraph;
-		}
+		outputFileCheck = es.OutputData1;
 
 		pinfo.FileName=pBin;
 
 		pinfo.CreateNoWindow = true;
 		pinfo.UseShellExecute = false;
 
+		Console.WriteLine(outputFileCheck);
+		if (File.Exists(outputFileCheck))
+			File.Delete(outputFileCheck);
+	
+		p = new Process();
+		p.StartInfo = pinfo;
+		p.Start();
+		Log.WriteLine(p.Id.ToString());
+
+		p.WaitForExit();
+		while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
+	}
+	
+	public static void RunEncoderGraph(string script, string title, EncoderStruct es) {
+		CancelRScript = false;
+
+		ProcessStartInfo pinfo;
+	        Process p;
+		//If output file is not given, R will try to write in the running folder
+		//in which we may haven't got permissions
+		
+		string pBin="";
+		pinfo = new ProcessStartInfo();
+
+		string outputFileCheck = "";
+			
+		pBin="Rscript";
+		if (IsWindows())
+			pBin=System.IO.Path.Combine(GetPrefixDir(), "bin/R.exe");
+
 		/*
-		Console.WriteLine("-------------------");
-		Console.WriteLine(pBin);
-		Console.WriteLine(pinfo.Arguments);
+		//--- way A. passing options to a file
+		string scriptOptions = es.InputData + "\n" + 
+		es.OutputGraph + "\n" + es.OutputData1 + "\n" + es.OutputData2 + "\n" + 
+		es.Ep.ToString2("\n") + "\n" + title + "\n";
+
+		TextWriter writer = File.CreateText("/tmp/Roptions.txt");
+		writer.Write(scriptOptions);
+		writer.Flush();
+		((IDisposable)writer).Dispose();
+
+		pinfo.Arguments = script + " " + "/tmp/Roptions.txt";
+		//pinfo.Arguments ="CMD BATCH --no-save '--args=/tmp/Roptions.txt' " + script + " " + "/tmp/error.txt";
 		*/
+		//--- way B. put options as arguments
+		string argumentOptions = es.InputData + " " + 
+			es.OutputGraph + " " + es.OutputData1 + " " + es.OutputData2 + " " + 
+			es.Ep.ToString2(" ") + " " + title;
+		pinfo.Arguments = script + " " + argumentOptions;
+
+		//curves does first graph and then csv curves. 
+		//Wait until this to update encoder gui (if don't wait then treeview will be outdated)
+		if(es.Ep.Analysis == "curves" || es.Ep.Analysis == "exportCSV")
+			outputFileCheck = es.OutputData1; 
+		else
+			outputFileCheck = es.OutputGraph;
+
+		pinfo.FileName=pBin;
+
+		pinfo.CreateNoWindow = true;
+		pinfo.UseShellExecute = false;
 
 		Console.WriteLine(outputFileCheck);
 		if (File.Exists(outputFileCheck))
@@ -1141,6 +1160,7 @@ public class Util
 		p.WaitForExit();
 		while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
 	}
+
 	private static string [] encoderFindPos(string contents, int start, int duration) {
 		int startPos = 0;
 		int durationPos = 0;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]