DIM Chunk%(5000) 'Graphics Workspace ... increase as necessary

PRINT "ConvIFF Test Reader"
PRINT "To read an ASCII block of DATA statements, MERGE the DATA block"
PRINT "   with this program, and press [Return] at the following prompt"
PRINT "To read a binary STRING of data, give the FileName of the stored"
PRINT "   graphics data."
PRINT "View successive Graphics Chunks (if one or more were appended to
PRINT "   the DATA-block/Binary-file) by pressing [Space].
PRINT :PRINT  

INPUT "FileName (Binary String), or press CR (Ascii)?";mode$

SCREEN 2,640,200,3,2
WINDOW 2,"",,0,2

IF mode$="" THEN
ALoop:
    READ siz%  'First value is the # of integers in the chunk
    FOR i%=0 TO siz%-1
      READ Chunk%(i%)
    NEXT
  
    PUT(100,20),Chunk%,PSET
    i$=INPUT$(1) 'Wait for key, then display next Chunk or give error
    GOTO ALoop
ELSE
    OPEN mode$ FOR INPUT AS 1
    lin$=INPUT$(LOF(1),1):CLOSE 1 'Read entire string into lin$
    p%=1 'Initialize pointer to first byte of string
    
    WHILE p%<LEN(lin$)
      ChunkLen%=CVI(MID$(lin$,p%,2)) 'Length of chunk in bytes
      p%=p%+2 'Advance pointer past length bytes into block area
      FOR i%=0 TO ChunkLen%/2-1
        Chunk%(i%)=CVI(MID$(lin$,p%+i%*2,2)) 'Read byte pairs as integers
      NEXT
      
      PUT(100,20),Chunk%,PSET
      i$=INPUT$(1) 'Wait for Key, then display next chunk
      p%=p%+ChunkLen% 'Adv ptr to next chunk area in string
    WEND
END IF
WINDOW CLOSE 2
SCREEN CLOSE 2
END
    

