6.4.2 Extracting Variables from the File Name and Header


When importing files with the Import Wizard, you have the opportunity to identify file name or header information as variables. The extraction of the information can be customized in the Variable Extraction page. After the variables are extracted, they are saved in the target page for future use.

From the file name, four standard file name variables (path + filename.extension, path, filename.extension, filename) can be extracted. Additionally, all of the header lines ( the main header lines and subheader lines) can supply variables. You can specify the number of the header lines in the Number of main header lines box and the Number of subheader lines box in the Header Lines page of the Import Wizard.

File information storage

Extracted variables are stored in the information storage object of the destination page. There are two areas where the variables can be saved:

  • page.info. The page.info area only holds variables extracted from the last imported file.
  • binary storage. Binary storage saves variables extracted from all files imported into the window.

These variables can be inserted into text labels or worksheet cells using the Insert Variables shortcut menu command. Variables can be listed from the command line using the impinfo X-Function or the following script command:

Page.info.user.=

Note: Please see the Accessing Metadata Associated with Imported Files section later in this chapter for more information.

Using variables for annotation

There are numerous ways in which you might use stored variable information in text annotations on graphs or worksheets. One possible use of this information might be to add it to a graph legend. In this example, assume that we have imported a data file in which we have specified saving some portion of the file name or header information to a variable and we will proceed to insert the file name into the graph legend.

  1. Start a new project.
  2. Open the Import Wizard by clicking the Import Wizard button Button Import Wizard.png on the Standard toolbar.
  3. Click the Browse button to the right of the File list. Navigate to the Origin \Samples\Signal processing\ subfolder. Add Average Sunspot.dat and click OK.
  4. Click Next.
  5. On the Header Lines page, make sure that the first two lines are identified as header lines.
  6. Click Next.
  7. On the Variable Extraction page, select Specify location of variable names and values using delimiters. Note that when you do this, Add variables to page info is automatically selected.
  8. Click Next.
  9. On the Variable Extraction by Delimiter page, choose FN04 from the Line drop-down list. Enter fname in the Enter variable name text box. Click Add.
  10. Click Finish. The file is imported into the workbook.
  11. Highlight the second column of the workbook. Click the Line button Button Line.png on the 2D Graphs toolbar to create a plot.
  12. Double-click on the graph legend so that you can edit it. Delete "%(1)". Hold down the CTRL key, and press the H key on your keyboard. This opens the Insert Info Variables dialog box.
  13. In the Insert Info Variables dialog box, select fname under User.Variables. Click Insert. The graph legend should now read Average Sunspot.