Topic: APLX Help : Help on APL language : System Functions & Variables : ⎕EXPORT Export APL array
[ Previous | Next | Contents | Index | APL Home ]

www.microapl.co.uk

⎕EXPORT Export APL array to file in specified format


The dyadic system function ⎕EXPORT exports an APL array to a file, in a format which can be read by other (non-APL) applications. (See also ⎕IMPORT which allows you to import data from a file of specified format).

The left argument is the array of data you want to export. The right argument determines the name of the file to be created, and the format of the file. If the right argument is a character vector, it is interpreted as the name of the file you want to create (including full path if required) and the format of the file is inferred from the file extension. If the right argument is a two element nested vector, the first element is the filename (or full pathname), and the second is a text string specifying the file type. File types are case-insensitive.

For example, the two following statements are equivalent, and will export the contents of the array BUDGET in 'comma-separated variables' ('CSV') format:

      BUDGET ⎕EXPORT 'Budget2007.csv'
      BUDGET ⎕EXPORT 'Budget2007.csv' 'csv'

The following file formats are supported, with the restrictions shown on the type and ranks of the data which can be exported in that format:

File type/extension Description Restrictions
'txt' Text representation of the array (same as monadic format), with characters represented in 8-bit extended ASCII form. For matrices and higher-rank arrays, lines of text will be separated by the appropriate newline character for the platform (CR-LF on Windows, LF on Linux and MacOS). All arrays supported, subject to available memory.
'utf16' or 'utf-16' Same as 'txt', with characters represented in 16-bit UTF-16 Unicode form (2 bytes per character). All arrays supported, subject to available memory.
'utf8' or 'utf-8' Same as 'txt', with characters represented in the 8-bit UTF-8 Unicode form (variable number of bytes per character). All arrays supported, subject to available memory.
'csv' 'Comma-separated variables' format, as used by many applications such as spreadsheets for data exchange. The file comprises one line of text per row of the data, with individual elements separated by commas. Numeric elements are expressed in text form. Text elements are surrounded by double-quotation marks; however, when importing CSV, many applications will ignore the quotation marks and treat the element as numeric if the string could be interpreted as a valid number. The maximum rank of the array is 2. The array can be nested, but any elements other than scalars and character vectors will be represented by their monadic format. The array must not contain object references. Characters are output in 8-bit (extended ASCII) form.
'tsv' 'Tab-separated variables' format. Same as CSV, except the fields are separated by tab characters instead of commas. Same as for CSV.
'htm' or 'html' HTML format. The result is an HTML page which can be loaded into a Web Browser or imported into another application such as Microsoft Word or Excel. The page will contain an HTML table containing the data, unless the array is a simple character array, in which case it is output as a paragraph with <BR> between lines. The maximum rank of the array is 2. The array can be nested, but any elements other than scalars and character vectors will be represented by their monadic format. The array must not contain object references. All printable characers in ⎕AV can be output (non-ASCII characters will be output in escaped Unicode form).
'slk' Symbolic Link (SYLK) format, a Microsoft-specified file format typically used to exchange data between applications such as Excel and other spreadsheets. The maximum rank of the array is 2. The array can be nested, but any elements other than scalars and character vectors will be represented by their monadic format. The array must not contain object references. Only ASCII characters, plus some other specific characters such as accented letters, can be represented. APL symbols and other non-representable characters will be replaced by '?'.
'xml' Extensible Markup Language (XML) format, a format used for saving structured data with markup information. The left argument must be an APL array with the same specification as ⎕XML. The data is written as UTF-8 encoded XML text. This conversion is equivalent to the two-stage command:

      (⎕XML array) ⎕EXPORT 'filename' 'utf8'

In order to ensure that the XML generated is valid, ⎕EXPORT will add the following XML prologue if the APL array does not contain one:

      <?xml version="1.0" encoding="utf-8"?>

Note that, because the intention is to allow APLX to exchange data with other applications, ⎕EXPORT translates APL high minus (¯) to ASCII or Unicode minus (-).

For example, suppose that BUDGET is a 4-row matrix of text vectors and numbers as follows:

     BUDGET
             Q1    Q2    Q3    Q4
 Sales    11300 13220 16550 19230
 Expenses 12450 12950 13640 13980
 Profit   ¯1150   270  2910  5250
      ⎕DISPLAY BUDGET
┌→───────────────────────────────────┐
↓ ┌⊖┐        ┌→─┐  ┌→─┐  ┌→─┐  ┌→─┐  │
│ │ │        │Q1│  │Q2│  │Q3│  │Q4│  │
│ └─┘        └──┘  └──┘  └──┘  └──┘  │
│ ┌→────┐                            │
│ │Sales│    11300 13220 16550 19230 │
│ └─────┘                            │
│ ┌→───────┐                         │
│ │Expenses│ 12450 12950 13640 13980 │
│ └────────┘                         │
│ ┌→─────┐                           │
│ │Profit│   ¯1150 270   2910  5250  │
│ └──────┘                           │
└∊───────────────────────────────────┘

This array can be exported in CSV format as follows:

      BUDGET ⎕EXPORT 'Budget2007.csv'

The contents of the file 'Budget2007.csv' will be:

"","Q1","Q2","Q3","Q4"
"Sales",11300,13220,16550,19230
"Expenses",12450,12950,13640,13980
"Profit",-1150,270,2910,5250

Alternatively, the same data can be exported in SYLK format:

      BUDGET ⎕EXPORT 'Budget2007.slk'

The contents of the file 'Budget2007.slk' will contain the data in SYLK format:

ID;PAPLX;N;E
P;PGeneral
B;Y4;X5
C;Y1;X1;K""
C;X2;K"Q1"
C;X3;K"Q2"
C;X4;K"Q3"
C;X5;K"Q4"
C;Y2;X1;K"Sales"
C;X2;K11300
C;X3;K13220
C;X4;K16550
C;X5;K19230
C;Y3;X1;K"Expenses"
C;X2;K12450
C;X3;K12950
C;X4;K13640
C;X5;K13980
C;Y4;X1;K"Profit"
C;X2;K-1150
C;X3;K270
C;X4;K2910
C;X5;K5250
E

Either format can be directly opened by another application such as Excel:

Special considerations for Client-Server implementations of APLX

In Client-Server implementations of APLX, the front-end which implements the user-interface (the "Client") runs on one machine, and the APLX interpreter itself (the "Server") can run on a different machine. Typically, the Client will be the APLX front-end built as a 32-bit Windows application running on a desktop PC, and the Server will be a 64-bit APLX64 interpreter running on a 64-bit Linux or Windows server.

In such systems, you can specify whether the file should be accessed on the Client or the Server machine. You do this by preceding the file name with either an Up Arrow to indicate that the file should be accessed on the Client, or a Down Arrow to indicate that it should be accessed on the Server. If you do not specify, the default is that the access takes place on the Client.


Topic: APLX Help : Help on APL language : System Functions & Variables : ⎕EXPORT Export APL array
[ Previous | Next | Contents | Index | APL Home ]