Message Boards Message Boards

What are rules for making templates for user-defined functions in packages?

Posted 10 years ago

In Mathematica 10.0 user help ref/menuitem/MakeTemplate, it shows the following simple instructions for creating an input template for my user-defined functions:

To define a function template for a user-defined function, make the template the first statement in the usage message for the function. For example, to define the template f[a,b] for the function f, you could use the following command: f::usage="f[a,b] is an example of a function".

That seems to work if the usage string is very short and simple, like this example from one of my functions:

OrificeDP::usage = "OrificeDP[Q, DesignQ, DesignDP] Returns the differential pressure across an orifice at a flow rate, given a design differential pressure at a design flow rate.";

However, I generally like to provide a lot more info in the usage statements, so that if I type ?OrificeDP, I actually get helpful info. Here's an example of that type of statement. When I try to use Make Template in a notebook with this one, it doesn't work.

OrificeFlow::usage = "OrificeFlow[OrificeBore, PipeID, P1, P2, Density, Viscosity, OrificeDischargeCoefficient_:0.62] calculates the flow rate of an 
incompressible fluid through an orifice installed in a pipeline.  Uses Eq.6-111 from Perry's Chemical 
Engineer's Handbook, 7th ed. The orifice coefficient is entered as an optional argument with a default value of 0.62, 
which is normally valid if the Reynolds number is > 20,000.  The Reynolds number is calculated in the module and an
error message is displayed if it is < 20000. P2 is the recovered downstream pressure, which is 
converted in the module to the vena contracta pressure for use in Eq.6-111.\n
Default units: Flow -> Gallons/Minutes, OrificeBore, PipeID -> Inches; P1, P2 -> PoundsForce/Inches^2; Density -> Pounds/Feet^3, 
Viscosity -> Centipoise
Input: Numeric value in default units or Quantity in any consistent units.
Output: Quantity";

Is anyone able to provide help on how to write the usage statements so that they work with Make Template and also provide the detailed information I need when I type ?OrificeFlow?

Thanks

POSTED BY: Andrew Makowski
2 Replies
Posted 10 years ago

Thanks very much - that did it.

POSTED BY: Andrew Makowski

If you remove your hard carriage returns from the string then it works.

OrificeFlow::usage = 
  "OrificeFlow[OrificeBore, PipeID, P1, P2, Density, Viscosity, \
OrificeDischargeCoefficient] calculates the flow rate of an \
incompressible fluid through an orifice installed in a pipeline.  \
Uses Eq.6-111 from Perry's Chemical Engineer's Handbook, 7th ed. The \
orifice coefficient is entered as an optional argument with a default \
value of 0.62, which is normally valid if the Reynolds number is > \
20,000.  The Reynolds number is calculated in the module and an error \
message is displayed if it is < 20000. P2 is the recovered downstream \
pressure, which is converted in the module to the vena contracta \
pressure for use in Eq.6-111.\nDefault units: Flow -> \
Gallons/Minutes, OrificeBore, PipeID -> Inches; P1, P2-> \
PoundsForce/Inches^2; Density -> Pounds/Feet^3, Viscosity -> \
Centipoise Input: Numeric value in default units or Quantity in any \
consistent units. Output: Quantity";
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract