SaveAscii v2

../_images/SaveAscii-v2_dlg.png

SaveAscii dialog.

Summary

Saves a 2D workspace to a ascii file.

Properties

Name Direction Type Default Description
InputWorkspace Input MatrixWorkspace Mandatory The name of the workspace containing the data you want to save to a Ascii file.
Filename Input string Mandatory The filename of the output Ascii file. Allowed extensions: [‘.dat’, ‘.txt’, ‘.csv’]
WorkspaceIndexMin Input number Optional The starting workspace index.
WorkspaceIndexMax Input number Optional The ending workspace index.
SpectrumList Input int list   List of workspace indices to save.
Precision Input number Optional Precision of output double values.
ScientificFormat Input boolean False If true, the values will be written to the file in scientific notation.
WriteXError Input boolean False If true, the error on X will be written as the fourth column.
WriteSpectrumID Input boolean True If false, the spectrum ID will not be written for single-spectrum workspaces. It is always written for workspaces with multiple spectra.
CommentIndicator Input string # Character(s) to put in front of comment lines.
Separator Input string CSV The separator between data columns in the data file. The possible values are “CSV”, “Tab”, “Space”, “SemiColon”, “Colon” or “UserDefined”. Allowed values: [‘CSV’, ‘Tab’, ‘Space’, ‘Colon’, ‘SemiColon’, ‘UserDefined’]
CustomSeparator Input string   If present, will override any specified choice given to Separator.
ColumnHeader Input boolean True If true, put column headers into file.
AppendToFile Input boolean False If true, don’t overwrite the file. Append to the end of it.
RaggedWorkspace Input boolean True If true, ensure that more than one xspectra is used.

Description

The workspace data are stored in the file in columns: the first column contains the X-values, followed by pairs of Y and E values. Columns are separated by commas. The resulting file can normally be loaded into a workspace by the LoadAscii v2 algorithm.

Limitations

The algorithm assumes that the workspace has common X values for all spectra (i.e. is not a ragged workspace).

Usage

Example - Save a workspace in CSV format

#import the os path libraries for directory functions
import os

# create histogram workspace
dataX1 = [0,1,2,3,4,5,6,7,8,9] # or use dataX1=range(0,10)
dataY1 = [0,1,2,3,4,5,6,7,8] # or use dataY1=range(0,9)
dataE1 = [1,1,1,1,1,1,1,1,1] # or use dataE1=[1]*9

ws1 = CreateWorkspace(dataX1, dataY1, dataE1)

#Create an absolute path by joining the proposed filename to a directory
#os.path.expanduser("~") used in this case returns the home directory of the current user
savefile = os.path.join(os.path.expanduser("~"), "AsciiFile.txt")

# perform the algorithm
SaveAscii(InputWorkspace=ws1,Filename=savefile)

print "File Exists:", os.path.exists(savefile)

Output:

File Exists: True

Example - Save a workspace as ASCII with a different delimiter

#import the os path libraries for directory functions
import os

# create histogram workspace
dataX1 = [0,1,2,3,4,5,6,7,8,9] # or use dataX1=range(0,10)
dataY1 = [0,1,2,3,4,5,6,7,8] # or use dataY1=range(0,9)
dataE1 = [1,1,1,1,1,1,1,1,1] # or use dataE1=[1]*9

ws1 = CreateWorkspace(dataX1, dataY1, dataE1)

#Create an absolute path by joining the proposed filename to a directory
#os.path.expanduser("~") used in this case returns the home directory of the current user
savefile = os.path.join(os.path.expanduser("~"), "AsciiFile.txt")

# perform the algorithm
SaveAscii(InputWorkspace=ws1,Filename=savefile,Separator="Space")

print "File Exists:", os.path.exists(savefile)

Output:

File Exists: True

Example - Save a workspace as ASCII with a different comment indicator

#import the os path libraries for directory functions
import os

# create histogram workspace
dataX1 = [0,1,2,3,4,5,6,7,8,9] # or use dataX1=range(0,10)
dataY1 = [0,1,2,3,4,5,6,7,8] # or use dataY1=range(0,9)
dataE1 = [1,1,1,1,1,1,1,1,1] # or use dataE1=[1]*9

ws1 = CreateWorkspace(dataX1, dataY1, dataE1)

#Create an absolute path by joining the proposed filename to a directory
#os.path.expanduser("~") used in this case returns the home directory of the current user
savefile = os.path.join(os.path.expanduser("~"), "AsciiFile.txt")

# perform the algorithm
# CommentIndicator can be changed, but when read back in must be specified
SaveAscii(InputWorkspace=ws1,Filename=savefile,CommentIndicator="!")

print "File Exists:", os.path.exists(savefile)

Output:

File Exists: True

Categories: Algorithms | DataHandling\Text

Source

C++ source: SaveAscii2.cpp

C++ header: SaveAscii2.h