1. correction

actually, i inadvertently ommited the comma's in my example.  The fileds ARE
comma separated values.

thx

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » topic index » view message » categorize

2. Re: correction

--Boundary_(ID_KiJ+tHyRzyD2CXScp2jMrg)
Content-type: text/plain; charset=iso-8859-1


----- Original Message -----
From: Steven G Astley <sgastley at HOTMAIL.COM>

Subject: correction


> actually, i inadvertently ommited the comma's in my example.  The fileds
ARE
> comma separated values.

Attached is a small program that can read files like the following, with or
without
quotes or commas, and massage the data..
---
991012,21.22, 23.34, 33.56, 32.23, 54321, 12345, 322 -- extraneous data
991013, "12.34"  34.44,  "3.1415pi",  14.00,  43211, 23  -- different
formatting
991015, 24.44,  32.33,  22.22,  33.45, 325,     23.3,4235,2343,5223
---
The only thing it throws up on is any unquoted text. i.e. 32.33rx won't fly.
Quoted text which can't be converted into a number will be considered zero.

Hope that helps.
Irv


--Boundary_(ID_KiJ+tHyRzyD2CXScp2jMrg)
Content-type: application/octet-stream; name=test.ex


include get.e
without warning
with trace
trace(1) -- set trace to 1 to step thru the program

constant Date = 1, Open = 2, Hi = 3, Lo = 4, Last = 5, Oi = 6, Vol = 7
atom file
object data
sequence array, average

file = open("test.dat","r")
array = {}

---------------------
procedure skiptoEOL() -- in case some lines contain extraneous data
---------------------
object c
 c = ' '
 while c != 10 do
    c = getc(file)
 end while
end procedure

---------------------
function readrecord() -- read a line of data
---------------------
object item, record
record = repeat(0,Vol)
for i = 1 to length(record) do
    item = get(file)
    if item[1] = GET_SUCCESS then                 -- valid read
        if atom(item[2]) then record[i] = item[2] -- valid numeric
        else item = value(item[2])                -- quoted numeric
             record[i] = item[2]
        end if
    else return -1
    end if
end for
skiptoEOL()
return record
end function

--------------------
procedure readfile() -- read the file
--------------------
while 1 do
 data = readrecord()
 if atom(data) then exit -- EOF or bad data encountered!
 else array = append(array,data)
 end if
end while
end procedure

---------------------------
function sum(sequence data) -- totals each column separately
---------------------------
sequence tmp
 tmp = repeat(0,length(data[1]))
 for i = 1 to length(data) do
     tmp += data[i]
 end for
 return tmp
end function

---------------------------
function avg(sequence data) -- compute averages
---------------------------
  return sum(data) / length(data)
end function

-------------------------------
-- MAIN
-------------------------------
readfile()

for j = 1 to length(array) do
printf(1,"The values read for %d are: HI:%8.2f LO:%8.2f VOL:%d\n",
         {array[j][Date],array[j][Hi],array[j][Lo],array[j][Vol]})
end for

average = avg(array)
printf(1,"%s\n",{repeat('=',65)})
printf(1,"Averages:                       HI:%8.2f LO:%8.2f VOL:%d\n",
                           {average[Hi],average[Lo],average[Vol]})





--Boundary_(ID_KiJ+tHyRzyD2CXScp2jMrg)--

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu