Announcement

Collapse
No announcement yet.

Dimensioning problem

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dimensioning problem

    I am working on a coordinate geometry problem in which I generate a file of double precision point coordinates - 62 pairs at this point. This shouldn't be a big deal as far as memory is concerned but I have run into a problem.

    I started a new program that imports the 62 pairs of double precision numbers. I had the expectation of plotting them on a graphic page but the program fails before I can plot points. This is in PBCC. Here's how the program flows.. .

    FUNCTION PBMAIN () AS LONG
    DIM SX(22) AS SINGLE
    DIM SY(22) AS SINGLE
    DIM PX(14) AS SINGLE
    DIM PY(14) AS SINGLE
    DIM RX(12) AS SINGLE
    DIM RY(12) AS SINGLE
    DIM IX(4) AS SINGLE
    DIM IY(4) AS SINGLE
    DIM TX(8) AS SINGLE
    DIM TY(8) AS SINGLE
    DIM EX(12) AS SINGLE
    DIM EY(12) AS SINGLE
    DIM VCX(14) AS SINGLE
    DIM VCY(14) AS SINGLE
    DIM I AS INTEGER
    DIM HWIN AS LONG
    DIM COUNT AS INTEGER

    CON.LOC = 400,300
    CON.COLOR 15,1
    CON.CLS

    OPEN "C:\USERS\TIM COLLINS\DOCUMENTS\BASIC\SPRITE\MATH MODEL\MATH MODEL POINTS.CSV" FOR INPUT AS #1

    At this point I use loops to read in the points S, P, R, I, T, E, VCX(), and VCY(). I then set up for the graphic page. . .

    GRAPHIC WINDOW NEW "SPRITE", 0, 0, 1920, 1040 TO hwin& 'this is the size of the display monitor - works
    GRAPHIC ATTACH hwin&, 0, REDRAW
    GRAPHIC COLOR %BLACK, %WHITE
    GRAPHIC SCALE (3.112964,5.731717) - (7.399191,3.410011)
    GRAPHIC LINE (3.112964,5.731717) - (7.399191,3.410011)
    GRAPHIC REDRAW
    GRAPHIC WAITKEY$
    GRAPHIC WINDOW END
    PRINT "DONE"
    WAITKEY$
    END FUNCTION

    As presented the program works. But when I change the dimension to DOUBLE and run it, the program imports the points OK, but the graphic screen just flashes but and after a few seconds (2?) the console screen closes on its own. Here's a sample of several of the 62 data points in the file POINTS.CSV. ..

    2.99388462600318,1.59375
    2.80638462600318,1.59375
    2.87449798800368,1.6875
    2.68699798800368,1.6875
    2.50536235600234,1.4375

    I have to be missing something pretty elementary here, but as a novice that's not unusual. What am I overlooking or doing wrong that causes the program to work when using SINGLE dimensions and crash when using DOUBLE dimensions. I'm running a rather new DELL computer that has plenty of memory. I can't see that this program calls for more than "a drop in the bucket" worth of memory.

    FYI, the point coordinates are for the corners of the letters in the graphic below. Some corners have a radius so the points VCX() & VCY() are for the vertex of the curve.

    Help would be appreciated!
    Tim


    Click image for larger version

Name:	SPRITE-PIC.bmp
Views:	1
Size:	18.4 KB
ID:	776597

  • #2
    You haven't shown the manner in which you access the array values, which is likely the source of your issue here. Also try #DEBUG DISPLAY ON at the beginning of your code. It seems you list 72 pairs not 62. They are dimensioned but the issue may be related in some manner.
    Rod
    "To every unsung hero in the universe
    To those who roam the skies and those who roam the earth
    To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

    Comment


    • #3
      What Rod said, plus - graphic commands use SINGLEs not DOUBLEs and not STRINGs (what you get from .csv files) No code using VAL() shown (convert string to binary). So also can't see if VAL() to SINGLE type vars or VAL() to DOUBLE type vars,

      The fact that you are getting a run time error, instead of compile tme error is interesting too. Maybe a more complete demo with only one array and fails when switched from SINGLE to DOUBLE.

      (and use code tags to preserve code indentation.)

      Cheers,
      Dale

      Comment


      • #4
        Dale, I think DOUBLEs are okay since under GRAPHIC SCALE it states 'World coordinates may be floating point values, with the only requirement that x1! not equal x2!, and y1! not equal y2!.' Thus one must be able to use almost any type of integer or floating point. Of course, the comment under "Note" under GRAPHIC SCALE is wrong so I might be too.
        Rod
        "To every unsung hero in the universe
        To those who roam the skies and those who roam the earth
        To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

        Comment


        • #5
          LINEs, PIXELs and POLYGONs, etc. ??? He only has one LINE in post 1, and that has a literal. So does the SCALE. We'll see!
          Dale

          Comment


          • #6
            Well, it seems that the use of floating point coordinates of any kind is moot, since when the pixels get drawn, the actual pixel drawn will be calculated (by virtue of the scaling but not obvious to us) as an integer, since the number of pixels doesn't change.
            Rod
            "To every unsung hero in the universe
            To those who roam the skies and those who roam the earth
            To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

            Comment


            • #7
              Amazing. I was just going to say something like that when I got back! Made a demo since my last post -
              Code:
              #compile exe
              #dim all
              '
              function pbmain () as long
                local hGrafWin as dword
               ' local X1, Y1, X2, Y2 as single
               ' local X1, Y1, X2, Y2 as double
                local X1, Y1, X2, Y2 as long
                graphic window new "Test", 20, 20, 100, 100 to hGrafWin
                graphic attach hGrafWin, 0  ', redraw
                graphic color %black, %white
                graphic width 3
                X1 = 10
                Y1 = 5
                X2 = 80
                Y2 = 50
                graphic line (X1, Y1) - (X2, Y2)
                waitkey$
              end function
              Yes, no such thing as fraction of a pixel.

              I'm still curious about the unseen code causing a problem.

              Cheers,
              Dale

              Comment


              • #8
                Thanks for the very useful input. Here's what I found.

                My dimension for the R x,y points was set to 12 (ie: DIM RX(12) AS SINGLE). However, I read in a point or two that were numbered RX(13), RY(13), RX(19) and RY(19). I knew I wasn't going to load 14 "R" named points so tricked myself into thinking if I didn't use a point (ie"RX(10)) that RX(19) could use that saved space. Novice error - I understand now. After redimensioning "R" the program works as I intended. (changed to RX(20), RY(20))

                I had never considered that .CVS files are strings and have never run into problems where my program balked because I was using the input as some kind of number. Here's an example of how I loaded the .CVS file.. . .

                FOR I = 6 TO 8
                INPUT #1, RX(I), RY(I)
                NEXT I

                So, Dale, the code was OK. The problem was with how I originally dimensioned the variables. And Dale, what's a code tag?

                I just repeated this for each letter (S P R I T E) and range of points I wanted to load. The graph part of the program recognized the numbers as numbers without needing to use the VAL function.

                Adding #DEBUG DISPLAY ON was a very helpful suggestion. When the program got to the undimensioned variables, it spit out an ERROR 9 which only is generated when the DEBUG DISPLAY is activated. I will use the command more often now that I know about it.

                I am making a math model of the SPRITE logo using DOUBLE precision numbers because I previously ran into a problem with the letters not being "closed" figures. So, when I tried to PAINT them, they leaked - I though. I believe now that I wasn't correctly using the PAINT command to look for a specified boundary color to stop painting (beyond that color.) At least that's what I am investigating. I am also wondering if a scale that greatly distorts a figure can cause the PAINT command to "leak" color. I don't believe it would - just checking.

                I started with TURBOBASIC and POWERBASIC 3 for decades doing little programs to shuffle student data. I didn't have to dimension variables back then. Now, in retirement, I am spending time to learn things I didn't know back then and I've upgraded to PBCC.

                Thanks for all the help! It is greatly appreciated.
                Tim

                Comment


                • #9
                  Probably moot but..

                  As requested above, more sample code needed to help but meanwhile I note that the sample data points will be outside the graphic area defined by the Scale statement..
                  Rgds, Dave

                  Comment


                  • #10
                    Originally posted by Tim Collins View Post
                    I had never considered that .CVS files are strings and have never run into problems where my program balked because I was using the input as some kind of number. Here's an example of how I loaded the .CVS file.. . .

                    FOR I = 6 TO 8
                    INPUT #1, RX(I), RY(I)
                    NEXT I

                    ...
                    Tim
                    When you tell PB to "INPUT #" a numeric variable, the text representation of the number in the sequential file is automagically converted into the appropriate form.

                    Code tags - surround the code with "open square bracket"CODE"closesquare bracket" and "open square bracket"/CODE"close square bracket" where "open/close square bracket" are the "[" and "]" characters.:

                    i.e. [ C O D E ].... [ / C O D E ] without any spaces


                    Code:
                    #COMPILE EXE
                    #DIM ALL
                    
                    FUNCTION PBMAIN () AS LONG
                        LOCAL s AS STRING
                        LOCAL n AS DOUBLE
                        s = "Some Text"
                        n = 1.2345
                        OPEN "temp.txt" FOR OUTPUT AS #1
                        WRITE #1, s,n
                        CLOSE #1
                        s = "": n = 0
                        OPEN "temp.txt" FOR INPUT AS #1
                        INPUT #1, s,n
                        ? "String: " & s & "   Number:" & STR$(n)
                    END FUNCTION

                    Comment


                    • #11
                      About code tags is fairly quick. Above the post compose area, to the right is an underlined upper case "A". When you click it it opens the tool bar.

                      When you are ready to insert some source code, press the large "#" That will create the code tags with cursor between, goto IDE and get the source code into the clipboard, back to browser and cntl C with cursor still between. You can type the tags, but create them first then paste the code. (pasteing first then making the tags often losses the indentation in the code.)

                      Glad it is working. I also started with TurboBASIC.
                      Dale

                      Comment

                      Working...
                      X