21 #include <caml/alloc.h>
22 #include <caml/callback.h>
23 #include <caml/fail.h>
24 #include <caml/memory.h>
25 #include <caml/misc.h>
26 #include <caml/mlvalues.h>
27 #include <caml/bigarray.h>
36 #define MAX_EXCEPTION_MESSAGE_LENGTH 1000
37 #define CAML_PLPLOT_PLOTTER_FUNC_NAME "caml_plplot_plotter"
38 #define CAML_PLPLOT_MAPFORM_FUNC_NAME "caml_plplot_mapform"
39 #define CAML_PLPLOT_DEFINED_FUNC_NAME "caml_plplot_defined"
40 #define CAML_PLPLOT_LABEL_FUNC_NAME "caml_plplot_customlabel"
41 #define CAML_PLPLOT_ABORT_FUNC_NAME "caml_plplot_abort"
42 #define CAML_PLPLOT_EXIT_FUNC_NAME "caml_plplot_exit"
43 #define CAML_PLPLOT_TRANSFORM_FUNC_NAME "caml_plplot_transform"
73 caml_callback2( *pltr, caml_copy_double( x ), caml_copy_double( y ) );
75 new_x = Double_val( Field( result, 0 ) );
76 new_y = Double_val( Field( result, 1 ) );
98 static value * defined = NULL;
99 if ( defined == NULL )
105 caml_callback2( *defined, caml_copy_double( x ), caml_copy_double( y ) );
106 is_it_defined = Int_val( result );
108 CAMLreturn( is_it_defined );
117 CAMLlocal1( result );
121 if ( mapform == NULL )
127 for ( i = 0; i < n; i++ )
130 caml_callback2( *mapform,
131 caml_copy_double( x[i] ), caml_copy_double( y[i] ) );
134 new_x = Double_val( Field( result, 0 ) );
135 new_y = Double_val( Field( result, 1 ) );
149 CAMLlocal1( result );
152 static value * callback = NULL;
153 if ( callback == NULL )
159 caml_callback2( *callback, Val_int( axis - 1 ), caml_copy_double( n ) );
162 snprintf( label, length,
"%s", String_val( result ) );
171 CAMLlocal1( result );
174 static value * handler = NULL;
175 if ( handler == NULL )
181 caml_callback( *handler, caml_copy_string( message ) );
190 CAMLlocal1( result );
193 static value * handler = NULL;
194 if ( handler == NULL )
200 caml_callback( *handler, caml_copy_string( message ) );
202 CAMLreturn( Int_val( result ) );
211 CAMLlocal1( result );
214 static value * transform = NULL;
215 if ( transform == NULL )
221 caml_callback2( *transform, caml_copy_double( x ), caml_copy_double( y ) );
223 *xt = Double_val( Field( result, 0 ) );
224 *yt = Double_val( Field( result, 1 ) );
237 if ( pltr == NULL || Val_int( 0 ) == *pltr )
250 static value * defined = NULL;
251 if ( defined == NULL )
254 if ( defined == NULL || Val_int( 0 ) == *defined )
268 if ( mapform == NULL )
271 if ( mapform == NULL || Val_int( 0 ) == *mapform )
291 if ( label == NULL || Val_int( 0 ) == *label )
302 CAMLreturn( Val_unit );
309 static value * handler = NULL;
310 if ( handler == NULL )
313 if ( handler == NULL || Val_int( 0 ) == *handler )
323 CAMLreturn( Val_unit );
328 static value * handler = NULL;
329 if ( handler == NULL )
332 if ( handler == NULL || Val_int( 0 ) == *handler )
342 CAMLreturn( Val_unit );
349 static value * handler = NULL;
350 if ( handler == NULL )
353 if ( handler == NULL || Val_int( 0 ) == *handler )
363 CAMLreturn( Val_unit );
388 caml_invalid_argument(
"A custom plotter must be defined \
389 before calling plcont" );
393 c_plcont( f, nx, ny, kx, lx, ky, ly, clevel, nlevel,
420 left, right, bottom, top,
421 shade_min, shade_max,
422 sh_cmap, sh_color, sh_width, min_color, min_width,
423 max_color, max_width,
plfill, rectangular,
458 xmin, xmax, ymin, ymax,
459 clevel, nlevel, fill_width,
460 cont_color, cont_width,
480 xmin, xmax, ymin, ymax,
509 type, minlong, maxlong, minlat, maxlat );
522 dlong, dlat, minlong, maxlong, minlat, maxlat );
538 CAMLparam5( x, y, z, xg, yg );
539 CAMLxparam2( type, data );
544 CAMLlocal2( zg, y_ml_array );
548 int npts, nptsx, nptsy;
552 npts = Wosize_val( x ) / Double_wosize;
553 if ( ( Wosize_val( y ) / Double_wosize != Wosize_val( z ) / Double_wosize ) ||
554 ( Wosize_val( y ) / Double_wosize != npts ) ||
555 ( Wosize_val( z ) / Double_wosize != npts )
558 caml_failwith(
"ml_plgriddata: x, y, z must all have the same dimensions" );
561 nptsx = Wosize_val( xg ) / Double_wosize;
562 nptsy = Wosize_val( yg ) / Double_wosize;
569 c_plgriddata( (
double *) x, (
double *) y, (
double *) z, npts, (
double *) xg, nptsx,
570 (
double *) yg, nptsy, zg_local, Int_val( type ) + 1,
571 Double_val( data ) );
574 zg = caml_alloc( nptsx, 0 );
576 for ( i = 0; i < nptsx; i++ )
579 y_ml_array = caml_alloc( nptsy * Double_wosize, Double_array_tag );
580 for ( j = 0; j < nptsy; j++ )
582 Store_double_field( y_ml_array, j, zg_local[i][j] );
584 caml_modify( &Field( zg, i ), y_ml_array );
595 return ml_plgriddata( argv[0], argv[1], argv[2], argv[3], argv[4],
607 plpoly3( n, x, y, z, draw, ifcc );
616 sprintf( exception_message,
"Error, return code %d", result );
617 caml_invalid_argument( exception_message );
626 int translated_option;
627 switch ( parse_option )
638 default: translated_option = -1;
640 return translated_option;
644 #define INIT_STRING_ARRAY( o ) \
646 o ## _length = Wosize_val( o ); \
647 const char *c_ ## o[o ## _length]; \
648 for ( i = 0; i < o ## _length; i++ ) { c_ ## o[i] = String_val( Field( o, i ) ); }
651 #define INIT_INT_ARRAY( o ) \
653 o ## _length = Wosize_val( o ); \
654 int c_ ## o[o ## _length]; \
655 for ( i = 0; i < ( o ## _length ); i++ ) { ( c_ ## o )[i] = Int_val( Field( ( o ), i ) ); }
658 #define INIT_INT_ARRAYS( o ) \
659 int o ## _length, o ## _inner; \
660 o ## _length = Wosize_val( o ); \
661 int *c_ ## o[o ## _length]; \
662 for ( i = 0; i < ( o ## _length ); i++ ) { \
663 INIT_INT_ARRAY( o ## _subarray ); \
664 ( c_ ## o )[i] = c_ ## o ## _subarray; \
673 while ( list != Val_emptylist )
676 result = result | variant_f( Int_val( Field( list, 0 ) ) );
678 list = Field( list, 1 );
681 CAMLreturn( result );
686 CAMLparam2( argv, parse_method );
689 int combined_parse_method;
696 result =
plparseopts( &argv_length, c_argv, combined_parse_method );
700 sprintf( exception_message,
"Invalid arguments in plparseopts, error %d", result );
701 caml_invalid_argument( exception_message );
703 CAMLreturn( Val_unit );
712 CAMLparam5( xspec, yspec, xmin, xmax, xjump );
713 CAMLxparam5( ymin, ymax, xlpos, ylpos, y_ascl );
714 CAMLxparam5( acc, colbox, collab, colline, styline );
715 CAMLxparam4( legline, labx, laby, labtop );
719 const char* legend_copy[4];
721 for ( i = 0; i < 4; i++ )
723 colline_copy[i] = Int_val( Field( colline, i ) );
724 styline_copy[i] = Int_val( Field( styline, i ) );
725 legend_copy[i] = String_val( Field( legline, i ) );
729 plstripc( &
id, String_val( xspec ), String_val( yspec ),
730 Double_val( xmin ), Double_val( xmax ),
731 Double_val( xjump ), Double_val( ymin ), Double_val( ymax ),
732 Double_val( xlpos ), Double_val( ylpos ), Bool_val( y_ascl ),
733 Bool_val( acc ), Int_val( colbox ), Int_val( collab ),
734 colline_copy, styline_copy, legend_copy,
735 String_val( labx ), String_val( laby ), String_val( labtop ) );
737 CAMLreturn( Val_int(
id ) );
742 return ml_plstripc( argv[0], argv[1], argv[2], argv[3], argv[4],
743 argv[5], argv[6], argv[7], argv[8], argv[9],
744 argv[10], argv[11], argv[12], argv[13], argv[14],
745 argv[15], argv[16], argv[17], argv[18] );
750 int translated_option;
751 switch ( legend_option )
761 default: translated_option = -1;
763 return translated_option;
768 int translated_option;
769 switch ( colorbar_option )
788 default: translated_option = -1;
790 return translated_option;
795 int translated_option;
796 switch ( position_option )
806 default: translated_option = -1;
808 return translated_option;
819 value box_line_widths,
824 CAMLparam5( position, opt, x, y, plot_width );
825 CAMLxparam5( bg_color, bb_color, bb_style, nrow, ncolumn );
826 CAMLxparam5( opt_array, text_offset, text_scale, text_spacing, text_justification );
827 CAMLxparam5( text_colors, text, box_colors, box_patterns, box_scales );
828 CAMLxparam5( box_line_widths, line_colors, line_styles, line_widths, symbol_colors );
829 CAMLxparam3( symbol_scales, symbol_numbers, symbols );
830 CAMLlocal1( result );
831 result = caml_alloc( 2, 0 );
836 int c_position, c_opt;
839 n_legend = Wosize_val( opt_array );
841 int c_opt_array[n_legend];
861 for ( i = 0; i < n_legend; i++ )
870 pllegend( &width, &height, c_opt, c_position, Double_val( x ), Double_val( y ),
871 Double_val( plot_width ), Int_val( bg_color ),
872 Int_val( bb_color ), Int_val( bb_style ),
873 Int_val( nrow ), Int_val( ncolumn ),
874 n_legend, c_opt_array,
875 Double_val( text_offset ), Double_val( text_scale ),
876 Double_val( text_spacing ),
877 Double_val( text_justification ),
878 c_text_colors, c_text,
879 c_box_colors, c_box_patterns, (
double *) box_scales,
880 (
double *) box_line_widths,
881 c_line_colors, c_line_styles, (
double *) line_widths,
882 c_symbol_colors, (
double *) symbol_scales, c_symbol_numbers,
886 Store_field( result, 0, caml_copy_double( width ) );
887 Store_field( result, 1, caml_copy_double( height ) );
889 CAMLreturn( result );
894 return ml_pllegend( argv[0], argv[1], argv[2], argv[3], argv[4],
895 argv[5], argv[6], argv[7], argv[8], argv[9],
896 argv[10], argv[11], argv[12], argv[13], argv[14],
897 argv[15], argv[16], argv[17], argv[18], argv[19],
898 argv[20], argv[21], argv[22], argv[23], argv[24],
899 argv[25], argv[26], argv[27] );
912 CAMLparam5( opt, position, x, y, x_length );
913 CAMLxparam5( y_length, bg_color, bb_color, bb_style, low_cap_color );
914 CAMLxparam5( high_cap_color, cont_color, cont_width, label_opts, label );
915 CAMLxparam4( axis_opts, ticks, sub_ticks, values );
916 CAMLlocal1( result );
917 result = caml_alloc( 2, 0 );
922 int c_opt, c_position;
925 n_labels = Wosize_val( label_opts );
928 n_axes = Wosize_val( axis_opts );
952 c_values = malloc( n_axes *
sizeof (
double * ) );
954 for ( i = 0; i < n_axes; i++ )
956 c_values[i] = (
double *) Field( values, i );
957 n_values[i] = Wosize_val( Field( values, i ) ) / Double_wosize;
964 c_opt, c_position, Double_val( x ), Double_val( y ),
965 Double_val( x_length ), Double_val( y_length ),
966 Int_val( bg_color ), Int_val( bb_color ), Int_val( bb_style ),
967 Double_val( low_cap_color ), Double_val( high_cap_color ),
968 Int_val( cont_color ), Double_val( cont_width ),
969 n_labels, c_label_opts, c_label,
971 (
double *) ticks, c_sub_ticks,
972 n_values, (
const PLFLT *
const *) c_values );
975 Store_field( result, 0, caml_copy_double( width ) );
976 Store_field( result, 1, caml_copy_double( height ) );
978 CAMLreturn( result );
983 return ml_plcolorbar( argv[0], argv[1], argv[2], argv[3], argv[4],
984 argv[5], argv[6], argv[7], argv[8], argv[9],
985 argv[10], argv[11], argv[12], argv[13], argv[14],
986 argv[15], argv[16], argv[17], argv[18] );
992 pltr0( x, y, tx, ty, NULL );
997 CAMLparam4( xg, yg, x, y );
999 tx_ty = caml_alloc( 2, 0 );
1003 grid.
xg = (
double *) xg;
1004 grid.
yg = (
double *) yg;
1005 grid.
nx = Wosize_val( xg ) / Double_wosize;
1006 grid.
ny = Wosize_val( yg ) / Double_wosize;
1007 pltr1( Double_val( x ), Double_val( y ), &tx, &ty, (
PLPointer ) & grid );
1010 Store_field( tx_ty, 0, caml_copy_double( tx ) );
1011 Store_field( tx_ty, 1, caml_copy_double( ty ) );
1012 CAMLreturn( tx_ty );
1017 CAMLparam4( xg, yg, x, y );
1018 CAMLlocal1( tx_ty );
1019 tx_ty = caml_alloc( 2, 0 );
1033 length1 = Wosize_val( xg );
1035 length2 = Wosize_val( Field( xg, 0 ) ) / Double_wosize;
1036 c_xg = malloc( length1 *
sizeof (
double* ) );
1037 for ( i = 0; i < length1; i++ )
1039 c_xg[i] = (
double *) Field( xg, i );
1041 c_yg = malloc( length1 *
sizeof (
double* ) );
1042 for ( i = 0; i < length1; i++ )
1044 c_yg[i] = (
double *) Field( yg, i );
1051 pltr2( Double_val( x ), Double_val( y ), &tx, &ty, (
PLPointer ) & grid );
1058 Store_field( tx_ty, 0, caml_copy_double( tx ) );
1059 Store_field( tx_ty, 1, caml_copy_double( ty ) );
1060 CAMLreturn( tx_ty );