Chris, OK, I remember seeing the \*HANDLE notation in the docs, and it does work. It's one of those things where I tried it but had other bugs to fix yet, so forgot to try it again once they were fixed.
I've never had to use a reference to a filehandle before, any important PDL lesson in why this is required? P.S. As it turned out, for this particular job, the ability to read a compressed file took precedence over the ability to seek() in the file: much faster to read in the entire file and toss what I don't need than to uncompress/read/compress, in this case, so I ended up not using open/seek/close at all. TMTOWTDI.... Thanks, --Edward H. -----Original Message----- From: Chris Marshall [mailto:[email protected]] Sent: Tuesday, March 10, 2009 7:42 PM To: [email protected] Cc: Hyer, Dr. Edward; [email protected] Subject: Re: [Perldl] Simple stuff: PDL::IO::FlexRaw and data types Chris Marshall wrote: > Doug Hunt wrote: >> Hi Edward: Two ideas: >> >> One, try using the newer style file open: >> >> open my $fh, '<', $file or die "Cannot open $file"; binmode($fh); # >> not sure if this is necessary (probably not on unix) my $header = >> readflex($fh, $hdr); >> >> (not tested!) >> >> I don't think its usual practice to pass raw file handles to routines: >> >> readflex(AREA, $hdr) >> >> The newer form of open gets around this problem. >> >> Secondly, it is sad that PDL does not have an unsigned long type, but >> you can often get away with using a signed long and then 'undoing' >> the sign bit manually and casting to a double: >> >> perldl> p $toobig = (2**31 + 1) >> 2147483649 >> perldl> p long($toobig) >> -2147483648 >> perldl> p double(long($toobig) + (2**32 + 1)) >> 2147483649 >> >> Regards, >> >> Doug Hunt >> >> >> [email protected] >> Software Engineer IV >> UCAR - COSMIC, Tel. (303) 497-2611 >> >> On Mon, 9 Mar 2009, Hyer, Dr. Edward wrote: >> >>> Craig, >>> >>> You're right: 'long' works fine for this application. Thanks! >>> >>> I did get readflex() to work, but only by giving it the filename >>> rather than the filehandle. As in, this works: >>> >>> $file='/path/to/file.dat'; >>> $hdr=[{NDims=>1,Dims=>[64],Type=>'long'}] >>> $header=readflex($file,$hdr); >>> >>> This does not: >>> >>> open(AREA,"<$file"); >>> binmode(AREA) >>> $header=readflex(AREA,$hdr); >>> >>> Error is 'PDL: Couldn't open 'AREA' for reading.' >>> >>> What am I doing wrong? > > You might try passing a reference to a typeglob instead of the bare > handle. (e.g. \*AREA) I took a look at the perl documentation for PDL::IO::FlexRaw and it explicitly says that you need a reference to a file handle. However, later in the short function descriptions, the requirement for a reference to a file handle is not shown. Looks like a POD bug to me. --Chris _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
