System Function Native Files: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
No edit summary
Line 18: Line 18:
</tr>
</tr>
<tr>
<tr>
   <td><apll>R</apll> is a numeric scalar or one- or two-element numeric vector.</td>
   <td><apll>R</apll> is a numeric scalar or one- or two-element vector.</td>
</tr>
</tr>
<tr>
<tr>
Line 27: Line 27:
<br />
<br />


<p>The first item in <apll>R</apll> is the file tie number; the optional second element is the conversion code used to convert the data in <apll>L</apll> before writing it to the file.  The File and Workspace conversion codes are as follows:</p>
<p>The first item in <apll>R</apll> is the tie number of a file created/opened by <apll>⎕NCREATE</apll> or <apll>⎕NTIE</apll>; the optional second element is the File Conversion code used to convert the data in <apll>L</apll> before writing it to the file.  The File and Workspace Conversion codes are as follows:</p>


<table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
<tr>
<tr>
   <td valign="bottom"><b>Code</b></td>
   <td valign="bottom" align="center"><b>Numeric<br />Value</b></td>
   <td valign="bottom"><b>Name</b></td>
   <td valign="bottom" align="center"><b>Character<br />Name</b></td>
   <td valign="bottom"><b>Datatype</b></td>
   <td valign="bottom"><b>Datatype</b></td>
   <td valign="bottom"><b>File(F) or<br />Workspace(W)</b></td>
   <td valign="bottom"><b>File(F) or<br />Workspace(W)</b></td>
Line 40: Line 40:
   <td><apll>&nbsp;110</apll></td>
   <td><apll>&nbsp;110</apll></td>
   <td><apll>'bool'</apll></td>
   <td><apll>'bool'</apll></td>
   <td>Boolean</td>
   <td>1-bit Boolean</td>
   <td>FW</td>
   <td>FW</td>
</tr>
</tr>
Line 102: Line 102:
</table>
</table>


<p>If the file conversion code is omitted, then the file conversion code specified implicitly or explicitly when the file was most recently created or opened is used.</p>
<p>You may use either the numeric value or upper-/lower-case character name to identify the conversion code.</p>
 
<p>If the file conversion code is omitted, then the corresponding code specified implicitly or explicitly when the file was most recently created or opened is used.</p>


<p>For example:</p>
<p>For example:</p>


<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tn←'C:\foo' ⎕ncreate 0 ⍝</apll> Implicit file conversion code of <apll>'char8'</apll> and workspace conversion code of <apll>'char16'</apll><apll><br />
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tn←'C:\foo' ⎕ncreate 0 ⍝</apll> Implicit file conversion code of <apll>'char8'</apll> and workspace conversion code of <apll>'char16'</apll><apll><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Now is the time' ⎕nappend tn<br /></apll>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Now is the time ' ⎕nappend tn<br /></apll>


<p>After which the file data consists of</p>
<p>After which the file data consists of</p>
Line 115: Line 117:
</pre>
</pre>


<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Now is the time' ⎕nappend tn 'char16'<br /></apll>
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Now is the time ' ⎕nappend tn 'char16'<br /></apll>


<p>After which the file data consists of</p>
<p>After which the file data consists of</p>
Line 126: Line 128:
</pre>
</pre>


<p>If the workspace data (in <apll>L</apll>) is wider than the width specified by the file conversion code, then a <apll>DOMAIN ERROR</apll> is signalled.  For example, if the data in <apll>L</apll> is character (<apll>'char16'</apll>) and the file conversion code is one of <apll>'char8'</apll>, <apll>'int8'</apll>, or <apll>'bool'</apll>, then enough of the high-order bits of each character in <apll>L</apll> must be zero so that the actual value fits without truncation.</p>
<p>If the workspace data (in <apll>L</apll>) is wider than the width specified by the file conversion code and it cannot be truncated at the high end without losing data, then a <apll>DOMAIN ERROR</apll> is signalled.  For example, if the data in <apll>L</apll> is character (<apll>'char16'</apll>) and the file conversion code is one of <apll>'char8'</apll>, <apll>'int8'</apll>, or <apll>'bool'</apll>, then enough of the high-order bits of each character in <apll>L</apll> must be zero so that the actual value fits without loss of data.</p>


<p>For example:</p>
<p>For example:</p>


<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'⊤○⍵ ⍳⌈ ∼∆∊ ∼⍳⍦∊ ' ⎕nappend tn<br />
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tn←'C:\foo' ⎕ncreate 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'⊤○⍵ ⍳⌈ ∼∆∊ ∼⍳⍦∊ ' ⎕nappend tn<br />
DOMAIN ERROR<br />
DOMAIN ERROR<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'⊤○⍵ ⍳⌈ ∼∆∊ ∼⍳⍦∊ ' ⎕nappend tn<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'⊤○⍵ ⍳⌈ ∼∆∊ ∼⍳⍦∊ ' ⎕nappend tn<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;∧<br /></apll>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;∧<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'⊤○⍵ ⍳⌈ ∼∆∊ ∼⍳⍦∊ ' ⎕nappend tn 'char16'</apll>
 
<p>After which the file data consists of</p>
 
<pre>
  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
|A4|22|CB|25|75|23|20|00|73|23|08|23|20|00|3C|22|  ⊤○⍵ ⍳⌈ ∼
|06|22|0A|22|20|00|3C|22|73|23|66|23|0A|22|20|00|  ∆∊ ∼⍳⍦∊
</pre>


== <apll>⎕NCREATE</apll> ==
== <apll>⎕NCREATE</apll> ==
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
<tr>
  <td>
    <table border="0" cellpadding="5" cellspacing="0" summary="">
    <tr>
      <td valign="top"><apll>Z←L ⎕NCREATE R</apll></td>
      <td></td>
      <td></td>
      <td>creates and opens the file named in <apll>L</apll> and associates with it the tie number from the first element in <apll>R</apll>.</td>
    </tr>
    </table>
  </td>
</tr>
<tr>
  <td><apll>L</apll> is a character scalar or vector.</td>
</tr>
<tr>
  <td><apll>R</apll> is a numeric scalar or one-, two-, or three-element vector.</td>
</tr>
<tr>
  <td><apll>Z</apll> is a numeric scalar of the tie number of the file.</td>
</tr>
</table>
<br />


== <apll>⎕NERASE</apll> ==
== <apll>⎕NERASE</apll> ==
Line 152: Line 190:


== <apll>⎕NNUMS</apll> ==
== <apll>⎕NNUMS</apll> ==
== <apll>⎕NTIE</apll> ==
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
<tr>
  <td>
    <table border="0" cellpadding="5" cellspacing="0" summary="">
    <tr>
      <td valign="top"><apll>Z←L ⎕NTIE R</apll></td>
      <td></td>
      <td></td>
      <td>opens the existing file named in <apll>L</apll> and associates with it the tie number from the first element in <apll>R</apll>.</td>
    </tr>
    </table>
  </td>
</tr>
<tr>
  <td><apll>L</apll> is a character scalar or vector.</td>
</tr>
<tr>
  <td><apll>R</apll> is a numeric scalar or one-, two-, or three-element vector.</td>
</tr>
<tr>
  <td><apll>Z</apll> is a numeric scalar of the tie number of the file.</td>
</tr>
</table>
<br />


== <apll>⎕NUNTIE</apll> ==
== <apll>⎕NUNTIE</apll> ==

Revision as of 11:57, 18 March 2012

⎕NAPPEND

Z←L ⎕NAPPEND R appends the raveled data in L to the file whose tie number is in R.
L is an arbitrary (but simple homogeneous) array.
R is a numeric scalar or one- or two-element vector.
Z is a numeric scalar of the offset in the file of the next byte after the data just appended.


The first item in R is the tie number of a file created/opened by ⎕NCREATE or ⎕NTIE; the optional second element is the File Conversion code used to convert the data in L before writing it to the file. The File and Workspace Conversion codes are as follows:

Numeric
Value
Character
Name
Datatype File(F) or
Workspace(W)
 110 'bool' 1-bit Boolean FW
 811 'char8' 8-bit character F
1611 'char16' 16-bit character FW
3211 'char32' 32-bit character F
 812 'int8' 8-bit integer F
1612 'int16' 16-bit integer F
3212 'int32' 32-bit integer F
6412 'int64' 64-bit integer FW
6413 'flt64' 64-bit float FW

You may use either the numeric value or upper-/lower-case character name to identify the conversion code.

If the file conversion code is omitted, then the corresponding code specified implicitly or explicitly when the file was most recently created or opened is used.

For example:

      tn←'C:\foo' ⎕ncreate 0 ⍝ Implicit file conversion code of 'char8' and workspace conversion code of 'char16'
      'Now is the time ' ⎕nappend tn

After which the file data consists of

  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
|4E|6F|77|20|69|73|20|74|68|65|20|74|69|6D|65|20|  Now is the time

      'Now is the time ' ⎕nappend tn 'char16'

After which the file data consists of

  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
|4E|6F|77|20|69|73|20|74|68|65|20|74|69|6D|65|20|  Now is the time
|4E|00|6F|00|77|00|20|00|69|00|73|00|20|00|74|00|  N o w   i s   t
|68|00|65|00|20|00|74|00|69|00|6D|00|65|00|20|00|  h e   t i m e  

If the workspace data (in L) is wider than the width specified by the file conversion code and it cannot be truncated at the high end without losing data, then a DOMAIN ERROR is signalled. For example, if the data in L is character ('char16') and the file conversion code is one of 'char8', 'int8', or 'bool', then enough of the high-order bits of each character in L must be zero so that the actual value fits without loss of data.

For example:

      tn←'C:\foo' ⎕ncreate 0
      '⊤○⍵ ⍳⌈ ∼∆∊ ∼⍳⍦∊ ' ⎕nappend tn
DOMAIN ERROR
      '⊤○⍵ ⍳⌈ ∼∆∊ ∼⍳⍦∊ ' ⎕nappend tn
                         ∧
      '⊤○⍵ ⍳⌈ ∼∆∊ ∼⍳⍦∊ ' ⎕nappend tn 'char16'

After which the file data consists of

  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
|A4|22|CB|25|75|23|20|00|73|23|08|23|20|00|3C|22|  ⊤○⍵ ⍳⌈ ∼
|06|22|0A|22|20|00|3C|22|73|23|66|23|0A|22|20|00|  ∆∊ ∼⍳⍦∊ 

⎕NCREATE

Z←L ⎕NCREATE R creates and opens the file named in L and associates with it the tie number from the first element in R.
L is a character scalar or vector.
R is a numeric scalar or one-, two-, or three-element vector.
Z is a numeric scalar of the tie number of the file.


⎕NERASE

⎕NREAD

⎕NRENAME

⎕NREPLACE

⎕NRESIZE

⎕NSIZE

⎕NNAMES

⎕NNUMS

⎕NTIE

Z←L ⎕NTIE R opens the existing file named in L and associates with it the tie number from the first element in R.
L is a character scalar or vector.
R is a numeric scalar or one-, two-, or three-element vector.
Z is a numeric scalar of the tie number of the file.


⎕NUNTIE