public LoadDataForm(DataForm data, DataItem item)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			this.item = item;
			this.data = data;
		}
Beispiel #2
0
		/// <summary>
		/// Creates a copy of the DataItem.
		/// </summary>
		public override PlotItem Clone() {
			DataItem item = new DataItem();
			item.CopyFrom(this);
			return item;
		}
Beispiel #3
0
		/// <summary>
		/// Creates either a deep or a shallow copy, depending on the value of the <c>deepCopy</c> field.
		/// </summary>
		/// <param name="parent">The parent <see cref="DataItem">DataItem</see> of the copy.</param>
		public virtual DataColumn Clone(DataItem parent) {
			DataColumn r = new DataColumn(parent);
			r.CopyFrom(this);
			return r;
		}
Beispiel #4
0
		/// <summary>
		/// A constructor setting the parent <see cref="DataItem">DataItem</see>.
		/// </summary>
		public DataColumn(DataItem parent) { this.parent = parent; }
Beispiel #5
0
		public void ResetPar() {
			bool fitpok = true;
			lock(this) {
				GraphModel model = graph.Model;
				string name;
				int i;
				name = (string)function.Text;
				f = null;
				for (i = 0; i < model.Items.Count; i++) {
					if ((model.Items[i].name == name) && (model.Items[i] is Function1D) &&
						(((Function1D)model.Items[i]).Fitable())) {
						f = (Function1D)model.Items[i];
					}
				}
				name = (string)data.Text;
				dataItem = null;
				for (i = 0; i < model.Items.Count; i++) {
					if ((model.Items[i].name == name) && (model.Items[i] is DataItem)) {
						dataItem = (DataItem)model.Items[i];
					}
				}
				if (f != null) {
					if (f != oldf || f.Modified) {
						if (f != oldf) {
							fitp = new bool[f.p.Length];
							for (i = 0; i < f.p.Length; i++) {
								fitp[i] = true;
							}
						}
						grid.ColumnsCount = 4;
						grid.RowsCount = f.p.Length + 1;
						grid[0, 0] = new SourceGrid2.Cells.Real.ColumnHeader("n");
						grid[0, 1] = new SourceGrid2.Cells.Real.ColumnHeader("fit");
						grid[0, 2] = new SourceGrid2.Cells.Real.ColumnHeader("p[n]");
						grid[0, 3] = new SourceGrid2.Cells.Real.ColumnHeader("±Δp[n]");
						for (i = 0; i < f.p.Length; i++) {
							grid[i+1, 0] = new SourceGrid2.Cells.Real.RowHeader(i.ToString());
							grid[i+1, 1] = new SourceGrid2.Cells.Real.CheckBox(fitp[i]);
							grid[i+1, 2] = new SourceGrid2.Cells.Real.Cell(f.p[i], typeof(double));
							if (covar == null) {
								grid[i+1, 3] = new SourceGrid2.Cells.Real.Cell("", typeof(string));
							} else {
								grid[i+1, 3] = new SourceGrid2.Cells.Real.Cell(Math.Sqrt(covar[i, i]), typeof(double));
							}
							grid[i+1, 3].DataModel.EnableEdit = false;
						}
						covar = null;
					}

					plength = f.p.Length;
				}
				if (f == null) {
					grid.RowsCount = 4;
					grid.ColumnsCount = 1;
					grid[0, 0] = new SourceGrid2.Cells.Real.ColumnHeader("n");
					grid[0, 1] = new SourceGrid2.Cells.Real.ColumnHeader("fit");
					grid[0, 2] = new SourceGrid2.Cells.Real.ColumnHeader("p[n]");
					grid[0, 3] = new SourceGrid2.Cells.Real.ColumnHeader("±Δp[n]");

				}
				grid.AutoSize();
				oldf = f;
				Q.Text = "";
				chisq.Text = "";
				covariance.Enabled = covar != null;
				fitpok = false;
				for (i = 0; i < fitp.Length; i++) {
					if (fitp[i]) fitpok = true;
				}
				start.Enabled = (f != null && data != null && fitpok);
				neval.Text = "";
			}
		}
Beispiel #6
0
		private void asciiClick(object sender, System.EventArgs e) {
			DataItem data = new DataItem();
			//The loadsource represents the body of the following function:
			//void Load(System.IO.FileStream stream) {
			//  ...
			//}
			//The function loads the data from the stream and sets the arrays x, y, dx and dy accordingly.
			//The size of the arrays is automatically adjusted upon access.
			data.loadsource = 
				"using (StreamReader r = new StreamReader(stream)) {" +
				"  int n = 0; string line; string[] tokens;" +
				"  char[] separator = \";,|\".ToCharArray();" +
				"  while ((line = r.ReadLine()) != null) {" +
				"    tokens = line.Split(separator);" +
				"    try {x[n] = double.Parse(tokens[0]);} catch {x[n] = 0;}" +
				"    try {y[n] = double.Parse(tokens[1]);} catch {y[n] = 0;}" +
				"    try {dx[n] = double.Parse(tokens[2]);} catch {dx[n] = 0;}" +
				"    try {dy[n] = double.Parse(tokens[3]);} catch {dy[n] = 0;}" +
				"    n++;" +
		    "  }" +
		    "}";
			data.Compile(true);
			if (!data.compiled) MessageBox.Show("Error in sourcecode:\n" + data.errors[0]);
			try {
				data.LoadFromFile("data.csv");
			} catch (Exception ex) {
				MessageBox.Show("Could not open the file data.csv\n" + ex.Message);
			}
			graph.Model.Items.Add(data);
			Console.WriteLine("data Length: {0}", data.Length);
			Console.WriteLine("x     y     dx     dy");
			for (int n = 0; n < data.Length; n++) {
				Console.WriteLine("{0}, {1}, {2}, {3}", data.x[n], data.y[n], data.dx[n], data.dy[n]);
			}
			graph.Invalidate();
		}
Beispiel #7
0
		public Fit(DataItem data, Function1D f, bool[] fitp) {
			Data = data;
			f0 = f;
			this.fitp = (bool[])fitp.Clone();
		}
Beispiel #8
0
		public Fit(DataItem data, Function1D f) {
			Data = data;
			Function = f;
		}
Beispiel #9
0
 /// <summary>
 /// A constructor setting the parent <see cref="DataItem">DataItem</see>.
 /// </summary>
 public DataColumn(DataItem parent)
 {
     this.parent = parent;
 }
Beispiel #10
0
		public static void LoadFile(GraphControl graph, string filename) {
			Header h;
		
			using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
				using (BinaryReader r = new BinaryReader(stream)) {
					//Read WAV header
					h.ChunkID = r.ReadUInt32();
					h.ChunkSize = r.ReadUInt32();
					h.Format = r.ReadUInt32();
					h.Subchunk1ID = r.ReadUInt32();
					h.Subchunk1Size = r.ReadUInt32();
					h.AudioFormat = r.ReadUInt16();
					h.Channels = r.ReadUInt16();
					h.SampleRate = r.ReadUInt32();
					h.ByteRate = r.ReadUInt32();
					h.BlockAlign = r.ReadUInt16();
					h.BitsPerSample = r.ReadUInt16();
					h.Subchunk2ID = r.ReadUInt32();
					h.Subchunk2Size = r.ReadUInt32();
					int channels = h.Channels;
					int bytes = h.BitsPerSample / 8;
					int samples = (int)(h.Subchunk2Size / channels / bytes);
					int m, n;
					byte[] d;
					DataItem[] items = new DataItem[channels];
					for (m = 0; m < channels; m++) {
						items[m] = new DataItem();
						items[m].lines = true; // join points with a line.
						items[m].marks = false; // draw no error marks.
						items[m].Length = samples; // Set the length of the arrays.
						// set formula for x-array
						items[m].x.source = "n/((float)Length)*" + (samples / (float)h.SampleRate).ToString(); 
						items[m].dx.source = "0"; // set formula for dx-array
						items[m].dy.source = "0"; // set formula for dy-array
						items[m].name = "channel " + m.ToString(); // set the name of the DataItem.
						items[m].Compile(true);
						switch (m % 3) {
						case 0: items[m].Color = Color.Blue; break;
						case 1: items[m].Color = Color.Red; break;
						case 2: items[m].Color = Color.Green; break;
						}
						graph.Model.Items.Add(items[m]);
					}
					for (n = 0; n < samples; n++) {
						for (m = 0; m < channels; m++) {
							// Set y.AutoResize to true, so the size of the y-array will be adapted automatically.
							items[m].y.AutoResize = true;
							d = r.ReadBytes(bytes);
							switch (bytes) {
							case 1:	items[m].y[n] = (double)((int)d[0])/0x100; break;
							case 2: items[m].y[n] = (double)BitConverter.ToInt16(d, 0)/0x10000; break;
							case 3: items[m].y[n] = (double)(d[0]*0x10000 + d[1]*0x100 + d[3])/0x1000000; break;
							case 4: items[m].y[n] = (double)BitConverter.ToInt32(d, 0)/0x100000000; break;
							}
							items[m].y.AutoResize = false;
						}
					}

				}
			}
		}