I am looking for a function to extract the time duration from a series of .txt files with written dates/times and compile it into one time wave in Igor. This will provide a time wave as the independent variable for graphing purposes. Does anyone have something like this or at least close so I have a starting point...as I am new to the Igor programming language. Any help would be much appreciated. Thanks in advance.
Since you are asking for time duration, I am assuming that you want the amount of time it took to collect the data in a text file; is this correct? If you write the time values to the .txt file as header/footer information, you can extract it using the "Open" and "FReadLine" commands. Once you extract the date and time from the string which FReadLine returns, you can place these values into a wave. You can choose to either use a text wave and just enter strings, or format the information into the format for Igor date/time waves.
I don't have any code that utilized date/time waves so I hope this advice will get you started.
I am looking for a function to extract the time duration from a series of .txt files with written dates/times and compile it into one time wave in Igor
There is no built-in "duration" function that would compute time differences for arbitrary time formats.
If you are dealing with short term time differences, i.e., hours, minutes, seconds, then your best bet is to convert your dates/times into IGOR's format and simply subtract values to obtain a time difference in seconds. The latter you can convert into your resolution of choice.
If you are dealing with long term time differences, i.e., in days, months, etc., then your best bet is to convert each date into a Julian date (see DateToJulian) and then subtract the Julian dates from each other to obtain the number of days between two dates.
If these two choices do not cover your application please provide us with more details.
If you are dealing with long term time differences, i.e., in days, months, etc., then your best bet is to convert each date into a Julian date (see DateToJulian) and then subtract the Julian dates from each other to obtain the number of days between two dates.
You can obtain the number of days between dates stored in Igor date format by subtracting two values and dividing by the number of seconds in a day. I don't see the utility of converting to Julian which Igor can not display as dates in tables or graphs.
Thanks for all of the help so far, but let me clarify. I have my instrument taking readings over the course of three days. The instrument creates an output file, .txt, with a date and time stamp of the form, "DATE YY/MM/DD TIME HH:MM:SS" followed by a two column output of data that the instrument collects, of which I only need 1 column of the data. I currently have a macro that inputs all of the collected data that I need from multiple files into individual waves in Igor.
I would like to modify the macro or create a new function to extract the date and time from each of these files and create a "time" wave with points that represent the total elapsed time(in seconds) since the beginning of the experiment associated with each data wave. This way I can plot the number of seconds that have elapsed since the start of the experiment vs. the data for that particular time point on a graph.
I guess my two major questions are:
1. what is the loadwave suffix needed to extract the date from my file type?(example file is attached
2. how would I use the date2secs function to accomplish building this "timecourse" wave?
I would like to modify the macro or create a new function to extract the date and time from each of these files and create a "time" wave with points that represent the total elapsed time(in seconds) since the beginning of the experiment associated with each data wave.
Here is a function that will read the file and return and Igor date/time value representing the date and time:
Function LoadDateTime(fullPath) String fullPath // Full path to file
Variable refNum Open/R refNum as fullPath
String text Variable lineNum = 0 Variable dt
// Read lines till DATE line do FReadLine refNum, text if(strlen(text) == 0) Print"LoadDateTime: DATE not found" return0 endif if(CmpStr(text[0,3],"DATE") == 0) Variable year, month, dayOfMonth sscanf text, "DATE %d/%d/%d", month, dayOfMonth, year if(year <100)
year += 1900// Assume two-digit years are 20th century endif
dt = Date2Secs(year,month,dayOfMonth) break// End this loop endif
lineNum += 1 while(1)
// Read lines till TIME line do FReadLine refNum, text if(strlen(text) == 0) Print"LoadDateTime: TIME not found" return0 endif if(CmpStr(text[0,3],"TIME") == 0) Variable hour, minute, second sscanf text, "TIME %d:%d:%d", hour, minute, second Variable timeOfDay = second + 60*minute + 3600*hour
dt += timeOfDay break// End this loop endif
lineNum += 1 while(1)
return dt End
The LoadWave operation sets automatic local variables from which you can obtain the path to the file just loaded. You can use this to get the date/time from the file just loaded:
LoadWave ... String fullPath = S_path + S_fileName // S_path and S_fileName are set by LoadWave Variable dt = LoadDateTime(fullPath)
You can store this value in a wave. Make sure that it is a double-precision wave. In order to view it properly in a table or use to control graph axis, it must be set up to be an Igor date/time wave (double precision with data units set to "dat"). Execute this for further information on date/time waves:
DisplayHelpTopic"Date/Time Waves"// This help topic was added in Igor Pro 6.22
Once you have a wave containing the file date/times, you can create another wave containing the time relative to the first file like this:
Wave fileDateTimes // Assume this wave contains the file date/times Variable firstDateTime = fileDateTimes[0] Duplicate/O fileDateTimes, fileElapsedTimes
fileElapsedTimes -= firstDateTime
If you view these waves in a table, set the fileDateTimes colum format to Date&Time and set the elapsedDateTimes column to Time.
Quote:
1. what is the loadwave suffix needed to extract the date from my file type?(example file is attached
There is no LoadWave flag for this so you have to use a function like the one above.
Quote:
2. how would I use the date2secs function to accomplish building this "timecourse" wave?
Date2Secs is used in the LoadDateTime function to convert year, month and dayOfMonth to an Igor date/time value.
I don't have any code that utilized date/time waves so I hope this advice will get you started.
February 13, 2012 at 03:45 pm - Permalink
There is no built-in "duration" function that would compute time differences for arbitrary time formats.
If you are dealing with short term time differences, i.e., hours, minutes, seconds, then your best bet is to convert your dates/times into IGOR's format and simply subtract values to obtain a time difference in seconds. The latter you can convert into your resolution of choice.
If you are dealing with long term time differences, i.e., in days, months, etc., then your best bet is to convert each date into a Julian date (see DateToJulian) and then subtract the Julian dates from each other to obtain the number of days between two dates.
If these two choices do not cover your application please provide us with more details.
A.G.
WaveMetrics, Inc.
February 14, 2012 at 10:08 am - Permalink
You can obtain the number of days between dates stored in Igor date format by subtracting two values and dividing by the number of seconds in a day. I don't see the utility of converting to Julian which Igor can not display as dates in tables or graphs.
February 14, 2012 at 11:31 am - Permalink
I would like to modify the macro or create a new function to extract the date and time from each of these files and create a "time" wave with points that represent the total elapsed time(in seconds) since the beginning of the experiment associated with each data wave. This way I can plot the number of seconds that have elapsed since the start of the experiment vs. the data for that particular time point on a graph.
I guess my two major questions are:
1. what is the loadwave suffix needed to extract the date from my file type?(example file is attached
2. how would I use the date2secs function to accomplish building this "timecourse" wave?
Again thanks for the help
February 14, 2012 at 04:36 pm - Permalink
Here is a function that will read the file and return and Igor date/time value representing the date and time:
String fullPath // Full path to file
Variable refNum
Open /R refNum as fullPath
String text
Variable lineNum = 0
Variable dt
// Read lines till DATE line
do
FReadLine refNum, text
if (strlen(text) == 0)
Print "LoadDateTime: DATE not found"
return 0
endif
if (CmpStr(text[0,3],"DATE") == 0)
Variable year, month, dayOfMonth
sscanf text, "DATE %d/%d/%d", month, dayOfMonth, year
if (year < 100)
year += 1900 // Assume two-digit years are 20th century
endif
dt = Date2Secs(year,month,dayOfMonth)
break // End this loop
endif
lineNum += 1
while(1)
// Read lines till TIME line
do
FReadLine refNum, text
if (strlen(text) == 0)
Print "LoadDateTime: TIME not found"
return 0
endif
if (CmpStr(text[0,3],"TIME") == 0)
Variable hour, minute, second
sscanf text, "TIME %d:%d:%d", hour, minute, second
Variable timeOfDay = second + 60*minute + 3600*hour
dt += timeOfDay
break // End this loop
endif
lineNum += 1
while(1)
return dt
End
The LoadWave operation sets automatic local variables from which you can obtain the path to the file just loaded. You can use this to get the date/time from the file just loaded:
String fullPath = S_path + S_fileName // S_path and S_fileName are set by LoadWave
Variable dt = LoadDateTime(fullPath)
You can store this value in a wave. Make sure that it is a double-precision wave. In order to view it properly in a table or use to control graph axis, it must be set up to be an Igor date/time wave (double precision with data units set to "dat"). Execute this for further information on date/time waves:
Once you have a wave containing the file date/times, you can create another wave containing the time relative to the first file like this:
Variable firstDateTime = fileDateTimes[0]
Duplicate/O fileDateTimes, fileElapsedTimes
fileElapsedTimes -= firstDateTime
If you view these waves in a table, set the fileDateTimes colum format to Date&Time and set the elapsedDateTimes column to Time.
There is no LoadWave flag for this so you have to use a function like the one above.
Date2Secs is used in the LoadDateTime function to convert year, month and dayOfMonth to an Igor date/time value.
February 14, 2012 at 08:55 pm - Permalink