%include "inc:util.imp"
{}%include "fractl:iff.inc"
!Brian - JHB has been here.  IFF routines are now in FRACTL:IFF.INC.
!I've commented out your stuff (!!) and commented mine ({})
%begin

%string(255) file,bumph,outfile
%string(255) seeornot

!!%recordformat strings (%short hlen,type,ht,wid,
!!                     %shortarray(0:8) junk,%bytearray(0:15) dattim,
!!                     %integer junk2, %byte magic1,magic2,
!!                     %bytearray(0:254) title)
!!
!!%recordformat blah (%bytearray(0:16_1ff) header %or %record (strings) hed)
!!%record(blah) the header
{}%record (iffhdr fm) iffhdr

%bytearray(0:511,0:511) image
%string(255) name
%short height,width
%integer i,loop,sym,x,y
%label close

%onevent 9 %start
   selectoutput(1)
   closeoutput
   selectoutput(0) 
   newline
   printline("What's goin' on here?!")
   %stop
%finish

file=cliparam
%if file = "" %start
  %cycle
    prompt("Inputfilename: ")
    readline(file)
  %repeat %until file # ""
%finish

prompt("Outputfile? ")
readline(outfile)
prompt ("Picture width? " )
read(width)
prompt ("Picture height? " )
read (height)
readline(seeornot)
prompt("Is this a seescan picture (Y/N)")
readline(seeornot)

!!%for i=0,1,16_1ff %cycle { Clear header to zeroes }
!!  the header_header(i) = 0
!!%repeat
 
!!%for i=1,1,length(datetime) %cycle
!!  the header_hed_dattim(i-1) = charno(datetime,i)
!!%repeat
!!%for i=1,1,length(file) %cycle
!!  the header_hed_title(i-1)  = charno(file,i)
!!%repeat
!!the header_hed_magic1 = 16_85
!!the header_hed_magic2 = 16_16
!!the header_hed_hlen  = 256
!!the header_hed_type  = 0
!!the header_hed_ht    = height   
!!the header_hed_wid   = width

{}iffhdr = 0
{}iffhdr_title = "Microneye - ".file
{}iffhdr_ht    = height
{}iffhdr_wid   = width
{}iffhdr_focus = 16  ;!16mm lens
{}iffhdr_fstop = 140 ;!f/1.4     (both opticram and seescan are 16mm f/1.4

printline("Reading ".file)

openinput(1,file); selectinput(1)
openoutput(1,outfile); select output(1)

{}iff write header(iffhdr)
!!%for i=0,1,16_1ff %cycle
!!  printsymbol(the header_header(i))
!!%repeat


%for y=0,1,height-1 %cycle
  %for x=0,1,width-1 %cycle
    readsymbol(sym)
    image(x,y)=sym
  %repeat
%repeat

close: 
closeinput
selectinput(0)

!Turn image upside-down
i=0
  
selectoutput(0)
printline("Writing ".outfile)
selectoutput(1)

%if seeornot = "N" %start
    %for y=height-1,-1,0 %cycle
    %for x=0,1,width-1 %cycle
      sym=image(x,y)
      sym=sym*8
      %if i>255 %then printsymbol(sym)
      i=i+1
    %repeat
  %repeat
%else
    %for y=0,1,height-1 %cycle
    %for x=0,1,width-1 %cycle
      printsymbol(image(x,y))
    %repeat
  %repeat
%finish
    
closeoutput
selectoutput(0)

%endofprogram
