mdbtxt1
mdbtxt2
Proceed to Safety

MU_01.C    

Robert P. Munafo, 1994 Jan 27



/* MU_01.C    This is the Universal Mandelbrot Browser, by Robert P. Munafo    This version is version 01, dated 19940113.    Contents 1. Background: who, what, why 2. Configuration; which files you'll need 3. Pseudocode 4. The source code    1. Background: who, what, why    This program is used as a central example by Mu-Ency, the Mandelbrot Set Glossary and Encyclopedia, which is accessible through electronic mail relay at mu-ency@mrob.UUCP , or mu-ency%mrob@uunet.uu.net . If you haven't used Mu-Ency yet, you should send a message containing the word "intro" to receive an introduction to Mu-Ency, and instructions on how to access its extensive resources.    This program was designed to teach several important algorithms that relate to exploring the Mandelbrot Set. To make the code easy to read, it was written most of the "instructional" algorithms were written in a special pseudocode developed specifically for use in Mu-Ency. This pseudocode is translated into C by the preprocessor when you compile the program.    In addition to the pseudocode, there is a large amount of specific interface code that enables the system to run on many specific real environments, including: DOS (Borland C 4.0, Symantec C 6.0, Microsoft C) Microsoft Windows 3.0/3.1 (Borland, Symantec, Microsoft) Macintosh (Think C 5.0 & 6.0, MPW, CodeWarrior) X Windows Xlib X11R4 or X11R5 (with ANSI C compiler) Generic ASCII console interface (with ANSI C compiler) Depending on which environment you have, the program will operate in different ways. For example, selecting a subview is done with a mouse on the graphical systems, with arrow keys in the DOS version, and with a multiple-choice menu in the generic ASCII console version.    %%%interrupt with control-D in console version? fork() a process to do computing in background?    2. Configuration; which files you'll need    After this instruction section you will find the configuration section. There are four questions that you need to answer; each is a multiple-choice.    You answer the questions by removing one or more "/*"s as instructed in the configuration section. Your answers determine which of the other files are used in the compile.    Here are the questions with the currently supported answers:    Calculation Method - use this to indicate whether you have an FPU Integer Floating-point Display Method - selects specific output routine for your display ASCII - Uses UIASC.C Mac - Uses UIMAC.C X - Uses UIX.C CGA - Uses UICGA.C VGA - Uses UIVGA.C File System - selects type of filename and format of logfile generic ANSI C - Uses FSC.C Mac - Uses FSMAC.C UNIX - Uses FSUNX.C DOS - Uses FSDOS.C Compiler - allows the use of optimized assembly-language routines Think C 5.0 or 6.0 on a Mac - Uses OPM1.C Borland C on a 386, 486, or Pentium - Uses OPB1.C generic - Answer this way if your compiler is none of the above.    3. Pseudocode    After the configiration section is the beginning of the main pseudocode. There are many routines, each of which is preceded by a description. Many of these have their own entries in Mu-Ency. */    /* Display methods. The following define selects one of the possible methods of displaying a Mandelbrot image to you. Remove the "/*" from the beginning of one of the following lines to indicate the type of display system you will use. (If you remove none of them, the ASCII Graphics method will be used. See CONFIG.DOC section 4.2) */ /* #define DM_MAC1 /* Macintosh monochrome QuickDraw (see CONFIG.DOC section 4.2.1) */ /* #define DM_MAC2 /* Macintosh color QuickDraw (see CONFIG.DOC section 4.2.2) */ /* #define DM_CGA1 /* DOS CGA, 320x200 4 colors (see CONFIG.DOC section 4.2.3) */ /* #define DM_VGA1 /* DOS VGA, 640x480 16 colors (see CONFIG.DOC section 4.2.4) */ /* #define DM_VGA2 /* DOS VGA, 640x480 256 colors (see CONFIG.DOC section 4.2.4) */ /* #define DM_VGA3 /* DOS VGA, 800x600 256 colors (see CONFIG.DOC section 4.2.5) */ /* #define DM_SV1 /* SunView 5.3 (see CONFIG.DOC section 4.2.6) */ /* #define DM_XW113 /* X Windows V11R3 (see CONFIG.DOC section 4.2.7) */ /* #define DM_XW115 /* X Windows V11R4 or R5 (see CONFIG.DOC section 4.2.8) */ /* #define DM_TTY1 /* Generic ANSI C text-mode I/O (see CONFIG.DOC section 4.2.9) */       /* This is the header. It defines all the pseudocode macros. */ #include <stdio.h>    /* Keywords of the C_SIC programming language.    C_SIC is a language remotely resembling BASIC which can be emulated by any ANSI C compiler, by simply prepending a file with a set of preprocessor macros. This is of course a really brain-damaged thing to do, thus the deliberate pun on "seasick".    Here are the C_SIC constructs:    PROGRAM .. END Defines the main program routine. Okay, so that's a PASCAL concept. Shoot me.    INT_FUNCTION .. BEGIN .. END REAL_FUNCTION .. BEGIN .. END SUBROUTINE .. BEGIN .. END Use these to define functions and subroutines.    DECLARE( .. ) DECLARE_INT( .. ) Declares variables. Alas, the need to declare variables is a C-like thing to do, not a BASIC-like thing. Oh, well.    IF .. THEN .. ENDIF IF .. THEN .. ELSE .. ENDIF IF .. THEN .. ELSE IF .. THEN .. ENDIF .. ENDIF Conditional constructs. Alas (again) you need an ENDIF for each IF. We could opt for a PASCAL-like alternative requiring BEGIN..END pairs for multi-statement conditional actions.    FOR .. TO .. BY .. DO .. END Loop construct. Works as an increasing or decreasing loop, and uses a user-specified assignment expression to alter the variable, thus it's very flexible.    WHILE .. DO .. END Another loop construct. If C allows "while(x) statement;" we could opt for a PASCAL-like form requiring BEGIN..END for multistatement blocks.    TRUE FALSE Boolean constants useful in writing and using functions that return a boolean.    LESS_THAN GREATER_THAN EQUALS Sometimes pseudocode is more readable when we use these    LET Does nothing, but allows us to say "LET x = x+1" just like in BASIC (-: */    #define IF if ( #define THEN ) {{ #define ELSE }} else {{ #define ENDIF }}    /* This version of for..next allows the loop variable to be any type, and its value can change in either direction via a user-specified iterator assignment function. Its only shortcoming is that you have to include the "BY x=x+1" even for simple increment loops. */ #define FOR {double __c,__e;int __d;__c=( #define TO );__e=( #define BY );for(__d=(__c<__e);((__c<__e)==__d)||(__c==__e);__c=( #define DO )){ #define END }}    #define WHILE { while (( /* DO already defined as )){ */ /* END already defined as }} */    #define INT_FUNCTION int #define REAL_FUNCTION double #define SUBROUTINE void #define BEGIN {{ /* END already defined as }} */    #define PRINT_STR(s) printf("%s", (s)); #define STR(s) PRINT_STR(s) #define PRINT_INT(i) printf("%ld", ((long) (i))); #define INT(i) PRINT_INT(i) #define PRINT_REAL(r) printf("%f", ((double) (r))); #define REAL(r) PRINT_REAL(r) #define NEWLINE printf("\n");    #define DECLARE(v) double v ; #define DECLARE_INT(v) long v ;    #define PROGRAM main() {{ /* END already defined as }} */    #define TRUE (1==1) #define FALSE (1==0)    #define LESS_THAN < #define GREATER_THAN > #define EQUALS ==    #define LET /* */       /* Obsolete macros    Single-brace version of if..then #define IF if ( #define THEN ) { #define ELSE } else { #define ENDIF }    PASCAL-like if..then (requires BEGIN..END if doing multiple statements conditionally) #define IF if ( #define THEN ) #define ELSE else       This version of for..next works as long as the increment is 1 and the variable type is double. #define FOR {double __c,__e;double *__p;__p=& #define FROM ;*__p= #define TO ;__c=*__p;__e= #define BEGIN ;for(;__c<=__e;__c+=1.0,*__p=__c){ #define END }}    */




From the Mandelbrot Set Glossary and Encyclopedia, by Robert Munafo, (c) 1987-2024.

Mu-ency main pageindexrecent changesDEMZ


Robert Munafo's home pages on AWS    © 1996-2024 Robert P. Munafo.    about    contact
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Details here.

This page was written in the "embarrassingly readable" markup language RHTF, and was last updated on 1999 Aug 17. s.27