POV-Ray : Newsgroups : povray.general : File I/O Server Time
27 Dec 2024 17:36:56 EST (-0500)
  File I/O (Message 1 to 8 of 8)  
From: pbrants
Subject: File I/O
Date: 17 Apr 2014 11:20:01
Message: <web.534ff08a911c57344e8159130@news.povray.org>
Here I am again!

#fopen MyFile "niks.txt" write
  #declare i=1;
  #while (i <= 5)
     #write (MyFile, i,",")
     #declare i=i+1;
     #end  // while
  #fclose Myfile

  #fopen MyFile "niks.txt" read    // Here parse error!
  #declare i=1;
  #while (i <= 5)
     #read (MyFile, i)
     #declare i=i+1;
     #end  // while
  #fclose Myfile

This piece of code gives a parse error on the indicated line:
Cannot read from file niks.txt because the file is open for writing only

What is wrong here?
I'm using Windows 7

Paul


Post a reply to this message

From: Le Forgeron
Subject: Re: File I/O
Date: 17 Apr 2014 11:54:13
Message: <534ff925$1@news.povray.org>
Le 17/04/2014 17:17, pbrants nous fit lire :
> Here I am again!
> 
> #fopen MyFile "niks.txt" write
>   #declare i=1;
>   #while (i <= 5)
>      #write (MyFile, i,",")
>      #declare i=i+1;
>      #end  // while
>   #fclose Myfile
> 
>   #fopen MyFile "niks.txt" read    // Here parse error!
>   #declare i=1;
>   #while (i <= 5)
>      #read (MyFile, i)
>      #declare i=i+1;
>      #end  // while
>   #fclose Myfile
> 
> This piece of code gives a parse error on the indicated line:
> Cannot read from file niks.txt because the file is open for writing only
> 
> What is wrong here?
> I'm using Windows 7


You closed Myfile, but opened MyFile. Typo! (Camel vs Pascal)


Post a reply to this message

From: Warp
Subject: Re: File I/O
Date: 17 Apr 2014 13:11:20
Message: <53500b38@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
> >   #fclose Myfile

> You closed Myfile, but opened MyFile. Typo! (Camel vs Pascal)

Which raises the question of why POV-Ray doesn't give an error if you
use #fclose with an undefined identifier.

-- 
                                                          - Warp


Post a reply to this message

From: pbrants
Subject: Re: File I/O
Date: 17 Apr 2014 18:10:00
Message: <web.53505012830820894e8159130@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
> Le 17/04/2014 17:17, pbrants nous fit lire :
> > Here I am again!
> >
> > #fopen MyFile "niks.txt" write
> >   #declare i=1;
> >   #while (i <= 5)
> >      #write (MyFile, i,",")
> >      #declare i=i+1;
> >      #end  // while
> >   #fclose Myfile
> >
> >   #fopen MyFile "niks.txt" read    // Here parse error!
> >   #declare i=1;
> >   #while (i <= 5)
> >      #read (MyFile, i)
> >      #declare i=i+1;
> >      #end  // while
> >   #fclose MyFile
> >
> > This piece of code gives a parse error on the indicated line:
> > Cannot read from file niks.txt because the file is open for writing only
> >
> > What is wrong here?
> > I'm using Windows 7
>
>
> You closed Myfile, but opened MyFile. Typo! (Camel vs Pascal)

Sorry, it was a typo indeed, but it gives the same error with the typo
corrected!

Paul


Post a reply to this message

From: pbrants
Subject: Re: File I/O
Date: 17 Apr 2014 18:20:01
Message: <web.53505324830820894e8159130@news.povray.org>
Sorry again, it was a typo in the original program, all works OK now!

Paul


Post a reply to this message

From: Ger
Subject: Re: File I/O
Date: 17 Apr 2014 18:21:22
Message: <535053e2@news.povray.org>
pbrants wrote:

> Le_Forgeron <jgr### [at] freefr> wrote:
>> Le 17/04/2014 17:17, pbrants nous fit lire :
>> > Here I am again!
>> >
>> > #fopen MyFile "niks.txt" write
>> >   #declare i=1;
>> >   #while (i <= 5)
>> >      #write (MyFile, i,",")
>> >      #declare i=i+1;
>> >      #end  // while
>> >   #fclose Myfile
>> >
>> >   #fopen MyFile "niks.txt" read    // Here parse error!
>> >   #declare i=1;
>> >   #while (i <= 5)
>> >      #read (MyFile, i)
>> >      #declare i=i+1;
>> >      #end  // while
>> >   #fclose MyFile
>> >
>> > This piece of code gives a parse error on the indicated line:
>> > Cannot read from file niks.txt because the file is open for writing
>> > only
>> >
>> > What is wrong here?
>> > I'm using Windows 7
>>
>>
>> You closed Myfile, but opened MyFile. Typo! (Camel vs Pascal)
> 
> Sorry, it was a typo indeed, but it gives the same error with the typo
> corrected!
> 
> Paul
What is the content of niks.txt if you open it in text editor?
-- 

Ger


Post a reply to this message

From: Kenneth
Subject: Re: File I/O
Date: 17 Apr 2014 22:20:01
Message: <web.53508a8983082089c2d977c20@news.povray.org>
"pbrants" <pbr### [at] telenetbe> wrote:
> Le_Forgeron <jgr### [at] freefr> wrote:

> >
> > You closed Myfile, but opened MyFile. Typo! (Camel vs Pascal)
>
> Sorry, it was a typo indeed, but it gives the same error with the typo
> corrected!
>
> Paul

> Sorry again, it was a typo in the original program, all works OK now!

I didn't see that typo for about half an hour(!), while playing with your code.
Prior to noticing it, I was trying everything under the Sun-- eventually
re-writing your code verbatim. I was just getting ready to post the same
'solution.' ;-)

BTW, the #write and #read blocks can have *different* 'file handle identifiers'
and still work OK (I've never seen any problems when doing so.)

#fopen ABC "niks.txt" write
#write(ABC, ... )
#fclose ABC

#fopen XYZ "niks.txt" read
#read(XYZ, ...)
#fclose XYZ


Post a reply to this message

From: Thomas de Groot
Subject: Re: File I/O
Date: 18 Apr 2014 03:17:41
Message: <5350d195$1@news.povray.org>
On 18-4-2014 0:05, pbrants wrote:
> Le_Forgeron <jgr### [at] freefr> wrote:
>> Le 17/04/2014 17:17, pbrants nous fit lire :
>>> Here I am again!
>>>
>>> #fopen MyFile "niks.txt" write
>>>    #declare i=1;
>>>    #while (i <= 5)
>>>       #write (MyFile, i,",")
>>>       #declare i=i+1;
>>>       #end  // while
>>>    #fclose Myfile
>>>

>>>
>>> This piece of code gives a parse error on the indicated line:
>>> Cannot read from file niks.txt because the file is open for writing only
>>>
>>> What is wrong here?
>>> I'm using Windows 7
>>
>>
>> You closed Myfile, but opened MyFile. Typo! (Camel vs Pascal)
>
> Sorry, it was a typo indeed, but it gives the same error with the typo
> corrected!

IF I read your code above, you corrected the typo in the #read but not 
in the #write section...

As a side note, be aware that in your #read section, you use the 
parameter i for two different things at the same time. Except if 
intended, you may get strange results. An alternative would be:

#fopen MyFile "niks.txt" read    // Here parse error!
#while (defined (MyFile))
   #read (MyFile, i)
   do here what you want to do with i
#end  // while
#fclose MyFile


Thomas


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.