From: <and...@us...> - 2009-02-05 20:23:12
|
Revision: 9458 http://plplot.svn.sourceforge.net/plplot/?rev=9458&view=rev Author: andrewross Date: 2009-02-05 20:23:08 +0000 (Thu, 05 Feb 2009) Log Message: ----------- Apply patch from Terrence Keats(?) to fix compilation of qsastime library on MSVC. Modified Paths: -------------- trunk/lib/qsastime/CMakeLists.txt trunk/lib/qsastime/qsastime.c trunk/lib/qsastime/qsastime.h trunk/lib/qsastime/qsastime_extra.c trunk/lib/qsastime/qsastime_extra.h trunk/lib/qsastime/qsastime_test.c Modified: trunk/lib/qsastime/CMakeLists.txt =================================================================== --- trunk/lib/qsastime/CMakeLists.txt 2009-02-05 20:06:41 UTC (rev 9457) +++ trunk/lib/qsastime/CMakeLists.txt 2009-02-05 20:23:08 UTC (rev 9458) @@ -25,8 +25,6 @@ set(qsastime_LIB_SRCS qsastime.c -qsastime.h -qsastimedll.h ) if(BUILD_SHARED_LIBS) @@ -44,6 +42,14 @@ INSTALL_NAME_DIR "${LIB_DIR}" ) + +set(qsastime_INSTALLED_HEADERS + qsastime.h + qsastimedll.h +) + +install(FILES ${qsastime_INSTALLED_HEADERS} DESTINATION ${INCLUDE_DIR}) + install(TARGETS qsastime ARCHIVE DESTINATION ${LIB_DIR} LIBRARY DESTINATION ${LIB_DIR} Modified: trunk/lib/qsastime/qsastime.c =================================================================== --- trunk/lib/qsastime/qsastime.c 2009-02-05 20:06:41 UTC (rev 9457) +++ trunk/lib/qsastime/qsastime.c 2009-02-05 20:23:08 UTC (rev 9458) @@ -37,7 +37,7 @@ Thus 2006-12-32 00:62:00.0 will safely, and correctly, be treated as 2007-01-01 01:02:00.0 */ - +#include <ctype.h> #include "qsastime.h" double SecInDay = 86400; /* we ignore leap seconds */ @@ -54,13 +54,15 @@ /* default is to use Gregorian after 4 Oct 1582 (Julian) i.e. from 15 Oct 1582 Gregorian */ /* Note C libraries use Gregorian only from 14 Sept 1752 onwards */ + int leaps, lastyear; + if(year <= 0) { /* count leap years on Julian Calendar */ /* MJD for Jan 1 0000 (correctly Jan 01, BCE 1) is - 678943, count from there */ /* negative CE (AD) years convert to BCE (BC) as BCE = 1 - CE, e.g. 2 BCE = -1 CE */ - int leaps = year / 4 - 1 ; /* (note leaps is negative here and year 0 (1 BCE) was a leap year */ + leaps = year / 4 - 1 ; /* (note leaps is negative here and year 0 (1 BCE) was a leap year */ if(year%4 == 0) MJD->base_day = year * 365 + leaps + MonthStartDOY_L[month-1] + day - 678943; else @@ -72,7 +74,7 @@ /* count leap years on Julian Calendar */ /* MJD for Jan 1 0000 (correctly Jan 01, BCE 1) is - 678943, count from there */ - int leaps = (year -1 ) / 4; + leaps = (year -1 ) / 4; if(year%4 == 0) MJD->base_day = year * 365 + leaps + MonthStartDOY_L[month-1] + day - 678943; else @@ -84,8 +86,8 @@ /* Algorithm below for 17 Nov 1858 (0 MJD) gives */ /* leaps = 450 and hence base_day of 678941, so subtract it to give MJD day */ - int lastyear = year - 1; - int leaps = lastyear / 4 - lastyear / 100 + lastyear / 400; + lastyear = year - 1; + leaps = lastyear / 4 - lastyear / 100 + lastyear / 400; if( (year%4 == 0 && year%100 != 0) || (year%4 == 0 && year%400 == 0) ) MJD->base_day = year * 365 + leaps + MonthStartDOY_L[month-1] + day - 678941; else @@ -137,7 +139,7 @@ /* Get from Day Of Year */ int doy, year; - int extra_days; + int extra_days,j,lastyear; if(MJD->time_sec >= 0) { @@ -150,7 +152,7 @@ } - int j = MJD->base_day + extra_days; + j = MJD->base_day + extra_days; if( j <= -678943) { @@ -187,7 +189,7 @@ j += 678941; year = (int) ((float)j / 365.2425); - int lastyear = year - 1; + lastyear = year - 1; doy = j - year * 365 - lastyear / 4 + lastyear / 100 - lastyear / 400; } @@ -201,7 +203,8 @@ /* Note year 0 CE (AD) [1 BCE (BC)] is a leap year */ /* There are 678943 days from year 0 to MJD(0) */ - int extra_days; + int extra_days,j,lastyear; + double seconds; if(MJD->time_sec >= 0) { @@ -214,7 +217,7 @@ } - int j = MJD->base_day + extra_days; + j = MJD->base_day + extra_days; if( j <= -678943) { @@ -295,7 +298,7 @@ j += 678941; *year = (int) ((float)j / 365.2425); - int lastyear = *year - 1; + lastyear = *year - 1; j = j - *year * 365 - lastyear / 4 + lastyear / 100 - lastyear / 400; *month = 0; @@ -322,7 +325,7 @@ /* Time part */ - double seconds = MJD->time_sec - extra_days * SecInDay; + seconds = MJD->time_sec - extra_days * SecInDay; *hour = (int)( seconds / 3600.); seconds -= (double) *hour * 3600.; *min = (int) ( seconds / 60.); @@ -335,11 +338,12 @@ Uses the same syntax as strftime() but does not use current locale. The null terminator is included in len for safety. */ - int year, month, day, hour, min, ysign, sec1, sec_fract, second; - int i, count; - int nplaces, slen; + int year, month, day, hour, min, ysign, sec1, second,d,y; + int i, count,secsSince1970; + int nplaces,fmtlen,slen; char * ptr; - double sec; + double sec,sec_fraction; + int w,doy,days_in_wk1; const char *dayText; const char *monthText; char DateTime[80]; @@ -361,8 +365,9 @@ sec -= (double) sec1*10; /* Read format string, character at a time */ + fmtlen = strlen(format); i=0; - while(i<strlen(format)) + while(i<fmtlen) { char next = format[i]; if( next == '%') @@ -605,8 +610,8 @@ else if(next == 's') { /* seconds since 01 Jan 1970 Gregorian */ - int s = MJD->time_sec + (MJD->base_day - MJD_1970) * SecInDay; - sprintf(DateTime, "%d", s); + secsSince1970 = (int)(MJD->time_sec + (MJD->base_day - MJD_1970) * SecInDay); + sprintf(DateTime, "%d", secsSince1970); strncat(&(buf[posn]), DateTime, last - posn); posn = strlen(buf); @@ -631,9 +636,8 @@ else if(next == 'U') { /* week of year as a number, (00 - 53) start of week is Sunday */ - int w; - int doy = getDOY(MJD, forceJulian); - int days_in_wk1 = (MJD->base_day - doy - 4) % 7; + doy = getDOY(MJD, forceJulian); + days_in_wk1 = (MJD->base_day - doy - 4) % 7; w = (doy + 6 - days_in_wk1) / 7; @@ -646,7 +650,7 @@ else if(next == 'u') { /* weekday as a number, 0 = Monday */ - int d = 1 + (MJD->base_day - 5) % 7; + d = 1 + (MJD->base_day - 5) % 7; sprintf(DateTime, "%01d", d); @@ -682,7 +686,6 @@ else if(next == 'V') { /* week of year as a number, (01 - 53) start of week is Monday and first week has at least 3 days in year */ - int w; int doy = getDOY(MJD, forceJulian); int days_in_wk1 = (MJD->base_day - doy - 3) % 7; @@ -699,7 +702,7 @@ else if(next == 'w') { /* weekday as a number, 0 = Sunday */ - int d = (MJD->base_day - 4) % 7; + d = (MJD->base_day - 4) % 7; sprintf(DateTime, "%01d", d); @@ -710,9 +713,8 @@ else if(next == 'W') { /* week of year as a number, (00 - 53) start of week is Monday */ - int w; - int doy = getDOY(MJD, forceJulian); - int days_in_wk1 = (MJD->base_day - doy - 3) % 7; + doy = getDOY(MJD, forceJulian); + days_in_wk1 = (MJD->base_day - doy - 3) % 7; w = (doy +6 - days_in_wk1) / 7; @@ -748,7 +750,7 @@ else if(next == 'y') { /* 2 digit year */ - int y = year %100; + y = year %100; if(ysign == 0) sprintf(DateTime, "%02d", y ); @@ -807,7 +809,7 @@ { nplaces = strtol(&(format[i]), NULL, 10); /* numeric value is number of decimal places ( > 0 ) */ - double sec_fraction = sec - (double) second; + sec_fraction = sec - (double) second; for(count=0; count<nplaces; count++) sec_fraction *= 10; sprintf(DateTime, ".%d", (int) sec_fraction); @@ -827,7 +829,7 @@ else if( next == '.' ) { /* fractional part of seconds to maximum available accuracy */ - double sec_fraction = sec - (double) second; + sec_fraction = sec - (double) second; sprintf(DateTime, "%-11.9f", sec_fraction); while( ( ptr = strrchr(&(DateTime[0]), ' ')) != NULL) ptr[0] ='\0'; /* remove trailing white space */ slen = strlen(DateTime) -1; Modified: trunk/lib/qsastime/qsastime.h =================================================================== --- trunk/lib/qsastime/qsastime.h 2009-02-05 20:06:41 UTC (rev 9457) +++ trunk/lib/qsastime/qsastime.h 2009-02-05 20:23:08 UTC (rev 9458) @@ -1,3 +1,5 @@ +#ifndef _QSASTIME_H_ +#define _QSASTIME_H_ /* This software originally contributed under the LGPL in January 2009 to PLplot by the @@ -69,3 +71,5 @@ QSASTIMEDLLIMPEXP const char * getMonth(int m); QSASTIMEDLLIMPEXP const char * getLongMonth(int m); QSASTIMEDLLIMPEXP int getDOY(const MJDtime *MJD, int forceJulian); + +#endif Modified: trunk/lib/qsastime/qsastime_extra.c =================================================================== --- trunk/lib/qsastime/qsastime_extra.c 2009-02-05 20:06:41 UTC (rev 9457) +++ trunk/lib/qsastime/qsastime_extra.c 2009-02-05 20:23:08 UTC (rev 9458) @@ -47,7 +47,6 @@ { double seconds; int y, m, d, h, min; - char* ptr; int startAt=0; int len = strlen(ISOstring); @@ -93,13 +92,15 @@ /* default is to use Gregorian after 4 Oct 1582 (Julian) i.e. from 15 Oct 1582 Gregorian */ /* Note C libraries use Gregorian only from 14 Sept 1752 onwards*/ + int leaps, lastyear,extraDays; + if(year <= 0) { /* count leap years on Julian Calendar */ /* MJD for Jan 1 0000 (correctly Jan 01, BCE 1) is - 678943, count from there */ /* negative CE (AD) years convert to BCE (BC) as BCE = 1 - CE, e.g. 2 BCE = -1 CE */ - int leaps = year / 4 - 1 ; /* (note leaps is negative here and year 0 (1 BCE) was a leap year */ + leaps = year / 4 - 1 ; /* (note leaps is negative here and year 0 (1 BCE) was a leap year */ MJD->base_day = year * 365 + leaps + doy - 678943; } @@ -108,7 +109,7 @@ /* count leap years on Julian Calendar */ /* MJD for Jan 1 0000 (correctly Jan 01, BCE 1) is - 678943, count from there */ - int leaps = (year -1 ) / 4; + leaps = (year -1 ) / 4; MJD->base_day = year * 365 + leaps + doy - 678943; } @@ -118,8 +119,8 @@ /* Algorithm below for 17 Nov 1858 (0 MJD) gives */ /* leaps = 450 and hence base_day of 678941, so subtract it to give MJD day */ - int lastyear = year - 1; - int leaps = lastyear / 4 - lastyear / 100 + lastyear / 400; + lastyear = year - 1; + leaps = lastyear / 4 - lastyear / 100 + lastyear / 400; MJD->base_day = year * 365 + leaps + doy - 678941; } @@ -128,7 +129,7 @@ if(MJD->time_sec >= SecInDay) { - int extraDays = (int) (MJD->time_sec / SecInDay); + extraDays = (int) (MJD->time_sec / SecInDay); MJD->base_day += extraDays; MJD->time_sec -= extraDays * SecInDay; } @@ -217,11 +218,17 @@ { /* ISO time string for UTC */ /* uses default behaviour for Julian/Gregorian switch over */ - static char DateTime[50]; + /*** + Warning getISOString is not thread safe + as it writes to a static variable DateTime + ***/ + + static char DateTime[50]; int y, m, d, hour, min; int sec1, ysign; double sec; int slen; + char* ptr; breakDownMJD(&y, &m, &d, &hour, &min, &sec, MJD, 0); @@ -243,7 +250,6 @@ sprintf(DateTime, "-%04d-%02d-%02dT%02d:%02d:%01d%-11.10f", y, m, d, hour, min, sec1, sec ); /* remove trailing white space */ - char * ptr; while( ( ptr = strrchr(&(DateTime[0]), ' ')) != NULL) ptr[0] ='\0'; strcat(&(DateTime[0]), "Z"); } @@ -255,7 +261,6 @@ sprintf(DateTime, "-%04d-%02d-%02d %02d:%02d:%01d%-11.10f", y, m, d, hour, min, sec1, sec ); /* remove trailing white space */ - char * ptr; slen = strlen(DateTime)-1; while( DateTime[slen] == ' ') { Modified: trunk/lib/qsastime/qsastime_extra.h =================================================================== --- trunk/lib/qsastime/qsastime_extra.h 2009-02-05 20:06:41 UTC (rev 9457) +++ trunk/lib/qsastime/qsastime_extra.h 2009-02-05 20:23:08 UTC (rev 9458) @@ -1,3 +1,5 @@ +#ifndef _QSASTIME_EXTRA_H_ +#define _QSASTIME_EXTRA_H_ /* This software originally contributed under the LGPL in January 2009 to PLplot by the @@ -56,3 +58,7 @@ QSASTIMEDLLIMPEXP double getDiffSecs(MJDtime *MJD1, MJDtime *MJD2); QSASTIMEDLLIMPEXP double getCDFepoch(MJDtime *MJD); QSASTIMEDLLIMPEXP const char * getISOString(MJDtime *MJD, int delim); + /*** Warning getISOString is not thread safe ***/ + +#endif + Modified: trunk/lib/qsastime/qsastime_test.c =================================================================== --- trunk/lib/qsastime/qsastime_test.c 2009-02-05 20:06:41 UTC (rev 9457) +++ trunk/lib/qsastime/qsastime_test.c 2009-02-05 20:23:08 UTC (rev 9458) @@ -43,6 +43,10 @@ double epoch; int doy; double zeroTest; + + size_t used; + time_t localt; + struct tm *ptm; MJDtime MJD1; MJDtime MJD2; @@ -111,14 +115,30 @@ /* Compare formatting from strftime() */ - size_t used = strfMJD(&(buf[0]), 360, " strfMJD():\n --------\n '%+' \n %c\n %D %F \n %j \n %r \n %s \n %v\n\n", &MJD2, 0); + used = strfMJD(&(buf[0]), 360, " strfMJD():\n --------\n '%+' \n %c\n %D %F \n %j \n %r \n %s \n %v\n\n", &MJD2, 0); printf("chars %d for \n%s\n" , (int) used, buf); /* seconds since 01 Jan 1970 Gregorian for strftime use */ - time_t localt = MJD2.time_sec + (MJD2.base_day - 40587) * 86400; - struct tm *ptm; + localt = (int)MJD2.time_sec + (MJD2.base_day - 40587) * 86400; ptm = gmtime(&localt); - 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); +#ifndef _MSC_VER + /* note %s not implement 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 + /* the following format options are not defined in MSVC (2008) + and are replaced as follows + %e -> %d will print as 01 etc + %D -> %m/%d/%y + %F -> %Y-%m-%d + %r -> %I:%M:%S %p + %s -> %%s - turned into literal as not implemented + + also %c and %p are locale dependent + */ + strftime(&(buf[0]), 360, + " strftime(): (invalid before 1970)\n ------\n '%a %b %d %H:%M:%S UTC %Y' \n %c\n %m/%d/%y %Y-%m-%d \n %j \n %I:%M:%S %p \n %%s not implemented \n %d-%b-%Y", ptm); +#endif printf("%s\n" , buf); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |