From: <and...@us...> - 2013-06-02 20:07:10
|
Revision: 12353 http://sourceforge.net/p/plplot/code/12353 Author: andrewross Date: 2013-06-02 20:07:07 +0000 (Sun, 02 Jun 2013) Log Message: ----------- Update octave bindings and examples 16 and 33 to use the latest plcolorbar API. Modified Paths: -------------- trunk/bindings/octave/plplot_octave.h.in trunk/bindings/octave/plplot_octave.i trunk/bindings/swig-support/plplotcapi.i trunk/examples/octave/x16c.m trunk/examples/octave/x33c.m Modified: trunk/bindings/octave/plplot_octave.h.in =================================================================== --- trunk/bindings/octave/plplot_octave.h.in 2013-06-02 19:56:22 UTC (rev 12352) +++ trunk/bindings/octave/plplot_octave.h.in 2013-06-02 20:07:07 UTC (rev 12353) @@ -1809,6 +1809,45 @@ c_plimagefr( aa, nx, ny, xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax, pltr2, &grid2 ); } //%name plimagefr2 //%input a(nx,ny), xg(nx+1,ny+1), yg(nx+1,ny+1) +void plcolorbar( PLFLT *p_colorbar_width, PLFLT *p_colorbar_height, + PLINT opt, PLINT position, PLFLT x, PLFLT y, + PLFLT x_length, PLFLT y_length, + PLINT bg_color, PLINT bb_color, PLINT bb_style, + PLFLT low_cap_color, PLFLT high_cap_color, + PLINT cont_color, PLFLT cont_width, + PLINT n_labels, const PLINT *label_opts, const char * const *label, + PLINT n_axes, const char * const * axis_opts, + const PLFLT *ticks, const PLINT *sub_ticks, + const PLINT *n_values, const PLFLT * const *values ) // %nowrap + +void my_plcolorbar( PLFLT *p_colorbar_width, PLFLT *p_colorbar_height, + PLINT opt, PLINT position, PLFLT x, PLFLT y, + PLFLT x_length, PLFLT y_length, + PLINT bg_color, PLINT bb_color, PLINT bb_style, + PLFLT low_cap_color, PLFLT high_cap_color, + PLINT cont_color, PLFLT cont_width, + PLINT n_labels, const PLINT *label_opts, const char * const *label, + PLINT nx, const char * const * axis_opts, + const PLFLT *ticks, const PLINT *sub_ticks, + const PLINT *n_values, const PLFLT *a ) +{ + PLINT ny, i; + ny = -1; + for ( i = 0; i < nx ; i++ ) + if ( n_values[i] < ny ) ny = n_values[i]; + f2c( a, aa, nx, ny ); + c_plcolorbar(p_colorbar_width, p_colorbar_height, + opt, position, x, y, + x_length, y_length, + bg_color, bb_color, bb_style, + low_cap_color, high_cap_color, + cont_color, cont_width, + n_labels, label_opts, label, + nx, axis_opts, + ticks, sub_ticks, + n_values, aa); +} //%name plcolorbar //%input a(nx,ny) + #ifdef __cplusplus } #endif Modified: trunk/bindings/octave/plplot_octave.i =================================================================== --- trunk/bindings/octave/plplot_octave.i 2013-06-02 19:56:22 UTC (rev 12352) +++ trunk/bindings/octave/plplot_octave.i 2013-06-02 20:07:07 UTC (rev 12353) @@ -337,6 +337,30 @@ } %typemap( freearg ) const PLINT * ArrayCkMinus1Null { delete [] $1;} +// Set X and Y lengths for later consistency checking +%typemap( in ) const PLINT * ArrayN( Matrix temp ) +{ + int i; + if ( _n_dims( $input ) > 1 ) + { + error( "argument must be a scalar or vector" ); SWIG_fail; + } + if ( _dim( $input, 0 ) != Alen ) + { + error( "argument vectors must be same length" ); SWIG_fail; + } + Xlen = Alen; + temp = $input.matrix_value(); + $1 = new PLINT[Alen]; + _cvt_double_to( $1, &temp( 0, 0 ), Alen ); + Ylen = -1; + for ( i = 0; i < Xlen; i++ ) + if ( $1[i] > Ylen ) Ylen = $1[i]; +} +%typemap( freearg ) ( const PLINT * ArrayN ) +{ + delete [] $1; +} //-------------------------------------------------------------------------- // PLFLT Arrays @@ -876,6 +900,239 @@ } } +// This test function should be removed when we are confident of our +// dealings with all types of octave string arrays. +%{ + void testppchar( PLINT nlegend, const PLINT *opt_array, const char ** text ) + { + PLINT i; + printf( "nlegend =%d\n", nlegend ); + for ( i = 0; i < nlegend; i++ ) + { + printf( "opt_array[%d] =%d\n", i, opt_array[i] ); + printf( "strlen(text[%d]) =%d\n", i, (int) strlen( text[i] ) ); + printf( "text[%d] =%s\n", i, text[i] ); + } + } +%} + +// No count but check consistency with previous +%typemap( in ) const char **ArrayCk { + charMatrix temp_matrix; + Cell temp_cell; + char *tmp_cstring; + std::string str; + size_t max_length, non_blank_length; + int i, ifcell; + if ( _n_dims( $input ) > 2 ) + { + error( "argument must be a scalar or vector or matrix" ); SWIG_fail; + } + if ( !$input.is_empty() ) + { + if ( _dim( $input, 0 ) != Alen ) + { + error( "first dimension must be same length as previous vector" ); SWIG_fail; + } + $1 = new char*[Alen]; + ifcell = $input.is_cell(); + if ( ifcell ) + { + temp_cell = $input.cell_value(); + } + else + { + temp_matrix = $input.char_matrix_value(); + // Allow one extra space for null termination. + max_length = _dim( $input, 1 ) + 1; + } + + for ( i = 0; i < Alen; i++ ) + { + // Must copy string to "permanent" location because the string + // location corresponding to tmp_cstring gets + // overwritten for each iteration of loop. + if ( ifcell ) + { + if ( temp_cell.elem( i ).is_string() ) + { + str = temp_cell.elem( i ).string_value(); + // leave room for null termination. + max_length = str.size() + 1; + tmp_cstring = (char *) str.c_str(); + } + else + { + // Use null string if user attempts to pass a cell array + // with a non-string element (likely an empty element + // since that should be allowed by the PLplot interface + // if that element is going to be unused). + // leave room for null termination. + max_length = 1; + tmp_cstring = (char *) ""; + } + } + else + { + tmp_cstring = (char *) temp_matrix.row_as_string( i ).c_str(); + } + $1[i] = new char[max_length]; + strncpy( $1[i], tmp_cstring, max_length - 1 ); + $1[i][max_length - 1] = '\0'; + // All the trailing blank crapola should not be needed for + // string cell arrays. + if ( !ifcell ) + { + // remove trailing-blank padding that is used by the + // charMatrix class to insure all strings in a given + // charMatrix instance have the same length. + // This transformation also removes legitimate trailing + // blanks but there is nothing we can do about that + // for the charMatrix class. + + // Look for trailing nulls first (just in case, although that + // shouldn't happen if charMatrix implemented as documented) + // before looking for trailing blanks. + non_blank_length = max_length - 2; + while ( non_blank_length >= 0 && $1[i][non_blank_length] == '\0' ) + { + non_blank_length--; + } + while ( non_blank_length >= 0 && $1[i][non_blank_length] == ' ' ) + { + non_blank_length--; + } + $1[i][non_blank_length + 1] = '\0'; + } + } + } + else + { + $1 = NULL; + } +} +%typemap( freearg ) const char **ArrayCk { + int i; + if ( $1 != NULL ) + { + for ( i = 0; i < Alen; i++ ) + { + delete[] $1[i]; + } + delete[] $1; + } +} + +// No count but check consistency with previous +%typemap( in ) (PLINT n, const char **Array) { + charMatrix temp_matrix; + Cell temp_cell; + char *tmp_cstring; + std::string str; + size_t max_length, non_blank_length; + int i, ifcell; + if ( _n_dims( $input ) > 2 ) + { + error( "argument must be a scalar or vector or matrix" ); SWIG_fail; + } + if ( !$input.is_empty() ) + { + Alen = _dim( $input, 0 ); + $1 = Alen; + $2 = new char*[Alen]; + ifcell = $input.is_cell(); + if ( ifcell ) + { + temp_cell = $input.cell_value(); + } + else + { + temp_matrix = $input.char_matrix_value(); + // Allow one extra space for null termination. + max_length = _dim( $input, 1 ) + 1; + } + + for ( i = 0; i < Alen; i++ ) + { + // Must copy string to "permanent" location because the string + // location corresponding to tmp_cstring gets + // overwritten for each iteration of loop. + if ( ifcell ) + { + if ( temp_cell.elem( i ).is_string() ) + { + str = temp_cell.elem( i ).string_value(); + // leave room for null termination. + max_length = str.size() + 1; + tmp_cstring = (char *) str.c_str(); + } + else + { + // Use null string if user attempts to pass a cell array + // with a non-string element (likely an empty element + // since that should be allowed by the PLplot interface + // if that element is going to be unused). + // leave room for null termination. + max_length = 1; + tmp_cstring = (char *) ""; + } + } + else + { + tmp_cstring = (char *) temp_matrix.row_as_string( i ).c_str(); + } + $2[i] = new char[max_length]; + strncpy( $2[i], tmp_cstring, max_length - 1 ); + $2[i][max_length - 1] = '\0'; + // All the trailing blank crapola should not be needed for + // string cell arrays. + if ( !ifcell ) + { + // remove trailing-blank padding that is used by the + // charMatrix class to insure all strings in a given + // charMatrix instance have the same length. + // This transformation also removes legitimate trailing + // blanks but there is nothing we can do about that + // for the charMatrix class. + + // Look for trailing nulls first (just in case, although that + // shouldn't happen if charMatrix implemented as documented) + // before looking for trailing blanks. + non_blank_length = max_length - 2; + while ( non_blank_length >= 0 && $2[i][non_blank_length] == '\0' ) + { + non_blank_length--; + } + while ( non_blank_length >= 0 && $2[i][non_blank_length] == ' ' ) + { + non_blank_length--; + } + $2[i][non_blank_length + 1] = '\0'; + } + } + } + else + { + $1 = 0; + $2 = NULL; + } +} +%typemap( freearg ) (PLINT n, const char **Array) { + int i; + if ( $2 != NULL ) + { + for ( i = 0; i < Alen; i++ ) + { + delete[] $2[i]; + } + delete[] $2; + } +} + +// This test function should be removed when we are confident of our +// dealings with all types of octave string arrays. +void testppchar( PLINT n, const PLINT *Array, const char **ArrayCk ); + // The octave bindings started out as an independent project with a // historical API that does not match up that well with the PLplot API // function names and numbers and types of arguments. So there are a @@ -1521,133 +1778,53 @@ PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax, PLFLT valuemin, PLFLT valuemax, const PLFLT *Matrix, const PLFLT *Matrix ); -// This test function should be removed when we are confident of our -// dealings with all types of octave string arrays. +// plcolorbar-related wrappers. +%ignore plcolorbar; +%rename( plcolorbar ) my_plcolorbar; + %{ - void testppchar( PLINT nlegend, const PLINT *opt_array, const char ** text ) + void my_plcolorbar( PLFLT *p_colorbar_width, PLFLT *p_colorbar_height, + PLINT opt, PLINT position, PLFLT x, PLFLT y, + PLFLT x_length, PLFLT y_length, + PLINT bg_color, PLINT bb_color, PLINT bb_style, + PLFLT low_cap_color, PLFLT high_cap_color, + PLINT cont_color, PLFLT cont_width, + PLINT n_labels, const PLINT *label_opts, const char **label, + PLINT n_axes, const char ** axis_opts, + const PLFLT *ticks, const PLINT *sub_ticks, + const PLINT *n_values, const PLFLT *a ) { - PLINT i; - printf( "nlegend =%d\n", nlegend ); - for ( i = 0; i < nlegend; i++ ) - { - printf( "opt_array[%d] =%d\n", i, opt_array[i] ); - printf( "strlen(text[%d]) =%d\n", i, (int) strlen( text[i] ) ); - printf( "text[%d] =%s\n", i, text[i] ); - } + PLINT nx, ny, i; + nx = n_axes; + ny = -1; + for ( i = 0; i < nx ; i++ ) + if ( n_values[i] > ny ) ny = n_values[i]; + f2c( a, aa, nx, ny ); + c_plcolorbar(p_colorbar_width, p_colorbar_height, + opt, position, x, y, + x_length, y_length, + bg_color, bb_color, bb_style, + low_cap_color, high_cap_color, + cont_color, cont_width, + n_labels, label_opts, label, + n_axes, axis_opts, + ticks, sub_ticks, + n_values, aa); } + %} -// No count but check consistency with previous -%typemap( in ) const char **ArrayCk { - charMatrix temp_matrix; - Cell temp_cell; - char *tmp_cstring; - std::string str; - size_t max_length, non_blank_length; - int i, ifcell; - if ( _n_dims( $input ) > 2 ) - { - error( "argument must be a scalar or vector or matrix" ); SWIG_fail; - } - if ( !$input.is_empty() ) - { - if ( _dim( $input, 0 ) != Alen ) - { - error( "first dimension must be same length as previous vector" ); SWIG_fail; - } - $1 = new char*[Alen]; - ifcell = $input.is_cell(); - if ( ifcell ) - { - temp_cell = $input.cell_value(); - } - else - { - temp_matrix = $input.char_matrix_value(); - // Allow one extra space for null termination. - max_length = _dim( $input, 1 ) + 1; - } +void my_plcolorbar( PLFLT *OUTPUT, PLFLT *OUTPUT, + PLINT opt, PLINT position, PLFLT x, PLFLT y, + PLFLT x_length, PLFLT y_length, + PLINT bg_color, PLINT bb_color, PLINT bb_style, + PLFLT low_cap_color, PLFLT high_cap_color, + PLINT cont_color, PLFLT cont_width, + PLINT n, const PLINT *Array, const char **ArrayCk, + PLINT n, const char **Array, + const PLFLT *ArrayCk, const PLINT *ArrayCk, + const PLINT *ArrayN , const PLFLT *MatrixCk ); - for ( i = 0; i < Alen; i++ ) - { - // Must copy string to "permanent" location because the string - // location corresponding to tmp_cstring gets - // overwritten for each iteration of loop. - if ( ifcell ) - { - if ( temp_cell.elem( i ).is_string() ) - { - str = temp_cell.elem( i ).string_value(); - // leave room for null termination. - max_length = str.size() + 1; - tmp_cstring = (char *) str.c_str(); - } - else - { - // Use null string if user attempts to pass a cell array - // with a non-string element (likely an empty element - // since that should be allowed by the PLplot interface - // if that element is going to be unused). - // leave room for null termination. - max_length = 1; - tmp_cstring = (char *) ""; - } - } - else - { - tmp_cstring = (char *) temp_matrix.row_as_string( i ).c_str(); - } - $1[i] = new char[max_length]; - strncpy( $1[i], tmp_cstring, max_length - 1 ); - $1[i][max_length - 1] = '\0'; - // All the trailing blank crapola should not be needed for - // string cell arrays. - if ( !ifcell ) - { - // remove trailing-blank padding that is used by the - // charMatrix class to insure all strings in a given - // charMatrix instance have the same length. - // This transformation also removes legitimate trailing - // blanks but there is nothing we can do about that - // for the charMatrix class. - - // Look for trailing nulls first (just in case, although that - // shouldn't happen if charMatrix implemented as documented) - // before looking for trailing blanks. - non_blank_length = max_length - 2; - while ( non_blank_length >= 0 && $1[i][non_blank_length] == '\0' ) - { - non_blank_length--; - } - while ( non_blank_length >= 0 && $1[i][non_blank_length] == ' ' ) - { - non_blank_length--; - } - $1[i][non_blank_length + 1] = '\0'; - } - } - } - else - { - $1 = NULL; - } -} -%typemap( freearg ) const char **ArrayCk { - int i; - if ( $1 != NULL ) - { - for ( i = 0; i < Alen; i++ ) - { - delete[] $1[i]; - } - delete[] $1; - } -} - -// This test function should be removed when we are confident of our -// dealings with all types of octave string arrays. -void testppchar( PLINT n, const PLINT *Array, const char **ArrayCk ); - // Probably never deal with this one. %ignore plMinMax2dGrid; //%feature commands supporting swig-generated documentation for the bindings. Modified: trunk/bindings/swig-support/plplotcapi.i =================================================================== --- trunk/bindings/swig-support/plplotcapi.i 2013-06-02 19:56:22 UTC (rev 12352) +++ trunk/bindings/swig-support/plplotcapi.i 2013-06-02 20:07:07 UTC (rev 12353) @@ -481,7 +481,7 @@ const PLINT *ArrayCkNull, const PLFLT *ArrayCkNull, const PLINT *ArrayCkNull, const char **ArrayCk ); -#if defined (SWIG_PYTHON) || defined(SWIG_JAVA) +#if defined (SWIG_PYTHON) || defined(SWIG_JAVA) || defined(SWIG_OCTAVE) void plcolorbar( PLFLT *OUTPUT, PLFLT *OUTPUT, PLINT opt, PLINT position, PLFLT x, PLFLT y, Modified: trunk/examples/octave/x16c.m =================================================================== --- trunk/examples/octave/x16c.m 2013-06-02 19:56:22 UTC (rev 12352) +++ trunk/examples/octave/x16c.m 2013-06-02 20:07:07 UTC (rev 12353) @@ -32,6 +32,9 @@ function ix16c global tr; global nx; global ny; + global PL_COLORBAR_LABEL_BOTTOM; + global PL_COLORBAR_SHADE; + global PL_COLORBAR_SHADE_LABEL; ## Fundamental settings. See notes[] for more info. ns = 20; ## Default number of shade levels @@ -43,7 +46,19 @@ sh_cmap = 1; fill_width = 2.; cont_color = 0; cont_width = 0.; + + num_axes = 1; + n_axis_opts = num_axes; + axis_opts = { "bcvtm" }; + values = zeros(num_axes,ns+1); + axis_ticks = zeros(1,1); + axis_subticks = zeros(1,1); + num_labels = 1; + label_opts = [ PL_COLORBAR_LABEL_BOTTOM ]; + labels = { "Magnitude" }; + + ## Parse and process command line arguments ## plMergeOpts(options, "x16c options", notes); @@ -110,6 +125,28 @@ cont_color, cont_width, 1); + # Smaller text + plschr( 0.0, 0.75 ); + # Small ticks on the vertical axis + plsmaj( 0.0, 0.5 ); + plsmin( 0.0, 0.5 ); + + num_values(1) = ns + 1; + values(1,:) = shedge; + + [colorbar_width, colorbar_height] = plcolorbar( + bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0, + 0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0, + cont_color, cont_width, + label_opts, labels, axis_opts, + axis_ticks, axis_subticks, + num_values, values ); + + # Reset text and tick sizes + plschr( 0.0, 1.0 ); + plsmaj( 0.0, 1.0 ); + plsmin( 0.0, 1.0 ); + plcol0(1); plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); plcol0(2); @@ -136,6 +173,28 @@ cont_color, cont_width, 1, xg1, yg1); + # Smaller text + plschr( 0.0, 0.75 ); + # Small ticks on the vertical axis + plsmaj( 0.0, 0.5 ); + plsmin( 0.0, 0.5 ); + + num_values(1) = ns + 1; + values(1,:) = shedge; + + [colorbar_width, colorbar_height] = plcolorbar( + bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0, + 0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0, + cont_color, cont_width, + label_opts, labels, axis_opts, + axis_ticks, axis_subticks, + num_values, values ); + + # Reset text and tick sizes + plschr( 0.0, 1.0 ); + plsmaj( 0.0, 1.0 ); + plsmin( 0.0, 1.0 ); + plcol0(1); plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); plcol0(2); @@ -162,6 +221,28 @@ cont_color, cont_width, 0, xg2, yg2); + # Smaller text + plschr( 0.0, 0.75 ); + # Small ticks on the vertical axis + plsmaj( 0.0, 0.5 ); + plsmin( 0.0, 0.5 ); + + num_values(1) = ns + 1; + values(1,:) = shedge; + + [colorbar_width, colorbar_height] = plcolorbar( + bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0, + 0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0, + cont_color, cont_width, + label_opts, labels, axis_opts, + axis_ticks, axis_subticks, + num_values, values ); + + # Reset text and tick sizes + plschr( 0.0, 1.0 ); + plsmaj( 0.0, 1.0 ); + plsmin( 0.0, 1.0 ); + plcol0(1); plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); plcol0(2); @@ -187,6 +268,28 @@ 2, 3., 0, xg2, yg2); + # Smaller text + plschr( 0.0, 0.75 ); + # Small ticks on the vertical axis + plsmaj( 0.0, 0.5 ); + plsmin( 0.0, 0.5 ); + + num_values(1) = ns + 1; + values(1,:) = shedge; + + [colorbar_width, colorbar_height] = plcolorbar( + bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0, + 0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0, + 2, 3, + label_opts, labels, axis_opts, + axis_ticks, axis_subticks, + num_values, values ); + + # Reset text and tick sizes + plschr( 0.0, 1.0 ); + plsmaj( 0.0, 1.0 ); + plsmin( 0.0, 1.0 ); + plcol0(1); plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); plcol0(2); @@ -259,6 +362,28 @@ cont_color, cont_width, 0, xg2, yg2); + # Smaller text + plschr( 0.0, 0.75 ); + # Small ticks on the vertical axis + plsmaj( 0.0, 0.5 ); + plsmin( 0.0, 0.5 ); + + num_values(1) = ns + 1; + values(1,:) = shedge; + + [colorbar_width, colorbar_height] = plcolorbar( + bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0, + 0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0, + cont_color, cont_width, + label_opts, labels, axis_opts, + axis_ticks, axis_subticks, + num_values, values ); + + # Reset text and tick sizes + plschr( 0.0, 1.0 ); + plsmaj( 0.0, 1.0 ); + plsmin( 0.0, 1.0 ); + ## Now we can draw the perimeter. (If do before, shade stuff may overlap.) i = 0:PERIMETERPTS-1; t = (2*pi/(PERIMETERPTS-1))*i; Modified: trunk/examples/octave/x33c.m =================================================================== --- trunk/examples/octave/x33c.m 2013-06-02 19:56:22 UTC (rev 12352) +++ trunk/examples/octave/x33c.m 2013-06-02 20:07:07 UTC (rev 12353) @@ -29,7 +29,9 @@ 1; -global position_options special_symbols +global position_options special_symbols colorbar_option_kinds colorbar_option_kind_labels colorbar_position_options colorbar_position_option_labels colorbar_label_options colorbar_label_option_labels colorbar_cap_options colorbar_cap_option_labels +global COLORBAR_KINDS COLORBAR_POSITIONS COLORBAR_LABELS COLORBAR_CAPS + position_options = [ bitor(PL_POSITION_LEFT, bitor(PL_POSITION_TOP, PL_POSITION_OUTSIDE)); bitor(PL_POSITION_TOP, PL_POSITION_OUTSIDE); @@ -58,117 +60,179 @@ "✦" ]; -function plcolorbar_example_1( bar_type, ticks, sub_ticks, values, title ) - global PL_POSITION_LEFT PL_COLORBAR_LABEL_LEFT PL_COLORBAR_CAP_HIGH PL_COLORBAR_SHADE_LABEL PL_POSITION_RIGHT PL_COLORBAR_LABEL_RIGHT PL_COLORBAR_CAP_LOW PL_POSITION_TOP PL_COLORBAR_LABEL_TOP PL_COLORBAR_CAP_HIGH PL_POSITION_BOTTOM PL_COLORBAR_LABEL_BOTTOM PL_COLORBAR_CAP_LOW - pladv( 0 ); - ## Setup color palette 1 - plspal1( "cmap1_blue_red.pal", 1 ); +# plcolorbar options - n = length(values); - color_step = 1.0 / (n - 1); - colors = (0:n-1)'*color_step; +# Colorbar type options +COLORBAR_KINDS = 4; +colorbar_option_kinds = [ + PL_COLORBAR_SHADE; + bitor(PL_COLORBAR_SHADE,PL_COLORBAR_SHADE_LABEL); + PL_COLORBAR_IMAGE; + PL_COLORBAR_GRADIENT +]; - opt = bitor(PL_POSITION_LEFT, bitor(bar_type, bitor(PL_COLORBAR_LABEL_LEFT, PL_COLORBAR_CAP_HIGH))); +colorbar_option_kind_labels = { + "Shade colorbars"; + "Shade colorbars with custom labels"; + "Image colorbars"; + "Gradient colorbars" +}; - if (bitand(bar_type, PL_COLORBAR_SHADE_LABEL)) - axis_opts_1 = "iv"; - axis_opts_2 = "i"; - else - if (sub_ticks != 0) - axis_opts_1 = "stv"; - axis_opts_2 = "st"; - else - axis_opts_1 = "tv"; - axis_opts_2 = "t"; - endif - endif +# Which side of the page are we positioned relative to? +COLORBAR_POSITIONS = 4; +colorbar_position_options = [ + PL_POSITION_LEFT; + PL_POSITION_RIGHT; + PL_POSITION_TOP; + PL_POSITION_BOTTOM +]; - plcolorbar( opt, 0.1, 0.1, 0.5, 0.1, - ticks, sub_ticks, - axis_opts_1, "Test label - Left, High Cap", - colors, values ); +colorbar_position_option_labels = { + "Left", + "Right", + "Top", + "Bottom" +}; - opt = bitor(PL_POSITION_RIGHT, bitor(bar_type, bitor(PL_COLORBAR_LABEL_RIGHT, PL_COLORBAR_CAP_LOW))); +# Colorbar label positioning options +COLORBAR_LABELS = 4; +colorbar_label_options = [ + PL_COLORBAR_LABEL_LEFT; + PL_COLORBAR_LABEL_RIGHT; + PL_COLORBAR_LABEL_TOP; + PL_COLORBAR_LABEL_BOTTOM +]; - plcolorbar( opt, 0.1, 0.4, 0.5, 0.1, - ticks, sub_ticks, - axis_opts_1, "Test label - Right, Low Cap", - colors, values ); +colorbar_label_option_labels = { + "Label left", + "Label right", + "Label top", + "Label bottom" +}; - opt = bitor(PL_POSITION_TOP, bitor(bar_type, bitor(PL_COLORBAR_LABEL_TOP, PL_COLORBAR_CAP_HIGH))); +# Colorbar cap options +COLORBAR_CAPS = 4; +colorbar_cap_options = [ + PL_COLORBAR_CAP_NONE; + PL_COLORBAR_CAP_LOW; + PL_COLORBAR_CAP_HIGH; + bitor(PL_COLORBAR_CAP_LOW, PL_COLORBAR_CAP_HIGH) +]; - plcolorbar( opt, 0.1, 0.1, 0.5, 0.1, - ticks, sub_ticks, - axis_opts_2, "Test label - Upper, High Cap", - colors, values ); +colorbar_cap_option_labels = { + "No caps"; + "Low cap"; + "High cap"; + "Low and high caps" +}; - opt = bitor(PL_POSITION_BOTTOM, bitor(bar_type, bitor(PL_COLORBAR_LABEL_BOTTOM, PL_COLORBAR_CAP_LOW))); +function plcolorbar_example_page( kind_i, label_i, cap_i, cont_color, cont_width, values ) + + global COLORBAR_POSITIONS colorbar_option_kinds colorbar_option_kind_labels colorbar_position_options colorbar_position_option_labels colorbar_label_options colorbar_label_option_labels colorbar_cap_options colorbar_cap_option_labels + global PL_POSITION_LEFT PL_POSITION_RIGHT PL_POSITION_BOTTOM PL_COLORBAR_BOUNDING_BOX PL_COLORBAR_BACKGROUND - plcolorbar( opt, 0.4, 0.1, 0.5, 0.1, - ticks, sub_ticks, - axis_opts_2, "Test label - Lower, Low Cap", - colors, values ); + label_opts = zeros(1,1); + ticks = zeros(1,1); + sub_ticks = zeros(1,1); + + n_values_array(1,:) = length(values); + values_array(1,:) = values; - plvpor( 0.0, 1.0, 0.0, 1.0 ); - plwind( 0.0, 1.0, 0.0, 1.0 ); - plptex( 0.5, 0.5, 0.0, 0.0, 0.5, title ); -endfunction + low_cap_color = 0.0; + high_cap_color = 1.0; -function plcolorbar_example_2( bar_type, ticks, sub_ticks, values, title ) - global PL_POSITION_LEFT PL_COLORBAR_LABEL_LEFT PL_COLORBAR_CAP_HIGH PL_COLORBAR_SHADE_LABEL PL_POSITION_RIGHT PL_COLORBAR_LABEL_RIGHT PL_COLORBAR_CAP_LOW PL_POSITION_TOP PL_COLORBAR_LABEL_TOP PL_COLORBAR_CAP_HIGH PL_POSITION_BOTTOM PL_COLORBAR_LABEL_BOTTOM PL_COLORBAR_CAP_LOW - pladv( 0 ); - ## Setup color palette 1 - plspal1( "cmap1_blue_yellow.pal", 1 ); + # Start a new page + pladv( 0 ); - n = length(values); - color_step = 1.0 / (n - 1); - colors = (0:n-1)'*color_step; - opt = bitor(PL_POSITION_LEFT, bitor(bar_type, bitor(PL_COLORBAR_LABEL_LEFT, PL_COLORBAR_CAP_LOW))); + # Draw one colorbar relative to each side of the page + for position_i = 1:COLORBAR_POSITIONS + position = colorbar_position_options(position_i); + opt = bitor( + colorbar_option_kinds(kind_i), bitor( + colorbar_label_options(label_i), + colorbar_cap_options(cap_i) ) ); - if (bar_type == PL_COLORBAR_SHADE_LABEL) - axis_opts_1 = ""; - axis_opts_2 = ""; - else - if( sub_ticks != 0) - axis_opts_1 = "stv"; - axis_opts_2 = "st"; - else - axis_opts_1 = "tv"; - axis_opts_2 = "t"; - endif - endif + vertical = bitand(position, PL_POSITION_LEFT) || bitand(position, PL_POSITION_RIGHT); + ifn = bitand(position, PL_POSITION_LEFT) || bitand(position, PL_POSITION_BOTTOM); - plcolorbar( opt, 0.1, 0.1, 0.5, 0.1, - ticks, sub_ticks, - axis_opts_1, "Test label - Left, Low Cap", - colors, values ); + # Set the offset position on the page + if ( vertical ) + x = 0.0; + y = 0.0; + x_length = 0.05; + y_length = 0.5; + else + x = 0.0; + y = 0.0; + x_length = 0.5; + y_length = 0.05; + endif + + # Set appropriate labelling options. + if ( ifn ) + if ( cont_color == 0 || cont_width == 0. ) + axis_opts(1,:) = "uwtivn"; + else + axis_opts(1,:) = "uwxvn"; + endif + else + if ( cont_color == 0 || cont_width == 0. ) + axis_opts(1,:) = "uwtivm"; + else + axis_opts(1,:) = "uwxvm"; + endif + endif - opt = bitor(PL_POSITION_RIGHT, bitor(bar_type, bitor(PL_COLORBAR_LABEL_RIGHT, PL_COLORBAR_CAP_HIGH))); + label = cstrcat(char(colorbar_position_option_labels(position_i)), ", ", char(colorbar_label_option_labels(label_i)) ); - plcolorbar( opt, 0.1, 0.4, 0.5, 0.1, - ticks, sub_ticks, - axis_opts_1, "Test label - Right, High Cap", - colors, values ); + # Smaller text + plschr( 0.0, 0.75 ); + # Small ticks on the vertical axis + plsmaj( 0.0, 0.5 ); + plsmin( 0.0, 0.5 ); - opt = bitor(PL_POSITION_TOP, bitor(bar_type, bitor(PL_COLORBAR_LABEL_TOP, PL_COLORBAR_CAP_LOW))); + plvpor( 0.20, 0.80, 0.20, 0.80 ); + plwind( 0.0, 1.0, 0.0, 1.0 ); + # Set interesting background colour. + plscol0a( 15, 0, 0, 0, 0.20 ); + [colorbar_width, colorbar_height] = plcolorbar( \ + bitor(opt, bitor(PL_COLORBAR_BOUNDING_BOX, PL_COLORBAR_BACKGROUND)), \ + position, x, y, x_length, y_length, \ + 15, 1, 1, low_cap_color, high_cap_color, \ + cont_color, cont_width, label_opts, label, \ + axis_opts, ticks, sub_ticks, \ + n_values_array, values_array ); - plcolorbar( opt, 0.1, 0.1, 0.5, 0.1, - ticks, sub_ticks, - axis_opts_2, "Test label - Upper, Low Cap", - colors, values ); + # Reset text and tick sizes + plschr( 0.0, 1.0 ); + plsmaj( 0.0, 1.0 ); + plsmin( 0.0, 1.0 ); + endfor - opt = bitor(PL_POSITION_BOTTOM, bitor(bar_type, bitor(PL_COLORBAR_LABEL_BOTTOM, PL_COLORBAR_CAP_HIGH))); + # Draw a page title + title = cstrcat(char(colorbar_option_kind_labels(kind_i)), " - ", char(colorbar_cap_option_labels(cap_i)) ); + plvpor( 0.0, 1.0, 0.0, 1.0 ); + plwind( 0.0, 1.0, 0.0, 1.0 ); + plptex( 0.5, 0.5, 0.0, 0.0, 0.5, title ); +endfunction - plcolorbar( opt, 0.4, 0.1, 0.5, 0.1, - ticks, sub_ticks, - axis_opts_2, "Test label - Lower, High Cap", - colors, values ); +function plcolorbar_example( palette, kind_i, cont_color, cont_width, values ) - plvpor( 0.0, 1.0, 0.0, 1.0 ); - plwind( 0.0, 1.0, 0.0, 1.0 ); - plptex( 0.5, 0.5, 0.0, 0.0, 0.5, title ); + global COLORBAR_LABELS COLORBAR_CAPS + + # Load the color palette + plspal1( palette, 1 ); + + for label_i = 1:COLORBAR_LABELS + for cap_i = 1:COLORBAR_CAPS + plcolorbar_example_page( kind_i, label_i, cap_i, + cont_color, cont_width, values ); + endfor + endfor endfunction + + function ix33c() ## Parse and process command line arguments @@ -180,6 +244,7 @@ global PL_POSITION_LEFT PL_POSITION_RIGHT PL_POSITION_TOP PL_POSITION_BOTTOM PL_POSITION_INSIDE PL_POSITION_OUTSIDE PL_POSITION_SUBPAGE global PL_COLORBAR_IMAGE PL_COLORBAR_SHADE PL_COLORBAR_GRADIENT PL_COLORBAR_SHADE_LABEL global position_options special_symbols + global COLORBAR_KINDS plinit(); ## First page illustrating the 16 standard positions. @@ -877,18 +942,28 @@ [], [], [], [] ); max_height = max(max_height, legend_height); -if(0== 1) - ## Color bar examples - values_small = [ 0.0; 1.0 ]; - values_uneven = [ 0.0; 2.0; 2.6; 3.4; 6.0; 7.0; 8.0; 9.0; 10.0 ]; - values_even = [ 0.0; 1.0; 2.0; 3.0; 4.0; 5.0; 6.0; 7.0; 8.0 ]; - plcolorbar_example_1( PL_COLORBAR_IMAGE, 0.0, 0, values_small, "Image Color Bars" ); - plcolorbar_example_2( PL_COLORBAR_IMAGE, 0.0, 0, values_small, "Image Color Bars" ) - plcolorbar_example_1( bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0.0, 0, values_uneven, "Shade Color Bars - Uneven Steps" ); - plcolorbar_example_2( PL_COLORBAR_SHADE, 3.0, 3, values_even, "Shade Color Bars - Even Steps" ); - plcolorbar_example_1( PL_COLORBAR_GRADIENT, 0.5, 5, values_small, "Gradient Color Bars" ); - plcolorbar_example_2( PL_COLORBAR_GRADIENT, 0.5, 5, values_small, "Gradient Color Bars" ); -endif + # Color bar examples + values_small = [ -1.0e-200, 1.0e-200 ]; + values_uneven = [ -1.0e-200, 2.0e-200, 2.6e-200, 3.4e-200, 6.0e-200, 7.0e-200, 8.0e-200, 9.0e-200, 10.0e-200 ]; + values_even = [ -2.0e-200, -1.0e-200, 0.0e-200, 1.0e-200, 2.0e-200, 3.0e-200, 4.0e-200, 5.0e-200, 6.0e-200 ]; + + # Use unsaturated green background colour to contrast with black caps. + plscolbg( 70, 185, 70 ); + # Cut out the greatest and smallest bits of the color spectrum to + # leave colors for the end caps. + plscmap1_range( 0.01, 0.99 ); + + # We can only test image and gradient colorbars with two element arrays + for i = 3:COLORBAR_KINDS + plcolorbar_example( "cmap1_blue_yellow.pal", i, 0, 0, values_small ); + endfor + # Test shade colorbars with larger arrays + for i = 1:2 + plcolorbar_example( "cmap1_blue_yellow.pal", i, 4, 2, values_even ); + endfor + for i = 1:2 + plcolorbar_example( "cmap1_blue_yellow.pal", i, 0, 0, values_uneven ); + endfor plend1(); endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |