Reading from File into an Array

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

  • Reading from File into an Array

    Hello,
    I'm currently running a measurement routine that calls this subroutine to read nominal positions of x and y into two arrays:
    STARTUP =ALIGNMENT/START,RECALL:USE_PART_SETUP,LIST=YES
    ALIGNMENT/END
    MODE/MANUAL
    MOVESPEED/ 50
    TOUCHSPEED/ 3
    FORMAT/TEXT,OPTIONS, ,HEADINGS,SYMBOLS, ;NOM,MEAS,TOL,DEV,OUTTOL, ,
    SUBROUTINE/MATRIX,
    V_MATRIX = V_MATRIX : V_MATRIX,
    =
    LOADPROBE/5X-
    TIP/TIP1, SHANKIJK=0, 0, 1, ANGLE=0
    IF_GOTO/V_MATRIX=="NO",GOTO = ENDEMATRIX
    ASSIGN/AVXPOS=ARRAY(0)
    ASSIGN/AVYPOS=ARRAY(0)
    ASSIGN/AVX=0
    ASSIGN/AVY=0
    ASSIGN/TZ=","
    FPTR =FILE/OPEN,D:\V_2019R1\NOMINALS.txt,READ
    ASSIGN/INC=1
    DO/
    V1 =FILE/READLINE,FPTR,{AVX}+TZ+{AVY}
    ASSIGN/AVXPOS[INC]=AVX
    ASSIGN/AVYPOS[INC]=AVY
    ASSIGN/AVXPOS[LENG(AVXPOS)+1]=0
    ASSIGN/AVYPOS[LENG(AVYPOS)+1]=0
    ASSIGN/INC=INC+1
    UNTIL/V1=="EOF"
    FILE/CLOSE,FPTR,KEEP
    ASSIGN/V_AVX=AVXPOS
    ASSIGN/V_AVY=AVYPOS
    ENDEMATRIX =LABEL/
    ENDSUB/

    I use the subroutine it like this:
    CS8 =CALLSUB/MATRIX,D:\V_2019R1\SUB_MATRIX.PRG:,,
    ASSIGN/XMITT=V_AVX
    ASSIGN/YMITT=V_AVY

    This is all running very slow. For 1100 lines in the NOMINALS.txt it takes about 60 sec to read. I heard that using a basic script could speed this up. But how do I read into an array?

  • #2
    I don't know if this will do it for you, but in code it would be something like:

    (In declarations):

    Public Xval(5000) as Double, Yval(5000) as double


    In the sub:
    Code:
    Open {path/filename} For Input as #1
    Do While Not EOF(1)
    input #1, Xval(MyCount),Yval(MyCount)
    Mycount=MyCount+1
    Loop
    Close #1
    May work for you....

    Comment


    • StefanH
      StefanH commented
      Editing a comment
      Thanks, but I'm struggling to understand how to name/address the array in my meaesurement routine.

  • #3
    See https://www.pcdmisforum.com/forum/pc...-pc-dmis-basic for accessing PC-DMIS Array variables from PC-DMIS Basic.
    AndersI
    SW support - Hexagon Metrology Nordic AB

    Comment


    • #4
      I think I snagged this from the PCDBASIC help file, not sure. This should be run as a script though.

      Code:
      Sub Main()
      Dim FileArray() As String
      Dim FileName As String
      
      ' Setup Folder And filecounter
      ' Example lists all bitmaps In C:\Windows
      Folder = Dir("C:\Windows\*.bmp")
      count = 0
      
      ' Parse the folder Until filename returns empty (no more files)
      ' And count the files ending With .bmp
      While Folder <> ""
          count = count + 1
          Folder = Dir
      Wend
      
      ' The MsgBox is For debug/example purposes And displays the
      ' number of bitmaps found
      MsgBox "Filecount: " & count
      
      ' Initialize the FileArray (create the array) With the size of
      ' count (number of files found)
      ReDim FileArray(count)
      
      ' Fill the filearray With the bitmap filenames
      FileArray(0) = Dir("C:\Windows\*.bmp")
      
      ' For debug/example purposes, displays the bitmap filenames
      For i = 1 To count
          FileArray(i) = Dir
          FileName = FileName + Chr(13) + FileArray(i)
      Next i
      MsgBox FileName
      
      End Sub
      PC-DMIS CAD++ 2o19 R1 SP10

      Comment


      • vpt.se
        vpt.se commented
        Editing a comment
        I heard that using a basic script could speed this up. But how do I read into an array?
        I went for this ^^

      • StefanH
        StefanH commented
        Editing a comment
        So I have to create the array inside my PC-DMIS program and then I can try to access it with Part.GetVariableValue(<ArrayName>) in my Basic script? In the https://www.pcdmisforum.com/forum/pc...-pc-dmis-basic it seems as if this didn't work, correct?
        Last edited by StefanH; 08-21-2019, 12:28 PM.

      • vpt.se
        vpt.se commented
        Editing a comment
        It seems so, yes. Depending on what you need the data in array for, you might be able to do that in the script without the need to do the manipulation of the array in PC-DMIS?

    Related Topics

    Collapse

    Working...
    X