reading Pokeys pins

C Scripting questions and answers
gburk
Site Admin
Posts: 324
Joined: Mon Nov 26, 2018 2:57 am

Re: reading Pokeys pins

Post by gburk »

Art

One problem on large files it seems to read the EOF before its read the whole file at least it exits the loop and stops printing

small files its good, don't see any errors popping up is there a buffer limit to a table ?..

Gary
ArtF
Global Moderator
Global Moderator
Posts: 4557
Joined: Sun Sep 05, 2010 5:14 pm
Contact:

Re: reading Pokeys pins

Post by ArtF »

Gary:

Im sure a limit may exist, but I dont think in this case, unless one line gets too
large it shouldnt run into memory problems.

  Your routine will skip the first line though... Id suggest the following change.
I might add the the null check may not be necessary as the print routine shouldn't
fail on a print(null) and it is possible for readline to return null without being at
the end of a file.

line = 0;
next_line[line] = myfile.ReadLine();
while (next_line[line] != EOF)
  {
    print(next_line[line]);
    line = line + 1;
    next_line[line] = myfile.ReadLine();
    if (next_line[line] == null)
    {
      print("Null line found before end of file"); //can be ignored in many cases..
      exit();
    }
  };

Art
]
gburk
Site Admin
Posts: 324
Joined: Mon Nov 26, 2018 2:57 am

Re: reading Pokeys pins

Post by gburk »

Art

I gave it a try same results, it seems its reading the end of file early...
It printed part of the file then quit, I assume it thought it read EOF, because it didn't print the null line..

it seems to run for a few second before it starts to print, I have no delays in there.. do you think its looping faster that it can print to screen..?

I will try looping with no print just storing the text lines in the table then print out the table in a loop worth a try..

Gary
ArtF
Global Moderator
Global Moderator
Posts: 4557
Joined: Sun Sep 05, 2010 5:14 pm
Contact:

Re: reading Pokeys pins

Post by ArtF »

Gary:

There shouldnt be any buffer limit for the file, but the table may have a
line limit. Try replacing the same table line each time and see if it reads
the entire file. Im not sure the error, I havent played with files much, just
scripting tests early on for putting out point clouds and such.

Art
gburk
Site Admin
Posts: 324
Joined: Mon Nov 26, 2018 2:57 am

Re: reading Pokeys pins

Post by gburk »

Art

Will give that a shot, I added line numbers to the print, one file reaches line 48 before it thinks it is reading a null and the other file stopped at line 46 before nulling out of the loop..

so could be table does have a limit and one file has more char's per line than the other so reads a couple more lines..

tried printing the file and only using a var next_line no table clearing the var each loop but did the same thing..
I wouldn't think there is some sort of looping limit going on?. just a thought

Update I have tried a few different txt files now and seems to make it to line 50 then exits the loop no print output so its not getting  the null check just quits looping at or just under 50 lines of text..

Thanks gary
Last edited by gburk on Wed Jul 24, 2019 8:27 pm, edited 1 time in total.
gburk
Site Admin
Posts: 324
Joined: Mon Nov 26, 2018 2:57 am

Re: reading Pokeys pins

Post by gburk »

Art

I tried a loop that should loop 200 times and reading the file but it seems after 50 line read it exits the loop it doesn't print any of my messages like it hit a null or EOF or file closed just exits the loop.. here is a sample..

global next_line = table();
fileload = function()
{
myfile = system.File();
myfile.Open("*");
line = 0;
next_line[line] = myfile.ReadLine();
dowhile (line !=200)
  {
    print("Line # "+line+"  "+next_line[line]);
    line = line + 1;
    next_line[line] = myfile.ReadLine();
    if (next_line[line] == EOF)
    {
      print("EOF Reached");
      myfile.Close();
      print("File Closed");
      return;
    }
    if (next_line[line] == null)
    {
      print("Line = Null");
      myfile.Close();
      print("File Closed");
      exit();
    }
  };
myfile.Close();
print("File Closed");
};

fileload();

this script also only print 49 or 50 lines

x = 0;
dowhile( x < 400)
{
x = x + 1;
print("X = "+x);
};

gary
Last edited by gburk on Fri Jul 26, 2019 12:29 am, edited 1 time in total.
gburk
Site Admin
Posts: 324
Joined: Mon Nov 26, 2018 2:57 am

Re: reading Pokeys pins

Post by gburk »

Art

I removed the print during the loops, and only printed the last line read and line number when exiting the loop.
Its seems to finish looping this way, so it does seem that the print() is doing something to the loops if printing every line in the loop..
then it doesn't finish the loop or give an error either..

but read a 5000 plus line file not printing the lines only printed the last line on exit of the loop and it printed line 5082..



Gary
Amazon [Bot]
Full Member
Full Member
Posts: 185
Joined: Tue Jan 06, 2026 4:56 pm

Re: reading Pokeys pins

Post by Amazon [Bot] »

have you tried a
sleep(.04); //of some micro second
after or before a line read?
sounds like reading of the file or printing is causing a buffer spooling/overload/limit of some kind.

I believe Art is off cruising on vacation.

gburk
Site Admin
Posts: 324
Joined: Mon Nov 26, 2018 2:57 am

Re: reading Pokeys pins

Post by gburk »

Ya-Nvr-No

Thanks that seemed to fix it I thought there was a buffer problem but had no errors, I wouldn't use the print while loading a file normally but was testing to make sure the entire file was loaded, and it is..

Thanks gary
ArtF
Global Moderator
Global Moderator
Posts: 4557
Joined: Sun Sep 05, 2010 5:14 pm
Contact:

Re: reading Pokeys pins

Post by ArtF »

Hi Gary:

&nbsp; Sorry I missed that one, luckily YaNvrNo was around, he knows Auggie
pretty much as well as I and somewhat better in scripting. He was instrumental
in its development. Im deep into serious math learning for an upcoming (perhaps)
module Im writing so Im a bit intermittant. When the math gets too deep
for me I tend to lose track and hadnt checked in a few days to see how this
thread was doing (for some reason it no longer sends me notifications on this
thread.).

&nbsp; Glad the fix helped, probably the print buffer was filled and waiting for a sleep or
yield to get time to finish its work.

Art
Post Reply