![]() |
|
#1
|
|||
|
|||
Multidimensional ArrayI'm trying to read in a file of data that has multiple lines that contain a date, timestamp, and other data. What I'm wanting to do is use the timestamp, and only print out every 4th second worth of data by line. I was thinking of using a multidimensional array, but not sure how. Here is the first few lines of the file:
Code:
The array I've created is PHP Code:
I'm pretty familiar with the file i/o, but just need help with the script to sort the lines by the timestamp. Thank you. Last edited by phrygianphreak : 21-Oct-2005 at 10:11.
Reason: Please insert your Php code between [php] & [/php] tags
|
|||
|
#2
|
||||
|
||||
Re: Multidimensional ArrayQuote:
Hello and Welcome to GIDForums™ phrygianphreak. By every fourth second do you mean if you get the first timestamp seconds, (in your example 15) you would like to print out that line and then not print out another until 4 seconds have passed (in this case 19 or higher)? Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#3
|
|||
|
|||
Re: Multidimensional ArrayWhat I mean is that I want to output the first line, with the 13:44:15 timestamp, then skip 4 seconds and print out the line with 13:44:20, and so on in that fashion until all the lines have been printed out. Does that make sense?
|
|
#4
|
||||
|
||||
Re: Multidimensional ArrayHello phrygianphreak,
I assume you've already seen this page: http://www.desilva.biz/arrays/filter.html? Because you left out a lot of details, I will assume a lot of things about the data file. If you look at your example data file, you will notice that the record for 13:44:18 is missing. I'll assume that data is recorded every second and that there is no duplicate timestamps and no missing seconds. Also I'll asume new records are appended to the data file. In other words, the last record is right at the bottom of the file, as it is in your example file. Having assumed all that, here's how my dataarray.PHP will look like (please read comments to understand what it's supposed to do): PHP Code:
I just tried this script (with your example data file) and it fails only when you use INTERVAL=3, since the record for the 18th second is missing! __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#5
|
|||
|
|||
Re: Multidimensional ArrayThat's perfect,JdS. Your assumptions must have been pretty intuitive because it did exactly what I wanted it to!
Thank you! |
|
#6
|
|||
|
|||
Re: Multidimensional ArrayI was going over the data after it got processed, and for some reason it stops halfway through the file. The file goes up to about 14:00:55, but for some reason it stops at 13:50:10. I tried increasing the numbrer in the EOF from 4096 to a higher number, but that doesn't seem to have any affect on the file.
Here's the file if you want to try it. |
|
#7
|
|||
|
|||
Re: Multidimensional ArrayHey, JdS, did you get my last post? I need to see if I can get the code to read the whole file.
Thanks! |
|
#8
|
||||
|
||||
Re: Multidimensional ArrayI already mentioned that the script will fail if there are missing seconds.
If you analysed and understood how the example script works, you would have figured this out yourself too. __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#9
|
|||
|
|||
Re: Multidimensional ArrayUnfortunately, it does sometimes skip a second, and there are duplicate seconds. Is there no way around this?
|
|
#10
|
||||
|
||||
Re: Multidimensional ArrayOf course there is a way around; there is always a way around.
Like I said, you didn't supply a lot of details with your original question, so I had to assume a lot of essential details. To fix this example to work for you, you just simply need to convert the formatted time string i.e. 13:44:23 into a unixtimestamp for each row. You compare that value to the next interval's unixtimestamp. If it fails to match, you must test to see if this row's unixtimestamp is later than the interval's timestamp. If it's true, you set the next, new interval timestamp and proceed. __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pointer Usage in C++: Beginner to Advanced | varunhome | C++ Forum | 0 | 19-Aug-2005 10:25 |
| template comiling problems - need expert debugger! | crq | C++ Forum | 1 | 01-Feb-2005 22:26 |
| Linear search on a multidimensional array. | anignna | C++ Forum | 4 | 07-Mar-2004 21:07 |
| Array_search on a multidimensional array | JdS | MySQL / PHP Forum | 3 | 11-May-2003 07:22 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The