Re: Sequences

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Sun, 8 Nov 1998 20:07:26 -0600, Jim Roberts <jhroberts1 at JUNO.COM> wrote:

>In EUPHORIA I read a file that was written in FORTRAN and it has the
>following format:
>
>  4I4
>
>A record might look like this where "b" is considered to be a blank.
>
>  bbb0bbb0bbb0bbb0
>
>     or
>
>   bb23b112bb34bb23
>
>    or
>
>  b103bb58bbb6bb23
>
>I can go thru each record checking for blanks and probably convert the
>numeric values but I have not found an easy way.  When I look at each
>record in a sequence statement all four characters are in a group. There
>has got to be a simple way to convert each 4 character field to an
>integer.  It is my understanding that a dimension statement does not
>exist in EUPHORIA.  Is this true?  The reason I ask is that as I unpack
>each 4 characrter numbers in each record I would like to place it in a
>buffer where I can use it as an integer for later calculations.
>
>I guess I can place them back in a sequence to do all of my calculations.
>
>If someone will help me with this simple problem I would be very
>appreciative as I am still trying to convert a simple QB program to a
>EUPHORIA program!
>
>Thanks,
>Jim Roberts
Here's my test file:
   1   2   3   4
  12  13  14  15
 110 111 112 112
4321432243234324

Here's tested (TESTED!) code:
include get.e -- for value function
object input
sequence n,nums
atom fn


fn = open("test.dat","r")
nums = {}
while 1 do
   input = gets(fn)
   if atom(input) then exit -- bye bye at eof
   elsif length(input) < 16 then exit -- or a blank line, whichever

   else
   puts(1,"Line in:" & input) -- show me what you've got
   for i = 1 to 16 by 4 do    -- for each field
       n = value(input[i..i+3]) -- convert from string to #
       nums = append(nums,n[2]) -- stick the # onto end of sequence
   end for
   end if
   puts(1,"Converted:") ? nums
end while

Regards,
Irv

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu