The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Computing relative time
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

greadey

UK
Posts

Posted - 11/08/2005 :  04:12:42 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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.

regards,

greadey



Mike Buess

USA
3037 Posts

Posted - 11/08/2005 :  06:48:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi greadey,

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

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 11/08/2005 07:16:44 AM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 11/08/2005 :  08:31:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.

Mike Buess
Origin WebRing Member
Go to Top of Page

greadey

UK
Posts

Posted - 11/08/2005 :  11:02:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.

Anyway, once again, thanks for your help.

Greadey

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000