From: <ai...@us...> - 2009-02-06 19:36:07
|
Revision: 9465 http://plplot.svn.sourceforge.net/plplot/?rev=9465&view=rev Author: airwin Date: 2009-02-06 19:36:00 +0000 (Fri, 06 Feb 2009) Log Message: ----------- Interpretation of the month argument changed from 1-12 to 0-11 for setFromUT, breakDownMJD, and for some corresponding qsastime_extra.c functions. This change makes our month index convention consistent with the C library's convention for tm->tm_month (see K&R page 255) where 0 corresponds to January, and 11 corresponds to December and should be much less confusing for those who are used to the C library convention which probably originated in the idea that the month index was going to be used as the index of arrays whose starting index was 0. Note, in contrast, the C library time formatting function, strftime, has a month format %m which returns 01-12 for the results (see K&R page 257) which is the understood human convention for specifying month indexes. The corresponding %m field in strfMJD of libqsastime continues to follow that same human convention. I still get the same result for qsastime_test and example 29, but that test is fairly superficial and the implementation of the changed month convention affects a fair number of lines of code. Thus, planned detailed testing of setFromUT, breakDownMJD, and strfMJD against the closest Linux library functions is essential to increase confidence that this convention change introduced no bugs. Modified Paths: -------------- trunk/lib/qsastime/qsastime.c trunk/lib/qsastime/qsastime_extra.c trunk/lib/qsastime/qsastime_test.c trunk/src/plbox.c Modified: trunk/lib/qsastime/qsastime.c =================================================================== --- trunk/lib/qsastime/qsastime.c 2009-02-06 05:14:29 UTC (rev 9464) +++ trunk/lib/qsastime/qsastime.c 2009-02-06 19:36:00 UTC (rev 9465) @@ -58,7 +58,7 @@ double dbase_day, time_sec, dextraDays; int extraDays; - if(month < 1 || month > 12) + if(month < 0 || month > 11) return 1; if(year <= 0) { @@ -75,21 +75,21 @@ stores the expected exact integer results of the calculation with exact representation unless the result is much larger than the integer overflow limit. */ - dbase_day = year * 365. + leaps + MonthStartDOY_L[month-1] + day - 678943; + dbase_day = year * 365. + leaps + MonthStartDOY_L[month] + day - 678943; else - dbase_day = year * 365. + leaps + MonthStartDOY[month-1] + day - 678943; + dbase_day = year * 365. + leaps + MonthStartDOY[month] + day - 678943; } - else if(year < 1582 || (year == 1582 && month < 10) || (year == 1582 && month == 10 && day < 15) || forceJulian) + else if(year < 1582 || (year == 1582 && month < 9) || (year == 1582 && month == 9 && day < 15) || forceJulian) { /* count leap years on Julian Calendar */ /* MJD for Jan 1 0000 (correctly Jan 01, BCE 1) is - 678943, count from there */ leaps = (year -1 ) / 4; if(year%4 == 0) - dbase_day = year * 365. + leaps + MonthStartDOY_L[month-1] + day - 678943; + dbase_day = year * 365. + leaps + MonthStartDOY_L[month] + day - 678943; else - dbase_day = year * 365. + leaps + MonthStartDOY[month-1] + day - 678943; + dbase_day = year * 365. + leaps + MonthStartDOY[month] + day - 678943; } else { @@ -100,9 +100,9 @@ lastyear = year - 1; leaps = lastyear / 4 - lastyear / 100 + lastyear / 400; if( (year%4 == 0 && year%100 != 0) || (year%4 == 0 && year%400 == 0) ) - dbase_day = year * 365. + leaps + MonthStartDOY_L[month-1] + day - 678941; + dbase_day = year * 365. + leaps + MonthStartDOY_L[month] + day - 678941; else - dbase_day = year * 365. + leaps + MonthStartDOY[month-1] + day - 678941; + dbase_day = year * 365. + leaps + MonthStartDOY[month] + day - 678941; } @@ -150,13 +150,13 @@ const char * getMonth( int m) { static char *months = {"Jan\0Feb\0Mar\0Apr\0May\0Jun\0Jul\0Aug\0Sep\0Oct\0Nov\0Dec"}; - return &(months[(m-1)*4]); + return &(months[(m)*4]); } const char * getLongMonth( int m) { static char *months = {"January\0\0\0February\0\0March\0\0\0\0\0April\0\0\0\0\0May\0\0\0\0\0\0\0June\0\0\0\0\0\0July\0\0\0\0\0\0August\0\0\0\0September\0October\0\0\0November\0\0December"}; - return &(months[(m-1)*10]); + return &(months[(m)*10]); } @@ -264,27 +264,27 @@ } /* j is now always positive */ - *month = 0; + *month = -1; if(*year%4 != 0) { - while(j > MonthStartDOY[*month]) + while(j > MonthStartDOY[*month +1]) { (*month)++; - if(*month == 12) break; + if(*month == 11) break; } - *day = j - MonthStartDOY[*month -1]; + *day = j - MonthStartDOY[*month]; } else { /* put this year's leap day back as it is done here */ j++; - while(j > MonthStartDOY_L[*month]) + while(j > MonthStartDOY_L[*month +1]) { (*month)++; - if(*month == 12) break; + if(*month == 11) break; } - *day = j - MonthStartDOY_L[*month -1]; + *day = j - MonthStartDOY_L[*month]; } } else if( j < -100840 || forceJulian == 1) @@ -296,26 +296,26 @@ j = j - (int)(*year * 365.25); - *month = 0; + *month = -1; if(*year%4 != 0) { - while(j > MonthStartDOY[*month]) + while(j > MonthStartDOY[*month +1]) { (*month)++; - if(*month == 12) break; + if(*month == 11) break; } - *day = j - MonthStartDOY[*month -1]; + *day = j - MonthStartDOY[*month]; } else { /* put leap day back for this year as done here */ j++; - while(j > MonthStartDOY_L[*month]) + while(j > MonthStartDOY_L[*month + 1]) { (*month)++; - if(*month == 12) break; + if(*month == 11) break; } - *day = j - MonthStartDOY_L[*month -1]; + *day = j - MonthStartDOY_L[*month]; } } else @@ -327,24 +327,24 @@ lastyear = *year - 1; j = j - *year * 365 - lastyear / 4 + lastyear / 100 - lastyear / 400; - *month = 0; + *month = -1; if((*year%4 == 0 && *year%100 != 0) || (*year%4 == 0 && *year%400 == 0) ) { - while(j > MonthStartDOY_L[*month]) + while(j > MonthStartDOY_L[*month +1]) { (*month)++; - if(*month == 12) break; + if(*month == 11) break; } - *day = j - MonthStartDOY_L[*month -1]; + *day = j - MonthStartDOY_L[*month]; } else { - while(j > MonthStartDOY[*month]) + while(j > MonthStartDOY[*month +1]) { (*month)++; - if(*month == 12) break; + if(*month == 11) break; } - *day = j - MonthStartDOY[*month -1]; + *day = j - MonthStartDOY[*month]; } } @@ -481,9 +481,9 @@ /* month/day/year */ int y = year %100; if(ysign == 0) - sprintf(DateTime, "%02d/%02d/%02d", month, day, y ); + sprintf(DateTime, "%02d/%02d/%02d", month+1, day, y ); else - sprintf(DateTime, "%02d/%02d/-%02d", month, day, y ); + sprintf(DateTime, "%02d/%02d/-%02d", month+1, day, y ); strncat(&(buf[posn]), DateTime, last - posn); posn = strlen(buf); @@ -505,9 +505,9 @@ { /* year-month-day */ if(ysign == 0) - sprintf(DateTime, "%04d-%02d-%02d", year, month, day ); + sprintf(DateTime, "%04d-%02d-%02d", year, month+1, day ); else - sprintf(DateTime, "-%04d-%02d-%02d", year, month, day ); + sprintf(DateTime, "-%04d-%02d-%02d", year, month+1, day ); strncat(&(buf[posn]), DateTime, last - posn); posn = strlen(buf); @@ -571,7 +571,7 @@ else if(next == 'm') { /* month (01 - 12) */ - sprintf(DateTime, "%02d", month); + sprintf(DateTime, "%02d", month+1); strncat(&(buf[posn]), DateTime, last - posn); posn = strlen(buf); @@ -802,7 +802,7 @@ else if(next == 'Z') { /* time zone and calendar, alwaus UTC */ - if(year < 1582 || (year == 1582 && month < 10) || (year == 1582 && month == 10 && day < 15) || forceJulian == 1) + if(year < 1582 || (year == 1582 && month < 9) || (year == 1582 && month == 9 && day < 15) || forceJulian == 1) strncat(&(buf[posn]), "UTC Julian", last - posn); else strncat(&(buf[posn]), "UTC Gregorian", last - posn); Modified: trunk/lib/qsastime/qsastime_extra.c =================================================================== --- trunk/lib/qsastime/qsastime_extra.c 2009-02-06 05:14:29 UTC (rev 9464) +++ trunk/lib/qsastime/qsastime_extra.c 2009-02-06 19:36:00 UTC (rev 9465) @@ -75,7 +75,7 @@ if(startAt > len) return 1; seconds = strtod(&(ISOstring[startAt]), NULL); - setFromUT(y, m, d, h, min, seconds, MJD, 0); + setFromUT(y, m-1, d, h, min, seconds, MJD, 0); return 0; } @@ -245,9 +245,9 @@ if(delim == 1) { if(ysign == 0) - sprintf(DateTime, "%04d-%02d-%02dT%02d:%02d:%01d%-11.10f", y, m, d, hour, min, sec1, sec ); + sprintf(DateTime, "%04d-%02d-%02dT%02d:%02d:%01d%-11.10f", y, m+1, d, hour, min, sec1, sec ); else - sprintf(DateTime, "-%04d-%02d-%02dT%02d:%02d:%01d%-11.10f", y, m, d, hour, min, sec1, sec ); + sprintf(DateTime, "-%04d-%02d-%02dT%02d:%02d:%01d%-11.10f", y, m+1, d, hour, min, sec1, sec ); /* remove trailing white space */ while( ( ptr = strrchr(&(DateTime[0]), ' ')) != NULL) ptr[0] ='\0'; @@ -256,9 +256,9 @@ else { if(ysign == 0) - sprintf(DateTime, "%04d-%02d-%02d %02d:%02d:%01d%-11.10f", y, m, d, hour, min, sec1, sec ); + sprintf(DateTime, "%04d-%02d-%02d %02d:%02d:%01d%-11.10f", y, m+1, d, hour, min, sec1, sec ); else - sprintf(DateTime, "-%04d-%02d-%02d %02d:%02d:%01d%-11.10f", y, m, d, hour, min, sec1, sec ); + sprintf(DateTime, "-%04d-%02d-%02d %02d:%02d:%01d%-11.10f", y, m+1, d, hour, min, sec1, sec ); /* remove trailing white space */ slen = strlen(DateTime)-1; Modified: trunk/lib/qsastime/qsastime_test.c =================================================================== --- trunk/lib/qsastime/qsastime_test.c 2009-02-06 05:14:29 UTC (rev 9464) +++ trunk/lib/qsastime/qsastime_test.c 2009-02-06 19:36:00 UTC (rev 9465) @@ -34,7 +34,7 @@ char buf[360]; char copy[360]; int y = 2004; - int m = 1; + int m = 0; int d = 23; int hour = 13; int min =39; @@ -52,12 +52,12 @@ MJDtime MJD2; - printf("Start date/time components: %d-%d-%d %d:%d:%13.11g\n", y, m, d, hour, min, sec); + printf("Start date/time components: %d-%d-%d %d:%d:%13.11g\n", y, m+1, d, hour, min, sec); setFromUT(y, m, d, hour, min, sec, &MJD2, 0); breakDownMJD(&y,&m,&d,&hour,&min,&sec, &MJD2, 0); - printf("date/time components: %d-%d-%d %d:%d:%13.11g\n\n", y, m, d, hour, min, sec ); + printf("date/time components: %d-%d-%d %d:%d:%13.11g\n\n", y, m+1, d, hour, min, sec ); printf("MJD = %d, seconds = %17.15g\n", MJD2.base_day, MJD2.time_sec); printf( " MJD = %18.10f \n", getMJD(&MJD2)); @@ -101,7 +101,7 @@ /* try julian/gregorian changeover */ y = 1752; - m = 9; + m = 8; d = 15; hour = 0; @@ -122,7 +122,7 @@ localt = (int)MJD2.time_sec + (MJD2.base_day - 40587) * 86400; ptm = gmtime(&localt); #ifndef _MSC_VER - /* note %s not implement in cygwin 1.5 gcc 3.x nothing printed */ + /* note %s not implemented in cygwin 1.5 gcc 3.x nothing printed */ strftime(&(buf[0]), 360, " strftime(): (invalid before 1970)\n ------\n '%a %b %e %H:%M:%S UTC %Y' \n %c\n %D %F \n %j \n %r \n %s \n %e-%b-%Y", ptm); #else Modified: trunk/src/plbox.c =================================================================== --- trunk/src/plbox.c 2009-02-06 05:14:29 UTC (rev 9464) +++ trunk/src/plbox.c 2009-02-06 19:36:00 UTC (rev 9465) @@ -1248,7 +1248,7 @@ for (tn = tp; BETW(tn, vpwxmi, vpwxma); tn += xtick1) { if (ldx) { t = (double) tn; - setFromUT(1970,1,1,0,0,t,&tm,0); + setFromUT(1970,0,1,0,0,t,&tm,0); strfMJD(string, 40, timefmt, &tm, 0); } else { @@ -1297,7 +1297,7 @@ for (tn = tp; BETW(tn, vpwymi, vpwyma); tn += ytick1) { if (ldy) { t = (double) tn; - setFromUT(1970,1,1,0,0,t,&tm,0); + setFromUT(1970,0,1,0,0,t,&tm,0); strfMJD(string, 40, timefmt, &tm, 0); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |