Click or drag to resize

Importing ASCII data

Previous section: Copy/paste of worksheet data

This topic contains the following sections:


Importing ASCII data from a single file into a single worksheet

To import ASCII data from a single file into a (single) worksheet, first make the worksheet to import to the active document, or create a new (preferably empty) worksheet.

Then choose File→Import→Ascii from the main menu, or use the toolbar button (see Figure below).

175BA38271F9EFD451538A761150E354

A file dialog opens. After selecting the Ascii file and pressing OK the Ascii data are imported into your active worksheet. The import process is a two-step process:

  1. The Ascii file is analyzed first. The first 30 lines of the Ascii files are read, and the lines are analyzed for their structure. The structure that is most frequently repeated in the other lines wins the game and determines the number of columns and their type. The recognized columns are created in the worksheet.

  2. The data are then imported in the thus prepared worksheet.

If the result of the import is not satisfactory, you can control the import options by choosing File→Import→Ascii with options from the main menu instead. Here too, at first a dialog opens in which you can choose the file to import. The Ascii file is then analyzed, and the result of the analysis is shown in another dialog.

The dialog is divided into three parts: in the upper part, the analysis options are shown. In the middle part, the result of the analysis is shown. The lower part contains some user options.

When you press the button “Analyze!”, the options in the upper part of the dialog are used to analyze the Ascii file. Already known information is used from the middle part. In the figure above, there is nothing left to analyze, because on all results the checkbox is checked, meaning that this result is already known.

Suppose that Altaxo’s automatic analysis has incorrectly recognized the number of main header lines, and as a consequence, has also incorrectly determined the number and the type of columns. You can then correct the number of main header lines manually (if known to you). Leave the checkbox “Known number of main header lines” checked in order to indicate that the number of main header lines is already known. But uncheck the checkbox “Known column types”. If you now press the button “Analyze”, Altaxo runs the analysis again, but takes into account the correct number of main header lines. Hopefully, this will now lead to the correct recognition of the number and types of columns.

Likewise, you can correct any analysis result that you know better of, and uncheck those results that you want to be analyzed again.

Finally, press OK to import the Ascii file into your worksheet.

Importing ASCII data from multiple files into a single worksheet

Suppose you have a spectrometer that stores every spectrum in a single Ascii file. The data in each file is structured into two columns. The first column usually contains the values of the wavelength, and the second column the measured values (for instance absorbance). Furthermore, suppose that you acquire a series of spectra, e.g. the time dependence of some reaction, so that you have hundreds or even thousands of spectra.

You probably not want to import each spectrum into a single worksheet, because then you will get hundreds or thousands of worksheets. Instead, it would be convenient if all spectra would be imported into a single worksheet. And, because all spectra share the same wavelength values, you will need only one wavelength column in your worksheet (instead of one wavelength column per spectrum).

To import all spectra into a single worksheet, create a new (preferably empty) worksheet or open an existing one, and then choose File→Impor→Ascii (all into a single worksheet). A file dialog opens, in which you have to select all files you want to import. After pressing OK, the selected files will be sorted by their file name and in this order imported into the current worksheet.

Note: Should it happen, that the x-column of one or more imported data files is different from the first imported file: this is not a problem. The new x-values will be imported into a different column, which gets a new group number, and all other imported columns of that file will get the same new group number.

Note: A property column named “FilePath” is created in the current worksheet. The cells of this property column are filled with the file name of the file where the data originate from.

In the figure below you can see the result after importing three spectrum files.

As you can see, the first column contains the wavelength values. Because there is only this one x-column, we conclude that the three spectra share the same wavelength values. The next 3 columns contain the spectral amplitudes of each spectrum. The property column “FilePath” contains the file names of the spectrum files. As you can see, the spectrometer codes the date and time into the filename. With the help of a script, one can extract this date/time and use it to calculate the time span relative to the start of measurement.

Importing ASCII data from multiple files into separate worksheets

If you want to import Ascii data from multiple files into separate worksheets, the most preferable way is to start when your current document is either a graph, or there is no current document at all.

Background: if your current document is a worksheet, the first Ascii file is imported into this worksheet, and the other files are imported into newly created worksheets. The newly created worksheets get the name of the corresponding Ascii file, but the first worksheet is not renamed.

Thus, either select a graph, or close all documents (main menu: Window→Close all documents) before importing into separate worksheets.

Choose File→Import→Ascii (or File→Import→Ascii with Options), and select multiple Ascii files in the file dialog.

If you press OK, the selected files will be sorted by their file name, and then imported into newly created worksheets. The new worksheets are located in the root folder of the project.

The figure below shows the result after importing the three spectrum files from the example of the previous chapter into separate worksheets.

Please note that the new worksheets get the names of their corresponding Ascii files (see Project explorer at the right side). Furthermore, the “Notes” tool window of each worksheet (at the bottom) contains a note with information about the original file name and the date/time of the import. In contrast to the example in chapter “Importing ASCII data from multiple files into a single worksheet”, each worksheet now contains a separate x-column with the wavelength values.

Importing multiple ASCII files into a single worksheet vertically

This command is useful if you have a time series of data in one file, which is continued in another file and so on. You can then import all data into a single worksheet. The data from the second file is appended to the data from the first file. This means that the data from the second file is imported starting from the next free data row of the worksheet.

Create a new (preferably empty) worksheet or choose an existing one. Then use File→Import→Import ASCII vertically from the menu. Select multiple Ascii files in the file dialog. After pressing OK, the files are sorted by their file name and imported into the current worksheet.

I have to admit that this function makes no sense for my example (see previous chapters) with the three spectra, but the next figure shows the outcome after I imported the three spectra with this command.

E21C36582AE1B83887AD842DCE2B70A5

As you can see, data row [1310] is the end of the first spectrum. The first row of the next spectrum is imported into data row [1311]. Note that the file name of the imported file is stored in column ‘FilePath’ at the beginning of each data chunk.