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 )
287 static value * label = NULL;
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,
517 type, minlong, maxlong, minlat, maxlat );
530 dlong, dlat, minlong, maxlong, minlat, maxlat );
546 CAMLparam5( x, y, z, xg, yg );
547 CAMLxparam2( type, data );
552 CAMLlocal2( zg, y_ml_array );
556 int npts, nptsx, nptsy;
560 npts = Wosize_val( x ) / Double_wosize;
561 if ( ( Wosize_val( y ) / Double_wosize != Wosize_val( z ) / Double_wosize ) ||
562 ( Wosize_val( y ) / Double_wosize != npts ) ||
563 ( Wosize_val( z ) / Double_wosize != npts )
566 caml_failwith(
"ml_plgriddata: x, y, z must all have the same dimensions" );
569 nptsx = Wosize_val( xg ) / Double_wosize;
570 nptsy = Wosize_val( yg ) / Double_wosize;
577 c_plgriddata( (
double *) x, (
double *) y, (
double *) z, npts, (
double *) xg, nptsx,
578 (
double *) yg, nptsy, zg_local, Int_val( type ) + 1,
579 Double_val( data ) );
582 zg = caml_alloc( nptsx, 0 );
584 for ( i = 0; i < nptsx; i++ )
587 y_ml_array = caml_alloc( nptsy * Double_wosize, Double_array_tag );
588 for ( j = 0; j < nptsy; j++ )
590 Store_double_field( y_ml_array, j, zg_local[i][j] );
592 caml_modify( &Field( zg, i ), y_ml_array );
603 return ml_plgriddata( argv[0], argv[1], argv[2], argv[3], argv[4],
615 plpoly3( n, x, y, z, draw, ifcc );
624 sprintf( exception_message,
"Error, return code %d", result );
625 caml_invalid_argument( exception_message );
634 int translated_option;
635 switch ( parse_option )
646 default: translated_option = -1;
648 return translated_option;
652 #define INIT_STRING_ARRAY( o ) \
654 o ## _length = Wosize_val( o ); \
655 const char *c_ ## o[o ## _length]; \
656 for ( i = 0; i < o ## _length; i++ ) { c_ ## o[i] = String_val( Field( o, i ) ); }
659 #define INIT_INT_ARRAY( o ) \
661 o ## _length = Wosize_val( o ); \
662 int c_ ## o[o ## _length]; \
663 for ( i = 0; i < ( o ## _length ); i++ ) { ( c_ ## o )[i] = Int_val( Field( ( o ), i ) ); }
666 #define INIT_INT_ARRAYS( o ) \
667 int o ## _length, o ## _inner; \
668 o ## _length = Wosize_val( o ); \
669 int *c_ ## o[o ## _length]; \
670 for ( i = 0; i < ( o ## _length ); i++ ) { \
671 INIT_INT_ARRAY( o ## _subarray ); \
672 ( c_ ## o )[i] = c_ ## o ## _subarray; \
681 while ( list != Val_emptylist )
684 result = result | variant_f( Int_val( Field( list, 0 ) ) );
686 list = Field( list, 1 );
689 CAMLreturn( result );
694 CAMLparam2( argv, parse_method );
697 int combined_parse_method;
704 result =
plparseopts( &argv_length, c_argv, combined_parse_method );
708 sprintf( exception_message,
"Invalid arguments in plparseopts, error %d", result );
709 caml_invalid_argument( exception_message );
711 CAMLreturn( Val_unit );
720 CAMLparam5( xspec, yspec, xmin, xmax, xjump );
721 CAMLxparam5( ymin, ymax, xlpos, ylpos, y_ascl );
722 CAMLxparam5( acc, colbox, collab, colline, styline );
723 CAMLxparam4( legline, labx, laby, labtop );
727 const char* legend_copy[4];
729 for ( i = 0; i < 4; i++ )
731 colline_copy[i] = Int_val( Field( colline, i ) );
732 styline_copy[i] = Int_val( Field( styline, i ) );
733 legend_copy[i] = String_val( Field( legline, i ) );
737 plstripc( &
id, String_val( xspec ), String_val( yspec ),
738 Double_val( xmin ), Double_val( xmax ),
739 Double_val( xjump ), Double_val( ymin ), Double_val( ymax ),
740 Double_val( xlpos ), Double_val( ylpos ), Bool_val( y_ascl ),
741 Bool_val( acc ), Int_val( colbox ), Int_val( collab ),
742 colline_copy, styline_copy, legend_copy,
743 String_val( labx ), String_val( laby ), String_val( labtop ) );
745 CAMLreturn( Val_int(
id ) );
750 return ml_plstripc( argv[0], argv[1], argv[2], argv[3], argv[4],
751 argv[5], argv[6], argv[7], argv[8], argv[9],
752 argv[10], argv[11], argv[12], argv[13], argv[14],
753 argv[15], argv[16], argv[17], argv[18] );
758 int translated_option;
759 switch ( legend_option )
769 default: translated_option = -1;
771 return translated_option;
776 int translated_option;
777 switch ( colorbar_option )
796 default: translated_option = -1;
798 return translated_option;
803 int translated_option;
804 switch ( position_option )
814 default: translated_option = -1;
816 return translated_option;
827 value box_line_widths,
832 CAMLparam5( position, opt, x, y, plot_width );
833 CAMLxparam5( bg_color, bb_color, bb_style, nrow, ncolumn );
834 CAMLxparam5( opt_array, text_offset, text_scale, text_spacing, text_justification );
835 CAMLxparam5( text_colors, text, box_colors, box_patterns, box_scales );
836 CAMLxparam5( box_line_widths, line_colors, line_styles, line_widths, symbol_colors );
837 CAMLxparam3( symbol_scales, symbol_numbers, symbols );
838 CAMLlocal1( result );
839 result = caml_alloc( 2, 0 );
844 int c_position, c_opt;
847 n_legend = Wosize_val( opt_array );
849 int c_opt_array[n_legend];
869 for ( i = 0; i < n_legend; i++ )
878 pllegend( &width, &height, c_opt, c_position, Double_val( x ), Double_val( y ),
879 Double_val( plot_width ), Int_val( bg_color ),
880 Int_val( bb_color ), Int_val( bb_style ),
881 Int_val( nrow ), Int_val( ncolumn ),
882 n_legend, c_opt_array,
883 Double_val( text_offset ), Double_val( text_scale ),
884 Double_val( text_spacing ),
885 Double_val( text_justification ),
886 c_text_colors, c_text,
887 c_box_colors, c_box_patterns, (
double *) box_scales,
888 (
double *) box_line_widths,
889 c_line_colors, c_line_styles, (
double *) line_widths,
890 c_symbol_colors, (
double *) symbol_scales, c_symbol_numbers,
894 Store_field( result, 0, caml_copy_double( width ) );
895 Store_field( result, 1, caml_copy_double( height ) );
897 CAMLreturn( result );
902 return ml_pllegend( argv[0], argv[1], argv[2], argv[3], argv[4],
903 argv[5], argv[6], argv[7], argv[8], argv[9],
904 argv[10], argv[11], argv[12], argv[13], argv[14],
905 argv[15], argv[16], argv[17], argv[18], argv[19],
906 argv[20], argv[21], argv[22], argv[23], argv[24],
907 argv[25], argv[26], argv[27] );
920 CAMLparam5( opt, position, x, y, x_length );
921 CAMLxparam5( y_length, bg_color, bb_color, bb_style, low_cap_color );
922 CAMLxparam5( high_cap_color, cont_color, cont_width, label_opts, label );
923 CAMLxparam4( axis_opts, ticks, sub_ticks, values );
924 CAMLlocal1( result );
925 result = caml_alloc( 2, 0 );
930 int c_opt, c_position;
933 n_labels = Wosize_val( label_opts );
936 n_axes = Wosize_val( axis_opts );
951 int c_label_opts[ n_labels ];
952 for ( i = 0; i < n_labels; i++ )
959 int n_values[ n_axes ];
960 c_values = malloc( n_axes *
sizeof (
double * ) );
962 for ( i = 0; i < n_axes; i++ )
964 c_values[i] = (
double *) Field( values, i );
965 n_values[i] = Wosize_val( Field( values, i ) ) / Double_wosize;
972 c_opt, c_position, Double_val( x ), Double_val( y ),
973 Double_val( x_length ), Double_val( y_length ),
974 Int_val( bg_color ), Int_val( bb_color ), Int_val( bb_style ),
975 Double_val( low_cap_color ), Double_val( high_cap_color ),
976 Int_val( cont_color ), Double_val( cont_width ),
977 n_labels, c_label_opts, c_label,
979 (
double *) ticks, c_sub_ticks,
980 n_values, (
const PLFLT *
const *) c_values );
983 Store_field( result, 0, caml_copy_double( width ) );
984 Store_field( result, 1, caml_copy_double( height ) );
986 CAMLreturn( result );
991 return ml_plcolorbar( argv[0], argv[1], argv[2], argv[3], argv[4],
992 argv[5], argv[6], argv[7], argv[8], argv[9],
993 argv[10], argv[11], argv[12], argv[13], argv[14],
994 argv[15], argv[16], argv[17], argv[18] );
998 void ml_pltr0(
double x,
double y,
double* tx,
double* ty )
1000 pltr0( x, y, tx, ty, NULL );
1005 CAMLparam4( xg, yg, x, y );
1006 CAMLlocal1( tx_ty );
1007 tx_ty = caml_alloc( 2, 0 );
1011 grid.
xg = (
double *) xg;
1012 grid.
yg = (
double *) yg;
1013 grid.
nx = Wosize_val( xg ) / Double_wosize;
1014 grid.
ny = Wosize_val( yg ) / Double_wosize;
1015 pltr1( Double_val( x ), Double_val( y ), &tx, &ty, (
PLPointer ) & grid );
1018 Store_field( tx_ty, 0, caml_copy_double( tx ) );
1019 Store_field( tx_ty, 1, caml_copy_double( ty ) );
1020 CAMLreturn( tx_ty );
1025 CAMLparam4( xg, yg, x, y );
1026 CAMLlocal1( tx_ty );
1027 tx_ty = caml_alloc( 2, 0 );
1041 length1 = Wosize_val( xg );
1043 length2 = Wosize_val( Field( xg, 0 ) ) / Double_wosize;
1044 c_xg = malloc( length1 *
sizeof (
double* ) );
1045 for ( i = 0; i < length1; i++ )
1047 c_xg[i] = (
double *) Field( xg, i );
1049 c_yg = malloc( length1 *
sizeof (
double* ) );
1050 for ( i = 0; i < length1; i++ )
1052 c_yg[i] = (
double *) Field( yg, i );
1059 pltr2( Double_val( x ), Double_val( y ), &tx, &ty, (
PLPointer ) & grid );
1066 Store_field( tx_ty, 0, caml_copy_double( tx ) );
1067 Store_field( tx_ty, 1, caml_copy_double( ty ) );
1068 CAMLreturn( tx_ty );