An earlier approach to map C structs was 
the "Method of Named Fields", but it's maybe
not very efficient. See the task.ijs (open'task').

For working with binary structures, please see
the media/wav addon, wav.ijs, the wavhead verb.
It was used as a more contemporary approach and
proved to be very easy and reliable.

The idea is to overcome the complexity of the binary
structure with the deliberate simplicity of declarative
approach to defining the structures (what). As opposed
to direct use of low-level foreigns (how), which
confuse and mangle the structure with details.
This is especially reliable in conjunction with 
validation, as in wav. So working with binaries 
becomes almost as easy as with XML.

I am thinking to further generalize the approach and
simplify the interface, in the way pack/unpack work
in Perl (but also giving a level of direct verbs for each type).
There should be a set of parallel accessor sources:
string (noun), mapped file, memory address, disk file, 
stream, socket, etc. Should allow incremental reader/writer
like in wav.

I was wondering if someone already done it or at least
thought of such interface. It's important to come up
with a good compact yet expressive paradigm.


--- David Porter <[EMAIL PROTECTED]> wrote:

> (Still a newbie, but more knowledgeable than before)
> I am having trouble reading images from a only few files out of a series 
> of files.  The image file info is below. 
> 
> 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 following line is from the header file referred to above)
> 
> Float    32 bit    IEEE floating point number, sign + 23 bit mantissa + 
> 8 bit exponent,Representing numbers in the range +/- 1038
> 
> My code boils down to this:
>     c4f =: _1 & (3!:5)   NB. 4 chars to float
> 
>  
>     dat=:  freads  fn                      NB. reads the file
>     i1=:  (pixeloffset)}.  dat          NB. drop header
>     i2=:c4f {.i1                             NB. converts to float  
> 
> This seems to work on 43 files, but on the 44th file, I get a length 
> error.  Looking at i1, it is not mod 4.  When I either curtail it to be 
> mod 4 or pad it to be mod 4, it reads but the image looks like an old TV 
> with the horizontal hold mis-set. 
> 
> To add to the confusion, the viewing software from the vendor reads all 
> the files wonderfully.  So I am guessing I am doing something wrong.  
> Any suggestions?
> 
> Dave Porter
> 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 



      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to