public override void CopyDataFrom(Altaxo.Data.DataColumn v) { if (v.GetType() != typeof(Altaxo.Data.DateTimeColumn)) { throw new ArgumentException("Try to copy " + v.GetType() + " to " + this.GetType(), "v"); // throw exception } Altaxo.Data.DateTimeColumn vd = (Altaxo.Data.DateTimeColumn)v; // suggestion, but __not__ implemented: // if v is a standalone column, then simply take the dataarray // otherwise: copy the data by value int oldCount = this.m_Count; if (null == vd.m_Array || vd.m_Count == 0) { m_Array = null; m_Capacity = 0; m_Count = 0; } else { m_Array = (DateTime[])vd.m_Array.Clone(); m_Capacity = m_Array.Length; m_Count = ((Altaxo.Data.DateTimeColumn)v).m_Count; } if (oldCount > 0 || m_Count > 0) // message only if really was a change { NotifyDataChanged(0, oldCount > m_Count? (oldCount):(m_Count), m_Count < oldCount); } }
public void GetObjectData(object obj, System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { Altaxo.Data.DateTimeColumn s = (Altaxo.Data.DateTimeColumn)obj; System.Runtime.Serialization.ISurrogateSelector ss = AltaxoStreamingContext.GetSurrogateSelector(context); if (null != ss) { System.Runtime.Serialization.ISerializationSurrogate surr = ss.GetSurrogate(typeof(Altaxo.Data.DataColumn), context, out ss); surr.GetObjectData(obj, info, context); // stream the data of the base object } { ((DataColumn)s).GetObjectData(info, context); } if (s.m_Count != s.m_Capacity) { // instead of the data array itself, stream only the first m_Count // array elements, since only they contain data DateTime[] streamarray = new DateTime[s.m_Count]; System.Array.Copy(s.m_Array, streamarray, s.m_Count); info.AddValue("Data", streamarray); } else // if the array is fully filled, we don't need to save a shrinked copy { info.AddValue("Data", s.m_Array); } }
public static Altaxo.Data.DateTimeColumn operator -(Altaxo.Data.DateTimeColumn c1, double c2) { var c3 = new Altaxo.Data.DateTimeColumn(c1._count); int len = c1._count; for (int i = 0; i < len; i++) { c3._data[i] = c1._data[i].AddSeconds(-c2); } c3._count = len; return(c3); }
public static Altaxo.Data.DateTimeColumn operator -(Altaxo.Data.DateTimeColumn c1, Altaxo.Data.DoubleColumn c2) { int len = c1.Count < c2.Count ? c1.Count : c2.Count; var c3 = new Altaxo.Data.DateTimeColumn(len); for (int i = 0; i < len; i++) { c3._data[i] = c1._data[i].AddSeconds(-c2.GetValueDirect(i)); } c3._count = len; return(c3); }
public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent) { Altaxo.Data.DateTimeColumn s = null != o ? (Altaxo.Data.DateTimeColumn)o : new Altaxo.Data.DateTimeColumn(); // deserialize the base class info.GetBaseValueEmbedded(s, typeof(Altaxo.Data.DataColumn), parent); int count = info.GetInt32Attribute("Count"); s._data = new DateTime[count]; info.GetArray(s._data, count); s._capacity = null == s._data ? 0 : s._data.Length; s._count = s._capacity; return(s); }
public void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info) { Altaxo.Data.DateTimeColumn s = (Altaxo.Data.DateTimeColumn)obj; // serialize the base class info.AddBaseValueEmbedded(s, typeof(Altaxo.Data.DataColumn)); if (null == info.GetProperty("Altaxo.Data.DataColumn.SaveAsTemplate")) { info.AddArray("Data", s.m_Array, s.m_Count); } else { info.AddArray("Data", s.m_Array, 0); } }
public static Altaxo.Data.DateTimeColumn operator +(Altaxo.Data.DateTimeColumn c1, double c2) { int len = c1.m_Count; Altaxo.Data.DateTimeColumn c3 = new Altaxo.Data.DateTimeColumn(len); for (int i = 0; i < len; i++) { c3.m_Array[i] = c1.m_Array[i].AddSeconds(c2); } c3.m_Count = len; return(c3); }
public object SetObjectData(object obj, System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.ISurrogateSelector selector) { Altaxo.Data.DateTimeColumn s = (Altaxo.Data.DateTimeColumn)obj; System.Runtime.Serialization.ISurrogateSelector ss = AltaxoStreamingContext.GetSurrogateSelector(context); if (null != ss) { System.Runtime.Serialization.ISerializationSurrogate surr = ss.GetSurrogate(typeof(Altaxo.Data.DataColumn), context, out ss); surr.SetObjectData(obj, info, context, selector); } else { ((DataColumn)s).SetObjectData(obj, info, context, selector); } s.m_Array = (DateTime[])(info.GetValue("Data", typeof(DateTime[]))); s.m_Capacity = null == s.m_Array ? 0 : s.m_Array.Length; s.m_Count = s.m_Capacity; return(s); }
/// <summary> /// This function searches for patterns like aaa=bbb in the provided string. If it finds such a item, it creates a column named aaa /// and stores the value bbb at the same position in it as in the text column. /// </summary> /// <param name="strg">The string where to search for the patterns described above.</param> /// <param name="store">The column collection where to store the newly created columns of properties.</param> /// <param name="index">The index into the column where to store the property value.</param> public static void ExtractPropertiesFromString(string strg, Altaxo.Data.DataColumnCollection store, int index) { string pat; pat = @"(\S+)=(\S+)"; Regex r = new Regex(pat, RegexOptions.Compiled | RegexOptions.IgnoreCase); for (Match m = r.Match(strg); m.Success; m = m.NextMatch()) { string propname = m.Groups[1].ToString(); string propvalue = m.Groups[2].ToString(); // System.Diagnostics.Trace.WriteLine("Found the pair " + propname + " : " + propvalue); if (!store.ContainsColumn(propname)) { Altaxo.Data.DataColumn col; if (Altaxo.Serialization.DateTimeParsing.IsDateTime(propvalue)) { col = new Altaxo.Data.DateTimeColumn(); } else if (Altaxo.Serialization.NumberConversion.IsNumeric(propvalue)) { col = new Altaxo.Data.DoubleColumn(); } else { col = new Altaxo.Data.TextColumn(); } store.Add(col, propname); // add the column to the collection } // now the column is present we can store the value in it. store[propname][index] = new Altaxo.Data.AltaxoVariant(propvalue); } }
/// <summary> /// This function searches for patterns like aaa=bbb in the provided string. If it finds such a item, it creates a column named aaa /// and stores the value bbb at the same position in it as in the text column. /// </summary> /// <param name="strg">The string where to search for the patterns described above.</param> /// <param name="store">The column collection where to store the newly created columns of properties.</param> /// <param name="index">The index into the column where to store the property value.</param> public static void ExtractPropertiesFromString(string strg, Altaxo.Data.DataColumnCollection store, int index) { string pat; pat = @"(\S+)=(\S+)"; Regex r = new Regex(pat, RegexOptions.Compiled | RegexOptions.IgnoreCase); for ( Match m = r.Match(strg); m.Success; m = m.NextMatch()) { string propname = m.Groups[1].ToString(); string propvalue = m.Groups[2].ToString(); // System.Diagnostics.Trace.WriteLine("Found the pair " + propname + " : " + propvalue); if(!store.ContainsColumn(propname)) { Altaxo.Data.DataColumn col; if(Altaxo.Serialization.DateTimeParsing.IsDateTime(propvalue)) col = new Altaxo.Data.DateTimeColumn(); else if(Altaxo.Serialization.NumberConversion.IsNumeric(propvalue)) col = new Altaxo.Data.DoubleColumn(); else col = new Altaxo.Data.TextColumn(); store.Add(col,propname); // add the column to the collection } // now the column is present we can store the value in it. store[propname][index] = new Altaxo.Data.AltaxoVariant(propvalue); } }
public static Altaxo.Data.DateTimeColumn operator -(Altaxo.Data.DateTimeColumn c1, double c2) { Altaxo.Data.DateTimeColumn c3 = new Altaxo.Data.DateTimeColumn(c1._count); int len = c1._count; for (int i = 0; i < len; i++) { c3._data[i] = c1._data[i].AddSeconds(-c2); } c3._count = len; return c3; }
public static Altaxo.Data.DateTimeColumn operator -(Altaxo.Data.DateTimeColumn c1, Altaxo.Data.DoubleColumn c2) { int len = c1.Count < c2.Count ? c1.Count : c2.Count; Altaxo.Data.DateTimeColumn c3 = new Altaxo.Data.DateTimeColumn(len); for (int i = 0; i < len; i++) { c3._data[i] = c1._data[i].AddSeconds(-c2.GetValueDirect(i)); } c3._count = len; return c3; }
public void ImportAscii(AsciiImportOptions impopt, Altaxo.Data.DataTable table) { string sLine; stream.Position = 0; // rewind the stream to the beginning System.IO.StreamReader sr = new System.IO.StreamReader(stream, System.Text.Encoding.Default, true); Altaxo.Data.DataColumnCollection newcols = new Altaxo.Data.DataColumnCollection(); Altaxo.Data.DataColumnCollection newpropcols = new Altaxo.Data.DataColumnCollection(); // in case a structure is provided, allocate already the columsn if (null != impopt.recognizedStructure) { for (int i = 0; i < impopt.recognizedStructure.Count; i++) { if (impopt.recognizedStructure[i] == typeof(Double)) { newcols.Add(new Altaxo.Data.DoubleColumn()); } else if (impopt.recognizedStructure[i] == typeof(DateTime)) { newcols.Add(new Altaxo.Data.DateTimeColumn()); } else if (impopt.recognizedStructure[i] == typeof(string)) { newcols.Add(new Altaxo.Data.TextColumn()); } else { newcols.Add(new Altaxo.Data.DBNullColumn()); }; } } // add also additional property columns if not enough there if (impopt.nMainHeaderLines > 1) // if there are more than one header line, allocate also property columns { int toAdd = impopt.nMainHeaderLines - 1; for (int i = 0; i < toAdd; i++) { newpropcols.Add(new Data.TextColumn()); } } // if decimal separator statistics is provided by impopt, create a number format info object System.Globalization.NumberFormatInfo numberFormatInfo = null; if (impopt.m_DecimalSeparatorCommaCount > 0 || impopt.m_DecimalSeparatorDotCount > 0) { numberFormatInfo = (System.Globalization.NumberFormatInfo)System.Globalization.NumberFormatInfo.CurrentInfo.Clone(); // analyse the statistics if (impopt.m_DecimalSeparatorCommaCount > impopt.m_DecimalSeparatorDotCount) // the comma is the decimal separator { numberFormatInfo.NumberDecimalSeparator = ","; if (numberFormatInfo.NumberGroupSeparator == numberFormatInfo.NumberDecimalSeparator) { numberFormatInfo.NumberGroupSeparator = ""; // in case now the group separator is also comma, remove the group separator } } else if (impopt.m_DecimalSeparatorCommaCount < impopt.m_DecimalSeparatorDotCount) // the comma is the decimal separator { numberFormatInfo.NumberDecimalSeparator = "."; if (numberFormatInfo.NumberGroupSeparator == numberFormatInfo.NumberDecimalSeparator) { numberFormatInfo.NumberGroupSeparator = ""; // in case now the group separator is also comma, remove the group separator } } } else // no decimal separator statistics is provided, so retrieve the numberFormatInfo object from the program options or from the current thread { numberFormatInfo = System.Globalization.NumberFormatInfo.CurrentInfo; } char [] splitchar = new char[] { impopt.cDelimiter }; // first of all, read the header if existent for (int i = 0; i < impopt.nMainHeaderLines; i++) { sLine = sr.ReadLine(); if (null == sLine) { break; } string[] substr = sLine.Split(splitchar); int cnt = substr.Length; for (int k = 0; k < cnt; k++) { if (substr[k].Length == 0) { continue; } if (k >= newcols.ColumnCount) { continue; } if (i == 0) // is it the column name line { newcols.SetColumnName(k, substr[k]); } else // this are threated as additional properties { ((Data.DataColumn)newpropcols[i - 1])[k] = substr[k]; // set the properties } } } for (int i = 0; true; i++) { sLine = sr.ReadLine(); if (null == sLine) { break; } string[] substr = sLine.Split(splitchar); int cnt = Math.Min(substr.Length, newcols.ColumnCount); for (int k = 0; k < cnt; k++) { if (substr[k].Length == 0) { continue; } if (newcols[k] is Altaxo.Data.DoubleColumn) { try { ((Altaxo.Data.DoubleColumn)newcols[k])[i] = System.Convert.ToDouble(substr[k], numberFormatInfo); } catch {} } else if (newcols[k] is Altaxo.Data.DateTimeColumn) { try { ((Altaxo.Data.DateTimeColumn)newcols[k])[i] = System.Convert.ToDateTime(substr[k]); } catch {} } else if (newcols[k] is Altaxo.Data.TextColumn) { ((Altaxo.Data.TextColumn)newcols[k])[i] = substr[k]; } else if (null == newcols[k] || newcols[k] is Altaxo.Data.DBNullColumn) { bool bConverted = false; double val = Double.NaN; DateTime valDateTime = DateTime.MinValue; try { val = System.Convert.ToDouble(substr[k]); bConverted = true; } catch { } if (bConverted) { Altaxo.Data.DoubleColumn newc = new Altaxo.Data.DoubleColumn(); newc[i] = val; newcols.Replace(k, newc); } else { try { valDateTime = System.Convert.ToDateTime(substr[k]); bConverted = true; } catch { } if (bConverted) { Altaxo.Data.DateTimeColumn newc = new Altaxo.Data.DateTimeColumn(); newc[i] = valDateTime; newcols.Replace(k, newc); } else { Altaxo.Data.TextColumn newc = new Altaxo.Data.TextColumn(); newc[i] = substr[k]; newcols.Replace(k, newc); } } // end outer if null==newcol } } // end of for all cols } // end of for all lines // insert the new columns or replace the old ones table.Suspend(); bool tableWasEmptyBefore = table.DataColumns.ColumnCount == 0; for (int i = 0; i < newcols.ColumnCount; i++) { if (newcols[i] is Altaxo.Data.DBNullColumn) // if the type is undefined, use a new DoubleColumn { table.DataColumns.CopyOrReplaceOrAdd(i, new Altaxo.Data.DoubleColumn(), newcols.GetColumnName(i)); } else { table.DataColumns.CopyOrReplaceOrAdd(i, newcols[i], newcols.GetColumnName(i)); } // set the first column as x-column if the table was empty before, and there are more than one column if (i == 0 && tableWasEmptyBefore && newcols.ColumnCount > 1) { table.DataColumns.SetColumnKind(0, Altaxo.Data.ColumnKind.X); } } // end for loop // add the property columns for (int i = 0; i < newpropcols.ColumnCount; i++) { table.PropCols.CopyOrReplaceOrAdd(i, newpropcols[i], newpropcols.GetColumnName(i)); } table.Resume(); } // end of function ImportAscii
public void ImportAscii(AsciiImportOptions impopt, Altaxo.Data.DataTable table) { string sLine; stream.Position=0; // rewind the stream to the beginning System.IO.StreamReader sr = new System.IO.StreamReader(stream,System.Text.Encoding.Default,true); Altaxo.Data.DataColumnCollection newcols = new Altaxo.Data.DataColumnCollection(); Altaxo.Data.DataColumnCollection newpropcols = new Altaxo.Data.DataColumnCollection(); // in case a structure is provided, allocate already the columsn if(null!=impopt.recognizedStructure) { for(int i=0;i<impopt.recognizedStructure.Count;i++) { if(impopt.recognizedStructure[i]==typeof(Double)) newcols.Add(new Altaxo.Data.DoubleColumn()); else if(impopt.recognizedStructure[i]==typeof(DateTime)) newcols.Add(new Altaxo.Data.DateTimeColumn()); else if(impopt.recognizedStructure[i]==typeof(string)) newcols.Add(new Altaxo.Data.TextColumn()); else newcols.Add(new Altaxo.Data.DBNullColumn());; } } // add also additional property columns if not enough there if(impopt.nMainHeaderLines>1) // if there are more than one header line, allocate also property columns { int toAdd = impopt.nMainHeaderLines-1; for(int i=0;i<toAdd;i++) newpropcols.Add(new Data.TextColumn()); } // if decimal separator statistics is provided by impopt, create a number format info object System.Globalization.NumberFormatInfo numberFormatInfo=null; if(impopt.m_DecimalSeparatorCommaCount>0 || impopt.m_DecimalSeparatorDotCount>0) { numberFormatInfo = (System.Globalization.NumberFormatInfo)System.Globalization.NumberFormatInfo.CurrentInfo.Clone(); // analyse the statistics if(impopt.m_DecimalSeparatorCommaCount>impopt.m_DecimalSeparatorDotCount) // the comma is the decimal separator { numberFormatInfo.NumberDecimalSeparator=","; if(numberFormatInfo.NumberGroupSeparator==numberFormatInfo.NumberDecimalSeparator) numberFormatInfo.NumberGroupSeparator=""; // in case now the group separator is also comma, remove the group separator } else if(impopt.m_DecimalSeparatorCommaCount<impopt.m_DecimalSeparatorDotCount) // the comma is the decimal separator { numberFormatInfo.NumberDecimalSeparator="."; if(numberFormatInfo.NumberGroupSeparator==numberFormatInfo.NumberDecimalSeparator) numberFormatInfo.NumberGroupSeparator=""; // in case now the group separator is also comma, remove the group separator } } else // no decimal separator statistics is provided, so retrieve the numberFormatInfo object from the program options or from the current thread { numberFormatInfo = System.Globalization.NumberFormatInfo.CurrentInfo; } char [] splitchar = new char[]{impopt.cDelimiter}; // first of all, read the header if existent for(int i=0;i<impopt.nMainHeaderLines;i++) { sLine = sr.ReadLine(); if(null==sLine) break; string[] substr = sLine.Split(splitchar); int cnt = substr.Length; for(int k=0;k<cnt;k++) { if(substr[k].Length==0) continue; if(k>=newcols.ColumnCount) continue; if(i==0) // is it the column name line { newcols.SetColumnName(k, substr[k]); } else // this are threated as additional properties { ((Data.DataColumn)newpropcols[i-1])[k] = substr[k]; // set the properties } } } for(int i=0;true;i++) { sLine = sr.ReadLine(); if(null==sLine) break; string[] substr = sLine.Split(splitchar); int cnt = Math.Min(substr.Length,newcols.ColumnCount); for(int k=0;k<cnt;k++) { if(substr[k].Length==0) continue; if(newcols[k] is Altaxo.Data.DoubleColumn) { try { ((Altaxo.Data.DoubleColumn)newcols[k])[i] = System.Convert.ToDouble(substr[k],numberFormatInfo); } catch {} } else if( newcols[k] is Altaxo.Data.DateTimeColumn) { try { ((Altaxo.Data.DateTimeColumn)newcols[k])[i] = System.Convert.ToDateTime(substr[k]); } catch {} } else if( newcols[k] is Altaxo.Data.TextColumn) { ((Altaxo.Data.TextColumn)newcols[k])[i] = substr[k]; } else if(null==newcols[k] || newcols[k] is Altaxo.Data.DBNullColumn) { bool bConverted = false; double val=Double.NaN; DateTime valDateTime=DateTime.MinValue; try { val = System.Convert.ToDouble(substr[k]); bConverted=true; } catch { } if(bConverted) { Altaxo.Data.DoubleColumn newc = new Altaxo.Data.DoubleColumn(); newc[i]=val; newcols.Replace(k,newc); } else { try { valDateTime = System.Convert.ToDateTime(substr[k]); bConverted=true; } catch { } if(bConverted) { Altaxo.Data.DateTimeColumn newc = new Altaxo.Data.DateTimeColumn(); newc[i]=valDateTime; newcols.Replace(k, newc); } else { Altaxo.Data.TextColumn newc = new Altaxo.Data.TextColumn(); newc[i]=substr[k]; newcols.Replace(k,newc); } } // end outer if null==newcol } } // end of for all cols } // end of for all lines // insert the new columns or replace the old ones table.Suspend(); bool tableWasEmptyBefore = table.DataColumns.ColumnCount==0; for(int i=0;i<newcols.ColumnCount;i++) { if(newcols[i] is Altaxo.Data.DBNullColumn) // if the type is undefined, use a new DoubleColumn table.DataColumns.CopyOrReplaceOrAdd(i,new Altaxo.Data.DoubleColumn(), newcols.GetColumnName(i)); else table.DataColumns.CopyOrReplaceOrAdd(i,newcols[i], newcols.GetColumnName(i)); // set the first column as x-column if the table was empty before, and there are more than one column if(i==0 && tableWasEmptyBefore && newcols.ColumnCount>1) table.DataColumns.SetColumnKind(0,Altaxo.Data.ColumnKind.X); } // end for loop // add the property columns for(int i=0;i<newpropcols.ColumnCount;i++) { table.PropCols.CopyOrReplaceOrAdd(i,newpropcols[i], newpropcols.GetColumnName(i)); } table.Resume(); } // end of function ImportAscii