file: mlabfiles.txt date: June 13, 2012 This is information for running MLAB under an MSWindows operating system. You may want to print this text and keep it for reference. Some details differ for Mac OSX and for Linux, but this information is still valuable for those systems. A Quick Example of using MLAB: ------------------------------ When you run MLAB, a "console" window is put on the screen, and a smaller "start-up menu" window is displayed in which you must make a selection. Actually, the very first time you run MLAB, the MLAB console window will be displayed and you will be asked for a "user-name". This user-name is kept just for display purposes; it will subsequently be typed-out in the MLAB console window before the start-up menu is presented. And later on, starting on the second day after installation, until you "register" MLAB, when you run MLAB you will be asked for an "authorization key-value" that you obtain from Civilized Software. When you obtain the authorization key-value and enter it, you will never be asked for it again. Until you obtain your authorization key-value, you should enter "0". After responding, the MLAB start-up menu window will be displayed. (You get the authorization key-value from Civilized Software by sending-in the "MLAB identifier value" which is typed-out in the MLAB console window when MLAB starts, and requesting that the authorization key-value be sent back. You may send email to csi@civilized.com.) One choice in the MLAB start-up menu window is to run various examples. Another choice is to go to "top-level", which means that the startup menu window is removed from the screen, and a "*" prompt symbol is displayed in the MLAB console window; this prompt means that MLAB is 'waiting' for you to enter an MLAB command. [The first time or two you run MLAB, you should not go directly to "top-level", but first look at the examples, and run some of them!] There are dozens of MLAB commands and hundreds of MLAB functions waiting to be used. In essence, MLAB is an interpreter for a high-level mathematical language and you use MLAB by specifying purposeful sequences of MLAB commands to accomplish your end. (As a practical matter, you will probably often enter these commands in a text-file to construct a re-runnable 'script' called a do-file.) You can define a function and graph it as follows. function f(x) = a*cos(b*x)*exp(-k*x) a = 1; b=4; k =.5 v=1:10!100 m= points(f,v) draw m view Note 1:10!100 = 1:10:.0909090909, and 1:10:.0909090909 means the column vector of values from 1 to 10 in steps of size .0909090909 (So can you guess what 1:10!100 means in 'plain English'?) Also note points(f,v) = v&'(f on v), and v$'(f on v) means the column-wise concatenation of the matrix v with the same-sized column vector consisting of the values of f computed on the values in v. (What do you think the operator & does as opposed to &' ? What do you think v$'7 is?) You can read-in 110 data values from a file into a 2-column matrix as follows. The result is a 55 row by 2 column matrix. d = read("filename",55,2) Taking the rows of the matrix d as (x,y) data-points - with error in the y-values - where these data points are "modeled" by the function f, defined above, you can estimate the unknown parameters a,b,k as follows. fit(a,b,k), f to d You can use estimated weights for the various data points in d based on a moving-variance estimation function ewt as follows. fit(a,b,k). f to d with wt ewt(d) You can graph the data and the "fit" as follows. delete w /* to discard any previous picture */ draw d linetype none, pointtype circle draw points(f,d col 1) color green view You can look at the symbolic derivative of f and graph it as follows. type f'x draw points(f'x, d col 1) color red view Note MLAB can use symbolic-derivatives when derivative values are needed during curve-fitting, or solving ODEs. You can fit (or just solve) differential-equation-defined models in MLAB, so that chemical kinetics and physiological and compartmental models, etc. can be handled. [Look at the MLAB examples that are available when you run MLAB.] Try this: a=3.14159e200 b= -(10e201) type a, b, a*b, a^2, b^2 Now try that with any other computational program you have access to. (This behavior is often useful in curve-fitting. Can you see why?) Note, you can probably see that you need to have the MLAB manuals available because there is so much in MLAB that you will miss otherwise. You can find a link within the web-site www.civilized.com that offers the option to download the MLAB manuals in PDF format. [There is a somewhat helpful command "help" that you can use to access some reference material for MLAB on-line, but looking at the .pdf Reference Manual is better, and looking at examples in the MLAB Applications Manual is sometimes even better.] The directions for installing MLAB on your PC are given at the end of this document. --------------------------------------------------------------- The MLAB Executable Directory and the MLAB Working Directory: There are two important directories (or "folders") that you must(!) be aware of when running MLAB. The first is the "MLAB executable directory", and the second is your "current working directory". The "MLAB executable directory" is that directory where the MLAB executable program file (and other MLAB system files) are stored. This directory is established by the MLAB setup program which is run when MLAB is installed. Generally, this directory is C:\MLAB\ unless you specify some other directory to the setup program. In any event, you MUST know the full path and the name of this directory. You should write it on a piece of paper and tape it to your computer. (but in case you don't, MLAB prints-out this full directory name when it is run.) Your "current working directory" is that directory where you want to get your "input" and write your log-file and other output, at least for "today". When you run MLAB and ask it to execute a do-file (an MLAB script,) or read a data-file, then, unless you specify a specific path as part of the file-name (or set the FILEDIR variable,) the current working directory will be the place that MLAB looks for such files. Thus the directory where you keep do-files and data-files for some project is the directory that you want to make your current working directory when you want to deal with that project. There is a third important directory called your "home directory". For XP, this is C:\Documents and Settings\[username]\, for Win7, this is C:\Users\[username]. Your home directory is where you should keep all your personal files and subdirectories that you create for various purposes such as an MLAB "project". There is also a bunch of directories that Windows puts in your home directory. Most of these are useless and annoying and can be deleted, but your personal Desktop subdirectory is vitally important. --------------- How to Run MLAB In a Unix/Linux system, MLAB is run by starting a "terminal-emulator" program (like xterm) and then 'cd'-ing to the directory that you want to be your working directory, and then running MLAB by typing "MLAB" at the 'command-line'. ('cd' stands for 'change directory'.) You can run MLAB the same way in a Windows system (almost). You start a so-called DOS window (also called a "command-prompt" window in XP and later,) and set the 'volume' (e.g. C:) and 'cd' to your desired working directory, and then run MLAB by typing "MLAB" as the next command. In this case, the working directory is established as you want it, i.e., as the directory you have 'cd'-ed to. Note, however, unlike in Unix, in Windows MLAB puts its own "console" window on the screen wherein all MLAB commands are entered and printed, and where text-output occurs. Thus the DOS window is only used to get MLAB started with the desired current working directory. Also, note that to run MLAB from the "command-line" in either Unix or Windows, you must(!) have the MLAB executable directory in your PATH environment variable, or else you must specify the fully-qualified executable-file name in order to run MLAB (e.g. C:\MLAB\MLAB). Without any 'cd' command, when you run MLAB from within a DOS-window, your current working directory will start-out being the directory specifed as the "start-in" directory associated with the 'command-prompt' icon. By default, in XP, this "start-in" directory is C:\windows\system32\. (In Win7, the "start-in" directory is your home directory which is C:\Users\[username]\.) (It is thus generally a bad idea to run MLAB in a DOS window without explicitly cd-ing to where you want to be.) [You will probably need to establish a "desktop shortcut icon" for the cmd.exe program generally found in C:\windows\system32\ for both XP and Win7 in order to conveniently run the 'command-prompt' program; if you don't do this, you will have to use the 'start-menu' to find and execute the cmd.exe 'command prompt' program. How to do this will be described below.] There are two other ways to run MLAB in Windows. One way is to run the MS file-finder program (by clicking start -> find, or start -> search) and "navigate" by clicking to the MLAB executable directory, and then double-click on the MLAB executable file, mlab.exe, to run it. In this case, your initial working directory will be the same as the MLAB executable directory, and you will need to use the FILEDIR control string in MLAB to "override" this. The final way to run MLAB is to double-click on an MLAB "shortcut" icon on the "desktop". (Such an icon will be created when the MLAB setup program is run at the time MLAB is installed - and you can create a shortcut icon yourself at at any time as described below.) When you run MLAB in this manner, your initial working directory will be whatever is set as the "start-in" directory associated with the 'icon' (Clicking on the icon actually causes Windows to refer to a collection of files in a directory called the "program group" directory that tell it the full-name of the associated executable file, and various other properties, including the "start-in" directory.) Generally the "start-in" directory associated with the MLAB shortcut icon is the MLAB executable directory, but you can change this by right-clicking on the MLAB shortcut icon, then click on 'properties', and then, if necessary, click on the "shortcut" tab in the window that pops up. Then you can change the "start-in" text-field to whatever you want it to be. Thus, before you run MLAB, you could do this to set the "start-in" directory, And you might re-do this whenever your desired working directory is different from whatever is set. In fact, you can set this text-field to %HOMEDRIVE%%HOMEPATH% to always do an initial implicit 'cd' to your home directory (use this exact text - it specifies that the 'environment variables' HOMEDRIVE and HOMEPATH be used.) This is what we do to aid us in running MLAB. However, another simple way to run MLAB with easy control of your working directory is the first way: run the cmd.exe 'command-prompt' program by double-clicking on a 'command-prompt' icon you have created, 'cd' to the desired directory where you want your data files and log files to be for your current purposes, (generally this directory should be either your home directory \Users\[username] or a subdirectory of your home directory.) Then you type 'MLAB' (or \MLAB\MLAB if you do not have your search-path set) to run MLAB. [Creating a subdirectory for data and log-files for an MLAB "project": Type the command 'mkdir subdirname' in your 'command-prompt' window, after 'cd'-ing to the directory (such as \Users\[username]) where you want the subdiretory to be. "mkdir" stands for "make directory".] [Adding C:/MLAB to your search-path: {This is awkward to do due to design deficiencies!) You can add the text "C:\MLAB" to your search-path as follows. Double click on your "Computer" or "My Computer" system management program either in the start menu, or a desktop icon (we have created such an icon for convenience.) Then select "system properties", and then "advanced" (it is hard to see - look at all of the window.) Then "enviroment" (which is also hard to see.) Then scroll down to the "path" environment string and select it and click on 'edit'. In the window for editing, click in the string value of 'path', right-arrow to its end and insert the text: ";C:\MLAB" (without the quotes, of course.) click on "Okay" or the equivalent, window by window all the way out.] [Creating a Desktop icon for running MLAB: A shortcut is a "LNK" (link) file "pointing to" an executable file. To have a visible icon associated, the .lnk file must be stored in a "desktop" directory where the Windows program manager can "see" it and display an icon corresponding to it. (Having such a shortcut icon for a program allows the user to run the program by double-clicking on the icon without going through the start-menu.) If you do not have a Desktop "shortcut" icon for running MLAB, you can create one as follows. (1) Double-click on "My Computer" or "Computer", found either on the desktop or in the Start menu. This runs the file-manager program. (2) Double-click "local disk (C:)" to display a listing of the directory [C:\]. Look for the entry "mlab" for the mlab directory. double-click on this entry. (If you put MLAB in another directory, you will need to "navigate" to it. -remember you need to click IN the picture of a directory entry, not its title.) This will display the files in the mlab directory within the file-manager window. [A note about filenames in Windows. When you use Windows GUI tools to look at the files in a directory, you generally do not see the truth. The Windows file manager and other such tools display file names without the so-called filename-extension showing. Thus the file named "dimer.do" is listed as "dimer". More troublesome, the directory "mlab" is listed as "mlab", but so is the file "mlab.exe". Because of this problem, you are better off using a "command-prompt" window, i.e., a so-called DOS-window, and the cd and dir commands to see what files are in a directory, since the dir command does tell the truth. You can fix this problem in Windows as follows. (2.1) Run the "My Computer" or "Computer" function from the start menu (you should really put a shortcut link to "My Computer" on your desktop and rename it "file finder".) (2.2) Click on "Tools" in the top menu and select the "folder options" option from the drop-down menu. (2.3) Click on the "View" tab in the window that appears. (2.4) scroll through the "advanced settings" list and uncheck the item "Hide extensions for known file types". (2.5) Click the "Apply" 'button' at the bottom of the window. This also has the benefit that Notepad will show full filenames to you - but you will only see all your files after you change the "file type" selection from "text documents" to "All files"(!) This is a very troublesome problem! Be careful of this 'gotcha'. ] (3) Look for the executable program file "mlab.exe" in the displayed mlab directory. Right-click on the file-name 'mlab.exe'. This will "pop-up" a menu. (Remember "mlab.exe" appears as the name "mlab" in an unfixed file manager window.] (4) Click on the entry "Create Shortcut" in this menu. This will cause a "shortcut" file called "Shortcut to mlab.exe" to be created in the mlab directory which is now displayed in the file-manager window. (5) Place the mouse on this "Shortcut to mlab.exe" file, press the left-mouse-button and hold it and "drag" the shortcut file to the "desktop" and release the mouse button. For XP, this moves the "Shortcut to mlab.exe" file to C:\Documents and Settings\[username]\ Desktop\. For Win7, this moves the "Shortcut to mlab.exe" file to C:\Users\[username]\Desktop\. Now you have an MLAB "shortcut icon" on the desktop, because all files in all the Desktop directories are displayed on the desktop. You can run MLAB by double-clicking on this icon.] ---------- In all cases, MLAB will write a session log-file in the initial working directory! This log-file will be called "MLAB.LOG" (and the earlier log-files found there will be renamed with the 'shifted' names MLAB1.LOG, MLAB2.LOG, etc.) The session log-file is convenient. You can print it to obtain a record of what you did. You can extract text from it to construct a do-file. And you can review error messages recorded there to "debug" an MLAB do-file. (You will need to use some simple ASCII text editor such as Notepad to do these things. You can run Notepad from within MLAB by typing the command 'edit file "x"' where x is the desired filename, qualified with the appropriate path. [You CANNOT use MS Word, or Wordpad! These programs do not deal with ASCII files - they use their own non-plain-text format!]) Even if you start MLAB with the MLAB executable directory as the initial working directory, you can, in effect, change directories at will as you use MLAB. There is a control variable in MLAB called FILEDIR. This variable is a string of text that is prepended to every file-name you refer to in your MLAB session! [Your session log-file, MLAB.LOG, will, however, be created in the initial working directory that is set or that MLAB is given by Windows. Setting FILEDIR has no effect on where the log-file is.] The FILEDIR variable starts-out as the empty-string. Thus, assuming FILEDIR is empty, if you type 'DO afile' in MLAB, you are referring to the file afile.DO in your current working directory. If, however, you set FILEDIR - for example: FILEDIR = "C:\project1" (or FILEDIR = "C:\project1\") and then type 'DO afile', you will be asking MLAB to execute the do-file 'C:\project1\afile.DO'. (Note you need to know the DOS/Windows notation for specifying a "path", i.e a fully-qualified directory on a specified disk-partition 'volume'.) The same prepending of FILEDIR occurs for all files you refer to in MLAB. Thus, for example, if you read a data-file into a matrix with the command 'm = read(dfile,120,2)', you are actually asking MLAB to read the first 240 numbers found in the ascii-text file dfile.dat within the directory specified by FILEDIR into the 120-row, 2-column matrix m. There is an exception to the FILEDIR prepending rule in MLAB for do-files. If the MLAB control variable DOFILEDIR is set to a non-empty string, then this string, rather than FILEDIR is prepended to any do-file name that is specified to MLAB. (This lets you access do-files in a particular directory (specified by DOFILEDIR), while accessing other files in some other directory (specified by FILEDIR.) Thus, if you have your "project" data-files and do-files stored in some specially-named directory (and it is generally a good idea to work in this way,) then the first command you should execute in MLAB is: "FILEDIR = "xxx", where xxx is the fully-qualified path to the desired working directory. (Remember, you can change your working directory at any time in an MLAB session by resetting the FILEDIR string control variable appropriately.) When you run MLAB, a "console" window is put on the screen, and a smaller "menu" window is displayed in which you must make a selection. One choice is to run various examples. (The first few times you run MLAB, you should look at some examples!) Another choice is to go to "top-level", which means that the menu window is removed from the screen, and a "*" prompt symbol is displayed in the console window; this prompt is waiting for you to enter an MLAB command. Once you are at "top-level" and able to enter MLAB commands, you can use the up-arrow and down-arrow keys to "scroll" back through the previous MLAB commands and responses. Hitting the Enter key will take you back to the 'current' prompt line. (You will note there are no scroll bars on the MLAB console window; the arrow keys are the way you "scroll" in the MLAB console window.) In addition to looking at the previous lines in the console window, you can "select" a line by hitting the Insert key. This will cause the selected line to appear at the 'end' of the console window as the subject of a simple single-line editor facility in MLAB. You can then modify the selected line, and hit the Enter key to execute it. (When you enter an MLAB statement which is malformed in some way, you will receive an error message and the malformed line will be re-displayed in the MLAB single-line editor facility where you can (attempt to) repair the error and re-execute the line. You can also abort this 'editing' and just go to a new '*'-prompt.) ================================================= MLAB reads, writes or otherwise uses the following files or types of files. -------- 1 - gxfonts.0: a binary file containing the 34 MLAB stroke font definitions. gxfonts.0 is a read-only file and found in the directory where the MLAB program file is located. The file is accessed whenever a title string or axis label is to be drawn in the MLAB graphics window. -------- 2 - mlab.hlp and mlabref.hlp: files containing text used by the MLAB HELP systems. These read-only files are found in the directory where the MLAB program file is located. mlab.hlp is read when either the commands "HELP" or "HELP topic" are given by the user. The file mlabref.hlp is read when the user strikes the F1-key to access the special Windows help presentation system. This text is not very useful, and it fails to work for systems after XP (e.g. Vista, Win7.) Also the content of the MLAB help-file, mlab.hlp, that is accessed via the "HELP" command, although useful, is incomplete, and sometimes wrong, so be sure to depend on the MLAB Reference Manual as the final authority. -------- 3 - mlab.log, mlab0.log, mlab1.log, and mlab2.log: These are ASCII text files containing the dialog of the current MLAB session (in mlab.log) and the previous three MLAB sessions (in the files mlab0.log, mlab1.log, and mlab2.log). These files are created by MLAB in the user's working directory and are useful for seeing a record of MLAB results. They are also useful for constructing .do-files, since you can copy the text in an mlab log-file and edit it to construct a do-file. It is also useful to look at an mlab log-file to aid in debugging an mlab do-file. (Note: see the definition of the system variable ECHODO, below.) -------- 4 - .do-files: An mlab do-file is an ASCII text file containing comments and MLAB commands, i.e. a 'script' in the mlab language. Such a 'script' can be repeatedly re-run, and also easily changed as desired. Constructing and running a do-file is the preferred way of using mlab whenever you have a relatively substantial computation to do. An example of a .do-file is the file DIMER.DO in the directory containing the MLAB program file. Also there are example .do-files in the MLAB\EXAMPLES\ directory. A do-file can be generated with any ASCII text editor, such as the MSWindows Notepad Accessory program. DO NOT USE MS-WORD to create or change do-files or data-files intended for use in MLAB unless you know how to save files as ordinary text files! MS-WORD generally 'saves' binary files. (and remember "rich" text is NOT text!)- use Notepad or some other editor that can save plain ASCII .txt files easily. The MLAB command: [EDIT FILE filename.do] will run the Notepad program for editing the specified new or existing .do-file from within an mlab session. (When you run Notepad from within MLAB in this manner, you do not have the annoying problem of Notepad showing only *.txt files (and directories) to select for editing.) When running the Notepad editor via the EDIT FILE command within mlab, the named .do-file is searched-for or created in the directory specified by the path in the DOFILEDIR control string. If DOFILEDIR is null, then the directory specified by the path in the FILEDIR control string is used. If FILEDIR is null, then the initial "start-in" working directory is used. Also, note that you can use Notepad directly by running it from the start menu or by double-clicking on a desktop shortcut icon for Notepad.) But, beware! You must use the initial Notepad startup window to set the "type" of file to be input or accessed to the type "All Files" and you cannot type the desired filename in with clarity. There is a short manual about how to use Notepad below. MLAB .do-files contain MLAB commands and comments. Comments begin with the 2-character sequence: /* and are terminated with the 2-character sequence: */. Comments may span multiple lines. Note, comments may NOT be embedded within enclosing comments. If more than one MLAB command appears on a line of a .do-file, they must be separated by semicolons (;). (There are other situations where terminating semicolons must be used as well.) An MLAB .do-file is executed by the command: [DO filename.do]; that's why it is called a do-file. The three scalar control variables DOSTEP, ECHODO, and CASESW control aspects of general mlab execution and .do-file execution. If DOSTEP = k (a positive integer), then MLAB will pause--waiting for a key to be struck by the user--after every k lines in the .do-file have been executed. Thus, DOSTEP=1 will allow you to "single-step" through the do-file, perhaps, looking for a line that cause an error messsage. If DOSTEP = 0, which is the default case, then a DO-command will run the specified do-file without interruption to completion, unless MLAB commands requiring keyboard input are encountered, or there is an error detected. The control scalar ECHODO controls the "echoing" of do-file commands to the screen and the log-file, mlab.log. If ECHODO = 0, then the .do-file is executed silently--no commands are echoed to the screen or the log-file; if ECHODO = 1, then the lines of the .do-file are echoed to the screen but not the log-file; if ECHODO = 2, then the .do-file is echoed to the log-file but not the screen; and if ECHODO = 3, the do-file is echoed to both the screen and the log-file. The control scalar CASESW controls the case-sensitivity of MLAB names. If CASESW = 0, then upper-case characters are not distinguished from lower-case characters; all input is converted to upper-case, except within quoted-strings. If CASESW = 1, no such conversion is done, except for control variable names, mlab function names, and mlab reserved syntax words, like "TYPE" or "DO". The implications of using CASESW =1 are sometimes subtle, especially with identifiers used as filenames, and we reccomend you keep CASESW set to 0. (MLAB generaly tries both upper-case and lower-case versions of filenames in an attempt to not disappoint the user.) . -------- [How to Use MLAB] The most convenient way to run MLAB when you have a repetitive or a complex computation to do, is to setup a do-file to do it. (Remember, once you have read about how to use the Notepad editor, you can do this by typing EDIT FILE xdofile.do to create the do-file xdofile.do in your working directory.) You should be sure to put comments in your do-file to define all the variables and functions, etc. and don't forget to include comments specifying the units for all data where this is important. Note, it is convenient to give the commands "reset; echodo=3" as the first commands in your do-file. Also, remember the READ, READON, KREAD, and SREAD MLAB functions. Another tip is that you can construct strings by concatenation and you can execute such a string containing a sequence of MLAB commands as a do-file! For example, try z=99; S="type "+"value of z:"+z; do S; and you can construct more elaborate and useful examples. [You should look at the file startup.do and the do-files provided in the examples sub-directory.] After your do-file is written and saved on disk, you should print it (You can use the MLAB command "PRINT FILE xdofile.do" to get this listing.) Then you should read your do-file, add more comments, and verify that it does what you want to the best of your ability. (Remember to keep the MLAB manuals close at hand.) After you have iterated this step as much as you feel is helpful, you should then run MLAB and use the command "DO xdofile" to run your do-file. (Remember you will need to have set-up any data-files or other do-files that your do-file reads. It is quite likely that there will be errors in your do-file. If you can see what the problem is, you can just tyoe "EDIT FILE xdofile.do" and fix your do-file and resave it on disk. [You should leave the NotePad editor window 'open', so you can use it again in a few moments.] Then you can just type "DO xdofile" again, and see what happens. You can "flip" back and forth between NotePad and MLAB, until your do-file is "debugged". Sometimes it will be helpful to put TYPE statements in your do-file so it will tell you the progress of execution. This is just one of the standard debugging devices that can sometimes be helpful. When your do-file is debugged, it can be run whenever you wish by running MLAB and typing "DO xdofile". Of course, for all your work with MLAB, you must be aware of your current working directory and have FILEDIR set appropriately. One useful 'trick' you can use in a do-file is the command [DO KLINE], 'KLINE' stands for "keyboard-line". When this command is executed, MLAB will type a '>' prompt and wait for input. Whatever is typed will be executed as a do-file. Note this is a good way to pause if you don't want to use the undocumented MLAB PAUSE statement. Also, you can use DO KLINE in other ways like: [type "enter the desired function as 'fct f(x)=...':"; do kline;] (Here are some other experiments you should run. [do dofilename], [do "dofilename"], [do ksread()], [do ""+ksread()].) MLAB Example Do-Files All the examples that are available to you from the start-up menu are just .do-files that are stored in the sub-directory 'EXAMPLES' in the MLAB executable directory (generally C:\MLAB\). You should go look at those .do-files (using Notepad, or using the 'type' command or 'edit' command in a DOS-window.) You can also print any of these files using the MLAB PRINT FILE command. To do this, type the MLAB commands: filedir ="C:MLAB\EXAMPLES" type dir "*.do" Then select a file to print, such as dimerex.do, and type print file "dimerex.do" One of the interesting things you will see in some of the example .do-files is how to use the 'MENUCHOICE' and 'GETSTRINGS' MLAB functions that allow you to make your own menus and to obtain text input. (See in particular the Hogkin-Huxley Nerve Axon Model example.) There are many other interesting "lessons" to be found in the example .do-files as well. You can copy any of these do-files into your working directory, and then modify it to construct your own do-file. This is particularly appropriate if you want to do a computation related to one of the example do-files. -------- 5 - .dat-files: .dat files are plain ASCII files containing numbers to be read-in as data; the READ command is used to do this. Examples of .dat-files appear in the MLAB\EXAMPLES\ directory. (The READ command scans the specified file for numbers given by ASCII characters in any "standard" form, such as 123 or 12.34 or -3.1e12, etc. All other bytes are ignored; thus the mlab READ command can read appropriate non-ASCII files too.) As with .do-files, .dat-files can be created or modified with any ASCII text editor, such as the MSWindows Notepad Accessory program. And, as with do-files, The MLAB command: EDIT FILE can be used to construct or change a dat-file. Note, the MLAB string variable DOFILEDIR only affects the path for .do-files, and does not affect the location of .dat-files so that .do-files and .dat-files can be read from different directories. A .dat-file can also be created using Notepad, or any other program as long as it contains the numbers you want (and only those numbers) in ASCII (i.e. .txt format.) DO NOT TRY TO READ MS-WORD or EXCEL FILES IN MLAB UNLESS YOU KNOW THEY ARE TEXT FILES. Files created by MS-WORD and by EXCEL are generally not text files unless you know how to save them as such, they are usually binary files. (and remember "rich text" is NOT text!)- use Notepad or some other editor that can save plain ASCII .txt files easily.) The numbers in a .dat-file are read and stored as the elements of a matrix M by using the READ command: M = READ("filename.dat",nr) This READ-command will read nr or fewer values from the file filename.dat in the implicit directory (either specified by FILEDIR or established at initial start-up.) The i-th successively-read value is assigned to M[i] (so M will be a one-column matrix.). The input file will be scanned for numbers embedded in ANY non-digit text. However, you can prevent any text you want from being scanned by enclosing it in "'s or by the C-comment brackets /*, */. When FILEDIR is null, the read command [M = READ("C:\DX\DY\S.DAT", rr)] reads rr numbers from the file C:\DX\DY\S.DAT into M as a single column of rr values. (If the file does not contain rr numbers, then all the numbers present will be read.) Data matrices with nr rows and nc cols can be constructed with the following command: M = READ("filename.dat",nr,nc) If a .dat-file contains values for more than one matrix, a special version of the READ command can be used. the READON command can be used sequentially, as: M1 = READON("filename.dat",nr1,nc1) M2 = READON("filename.dat",nr2,nc2) . . . MN = READON("filename.dat",nrn,ncn) Each READON command continues reading in the input file where the previous READON command left-off. There are other MLAB data-input commands you should learn about - notably the KREAD and KSREAD functions. -------- 6 - .ps or .lj-files: A .ps file is an ASCII file in the Adobe PostScript graphics language. A .lj file is a binary file containing or Hewlett- Packard PCL language. Both forms of output files are called "plot-files". They contain the printer commands for an MLAB graphics picture. After creating an MLAB 'picture' (consisting of one or more MLAB "windows" all within the main mlab graphics window, using the DRAW command, etc.), the MLAB-command [PLOT] will generate a plot-file in the current working directory. This plot-file is either a file named MLABP#.PS containing commands suitable for printing on either a PostScript-capable printer or a printer on a computer with appropriate conversion software like Ghostscript, or it is a file named MLABP#.LJ containing HP PCL-GL/2 commands suitable for printing on a GL/2-compatible printer. The symbol # denotes the next succesive integer in the sequence 0,1,2,... (e.g. the first PLOT command writes-out MLAB0.PS, the next PLOT command writes-out MLAB1.PS, etc.) If the MLAB control variable PLOTDEV is set to PSL (or "PSL" - try typing PSL) then a .PS plot-file is created containing a black and white, Landscape orientation Postscript picture. If the MLAB control variable PLOTDEV is set to PSCL (or "PSCL") then a .PS plot-file is created containing a color, Landscape orientation Postscript picture. If the MLAB control variable PLOTDEV is set to PSP (or "PSP") then a .PS plot-file is created containing a black and white, Portrait orientation Postscript picture. This is the preferred plotting mode for creating a .ps plotfile for "embedding" in a document. If the MLAB control variable PLOTDEV is set to PSCP (or "PSCP") then a .PS plot-file is created containing a color, Portrait orientation Postscript picture. If the MLAB control variable PLOTDEV is set to HPLJ (or "HPLJ") then a .PS plot-file is created containing a black and white, Landscape orientation PCL-GL/2 language picture. An MLAB .PS plot-file is a so-called 'Encapsulated Postscript' file suitable for embedding in a "document" file such as an MSWord file, or a .tex file by respecifying the size of the picture in your document file. You may change the name of your .PS file to be a .eps file which is sometimes required. The 'encapsulated PostScript' file, thus created by renaming can be "imported" to Microsoft Office (Word, PowerPoint, Excel) or TeX 'documents' (i.e. files). For example, to add the MLAB graph in the file MLABP0.EPS to an MSWord document, position the text cursor in the MS Word document where the graph is desired, goto the "Insert" menu, select "Picture" from the drop-down menu, select the "FromFile" option, select the MLABP0.EPS in the resulting FileSelect dialogue box, and then select "Convert File From Encapsulated PostScript". An MLAB .PS file is just a text file, and you can look at it and change it with any ASCII text editor program. For example, you can "open" the plot-file (MLABP0.PS say) with the MLAB command: EDIT FILE MLABP0.PS), Note the fifth line in the file contains the text defining the bounding box given in 'point'-units (1 inch = 72 points) that encloses the graphical image: -------- 7 - .lst files: ASCII files containing MLAB data names and data. The MLAB PRINT command: PRINT [name1,name2,....] in generates an ASCII text file named 'filename.lst' in the current working directory containing the MLAB data names name1, name2, etc. and their corresponding values. If the mlab control variable NAMESW = 0, then the MLAB data names are suppressed in the output file. This provides a convenient way, for example, to "export" an MLAB matrix to another computer program that accepts ASCII data files. Note, the MLAB command: PRINT FILE sends a command to the local printer, to print the named file in the current working directory. -------- 8 - .sav files: A .sav file is a binary file containing "saved" MLAB data names and values. The entire current state of MLAB, including all control variables and user-created curves, windows, functions, matrices, scalars, etc., can be saved in a .sav file in the current working directory by the command: SAVE IN The saved state of MLAB can then be restored at any other time and in any other MLAB session by typing the command: USE The SAVE command can also be used to save specific MLAB data structures, such as an MLAB graphic window named Q and a scalar vaule named B by listing the specific data items to be stored; for example: SAVE Q,B IN The window can be restored in a later MLAB session by typing the command: USE .SAV files are binary files; they can not be edited directly with ASCII editors and are not exchangeable across different types of computers; i.e. a .SAV file from Windows MLAB can not be easily transferred to a non-Intel Macintosh version of MLAB due to the "endian" conflict. The pre-defined .sav-file DW.SAV defines the elements of the default MLAB graphics window, W, and provides an example of a .sav file. DW.SAV is generated by giving the MLAB commands (we do this via a do-file): WINDOW 0 TO 10, 0 TO 10 ADJUST WNICE IN W; XAXIS 0:10!6&'0 LABEL 0:10!6 LABELSIZE .015 FFRACT OFFSET (-.01,-.025) \ FFRACT FORMAT (-3,5,0,0,2,0) PT UTICK IN W; YAXIS 0&'0:10!6 LABEL 0:10!6 LABELSIZE .015 FFRACT OFFSET (-.09,-.01) \ FFRACT FORMAT (-3,5,0,0,2,0) PT RTICK IN W; FRAME COLOR VIOLET IN W; IMAGE COLOR BLUE IN W; SAVE W IN DW When drawing in MLAB without specifying the target MLAB "window", the default MLAB-"window", W, will be used. MLAB obtains W by USE-ing it from DW.SAV. ------- 9. - Printing Files on a Windows system. The MLAB command: PRINT FILE sends a command to the local printer, to print the named file in the current working directory. The MLAB PRINT FILE command works for ASCII files, such as .dat or .lst files, and it also works for .lj files if you have a directly-attached HP PCL-language printer (most printers understand the PCL language.) This also works for .ps files if you have a directly-attached Postscript-language printer. (If not, you may need to use a web-browser to view .ps files generated by MLAB. You may be able to print them via the web-browser program. Also, if MSWord is properly programmed with the analog of the Ghostscript Postscript to PCL converter, you may be able to view a .ps file via MSWord.) Also, you can send a file to your printer to be printed with the command "COPY LPT1:" given in a DOS command window. The file must be an ASCII text file, or in a native language of the printer. ======================== Some More Information about Using MLAB 1. How to draw and plot a 3-D surface picture. You may want to see a surface (a graph of some function f(x,y), or a parametrically-defined surface of the form (x(s,t), y(s,t),z(s,t)) for example.) When that surface is the surface of a single-valued function, a useful way to "see" it is to look at a corresponding contour map. See the contour-map example: conex.do, found in the MLAB examples directory reached from the MLAB start-up menu. A "fancier" way to view a surface is to generate a perspective 3D view of the surface. An example of how to do this is found in the example do-file: torex.do located in the examples sub-directory (For Win7, generally this is /Users/[username]/Desktop/mlab/examples/). The DRAW command described earlier for ordinary 2D graphs can also be used to create 3D perspective views of 3 dimensional data. The simplest 3D graph is a simple plot of a set of 3 dimensional points in which each point is drawn with a specified point-type symbol. For example, consider a set of 100 points with random coordinates. Such a set can be created with MLAB with the following command: M = SHAPE(100,3,RAN ON 0^^300) Then the command: DRAW M POINTTYPE DOT3D LINETYPE NONE creates the 3D window, W3, with a dot at each point given in the data matrix, M. Other 3D graphics point-types include: CROSS3D - this draws a 3D cross at each point, "char" - this draws the given quoted ASCII character (such as "x") at each point.. When you enter the command: VIEW MLAB displays a default 3D perspective view of the points. The default 3D perspective view is a view of the data as it would appear in the viewfinder of a camera placed at a suitably-chosen position and pointed in a suitably-chosen direction. The default position and direction of the "camera" are determined as follows: first, find the limits of the bounding box for all 3D points, lines, curves, and surfaces: (xmin<=x<=xmax, ymin<=y<=ymax, zmin<=z<=zmax) with box-dimensions x1=(xmax-xmin), y1=(ymax-ymin), z1=(zmax-zmin) on the sides parallel to the x,y, and z-axis, respectively. The center of the box is at (xcenter=xmin+x1/2, ycenter=ymin+y1/2, zcenter=zmin+z1/2). When the VIEW command is first given, the initial view drawn is that seen in the 'viewfinder' of a camera positioned at (xcenter,ymax+y1,zmax) with its lens pointed in the direction which results from right-hand-screw rotating a unit vector which is initially parallel to the z-axis by 105 degrees about the x-axis. The camera's initial viewing angle is 90 degrees. After MLAB displays the initial 3D perspective view, a double-arrow prompt, >>, is printed. At this stage, MLAB is awaiting a 3D view command. Striking the Enter key without giving a 3D viewing command will terminate the viewing command input at once, and return to the usual MLAB command prompt, *. There are eleven 3D perspective view commands that modify the camera position and pointing direction. These are: DOLLY K - which moves the camera forward in the view direction TRUCK K - which moves the camera to the right of the view direction RAISE K - which moves the camera up from the view direction PAN A - which rotates the camera about the vertical axis TILT A - which rotates the camera about the horizontal axis TWIST A - which rotates the camera about the viewing axis TRACK - which rotates the camera so as to point to the origin TURN A - which right-hand-screw rotates the camera about the center of the 3D bounding box (x1,y1,z1) ZOOM A - which changes the angle of view ORIGIN - which moves the camera to the origin, looking up the z-axis RESET - which automatically returns the camera to the initial view In these commands, A is an angle in degrees [0:360] and K is a number of "relative-box" units such that the main diagonal of the bounding box is 1 relative-box unit. Fore example, DOLLY -.5 would move the camera backward in the viewing direction by .5 relative-box units. There are also 3D graphics commands for adding or removing graphical 'elements' of the 3D MLAB "window"; for example, the bounding box can be drawn with the command: BOX or can be erased with the command: NO BOX In addition to the commands listed above, there are more than 75 other 3D graphical commands for manipulating the 'elements' of the 3D perspective MLAB window. See the MLAB Reference Manual and MLAB Graphics Examples Manual for further discussion. MLAB has seven line-types for 3 dimensional graphics. These are: NONE NEEDLES SEQUENCE ALTERNATE MARKER NET HIDDEN As seen in the example above where we drew points using LINETYPE NONE, the line-type NONE draws no line segments. The NEEDLES line-type draws line-segments from each point in the 3D data matrix, say (x[i],y[i],z[i]), to the bounding box floor at (x[i],y[i],0). The SEQUENCE line type draws line-segments from the i-th data point to the (i+1)-th data point for all the 3D data points. This line-type is of use when drawing the 3D perspective view of a space curve. The ALTERNATE line type draws line-segments between every other pair of 3D data points; i.e. between the first and second, third and fourth, fifth and sixth, seventh and eighth data points, etc. The result of a MARKER line-type is similar to the MARKER line-type used for 2D data. The values of the first row of the 3D data matrix define a 'marker' value. As line drawing proceeds sequentially from a 3D data point to the following 3D data point, if the marker value is encountered in column 1 then no line-segment is drawn and the sequential drawing of line-segments is started anew until the next marker value is found. The line types NET and HIDDEN are used for graphs of 3D data in which the data describe a surface. The surface may be an explicit function of two variables with data {(x[i],y[j],f(x[i],y[j])), for i=1,2,...,nx and j=1,2,...,ny} or the surface may be defined parametrically, in the form {(x(s[i],t[j]),y(s[i],t[j]),f(x[i],t[j])), for i=1,2,...,nx and j=1,2,...,ny}. For an example you may define a function of two variables: FCT F(X,Y) = (x^2+y^2)/2 + x^2*y-y^3/3 and then generate a grid of x and y values: M = CROSS(-2:2:.2,-2:2:.2) and then evaluate the function F at each grid point: M COL 3 = F ON M and then graph the data with the NET line-type: DRAW M LINETYPE NET VIEW the resulting 3D perspective graph shows an image resembling a wire mesh with each point of the grid connected to its four nearest grid neighbors. The HIDDEN line-type for 3D perspective graphs corresponds to the NET line-type except that "quads" are filled-in with color and parts of "quads" on the surface that are obscured by intervening quads of the surface are not seen! The HIDDEN linetype is demonstrated in the TOREX.DO do-file in the examples subdirectory. The command CMD3D can be used to specify 3D graphics commands; this is particularly useful in do-files. You simply give a sequence of desired 3D graphics commands deparated by semicolons [;] in a quoted-string as the argument of the CMD3D 'function'. For example, CMD3D("TRACK; DOLLY .5") given in a do-file (or even at 'top-level' before the VIEW command) will have the same result as typing the commands TRACK; DOLLY .5 at the <<-prompt. You will want to experiment and read the MLAB Reference manual about all the 3d, hidden-surface, and other viewing commands and options. If you are "plotting" an MLAB hidden-surface picture, you should use PLOTDEV = PSCL (PSCL stands for Postscript-color-landscape.) This will render your picture correctly on both a color PostScript printer, and on a black and white PostScript printer (via grey-scale dithering matching the specified colors.) Using PLOTDEV = LJ2L specifies that a "raw" plot file for a PCL-language printer be created. A PCL-language plot-file cannot (currently) be used to render an MLAB hidden-surface picture. ======================== How to Get and Install MLAB for Windows You get a copy of MLAB by going to www.civilized.com and following the indicated links to come to the page for downloading the MLAB "package" file for Windows, (or for OSX, or for Linux.) When you click on [Click here to download MLAB via http protocol] at the appropriate page at www.civilized.com, your browser will begin the download process of a file called zmlab.exe (for Windows.) This file is a "self-extracting" WinZip file containing the various MLAB files. ('self-extracting' means the file zmlab.exe starts with an executable program that, when executed, unpacks the remaining compressed content of the zmlab.exe and writes these files to a specified directory on the disk.) When downloading MLAB in Firefox and installing MLAB after downloading, you will see a sequence of windows. [1.] "Opening zmlab.exe" window The first window that you get will be an "Opening zmlab.exe" window produced by Firefox; this window says: "You have chosen to open zmlab.exe. Would you like to save this file?" You must click on [Save File]. ("Opening" is a misnomer - they mean "Downloading".) Firefox will then download the file zmlab.exe into the directory that has been previously specified as your "download directory". (This is sometimes incovenient; it would be better if Firefox had retained the option to explicitly ask where you want a download file to go at each download.) By default your 'download directory' is C:\Documents and Settings\[username]\My Documents\Downloads\ for Win-XP and C:\Users\[username]\Downloads\ for Win7. However it is better if you reset your download directory to \Desktop, so that you can 'see' what you have downloaded on the desktop. (You do this in Firefox by going to Tools -> Options, and then entering your desired download directory name.) (You need to have "Administrator" privileges to set your download directory to \Desktop and to download into it.) You need to do this before you download files, of course. [2.] Firefox "downloads" window. This Firefox-produced window reports the recently-downloaded files, with zmlab.exe as the first entry, together with a "completion bar" showing the download progress. After the download is complete, this window remains on the screen. The next step you want to do is to run the self-extracting file zmlab.exe that has just been downloaded. This starts the process of installing the MLAB prgram. You can run the self-extracting file zmlab.exe by double-clicking on the zmlab.exe entry in the Firefox "downloads" window. (One can also run zmlab.exe in various other ways. You can run zmlab.exe by double-clicking the icon for zmlab.exe on the desktop (if you downloaded to a Desktop directory,) or by using "Computer" or "My Computer" or some other means to display whatever your download directory is, and double-clicking on the filename zmlab.exe shown there to run it.) When the user runs the zmlab.exe program (by whatever means,) another sequence of windows will be "generated". [3.] Firefox "Open executable file" warning window (You will only see this window when zmlab.exe is run from the Firefox Download List Window.) Firefox displays this window and asks "are you sure?" because you are trying to run the downloaded program zmlab.exe, and Firefox wants to make sure you understand you are running a downloaded program. [Click OK]. Running zmlab.exe is really running the WinZip Self-extractor program appearing at the "front" of zmlab.exe. If you run zmlab.exe by some other means, this "open executable file" window will not appear. [4.] Windows "open file-security warning" window. This window (produced by the Windows OS) says "publisher not verified, are you sure?" At this point you are trying (or still trying) to run the WinZip Self-Extractor program, and zmlab.exe is not a registered application known to Windows. [Click RUN]. (This happens because our WinZip self-extractor program does not have a registration with Microsoft, and we do not know how to get or use the "key" that makes this window not appear.) [5.] WinZip Self-Extractor window for zmlab.exe. When the WinZip Self-Extractor program runs to "unzip" the various MLAB files in the 'tail' of zmlab.exe, it displays this WinZip dialog window. This window has an editable text-entry field titled "unzip to folder" with a "browse" button in which the user can specify the directory where MLAB is to be installed. The default specified there is "\MLAB". (You may change the MLAB directory to another name, or even another path, if you wish, but we recommend you leave it alone.) [Click "Unzip"] [6.] WinZip Self-Extractor completion window. WinZip reports 52 files "unzipped" successfully. [Click OK] The Civilized Software setup.exe program that was included among the downloaded and unzipped files is now run by the WinZip Self-Extractor program. [7.] Windows Install-As-Administrator Window (You will only see this Windows-produced window when NOT running as Administrator on WinXP/Win2K. On Win7, we do a "personal" install, and this window never appears). On XP, if you do not have "administrator" privileges, (i.e. if you are logged in as a limited user), then before the setup.exe program is started, then an Install-As-Administrator window will be displayed by Windows. This window offers two choices: 1. Run as hostname/user, or 2. Run as administrator (the username Administrator and the corresponding password is required). If you are logged-in with administrator privileges, then this window is not displayed. Now, after responding to the options offered (assuming the Install-as-Administrator window is presented,) the setup.exe program will be executed. If you select option 1 and continue as "hostname\user", then the MLAB setup program runs and it asks again whether you want to terminate and re-login as administrator, or continue. If you continue, MLAB is installed with an MLAB shortcut .lnk file placed in the user's desktop directory. If you select option 2, you will be asked to supply the Administrator password, and then the MLAB setup program runs. MLAB is installed with an MLAB shortcut .lnk file placed in the system desktop directory. On Win7, we do not know how to "overcome" the access-control features that prevent us from creating an MLAB shortcut file in \Users\Public\Desktop. Thus we currently ALWAYS do a "personal" install where setup.exe places the MLAB shortcut file in the user's desktop directory. [8.] "DOS" command window. This window may be obscured by your browser window, and you should either minimize or move your browser window to see this window or just click in this window to bring it "to the front." This window appears when the setup program is run. We see a "DOS" command window because setup.exe is a "console" application which will present output and receive keyboard input in this "DOS" window. When the MLAB installation process is finished, the setup program will report some information in this window and ask you to type any key to exit. Read the output there and then type a character. When you strike a key as directed to terminate setup.exe, then this associated console window disappears. Now you are done installing MLAB and you will have a desktop "shortcut" icon showing there for later use. Now you should maximize your browser window, if necessary, and click on "go back to www.civilized.com". Later, when you have finished with your browser, you can run MLAB by double-clicking on the new MLAB desktop icon. ==================================== [Creating a Desktop icon for running MLAB: If you do not have a Desktop "shortcut" icon for running MLAB, you can create one as follows. (0) If you do this on Win7 right after installing MLAB, when you click on "start" to display the Start menu, you can find the MLAB desktop shortcut icon in the list of "recently-run programs in the start-menu. All you need to do is to press the mouse button down while positioned at the MLAB icon and "drag and drop" it onto your desktop. Otherwise: (1) Double-click on "My Computer" or "Computer", found either on the desktop or in the Start menu. This runs the file-manager program. (2) Double-click "local disk (C:)" to display a listing of the directory [C:\]. Look for the entry "mlab" for the mlab directory. double-click on this entry. (If you put MLAB in another directory, you will need to "navigate" to it. -remember you need to click IN the picture of a directory entry, not its title.) This will display the files in the mlab directory within the file-manager window. (3) Look for the executable program file "mlab.exe" in the displayed mlab directory. Right-click on the file-name 'mlab.exe'. This will "pop-up" a menu. (4) Click on the entry "Create Shortcut" in this menu. This will cause a "shortcut" file called "Shortcut to mlab.exe" to be created in the mlab directory which is now displayed in the file-manager window. (5) Place the mouse on this "Shortcut to mlab.exe" file, press the left-mouse-button and hold it and "drag" the shortcut file to the "desktop" and release the mouse button. For Win-XP and Win7, this moves the "Shortcut to mlab.exe" file to C:\Documents and Settings\[username]\ Desktop\. Now you have an MLAB "shortcut icon" on the desktop, because all files in all the Desktop directories are displayed on the desktop. You can run MLAB by double-clicking on this icon.] -------------- A Step-by-step Guide to using MLAB 1. Install MLAB 2. Establish a Desktop shortcut icon for MLAB, if necessary. 3. Run MLAB enter your name for display purposes, and verify that your current directory is listed in the MLAB console window as C:\mlab\ 4. Use the first choice on the start-up menus window to look at the example menu and run the first few examples. 4. Exit MLAB. 5. Run MLAB 6. Goto "top-level", and type the MLAB command: [type 3+exp(2)]. Now type the command [3+exp(2)]. 7. Now type the command ... 8. Run MLAB, go top-level, and type the command [edit file "toy.do"] ... ======================== How to Use the Windows Notepad text-editor program [You can use Notepad, but it is better to get a better text editor like emacs or vi or many others. Try to get an editor that tells the truth about file names! You must be able to edit ascii text. You CANNOT use MS Word or any other non-ascii-text-editor.] ---