1Misc(3)               User Contributed Perl Documentation              Misc(3)
2
3
4

NAME

6       PDL::IO::Misc - misc IO routines for PDL
7

DESCRIPTION

9       Some basic I/O functionality: FITS, tables, byte-swapping
10

SYNOPSIS

12        use PDL::IO::Misc;
13

FUNCTIONS

15   bswap2
16         Signature: (x(); )
17
18       Swaps pairs of bytes in argument x()
19
20       bswap2 does not process bad values.  It will set the bad-value flag of
21       all output piddles if the flag is set for any of the input piddles.
22
23   bswap4
24         Signature: (x(); )
25
26       Swaps quads of bytes in argument x()
27
28       bswap4 does not process bad values.  It will set the bad-value flag of
29       all output piddles if the flag is set for any of the input piddles.
30
31   bswap8
32         Signature: (x(); )
33
34       Swaps octets of bytes in argument x()
35
36       bswap8 does not process bad values.  It will set the bad-value flag of
37       all output piddles if the flag is set for any of the input piddles.
38
39   rcols()
40       Read ASCII whitespaced cols from a file into piddles and perl arrays
41       (also see "rgrep()").
42
43       There are two calling conventions - the old version, where a pattern
44       can be specified after the filename/handle, and the new version where
45       options are given as as hash reference. This reference can be given as
46       either the second or last argument.
47
48       The default behaviour is to ignore lines beginning with a # character
49       and lines that only consist of whitespace. Options exist to only read
50       from lines that match, or do not match, supplied patterns, and to set
51       the types of the created piddles.
52
53       Can take file name or *HANDLE, and if no columns are specified, all are
54       assumed. For the allowed types, see "Datatype_conversions" in
55       PDL::Core.
56
57       Options:
58
59       EXCLUDE or IGNORE - ignore lines matching this pattern (default
60       '/^#/').
61
62       INCLUDE or KEEP - only use lines which match this pattern (default '').
63
64       LINES - which line numbers to use. Line numbers start at 0 and the
65       syntax is 'a:b:c' to use every c'th matching line between a and b
66       (default '').
67
68       DEFTYPE - default data type for stored data (if not specified, use the
69       type stored in $PDL::IO::Misc::deftype, which starts off as double).
70
71       TYPES - reference to an array of data types, one element for each
72       column to be read in.  Any missing columns use the DEFTYPE value
73       (default []).
74
75       PERLCOLS - an array of column numbers which are to be read into perl
76       arrays rather than piddles. References to these arrays are returned
77       after the requested piddles (default undef).
78
79         Usage:
80           ($x,$y,...) = rcols( *HANDLE|"filename", { EXCLUDE => '/^!/' },
81                                $col1, $col2, ... )
82           ($x,$y,...) = rcols( *HANDLE|"filename", $col1, $col2, ...,
83                                { EXCLUDE => '/^!/' } )
84           ($x,$y,...) = rcols( *HANDLE|"filename", "/foo/", $col1, $col2, ... )
85
86       e.g.,
87
88         $x      = PDL->rcols 'file1';
89         ($x,$y) = rcols *STDOUT;
90
91         # read in lines containing the string foo, where the first
92         # example also ignores lines that with a # character.
93         ($x,$y,$z) = rcols 'file2', 0,4,5, { INCLUDE => '/foo/' };
94         ($x,$y,$z) = rcols 'file2', 0,4,5,
95                        { INCLUDE => '/foo/', EXCLUDE => '' };
96
97         # ignore the first 27 lines of the file, reading in as ushort's
98         ($x,$y) = rcols 'file3', { LINES => '27:-1', DEFTYPE => ushort };
99         ($x,$y) = rcols 'file3',
100                     { LINES => '27:', TYPES => [ ushort, ushort ] };
101
102         # read in the first column as a perl array and the next two as piddles
103         ($x,$y,$name) = rcols 'file4', 1, 2, { PERLCOLS => [ 0 ] };
104         printf "Number of names read in = %d\n", 1 + $#$name;
105
106       Notes:
107
108       1. Quotes are required on patterns.
109
110       2. Columns are separated by whitespace by default, use
111       $PDL::IO::Misc::colsep to specify an alternate separator.
112
113       3. For PDL-2.003, the meaning of the 'c' value in the LINES option has
114       changed: it now only counts matching lines rather than all lines as in
115       previous versions of PDL.
116
117       4. LINES => '-1:0:3' may not work as you expect, since lines are
118       skipped when read in, then the whole array reversed.
119
120   wcols()
121       Write ASCII whitespaced cols into file from piddles efficiently.
122
123       If no columns are specified all are assumed.  Will optionally only
124       process lines matching a pattern.  Can take file name or *HANDLE, and
125       if no file/filehandle is given defaults to STDOUT.
126
127       Options:
128
129       HEADER - prints this string before the data. If the string is not
130       terminated by a newline, one is added (default '').
131
132        Usage: wcols $piddle1, $piddle2,..., *HANDLE|"outfile", [\%options];
133
134       e.g.,
135
136         wcols $x, $y+2, 'foo.dat';
137         wcols $x, $y+2, *STDERR;
138         wcols $x, $y+2, '|wc';
139         wcols $a,$b,$c; # Orthogonal version of 'print $a,$b,$c' :-)
140
141         wcols "%10.3f", $a,$b; # Formatted
142         wcols "%10.3f %10.5g", $a,$b; # Individual column formatting
143
144         wcols $a,$b, { HEADER => "#   a   b" };
145
146       Note: columns are separated by whitespace by default, use
147       $PDL::IO::Misc::colsep to specify an alternate separator.
148
149   swcols()
150       generate string list from "sprintf" format specifier and a list of
151       piddles
152
153       "swcols" takes an (optional) format specifier of the printf sort and a
154       list of 1d piddles as input. It returns a perl array (or array
155       reference if called in scalar context) where each element of the array
156       is the string generated by printing the corresponding element of the
157       piddle(s) using the format specified. If no format is specified it uses
158       the default print format.
159
160        Usage: @str = swcols format, pdl1,pdl2,pdl3,...;
161         or
162               $str = swcols format, pdl1,pdl2,pdl3,...;
163
164   rgrep()
165       Read columns into piddles using full regexp pattern matching.
166
167       Options:
168
169       UNDEFINED: This option determines what will be done for undefined
170       values. For instance when reading a comma-separated file of the type
171       "1,2,,4" where the ",," indicates a missing value.
172
173       The default value is to assign $PDL::undefval to undefined values, but
174       if "UNDEFINED" is set this is used instead. This would normally be set
175       to a number, but if it is set to "Bad" and PDL is compiled with
176       Badvalue support (see "" in PDL::Bad) then undefined values are set to
177       the appropriate badvalue and the column is marked as bad.
178
179       DEFTYPE: Sets the default type of the columns - see the documentation
180       for
181        "rcols()"
182
183       TYPES:   A reference to a Perl array with types for each column - see
184       the documentation for "rcols()"
185
186       BUFFERSIZE: The number of lines to extend the piddle by. It might speed
187       up the reading a little bit by setting this to the number of lines in
188       the file, but in general "rasc()" is a better choice
189
190       Usage
191
192        ($x,$y,...) = rgrep(sub, *HANDLE|"filename")
193
194       e.g.
195
196        ($a,$b) = rgrep {/Foo (.*) Bar (.*) Mumble/} $file;
197
198       i.e. the vectors $a and $b get the progressive values of $1, $2 etc.
199
200   rdsa()
201       Read a FIGARO/NDF format file.
202
203       Requires non-PDL DSA module. Contact Frossie (frossie@jach.hawaii.edu)
204       Usage:
205
206        ([$xaxis],$data) = rdsa($file)
207
208        $a = rdsa 'file.sdf'
209
210       Not yet tested with PDL-1.9X versions
211
212   isbigendian()
213       Determine endianness of machine - returns 0 or 1 accordingly
214
215   rasc()
216       Simple function to slurp in ASCII numbers quite quickly, although error
217       handling is marginal (to nonexistent).
218
219         $pdl->rasc("filename"|FILEHANDLE [,$noElements]);
220             Where:
221               filename is the name of the ASCII file to read or
222                 open file handle
223               $noElements is the optional number of elements in the file to read.
224                   (If not present, all of the file will be read to fill up $pdl).
225               $pdl can be of type float or double for more precision.
226
227         #  (test.num is an ascii file with 20 numbers. One number per line.)
228         $in = PDL->null;
229         $num = 20;
230         $in->rasc('test.num',20);
231         $imm = zeroes(float,20,2);
232         $imm->rasc('test.num');
233
234   rcube
235       Read list of files directly into a large data cube (for efficiency)
236
237        $cube = rcube \&reader_function, @files;
238
239        $cube = rcube \&rfits, glob("*.fits");
240
241       This IO function allows direct reading of files into a large data cube,
242       Obviously one could use cat() but this is more memory efficient.
243
244       The reading function (e.g. rfits, readfraw) (passed as a reference) and
245       files are the arguments.
246
247       The cube is created as the same X,Y dims and datatype as the first
248       image specified. The Z dim is simply the number of images.
249

AUTHOR

251       Copyright (C) Karl Glazebrook 1997 and Craig DeForest 2001, 2003.  All
252       rights reserved. There is no warranty. You are allowed to redistribute
253       this software / documentation under certain conditions. For details,
254       see the file COPYING in the PDL distribution. If this file is separated
255       from the PDL distribution, the copyright notice should be included in
256       the file.
257
258
259
260perl v5.12.3                      2011-03-31                           Misc(3)
Impressum