naugty problem with for next in grid calculations

Just starting out? Need help? Post your questions and find answers here.
User avatar
STARGÅTE
Addict
Addict
Posts: 2236
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: naugty problem with for next in grid calculations

Post 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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

Re: naugty problem with for next in grid calculations

Post 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
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

Re: naugty problem with for next in grid calculations

Post 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
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: naugty problem with for next in grid calculations

Post 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 
      
      ......
      ......
      
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

Re: naugty problem with for next in grid calculations

Post 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
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: naugty problem with for next in grid calculations

Post 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
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

Re: naugty problem with for next in grid calculations

Post 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
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

Re: naugty problem with for next in grid calculations

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 6255
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: naugty problem with for next in grid calculations

Post 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]])
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

Re: naugty problem with for next in grid calculations

Post by wimapon »

thank you mk-soft,
i will experiment with that.

Wim
BarryG
Addict
Addict
Posts: 4180
Joined: Thu Apr 18, 2019 8:17 am

Re: naugty problem with for next in grid calculations

Post 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.
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

Re: naugty problem with for next in grid calculations

Post by wimapon »

Okay BarryG,
It is a pitty!

thanks anyway again
Wim
infratec
Always Here
Always Here
Posts: 7625
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: naugty problem with for next in grid calculations

Post 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.
BarryG
Addict
Addict
Posts: 4180
Joined: Thu Apr 18, 2019 8:17 am

Re: naugty problem with for next in grid calculations

Post 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
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: naugty problem with for next in grid calculations

Post 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.
Image
Post Reply