From: <and...@us...> - 2009-08-18 13:52:28
|
Revision: 10281 http://plplot.svn.sourceforge.net/plplot/?rev=10281&view=rev Author: andrewross Date: 2009-08-18 13:52:20 +0000 (Tue, 18 Aug 2009) Log Message: ----------- Implement plsfunclabel for f77 / f95 and update example 19 accordingly. Modified Paths: -------------- trunk/bindings/f77/plstubs.h trunk/bindings/f77/scstubs.c trunk/bindings/f95/plstubs.h trunk/bindings/f95/scstubs.c trunk/examples/f77/x19f.fm4 trunk/examples/f95/x19f.f90 Modified: trunk/bindings/f77/plstubs.h =================================================================== --- trunk/bindings/f77/plstubs.h 2009-08-18 09:53:03 UTC (rev 10280) +++ trunk/bindings/f77/plstubs.h 2009-08-18 13:52:20 UTC (rev 10281) @@ -303,6 +303,7 @@ #define PLSHADES17 FNAME(PLSHADES17,plshades17) #define PLSHADES27 FNAME(PLSHADES27,plshades27) #define PLSHADES7 FNAME(PLSHADES7,plshades7) +#define PLSLABELFUNC FNAME(PLSLABELFUNC,plslabelfunc) #define PLSMAJ FNAME(PLSMAJ,plsmaj) #define PLSMEM FNAME(PLSMEM,plsmem) #define PLSMIN FNAME(PLSMIN,plsmin) Modified: trunk/bindings/f77/scstubs.c =================================================================== --- trunk/bindings/f77/scstubs.c 2009-08-18 09:53:03 UTC (rev 10280) +++ trunk/bindings/f77/scstubs.c 2009-08-18 13:52:20 UTC (rev 10281) @@ -36,6 +36,9 @@ #endif static void (STDCALL *plmapform)(PLINT *, PLFLT *, PLFLT *) ; /* Note: slightly different prototype than (*mapform)! */ +/* Slightly different to (*label_func) as we don't support PLPointer for + * additional data in f77. */ +static void (STDCALL *pllabelfunc)(PLINT *, PLFLT *, char *, PLINT *); void PL_SETCONTLABELFORMAT(PLINT *lexp, PLINT *sigdig) @@ -471,6 +474,21 @@ c_pllab(xlab, ylab, title); } +static void +pllabelfuncf2c( PLINT axis, PLFLT value, char *label, PLINT length, PLPointer data) +{ + int i; + + (*pllabelfunc)( &axis, &value, label, &length ); + + /* Ensure string is null terminated */ + i = length-1; + while ((i >= 0) && (label[i]== ' ')) + i--; + label[i+1] = '\0'; + +} + void PLLIGHTSOURCE(PLFLT *x, PLFLT *y, PLFLT *z) { @@ -819,6 +837,14 @@ } void +PLSLABELFUNC( void (STDCALL *labelfunc)(PLINT *, PLFLT *, char *, PLINT *)) +{ + pllabelfunc = labelfunc; + /* N.B. neglect pointer to additional data for f77 */ + c_plslabelfunc(pllabelfuncf2c, NULL); +} + +void PLSMAJ(PLFLT *def, PLFLT *scale) { c_plsmaj(*def, *scale); Modified: trunk/bindings/f95/plstubs.h =================================================================== --- trunk/bindings/f95/plstubs.h 2009-08-18 09:53:03 UTC (rev 10280) +++ trunk/bindings/f95/plstubs.h 2009-08-18 13:52:20 UTC (rev 10281) @@ -313,6 +313,7 @@ #define PLSHADES17 FNAME(PLSHADES17,plshades17) #define PLSHADES27 FNAME(PLSHADES27,plshades27) #define PLSHADES7 FNAME(PLSHADES7,plshades7) +#define PLSLABELFUNC FNAME(PLSLABELFUNC,plslabelfunc) #define PLSMAJ FNAME(PLSMAJ,plsmaj) #define PLSMEM FNAME(PLSMEM,plsmem) #define PLSMIN FNAME(PLSMIN,plsmin) Modified: trunk/bindings/f95/scstubs.c =================================================================== --- trunk/bindings/f95/scstubs.c 2009-08-18 09:53:03 UTC (rev 10280) +++ trunk/bindings/f95/scstubs.c 2009-08-18 13:52:20 UTC (rev 10281) @@ -36,6 +36,9 @@ #endif static void (STDCALL *plmapform)(PLINT *, PLFLT *, PLFLT *) ; /* Note: slightly different prototype than (*mapform)! */ +/* Slightly different to (*label_func) as we don't support PLPointer for + * additional data in f77. */ +static void (STDCALL *pllabelfunc)(PLINT *, PLFLT *, char *, PLINT *); void PL_SETCONTLABELFORMAT(PLINT *lexp, PLINT *sigdig) @@ -516,6 +519,21 @@ c_pllab(xlab, ylab, title); } +static void +pllabelfuncf2c( PLINT axis, PLFLT value, char *label, PLINT length, PLPointer data) +{ + int i; + + (*pllabelfunc)( &axis, &value, label, &length ); + + /* Ensure string is null terminated */ + i = length-1; + while ((i >= 0) && (label[i]== ' ')) + i--; + label[i+1] = '\0'; + +} + void PLLIGHTSOURCE(PLFLT *x, PLFLT *y, PLFLT *z) { @@ -878,6 +896,14 @@ } void +PLSLABELFUNC( void (STDCALL *labelfunc)(PLINT *, PLFLT *, char *, PLINT *)) +{ + pllabelfunc = labelfunc; + /* N.B. neglect pointer to additional data for f77 */ + c_plslabelfunc(pllabelfuncf2c, NULL); +} + +void PLSMAJ(PLFLT *def, PLFLT *scale) { c_plsmaj(*def, *scale); Modified: trunk/examples/f77/x19f.fm4 =================================================================== --- trunk/examples/f77/x19f.fm4 2009-08-18 09:53:03 UTC (rev 10280) +++ trunk/examples/f77/x19f.fm4 2009-08-18 13:52:20 UTC (rev 10281) @@ -67,6 +67,65 @@ return end +c "Normalize" longitude values so that they always fall between +c -180.0 and 180.0 + function normalize_longitude(lon) + implicit none + real*8 normalize_longitude + real*8 lon, times + + if ((lon .ge. -180.0d0) .and. (lon .le. 180.0d0)) then + normalize_longitude = lon + else + times = floor ((abs(lon) + 180.0d0) / 360.0d0) + if (lon .lt. 0.0d0) then + normalize_longitude = lon + 360.0d0 * times + else + normalize_longitude = lon - 360.0d0 * times + endif + endif + return + end function + +c A custom axis labeling function for longitudes and latitudes. + subroutine geolocation_labeler(axis, value, label, length) + implicit none + integer axis, length + real*8 value + character*(length) label + character*5 direction_label + real*8 label_val + real*8 normalize_longitude + + if (axis .eq. 2) then + label_val = value + if (label_val .gt. 0.0d0) then + direction_label = ' N' + else if (label_val .lt. 0.0d0) then + direction_label = ' S' + else + direction_label = 'Eq' + endif + else if (axis .eq. 1) then + label_val = normalize_longitude(value) + if (label_val .gt. 0.0d0) then + direction_label = ' E' + else if (label_val .lt. 0.0d0) then + direction_label = ' W' + else + direction_label = '' + endif + endif + if (axis .eq. 2 .and. value .eq. 0.0d0) then +c A special case for the equator + label = direction_label + else if (abs(label_val) .lt. 100.0d0) then + write(label,'(I2.1,A2)') iabs(int(label_val)),direction_label + else + write(label,'(I3.1,A2)') iabs(int(label_val)),direction_label + endif + end + c-------------------------------------------------------------------------- c main c @@ -78,6 +137,7 @@ real*8 minx, maxx, miny, maxy external ident external mapform19 + external geolocation_labeler integer PL_PARSE_FULL parameter(PL_PARSE_FULL = 1) @@ -97,8 +157,11 @@ minx = 190 maxx = 190+360 +c Setup a custom latitude and longitude-based scaling function. + call plslabelfunc(geolocation_labeler) + call plcol0(1) - call plenv(minx, maxx, miny, maxy, 1, -1) + call plenv(minx, maxx, miny, maxy, 1, 70) call plmap(ident, 'usaglobe', minx, maxx, miny, maxy) c The Americas @@ -107,9 +170,12 @@ maxx = 340 call plcol0(1) - call plenv(minx, maxx, miny, maxy, 1, -1) + call plenv(minx, maxx, miny, maxy, 1, 70) call plmap(ident, 'usaglobe', minx, maxx, miny, maxy) +c Clear the labeling function + call plslabelfunc(0) + c Polar, Northern hemisphere minx = 0 Modified: trunk/examples/f95/x19f.f90 =================================================================== --- trunk/examples/f95/x19f.f90 2009-08-18 09:53:03 UTC (rev 10280) +++ trunk/examples/f95/x19f.f90 2009-08-18 13:52:20 UTC (rev 10281) @@ -65,8 +65,71 @@ y(i) = yp enddo return - end + end subroutine +! "Normalize" longitude values so that they always fall between +! -180.0 and 180.0 + function normalize_longitude(lon) + use plplot + implicit none + real(kind=plflt) :: normalize_longitude + real(kind=plflt) :: lon, times + + if ((lon .ge. -180.0d0) .and. (lon .le. 180.0d0)) then + normalize_longitude = lon + else + times = floor ((abs(lon) + 180.0d0) / 360.0d0) + if (lon .lt. 0.0d0) then + normalize_longitude = lon + 360.0d0 * times + else + normalize_longitude = lon - 360.0d0 * times + endif + endif + return + end function + +! +! A custom axis labeling function for longitudes and latitudes. +! + subroutine geolocation_labeler(axis, value, label, length) + use plplot + implicit none + integer :: axis, length + real(kind=plflt) :: value + character*(length) label + character*5 direction_label + real(kind=plflt) :: label_val + real(kind=plflt) :: normalize_longitude + + if (axis .eq. 2) then + label_val = value + if (label_val .gt. 0.0d0) then + direction_label = ' N' + else if (label_val .lt. 0.0d0) then + direction_label = ' S' + else + direction_label = 'Eq' + endif + else if (axis .eq. 1) then + label_val = normalize_longitude(value) + if (label_val .gt. 0.0d0) then + direction_label = ' E' + else if (label_val .lt. 0.0d0) then + direction_label = ' W' + else + direction_label = '' + endif + endif + if (axis .eq. 2 .and. value .eq. 0.0d0) then +! A special case for the equator + label = direction_label + else if (abs(label_val) .lt. 100.0d0) then + write(label,'(I2.1,A2)') iabs(int(label_val)),direction_label + else + write(label,'(I3.1,A2)') iabs(int(label_val)),direction_label + endif + end subroutine + !-------------------------------------------------------------------------- ! main ! @@ -80,6 +143,7 @@ integer c external ident external mapform19 + external geolocation_labeler ! Process command-line arguments call plparseopts(PL_PARSE_FULL) @@ -97,8 +161,11 @@ minx = 190 maxx = 190+360 +! Setup a custom latitude and longitude-based scaling function. + call plslabelfunc(geolocation_labeler) + call plcol0(1) - call plenv(minx, maxx, miny, maxy, 1, -1) + call plenv(minx, maxx, miny, maxy, 1, 70) call plmap(ident, 'usaglobe', minx, maxx, miny, maxy) ! The Americas @@ -107,9 +174,12 @@ maxx = 340 call plcol0(1) - call plenv(minx, maxx, miny, maxy, 1, -1) + call plenv(minx, maxx, miny, maxy, 1, 70) call plmap(ident, 'usaglobe', minx, maxx, miny, maxy) +! Clear the labeling function + call plslabelfunc(0) + ! Polar, Northern hemisphere minx = 0 @@ -124,4 +194,4 @@ 0.0_plflt, 360.0_plflt, -10.0_plflt, & 80.0_plflt) call plend() - end + end program x19f This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |