LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to format a text file

Hello I'm generating a text file in tab delimited format of frequency vs intensity. I wish to format it and save it in another text file. I'm getting my data in this format in the text file...
1312500000.00    -6.69
1375000000.00    -6.25
1437500000.00    -5.94
1500000000.00    -5.66
1562500000.00    -5.89
1625000000.00    -6.29
1687500000.00    -6.45
1750000000.00    -6.28
1812500000.00    -5.59
...
...
...
...
Now I'm trying to format this data into different coloums...like after every 201,401,601 or 1601(a control which tells this to vi)...I should jump to new set of coloumns, like:

Frequency             Int.       Frequency             int.
1312500000.00    -6.69    1312500000.00     -7.71        ...                ...               ...             ...   
1375000000.00    -6.25     1375000000.00    -6.55        ...               ...                ...           ...
1437500000.00    -5.94     1437500000.00    -7.94
1500000000.00    -5.66     1500000000.00    -7.66
1562500000.00    -5.89     1562500000.00    -4.89
1625000000.00    -6.29     625000000.00      -9.09
1687500000.00    -6.45     1687500000.00    -6.40
1750000000.00    -6.28     1750000000.00    -6.88
1812500000.00    -5.59     1812500000.00    -5.89
1375000000.00    -6.25     1375000000.00    -5.25
1437500000.00    -5.94     12500000.00        -5.59
...                          ...           ...                          ...
...                          ...          ...                           ...
...                           ...          ...                            ...
...                           ...          ...                           ...
...till 201 rows(If I input 201 in a control)

I'm facing some problems with editing can anyone help me around.
Attached my text file for reference
Looking for help,
Regards
0 Kudos
Message 1 of 9
(4,408 Views)

Though Applications Engineers at National Instruments do not typically write customer code, today I felt like a challenge. I have attached a VI (ViewDataColumns.vi) that should accomplish exactly what you are trying to do.

Essentially, this application reads in your data as a 2D array (a sample file is attached as OldData.txt). After this point, the program loops for the number of columns that you would like to end up with (based on the number of rows / col). During each iteration of the loop, a chunk of the original data array is extracted and then inserted into an output array. When the program is finished running, you can view the output on the front panel.

If you wish to save the altered data to a text file, you can use the Write Spreadsheet File function located on the File I/O palette. I hope this helps!

Regards,

Casey Weltzin
Applications Engineer
National Instruments

Download All
Message 2 of 9
(4,356 Views)
Oops,
The code seems to be in Version 8.2.1 I'm using LabView version 8....Please can you attach the vi in version 8.
Thanks for the efforts.
Regards
0 Kudos
Message 3 of 9
(4,353 Views)
I'm sorry about that; the version 8.0 VI is attached to this post. Have a great weekend!
 
Regards,
 
Casey Weltzin
Applications Engineer
National Instruments
 
0 Kudos
Message 4 of 9
(4,350 Views)
Thanks a Lot!! It's wroking so sexy!
Though you forgot to place Number to string pallatte in between, but I've placed it now and it's working simply great.
Have a great weekend ahead!
0 Kudos
Message 5 of 9
(4,339 Views)
I don't think you need any loops and there is certainly no need o convert to numbers and back!
(scanning and formatting operations are expensive!)
 
Read the file as a plain string, then convert it to a 1D array of strings, one line per array element.
Reshape to a 2D array of proper dimensions and transpose to fill columns first.
Use spreadsheet string to array (now with tab as delimiter) to generate the desired string.
Write the string to a new file.
 
Here's a simple draft (LabVIEW 8.0). Look ma, no loops! 😄
 
 
Modify as needed.

Message Edited by altenbach on 06-15-2007 03:29 PM

Download All
Message 6 of 9
(4,342 Views)
That's cool! No loops great!
Thanks
0 Kudos
Message 7 of 9
(4,330 Views)


@roiht wrote:
Though you forgot to place Number to string pallatte in between, but I've placed it now and it's working simply great.

Just for your reference:

Actually, this VI works correctly under LabVIEW 8.2, where the "read from spreadsheet file" got enhanced with a polymorphic selector that allows reading arrays of strings instead of arrays of numbers. The downconversion to LabVIEW 8.0 can only read numeric spreadsheets, breaking the code.

This is how it looks in 8.2:

(Whenever possible, I check downconverted code in the target version and correct such issues. Most likely, Caseyw does not have 8.0.)

If you want to adapt this code for 8.0, read it as a string, then convert to a 2D array of strings to simulate the 8.2 capabilities.

Still, I prefer my method. 😄

Message Edited by altenbach on 06-15-2007 03:46 PM

Message 8 of 9
(4,327 Views)

Thank you Altenbach! It is always great to learn some new LabVIEW tricks. In addition, thank you once again for your constant contribution to the LabVIEW forums; all of the Applications Engineers at National Instruments really appreciate it.

Regards,

Casey Weltzin
Applications Engineer
National Instruments

0 Kudos
Message 9 of 9
(4,268 Views)