Using Morpho for the very first time
Morpho is a command line program. To launch it, open a Terminal window and type,
[code lang=”js” gutter=”false”]morpho[/code]
pressing return or enter afterwards to tell the computer to execute your command. Optionally you can also type something like
[code lang=”js” gutter=”false”]morpho input.morpho[/code]
which would ask Morpho to execute the contents of the file input.morpho. While we’ll use Morpho in interactive mode here, it’s very common to write Morpho programs in a separate text editor and run them in this fashion.
Once Morpho has started, it awaits commands with a prompt
>
which changes to
?
if Morpho detects that you’ve typed an incomplete statement. If commands are being loaded from an input file, it will display them prefaced with
~
Inside Morpho, simply type commands and Morpho’s own command line interface will execute them, displaying the results. A few commands are available that are not considered part of the Morpho language:—
• quit
Exits Morpho.
• save [filename]
Saves the sequence of commands entered since the start of Morpho or the last restart to a file [filename].
As is typical when encountering an unfamiliar programming language, we’ll begin by writing a very simple “Hello World!” program. Type
[code lang=”js” gutter=”false”]print("Hello World!")[/code]
and you’ll see
Hello World!
What this program does is call a built in function, print
, with a single parameter, a string "Hello World!"
. The purpose of print
is to print any parameters it is called with to the current output, which since we’re using interactive mode is just the terminal window.
Those familiar with other programming languages will recognize that Morpho is quite similar in syntax to the C family of languages, which includes C++, Java and many other languages in common use. Unlike many of these languages, it is a Dynamic programming language and places relatively little emphasis on types. It is more akin to languages such as SmallTalk, Self and Objective C.
Morpho aims to be:
• simple, easy to use and human readable.
• oriented towards those who have limited experience with programming.
• familiar to those who have used languages common in scientific programming, i.e. C, C++, Fortran, etc.
• supported by a rich variety of intrinsic functions and classes specific to the intended applications, i.e. shape optimization and computational differential geometry.
In the next tutorial in this sequence, we’ll introduce many of Morpho’s language features. Those wanting to jump right in to shape minimization may want to go straight to the Loop minimization sequence of tutorials, which explains how to set up such problems in Morpho.