Origin Version (Select Help-->About Origin): 7.5 pro Operating System: Win XP pro
Greetings all,
My problem is this - I am sorting through a large data set to extract the data I wish to plot - easy enough. My X column has date / time values (probably as strings when imported) in the from dd/mm/yyyy hh:mm:ss. What I need to do is calculate relative time from these date / time values i.e. when I have found the point at which to start extracting data need to set the time to 0 and compute subsequent times relative to this. Unfortunately I cannot rely on all the time intervals being the same.
I think that the way to do this would be to convert the values into seconds since the epoch and then use these values to convert to relative time. I cannot seem to find an easy way to do this so is it possible? Another thing I have found is that if you set the format of the date / time column to type DATE in Origin C you seem to lose the hh:mm:ss. Can this be got round as well.
If the date column is properly formatted you can read its values as doubles (Julian date) rather than strings so your two problems are closely related. When importing the dates as strings it's probably best to format the column prior to importing...
Worksheet wks; wks.Create("Origin"); wks.Columns(0).SetFormat(OKCOLTYPE_DATE); wks.Columns(0).SetSubFormat(10); // subformat index (yours may be different) // import data Dataset dd(wks,0); int nRows = dd.GetSize(); // total number of rows printf("Total span = %g days\n",dd[nRows-1] - dd[0]); // elapsed time in days
If you use the Import Wizard or simple Import ASCII it might be easier to use a wks template on which the date column is already formatted.
...Turns out that it probably doesn't matter if you format the column before or after importing. You just need to use the proper subformat index. Following code returns the elapsed time for the active wks.
Worksheet wks = Project.ActiveLayer(); if( !wks ) return; wks.Columns(0).SetFormat(OKCOLTYPE_DATE); wks.Columns(0).SetSubFormat(10); // your subformat index may be different Dataset dd(wks,0); int nRows = dd.GetSize(); // total number of rows printf("Total span = %g days\n",dd[nRows-1] - dd[0]); // elapsed time in days
I glossed over the specifics of your date format which requires special treatment. Yours is not one of Origin's standard date formats so you also need to do the following.
1> Select Tools > Options and click the Miscellaneous tab.
2> Enter the following for one of the Custom Date Formats...
dd'/'MM'/'yyyy hh':'mm':'ss
3> If you defined your format as Custom Format 1 use 19 for the index in the SetSubFormat() function. If you defined it as Custom Format 2 use 20.
Thanks for your help Mike. I have tried your first suggestion and it certainly has worked for one import i.e. set column format after import as subformat 10 - which is actually listed in the format dialog as 18/11/2004 08:43:78 or something similar.
Anyway if I run into problems I can do what you suggest with setting my own custom format.
I now have to try the time computation which as you suggest shouldn't be too difficult now.