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) --Chris >> --Edward H. >> >>> -----Original Message----- >>> From: Craig DeForest [mailto:[email protected]] >>> Sent: Sunday, March 08, 2009 9:54 PM >>> To: Hyer, Dr. Edward >>> Cc: Craig DeForest; [email protected] >>> Subject: Re: [Perldl] Simple stuff: PDL::IO::FlexRaw and data types >>> >>> Hi, Edward, >>> >>> You're right, PDL doesn't have a ulong type -- only a ushort. >>> Since your values aren't likely to be larger than 2**31, you >>> are probably OK >>> just using "long" rather than "ulong". That might be the source of >>> your readflex error, too; why not try it with "long" instead >>> of "ulong"? >>> >>> Cheers, >>> Craig >>> >>> >>> On Mar 8, 2009, at 10:22 PM, Hyer, Dr. Edward wrote: >>> >>>> Hello PDL Wizards, >>>> >>>> Always embarrassed to ask easy questions, but I'm stumped. >>>> >>>> Trying to set up and read from a raw binary file (from >>> someone else). >>>> File has a 64-item,unsigned-long header, which must be >>> queried to find >>>> the start and dimensions of the data block. Cribbing >>> directly from the >>>> FlexRaw docs, I did this: >>>> >>>> open(AREA,"<$file2"); >>>> binmode(AREA) >>>> $head = readflex(AREA, [{NDims=>1, Dims=>[64], Type='ulong'}]) >>>> $pixels=$head->(9) >>>> $lines=$head->(8) >>>> $datastart=$head->(33) >>>> seek(AREA,($pixels * $lines)+$datastart,0) $areadata = >>> readflex(AREA, >>>> [{NDims=>2, Dims=>[$pixels,$lines], >>>> Type='byte'}]) >>>> close(AREA); >>>> >>>> Two questions: >>>> >>>> 1) I can't get past the first readflex(), because of this error: >>>> >>>> Can't modify constant item in scalar assignment at (eval >>> 119) line 4, >>>> at EOF >>>> >>>> 2) Does PDL actually have a 'ulong' type? (32-bit unsigned) >>>> >>>> Thanks, >>>> >>>> >>>> --Edward H. _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
