Results 1 to 5 of 5

Thread: [RESOLVED] Problem to read minimum value of input file

  1. #1

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Resolved [RESOLVED] Problem to read minimum value of input file

    I have a program to read 5000 points of xyz coordinates. I'm using the code below to read and calculate the minimum and maximum value of the coordinates but the code doesn't seems to give the correct output. It didn't display the correct xmin and ymin. Can anybody help to see what wrong with the code or maybe suggest a better way to do this? Thanks a lot

    VB Code:
    1. npnt = 1
    2.  
    3. Open "c:\PSM\Data\pnt.dat" For Input As #1
    4. Line Input #1, xyz 'Read file header
    5. Input #1, Point.X, Point.Y, Point.Z
    6.  
    7. xmin = Point.X
    8. ymin = Point.Y
    9. xmax = Point.X
    10. ymax = Point.Y
    11. infolist.AddItem "Calculating min and max xy..."
    12.  
    13. 'Loop to read every line of points
    14. While Not EOF(1)    
    15.     Input #1, Point.X, Point.Y, Point.Z    
    16.     If (xmin > Point.X) Then
    17.         xmin = Point.X
    18.     End If
    19.     If (ymin > Point.Y) Then
    20.         ymin = Point.Y
    21.     End If
    22.     If (xmax < Point.X) Then
    23.         xmax = Point.X
    24.     End If
    25.     If (ymax < Point.Y) Then
    26.         ymax = Point.Y
    27.     End If
    28.    
    29.     npnt = npnt + 1
    30.    
    31.  Wend
    Attached Files Attached Files
    Last edited by Bearnerd; May 1st, 2006 at 12:33 PM.

  2. #2
    Lively Member
    Join Date
    Apr 2006
    Location
    Planet Earth
    Posts
    64

    Re: Problem to read minimum value of input file

    i've tried ur codes and it worked just well..to be sure, sort the data using MS excel...however, i've tried to compare it when i wrote it again using c++ codes and the result are slightly different. I think thats because in c++, it eliminates the embedded values..Ur codes are good though, nothing's wrong there.
    I'm Still learning!
    satisfied/not satisfied, PLEASE TAKE SOME TIME TO rate me accordingly.
    Ur opinions helps me to be better!


    Appreciation Triggers Another Good Deeds.

  3. #3

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Problem to read minimum value of input file

    Thanks for your ideas. I tried to read the points in C++ and compares the xmin and ymin values. You're right, the points was truncated. So, that's mean the vb code is ok and I don't need to worry about the result. Actually, I try to translate a c++ code into vb, and the way I wrote the code is actually the same way as the cpp code. I just wonder why the result is not the same as vb does. Here's the code I wrote in cpp

    Code:
       // reads the file header
       XYZfile >> charX >> charY >> charZ;
       
       npnt = 1;
       XYZfile >> Point.x >> Point.y >> Point.z;
    
       // to calculate min xy, max xy
       xmin = Point.x;
       ymin = Point.y;
       xmax = Point.x;
       ymax = Point.y;
    
       do
         {
          printf("\r");
          cout << "Reading points ... " << npnt;
    
          XYZfile >> Point.x >> Point.y >> Point.z;
            if (xmin > Point.x)
                xmin = Point.x;
    
            if (ymin > Point.y)
                ymin = Point.y;
    
            if (xmax < Point.x)
                xmax = Point.x;
    
            if (ymax < Point.y)
                ymax = Point.y;
         npnt ++;
         } while (! XYZfile.eof());
    
       xlength = xmax - xmin;
       ylength = ymax - ymin;
       maxpnt = npnt - 1;
       XYZfile.close();
       getch();
      }

  4. #4
    Lively Member
    Join Date
    Apr 2006
    Location
    Planet Earth
    Posts
    64

    Re: Problem to read minimum value of input file

    as i said, i also wrote it in c++ to compare it with ur vb codes and the results is slightly different..i've tried it using the dataset that u've provided..i dont know what datatype did u used but i used Double..even though both in vb and c++ the variables type is double, but still in c++ it truncated the embedded values..but when u sort the dataset using MS excel, the results is the same as in vb..so in my opinion, the result in vb code is the accurate 1..maybe other people have other opinion..
    I'm Still learning!
    satisfied/not satisfied, PLEASE TAKE SOME TIME TO rate me accordingly.
    Ur opinions helps me to be better!


    Appreciation Triggers Another Good Deeds.

  5. #5

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Problem to read minimum value of input file

    Thanks a lot pal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width