示例#1
0
    /// <summary>
    /// Imports a Origin OPJ file (tables only) into corresponding new tables in Altaxo.
    /// </summary>
    /// <param name="filename">The file name of the origin OPJ file.</param>
    /// <returns>Null if the import was successfull, or a error message.</returns>
    public static string Import(string filename)
    {
      OpjFile opj = new OpjFile(filename);
      opj.Parse();

      // now create corresponding tables in Altaxo

      for (int nspread = 0; nspread < opj.numSpreads(); nspread++)
      {
        // Create a new table
        string tablename = Current.Project.DataTableCollection.FindNewTableName(opj.spreadName(nspread));
        DataTable table = new DataTable(tablename);

        int numberOfColumns = opj.numCols(nspread);
        for (int ncol = 0; ncol < numberOfColumns; ncol++)
        {
          string colname = opj.colName(nspread, ncol);
          string coltype = opj.colType(nspread, ncol);
          int numberOfRows = opj.numRows(nspread, ncol);
          ColumnKind kind = coltype == "X" ? ColumnKind.X : ColumnKind.V;

          DoubleColumn column = new DoubleColumn(numberOfRows);
          column.CopyDataFrom(opj.Data(nspread, ncol), numberOfRows);


          colname = table.DataColumns.FindUniqueColumnName(colname);
          table.DataColumns.Add(column, colname, kind, 0);
        }


        table.Name = tablename;
        Current.Project.DataTableCollection.Add(table);
        Current.ProjectService.CreateNewWorksheet(table);
      }
      return null;
    }
    /// <summary>
    /// Imports a couple of SPC files into a table. The spectra are added as columns to the table. If the x column
    /// of the rightmost column does not match the x-data of the spectra, a new x-column is also created.
    /// </summary>
    /// <param name="filenames">An array of filenames to import.</param>
    /// <param name="table">The table the spectra should be imported to.</param>
    /// <returns>Null if no error occurs, or an error description.</returns>
    public static string ImportSpcFiles(string[] filenames, Altaxo.Data.DataTable table)
    {
      Altaxo.Data.DoubleColumn xcol=null;
      double[] xvalues, yvalues;
      System.Text.StringBuilder errorList = new System.Text.StringBuilder();
      int lastColumnGroup = 0;

      if(table.DataColumns.ColumnCount>0)
      {
        lastColumnGroup = table.DataColumns.GetColumnGroup(table.DataColumns.ColumnCount-1);
        Altaxo.Data.DataColumn xColumnOfRightMost = table.DataColumns.FindXColumnOfGroup(lastColumnGroup);
        if(xColumnOfRightMost is Altaxo.Data.DoubleColumn)
          xcol = (Altaxo.Data.DoubleColumn)xColumnOfRightMost;
      }

      foreach(string filename in filenames)
      {
        string error = ToArrays(filename,out xvalues, out yvalues);
        if(null!=error)
        {
          errorList.Append(error);
          continue;
        }

        bool bMatchsXColumn=false;

        // first look if our default xcolumn matches the xvalues
        if(null!=xcol)
          bMatchsXColumn=ValuesMatch(xvalues,xcol);
          
        // if no match, then consider all xcolumns from right to left, maybe some fits
        if(!bMatchsXColumn)
        {
          for(int ncol=table.DataColumns.ColumnCount-1;ncol>=0;ncol--)
          {
            if(  (ColumnKind.X == table.DataColumns.GetColumnKind(ncol)) &&
              (table.DataColumns[ncol] is DoubleColumn) &&
              (ValuesMatch(xvalues,(DoubleColumn)table.DataColumns[ncol]))
              )
            {
              xcol = (DoubleColumn)table.DataColumns[ncol];
              lastColumnGroup = table.DataColumns.GetColumnGroup(xcol);
              bMatchsXColumn=true;
              break;
            }
          }
        }

        // create a new x column if the last one does not match
        if(!bMatchsXColumn)
        {
          xcol = new Altaxo.Data.DoubleColumn();
          xcol.CopyDataFrom(xvalues);
          lastColumnGroup = table.DataColumns.GetUnusedColumnGroupNumber();
          table.DataColumns.Add(xcol,"SPC X values",Altaxo.Data.ColumnKind.X,lastColumnGroup);
        }

        // now add the y-values
        Altaxo.Data.DoubleColumn ycol = new Altaxo.Data.DoubleColumn();
        ycol.CopyDataFrom(yvalues);
        table.DataColumns.Add(ycol,
          table.DataColumns.FindUniqueColumnName(System.IO.Path.GetFileNameWithoutExtension(filename)),
          Altaxo.Data.ColumnKind.V,
          lastColumnGroup);

        // add also a property column named "FilePath" if not existing so far
        if(!table.PropCols.ContainsColumn("FilePath"))
          table.PropCols.Add(new Altaxo.Data.TextColumn(),"FilePath");

        // now set the file name property cell
        if(table.PropCols["FilePath"] is Altaxo.Data.TextColumn)
        {
          table.PropCols["FilePath"][table.DataColumns.GetColumnNumber(ycol)] = filename;
        }
      } // foreache file

      return errorList.Length==0 ? null : errorList.ToString();
    }
示例#3
0
        /// <summary>
        /// Imports a couple of SPC files into a table. The spectra are added as columns to the table. If the x column
        /// of the rightmost column does not match the x-data of the spectra, a new x-column is also created.
        /// </summary>
        /// <param name="filenames">An array of filenames to import.</param>
        /// <param name="table">The table the spectra should be imported to.</param>
        /// <returns>Null if no error occurs, or an error description.</returns>
        public static string ImportSpcFiles(string[] filenames, Altaxo.Data.DataTable table)
        {
            Altaxo.Data.DoubleColumn xcol = null;
            double[] xvalues, yvalues;
            System.Text.StringBuilder errorList = new System.Text.StringBuilder();
            int lastColumnGroup = 0;

            if (table.DataColumns.ColumnCount > 0)
            {
                lastColumnGroup = table.DataColumns.GetColumnGroup(table.DataColumns.ColumnCount - 1);
                Altaxo.Data.DataColumn xColumnOfRightMost = table.DataColumns.FindXColumnOfGroup(lastColumnGroup);
                if (xColumnOfRightMost is Altaxo.Data.DoubleColumn)
                {
                    xcol = (Altaxo.Data.DoubleColumn)xColumnOfRightMost;
                }
            }

            foreach (string filename in filenames)
            {
                string error = ToArrays(filename, out xvalues, out yvalues);
                if (null != error)
                {
                    errorList.Append(error);
                    continue;
                }

                bool bMatchsXColumn = false;

                // first look if our default xcolumn matches the xvalues
                if (null != xcol)
                {
                    bMatchsXColumn = ValuesMatch(xvalues, xcol);
                }

                // if no match, then consider all xcolumns from right to left, maybe some fits
                if (!bMatchsXColumn)
                {
                    for (int ncol = table.DataColumns.ColumnCount - 1; ncol >= 0; ncol--)
                    {
                        if ((ColumnKind.X == table.DataColumns.GetColumnKind(ncol)) &&
                            (table.DataColumns[ncol] is DoubleColumn) &&
                            (ValuesMatch(xvalues, (DoubleColumn)table.DataColumns[ncol]))
                            )
                        {
                            xcol            = (DoubleColumn)table.DataColumns[ncol];
                            lastColumnGroup = table.DataColumns.GetColumnGroup(xcol);
                            bMatchsXColumn  = true;
                            break;
                        }
                    }
                }

                // create a new x column if the last one does not match
                if (!bMatchsXColumn)
                {
                    xcol = new Altaxo.Data.DoubleColumn();
                    xcol.CopyDataFrom(xvalues);
                    lastColumnGroup = table.DataColumns.GetUnusedColumnGroupNumber();
                    table.DataColumns.Add(xcol, "SPC X values", Altaxo.Data.ColumnKind.X, lastColumnGroup);
                }

                // now add the y-values
                Altaxo.Data.DoubleColumn ycol = new Altaxo.Data.DoubleColumn();
                ycol.CopyDataFrom(yvalues);
                table.DataColumns.Add(ycol,
                                      table.DataColumns.FindUniqueColumnName(System.IO.Path.GetFileNameWithoutExtension(filename)),
                                      Altaxo.Data.ColumnKind.V,
                                      lastColumnGroup);

                // add also a property column named "FilePath" if not existing so far
                if (!table.PropCols.ContainsColumn("FilePath"))
                {
                    table.PropCols.Add(new Altaxo.Data.TextColumn(), "FilePath");
                }

                // now set the file name property cell
                if (table.PropCols["FilePath"] is Altaxo.Data.TextColumn)
                {
                    table.PropCols["FilePath"][table.DataColumns.GetColumnNumber(ycol)] = filename;
                }
            } // foreache file

            return(errorList.Length == 0 ? null : errorList.ToString());
        }
示例#4
0
		/// <summary>
		/// Imports a couple of JCAMP files into a table. The spectra are added as columns to the (one and only) table. If the x column
		/// of the rightmost column does not match the x-data of the spectra, a new x-column is also created.
		/// </summary>
		/// <param name="filenames">An array of filenames to import.</param>
		/// <param name="table">The table the spectra should be imported to.</param>
		/// <returns>Null if no error occurs, or an error description.</returns>
		public static string ImportJcampFiles(string[] filenames, Altaxo.Data.DataTable table)
		{
			DoubleColumn xcol = null;
			DoubleColumn xvalues, yvalues;
			System.Text.StringBuilder errorList = new System.Text.StringBuilder();
			int lastColumnGroup = 0;

			if (table.DataColumns.ColumnCount > 0)
			{
				lastColumnGroup = table.DataColumns.GetColumnGroup(table.DataColumns.ColumnCount - 1);
				Altaxo.Data.DataColumn xColumnOfRightMost = table.DataColumns.FindXColumnOfGroup(lastColumnGroup);
				if (xColumnOfRightMost is Altaxo.Data.DoubleColumn)
					xcol = (Altaxo.Data.DoubleColumn)xColumnOfRightMost;
			}

			foreach (string filename in filenames)
			{
				DataTable localTable;
				System.IO.FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
				string error = ToDataTable(stream, out localTable);
				stream.Close();

				if (null != error)
				{
					errorList.Append(error);
					continue;
				}
				if (localTable.DataColumns.RowCount == 0)
					continue;
				xvalues = (DoubleColumn)localTable[0];
				yvalues = (DoubleColumn)localTable[1];

				// Add the necessary property columns
				for (int i = 0; i < localTable.PropCols.ColumnCount; i++)
				{
					string name = localTable.PropCols.GetColumnName(i);
					if (!table.PropCols.ContainsColumn(name))
					{
						table.PropCols.Add((DataColumn)localTable.PropCols[i].Clone(), name, localTable.PropCols.GetColumnKind(i));
					}
				}

				bool bMatchsXColumn = false;

				// first look if our default xcolumn matches the xvalues
				if (null != xcol)
					bMatchsXColumn = ValuesMatch(xvalues, xcol);

				// if no match, then consider all xcolumns from right to left, maybe some fits
				if (!bMatchsXColumn)
				{
					for (int ncol = table.DataColumns.ColumnCount - 1; ncol >= 0; ncol--)
					{
						if ((ColumnKind.X == table.DataColumns.GetColumnKind(ncol)) &&
							(table.DataColumns[ncol] is DoubleColumn) &&
							(ValuesMatch(xvalues, (DoubleColumn)table.DataColumns[ncol]))
							)
						{
							xcol = (DoubleColumn)table.DataColumns[ncol];
							lastColumnGroup = table.DataColumns.GetColumnGroup(xcol);
							bMatchsXColumn = true;
							break;
						}
					}
				}

				// create a new x column if the last one does not match
				if (!bMatchsXColumn)
				{
					xcol = new Altaxo.Data.DoubleColumn();
					xcol.CopyDataFrom(xvalues);
					lastColumnGroup = table.DataColumns.GetUnusedColumnGroupNumber();
					table.DataColumns.Add(xcol, "X", Altaxo.Data.ColumnKind.X, lastColumnGroup);
				}

				// now add the y-values
				Altaxo.Data.DoubleColumn ycol = new Altaxo.Data.DoubleColumn();
				ycol.CopyDataFrom(yvalues);
				table.DataColumns.Add(ycol,
					table.DataColumns.FindUniqueColumnName(System.IO.Path.GetFileNameWithoutExtension(filename)),
					Altaxo.Data.ColumnKind.V,
					lastColumnGroup);

				// add also a property column named "FilePath" if not existing so far
				if (!table.PropCols.ContainsColumn("FilePath"))
					table.PropCols.Add(new Altaxo.Data.TextColumn(), "FilePath");

				// now set the file name property cell
				int yColumnNumber = table.DataColumns.GetColumnNumber(ycol);
				if (table.PropCols["FilePath"] is Altaxo.Data.TextColumn)
				{
					table.PropCols["FilePath"][yColumnNumber] = filename;
				}

				// set the other property columns
				for (int i = 0; i < localTable.PropCols.ColumnCount; i++)
				{
					string name = localTable.PropCols.GetColumnName(i);
					table.PropCols[name][yColumnNumber] = localTable.PropCols[i][1];
				}
			} // foreache file

			return errorList.Length == 0 ? null : errorList.ToString();
		}
示例#5
0
        /// <summary>
        /// Imports a couple of JCAMP files into a table. The spectra are added as columns to the (one and only) table. If the x column
        /// of the rightmost column does not match the x-data of the spectra, a new x-column is also created.
        /// </summary>
        /// <param name="filenames">An array of filenames to import.</param>
        /// <param name="table">The table the spectra should be imported to.</param>
        /// <returns>Null if no error occurs, or an error description.</returns>
        public static string ImportJcampFiles(string[] filenames, Altaxo.Data.DataTable table)
        {
            DoubleColumn xcol = null;
            DoubleColumn xvalues, yvalues;
            var          errorList       = new System.Text.StringBuilder();
            int          lastColumnGroup = 0;

            if (table.DataColumns.ColumnCount > 0)
            {
                lastColumnGroup = table.DataColumns.GetColumnGroup(table.DataColumns.ColumnCount - 1);
                Altaxo.Data.DataColumn xColumnOfRightMost = table.DataColumns.FindXColumnOfGroup(lastColumnGroup);
                if (xColumnOfRightMost is Altaxo.Data.DoubleColumn)
                {
                    xcol = (Altaxo.Data.DoubleColumn)xColumnOfRightMost;
                }
            }

            foreach (string filename in filenames)
            {
                var    stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                string error  = ToDataTable(stream, out var localTable);
                stream.Close();

                if (null != error)
                {
                    errorList.Append(error);
                    continue;
                }
                if (localTable.DataColumns.RowCount == 0)
                {
                    continue;
                }
                xvalues = (DoubleColumn)localTable[0];
                yvalues = (DoubleColumn)localTable[1];

                // Add the necessary property columns
                for (int i = 0; i < localTable.PropCols.ColumnCount; i++)
                {
                    string name = localTable.PropCols.GetColumnName(i);
                    if (!table.PropCols.ContainsColumn(name))
                    {
                        table.PropCols.Add((DataColumn)localTable.PropCols[i].Clone(), name, localTable.PropCols.GetColumnKind(i));
                    }
                }

                bool bMatchsXColumn = false;

                // first look if our default xcolumn matches the xvalues
                if (null != xcol)
                {
                    bMatchsXColumn = ValuesMatch(xvalues, xcol);
                }

                // if no match, then consider all xcolumns from right to left, maybe some fits
                if (!bMatchsXColumn)
                {
                    for (int ncol = table.DataColumns.ColumnCount - 1; ncol >= 0; ncol--)
                    {
                        if ((ColumnKind.X == table.DataColumns.GetColumnKind(ncol)) &&
                            (table.DataColumns[ncol] is DoubleColumn) &&
                            (ValuesMatch(xvalues, (DoubleColumn)table.DataColumns[ncol]))
                            )
                        {
                            xcol            = (DoubleColumn)table.DataColumns[ncol];
                            lastColumnGroup = table.DataColumns.GetColumnGroup(xcol);
                            bMatchsXColumn  = true;
                            break;
                        }
                    }
                }

                // create a new x column if the last one does not match
                if (!bMatchsXColumn)
                {
                    xcol = new Altaxo.Data.DoubleColumn();
                    xcol.CopyDataFrom(xvalues);
                    lastColumnGroup = table.DataColumns.GetUnusedColumnGroupNumber();
                    table.DataColumns.Add(xcol, "X", Altaxo.Data.ColumnKind.X, lastColumnGroup);
                }

                // now add the y-values
                var ycol = new Altaxo.Data.DoubleColumn();
                ycol.CopyDataFrom(yvalues);
                table.DataColumns.Add(ycol,
                                      table.DataColumns.FindUniqueColumnName(System.IO.Path.GetFileNameWithoutExtension(filename)),
                                      Altaxo.Data.ColumnKind.V,
                                      lastColumnGroup);

                // add also a property column named "FilePath" if not existing so far
                if (!table.PropCols.ContainsColumn("FilePath"))
                {
                    table.PropCols.Add(new Altaxo.Data.TextColumn(), "FilePath");
                }

                // now set the file name property cell
                int yColumnNumber = table.DataColumns.GetColumnNumber(ycol);
                if (table.PropCols["FilePath"] is Altaxo.Data.TextColumn)
                {
                    table.PropCols["FilePath"][yColumnNumber] = filename;
                }

                // set the other property columns
                for (int i = 0; i < localTable.PropCols.ColumnCount; i++)
                {
                    string name = localTable.PropCols.GetColumnName(i);
                    table.PropCols[name][yColumnNumber] = localTable.PropCols[i][1];
                }
            } // foreache file

            return(errorList.Length == 0 ? null : errorList.ToString());
        }