/* Subrogram: invtime.c Author: Mylene J. Remigio Date: November 12, 1997 Revision: For Y2K Author: Shyam Lakshmin Date: July 8, 1999 This procedure converts the minute timestamp for WOCE-MET ship data back into a standard year/month/day/hour/minute time. Based on the subroutine invtime.f INPUT VALUE: timestamp integer Number (in minutes) which repersents the time after January 1, 1980, at 00:00 UTC. Range is [0,21565439] OUTPUT VALUES: **NOTE: yr, mon, day, hr, and min are passed in the calling, but they are set to zero once the subprogram is initialized. ** yr integer Year from timestamp. Range is [1980, 2020] If the year is greater than 1999, year is set to -9999 and 0 is the value of mon, day, hr, and min. mon integer The month from timestamp. Range is [1,12] day integer The day from timestamp. Range is [1,31], depending on the month hr integer The hour from timestamp. Range is [0,23] min integer The minute from timestamp. Range is [0,59] ***********************************************************************/ void invtime(int timestamp, int *yr, int *mon, int *day, int *hr, int *min) { int year[42] = {0, 527040, 1052640, 1578240, 2103840, 2630880, 3156480, 3682080, 4207680, 4734720, 5260320, 5785920, 6311520, 6838560, 7364160, 7889760, 8415360, 8942400, 9468000, 9993600, 10519200, 11046240, 11571840, 12097440, 12623040, 13150080, 13675680, 14201280, 14726880, 15253920, 15779520, 16305120, 16830720, 17357760, 17883360, 18408960, 18934560, 19461600, 19987200, 20512800, 21038400, 21565440}; int month[13] = {0, 44640, 84960, 129600, 172800, 217440, 260640, 305280, 349920, 393120, 437760, 480960, 525600}; int leap_mon[13] = {0, 44640, 86400, 131040, 174240, 218880, 262080, 306720, 351360, 394560, 439200, 482400, 527040}; int min_day = 1440; int min_hr = 60; int iyr, imon, iday, ihour, itime, ttime, i; /* YEAR CALCULATION */ if (timestamp >= year[41]) { *yr = -9999; return; } iyr = 1979; itime = timestamp; for (i = 0; i < 41; i++) { iyr = iyr++; ttime = itime - year[i + 1]; if (ttime < 0) { itime = itime - year[i]; break; } } /* Year has been calculated -- assign return value. */ *yr = iyr; /* MONTH CALCULATION */ imon = 0; /* calculation of month for leap years */ if (iyr%4 == 0) { for (i = 0; i < 12; i++) { imon = imon++; ttime = itime - leap_mon[i + 1]; if (ttime < 0) { itime = itime - leap_mon[i]; break; } } } /* calculation of month for non-leap years */ else { for (i = 0; i < 12; i++) { imon = imon++; ttime = itime - month[i + 1]; if (ttime < 0) { itime = itime - month[i]; break; } } } /* Return month value. */ *mon = imon; /* DAY CALCULATION */ iday = 0; for (i = 0; i < 31; i++) { iday = iday++; ttime = itime - ( min_day * (i + 1) ); if (ttime < 0) { itime = itime - ( min_day * i ); break; } } /* Return day calculation. */ *day = iday; /* HOUR CALCULATION. */ ihour = -1; for (i = 0; i < 24; i++) { ihour = ihour++; ttime = itime - ( min_hr * (i + 1) ); if (ttime < 0) { itime = itime - ( min_hr * i ); break; } } *hr = ihour; /* MINUTE CALCULATION. */ *min = itime; }