![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Outputting to table | amatuer_lee_3 | Shell Programming and Scripting | 3 | 05-15-2008 08:15 PM |
| Help in outputting the result in log files | dave_nithis | Shell Programming and Scripting | 23 | 09-28-2007 04:44 AM |
| Linux Going Big Time and Prime Time Against Windows, UNIX (WSJ) (Addict 3D) | iBot | UNIX and Linux RSS News | 0 | 06-21-2007 01:10 PM |
| Outputting from two input files. | Liguidsoul | Shell Programming and Scripting | 5 | 04-09-2007 11:31 PM |
| How To Provide Time Sync Using Nts-150 Time Server On Unix Network? | pesty | UNIX for Advanced & Expert Users | 2 | 03-21-2007 11:20 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Outputting a VMS quadword time in UNIX
I am writing a C program under UNIX which needs to write out a VMS quadword time for the current time (to a file)
This quadword is the number of 100 nanoseconds since 1858. I know I can easily get the time in secs since 1970 in UNIX/C. The problem is how to multiply by a rather large number (convert to nanoseconds) and add a rather large number (difference between 1858 and 1970 in 100 nanoseconds) in a language that hasnt got quadwords. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
You want to create a VMS quadword - they are 64 bit unsigned integers. By the way, the quadword date stores information down to the millisecond (1000th of a second).
You have to know what a long is on your Unix machine - they are not all the same - what Driver is asking. If a long is 32 bits, then you need to write out a long long. If a long on your unix box is 64 bits, then you need to write out a long. That's problem one. Problem two. Is your Unix system big endian or small endian? For VMS to read the value it has to be written small endian format. VMS uses what is called a Modified Julian Date - mjd. This is a simple algorithm that takes two dates and returns the number of days between them. The VMS mjd is the number of days since Jan 17, 1858 which for this program is 0,0,0 as arguments (gives a zero day), so you only need to know the number of days for the date you are working with. You need to add the number of hours * 3600, plus the number of minutes * 60, plus the number of seconds to your you result (as milliseconds). This code returns an int - on my machine this is a 32 bit long. Arguments are the year as a number (eg, 1999), the month (1-12), and the day (1-31) Code:
int mjd(int dateyear,int datemonth,int dateday)
{
int y = dateyear;
int m = datemonth - 1;
int d = dateday - 678882;
d += 146097 * (y / 400);
y %= 400;
if (m >= 2){
m -= 2;
}else {
m += 10;
--y;
}
y += (m / 12);
m %= 12;
if (m < 0) {
m += 12;
--y;
}
d += (306 * m + 5) / 10;
d += 146097 * (y / 400);
y %= 400;
if (y < 0) {
y += 400;
d -= 146097;
}
d += (y & 3) * 365;
y >>= 2;
d += 1461 * (y % 25);
y /= 25;
d += (y & 3) * 36524;
return d;
}
|
|
#3
|
|||
|
|||
|
Thanks very much for this help.
I didnt know 'long long' existed. I tried it out and that solves the hardest bit of the problem. |
|||
| Google The UNIX and Linux Forums |