naugty problem with for next in grid calculations

Just starting out? Need help? Post your questions and find answers here.
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

naugty problem with for next in grid calculations

Post by wimapon »

Hi folks,
after a long time with no problems with purebasic i encounterd a naugty problem.
i made a program for drawing contour lines within a grid of 100 grid nodes.
if i draw one line, say line of 80, all is okay.
But when i add: for contourline = 80 to 81 the program gives with both lines some fautly values.
When i after that remove the for contour line... this one line for 80 gives the same faulty values....
You should say, the program is exactly the same as in the beginning.

I think this must be a purebasic program.
It is a large program, so its is better not to give it here.

Thanks for your help

Wim Apon
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 »

sorry, i will say: this must be a pure basic problem.
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 »

restarting the computer of restarting purebasic, and even run this progam on a other computer gives the same problem...
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 »

I don't understand your description. (limitation of your english?)
Where is the coding question?

Edit: You can edit your post, no need for adding two additional posts.
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
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: Fri Feb 25, 2022 10:53 amI think this must be a purebasic program
If you mean "bug" instead of "program", then I doubt it is. Try to make a small snippet showing the problem.
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 »

Imagesorry about my english: it is a difficult problem to explain.
i can show 3 .jpg files to demonstrate the results.....
but for me this is a new layout for the forum.
i can not find how to post a picture, and how to edit my text\

i will give it a try i can't


Image
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 »

wimapon wrote: Fri Feb 25, 2022 11:26 am i can not find how to post a picture, and how to edit my text\
Picture can be embedded with [img] URL of the image [/img].
However, the picture have to be uploaded on a third party website.
You can edit your post, when you click on the pencil icon next to this post.
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 »

Demonstration of my problem:
The grid nodes are measuring points of a continuous surface.
so my program draws lines of points with the same value. ( contour lines)
in this example the contourline of 80


first picture is only the 80 m contourline
the second picture is the same program with a extra for next line , so you get the contourlines 80 and 81
then i delete the for next line and you get the third picture.
the program is now exactly the same as for the first picture.
So what is happening.... ???
i made all used variables to zero for the next -- for next loop --

please forget the labels at the x and y axis
the grid nodes has more decimals than shown.

Image
Image
Image
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 »

Thanks for the pictures, but without any code example we can not help you.
For me it looks like, array elements or list elements are overwritten during the change of the contour line.

Because no code is given, here are general remarks:
- Do you use EnableExplicit?
- Do you use Threads?
- What happens, when you enable the debugger and the purifier?
- Are always the same points and same contour lines showing this issue?
- Are the array sizes correct?
- Do you use lists in multiple procedures?
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,
I made this program in 1987 in quick basic.
Now i translated it to purebasic.

I do not use special purebasic features. no threats, no stuctures, no purifier.
i start the program and go line for line down to the end.
grid sizes are correct.
i use only one subroutine which translate real coordinates to screen coordinates.

i can give the source of the contouring algoritme , but is is 300 lines...
if you wish i can delete all comments and debug lines.... then it will be something like 100 lines


so ??

Wim
Last edited by wimapon on Fri Feb 25, 2022 1:10 pm, edited 1 time in total.
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: Fri Feb 25, 2022 1:09 pmi can give the source of the contouring algoritme , but is is 300 lines
300 lines is nothing. Post it, or even the whole code if it's not private/secret.
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, i will post the contouring lines and delete most of the comments and debug lines.
this takes a while
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 »

Code: Select all

;  this is the part of the contouring program that calculates the contour lines.
;  It has 2 for next loops.. one for horizontal and one for vertical
;  this part of the program gives the third picture for the forum ( in the complete program)
;  it compiles okay, but does nothing.

      Declare Verschaal()


      n = 11    ; aantal gridlijnen    eerste=0
	    Dim w.d(n,n)  ; grid-matrix  eerste  getal is langs de x-as   tweede getal is langs de y-as
	    Dim puntx.d(40)  ; snijpunten van een contourlijn met een gridvierkant
	    Dim punty.d(40)


     ; De minima en maxima van mijn grafiek in mijn coordinaten
     Global Xmin.d = 0
     Global Xmax.d = 100
     Global Ymin.d = 0   ; -0.01
     Global Ymax.d = 100    ; 0.01

     Global x.d, y.d, xw.d, yw.d

     Global Xoffset.d = 90   ; 70.0
     Global Yoffset.d = 40.0



      
; $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
; $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      
     ; ga nu een contourlijn door alle gridcellen tekenen
 
     ; For contourlijn = 80 To 81 
       contourlijn = 80
       For j = 0 To 9    
         For i = 0 To 9 
        	;Even alle variabelen weer op 0 zetten
	        For i2=0 To 4
	          puntx(i2)=0
	          punty(i2)=0
	        Next i2

	        tel=0   ;'t.b.v. het trekken van een contourlijn binnen een gridcel
		            ;' Is het aantal keren dat een grid-cel-wand gesneden wordt         
           
     
          ; snijdt de contourlijn de basis van de gridcel? 
          ;================================================
          antw$ = "n"
          px.d = 0
          py.d = 0
      
      
          ; doe iets als een waarde van een gridpunt precies hetzelfde is als de contourlijn
          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
    
       
          If contourlijn > w(i,j) And contourlijn < w(i+1,j)
            antw$ = "j"
          EndIf
          If contourlijn < w(i,j) And contourlijn > w(i+1,j)
            antw$ = "j"
          EndIf
          
                
          If antw$ = "j"   ; de contourlijn cuts the base of the gridcell
            ; bereken het snijpunt.
            afstand.d = (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 
      
      
      
      
      
   
      
           
          ; snijdt de contourlijn de linkerzijde van de gridcel? 
          ;================================================
          antw$ = "n"
          px.d = 0
          py.d = 0
          
      
          If contourlijn=w(i,j) 
            w(i,j)=w(i,j)+0.00007
          EndIf
          If contourlijn=w(i,j+1) 
            w(i,j+1)=w(i,j+1)+0.00008
          EndIf
      
      
      
          If contourlijn > w(i,j) And contourlijn < w(i,j+1)
            antw$ = "j"
          EndIf
          If contourlijn < w(i,j) And contourlijn > w(i,j+1)
            antw$ = "j"
          EndIf
  
          
      
          If antw$ = "j"   ; de contourlijn snijdt de linker zijde van de gridcel
            ; bereken het snijpunt.
            afstand.d = (contourlijn-w(i,j) ) / (w(i,j+1) - w(i,j))  
            px = i
            py = j + afstand
            ;Debug px
            tel = tel + 1
            puntx(tel) = px
            punty(tel) = py
             
            ; plot dit punt
            x = puntx(tel)
            y = punty(tel)

            verschaal()
            Circle(xw,yw,5,RGB(0,0,255))   ; blauw  
                      
          EndIf 
      
      
              
          ; snijdt de contourlijn de bovenzijde van de gridcel? 
          ;================================================
          antw$ = "n"
          px.d = 0
          py.d = 0
          
      
          If contourlijn=w(i,j+1) 
            w(i,j+1)=w(i,j+1)+0.00005
          EndIf
          If contourlijn=w(i+1,j+1) 
            w(i+1,j+1)=w(i+1,j+1)+0.00006
          EndIf
      
      
      
          If contourlijn > w(i,j+1) And contourlijn < w(i+1,j+1)
            antw$ = "j"
          EndIf
          If contourlijn < w(i,j+1) And contourlijn > w(i+1,j+1)
            antw$ = "j"
          EndIf
          
          
      
          If antw$ = "j"   ; de contourlijn snijdt de bovenzijde van de gridcel
            ; bereken het snijpunt.
            afstand.d = (contourlijn-w(i,j+1) ) / (w(i+1,j+1) - w(i,j+1))  
            px = i + afstand
            py = j +1
            tel = tel + 1
            puntx(tel) = px
            punty(tel) = py
        
            ; plot dit punt
            x = puntx(tel)
            y = punty(tel)
         
            verschaal()
            Circle(xw,yw,5,RGB(0,255,0))   ; groen 
                     
          EndIf 
    
    
      
              
          ; snijdt de contourlijn de rechter zijde van de gridcel? 
          ;================================================
          antw$ = "n"
          px.d = 0
          py.d = 0
          
          If contourlijn=w(i+1,j) 
           w(i+1,j)=w(i+1,j)+0.00003
          EndIf
          If contourlijn=w(i+1,j+1) 
            w(i+1,j+1)=w(i+1,j+1)+0.00004
          EndIf
      
 
          If contourlijn > w(i+1,j) And contourlijn < w(i+1,j+1)
            antw$ = "j"
          EndIf
          If contourlijn < w(i+1,j) And contourlijn > w(i+1,j+1) ; moet als de twee waarden omgekeerd in grootte zijn
            antw$ = "j"
          EndIf
        ;  Debug antw$
         
          If antw$ = "j"   ; de contourlijn snijdt de rechterzijde van de gridcel
            ; bereken het snijpunt.
            afstand.d = (contourlijn-w(i+1,j) ) / (w(i+1,j+1) - w(i+1,j))  
            px = i+1 
            py = j + afstand
            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,0,0))   ; rood     
        
          EndIf 
    
          
          
          
         
          
          
          ; plot nu de lijnstukken
      
 
	        x = puntx(1)   
	        y = punty(1)    
	        verschaal()
	        xw1 = xw
	        yw1 = yw
	    
	    
	    
	        x = puntx(2)
	        y = punty(2) 
	        verschaal()  ;  input is x and y   output = xw and yw
	        xw2 = xw
	        yw2 = yw
	    	    
	 ;       LineXY(xw1,yw1,xw2,yw2,RGB(255,255,0))   ; this line will not compile because no drawing is defined.
	 ;                                                  in the real program it is running okay      
     
	        If puntx(4) <>0    ; there will be 2 lines going through this gridcell
		        x = puntx(3)
	          y = punty(3)
	          verschaal()
	          xw1 = xw
	          yw1 = yw
	    
	          x = puntx(4)
	          y = punty(4)
	          verschaal()
	          xw2 = xw
	          yw2 = yw
	    
	  ;        LineXY(xw1,yw1,xw2,yw2,RGB(255,255,0))
            
	        EndIf  
      
      
      
        Next i
      Next j
      
    ;  Next contourlijn        
      
; $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
; $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

      End
      
      
  
;
Procedure Verschaal()
;*====================*============================================***==============================*
;| Procedure Name ....| Verschaal
;| Description .......| changes real coordinates to screen coordinates 
;| Syntax ............| Verschaal()
;| Parameter(s) ......| x  y  
;| Return value ......| wx  yw
;| Author(s) .........| Wimapon
;| Versions ..........| 0001:2010-12-31:Creation Date
;*--------------------*-----------------------------------------------------------------------------*
;| Remarks ...........|
;*====================*=============================================================================*
   
  
    xw = (x-Xmin) / (Xmax-Xmin) * (ImageW - Xoffset) + Xoffset
    yw = (ImageH - Yoffset) -( (y - Ymin) / (Ymax-Ymin) * (ImageH - Yoffset))
EndProcedure

Last edited by wimapon on Fri Feb 25, 2022 4:13 pm, edited 1 time in total.
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 »

spaces are visible
Last edited by wimapon on Fri Feb 25, 2022 5:31 pm, edited 1 time in total.
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 »

Please edit your post and add the [code] [/code] tags around the code.
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
Post Reply