From: <arj...@us...> - 2011-02-03 08:19:58
|
Revision: 11544 http://plplot.svn.sourceforge.net/plplot/?rev=11544&view=rev Author: arjenmarkus Date: 2011-02-03 08:19:52 +0000 (Thu, 03 Feb 2011) Log Message: ----------- Implementation of the Fortran 95 interface to pllegend. Extended example 4 with the appropriate calls. No formal comparisons yet. Note: the interface uses the nlegend arguments just as the C version. I could have used the size of the text argument to determine this, but that would have meant that the user has to select the right section, e.g. call pllegend(..., text(1:nlegend), ...) to limit the number of entries. It would not have been as convenient as with the other cases where a "size" argument is derived on the Fortran 95 side. Modified Paths: -------------- trunk/bindings/f95/plplotf95.def trunk/bindings/f95/plplotf95_ifort.def trunk/bindings/f95/plplotf95_mingw.def trunk/bindings/f95/plstubs.h trunk/bindings/f95/scstubs.c trunk/bindings/f95/sfstubsf95.f90 trunk/examples/f95/x04f.f90 Modified: trunk/bindings/f95/plplotf95.def =================================================================== --- trunk/bindings/f95/plplotf95.def 2011-02-03 08:15:51 UTC (rev 11543) +++ trunk/bindings/f95/plplotf95.def 2011-02-03 08:19:52 UTC (rev 11544) @@ -55,6 +55,7 @@ _PLPLOTP_mp_PLIMAGEFR_1@44 _PLPLOTP_mp_PLIMAGEFR_2@44 _PLPLOTP_mp_PLIMAGEFR_TR@40 + _PLPLOT_mp_PLLEGEND@132 _PLPLOT_mp_PLLINE@8 _PLPLOT_mp_PLLINE3@12 _PLPLOT_mp_PLMESH@16 Modified: trunk/bindings/f95/plplotf95_ifort.def =================================================================== --- trunk/bindings/f95/plplotf95_ifort.def 2011-02-03 08:15:51 UTC (rev 11543) +++ trunk/bindings/f95/plplotf95_ifort.def 2011-02-03 08:19:52 UTC (rev 11544) @@ -57,6 +57,7 @@ PLPLOTP_mp_PLIMAGEFR_1 PLPLOTP_mp_PLIMAGEFR_2 PLPLOTP_mp_PLIMAGEFR_TR + PLPLOT_mp_PLLEGEND PLPLOT_mp_PLLINE PLPLOT_mp_PLLINE3 PLPLOT_mp_PLMESH Modified: trunk/bindings/f95/plplotf95_mingw.def =================================================================== --- trunk/bindings/f95/plplotf95_mingw.def 2011-02-03 08:15:51 UTC (rev 11543) +++ trunk/bindings/f95/plplotf95_mingw.def 2011-02-03 08:19:52 UTC (rev 11544) @@ -55,6 +55,7 @@ __plplot_MOD_plgriddata __plplot_MOD_plhist __plplot_MOD_plimage + __plplot_MOD_pllegend __plplot_MOD_plline __plplot_MOD_plline3 __plplot_MOD_plmesh Modified: trunk/bindings/f95/plstubs.h =================================================================== --- trunk/bindings/f95/plstubs.h 2011-02-03 08:15:51 UTC (rev 11543) +++ trunk/bindings/f95/plstubs.h 2011-02-03 08:19:52 UTC (rev 11544) @@ -245,6 +245,8 @@ #define PLINIT FNAME( PLINIT, plinit ) #define PLJOIN FNAME( PLJOIN, pljoin ) #define PLLAB7 FNAME( PLLAB7, pllab7 ) +#define PLLEGEND_CNV_TEXT FNAME( PLLEGEND07_CNV_TEXT, pllegend07_cnv_text ) +#define PLLEGEND FNAME( PLLEGEND07, pllegend07 ) #define PLLIGHTSOURCE FNAME( PLLIGHTSOURCE, pllightsource ) #define PLLINE FNAME( PLLINEF77, pllinef77 ) #define PLLINE3 FNAME( PLLINE3F77, plline3f77 ) Modified: trunk/bindings/f95/scstubs.c =================================================================== --- trunk/bindings/f95/scstubs.c 2011-02-03 08:15:51 UTC (rev 11543) +++ trunk/bindings/f95/scstubs.c 2011-02-03 08:19:52 UTC (rev 11544) @@ -43,6 +43,10 @@ // Slightly different to C version as we don't support PLPointer for additional data static void ( STDCALL *pltransform )( PLFLT *, PLFLT *, PLFLT *, PLFLT * ); + +static char **pllegend_text; +static char **pllegend_symbols; + static void pltransformf2c( PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer data ) { @@ -552,7 +556,80 @@ label[i + 1] = '\0'; } +// Auxiliary function to create a C-compatible string array +// Note the hidden argument void +PLLEGEND_CNV_TEXT( PLINT *id, PLINT *number, char *string, PLINT length ) +{ + int j; + int i; + char **p_string; + char *data; + + // Ensure the strings are null terminated + + p_string = (char **) malloc( sizeof ( char * ) * ( *number ) ); + data = (char *) malloc( sizeof ( char * ) * ( *number ) * ( length + 1 ) ); + + for ( j = 0; j < ( *number ); j++ ) + { + p_string[j] = data + j * ( length + 1 ); + memcpy( p_string[j], &string[j * length], length ); + p_string[j][length] = '\0'; + i = length - 1; + while ( ( i >= 0 ) && ( p_string[j][i] == ' ' ) ) + i--; + p_string[j][i + 1] = '\0'; + } + + if ( *id == 1 ) + { + pllegend_text = p_string; + } + else + { + pllegend_symbols = p_string; + } +} + +void PLLEGEND( + PLFLT *p_legend_width, PLFLT *p_legend_height, + PLINT *position, PLINT *opt, PLFLT *x, PLFLT *y, PLFLT *plot_width, + PLINT *bg_color, PLINT *bb_color, PLINT *bb_style, + PLINT *nrow, PLINT *ncolumn, + PLINT *nlegend, const PLINT *opt_array, + PLFLT *text_offset, PLFLT *text_scale, PLFLT *text_spacing, + PLFLT *text_justification, + const PLINT *text_colors, + const PLINT *box_colors, const PLINT *box_patterns, + const PLFLT *box_scales, const PLINT *box_line_widths, + const PLINT *line_colors, const PLINT *line_styles, + const PLINT *line_widths, + const PLINT *symbol_colors, const PLFLT *symbol_scales, + const PLINT *symbol_numbers ) +{ + c_pllegend( p_legend_width, p_legend_height, + *position, *opt, *x, *y, *plot_width, + *bg_color, *bb_color, *bb_style, + *nrow, *ncolumn, + *nlegend, opt_array, + *text_offset, *text_scale, *text_spacing, + *text_justification, + text_colors, (const char **)pllegend_text, + box_colors, box_patterns, + box_scales, box_line_widths, + line_colors, line_styles, + line_widths, + symbol_colors, symbol_scales, + symbol_numbers, (const char **)pllegend_symbols ) ; + + free( *pllegend_text ); + free( pllegend_text ); + free( *pllegend_symbols ); + free( pllegend_symbols ); +} + +void PLLIGHTSOURCE( PLFLT *x, PLFLT *y, PLFLT *z ) { c_pllightsource( *x, *y, *z ); Modified: trunk/bindings/f95/sfstubsf95.f90 =================================================================== --- trunk/bindings/f95/sfstubsf95.f90 2011-02-03 08:15:51 UTC (rev 11543) +++ trunk/bindings/f95/sfstubsf95.f90 2011-02-03 08:19:52 UTC (rev 11544) @@ -1059,6 +1059,52 @@ dxmin, dxmax, dymin, dymax ) end subroutine plimage + subroutine pllegend( legend_width, legend_height, & + & position, opt, x, y, & + & plot_width, bg_color, bb_color, bb_style, & + & nrow, ncolumn, nlegend, opt_array, & + & text_offset, text_scale, text_spacing, & + & text_justification, text_colors, text, & + & box_colors, box_patterns, box_scales, & + & box_line_widths, & + & line_colors, line_styles, line_widths, & + & symbol_colors, symbol_scales, & + & symbol_numbers, symbols ) + + real(kind=plflt) :: legend_width, legend_height, plot_width, x, y + real(kind=plflt) :: text_offset, text_scale, text_spacing, text_justification + integer :: position, opt, bg_color, bb_color, bb_style + integer :: nrow, ncolumn, nlegend + + character(len=*), dimension(:) :: text, symbols + + integer, dimension(:) :: opt_array, text_colors, box_colors + integer, dimension(:) :: box_patterns, box_line_widths + integer, dimension(:) :: line_colors, line_styles, line_widths + integer, dimension(:) :: symbol_colors, symbol_numbers + real(kind=plflt), dimension(:) :: box_scales, symbol_scales + + ! + ! Convert the text arrays and store the results in a convenient + ! albeit global location. This way we avoid all manner of complications. + ! (Though introducing a potentially nasty one: non-threadsafety) + ! + call pllegend07_cnv_text( 1, nlegend, text ) + call pllegend07_cnv_text( 2, nlegend, symbols ) + + call pllegend07( legend_width, legend_height, position, opt, x, y, & + plot_width, bg_color, bb_color, bb_style, & + nrow, ncolumn, nlegend, opt_array, & + text_offset, text_scale, text_spacing, & + text_justification, text_colors, & + box_colors, box_patterns, box_scales, & + box_line_widths, & + line_colors, line_styles, line_widths, & + symbol_colors, symbol_scales, & + symbol_numbers ) + + end subroutine pllegend + subroutine plline( x, y ) real(kind=plflt), dimension(:) :: x, y @@ -1145,8 +1191,8 @@ real(kind=plflt), dimension(:) :: x, y, clevel real(kind=plflt), dimension(:,:) :: z - call plmeshcf77( x, y, z, size(x), size(y), opt, & - clevel, size(clevel), size(x)) + call plmeshcf77( x, y, z, size(x), size(y), opt, & + clevel, size(clevel), size(x)) end subroutine plmeshc @@ -1155,10 +1201,10 @@ logical :: side real(kind=plflt), dimension(:) :: x, y real(kind=plflt), dimension(:,:) :: z - integer :: iside + integer :: iside iside = convert_to_int(side) - call plot3df77( x, y, z, size(x), size(y), opt, iside, size(x)) + call plot3df77( x, y, z, size(x), size(y), opt, iside, size(x)) end subroutine plot3d @@ -1184,7 +1230,7 @@ subroutine plsurf3d( x, y, z, opt, clevel ) integer :: opt real(kind=plflt), dimension(:) :: x, y, clevel - real(kind=plflt), dimension(:,:) :: z + real(kind=plflt), dimension(:,:) :: z call plsurf3df77( x, y, z, size(x), size(y), opt, clevel, & size(clevel), size(x)) @@ -1354,8 +1400,8 @@ subroutine plsvect( arrowx, arrowy, fill ) logical :: fill real(kind=plflt), dimension(:) :: arrowx, arrowy - integer ifill - ifill = convert_to_int(fill) + integer ifill + ifill = convert_to_int(fill) call plsvectf77( arrowx, arrowy, size(arrowx), ifill ) end subroutine plsvect Modified: trunk/examples/f95/x04f.f90 =================================================================== --- trunk/examples/f95/x04f.f90 2011-02-03 08:15:51 UTC (rev 11543) +++ trunk/examples/f95/x04f.f90 2011-02-03 08:19:52 UTC (rev 11544) @@ -21,6 +21,7 @@ use plplot implicit none + ! Process command-line arguments call plparseopts(PL_PARSE_FULL) @@ -38,6 +39,17 @@ real(kind=plflt) freql(0:100),ampl(0:100),phase(0:100), freq, f0 integer i, type + real(kind=plflt) legend_width, legend_height + integer nlegend + integer opt_array(2), text_colors(2), line_colors(2), & + line_styles(2), line_widths(2), symbol_colors(2), & + symbol_numbers(2) + real(kind=plflt) symbol_scales(2), box_scales(0) + integer box_colors(0), box_patterns(0) + integer box_line_widths(0) + character(len=20) text(2) + character(len=1) symbols(2) + call pladv(0) ! Set up data for log plot. f0 = 1._plflt @@ -71,6 +83,7 @@ 'Single Pole Low-Pass Filter') call plcol0(2) call plmtex('l', 5.0_plflt, 0.5_plflt, 0.5_plflt, 'Amplitude (dB)') + nlegend = 1 ! For the gridless case, put phase vs freq on same plot. if(type.eq.0) then call plcol0(1) @@ -82,5 +95,44 @@ call plcol0(3) call plmtex('r', 5.0_plflt, 0.5_plflt, 0.5_plflt, & 'Phase shift (degrees)') + nlegend = 2 endif + +! Draw a legend +! First legend entry. + opt_array(1) = PL_LEGEND_LINE + text_colors(1) = 2 + text(1) = 'Amplitude' + line_colors(1) = 2 + line_styles(1) = 1 + line_widths(1) = 1 +! note from the above opt_array the first symbol (and box) indices +! do not have to be specified + +! Second legend entry. + opt_array(2) = PL_LEGEND_LINE + PL_LEGEND_SYMBOL + text_colors(2) = 3 + text(2) = 'Phase shift' + line_colors(2) = 3 + line_styles(2) = 1 + line_widths(2) = 1 + symbol_colors(2) = 3 + symbol_scales(2) = 1.0 + symbol_numbers(2) = 4 + symbols(2) = '*' +! from the above opt_arrays we can completely ignore everything +! to do with boxes. (Hence the size 0 for the associated arrays) + + call plscol0a( 15, 32, 32, 32, 0.70_plflt ) + call pllegend( legend_width, legend_height, & + 0, PL_LEGEND_BACKGROUND + PL_LEGEND_BOUNDING_BOX, & + 0.0_plflt, 0.0_plflt, 0.1_plflt, 15, & + 1, 1, 0, 0, & + nlegend, opt_array, & + 1.0_plflt, 1.0_plflt, 2.0_plflt, & + 1.0_plflt, text_colors, text, & + box_colors, box_patterns, box_scales, box_line_widths, & + line_colors, line_styles, line_widths, & + symbol_colors, symbol_scales, symbol_numbers, symbols ) + end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |