Adam,
You can read in simple CSV files with rcols using the rather-well-hidden
$PDL::IO::Misc::colsep variable (which should probably be made another
option to rcols...). Here's an example using the interesting file xxx.dat,
whose contents are:
1,2,a string,4,5
3,4,another string,5,6
9,8,,2,1
perldl> $PDL::IO::Misc::colsep = ","
perldl> @a = rcols "xxx.dat", 0, 1, 3, 4, { perlcols => [2] }
Reading data into piddles of type: [ Double Double Double Double ]
Read in 3 elements.
perldl> p $a[0]
[1 3 9]
perldl> p $a[1]
[2 4 8]
perldl> p $a[2]
[4 5 2]
perldl> p $a[3]
[5 6 1]
perldl> p $a[4]
ARRAY(0x2171054)
perldl> p "/" . join("| ", @{$a[4]}) . "/"
/a string| another string| /
If you just did
perldl> @b = rcols "xxx.dat", { perlcols => [2] }
then @b would contain 6 elements where
b[0] == a[0], b[1] == a[1], b[2] == [0,0,0]
b[3] == a[2], b[4] == a[3], b[5] == a[4]
(ie it would reas in the string column twice, the first time as a piddle
and hence getting lots of 0's).
HTH,
Doug
On Thu, 15 Mar 2007, Adam Ginsburg wrote:
> I'm trying to read in a CSV file that contains non-numeric data. A
> normal PDL can't hold strings, so I figure I must use PDL::Char. I
> don't believe this can be used with rcols, but that would be the ideal
> situation.
>
> As it is, the solution I've come up with is:
> while (<$filename>) {
>
> @temp=split(",",$_);
>
> $t_pdl=PDL::Char->new(@temp);
> push
> (@file_pl_arr,$t_pdl);
> }
> $file_array=pdl(@file_pl_arr);
>
> However, using PDL::Char doesn't store strings, it stores each char in
> a different part of the grid... which kills the nice two-dimensional
> nature of a csv file. So I'm using the above code with
> $t_pdl=pdl(@temp) and referencing strings from the "2d" perl array I'm
> pushing @temp onto.
>
> Besides the ugliness of using a PDL and an "array" of "arrays", using
> perl's slurp function would probably be faster - any suggestions on
> how to slurp into a PDL? I find myself wanting to thread over a perl
> array =/
>
> On an entirely separate note... is there a pgplot command to draw an
> unfilled circle?
>
> Adam
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl