Thanks Dave, I was able to run this on my Mac (also in J602 by only changing
the one instance of y. to y in the script you sent at the bottom here).
The problem is in using the supplied routine <freads> to read the file.
I opened the file natively and inspected the size using ...
$ 1!:1 <'/Users/robhodgkinson/FPF/flirpics/Run43.FPF'
1311612
$ 1!:1 <'/Users/robhodgkinson/FPF/flirpics/Run44.FPF'
1311612 NB. Same size ??? ... Suspicious ...
So then tried ...
$ freads <'/Users/robhodgkinson/FPF/flirpics/Run43.FPF'
1311613
$ freads <'/Users/robhodgkinson/FPF/flirpics/Run44.FPF'
1311572
I don't know <freads> well enough to explain its assumptions, but it does
appear to use <toJ> to substitute LF for CR, and adjusts for LF at the end
and other things (just view freads to see this further).
So you need to substitute the following line of code in your script:
dat=:freads y.
for one of the following three choices (I believe):
===========================================================================
dat=:1!:1@< y. NB. J file read command (foreign conjunction)
dat=:nread y. NB. require 'nfiles'
NB. defaults to <82 nread>, so data as raw 8 bit char
dat=:fread y. NB. Same as <freads> but data appears not to be modified
NB. default case is <'' fread> which exits before toJ call
===========================================================================
Perhaps a more experienced J person using files may shed more light on the
best choice and why. I briefly tried <fread> and it worked (so did nread),
but I would think <nread> (which appears to be just like the []nread in STSC
APL, which just returns the faw file data) may be the best choice.
Regards,
Rob Hodgkinson
On 22/12/07 3:10 PM, "David Porter" <[EMAIL PROTECTED]> wrote:
> Hi Bob,
>
> Indeed it is the Flir Public format. I had the definition of the file
> from the manual, but the info below seems a bit more up to date. It is
> from the help file in their FPF viewer software. I do read the pixel
> offset, but it is always 892 bytes. I've included my code in
> readflir.ijs. It is for J504 with the image3 addon. I have also
> included two fpf files. #43 works OK and #44 fails.
>
> Thanks for any insight you can supply,
> Dave
>
> FLIR info:
> FLIR Public image format
> The "xxxx.fpf" files consist of a header followed by a matrix of single
> precision IEEE floating-point values, each representing one point of the
> image. A C-style description of the header layout can be found in the
> header file fpfimg.h, available in the installation directory. The image
> point values are stored starting from the top left corner, row by row.
> The FLIR Camera Control can only save FPF images.
>
> The basic data types are:
> Char 8 bit Often represents ASCII characters, may represent an 2's
> complement 8 bit integer (-128 - +127)
> Unsigned char 8 bit 8 bit integer number (0 - 255)
> Short 16 bit 16 bit integer (2's complement)
> Unsigned short 16 bit 16 bit integer
> Long 32 bit 32 bit integer (2's complement)
> Unsigned long 32 bit 32 bit integer
> Float 32 bit IEEE floating point number, sign + 23 bit mantissa +
> 8 bit exponent,Representing numbers in the range +/- 1038
> Char[<len>] Len * 8 bit ASCII character string, most certainly
> terminated with the NUL character (=0)
> Int 32 bit 32 bit integer (2's complement)
> Multiple byte data types are stored with the least significant byte first.
> The whole header data structure: (size 892 bytes)
<< Header file details cut from message for brevity >>
<< Dave's script file <readflir.ijs> appears below >>
require 'files'
addon_path=: jpath '~addons\image3\'
load addon_path,'image3.ijs'
load addon_path,'view_m.ijs'
NB. read_fpf v reads FLIR Public Image Format
read_fpf=: 3 : 0
c4i =: _2 & (3!:4) NB. 4 char to integer
c2i =: _1 & (3!:4) NB. 2 char to int
c4f =: _1 & (3!:5) NB. 4 chars to float
dat=:freads y.
ids=: 120{.dat NB. image data structure
cds=: 360{. 120}. dat NB. camera data structure
ods=: 104{. 480}. dat NB. object parameter data structure
dds=: 92{. 584}. dat NB. date and time data structure
sds=: 88{. 676}. dat NB. scaling data structure
NB.=============================
NB. image data structure
NB.=============================
fpfid=: 32{. ids
version=: c4i 4{. 32}. ids
pixeloffset=: c4i 4{. 36}. ids NB. offset to image
imagetype=: c2i 2{. 40}. ids
pixelformat=: c2i 2{. 42}. ids
xSize=: c2i 2{. 44}. ids NB. number of columns
ySize=: c2i 2{. 46}. ids NB. number of rows
trigcount=: c4i 4{. 48}. ids
framecount=: c4i 4{. 52}. ids
NB.============================
NB. Camera Data Structure
NB. ===========================
cameratype=: 31{. cds
camerapartno=: 31{. 31}. cds
camerasn=: 31{. 62}. cds
lenstype=: 31{. 93}. cds
lenspartno=: 31{. 124}. cds
lenssn=: 31{. 155}. cds
filtertype=: 31{. 186}. cds
filterpartno=: 31{. 217}. cds
filtersn=: 31{. 248}. cds
NB.============================
NB. read image
NB.===========================
if. pixelformat=2 do.
NB. conv. 4 byte to float starting at 892, drop last char (LF)
i1=: (pixeloffset)}. dat
mod=: 4|$i1
if.(LF={:i1) do. i1=:}:i1 end. NB. desparate try to make it work
i2=:c4f i1
NB. i2=:c4f (xSize*ySize*4){.i1
NB. i2=:c4f(($i1)-4|$i1){.i1
img=: (ySize,xSize)$i2
end.
NB. img is passed as result
)
tt=: 3 : 0
view_data read_fpf fselect ''
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm