From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Loading IRIG time format via plug-in wizard

Solved!
Go to solution

Greetings!  I'm sure this has already been asked and answered but I can't seem to find it, so please point it out to me!  I have a csv file with the first column in (what I call) IRIG time format, e.g. "277 18:25:30.123456".  I would like to use the data plug-in wizard to develop a plug-in to load this data set.  In the wizard I am defining the time format to be "DDD hh:nn:ss.ffffff".  After loading, the Time channel shows e.g. "10/05/0000 18:25:30.1234".  I understand the year being all zeros as there was no year information given to start with, but day 277 should be October 4th, not the 5th.  Why the 5th?  Once the Time channel is in the Portal what is then the easiest, most straightforward method of changing the year "0000" to "2017" for all the channel elements?  Thanks!

0 Kudos
Message 1 of 7
(3,107 Views)

The day in year depends on the year (leap day).

 

When loaded to DIAdem you can easily add the offset by using a script.

Option Explicit

' Get offset from 01/01/0000 in seconds by converting CDate to R1(float64) variable
R1 = Data.Root.Properties("datetime").Value ' e.g. DateSerial(2017,1,1)
' Add Offset to channel ([1]/[1] is the Time Channel of the example.tdm file)
dim resultChn : Set resultChn = ChnOffset("[1]/[1]","result/Time",R1,"free offset")
' Was no date channel so we have to set it to Time
resultChn(1).Properties("displaytype").Value = "Time"

In the script I assume that the DIAdem default example is loaded.

Should work for your case too. The time channel is relative to 0.

I add the "Storage Date/Time" as offset.

If one of the build in float64 variables is used Dates can be converted to offset in seconds.

0 Kudos
Message 2 of 7
(3,084 Views)

AndreasK, thanks for the quick response and I apologize for my late reply!  Normally I solve "time" issues like IRIG in DIAdem with explicit numeric calculation then re-type the channel to a time-type.  Your code has shown me some nifty new things.  I'm still not understanding why day-of-year 277 is converted to 5 Oct when doy 277 in a leap year is 3 Oct and 4 Oct in a non-leap year, but we can adapt:

Yr = DateSerial (2017, 1, 0)

Set oIRIG = Data.Root....Channels("IRIG")

Set oTime = Data.Root...Channels.Add("Time", DataTypeFloat64)

Call ChnOffset (oIRIG.Name, oTime.Name, Yr, "free offset")

oTime.Properties("displaytype").Value = "time"

 

Note that the "5 Oct" issue has been dealt with by specifying "(2017, 1, 0)" rather than the usual "(2017, 1, 1)".  Normally I would have subtracted 86400 seconds.

0 Kudos
Message 3 of 7
(3,028 Views)
DateSerial (2017, 1, 0)

using zero means 12/31/2017.

 

What does 1 mean in your time format?

I interpret it in a way that 24 hours alrady used up.

Does your time start with "0 00:00:00" or "1 00:00:00".

 

I assume you are 1 based and thats where the 24 hours come in. Right?

0 Kudos
Message 4 of 7
(3,024 Views)

Yes, the DateSerial (2017, 1, 0) equates to 12/31/2016 which is how I am subtracting one day from the time to account for the day-of-year 277 = 5 Oct issue.  I can run doy 277 through all of my IRIG gear or any on-line date calculator and get 4 Oct (non-leap) or 3 Oct (leap year) but when I feed it to DIAdem it returns 5 Oct.  IRIG deals with time the same way any calendar and 24 hour clock deals with time; there is no day "zero", day 1 is 1 Jan no matter what what time it is, e.g. 1 Jan 1:23 AM is IRIG "001 0123".  

0 Kudos
Message 5 of 7
(3,020 Views)
Solution
Accepted by topic author Chris_H1

So thats where your day comes in.

 

When the dataplugin gets the ddd for day without year and month it assumes zero based days.

When we introduced this there was an 0 based format starting with day zero while the IRIG format is 1 based for days.

 

So your solution with DateSerial (2017, 1, 0) is a perfect solution for your data.

 

Message 6 of 7
(3,018 Views)

Ah, that explains it!  On a side note I always thought it was a bit weird that DIAdem time began at year "0000" even though technically our calendar transitions from 1BC to 1AD without the year zero.  This makes more sense now.  Thanks, AndreasK, for answering all my questions!

0 Kudos
Message 7 of 7
(3,013 Views)