LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

filetoarray

I was wondering if the filetoArray function separate the columns in the file. I want to open a .dat file that has 2 columns which will be my x and y to plot.  Can i use filetoArray with this?
0 Kudos
Message 1 of 6
(4,802 Views)

FileToArray can split the content of a file into several groups: playing with the options of FileToArray command you can accomodate the function so that it can read several file types.

You can look at the attached example: it's the standard arrayfile example that ships with CVI (it's located into sample\fileio folder) that I have modified to treat a two-dimensional array both in writing and reading.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(4,787 Views)

Thank you for your response.  However, it does not seem to work if the file I am opening is in not written in CVI.  When I try to copy the 1d it said that it was not initialized.  Basically, I need to open a file (not necessarily from CVI) put it into an array and then plot it.  I really appreciate this.

 

 

0 Kudos
Message 3 of 6
(4,754 Views)

Hi Jemellie,

Can you tell us what line of code is the error coming from? What's the exact text of the error?


Mark E.
National Instruments

0 Kudos
Message 4 of 6
(4,710 Views)

The problem is when I plot it, its just a straight horizontal line at zero, when clearly its not supposed to be that way.

 

 

  if (FileSelectPopup ("", "*.txt", "*.txt", "Name of File to Read",
                  VAL_OK_BUTTON, 0, 0, 1, 0, file_name) > 0){
                GetCtrlVal (panelHandle, PANEL_InputType, &fileType);

                FileToArray (file_name, array, VAL_DOUBLE, COUNT, 1,
                             VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS, fileType);
                Copy1D (array, COUNT, xonea);
                Copy1D (array + COUNT, COUNT, yonea);
                /*for(i=1; i=COUNT; i++){
                    xonea[i] = xoneb[i]/10000;
                    yoneb[i] = yoneb[i]/10000;
                }       */
                DeleteGraphPlot (panelHandle, PANEL_GRAPH_3, -1, 1);
                PlotXY (panelHandle, PANEL_GRAPH_3, xonea, yonea, COUNT, VAL_DOUBLE, VAL_DOUBLE,
                       VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1,VAL_BLUE);
            } 

 

Thank You!

Message Edited by Jemellie on 06-24-2009 10:41 AM
0 Kudos
Message 5 of 6
(4,671 Views)

Hi Jemellie,

 

is the file you are trying to read an ASCII file or a binary file? In the first case I never had problems with FileToArray even with files produced by other programs: you may have to fiddle a little with command options but you are very likely to succeed. If you can post here a small sample of this file, we may try to help you in a more concrete way.

 

In case your file is a binary one, you may find problems if the other application does not stores data as CVI expects. Being this the case, can you detail a little how your file is created (type of data stored in it, organization of data within the file...)? Again, a small file sample together with relevant informations about it can help us in driving you to the correct way.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 6 of 6
(4,667 Views)