123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170openStdcompatmoduleLowlevel=Lowlevel(** Available workstation types, see also {{: (** Available line types, see also {{: https://gr-framework.org/workstations.html} GR Workstation Types} *)} GR Line Types} *)typeworkstation_type=|WISS(** Workstation Independent Segment ptr Storage *)|WinGDI(** Windows ptr GDI *)|PS_1(**PostScript (b/w @-> color) *)|PS_2(**PostScript (b/w @-> color) *)|PS_3(**PostScript (b/w @-> color) *)|PS_4(**PostScript (b/w @-> color) *)|PDFPlain(** Portable Document Format ptr plain *)|PDFCompressed(** Portable Document Format ptr compressed *)|X_1(** X ptr Windows *)|X_2(** X ptr Windows *)|X_3(** X ptr Windows *)|X_4(** X ptr Windows *)|SunRF(** Sun Raster file (RF) *)|GIF87(** Graphics Interchange Format ptr GIF87 *)|GIF89(**Graphics Interchange Format ptr GIF89 *)|MotifUIL(** Motif User Interface Language (UIL) *)|BMP(** Windows Bitmap (BMP) *)|JPEG(** JPEG image ptr file *)|PNG(** Portable Network Graphics file (PNG) *)|TIFF(** Tagged Image File Format (TIFF) *)|Gtk(** ptr Gtk *)|Wx(** ptr wxWidgets *)|Qt4(** ptr Qt4 *)|SVG(** Scaleable Vector Graphics (SVG) *)|WMF(** Windows ptr Metafile *)|Quartz(** ptr Quartz *)|Sock(** Socket ptr driver *)|ZMQ(** 0MQ ptr driver *)|OGL(** ptr OpenGL *)letint_of_workstation_type=function|WISS->5|WinGDI->41|PS_1->61|PS_2->62|PS_3->63|PS_4->64|PDFPlain->101|PDFCompressed->102|X_1->210|X_2->211|X_3->213|X_4->212|SunRF->214|GIF87->215|GIF89->218|MotifUIL->216|BMP->320|JPEG->321|PNG->322|TIFF->323|Gtk->371|Wx->380|Qt4->381|SVG->382|WMF->390|Quartz->400|Sock->410|ZMQ->415|OGL->420(** Available line types, see also {{: https://gr-framework.org/linetypes.html} GR Line Types} *)typelinetype=|SOLID(** Solid line *)|DASHED(** Dashed line *)|DOTTED(** Dotted line *)|DASHED_DOTTED(** Dashed-dotted line *)|DASH_2_DOT(** Sequence of one dash followed by two dots *)|DASH_3_DOT(** Sequence of one dash followed by three dots *)|LONG_DASH(** Sequence of long dashes *)|LONG_SHORT_DASH(** Sequence of a long dash followed by a short dash *)|SPACED_DASH(** Sequence of dashes double spaced *)|SPACED_DOT(** Sequence of dots double spaced *)|DOUBLE_DOT(** Sequence of pairs of dots *)|TRIPLE_DOT(** Sequence of groups of three dots *)letint_of_linetype=function|SOLID->1|DASHED->2|DOTTED->3|DASHED_DOTTED->4|DASH_2_DOT->-1|DASH_3_DOT->-2|LONG_DASH->-3|LONG_SHORT_DASH->-4|SPACED_DASH->-5|SPACED_DOT->-6|DOUBLE_DOT->-7|TRIPLE_DOT->-8(* let linetype_of_int = function
| 1 -> SOLID
| 2 -> DASHED
| 3 -> DOTTED
| 4 -> DASHED_DOTTED
| -1 -> DASH_2_DOT
| -2 -> DASH_3_DOT
| -3 -> LONG_DASH
| -4 -> LONG_SHORT_DASH
| -5 -> SPACED_DASH
| -6 -> SPACED_DOT
| -7 -> DOUBLE_DOT
| -8 -> TRIPLE_DOT
| d -> failwith @@ "Error when inferring line type. Got " ^ string_of_int d *)(** Available marker types, see also {{: https://gr-framework.org/markertypes.html} GR Marker Types} *)typemarkertype=|DOT(** Smallest displayable dot *)|PLUS(** Plus sign *)|ASTERISK(** Asterisk *)|CIRCLE(** Hollow circle *)|DIAGONAL_CROSS(** Diagonal cross *)|SOLID_CIRCLE(** Filled circle *)|TRIANGLE_UP(** Hollow triangle pointing upward *)|SOLID_TRI_UP(** Filled triangle pointing upward *)|TRIANGLE_DOWN(** Hollow triangle pointing downward *)|SOLID_TRI_DOWN(** Filled triangle pointing downward *)|SQUARE(** Hollow square *)|SOLID_SQUARE(** Filled square *)|BOWTIE(** Hollow bowtie *)|SOLID_BOWTIE(** Filled bowtie *)|HGLASS(** Hollow hourglass *)|SOLID_HGLASS(** Filled hourglass *)|DIAMOND(** Hollow diamond *)|SOLID_DIAMOND(** Filled Diamond *)|STAR(** Hollow star *)|SOLID_STAR(** Filled Star *)|TRI_UP_DOWN(** Hollow triangles pointing up and down overlaid *)|SOLID_TRI_RIGHT(** Filled triangle point right *)|SOLID_TRI_LEFT(** Filled triangle pointing left *)|HOLLOW_PLUS(** Hollow plus sign *)|SOLID_PLUS(** Solid plus sign *)|PENTAGON(** Pentagon *)|HEXAGON(** Hexagon *)|HEPTAGON(** Heptagon *)|OCTAGON(** Octagon *)|STAR_4(** 4-pointed star *)|STAR_5(** 5-pointed star (pentagram) *)|STAR_6(** 6-pointed star (hexagram) *)|STAR_7(** 7-pointed star (heptagram) *)|STAR_8(** 8-pointed star (octagram) *)|VLINE(** verical line *)|HLINE(** horizontal line *)|OMARK(** o-mark *)letint_of_markertype=function|DOT->1|PLUS->2|ASTERISK->3|CIRCLE->4|DIAGONAL_CROSS->5|SOLID_CIRCLE->-1|TRIANGLE_UP->-2|SOLID_TRI_UP->-3|TRIANGLE_DOWN->-4|SOLID_TRI_DOWN->-5|SQUARE->-6|SOLID_SQUARE->-7|BOWTIE->-8|SOLID_BOWTIE->-9|HGLASS->-10|SOLID_HGLASS->-11|DIAMOND->-12|SOLID_DIAMOND->-13|STAR->-14|SOLID_STAR->-15|TRI_UP_DOWN->-16|SOLID_TRI_RIGHT->-17|SOLID_TRI_LEFT->-18|HOLLOW_PLUS->-19|SOLID_PLUS->-20|PENTAGON->-21|HEXAGON->-22|HEPTAGON->-23|OCTAGON->-24|STAR_4->-25|STAR_5->-26|STAR_6->-27|STAR_7->-28|STAR_8->-29|VLINE->-30|HLINE->-31|OMARK->-32(* let markertype_of_int = function
| 1 -> DOT
| 2 -> PLUS
| 3 -> ASTERISK
| 4 -> CIRCLE
| 5 -> DIAGONAL_CROSS
| -1 -> SOLID_CIRCLE
| -2 -> TRIANGLE_UP
| -3 -> SOLID_TRI_UP
| -4 -> TRIANGLE_DOWN
| -5 -> SOLID_TRI_DOWN
| -6 -> SQUARE
| -7 -> SOLID_SQUARE
| -8 -> BOWTIE
| -9 -> SOLID_BOWTIE
| -10 -> HGLASS
| -11 -> SOLID_HGLASS
| -12 -> DIAMOND
| -13 -> SOLID_DIAMOND
| -14 -> STAR
| -15 -> SOLID_STAR
| -16 -> TRI_UP_DOWN
| -17 -> SOLID_TRI_RIGHT
| -18 -> SOLID_TRI_LEFT
| -19 -> HOLLOW_PLUS
| -20 -> SOLID_PLUS
| -21 -> PENTAGON
| -22 -> HEXAGON
| -23 -> HEPTAGON
| -24 -> OCTAGON
| -25 -> STAR_4
| -26 -> STAR_5
| -27 -> STAR_6
| -28 -> STAR_7
| -29 -> STAR_8
| -30 -> VLINE
| -31 -> HLINE
| -32 -> OMARK
| d -> failwith @@ "Error when inferring marker type. Got " ^ string_of_int d *)typescale_options=|OPTION_X_LOG(** Logarithmic X-axis *)|OPTION_Y_LOG(** Logarithmic Y-axis *)|OPTION_Z_LOG(** Logarithmic Z-axis *)|OPTION_FLIP_X(** Flip X-axis *)|OPTION_FLIP_Y(** Flip Y-axis *)|OPTION_FLIP_Z(** Flip Z-axis *)letint_of_scale_optionsopts=letint_of=function|OPTION_X_LOG->1|OPTION_Y_LOG->2|OPTION_Z_LOG->4|OPTION_FLIP_X->8|OPTION_FLIP_Y->16|OPTION_FLIP_Z->32inList.fold_left(funaccs->acc+int_ofs)0optstypespline_algo=|GeneralizedCrossValidatedSmoothing|InterpolatingNaturalCubic|CubicBSplineletint_of_spline_algo=function|GeneralizedCrossValidatedSmoothing->1|InterpolatingNaturalCubic->0|CubicBSpline->-1(** Available fonts, see also {{: https://gr-framework.org/fonts.html} GR Font list} *)typefont=|TIMES_ROMAN|TIMES_ITALIC|TIMES_BOLD|TIMES_BOLDITALIC|HELVETICA|HELVETICA_OBLIQUE|HELVETICA_BOLD|HELVETICA_BOLDOBLIQUE|COURIER|COURIER_OBLIQUE|COURIER_BOLD|COURIER_BOLDOBLIQUE|SYMBOL|BOOKMAN_LIGHT|BOOKMAN_LIGHTITALIC|BOOKMAN_DEMI|BOOKMAN_DEMIITALIC|NEWCENTURYSCHLBK_ROMAN|NEWCENTURYSCHLBK_ITALIC|NEWCENTURYSCHLBK_BOLD|NEWCENTURYSCHLBK_BOLDITALIC|AVANTGARDE_BOOK|AVANTGARDE_BOOKOBLIQUE|AVANTGARDE_DEMI|AVANTGARDE_DEMIOBLIQUE|PALATINO_ROMAN|PALATINO_ITALIC|PALATINO_BOLD|PALATINO_BOLDITALIC|ZAPFCHANCERY_MEDIUMITALIC|ZAPFDINGBATSletint_of_font=function|TIMES_ROMAN->101|TIMES_ITALIC->102|TIMES_BOLD->103|TIMES_BOLDITALIC->104|HELVETICA->105|HELVETICA_OBLIQUE->106|HELVETICA_BOLD->107|HELVETICA_BOLDOBLIQUE->108|COURIER->109|COURIER_OBLIQUE->110|COURIER_BOLD->111|COURIER_BOLDOBLIQUE->112|SYMBOL->113|BOOKMAN_LIGHT->114|BOOKMAN_LIGHTITALIC->115|BOOKMAN_DEMI->116|BOOKMAN_DEMIITALIC->117|NEWCENTURYSCHLBK_ROMAN->118|NEWCENTURYSCHLBK_ITALIC->119|NEWCENTURYSCHLBK_BOLD->120|NEWCENTURYSCHLBK_BOLDITALIC->121|AVANTGARDE_BOOK->122|AVANTGARDE_BOOKOBLIQUE->123|AVANTGARDE_DEMI->124|AVANTGARDE_DEMIOBLIQUE->125|PALATINO_ROMAN->126|PALATINO_ITALIC->127|PALATINO_BOLD->128|PALATINO_BOLDITALIC->129|ZAPFCHANCERY_MEDIUMITALIC->130|ZAPFDINGBATS->131typetext_precision=|STRING(** String precision (higher quality) *)|CHAR(** Character precision (medium quality) *)|STROKE(** Stroke precision (lower quality) *)letint_of_text_precision=function|STRING->0|CHAR->1|STROKE->2typetext_path_direction=|RIGHT(** left-to-right *)|LEFT(** right-to-left *)|UP(** downside-up *)|DOWN(** upside-down *)letint_of_text_path_direction=function|RIGHT->0|LEFT->1|UP->2|DOWN->3typetext_halign=|NORMAL|LEFT(** Left justify *)|CENTER(** Center justify *)|RIGHT(** Right justify *)letint_of_text_halign=function|NORMAL->0|LEFT->1|CENTER->2|RIGHT->3typetext_valign=|NORMAL|TOP(** Align with the top of the characters *)|CAP(** Aligned with the cap of the characters *)|HALF(** Aligned with the half line of the characters *)|BASE(** Aligned with the base line of the characters *)|BOTTOM(** Aligned with the bottom line of the characters *)letint_of_text_valign=function|NORMAL->0|TOP->1|CAP->2|HALF->3|BASE->4|BOTTOM->5(** Pattern style, see also {{: https://gr-framework.org/patterns.html} GR Fill Patterns and Hatches} *)typepattern_style=intletpattern_stylen=ifn>0&&n<109thennelsefailwith"pattern_style out of range"(** Hatch style, see also {{: https://gr-framework.org/patterns.html} GR Fill Patterns and Hatches} *)typehatch_style=intlethatch_stylen=ifn>1&&n<11thennelsefailwith"hatch_style out of range"typefill_style=|HOLLOW(** No filling. Just draw the bounding polyline *)|SOLID(** Fill the interior of the polygon using the fill color index *)|PATTERNofpattern_style(** Fill the interior of the polygon using the style index as a pattern index *)|HATCHofhatch_style(** Fill the interior of the polygon using the style index as a cross-hatched style *)letint_of_fill_style=function|HOLLOW->0|SOLID->1|PATTERN_->2|HATCH_->3(** Color Maps, see also {{: https://gr-framework.org/colormaps.html} GR Color Maps} *)typecolor_map=|Uniform|Temperature|Grayscale|Glowing|Rainbowlike|Geologic|Greenscale|Cyanscale|Bluescale|Magentascale|Redscale|Flame|Brownscale|Pilatus|Autumn|Bone|Cool|Copper|Gray|Hot|Hsv|Jet|Pink|Spectral|Spring|Summer|Winter|Gist_Earth|Gist_Heat|Gist_Ncar|Gist_Rainbow|Gist_Stern|Afmhot|Brg|Bwr|Coolwarm|Cmrmap|Cubehelix|Gnuplot|Gnuplot2|Ocean|Rainbow|Seismic|Terrain|Viridis|Inferno|Plasma|Magmaletint_of_color_map=function|Uniform->0|Temperature->1|Grayscale->2|Glowing->3|Rainbowlike->4|Geologic->5|Greenscale->6|Cyanscale->7|Bluescale->8|Magentascale->9|Redscale->10|Flame->11|Brownscale->12|Pilatus->13|Autumn->14|Bone->15|Cool->16|Copper->17|Gray->18|Hot->19|Hsv->20|Jet->21|Pink->22|Spectral->23|Spring->24|Summer->25|Winter->26|Gist_Earth->27|Gist_Heat->28|Gist_Ncar->29|Gist_Rainbow->30|Gist_Stern->31|Afmhot->32|Brg->33|Bwr->34|Coolwarm->35|Cmrmap->36|Cubehelix->37|Gnuplot->38|Gnuplot2->39|Ocean->40|Rainbow->41|Seismic->42|Terrain->43|Viridis->44|Inferno->45|Plasma->46|Magma->47typesurface_options=|LINES(** Use X Y polylines to denote the surface *)|MESH(** Use a wire grid to denote the surface *)|FILLED_MESH(** Applies an opaque grid to the surface *)|Z_SHADED_MESH(** Applies Z-value shading to the surface *)|COLORED_MESH(** Applies a colored grid to the surface *)|CELL_ARRAY(** Applies a grid of individually-colored cells to the surface *)|SHADED_MESH(** Applies light source shading to the 3-D surface *)letint_of_surface_options=function|LINES->0|MESH->1|FILLED_MESH->2|Z_SHADED_MESH->3|COLORED_MESH->4|CELL_ARRAY->5|SHADED_MESH->6moduleWorkstation=structtypeid=Wofintletwidid=Widletopen_(Wid)conntyp=Lowlevel.openwsidconn(int_of_workstation_typetyp)letclose(Wid)=Lowlevel.closewsidletactivate(Wid)=Lowlevel.activatewsidletdeactivate(Wid)=Lowlevel.deactivatewsidletclear=Lowlevel.clearwsletupdate=Lowlevel.updatewsletset_window=Lowlevel.setwswindowletset_viewport=Lowlevel.setwsviewportletcopy_segment=Lowlevel.copysegwsletredraw_segment=Lowlevel.redrawsegwsendmoduleGks=structletemergency_close=Lowlevel.emergencyclosegksletupdate=Lowlevel.updategksendmoduleState=structletsave()=Lowlevel.savestate()letrestore()=Lowlevel.restorestate()letwith_sandboxf=save();Fun.protect~finally:restorefendletset_window=Lowlevel.setwindowletset_viewport=Lowlevel.setviewportletselect_transformation=Lowlevel.selntranletclipc=Lowlevel.setclip(ifcthen1else2)typesegment=intletsegmenti=iletcreate_segment=Lowlevel.createsegletset_segment_transform=Lowlevel.setsegtranletclose_segment=Lowlevel.closesegletset_space=Lowlevel.setspaceletset_linetypelt=lt|>int_of_linetype|>Lowlevel.setlinetypeletset_linewidth=Lowlevel.setlinewidthletset_linecolorindex=function|cwhenc>=0&&c<1256->Lowlevel.setlinecolorindc|c->failwith@@"Color index must be in the range [0, 1256]. Got "^string_of_intcletset_markertypemt=mt|>int_of_markertype|>Lowlevel.setmarkertypeletset_markersize=Lowlevel.setmarkersizeletset_markercolorindex=function|cwhenc>=0&&c<1256->Lowlevel.setmarkercolorindc|c->failwith@@"Color index must be in the range [0, 1256]. Got "^string_of_intcletset_arrowstyles=ifs<0||s>18thenfailwith@@Printf.sprintf"Only styles 1..18 are supported. Got %d"s;Lowlevel.setarrowstylesletset_arrowsize=Lowlevel.setarrowsizeletset_text_font_prec?(precision=STRING)font=Lowlevel.settextfontprec(int_of_fontfont)(int_of_text_precisionprecision)letset_char_expand_factor=Lowlevel.setcharexpanletset_text_colorindex=function|cwhenc>=0&&c<1256->Lowlevel.settextcolorindc|c->failwith@@"Color index must be in the range [0, 1256]. Got "^string_of_intcletset_char_height=Lowlevel.setcharheightletset_char_up(x,y)=Lowlevel.setcharupxyletset_char_space=Lowlevel.setcharspaceletset_text_pathdirection=Lowlevel.settextpath(int_of_text_path_directiondirection)letset_text_align:text_halignoption->text_valignoption->unit=funhorizontalvertical->lethorizontal=Option.value~default:NORMALhorizontalinletvertical=Option.value~default:NORMALverticalinLowlevel.settextalign(int_of_text_halignhorizontal)(int_of_text_valignvertical)letset_fill_interior_stylestyle=Lowlevel.setfillintstyle(int_of_fill_stylestyle);matchstylewith|PATTERNpat->Lowlevel.setfillstylepat|HATCHhat->Lowlevel.setfillstylehat|_->()letset_fill_colorindex=function|cwhenc>=0&&c<1256->Lowlevel.setfillcolorindc|c->failwith@@"Color index must be in the range [0, 1256]. Got "^string_of_intcletset_color_representationindex(red,green,blue)=ifindex<0||index>=1256thenfailwith@@"Color index must be in the range [0, 1256]. Got "^string_of_intindex;if(red<0.0||red>1.0)||(green<0.0||green>1.0)||blue<0.0||blue>1.0thenfailwith@@Printf.sprintf"Color values must be in the range [0.0, 1.0]. Got: (%f, %f, %f)"redgreenblue;Lowlevel.setcolorrepindexredgreenblueletset_colormapcmap=Lowlevel.setcolormap(int_of_color_mapcmap)letset_scalescale=Lowlevel.setscale(int_of_scale_optionsscale)letset_shadow(offsetx,offsety)blur=Lowlevel.setshadowoffsetxoffsetyblurletset_transparencyalpha=ifalpha<0.0&&alpha>1.0thenfailwith@@"Alpha index must be between 0.0 and 1.0";Lowlevel.settransparencyalphaletset_coord_transformtransform=lettransform=matchBigarray.Genarray.dimstransformwith|[|3;2|]->transform|[|2;3|]->failwith"Need a 3x2 array, got a 2x3 array"|_->failwith"Need a 3x2 array but got something different"inLowlevel.setcoordxformCtypes.(bigarray_startgenarraytransform)moduleGraphics=structtypet=stringletbeging=Lowlevel.begingraphicsletendg=Lowlevel.endgraphicsletget:unit->t=Lowlevel.getgraphicsletdraw=Lowlevel.drawgraphicsletimport=Lowlevel.importgraphicsendletpolyline?linetype?linewidth?coloridxxy=State.with_sandbox(fun()->Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;letn,x,y=Lowlevel.get_size_and_pointersxyinLowlevel.polylinenxy)letpolyline3d?linetype?linewidth?coloridxxyz=State.with_sandbox(fun()->Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;letn,x,y=Lowlevel.get_size_and_pointersxyinlet_nz,z=Lowlevel.get_size_and_pointerzin(* TODO: Check z dimension *)Lowlevel.polyline3dnxyz)letpolymarker?markertype?markersize?coloridxxy=State.with_sandbox(fun()->Option.iterset_markertypemarkertype;Option.iterset_markersizemarkersize;Option.iterset_markercolorindexcoloridx;letn,x,y=Lowlevel.get_size_and_pointersxyinLowlevel.polymarkernxy)letpolymarker3d?markertype?markersize?coloridxxyz=State.with_sandbox(fun()->Option.iterset_markertypemarkertype;Option.iterset_markersizemarkersize;Option.iterset_markercolorindexcoloridx;letn,x,y=Lowlevel.get_size_and_pointersxyinlet_nz,z=Lowlevel.get_size_and_pointerzin(* TODO: Check z dimension *)Lowlevel.polymarker3dnxyz)lettext=Lowlevel.textletfillareaxy=letn,x',y'=Lowlevel.get_size_and_pointersxyinLowlevel.fillareanx'y'letcellarray(xmin,xmax)(ymin,ymax)(dimx,dimy)(scol,srow)(ncol,nrow)colors=letcolor'=Ctypes.(bigarray_startgenarraycolors)inLowlevel.cellarrayxminxmaxyminymaxdimxdimyscolsrowncolnrowcolor'(* let gdp = ... (* No idea what this does... *) *)letspline?linetype?linewidth?coloridxxymalgo=State.with_sandbox(fun()->Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;letn,x',y'=Lowlevel.get_size_and_pointersxyinLowlevel.splinenx'y'm(int_of_spline_algoalgo))letgriditxyz(nx,ny)=letx'=Bigarray.(Genarray.createfloat64c_layout[|nx|])inlety'=Bigarray.(Genarray.createfloat64c_layout[|ny|])inletz'=Bigarray.(Genarray.createfloat64c_layout[|nx*ny|])inletn,x,y=Lowlevel.get_size_and_pointersxyinletnz,z=Lowlevel.get_size_and_pointerzinifnz<>nthenfailwith@@Printf.sprintf"Expected arrays with dimensions n, n, n. Got %d, %d, %d"nnnz;Lowlevel.griditnxyznxnyCtypes.(bigarray_startgenarrayx')Ctypes.(bigarray_startgenarrayy')Ctypes.(bigarray_startgenarrayz');x',y',z'lettex_text(x,y)text=Lowlevel.textextxytextletmath_tex(x,y)tex=Lowlevel.mathtexxytexletaxes?(scale=[])?linetype?linewidth?coloridx?(origin=0.0,0.0)?(major=0,0)?(tick_size=-0.01)x_ticky_tick=State.with_sandbox(fun()->ifscale<>[]thenset_scalescale|>ignore;Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;letx_org,y_org=origininletmajor_x,major_y=majorinLowlevel.axesx_ticky_tickx_orgy_orgmajor_xmajor_ytick_size)letaxes_labels?(scale=[])?linetype?linewidth?coloridx?(origin=0.0,0.0)?(major=0,0)?(tick_size=-0.01)(fpx:float->float->string->float->unit)(fpy:float->float->string->float->unit)x_ticky_tick=State.with_sandbox(fun()->ifscale<>[]thenLowlevel.setscale(int_of_scale_optionsscale)|>ignore;Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;letx_org,y_org=origininletmajor_x,major_y=majorinLowlevel.axeslblx_ticky_tickx_orgy_orgmajor_xmajor_ytick_sizefpxfpy)letaxes3d?(scale=[])?linetype?linewidth?coloridx?(origin=0.0,0.0,0.0)?(major=0,0,0)?(tick_size=-0.01)x_ticky_tickz_tick=State.with_sandbox(fun()->ifscale<>[]thenset_scalescale|>ignore;Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;letx_org,y_org,z_org=origininletmajor_x,major_y,major_z=majorinLowlevel.axes3dx_ticky_tickz_tickx_orgy_orgz_orgmajor_xmajor_ymajor_ztick_size)letsurface?(options=LINES)xyz=letnx,x=Lowlevel.get_size_and_pointerxinletny,y=Lowlevel.get_size_and_pointeryinletnz,z=Lowlevel.get_size_and_pointerzinifnz<>nx*nythenfailwith@@Printf.sprintf"Expected arrays with dimensions n, n', n*n'. Got %d, %d, %d"nxnynz;Lowlevel.surfacenxnyxyz(int_of_surface_optionsoptions)letcontour?(major_h=0)xyhz=(* TODO: validate z *)letnx,x=Lowlevel.get_size_and_pointerxinletny,y=Lowlevel.get_size_and_pointeryinletnh,h=Lowlevel.get_size_and_pointerhinlet_nz,z=Lowlevel.get_size_and_pointerzinLowlevel.contournxnynhxyhzmajor_hletcontourf?(major_h=0)xyhz=(* TODO: validate z *)letnx,x=Lowlevel.get_size_and_pointerxinletny,y=Lowlevel.get_size_and_pointeryinletnh,h=Lowlevel.get_size_and_pointerhinlet_nz,z=Lowlevel.get_size_and_pointerzinLowlevel.contourfnxnynhxyhzmajor_hletgrid?(scale=[])?linetype?linewidth?coloridx?(origin=0.0,0.0)?(major=0,0)x_ticky_tick=State.with_sandbox(fun()->ifscale<>[]thenset_scalescale|>ignore;Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;letx_org,y_org=origininletmajor_x,major_y=majorinLowlevel.gridx_ticky_tickx_orgy_orgmajor_xmajor_y)letgrid3d?(scale=[])?linetype?linewidth?coloridx?(origin=0.0,0.0,0.0)?(major=0,0,0)x_ticky_tickz_tick=State.with_sandbox(fun()->ifscale<>[]thenset_scalescale|>ignore;Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;letx_org,y_org,z_org=origininletmajor_x,major_y,major_z=majorinLowlevel.grid3dx_ticky_tickz_tickx_orgy_orgz_orgmajor_xmajor_ymajor_z)letvertical_errorbarsxyeleu=letn,x,y=Lowlevel.get_size_and_pointersxyinletne,el,eu=Lowlevel.get_size_and_pointerseleuinifn<>nethenfailwith@@Printf.sprintf"Expected arrays of the same dimensions. Got: %d, %d"nne;Lowlevel.verrorbarsnxyeleulethorizontal_errorbarsxyeleu=letn,x,y=Lowlevel.get_size_and_pointersxyinletne,el,eu=Lowlevel.get_size_and_pointerseleuinifn<>nethenfailwith@@Printf.sprintf"Expected arrays of the same dimensions. Got: %d, %d"nne;Lowlevel.herrorbarsnxyeleulettitles3d=Lowlevel.titles3dlettricontourxyzlevels=letnx,x=Lowlevel.get_size_and_pointerxinlet_ny,y=Lowlevel.get_size_and_pointeryinlet_nz,z=Lowlevel.get_size_and_pointerzinletnlevels,levels=Lowlevel.get_size_and_pointerlevelsinLowlevel.tricontournxxyznlevelslevels(* (* TODO: I don't know what this function does... *)
let hexbin = foreign "gr_hexbin" (int @-> ptr double @-> ptr double @-> int @-> returning int)
*)letcolorbar()=Lowlevel.colorbar()(*
(* TODO: postponed *)
let hsvtorgb = foreign "gr_hsvtorgb" (double @-> double @-> double @-> ptr double@-> ptr double @-> ptr double @-> returning void)
*)lettick=Lowlevel.tickmodulePrint=structletvalidatepath=ifnot@@List.fold_left(funaccsuffix->acc||Filename.check_suffixpathsuffix)false[".ps";".eps";".pdf";".bmp";".jpeg";".jpg";".png";".tiff";".tif";".svg";".wmf";".mp4";".webm";".ogg"]thenfailwith@@Printf.sprintf"Unsupported file type: %s"pathletbeginppath=validatepath;Lowlevel.beginprintpathletendp=Lowlevel.endprintletbeginp_extendedpathmodeformatorientation=validatepath;letmode=matchmodewith|`Color->"Color"|`GreyScale->"GreyScale"inletorientation=matchorientationwith|`Landscape->"Landscape"|`Portrait->"Portrait"inletformat=matchformatwith|`A4->"A4"|`B5->"B5"|`Letter->"Letter"|`Legal->"Legal"|`Executive->"Executive"|`A0->"A0"|`A1->"A1"|`A2->"A2"|`A3->"A3"|`A5->"A5"|`A6->"A6"|`A7->"A7"|`A8->"A8"|`A9->"A9"|`B0->"B0"|`B1->"B1"|`B10->"B10"|`B2->"B2"|`B3->"B3"|`B4->"B4"|`B6->"B6"|`B7->"B7"|`B8->"B8"|`B9->"B9"|`C5E->"C5E"|`Comm10E->"Comm10E"|`DLE->"DLE"|`Folio->"Folio"|`Ledger->"Ledger"|`Tabloid->"Tabloid"inLowlevel.beginprintextpathmodeformatorientationend(*
(* TODO: operates on double pointers - postponed *)
let ndctowc = foreign "gr_ndctowc" (ptr double @-> ptr double @-> returning void)
let wctondc = foreign "gr_wctondc" (ptr double @-> ptr double @-> returning void)
let wc3towc = foreign "gr_wc3towc" (ptr double @-> ptr double @-> ptr double @-> returning void)
*)letdrawrect?linetype?linewidth?coloridxleftrightbottomup=State.with_sandbox(fun()->Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;Lowlevel.drawrectleftrightbottomup)letfillrect?fillstyle?fillcoloridx?linetype?linewidth?coloridxleftrightbottomup=State.with_sandbox(fun()->Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;Option.iterset_fill_interior_stylefillstyle;Option.iterset_fill_colorindexfillcoloridx;Lowlevel.fillrectleftrightbottomup)letdrawarc?linetype?linewidth?coloridxleftrightbottomupa1a2=State.with_sandbox(fun()->Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;Lowlevel.drawarcleftrightbottomupa1a2)letfillarc?fillstyle?fillcoloridx?linetype?linewidth?coloridxleftrightbottomupa1a2=State.with_sandbox(fun()->Option.iterset_linetypelinetype;Option.iterset_linewidthlinewidth;Option.iterset_linecolorindexcoloridx;Option.iterset_fill_interior_stylefillstyle;Option.iterset_fill_colorindexfillcoloridx;Lowlevel.fillarcleftrightbottomupa1a2)letdrawpathverticescodesfill=letcode_to_uchar=function|`STOP->Unsigned.UChar.of_int0|`MOVETO->Unsigned.UChar.of_int1|`LINETO->Unsigned.UChar.of_int2|`CURVE3->Unsigned.UChar.of_int3|`CURVE4->Unsigned.UChar.of_int4|`CLOSEPOLY->Unsigned.UChar.of_int0x4finletfill=iffillthen1else0inletn=Array.lengthverticesinletopenCtypesinletcvertices=CArray.makeLowlevel.vertexninletccodes=CArray.makeucharninfori=0ton-1doletx,y=vertices.(i)inletv=makeLowlevel.vertexinsetfvLowlevel.vertex_xx;setfvLowlevel.vertex_yy;CArray.setcverticesiv;CArray.setccodesi(code_to_ucharcodes.(i))done;Lowlevel.drawpathnCArray.(startcvertices)CArray.(startccodes)fillletdrawarrow?arrowsize?arrowstyle(x1,y1)(x2,y2)=State.with_sandbox(fun()->Option.iterset_arrowsizearrowsize;Option.iterset_arrowstylearrowstyle;Lowlevel.drawarrowx1y1x2y2)(* TODO:
let readimage = foreign "gr_readimage" (string @-> ptr int @-> ptr int @-> ptr (ptr int) @-> returning int)
*)letdrawimage(xmin,ymin)(xmax,ymax)image_datamodel=letmodel=matchmodelwith|`RGB->0|`HSV->1inletwidth,height,image_data=matchBigarray.Genarray.dimsimage_datawith|[|width;height|]->width,height,Ctypes.(bigarray_startgenarrayimage_data)|_->failwith"Expecting a 2D array, but got something else!"inLowlevel.drawimagexminyminxmaxymaxwidthheightimage_datamodelmoduleSelection=structletbegins=Lowlevel.beginselectionletends=Lowlevel.endselectionletmovexy=Lowlevel.moveselectionxyletresizekindxy=Lowlevel.resizeselectionkindxyend(*
TODO:
inqbbox &xmin &xmax &ymin &ymax
uselinespec linespec
*)(* let with_ws ?(typ = PNG) plot =
let id = Random.int 1024 in
try
Lowlevel.openws id ("plot" ^ string_of_int id) (int_of_workstation_type typ);
plot id;
Lowlevel.closews id
with
| exn ->
(try Lowlevel.closews id with
| _ -> ());
raise exn
*)