Menu

#66 problem reading sequential file

open
nobody
None
5
2012-12-29
2005-09-28
Peter Ottis
No

I used to exchanxe globals between various M systems
using my own %GIO utility.This utility guarantees correct
global transfer also in case when they have control
characters in indexes and /or nodes.
It uses a simple method used now mostly in tcp/ip data
tranfer:

<byte1><byte2>string1
<byte3><byte4>string2

where byte1,byte2 are binary data expressing the length of
string1

I use the following code to get the string1 and string2, then
set @string1=string2 does the rest.

READ ;
N BYTE1,BYTE2,VAL1,VAL2,LNG
S EOF=0 U FILE R BYTE1#1,BYTE2#1 S VAL1=$A
(BYTE1),VAL2=$A(BYTE2)
I VAL1=255,VAL2=255 S EOF=1 S RETVAL="" Q ;END
OF GLOBAL OR END OF FILE INDICATED
I VAL1=0,VAL2=0 S RETVAL="" Q ;EMPTY STRING
S LNG=VAL1*256+VAL2 U FILE R RETVAL#LNG
Q

My problem: this code doesn't work with GT.M.

Sometime I'm getting negative values in VAL1 or VAL2 (-
1), and READ VAR#LNG randomly returns

strings of other lenght than LNG.

As open parameters I use the following:
O FILE:(noreadonly:block=2048:record=2044:exception="g
noopen"):0

Maybe using parameters like TERMINATOR="", or
PASTHRU in the OPEN statement would solve the problem,
but they are not implemented.

Please let me know, if you need more detailed input to
understand my problem.
TIA
Peter

Discussion

  • Vinaya Revannaswamy

    Logged In: YES
    user_id=97924

    Could you please provide us a sample input file that
    demonstrates the failure. We will use it to run through your
    M code and see what might be returning -1. What are the
    terminator(s) for lines in the extract file? Was the
    exception triggered due to a failure of READ. Was End Of
    File reached - GT.M sets $ZEOF when end of file is reached.
    You may want to revise your M code to check for $ZEOF after
    each READ. Oh! what version of GT.M did you encounter this
    problem with, and which flavor of Linux?

    Thanks,
    Vinaya

     
  • Vinaya Revannaswamy

    Logged In: YES
    user_id=97924

    The default record format is VAR (variable). Please use
    FIX:NOWRAP device parameters to see if the problem
    disappears. The default recordsize/width is 32767 which
    should be fine for a two byte length.

    Thanks,
    Vinaya

     
  • Peter Ottis

    Peter Ottis - 2005-10-19

    Logged In: YES
    user_id=964483

    I will rephrase my question:

    In GT.M I am missing a open parameter for sequential files that
    will allow me to read the file in chunks : i.e. READ var#512

    Then, regardless if a CR or LF occurs in the record, the variable
    will be filled with 512 bytes (exception: last read may end with
    less than 512 characters).

    This feature is called as open a file in IMAGE mode, or BINARY,
    or could be achieved by setting the parameter TERMINATOR=""
    to nil.
    Thanks
    Peter

     
  • Steven Estes

    Steven Estes - 2005-10-19

    Logged In: YES
    user_id=97877

    GT.M does not have an "image" mode per se. But you can
    get the same effect as follows:

    Open "some.file":(Fixed:RecordSize=512:BlockSize=512)
    Use "some.file"
    Read chunk#512

    This technique is used in both GDE and the GTM V5 block
    upgrade utility V5CBSU.

    Hopefully this helps.

     

Log in to post a comment.