OOC Methods which return Data Values (with or without metadata)

Table of Contents

  1. Method all
  2. Method value
  3. Default method
  4. Format Conversion Strings

Method all

ooc_name all -format format -columns int -lines int -missing text -keep

This provides both data and metadata from a NAO. However it does not provide all information despite the name!

The following switches are allowed:
-format format: C format (default: Use internal format if any, else "" meaning automatic)
-columns int: maximum # columns (default: 6) (-1: no limit)
-lines int: maximum # lines (default: 20) (-1: no limit)
-list: print in tcl list form (using braces) e.g. "{1 9 2}"
-missing text: text printed for missing value (default: "_")
-keep: Do not delete NAO with reference count of 0

The all method provides the same information as the two commands:
ooc_name header
ooc_name value -format format -columns int -lines int -missing text

Example

% [nap "{3#2 2#_ -9}"] all -miss n/a
::NAP::39-39  i32  MissingValue: -2147483648  References: 0  Unit: (NULL)
Dimension 0   Size: 6      Name: (NULL)    Coordinate-variable: (NULL)
Value:
2 2 2 n/a n/a -9

Method value

ooc_name value -format format -columns int -lines int -missing text -keep

This returns data values. The default value is -1 for both the switches -columns and -lines, giving the entire array.

The following switches are allowed:
-format format: C format (default: Use internal format if any, else "" meaning automatic)
-columns int: maximum # columns (default: -1 i.e. no limit)
-lines int: maximum # lines (default: -1 i.e. no limit)
-list: print in tcl list form (using braces) e.g. "{1 9 2}"
-missing text: text printed for missing value (default: "_")
-keep: Do not delete NAO with reference count of 0

Example

% nap "y = (0 .. 2 ... 0.5) ** 2"
::NAP::61-61
% $y val -format %0.3f
0.000 0.250 1.000 2.250 4.000

Default method

ooc_name -format format -columns int -lines int -missing text -keep

This returns data values in a similar fashion to the value method, except that default line and column limits restrict the size.

The following switches are allowed:
-format format: C format (default: Use internal format if any, else "" meaning automatic)
-columns int: maximum # columns (default: 6) (-1: no limit)
-lines int: maximum # lines (default: 20) (-1: no limit)
-list: print in tcl list form (using braces) e.g. "{1 9 2}"
-missing text: text printed for missing value (default: "_")
-keep: Do not delete NAO with reference count of 0

Examples

The following example shows why and how to use switch -columns (abbreviated to -c):
% nap "m = reshape(0 .. 99, {10 12})"
::NAP::50-50
% $m
 0  1  2  3  4  5 ..
12 13 14 15 16 17 ..
24 25 26 27 28 29 ..
36 37 38 39 40 41 ..
48 49 50 51 52 53 ..
60 61 62 63 64 65 ..
72 73 74 75 76 77 ..
84 85 86 87 88 89 ..
96 97 98 99  0  1 ..
 8  9 10 11 12 13 ..
% $m -c -1
 0  1  2  3  4  5  6  7  8  9 10 11
12 13 14 15 16 17 18 19 20 21 22 23
24 25 26 27 28 29 30 31 32 33 34 35
36 37 38 39 40 41 42 43 44 45 46 47
48 49 50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69 70 71
72 73 74 75 76 77 78 79 80 81 82 83
84 85 86 87 88 89 90 91 92 93 94 95
96 97 98 99  0  1  2  3  4  5  6  7
 8  9 10 11 12 13 14 15 16 17 18 19

The following example shows how to use switch -format (abbreviated to -f) to include a dollar prefix and display two decimal places:

% [nap "{15 3.2 999}"] -f {$%.2f}
$15.00 $3.20 $999.00

The following example shows how to use switch -list:

% [nap "reshape(1.5 .. -1.5, {2 5})"] -list
{
{  1.5  0.5 -0.5 -1.5  1.5 }
{  0.5 -0.5 -1.5  1.5  0.5 }
}

Format Conversion Strings

The -format option (or NAO internal format field) specifies a format conversion string similar to that used in the standard Tcl format command (which is based on the ANSI C sprintf() function). Such strings have the form
%[flags][width][.precision]char
where:

The following example displays the same data using each of these codes. Note that (unlike C and the standard Tcl format command) any data-type can be displayed with any code.

% foreach code {d i o x X u c f E e g G} {
    puts "$code: [[nap "88 .. 92"] -f "%$code"]"
}
d: 88 89 90 91 92
i: 88 89 90 91 92
o: 130 131 132 133 134
x: 58 59 5a 5b 5c
X: 58 59 5A 5B 5C
u: 88 89 90 91 92
c: XYZ[\
f: 88.000000 89.000000 90.000000 91.000000 92.000000
E: 8.800000E+01 8.900000E+01 9.000000E+01 9.100000E+01 9.200000E+01
e: 8.800000e+01 8.900000e+01 9.000000e+01 9.100000e+01 9.200000e+01
g: 88 89 90 91 92
G: 88 89 90 91 92

Author: Harvey Davies       © 2002, CSIRO Australia.       Legal Notice and Disclaimer
CVS Version Details: $Id: ooc_data.html,v 1.2 2004/10/25 09:01:26 dav480 Exp $