University of Hone Kong

Computer Centre

User Document No,. 201

Using MEDAL in the UNIX Environment

Introduction

MEDAL ( Matrix & Expert system Development Aid Language ) is an application package for mathematics, simulation and expert system development. MEDAL has the novel and unique feature of providing an integrated envirorunent for both numeric computation and fuzzy expert systems.

MEDAL can handle knowledge constructs such as rules, facts and frames. Moreover, it also supports basic programming structures, such as script and function files, for the representation of algorithmic knowledge. Besides, it allows development of fuzzy logic and includes facilities for the representation of membership functions of linguistic variables and fuzzy rule inference.

MEDAL supports tightly-coupled symbolic and numeric processing. As an applied Artificial Intelligence tool, it can be used to build hybrid or coupled systems in many branches of science and engineering. As a control engineering tool, it can be used to model, analyze and design dynamic systems. Heuristic knowledge in control engineering can be represented by using rules and frames. The package can also be used as a fuzzy control development tool.

MEDAL is an interactive software package. The syntax of its programming language is similar to that of MATLAB ( Matrix Laboratory ). Hence, MEDAL is providing the mathematical functions and the M-files features which are similar to those of MATLAB. In addition, the package is including a new command syntax for fuzzy expert system development, and a few new data structures like packed matrices, rules and frames, which characterize the unique features of the software.

Starting/Quitting MEDAL

The MEDAL working environment on hkusua can be started from any UNIX workstations with the following procedure:

 
	1)   Login a UNIX workstation

	2)   Disable the access control by typing
		% xhost +
	Note: the command  xhost  can  be  found  under  the 
	paths  /usr/bin/X11   (for   IBM   or   DEC  machines) 
	and /usr/openwin/bin (for SUN machines).

	3)   Display the nodename of your workstation by typing
		% hostname

	4)   Login to hkusua UNIX server using the telnet command below
		% telnet hkusua.hku.hk

	5)   Direct graphic display to your workstation, say hkursb, by typing
		hkusua% setenv DISPLA Y hkursb. hku. hk:0. 0

	6)   Invoke MEDAL by typing
		hkusua% medal

        Note: % and hkusua% shown above are the system prompts  of  the 
	 particular  workstations  and  server mentioned; they may vary for 
	different systems.
After the above steps a main menu as shown in the following will be displayed and you can then select option 10 to get into the command-line mode for interactive execution of MEDAL commands.

Figure: Main Menu Display of MEDAL

 
	llll  MEDAL (version 2.1) Fuzzy Edition
	(c) Copyright 1991-1994 Dr. Grantham Pang
	All Rights Reserved
 	   March 17, 1994
	   Matrix and Expert system Development Aid Language package


	This is an Introductory Version of MEDAL with Demonstrations.
	Please read the conditions of usage in menu item 7.
	For a Professional Version with full capabilities, choose item 8.
 	*************************************************************************
	You are free to duplicate and distribute this demo MEDAL software
	provided no changes of any kind is made to the code and files.
	 ************************************************************************

	Main menu:
	1 .Start demonstration of MEDAL
	2. Unique Features of the MEDAL package
	3. Difference between MEDAL and MATLAB
	4. A Tutorial of the MEDAL package
	5. How to obtain the MEDAL User's Guide
	6. Setting up MEDAL for your Computer
	7. Limitations of the Introductory Version
	8. How to obtain the Professional Version
	9. Install Professional Version
	10. Exit to execute commands interactively in MEDAL
	(command-driven mode of MEDAL)
	Please choose one : 10

	Commands 'who','what','help','menu','exit'are available. 
	<MEDAL>

7) If plotting of graphs generated by MEDAL is required, type at the <MEDAL> prompt the command:

setterm "x11"

8) Now, you can then
a) Carry out your work under the MEDAL working environment.
b) Recall the above menu again, say for running the demonstration program, reading the tutorial, etc., by issuing the command at the <MEDAL> prompt:
menu

9) To ask for help, invoke the command at the <MEDAL> prompt:
help "command"
e.g. help "help"

10) To exit from the MEDAL environment, invoke the command at the <MEDAL> prompt:
exit

Basic Commnnds

Recording Text Input & Output

Users can keep a complete copy of MEDAL session, including both text input and output, by using the UNIX script command.

Save, View & Print Graph

Users can save a copy of displayed graphic image in a specially formatted file which can be retrieved later for display. Likewise user can save the displayed graphic image in a PostScript format and then send it to a PostScript printer for printing.

Coupling with External Programs

MEDAL can be coupled with external programs through the use of load, save and system commands.

Example:

Editing the user defined M-file, called matsqrt.m to allow MEDAL to be coupled with an external C program, called croutine.c, which reads data from an input file, called c_in.med, and writes data to an output file, called c_out.med

1. Editing,the M-file, matsqrt.m, and the C program, croutine.c, by using any available text editor, e.g. vi editor

	  - User  defined  M-file  called  matsqrt.m
                   function [x] = matsqrt(y)  {
                              save 'c_in' y
                              system './croutine'
                              load 'c_out'
	        }	
                 - Extemal  C  program  called  croutine.c
                    #include 
                    #include 
                     main()
                     {
                     FILE *in,*out;
                     char vname[80];
                     int vrow,vcol,vstate,vimag;
                     double *data;
                      int  i;
                           if ((in=fopen("c_in.med","r"))== NULL)  {
                                 printf("No input file!\n");
                                 exit;
                        }
                            fscanf(in,"%s %d %d %d %d\n",vname,&vrow,&vcol,&vstate,&vimag);
                            data = (double *)calloc(vrow*vcol,sizeof(doubIe));
                             for (i=0;i
 

2. Use the user defined function, matsqrt, which generates two files, c_in.med and c_out.med, recording the input and output for the extemal C program, croutine.c

                                     e.g.

                                       <MEDAL> matsqrt( [ 1; 2; 4; 3] )
                                       Saving current variables to c_in.med.
                                       Reading data from file c_out.med.
                                            ans =
                                            1.0000
                                            4.0000
                                            16.0000
                                            9.0000

                                       MEDAL data files, c_in.med and c_out.med

                                            c_in.med
                                       y 4 1 0 0
                                       1.00000000000000e+00
                                       2.00000000000000e+00
                                       4.00000000000000e+00
                                       3.00000000000000e+00

                                            c_out.med
                                       x 4 1 0  0
                                       1.00000000000000e+00
                                       4.00000000000000e+00
                                       1.60000000000000e+0l
                                       9.00000000000000e+00

REFERENCES

  1. MEDAL: Introductory Version User’s Guide, by Grantham Pang, Waterloo MEDAL Software & Technologies Inc.

  2. MEDAL: Fuzzy Edition Reference Manual, by Grantham Pang & Raymond Tang, MEDAL Software & Technologies Inc.