(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 4.0, MathReader 4.0, or any compatible application. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 8937, 313]*) (*NotebookOutlinePosition[ 9611, 337]*) (* CellTagsIndexPosition[ 9567, 333]*) (*WindowFrame->Normal*) Notebook[{ Cell[TextData[{ "An Enhanced FilterOptions Package\n", StyleBox["By Ted Ersek\n ersektr@navair.navy.mil", FontSize->12] }], "Subtitle"], Cell[TextData[{ "The standard package Utilities`FilterOptions` was modified to include a \ new function called CheckOptions. FilterOptions and CheckOptions are closely \ related, so it seemed logical make an addition to the FilterOptions package. \ Before evaluating the examples below you should replace the FilterOptions.m \ file in the ", Cell[BoxData[ \(TraditionalForm\`\(\(\(\\\)\(AddOns\)\)\\StandardPackages\)\\\ Utilities\)]], " folder with the new version of the same file posted on ", StyleBox["MathSource ", FontSlant->"Italic"], "along with this notebook. Once that is done evaluate the next cell." }], "Text"], Cell[BoxData[ \(<< Utilities`FilterOptions`\)], "Input"], Cell["\<\ The only changes in the new version of FilterOptions.m are the addition of a \ CheckOptions function, and a definition for a new message named \ General::opts. The usage message of CheckOptions is shown below.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?CheckOptions\)\)], "Input"], Cell[BoxData[ \("CheckOptions[func,opts] returns True if opts is an empty list or \ includes only options supported by func. If opts includes options not \ supported by func, then an appropriate message is posted and False is \ returned. CheckOptions[func] returns True. The second argument in \ CheckOptions can be a list or a sequence of options."\)], "Print"] }, Open ]], Cell[CellGroupData[{ Cell["Examples", "Section", CellFrame->{{0, 0}, {0, 2}}], Cell["\<\ In the next cell CheckOptions posts a message indicating that MaxBend and \ PlotJoined aren't valid options for Plot3D and returns False.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(CheckOptions[Plot3D, PlotPoints \[Rule] 40, PlotRange \[Rule] {0, 20}, \[IndentingNewLine]MaxBend\ \[Rule] 7, PlotJoined \[Rule] True]\)], "Input"], Cell[BoxData[ \(Plot3D::"opts" \(\(:\)\(\ \)\) "Unknown options \!\({\(\(MaxBend \[Rule] 7\)\), \(\(PlotJoined \[Rule] \ True\)\)}\) in \!\(Plot3D\)"\)], "Message"], Cell[BoxData[ \(False\)], "Output"] }, Open ]], Cell["\<\ In the next cell CheckOptions posts a message indicating that PlotJoined \ isn't a valid options for Plot3D and returns False.\ \>", "Text", CellFrame->{{0, 0}, {0, 0.5}}], Cell[CellGroupData[{ Cell[BoxData[ \(CheckOptions[Plot3D, PlotPoints \[Rule] 40, PlotRange \[Rule] {0, 20}, \[IndentingNewLine]PlotJoined \[Rule] True]\)], "Input"], Cell[BoxData[ \(Plot3D::"optx" \(\(:\)\(\ \)\) "Unknown option \!\(PlotJoined \[Rule] True\) in \!\(Plot3D\)."\)], \ "Message"], Cell[BoxData[ \(False\)], "Output"] }, Open ]], Cell["\<\ The next two example return True, and post no messages because the options \ provided are valid options for Plot3D.\ \>", "Text", CellFrame->{{0, 0}, {0, 0.5}}], Cell[CellGroupData[{ Cell[BoxData[ \(CheckOptions[ Plot3D, {PlotPoints \[Rule] 40, PlotRange \[Rule] {0, 20}}]\)], "Input"], Cell[BoxData[ \(True\)], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(CheckOptions[Plot3D]\)], "Input"], Cell[BoxData[ \(True\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell["Applications", "Section", CellFrame->{{0, 0}, {0, 2}}], Cell["\<\ A simple function that uses CheckOptions is defined in the next cell.\ \>", "Text"], Cell[BoxData[{ \(\(ClearAll[MyFunction];\)\), "\[IndentingNewLine]", \(\(Options[MyFunction] = {opt1 \[Rule] val1, \ opt2 \[Rule] val2, \ opt3 \[Rule] val3};\)\[IndentingNewLine]\), "\[IndentingNewLine]", \(MyFunction[x_, opts___?OptionQ] := \((\[IndentingNewLine]CheckOptions[MyFunction, opts]; \[IndentingNewLine]x\ Exp[x])\)\)}], "Input"], Cell["\<\ When the next two cells are evaluated no messages are posted. In the first \ example no options are used. In the second example the option used is \ recognized by MyFunction.\ \>", "Text", CellFrame->{{0, 0}, {0, 0.5}}], Cell[CellGroupData[{ Cell[BoxData[ \(MyFunction[3]\)], "Input"], Cell[BoxData[ \(3\ \[ExponentialE]\^3\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(MyFunction[t, \ opt1 \[Rule] 20]\)], "Input"], Cell[BoxData[ \(\[ExponentialE]\^t\ t\)], "Output"] }, Open ]], Cell["\<\ In the next two cells MyFunction is given one or more option that doesn't \ belong to MyFunction. When these cells are evaluated a message is posted \ indicating that MyFunction doesn't know what to do with one or more of the \ options.\ \>", "Text", CellFrame->{{0, 0}, {0, 0.5}}], Cell[CellGroupData[{ Cell[BoxData[ \(MyFunction[t, Trig \[Rule] True, opt1 \[Rule] 20]\)], "Input"], Cell[BoxData[ \(MyFunction::"optx" \(\(:\)\(\ \)\) "Unknown option \!\(Trig \[Rule] True\) in \!\(MyFunction\)."\)], \ "Message"], Cell[BoxData[ \(\[ExponentialE]\^t\ t\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(MyFunction[t, Trig \[Rule] True, Modulus \[Rule] 23, opt1 \[Rule] 20]\)], "Input"], Cell[BoxData[ \(MyFunction::"opts" \(\(:\)\(\ \)\) "Unknown options \!\({\(\(Modulus \[Rule] 23\)\), \(\(Trig \[Rule] True\ \)\)}\) in \!\(MyFunction\)"\)], "Message"], Cell[BoxData[ \(\[ExponentialE]\^t\ t\)], "Output"] }, Open ]], Cell["\<\ One can also use CheckOptions to ensure a function is undefined when given \ options it doesn't recognize. In the next cell MyFunction is defined using \ this approach.\ \>", "Text", CellFrame->{{0, 0}, {0, 0.5}}], Cell[BoxData[{ \(\(ClearAll[MyFunction];\)\), "\[IndentingNewLine]", \(\(Options[MyFunction] = {opt1 \[Rule] val1, \ opt2 \[Rule] val2, \ opt3 \[Rule] val3};\)\[IndentingNewLine]\), "\[IndentingNewLine]", \(MyFunction[x_, opts___?OptionQ] /; CheckOptions[MyFunction, opts] := \[IndentingNewLine]x\ Exp[ x]\)}], "Input"], Cell["\<\ This new definition of MyFunction is used in the cells below.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(MyFunction[3]\)], "Input"], Cell[BoxData[ \(3\ \[ExponentialE]\^3\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(MyFunction[t, \ opt1 \[Rule] 20]\)], "Input"], Cell[BoxData[ \(\[ExponentialE]\^t\ t\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(MyFunction[t, Trig \[Rule] True, opt1 \[Rule] 20]\)], "Input"], Cell[BoxData[ \(MyFunction::"optx" \(\(:\)\(\ \)\) "Unknown option \!\(Trig \[Rule] True\) in \!\(MyFunction\)."\)], \ "Message"], Cell[BoxData[ \(MyFunction[t, Trig \[Rule] True, opt1 \[Rule] 20]\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(MyFunction[t, Trig \[Rule] True, Modulus \[Rule] 23, opt1 \[Rule] 20]\)], "Input"], Cell[BoxData[ \(MyFunction::"opts" \(\(:\)\(\ \)\) "Unknown options \!\({\(\(Modulus \[Rule] 23\)\), \(\(Trig \[Rule] True\ \)\)}\) in \!\(MyFunction\)"\)], "Message"], Cell[BoxData[ \(MyFunction[t, Trig \[Rule] True, Modulus \[Rule] 23, opt1 \[Rule] 20]\)], "Output"] }, Open ]] }, Open ]] }, FrontEndVersion->"4.0 for Microsoft Windows", ScreenRectangle->{{0, 800}, {0, 527}}, CellGrouping->Manual, WindowSize->{729, 369}, WindowMargins->{{0, Automatic}, {Automatic, 0}} ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[1717, 49, 148, 4, 98, "Subtitle"], Cell[1868, 55, 649, 13, 90, "Text"], Cell[2520, 70, 60, 1, 30, "Input"], Cell[2583, 73, 236, 4, 52, "Text"], Cell[CellGroupData[{ Cell[2844, 81, 50, 1, 30, "Input"], Cell[2897, 84, 366, 5, 82, "Print"] }, Open ]], Cell[CellGroupData[{ Cell[3300, 94, 58, 1, 63, "Section"], Cell[3361, 97, 161, 3, 33, "Text"], Cell[CellGroupData[{ Cell[3547, 104, 182, 3, 50, "Input"], Cell[3732, 109, 175, 3, 24, "Message"], Cell[3910, 114, 39, 1, 29, "Output"] }, Open ]], Cell[3964, 118, 183, 4, 41, "Text"], Cell[CellGroupData[{ Cell[4172, 126, 163, 3, 50, "Input"], Cell[4338, 131, 138, 3, 24, "Message"], Cell[4479, 136, 39, 1, 29, "Output"] }, Open ]], Cell[4533, 140, 172, 4, 41, "Text"], Cell[CellGroupData[{ Cell[4730, 148, 112, 2, 30, "Input"], Cell[4845, 152, 38, 1, 29, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[4932, 159, 53, 1, 30, "Input"], Cell[4988, 162, 38, 1, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[5063, 168, 62, 1, 63, "Section"], Cell[5128, 171, 93, 2, 33, "Text"], Cell[5224, 175, 386, 6, 130, "Input"], Cell[5613, 183, 233, 5, 60, "Text"], Cell[CellGroupData[{ Cell[5871, 192, 46, 1, 30, "Input"], Cell[5920, 195, 55, 1, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6012, 201, 65, 1, 30, "Input"], Cell[6080, 204, 55, 1, 29, "Output"] }, Open ]], Cell[6150, 208, 294, 6, 60, "Text"], Cell[CellGroupData[{ Cell[6469, 218, 82, 1, 30, "Input"], Cell[6554, 221, 140, 3, 24, "Message"], Cell[6697, 226, 55, 1, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6789, 232, 109, 2, 30, "Input"], Cell[6901, 236, 178, 3, 24, "Message"], Cell[7082, 241, 55, 1, 29, "Output"] }, Open ]], Cell[7152, 245, 226, 5, 60, "Text"], Cell[7381, 252, 363, 6, 110, "Input"], Cell[7747, 260, 85, 2, 33, "Text"], Cell[CellGroupData[{ Cell[7857, 266, 46, 1, 30, "Input"], Cell[7906, 269, 55, 1, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[7998, 275, 65, 1, 30, "Input"], Cell[8066, 278, 55, 1, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[8158, 284, 82, 1, 30, "Input"], Cell[8243, 287, 140, 3, 24, "Message"], Cell[8386, 292, 83, 1, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[8506, 298, 109, 2, 30, "Input"], Cell[8618, 302, 178, 3, 24, "Message"], Cell[8799, 307, 110, 2, 29, "Output"] }, Open ]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)