/* Subprogram: convtime.c Author: Shyam Lakshmin (lakshmin@cs.fsu.edu) Date: July 13, 1999 This function will convert a year/month/day/hour/minute time into a minute timestamp measured from 1-1-1980 00:00. The function is passed the year/month/day/hour/minute time and the return value is the minute timestamp. A value of -9999 is returned if an error is encountered. Based upon the subroutine convtime.f */ int convtime(int yr, int mon, int day, int hr, int min) { int year[41] = {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}; int month[12] = {0, 44640, 84960, 129600, 172800, 217440, 260640, 305280, 349920, 393120, 437760, 480960}; int leap_mon[12] = {0, 44640, 86400, 131040, 174240, 218880, 262080, 306720, 351360, 394560, 439200, 482400}; int min_day = 1440; int min_hr = 60; /* Test values to see if they fit valid ranges */ if (yr < 1980 || yr > 2020) { printf("ERROR ---- year out of range (1980-2020)"); return -9999; } if (mon < 1 || mon > 12) { printf("ERROR ---- month out of range (1-12)"); return -9999; } if (mon == 2) { if ((yr%4 == 0) && (day < 1 || day > 29)) { printf("ERROR ---- Feb. day out of range (1-29)"); return -9999; } else if ((yr%4 != 0) && (day < 1 || day > 28)) { printf("ERROR ---- Feb. day out of range (1-28)"); return -9999; } } else if ((mon == 4) || (mon == 6) || (mon == 9) || (mon == 11)) { if (day < 1 || day > 30) { printf("ERROR ---- day out of range (1-30)"); return -9999; } } else { if (day < 1 || day > 31) { printf("ERROR ---- day out of range (1-31)"); return -9999; } } if (hr < 0 || hr > 23) { printf("ERROR ---- hour out of range (0-23)"); return -9999; } if (min < 0 || min > 60) { printf("ERROR ---- minute out of range (0-60)"); return -9999; } /* Convert time */ if (yr%4 == 0) return year[yr-1980] + leap_mon[mon-1] + ((day-1)*min_day) + (hr*min_hr) + min; else return year[yr-1980] + month[mon-1] + ((day-1)*min_day) + (hr*min_hr) + min; }