Page 2 of 3

Re: naugty problem with for next in grid calculations

Posted: Fri Feb 25, 2022 5:11 pm
by STARGĂ…TE
From the picture it looks like, the points (puntx() and punty()) are 0 in some cases.
This means, the "If antw$ = "j"" block is not evaluated.

Can you explain, what is the reason to add 0.00005 or 0.00006 or 0.00001 to w(i,j)?
The numbers look arbitrarily.

Code: Select all

         If contourlijn=w(i,j)
            w(i,j)=w(i,j)+0.00001
          EndIf
          If contourlijn=w(i+1,j) 
            w(i+1,j)=w(i+1,j)+0.00002
          EndIf
And after this evaluation the matrix w(i,j) is changed and is not reset. This means, when you plot contourlijn = 80 and then contourlijn = 81 and back to contourlijn = 80, it has not the same values! I think here is the issue.

Re: naugty problem with for next in grid calculations

Posted: Fri Feb 25, 2022 7:47 pm
by wimapon
Hi Stargate,
thank you very much.
You have here a point.
I have to look for this...

as i remember from 30 years ago, i got problems when a contourline had the same value as a gridnode.
therefore i added a very small amount to it.
but when i start the program again, the grid is coming from a file... and this file is not changed..


But, i hope this will solve the problem....

I will go working on it.

please stand by

Wim

Re: naugty problem with for next in grid calculations

Posted: Fri Feb 25, 2022 8:08 pm
by wimapon
Hi startgate,
Deleting this lines does not change the problem.

To me it is impossible what is happening:

the program (above) runs nice. ( first figure above)
then i instert the "for contourlijn = 80 to 81" and at the end "next contourlijn"
and i delete " contourlijn = 80"
then the program gives the zero's....

then i make the program the same as the program ( above) , thus deleting the line " for contourlijn etc) "
the output is still with the zero's.... and in every program start the grid data is coming from a file.. so is exactly the same

To me that is impossible.... maybe in purebasic happens something i can not see.....

What do you think?

Wim

Re: naugty problem with for next in grid calculations

Posted: Fri Feb 25, 2022 11:12 pm
by breeze4me
I think it seems to be a problem caused by mixing integer and double types.
Try to assign the value of the variable "contourlijn" to the double type variable.

Code: Select all

;For contourlijn = 80 To 81 
contourlijn = 80

temp_contourlijn.d = contourlijn    ;  <------
; Replace all of the following "contourlijn" variables with "temp_contourlijn".



For j = 0 To 9    
  For i = 0 To 9 
    ;Even alle variabelen weer op 0 zetten
    For i2=0 To 4
      
      ......
      ......
      ......
      
      ; doe iets als een waarde van een gridpunt precies hetzelfde is als de contourlijn
      If temp_contourlijn =w(i,j)
        w(i,j)=w(i,j)+0.00001
      EndIf
      If temp_contourlijn =w(i+1,j) 
        w(i+1,j)=w(i+1,j)+0.00002
      EndIf
      
      
      If temp_contourlijn > w(i,j) And temp_contourlijn < w(i+1,j)
        antw$ = "j"
      EndIf
      If temp_contourlijn < w(i,j) And temp_contourlijn > w(i+1,j)
        antw$ = "j"
      EndIf
      
      
      If antw$ = "j"   ; de contourlijn cuts the base of the gridcell
                       ; bereken het snijpunt.
        afstand.d = (temp_contourlijn -w(i,j) ) / (w(i+1,j) - w(i,j))   
        px = i + afstand
        py = j
        tel = tel + 1
        puntx(tel) = px
        punty(tel) = py
        
        ; plot dit punt
        x = puntx(tel)
        y = punty(tel)
        
        verschaal()
        Circle(xw,yw,5,RGB(255,255,0))   ; geel  
        
      EndIf 
      
      ......
      ......
      

Re: naugty problem with for next in grid calculations

Posted: Fri Feb 25, 2022 11:33 pm
by wimapon
Hi Breeze4me,
Yes that solves the problem a bit.
if i made the variable contourlijn to double, the program works nice for one contourline.
If i made it integer it gives the zero's.

But with the double the program will not compile with: an integer assignment is expected after for.

so what i have to do is: using an integer variable for the for next loop , and make some translation from
this integer to the double variable contourline...... that is not very easy.

Maybe there is a better approach????
possible a while wend loop with contourline = contourline + 5, for example???

Wim

Re: naugty problem with for next in grid calculations

Posted: Fri Feb 25, 2022 11:51 pm
by breeze4me
Then try to exchange the positions of the variables "contourlijn" and the following variables in all "if" comparisons.
(The front is a double type variable, and the back is an integer type variable.)
In this case, there is no need for a temporary double type variable.

For example,

Code: Select all

If w(i,j) = contourlijn               ; <----
  w(i,j)=w(i,j)+0.00001
EndIf
If w(i+1,j) = contourlijn              ; <----
  w(i+1,j)=w(i+1,j)+0.00002
EndIf

;***  Attention to the direction of the inequality sign !
If w(i,j) < contourlijn And w(i+1,j) > contourlijn          ; <----
  antw$ = "j"
EndIf
If w(i,j) > contourlijn And w(i+1,j) < contourlijn          ; <----
  antw$ = "j"
EndIf

Re: naugty problem with for next in grid calculations

Posted: Sat Feb 26, 2022 7:53 am
by wimapon
Hi Breeze4wme,

Yes yes yes,,, this works..
first the double and then the integer in a comparison.

I did not expect this.... I am an old man, and you can not learn an old horse a new trick.....
but i learned a new one now !


So, dear stargate, BarryG and breeze4me , thank you very much for your help
i am a happy man now

P.S. in GWbasic and Quickbasic all kinds of variable types worked with for next end if statements.
( if i do remenber it okay)
maybe this can be an idea for purebasic



Wim

Re: naugty problem with for next in grid calculations

Posted: Sat Feb 26, 2022 11:50 am
by wimapon
Look, this is the heart of the program
Only the userinterface is next work.
Then i can use it whithout thinking over how it works.

Image

AGAIN,,, THANK YOU ALL !


LAST QUESTION: the background is black... can i make this white?

Wim

Re: naugty problem with for next in grid calculations

Posted: Sat Feb 26, 2022 12:16 pm
by mk-soft
Draw first time a Box

PB-Help: Box(x, y, Width, Height [, Color])

Is a CreateImage

PB-Help: Result = CreateImage(#Image, Width, Height [, Depth [, BackColor]])

Re: naugty problem with for next in grid calculations

Posted: Sat Feb 26, 2022 12:34 pm
by wimapon
thank you mk-soft,
i will experiment with that.

Wim

Re: naugty problem with for next in grid calculations

Posted: Sun Feb 27, 2022 2:32 am
by BarryG
wimapon wrote: Sat Feb 26, 2022 7:53 amin GWbasic and Quickbasic all kinds of variable types worked with for next end if statements.
( if i do remenber it okay)
maybe this can be an idea for purebasic
For/Next with non-constant steps has been requested many times over the years, but for some reason it's never been done. Not even a technical explanation has been posted by Fred or Freak as to why. I've never understood the deafening silence on this popular request.

Re: naugty problem with for next in grid calculations

Posted: Sun Feb 27, 2022 7:21 am
by wimapon
Okay BarryG,
It is a pitty!

thanks anyway again
Wim

Re: naugty problem with for next in grid calculations

Posted: Sun Feb 27, 2022 11:39 am
by infratec
You don't know assembler :wink:

Else you would know that there is a loop command in assembler which directly decreases a register and jump if not zero.
Since registers are 'integers' this is easy and fast.
There is no such command for floating point numbers.

And since you know that only integers are possible, it is no problem to switch to while or repeat loops.
A for loop with integers is fast.
If you implement it also for floats, you will wonder why it is much slower.

Re: naugty problem with for next in grid calculations

Posted: Sun Feb 27, 2022 1:01 pm
by BarryG
infratec wrote: Sun Feb 27, 2022 11:39 amYou don't know assembler :wink:
Correct. And thank you for providing an explanation. But now I have another question: if While/Wend can increment in floats, what's the reason that For/Next can't internally also do it that way, invisibly to the user? Like this -> https://www.purebasic.fr/english/viewtopic.php?t=56685

Re: naugty problem with for next in grid calculations

Posted: Mon Feb 28, 2022 8:33 am
by Lord
infratec wrote: Sun Feb 27, 2022 11:39 am...
And since you know that only integers are possible, it is no problem to switch to while or repeat loops.
A for loop with integers is fast.
If you implement it also for floats, you will wonder why it is much slower.