POV-Ray : Newsgroups : povray.general : #read problems Server Time
24 Nov 2024 13:41:41 EST (-0500)
  #read problems (Message 1 to 10 of 10)  
From: Kenneth
Subject: #read problems
Date: 1 Oct 2018 05:10:00
Message: <web.5bb1e30d2a04246ea47873e10@news.povray.org>
I haven't used the #write/#read directives in quite a while, and I'm now having
a *basic* problem with the #read directive that's driving me crazy. (I'm running
3.7.1 beta 9 in Windows, BTW)

#declare AAA = <1,2,3>;

To write this to a new file:
#fopen FOOBAR "my file.txt" write
#write(FOOBAR, AAA)
#fclose FOOBAR

This successfully writes
<1,2,3>
to the file, on the first line. So far, so good.

During a later POV-Ray session, I want to read the file back into the same
scene, so I do this:

object{MY_OBJ
rotate
#fopen FOOBAR "my_file.txt" read
#read(FOOBAR,AAA)
#fclose // or this line can be commented-out
}

......but "my_file.txt" is *completely* ignored, as is the entire #fopen
construct. The fatal error message says, "Expected numeric expression, } found
instead", due to the rotate keyword apparently having nothing following it.

REMOVING the   rotate   keyword, but leaving the #fopen block intact, the scene
renders OK(!)-- but that seems quite strange: it's again as if the code block is
non-existent or invisible, when it should be throwing a fatal error.

I also tried this as a preliminary step:
#declare XYZ =
#fopen FOOBAR "my_file.txt" read
#read(FOOBAR,AAA)
; // semi-colon here...
#fclose // or this line can be commented-out
; // ... OR here; no change

...... but this produces its own (similar) fatal error, again as if the code
doesn't exist: "Expected Rvalue to declare, ; found instead"

So, what *basic thing* am I doing wrong?? I'm quite frustrated at this point.


Post a reply to this message

From: jr
Subject: Re: #read problems
Date: 1 Oct 2018 06:30:04
Message: <web.5bb1f70777bafccb0d4fc1e0@news.povray.org>
hi,

"Kenneth" <kdw### [at] gmailcom> wrote:
> I haven't used the #write/#read directives in quite a while, and I'm now having
> a *basic* problem with the #read directive that's driving me crazy. (I'm running
> 3.7.1 beta 9 in Windows, BTW)

doing:

#read (FP, AAA)
rotate AAA

should work.  (tried with debug concat, on v.3.8.0 alpha)


regards, jr.


Post a reply to this message

From: clipka
Subject: Re: #read problems
Date: 1 Oct 2018 09:44:00
Message: <5bb224a0@news.povray.org>
Am 01.10.2018 um 11:09 schrieb Kenneth:

> During a later POV-Ray session, I want to read the file back into the same
> scene, so I do this:
> 
> object{MY_OBJ
> rotate
> #fopen FOOBAR "my_file.txt" read
> #read(FOOBAR,AAA)
> #fclose // or this line can be commented-out
> }
> 
> .......but "my_file.txt" is *completely* ignored, as is the entire #fopen
> construct. The fatal error message says, "Expected numeric expression, } found
> instead", due to the rotate keyword apparently having nothing following it.

Heh! You're being fooled by the error message.

POV-Ray isn't complaining about a missing parameter for `rotate`, it is
complaining about a missing parameter for `#fclose`".

You need to specify which file you want to close (you can have multiple
open at the same time):

    #fclose FOOBAR

(Also, you then need to actually /use/ `AAA`, othjerwise POV-Ray /will/
complain about a missing parameter for `rotate`.)


Post a reply to this message

From: Kenneth
Subject: Re: #read problems
Date: 1 Oct 2018 14:55:01
Message: <web.5bb26c4777bafcca47873e10@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

>
> doing:
>
> #read (FP, AAA)
> rotate AAA
>
> should work.  (tried with debug concat, on v.3.8.0 alpha)
>

Thanks! It does indeed.

My own proper syntax is now:
object{MY_OBJ
#fopen FOOBAR "my_file.txt" read
#read(FOOBAR,AAA)
#fclose FOOBAR
rotate AAA
}

(Actually, the #fopen block could go *anywhere* in the scene code prior to AAA
being used.)

But this *proper* syntax didn't occur to me, for a reason (even though the
documentation at #read DOES include a #while-loop version of it): With the
#fclose FOOBAR command present, it *appears* that the AAA vector is only "here
and gone in a flash",  before the rotate command even has a chance to use it!
Not true, of course, but that's how the 'linear' nature of the code looks to me,
during the parsing stage. It's not obvious that AAA 'hangs around' or remains in
memory(?) after the txt file is closed. (There's no actual #declare or #local
anywhere.)

BTW, this also works OK:
#fopen FOOBAR "my_file.txt" read
#read(FOOBAR,AAA)
rotate AAA
#fclose FOOBAR


Post a reply to this message

From: Kenneth
Subject: Re: #read problems
Date: 1 Oct 2018 15:20:02
Message: <web.5bb2727677bafcca47873e10@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

>
> POV-Ray isn't complaining about a missing parameter for `rotate`, it is
> complaining about a missing parameter for `#fclose`".
>
> You need to specify which file you want to close (you can have multiple
> open at the same time):
>
>     #fclose FOOBAR
>

Geez, I apologize: That was my NEWSGROUP syntax error :-/  My real code included
#fclose FOOBAR. (At the time of writing my original post, I was so confused and
frustrated that I was about to toss my machine out the nearest window!!)

I'm curious about something: What is the actual problem when trying to do...

object{MY_OBJ
rotate
#fopen FOOBAR "my_file.txt" read
#read(FOOBAR,AAA)
#fclose FOOBAR // or this line can be commented-out, with no change
}

At first glance, this *looks* like it should be simple substitution of the
#written AAA vector into 'rotate' (kind of like the behavior of a macro.) But
this is the situation where the #fopen block appears to be 'invisible' to the
scene code, along with one of the fatal error messages. I'm not yet 'seeing' the
reason for its failure.

[Kenneth wrote:]
> REMOVING the   rotate   keyword, but leaving the #fopen block intact, the
> scene renders OK(!)-- but that seems quite strange: it's again as if the
> code block is non-existent or invisible, when it should be throwing a
> fatal error.

THIS is still a mystery to me-- why it's not throwing an error. But... I'm
beginning to see that the #fopen block itself is just 'idle code', sitting there
in limbo, doing nothing in particular... until AAA is actually used. My guess??

-----
I don't wish to complain TOO much about the documentation at #read, but...

IMO, the original author assumed a level of C or C++ knowledge (or some other
language) on the part of the user, as to the rules and usage of #write/#read.
(Maybe that *was* the case way back when, when the 'typical' POV-user was
probably a computer programmer.) But some useful, basic(?) info has been left
out (yes, 'spoon-feeding', ha.) I remember being similarly stuck and frustrated
years ago, when I first tried using these in POV-ray. That's unfortunate,
because #write and #read are really powerful tools. It would SO nice not to have
to initially run dead-end experiments, simply to arrive at some working code.


Post a reply to this message

From: clipka
Subject: Re: #read problems
Date: 1 Oct 2018 16:41:42
Message: <5bb28686$1@news.povray.org>
Am 01.10.2018 um 21:16 schrieb Kenneth:

> I'm curious about something: What is the actual problem when trying to do...
> 
> object{MY_OBJ
> rotate
> #fopen FOOBAR "my_file.txt" read
> #read(FOOBAR,AAA)
> #fclose FOOBAR // or this line can be commented-out, with no change
> }
> 
> At first glance, this *looks* like it should be simple substitution of the
> #written AAA vector into 'rotate' (kind of like the behavior of a macro.) But
> this is the situation where the #fopen block appears to be 'invisible' to the
> scene code, along with one of the fatal error messages. I'm not yet 'seeing' the
> reason for its failure.

It's pretty simple: `#read(FOOBAR,AAA)` is not a function that
/evaluates to/ the value read from the file; it is an instruction (or
directive) that /sets/ `AAA` to the value read. It's pretty much a
`#declare` on steroids.

So when all is said and done, the whole construct presents itself to the
final parser stage as:

    object{MY_OBJ
    rotate
    }

The solution is to change the construct to:

    object{MY_OBJ
    rotate
    #fopen FOOBAR "my_file.txt" read
    #read(FOOBAR,AAA)
    #fclose FOOBAR // or this line can be commented-out, with no change
    AAA      // <-- !!!!
    }

With that change, it eventually presents itself as:

    object{MY_OBJ
    rotate
    _VALUE_READ_FROM_FILE_
    }

> IMO, the original author assumed a level of C or C++ knowledge (or some other
> language) on the part of the user, as to the rules and usage of #write/#read.
> (Maybe that *was* the case way back when, when the 'typical' POV-user was
> probably a computer programmer.) But some useful, basic(?) info has been left
> out (yes, 'spoon-feeding', ha.) I remember being similarly stuck and frustrated
> years ago, when I first tried using these in POV-ray. That's unfortunate,
> because #write and #read are really powerful tools. It would SO nice not to have
> to initially run dead-end experiments, simply to arrive at some working code.

I think I'm getting a feel for where your misunderstanding is coming
from, and yes, I agree that the docs do nothing to get you off that
track and onto the right one.


Post a reply to this message

From: jr
Subject: Re: #read problems
Date: 1 Oct 2018 16:45:00
Message: <web.5bb2866877bafccb0d4fc1e0@news.povray.org>
hi,

"Kenneth" <kdw### [at] gmailcom> wrote:
> "jr" <cre### [at] gmailcom> wrote:
> > should work.  (tried with debug concat, on v.3.8.0 alpha)
> Thanks! It does indeed.
> My own proper syntax is now:
> object{MY_OBJ
> #fopen FOOBAR "my_file.txt" read
> #read(FOOBAR,AAA)
> #fclose FOOBAR
> rotate AAA
> }

fwiw, I'd write:

#fopen FOOBAR "my_file.txt" read
#read(FOOBAR,AAA)
#fclose FOOBAR
object{MY_OBJ rotate AAA}

no functional difference/reason.

> ... It's not obvious that AAA 'hangs around' or remains in memory(?)
> after the txt file is closed. (There's no actual #declare or #local
> anywhere.)

try the above.  (intruding on clipka's territory here) think of the
(re-)"#declare" of 'AAA' happening "inside" the #read.

(now you've got me using quotes too..  ;-))


regards, jr.


Post a reply to this message

From: Kenneth
Subject: Re: #read problems
Date: 1 Oct 2018 17:45:00
Message: <web.5bb2948377bafcca47873e10@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
[Kenneth wrote:]
>
> > ... It's not obvious that AAA 'hangs around' or remains in memory(?)
> > after the txt file is closed. (There's no actual #declare or #local
> > anywhere.)
>
> try the above.  (intruding on clipka's territory here) think of the
> (re-)"#declare" of 'AAA' happening "inside" the #read.
>

Yeah; you (and Clipka) will be happy to know that I came to that very same
conclusion, after only 24-hours of really hard thinking! :-[  #Read is 'kind of
like' #declare. Duh.

(IMO: One more little nugget of info to add to the #read documentation.)


Post a reply to this message

From: clipka
Subject: Re: #read problems
Date: 1 Oct 2018 21:47:53
Message: <5bb2ce49$1@news.povray.org>
Am 01.10.2018 um 22:41 schrieb jr:

> try the above.  (intruding on clipka's territory here) think of the
> (re-)"#declare" of 'AAA' happening "inside" the #read.

Tsk, tsk - how /dare/ you try explaining the same stuff in different
words; that might run the risk of increasing the chances that Kenneth
might grok it ;)


Post a reply to this message

From: jr
Subject: Re: #read problems
Date: 2 Oct 2018 14:15:00
Message: <web.5bb3b52477bafccb0d4fc1e0@news.povray.org>
hi,

clipka <ano### [at] anonymousorg> wrote:
> Am 01.10.2018 um 22:41 schrieb jr:
>
> > try the above.  (intruding on clipka's territory here) think of the
> > (re-)"#declare" of 'AAA' happening "inside" the #read.
>
> Tsk, tsk - how /dare/ you try explaining the same stuff in different
> words; that might run the risk of increasing the chances that Kenneth
> might grok it ;)

anything to prevent *that* from happening.  :-)


Post a reply to this message

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