LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching a file for a string

Hey all,
I am having a problem searching a file for a particular date. I have a file that contains temperatures and timing information. I need to be able to search the file for a particular date/time.
I would like it to then read all the temperatures following that date/time.
Is this possible???
Any help at all would be really appreciated!!!
Thanks
Maria
0 Kudos
Message 1 of 15
(3,109 Views)
It should be possible if the data has any unique identifier, i.e. the date. Could you attach a sample of the data file (doesn't have to be too big just with some data before and after the point you want to read). Also, what format is the data (comma seperated variables (CSV) or tab delimited or ?). How long is the expected file? If it is very large it will change the way the data is parsed. Also, what version of LabVIEW are you using?



Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 15
(3,103 Views)
Hey,
Thanks for getting back to me.
I am using labview version 7.1. The file is a .txt file and is layed out as follows:
43    Wed Mar  7 20:04:01 GMT 2007
42    Wed Mar  7 20:05:02 GMT 2007
42    Wed Mar  7 20:06:01 GMT 2007
etc......etc.....
The first values are the temperatures. What I want to do is to search the file for a particular date/time and to then read all the temperature values from that date/time onwards.
Will it be possible for me to do something like this???
Thanks for getting back to me so quickly,
Maria
0 Kudos
Message 3 of 15
(3,100 Views)
Yes, it should be relatively easy. Are the data seperated by spaces? How big are the files? If they aren't too big you could read the rows into an array of strings, using whatever "end of line" charecter you are using. Then parsing through each array element until you find the one you are looking for, giving you the point in the array where the data of interest starts.

I'm not currently on a machine with LV 7.1 so I can't give you an example just yet.


Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 4 of 15
(3,094 Views)
Hey,
The files are going to be quite large as they read in the temperature every minute while the machine is running. I will attach a copy of the file if this helps but I do not know how large they will get.
Thanks for getting back to me.
Maria

0 Kudos
Message 5 of 15
(3,091 Views)
Hi Maria,
I have made a vi that should do what you need. You have to expand the list of month names in the "Get Timestamp from String 2.vi". "TempandTime.vi" is the main VI.
Greets, Dave


Message Edited by daveTW on 03-08-2007 08:17 PM

Greets, Dave
0 Kudos
Message 6 of 15
(3,063 Views)
Hey,
Thank you very much!!!
Sorry to be a pain........but is there any way you could save those vi's so that I can open them??? I am using Labview version 7.1.
That would be great,
Thanks,
Maria
0 Kudos
Message 7 of 15
(3,059 Views)
Hi Maria,
sorry, but I only have 8.2 on my computer. But I attach pictures of the block diagrams so you can wire it yourself. I hope this helps. Perhaps anybody else can resave it.
Greets, Dave


TempandTime Doc.vi
It reads the file into a string and makes with "spreadsheet string to array" a 2D- Array, in every row the first element is the temperature (as a string, not a number), the second element is the Date&Time string. The SubVI "Get Timestamp from String 2.vi" then converts the string to a timestamp. If the time is later than the [Start Time] it will be appended to the array in the shift register.



Get Timestamp from String 2.vi
This is the subVI of TempandTime.vi



Message Edited by daveTW on 03-09-2007 10:25 AM

Greets, Dave
Download All
0 Kudos
Message 8 of 15
(3,044 Views)
When doing this sort of thing, remember it is always faster to read a chunk of data from the disk and analyze it from memory.  The optimum size to read from a Windows disk (FAT32 or NTFS) is about 65,000 bytes.  I usually create a set of VIs to handle the details of this chunked read, using some sort of cluster to keep track of the details (e.g. location in the file, whether or not you are at end-of-file, how much data you have unprocessed).  In your case, I would read in data a chunk at a time, doing a match pattern on each chunk to find the date (pay attention to chunk boundaries, you don't want to miss the date because it is split between two chunks).  After finding the date, I would read in the data a chunk at a time and process it in chunks.

You can find an example of this type of approach in the Read LVM Express VI.  If you start opening front panels, you will notice a cluster called file refs in or file refs out.  See ex_FileReadAll.vi, for example.  This is the file data used by the LVM read to keep track of chunks.  Processing occurs on the chunks in memory.  An example would be ex_GetOneLineFromChunk.vi, which extracts a single line from the chunk.  If there is not another line in the existing chunk, it fetches another chunk from the file.  These VIs are found in <vi.lib>/express/express input/ExFileReadBlock.llb.

Note that some of these VIs are generic enough that you can use them in your code.  Be careful to make copies and use the copies.  Since these VIs are not explicitly on the palette, their interfaces may change on different LabVIEW versions.  You may also want to make the info cluster into a typedef to allow easier development.

Let us know if you need more help.
0 Kudos
Message 9 of 15
(3,027 Views)
Hi Guys,
Thanks again for all your help. Now I am really new to Labview so I hope that ye won't mind me asking some stupid questions. I have been trying to wire up your suggested VI's but there are somefunctions that I cannot find!!!
I don't know if it is that my version of labview doesn't have these functions or I am just looking in the wrong place (probably this one!!!)
Anyway I am attaching a picture of the fuctions so if anyone would be kind enough to tell me where to find these I would be extremely grateful.
Thanks Again,
Maria
0 Kudos
Message 10 of 15
(3,020 Views)