Read from text file and seperate column
hello,
I have a problem reading my text file. This text file is downloaded from weather link. All data will be changed upon the selection of user. my problem is I can read the data column by column but i cannot retrive the right column header for each data. I also attached the test file. Can somebody help me? Thanks in advance..
Attachments:
download.txt 8 KB
read text file.JPG 11 KB
read data.JPG 43 KB
Hi
Sorry, I missed that one. The file formatting is strange though. It uses spaces to separate columns but also within columns. I attached a modified VI that tries to take care of that, but it fails at the columns "Solar Energy" and "Hi Solar Rad.". This is very difficult to read programmatically as there's one space each between "Solar", "Hi", and "Solar" again. So how do we distinguish between column separator and space within column?
Is download.txt the original file? Or was it probably modified by an editor that would replace tabs by space characters?
Attachments:
test-mod-2.vi 11 KB
Similar Messages
-
Urgent Help:read from text file and write to table
Hi,
I'm a super beginner looking for a vi to read this data from a text file and insert it into a table:
#19
Date: 05-01-2015
ID= 12345678
Sample_Rate= 01:00:00
Total_Records= 2
Unit: F
1 03-23-2015 10:45:46 70.1 3.6
2 03-23-2015 11:45:46 67.7 2.7
Output table
# date time x y Sample rate Total Records
1 03-23-2015 10:45:46 76.8 2.8 01:00:00 2
2 03-23-2015 10:45:46 48.7 2.1 01:00:00 2
Thanks for your help in advance.
Attachments:
sample.txt 1 KBjcarmody wrote:
Will there always be the same number of rows of noise header information?
Show us how you've read the data and what you've tried to do to parse it. Once you've got the last rows, you can loop over them using Spreadsheet String to Array (after cleaning up a few messy spaces).
Jim,
I didn't know you're that active on here.
Yes, There will always be the same number of noise header information.
I'll show you in person
Regards, -
Using servlets to read from text file and insert data
Hi,
Can I use a servlet to read from a space delimited text file on the client computer and use that data to insert into a table in my database? I want to make it easy for my users to upload their data without having to have them use SQL*Loader. If so can someone give me a hint as how to get started? I appreciate it.
Thanks,
ColbyCreate a page for the user to upload the file to your webserver and send a message (containing the file location) to a server app that will open the file, parse it, and insert it into your database. Make sure you secure the page.
or
Have the user paste the file into a simple web form that submits to a servlet that parses the data and inserts it into your db. -
Read from text file and plot in real time
Hello to everybody,
I recently started using labview and so I know very few features, I apologize for any crap I'm about to write.
My problem is as follows:
_ A wireless node is sampling, with a known frequency, the voltage and the current of an electronic device
_ These data are sent to a coordinator connected to the PC
_ Each packet sent includes a single column with: Letter V followed by voltage samples, Letter I followed by current samples (all in a single column as in the attached example)
_ The coordinator saves it in a .txt file
I want to do a labview application that:
_ Reads that file (continuosly update by the coordinator)
_ Plots on two different graphs the values (over the time) of current and voltage
Thanks for your help
Danilo
Attachments:
TextData.txt 1 KBThere are File IO examples that ship with LV which show you how to write to red from a file . A more fundamental question though is why have the file at all? Is it serving strictly as a data communication channel, or will it be used for something else?
The "coordinator" that you mention, can it be accessed directly? Serial IO? TCP/IP? Telnet? ActiveX? .NET? Anything?
If so, that would be the preferred way to handle this situation.
Mike...
PS: Sorry for the next bit, but I used to be a magazine editor and my grandmother was a school teacher so I am just a tiny bit anal retentive about word usage: In English "data" is a funny word in that while it is a singular form, it is (depending upon context) often understood to referring to multiple things and so can be sort of plural. Consequently, it is proper to say: "This data is sent.. " or "The data indicates...", but not, "The data are showing..". Likewise it is always incorrect to try to make it plural by saying "datas".
PPS: The same goes for the word "code" when used as a noun. It can also be a verb, but that's a whole different rant...
PPPS: Also be aware that many of the people who know me well would object to the "tiny bit" part...
Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion
"... after all, He's not a tame lion..."
Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps -
Trying to parse a file-read from text file.vi
I'm attempting to read a txt file that has tab separated data. In the fourth (or any) column is the only data I need. The data is a string of numbers (23.454).
I've used the Read from Text File.vi and the Read From Spreadsheet.vi and I just don't seem to have enough LV background to extract the pertinent data into a graph. any suggestions?(It is silly to use "delete from array" if all you want is a column. The correct function is "index array")
Joe's idea above basically works fine. Here's a quick adapdation (the node before the graph is "index array" from the array palette.).
Message Edited by altenbach on 06-11-2007 11:57 AM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
FileRead.png 11 KB -
How can i read the text files and buffer the data in Vector?
hi. I have been running into this problem for days, but with no luck and losing right direction.
The problem is : I am trying to read a text file and buffer the data into a
Queue for each user.
the sample text file is as below:( 1st column is timestamp, 2nd is user_id, 3rd is packet_id, 4th is packet_seqno, 5th is packet_size)
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512
17 8 2 18 512
18 9 2 19 512
19 10 2 20 512
20 1 3 21 512
21 2 3 22 512
22 3 3 23 512
23 4 3 24 512
24 5 3 25 512
25 6 3 26 512
26 7 3 27 512
27 8 3 28 512
28 9 3 29 512
29 10 3 30 512
30 1 4 31 512
31 2 4 32 512
32 3 4 33 512
33 4 4 34 512
34 5 4 35 512
35 6 4 36 512
36 7 4 37 512
37 8 4 38 512
38 9 4 39 512
39 10 4 40 512
40 1 5 41 512
41 2 5 42 512
42 3 5 43 512
43 4 5 44 512
44 5 5 45 512
45 6 5 46 512
46 7 5 47 512
47 8 5 48 512
48 9 5 49 512
49 10 5 50 512
50 1 6 51 512
51 2 6 52 512
52 3 6 53 512
53 4 6 54 512
54 5 6 55 512
55 6 6 56 512
56 7 6 57 512
57 8 6 58 512
58 9 6 59 512
59 10 6 60 512
60 1 7 61 512
61 2 7 62 512
62 3 7 63 512
63 4 7 64 512
64 5 7 65 512
65 6 7 66 512
66 7 7 67 512
67 8 7 68 512
68 9 7 69 512
69 10 7 70 512
70 1 8 71 512
71 2 8 72 512
What I wanna do is to read all the data above and buffer them in a queue for each user( there are only 10 users in total).
I already created a class called Class packet:
public class packet {
private int timestamp;
private int user_id;
private int packet_id;
private int packet_seqno;
private int packet_size;
/** Creates a new instance of packet */
public packet(int timestamp,int user_id, int packet_id,int packet_seqno, int packet_size)
this.timestamp = timestamp;
this.user_id=user_id;
this.packet_id=packet_id;
this.packet_seqno=packet_seqno;
this.packet_size=packet_size;
}then I wanna to create another Class called Class user which I can create a queue for each user (10 users in total) to store type packet information. the queue for each user will be in the order by timestamp.
any idea and sample code will be appreciated.Doesn't sound too hard to me. Your class User (the convention says to capitalize class names) will have an ArrayList or Vector in it to represent the queue, and a method to store a Packet object into the List. An array or ArrayList or Vector will hold the 10 user objects. You will find the right user object from packet.user_id and call the method.
Please try to write some code yourself. You won't learn anything from having someone else write it for you. Look at sample code using ArrayList and Vector, there's plenty out there. Post in the forum again if your code turns out not to behave. -
Read a text file and populate table
My email addres is [email protected]
I am new to java. My project requires me to read a text file and pick some values from the text file and populate a table in MS Access. The main fields are from the TEXT. Some of the columns to be read are:
Transaction ref.
Amount
User ref.
Date
The text file is as follows:
Receiver =
FBNINGLAXXX LT : A
FST BANK OF NIGERIA PLC
LAGOS
LAGOS
NG
NIGERIA
Transaction ref. = SPLOUK01P0008888 Related ref. = 00077003
Amount = 16675750, NGN Value/Date =
Format & Validation
Version = 0205 Checked = Minimum
Netw. Appl. = FIN Passed = Minimum
Sender to Receiver Instructions
Banking Prior. = User ref. = SPLOUK01P0008888
Warning Status =
Possible Duplicate Emission
Appl/Serv = SWIFT Interface
RP & Ft = SIfrom_SWIFT
Date/Time = 01/04/03 18:53:19
Text =
:20:SPLOUK01P0008888
:28D:1/1
:30:030401
:21:00077003
:32B:NGN16675750,00
:50H:/4072010014877
SPDC FBN East Main A/C
:57D:WEMA BANK PLC
PLOT 22 TRANS-AMADI BRANCH P.H.
PORT HARCOURT.
RIVERS STATE.
:59:/0421002101818
PROJECT MASTERS NIGERIA LTD.
C101 ELIOGBOLO VILLAGE OFF
EAST-WEST ROAD RUMUOKORO PORT HAR
COURT
:70:PM PCE-TS 03 001030226
:71A:OUR
Block 5:
{MAC:9F664844}{CHK:60EF6513E579}
Message History =
*Original (Completed)See in this case as you are dealing with Files and database. you need read the File by using the I/O Streams. if you have to select some particular values you can go Random access file.Once you have retrived values. You can go for the second part that is make a jdbc connection to database, and use simple SQL statements to populate those values into the table.
How this will give you a better picture -
Read multiple text files and sort them
I am trying to read multiple text files and store the data from the file in vector.
but for days. I am with no luck. anyone can help me out with it? any idea of how to sort them will be appreciated.
Below is part of the code I implemented.
public class packet {
private int timestamp;
private int user_id;
private int packet_id;
private int packet_seqno;
private int packet_size;
public packet(int timestamp0,int user_id0, int packet_id0,int packet_seqno0, int packet_size0)
timestamp = timestamp0;
user_id=user_id0;
packet_id=packet_id0;
packet_seqno=packet_seqno0;
packet_size=packet_size0;
public void setTime(int atimestamp)
this.timestamp=atimestamp;
public void setUserid(int auserid)
this.user_id=auserid;
public void setPacketid(int apacketid)
this.packet_id=apacketid;
public void setPacketseqno(int apacketseqno)
this.packet_seqno=apacketseqno;
public void setPacketsize(int apacketsize)
this.packet_size=apacketsize;
public String toString()
return timestamp+"\t"+user_id+"\t"+packet_id+"\t"+packet_seqno+"\t"+packet_size+"\t";
}Here is the data from part of the text files. ( the first column is timestamp, second is userid, third is packetid.....)
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512Here's a standard idiom for object-list-sorting:
/* cnleafdata.txt *********************************************
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512
import java.util.*;
import java.io.*;
public class Packet implements Comparable<Packet>{
private int timeStamp;
private int userId;
private int packetId;
private int packetSeqno;
private int packetSize;
public Packet(int timeStamp0, int userId0, int packetId0,
int packetSeqno0, int packetSize0) {
timeStamp = timeStamp0;
userId = userId0;
packetId = packetId0;
packetSeqno = packetSeqno0;
packetSize = packetSize0;
public Packet(String timeStamp0, String userId0, String packetId0,
String packetSeqno0, String packetSize0) {
this(Integer.parseInt(timeStamp0), Integer.parseInt(userId0),
Integer.parseInt(packetId0), Integer.parseInt(packetSeqno0),
Integer.parseInt(packetSize0));
public Packet(String[] a){
this(a[0], a[1], a[2], a[3], a[4]);
public void setTime(int aTimeStamp){
timeStamp = aTimeStamp;
public void setUserId(int aUserId){
userId = aUserId;
public void setPacketId(int aPacketId){
packetId = aPacketId;
public void setPacketSeqno(int aPacketSeqno){
packetSeqno = aPacketSeqno;
public void setPacketSize(int aPacketSize){
packetSize = aPacketSize;
public int getUserId(){
return userId;
public String toString(){
return String.format
("%2d %2d %2d %2d %4d", timeStamp, userId, packetId, packetSeqno, packetSize);
public int compareTo(Packet otherPacket){
return userId - otherPacket.getUserId();
/* main for test */
public static void main(String[] args){
String line;
ArrayList<Packet> alp;
alp = new ArrayList<Packet>();
try{
BufferedReader br = new BufferedReader(new FileReader("cnleafdata.txt"));
while ((line = br.readLine()) != null){
// if (! recordValid(line)){
// continue;
String[] ar = line.split("\\s");
alp.add(new Packet(ar));
catch (Exception e){
e.printStackTrace();
System.out.println("[original]");
for (Packet p : alp){
System.out.println(p);
System.out.println();
Collections.sort(alp);
System.out.println("[sorted by user ID]");
for (Packet p : alp){
System.out.println(p);
} -
Why does Read from Text file default to array of 9 elements
I am writing to a text file starting with a type def. cluster (control) of say 15 dbl numeric elements, that works fine I open the tab-delimited text file and all of the elements appear in the file. However when I read from the same text file back to the same type def. cluster (indicator), the read from text file defaults to 9 elements?? Is there a way to control how many elements are read from the file. This all works great when I initially use a cluster of 9 elements and read back to a cluster of 9 elements.
Solved!
Go to Solution.From the LabVIEW Help: http://zone.ni.com/reference/en-XX/help/371361G-01/glang/array_to_cluster/
Converts a 1D array to a cluster of elements of the same type as the array elements. Right-click the function and select Cluster Size from the shortcut menu to set the number of elements in the cluster.
The default is nine. The maximum cluster size for this function is 256.
Aside: so, how many times has this question been asked over the years? -
How to open saved files using 'read from text file' function
Hi everyone, I am having a hard time trying to solve the this particular problem ( probably because I am a newb to lanbview ). Anyway , I am able to save the acquired waveforms by using the 'Write to text file' icon. I did manually modify the block diagram of the 'Write to text file' icon and create the correct number of connector so as to make my program work. But now I have no idea on how to modify the block diagram of the 'Read from text file' block diagram to make my program 'open' my saved waveforms. Or i do not have to modify anything from the block diagram of the 'Read from text file'? Can anyone teach/help me connect up? Do i need the build array on the "open" page?
Here are some screenshots on part of my program
let me know if you guys would need more information / screenshots thank you!
Attachments:
ss_save.jpg 94 KB
ss_open.jpg 94 KB
modified_writetotextfile.jpg 99 KBOhmy, thanks altenbach. oh yeah i forgot about those sub VIs. will upload them now. Was rather demoralized after reading the comments and really struck me on how weak i'm at on labview really hope to get this done. But of course i have to study through and see how it works. Actually i am going to replace those 'signal generators sub vi' with ThoughtTechonology's sample code so i can obtain data waveforms real-time using Electrocardiography (ECG) ,Electromyography (EMG ) and Electroencephalography (EEG) hopefully i can find out how to connect the sample code.
( ps . cant connect it now unless my program is working otherwise labview will crash )
( p.s.s the encoder of my biofeedback trainer already acts as an DAQ so i wont need to place an DAQ assistant in my block diagram i suppose )
The sample code of ThoughtTechnology is named as attachment.ashx.vi. too bad i cant use it and present it as my project
Attachments:
frequency detactor.vi 53 KB
signal generator.vi 13 KB
attachment.ashx.vi 40 KB -
LabVIEW for ARM 2009 Read from text file bug
Hello,
If you use the read from text file vi for reading text files from a sdcard there is a bug when you select the option "read lines"
you cannot select how many lines you want to read, it always reads the whole file, which cause a memory fault if you read big files!
I fixed this in the code (but the software doesn't recognize a EOF anymore..) in CCGByteStreamFileSupport.c
at row 709 the memory is allocated but it tries to allocate to much (since u only want to read lines).
looking at the codes it looks like it supposed to allocated 256 for a string:
Boolean bReadEntireLine = (linemode && (cnt == 0));
if(bReadEntireLine && !cnt) {
cnt = BUFINCR; //BUFINCR=256
but cnt is never false since if you select read lines this is the size of the file!
the variable linemode is also the size of the file.. STRANGE!
my solution:
Boolean bReadEntireLine = (linemode && (cnt > 0)); // ==
if(bReadEntireLine) { //if(bReadEntireLine && !cnt) {
cnt = BUFINCR;
and now the read line option does work, and reads one line until he sees CR or LF or if the count of 256 is done.
maybe the code is good but the data link of the vi's to the variables may be not, (cnt and linemode are the size of the file!)
count should be the number of lines, like chars in char mode.
linemode should be 0 or 1.
Hope someone can fix this in the new version!
greets,
Wouter
Wouter.
"LabVIEW for ARM guru and bug destroyer"I have another solution, the EOF works with this one.
the cnt is the bytes that are not read yet, so the first time it tries to read (and allocate 4 MB).
you only want to say that if it's in line mode and cnt > 256 (BUFINCR) cnt = BUFINCR
the next time cnt is the value of the bytes that are not read yet, so the old value minus the line (until CR LF) or if cnt (256) is reached.
with this solution the program does not try to allocate the whole file but for the max of 256.
in CCGByteStreamFileSupprt.c row 705
if(linemode && (cnt>BUFINCR)){
cnt = BUFINCR;
don't use the count input when using the vi in line mode. count does not make sense, cnt will be the total file size. also the output will be an array.
linemode seems to be the value of the file size but I checked this and it is just 0 or 1, so this is good
update: damn it doesn't work!
Wouter.
"LabVIEW for ARM guru and bug destroyer" -
Set a timeout for "read from text file"
I Need to read from a text file on a remote pc and use the read from text file function to do this. It wotks but sometimes this pc is down causing long wait times in my vi.
Is there a way to set a timeout for the read from text file function, or is there an other solution?
Thank youYou could check that the path is valid first before you attempt to read the file. hen put the file read in a True-False case structure based on the results of the check. You can use the function "Check if File or Folder Exists" It checks whether a file or folder exists on disk at a specified path. This VI works with standard files and folders as well as files in LLB files. The function is found in the File I/O --> Advanced File Functions palette.
Tom -
Read from text file vi won't read file...
I am very new to LV programming so I hope you forgive any stupid mistakes I am making. I am using Ver. 8.2 on an XP machine.
I have a small program that stores small data sets in text files and can update them individually or read and update them all sequentially, sending the data out a USB device. Currently I am just using two data sets, each in their own small text file. The delimiter is two commas ",,".
The program works fine as written when run in the regular programming environment. I noticed, however, as soon as I built it into a project that the one function where it would read each file sequentially to update both files the read from text file vi would return an empty data set, resulting in blank values being written back into the file. I read and rewrite the values back to the text file to place the one updated field (price) in it'sproper place. Each small text file is identified and named with a 4 digit number "ID". I built it twce, and get the same result. I also built it into an installer and unfortunately the bug travelled into the installation as well.
Here is the overall program code in question:
Here is the reading and parsing subvi:
If you have any idea at all what could cause this I would really appreciate it!
Solved!
Go to Solution.Hi Kiauma,
Dennis beat me to it, but here goes my two cents:
First of all, it's great to see that you're using error handling - that should make troubleshooting a lot easier. By any chance, have you observed error 7 when you try to read your files and get an empty data set? (You've probably seen that error before - it means the file wasn't found)
If you're seeing that error, the issue probably has something to do with this:
Relative paths differ in an executable. This knowledge base document sums it up pretty well. To make matters more confusing, if you ever upgrade to LabVIEW 2009 the whole scheme changes. Also, because an installer contains the executable, building the installer will always yield the same results.
Lastly, instead of parsing each set of commas using the "match pattern" function, there's a function called "spreadsheet string to array" (also on the string palette) that does exactly what you're doing, except with one function:
I hope this is helpful...
Jim -
'read from text file' erases the file
I am trying to read text in from a text file. This is the exact code I am using. For some reason the output from 'read from text file' contains all the text that was originally in the file, but after the code executes the file is empty. I have several other vi's which use the same code and the file is fine. But whenever I run this code in this one specific vi the text file gets erased.
What is in the rest of that "specific vi"? I just tried the code you show, in v2011, and it works as expected, doesn't clear file.
What version are you running? Can you add an error out, or make sure error output is on in your LabVIEW configuration?
Putnam
Certified LabVIEW Developer
Senior Test Engineer
Currently using LV 6.1-LabVIEW 2012, RT8.5
LabVIEW Champion -
Read from Text File - Help Bug?
Hi - I am currently working on LV8 and I think that there is some misunderstanding potential in the help file. To be more exact in the help to the "Read From Text File" VI.
The description for "count":
" ... If count is <0, the function reads the entire file. The
default is –1, which indicates to read a single line if you placed a checkmark
next to the Read Lines shortcut menu item and to read the
entire file if you removed the checkmark next to the item. "
If count is lower than zero, the function reads the entire file. That sounds clear to me.
The default is -1, which indicates to read a single line if you placed a checkmark next to the "Read Lines" shortcut menu item. Now what? Does it read a single line or the whole file?
.. and to read the entire file if you removed the checkmark next to the item. I thought it reads the whole file if I use -1 ?
the VI itself behaves as I'd expect it to:
* If I place a checkmark next to Read Lines and put -1, I get an array containing the lines
* If I remove the checkmark, I get only a single string item.
Now where is the error? Is the VI not working properly or only the description a little bit ... strange ??hein??
?what?
Both you guys lost me..
And I drink coffee without sugar (being sweet enough, already)
Here is what I get from Context Help on the Read From Text File:
Read from Text File
Reads a specified number of characters or lines from a byte stream file. By default, this function reads all characters from the text file. Wire an integer value to count to specify how many individual characters you want to read starting with the first character. Right-click the function and place a checkmark next to the Read Lines option in the shortcut menu to read individual lines from the text file. When you select the Read Lines option in the shortcut menu, wire an integer value to the count input to specify how many individual lines you want to read from the file starting with the first line. Enter a value of -1 in count to read all characters and lines from the text file.
Humm.
New feature (again).. If you select checkmark the Read Lines option, it will not send the text to a sting indicator, as shown in the attached image. If selected, then it's expecting to write lines to an array of strings... WHY??? I don't know.. I'll ask..
Strange... LV8 is full of mysteries...
RayR
Attachments:
bad write file.JPG 33 KB
more bad write file.JPG 12 KB
Maybe you are looking for
-
I was reading the documentation for the media and all other related classes, and while there is functionality for video and audio playback, there doesn't seem to be any exposed lower level functionality in order to do things such as simple video and
-
Errors during LIST BACKUP after backup
Checking my backup logs for ORA- or RMAN- errors brought up this: RMAN-06900: WARNING: unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row RMAN-06901: WARNING: disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT rows ORACLE error from tar
-
Is anybody running Spector on an Intel based iMac or had any experience running Spector on an Intel based iMac. There are some postings recording Spector but nothing referencing it being run on an Intel iMac. I have tried contacting Spectorsoft but g
-
Hi, What is the field for "Business Unit" in SAP FICO table. What FICO table does it store this field ? Regards, Rajesh.
-
Where to download Developer Workspace SR2 (NW 7.0 Java Trial Version)
Hi together, I bought a Portal-Developement book with some very interessting tutorials. For this book the SAP NW 7.0 Java Trial Version (including Developer Workspace SR2 and Developer Studio) is recommended. Here in SDN I just found SAP NetWeaver Co