-1

I have a few hundred data files, each comprising of a 3 line header and a single column of sampled data values. In the header there is are multiple fields including a time field which gives the time the file was created e.g. "Time=10:00:00.156", sampling time "Tsamp=0.1000" and "TimeUnits=1.0000E-06" (i.e. time interval between data values in file = 0.1 microSeconds). I want to use this information to create a vector of times for each of the acquired data values in the file.

How can I do this? I tried chron and zoo libraries and the differnt ts functions but couldn't do it. Any help would be sincerely appreciated.

I would like to be able to put this into a script so that I can process all the files automatically. what I would like to end up with is a data frame with two columns showing the concatenated times for all of the above files in column 1 and the concatenated measured values for all of the above files in column 2.

ATF v1.00 Date=23-01-2012; 
Time=10:38:56.421000; 
TracePoints=16384; 
TSamp=0.100000; 
TimeUnits=1.00000e-006; 
AmpToVolts=1.0000;
TraceMaxVolts=0.10000; 
PTime=0.00000; 
STime=0.00000; 
[TraceData] 
 4.82178e-004 
-1.37329e-003 
2.19116e-003 
4.38843e-003 
1.65405e-003 
3.36304e-003 
5.95093e-003 
2.19116e-003

Again any help would be appreciated.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • 3
    Can you post a first few lines/columns of the file? – Roman Luštrik Feb 02 '12 at 11:26
  • Hello Ronan, Yes I can add some lines of the file. – user1184891 Feb 03 '12 at 09:59
  • Yes. The file has 3 header lines as follows: ATF v1.00 Date=23-01-2012; Time=10:38:56.421000; TracePoints=16384; TSamp=0.100000; TimeUnits=1.00000e-006; AmpToVolts=1.0000; TraceMaxVolts=0.10000; PTime=0.00000; STime=0.00000; [TraceData] This is followed by a single column of data 4.82178e-004 -1.37329e-003 2.19116e-003 4.38843e-003 1.65405e-003 3.36304e-003 5.95093e-003 2.19116e-003 There are a few hundred of these files, each containing approx 20000 data points. Any help is appreciated. Thanks. Will – user1184891 Feb 03 '12 at 10:06
  • Please add this to your question and format it properly (use the curly braces icon). – Roman Luštrik Feb 03 '12 at 13:43

1 Answers1

0

I edited your question to include the data you put in your comment. Using a textConnection is very similar to accessing a file, but you may need to use the skip option if you first usereadLines and then use read.table , since I'm not sure that the file connection will always be kept open with those two functions on a file. I do not think you will be able to convert the sub-millisecond data to R time classes, since the precision of time data is consumed by the need to represent decades on a millisecond resolution and there just are not enough extra digits in the mantissa of an eight byte number. The zoo package does not require time as the index so you are free to use either sequence number or a "numeric" time scale rather than a 'time" time scale.

txt <- textConnection("ATF v1.00 Date=23-01-2012; 
Time=10:38:56.421000; 
TracePoints=16384; 
TSamp=0.100000; 
TimeUnits=1.00000e-006; 
AmpToVolts=1.0000;
TraceMaxVolts=0.10000; 
PTime=0.00000; 
STime=0.00000; 
[TraceData] 
 4.82178e-004 
-1.37329e-003 
2.19116e-003 
4.38843e-003 
1.65405e-003 
3.36304e-003 
5.95093e-003 
2.19116e-003")

headers <- readLines(txt, n=9)
tracedat <- read.table(txt, header=TRUE)

closeAllConnections()

 headers
#-----------------
[1] "ATF v1.00 Date=23-01-2012; " "Time=10:38:56.421000; "     
[3] "TracePoints=16384; "         "TSamp=0.100000; "           
[5] "TimeUnits=1.00000e-006; "    "AmpToVolts=1.0000;"         
[7] "TraceMaxVolts=0.10000; "     "PTime=0.00000; "            
[9] "STime=0.00000; "      
# ----------      
tracedat
#-----------------
  X.TraceData.
1  0.000482178
2 -0.001373290
3  0.002191160
4  0.004388430
5  0.001654050
6  0.003363040
7  0.005950930
8  0.002191160
IRTFM
  • 258,963
  • 21
  • 364
  • 487