day of year hour minute to date?
pwright
such as:
2130630
2130730
2130830
etc....
these are the 213th day in 2006, at 6:30AM, 7:30AM, 8:30AM etc....
The year isn't specified in the data, so I will have to enter this manually somehow.
Does anyone have advice on how to do get this into a date and time wave?
I am trying to calculate this into seconds since 1/1/1904, then I can use the DateTime function.
If this works, I'm having trouble figuring out how many seconds IGOR figures is in a year. (it would be 31556925.947 sec using 365.242198781 days in a year)
Any advice would be great!!
Thank you,
Patrick
November 6, 2010 at 03:31 pm - Permalink
Constant secondsPerHour = 3600
Function EncodedDateToElapsedTime(encodedDateStr)
String encodedDateStr // e.g., "2130630"
Variable dayOfYear = str2num(encodedDateStr[0,2])
Variable hour = str2num(encodedDateStr[3,4])
Variable minute = str2num(encodedDateStr[5,6])
Variable result = kSecondsPerDay* dayOfYear + secondsPerHour*hour + 60*minute
return result
End
// ConvertToIgorDateTime(tw, year, outputName)
// tw is a text wave containing date/times encoded like this:
// 2130630 Day 213 of the specified year, time = 06:30
// Example:
// Make/T testIn = {"2130630", "2130730", "2130830"}
// ConvertToIgorDateTime(testIn, 2006, "testOut")
// Edit testIn, testOut
Function ConvertToIgorDateTime(tw, year, outputName)
Wave/T tw
Variable year // e.g., 2006
String outputName // Name for output wave
Variable numPoints = numpnts(tw)
Make/O/N=(numPoints)/D $outputName
Wave w = $outputName
SetScale d, 0, 0, "dat", w // Mark as date/time wave
Variable startOfYear = Date2Secs(year, 1, 1)
w = startOfYear + EncodedDateToElapsedTime(tw)
End
November 6, 2010 at 07:16 pm - Permalink