From: <arj...@us...> - 2011-01-19 08:21:50
|
Revision: 11494 http://plplot.svn.sourceforge.net/plplot/?rev=11494&view=rev Author: arjenmarkus Date: 2011-01-19 08:21:43 +0000 (Wed, 19 Jan 2011) Log Message: ----------- Preliminary implementation of pllegend for Fortran 77: - We probably want to introduce a new include file, because of the PL_LEGEND_* constants. The alternative is to copy them into the source code for each example, as done now. (Note that we can solve this for Fortran 90/95 via the module, no need for an extra file here) - The implementation now uses two extra static variables to convert the arrays of strings to the C conventions. However, that is not thread-safe (it does avoid a complication with passing the string lengths, though) - Not checked against the C output yet. The other examples still need to be done. - Only checked for gfortran. Modified Paths: -------------- trunk/bindings/f77/plplotf77.def trunk/bindings/f77/plplotf77_ifort.def trunk/bindings/f77/plplotf77_mingw.def trunk/bindings/f77/plstubs.h trunk/bindings/f77/scstubs.c trunk/bindings/f77/sfstubs.fm4 trunk/bindings/f77/sfstubs.h trunk/examples/f77/x04f.fm4 Modified: trunk/bindings/f77/plplotf77.def =================================================================== --- trunk/bindings/f77/plplotf77.def 2011-01-16 12:17:22 UTC (rev 11493) +++ trunk/bindings/f77/plplotf77.def 2011-01-19 08:21:43 UTC (rev 11494) @@ -16,6 +16,8 @@ _PLIMAGEFR2@56 _PLIMAGEFR@48 _PLLAB@24 + _PLLEGEND@128 + _PLLEGEND_CNV_TEXT@16 _PLMAP@28 _PLMAP_NONE@24 _PLMERIDIANS@28 Modified: trunk/bindings/f77/plplotf77_ifort.def =================================================================== --- trunk/bindings/f77/plplotf77_ifort.def 2011-01-16 12:17:22 UTC (rev 11493) +++ trunk/bindings/f77/plplotf77_ifort.def 2011-01-19 08:21:43 UTC (rev 11494) @@ -16,6 +16,8 @@ PLIMAGEFR2 PLIMAGEFR PLLAB + PLLEGEND + PLLEGEND_CNV_TEXT PLMAP PLMAP_NONE PLMERIDIANS Modified: trunk/bindings/f77/plplotf77_mingw.def =================================================================== --- trunk/bindings/f77/plplotf77_mingw.def 2011-01-16 12:17:22 UTC (rev 11493) +++ trunk/bindings/f77/plplotf77_mingw.def 2011-01-19 08:21:43 UTC (rev 11494) @@ -17,6 +17,8 @@ plimagefr2_ plimagefr_ pllab_ + pllegend_cnv_text_ + pllegend_ plmap_ plmap_none_ plmeridians_ Modified: trunk/bindings/f77/plstubs.h =================================================================== --- trunk/bindings/f77/plstubs.h 2011-01-16 12:17:22 UTC (rev 11493) +++ trunk/bindings/f77/plstubs.h 2011-01-19 08:21:43 UTC (rev 11494) @@ -244,6 +244,8 @@ #define PLINIT FNAME( PLINIT, plinit ) #define PLJOIN FNAME( PLJOIN, pljoin ) #define PLLAB7 FNAME( PLLAB7, pllab7 ) +#define PLLEGEND FNAME( PLLEGEND07, pllegend07 ) +#define PLLEGEND_CNV_TEXT FNAME( PLLEGEND07_CNVV_TEXT, pllegend07_cnv_text ) #define PLLIGHTSOURCE FNAME( PLLIGHTSOURCE, pllightsource ) #define PLLINE FNAME( PLLINE, plline ) #define PLLINE3 FNAME( PLLINE3, plline3 ) Modified: trunk/bindings/f77/scstubs.c =================================================================== --- trunk/bindings/f77/scstubs.c 2011-01-16 12:17:22 UTC (rev 11493) +++ trunk/bindings/f77/scstubs.c 2011-01-19 08:21:43 UTC (rev 11494) @@ -43,6 +43,9 @@ // 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 ) { @@ -509,7 +512,79 @@ 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 ); + 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 *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, + *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, pllegend_text, + box_colors, box_patterns, + box_scales, box_line_widths, + line_colors, line_styles, + line_widths, + symbol_colors, symbol_scales, + symbol_numbers, 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/f77/sfstubs.fm4 =================================================================== --- trunk/bindings/f77/sfstubs.fm4 2011-01-16 12:17:22 UTC (rev 11493) +++ trunk/bindings/f77/sfstubs.fm4 2011-01-19 08:21:43 UTC (rev 11494) @@ -265,6 +265,61 @@ c*********************************************************************** + subroutine pllegend( legend_width, legend_height, 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 ) + & + + implicit none + real*8 legend_width, legend_height, plot_width, x, y + real*8 text_offset, text_scale, text_spacing, text_justification + integer opt, bg_color, bb_color, bb_style + integer nrow, ncolumn, nlegend + + integer opt_array, text_colors, box_colors, box_patterns + integer box_scales, line_colors, line_styles + real*8 box_line_widths, line_widths, symbol_scales + integer symbol_colors, symbol_numbers + + character*(*) text, symbols + + dimension opt_array(*), text_colors(*), box_colors(*) + dimension box_patterns(*), box_scales(*) + dimension line_colors(*), line_styles(*) + dimension symbol_colors(*), symbol_numbers(*) + dimension box_line_widths(*), line_widths(*), symbol_scales(*) + dimension text(*), symbols(*) + +c +c Convert the text arrays and store the results in a convenient +c albeit global location. This way we avoid all manner of complications. +c (Though introducing a potentially nasty one: non-threadsafety) +c + call pllegend07_cnv_text( 1, nlegend, text ) + call pllegend07_cnv_text( 2, nlegend, symbols ) + + call pllegend07( legend_width, legend_height, 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 + +c*********************************************************************** + subroutine plvec0(u, v, nx, ny, scale) implicit none Modified: trunk/bindings/f77/sfstubs.h =================================================================== --- trunk/bindings/f77/sfstubs.h 2011-01-16 12:17:22 UTC (rev 11493) +++ trunk/bindings/f77/sfstubs.h 2011-01-19 08:21:43 UTC (rev 11494) @@ -40,3 +40,66 @@ common /zzplstr7/ string7 common /zzplstr8/ string8 common /zzplstr9/ string9 + +c Flags for pllegend. + integer PL_LEGEND_NONE + integer PL_LEGEND_COLOR_BOX + integer PL_LEGEND_LINE + integer PL_LEGEND_SYMBOL + integer PL_LEGEND_TEXT_LEFT + integer PL_LEGEND_BACKGROUND + integer PL_LEGEND_BOUNDING_BOX + integer PL_LEGEND_ROW_MAJOR + integer PL_LEGEND_LEFT + integer PL_LEGEND_RIGHT + integer PL_LEGEND_UPPER + integer PL_LEGEND_LOWER + integer PL_LEGEND_INSIDE + integer PL_LEGEND_OUTSIDE + + parameter (PL_LEGEND_NONE = 1 ) + parameter (PL_LEGEND_COLOR_BOX = 2 ) + parameter (PL_LEGEND_LINE = 4 ) + parameter (PL_LEGEND_SYMBOL = 8 ) + parameter (PL_LEGEND_TEXT_LEFT = 16 ) + parameter (PL_LEGEND_BACKGROUND = 32 ) + parameter (PL_LEGEND_BOUNDING_BOX = 64 ) + parameter (PL_LEGEND_ROW_MAJOR = 128 ) + parameter (PL_LEGEND_LEFT = 256 ) + parameter (PL_LEGEND_RIGHT = 512 ) + parameter (PL_LEGEND_UPPER = 1024 ) + parameter (PL_LEGEND_LOWER = 2048 ) + parameter (PL_LEGEND_INSIDE = 4096 ) + parameter (PL_LEGEND_OUTSIDE = 8192 ) + +c Flags for plcolorbar + integer PL_COLORBAR_LEFT + integer PL_COLORBAR_RIGHT + integer PL_COLORBAR_UPPER + integer PL_COLORBAR_LOWER + integer PL_COLORBAR_LABEL_LEFT + integer PL_COLORBAR_LABEL_RIGHT + integer PL_COLORBAR_LABEL_UPPER + integer PL_COLORBAR_LABEL_LOWER + integer PL_COLORBAR_IMAGE + integer PL_COLORBAR_SHADE + integer PL_COLORBAR_GRADIENT + integer PL_COLORBAR_CAP_LOW + integer PL_COLORBAR_CAP_HIGH + integer PL_COLORBAR_SHADE_LABEL + + parameter (PL_COLORBAR_LEFT = 1 ) + parameter (PL_COLORBAR_RIGHT = 2 ) + parameter (PL_COLORBAR_UPPER = 4 ) + parameter (PL_COLORBAR_LOWER = 8 ) + parameter (PL_COLORBAR_LABEL_LEFT = 16 ) + parameter (PL_COLORBAR_LABEL_RIGHT = 32 ) + parameter (PL_COLORBAR_LABEL_UPPER = 64 ) + parameter (PL_COLORBAR_LABEL_LOWER = 128 ) + parameter (PL_COLORBAR_IMAGE = 256 ) + parameter (PL_COLORBAR_SHADE = 512 ) + parameter (PL_COLORBAR_GRADIENT = 1024 ) + parameter (PL_COLORBAR_CAP_LOW = 2048 ) + parameter (PL_COLORBAR_CAP_HIGH = 4096 ) + parameter (PL_COLORBAR_SHADE_LABEL = 8192 ) + Modified: trunk/examples/f77/x04f.fm4 =================================================================== --- trunk/examples/f77/x04f.fm4 2011-01-16 12:17:22 UTC (rev 11493) +++ trunk/examples/f77/x04f.fm4 2011-01-19 08:21:43 UTC (rev 11494) @@ -40,6 +40,51 @@ real*8 freql(0:100),ampl(0:100),phase(0:100), freq, f0 integer i, type + real*8 legend_width, legend_height + integer nlegend + integer opt_array(2), text_colors(2), line_colors(2), + & line_styles(2), symbol_colors(2), + & symbol_numbers(2) + real*8 line_widths(2), symbol_scales(2) + integer box_colors(1), box_patterns(1), box_scales(1) + real*8 box_line_widths(1) + character*20 text(2) + character*1 symbols(2) + +c To include file! + + integer PL_LEGEND_NONE + integer PL_LEGEND_COLOR_BOX + integer PL_LEGEND_LINE + integer PL_LEGEND_SYMBOL + integer PL_LEGEND_TEXT_LEFT + integer PL_LEGEND_BACKGROUND + integer PL_LEGEND_BOUNDING_BOX + integer PL_LEGEND_ROW_MAJOR + integer PL_LEGEND_LEFT + integer PL_LEGEND_RIGHT + integer PL_LEGEND_UPPER + integer PL_LEGEND_LOWER + integer PL_LEGEND_INSIDE + integer PL_LEGEND_OUTSIDE + + parameter (PL_LEGEND_NONE = 1 ) + parameter (PL_LEGEND_COLOR_BOX = 2 ) + parameter (PL_LEGEND_LINE = 4 ) + parameter (PL_LEGEND_SYMBOL = 8 ) + parameter (PL_LEGEND_TEXT_LEFT = 16 ) + parameter (PL_LEGEND_BACKGROUND = 32 ) + parameter (PL_LEGEND_BOUNDING_BOX = 64 ) + parameter (PL_LEGEND_ROW_MAJOR = 128 ) + parameter (PL_LEGEND_LEFT = 256 ) + parameter (PL_LEGEND_RIGHT = 512 ) + parameter (PL_LEGEND_UPPER = 1024 ) + parameter (PL_LEGEND_LOWER = 2048 ) + parameter (PL_LEGEND_INSIDE = 4096 ) + parameter (PL_LEGEND_OUTSIDE = 8192 ) + + + call pladv(0) c Set up data for log plot. f0 = 1.d0 @@ -73,6 +118,7 @@ & 'Single Pole Low-Pass Filter') call plcol0(2) call plmtex('l', 5.0d0, 0.5d0, 0.5d0, 'Amplitude (dB)') + nlegend = 1 c For the gridless case, put phase vs freq on same plot. if(type.eq.0) then call plcol0(1) @@ -84,5 +130,43 @@ call plcol0(3) call plmtex('r', 5.0d0, 0.5d0, 0.5d0, & 'Phase shift (degrees)') + nlegend = 2 endif +c Draw a legend +c 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 +c note from the above opt_array the first symbol (and box) indices +c do not have to be specified + +c 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) = '*' +c from the above opt_arrays we can completely ignore everything +c to do with boxes. + + call plscol0a( 15, 32, 32, 32, 0.70 ) + call pllegend( legend_width, legend_height, + & PL_LEGEND_BACKGROUND + PL_LEGEND_BOUNDING_BOX, + & 0.0d0, 0.0d0, 0.1d0, 15, + & 1, 1, 0, 0, + & nlegend, opt_array, + & 1.0d0, 1.0d0, 2.0d0, + & 1.0d0, 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. |