Category : C Source Code
Archive   : DYNAM_S1.ZIP
Filename : Y.C

 
Output of file : Y.C contained in archive : DYNAM_S1.ZIP
/******************* (C) 1986,7,8 by JAMES A. YORKE **************************/
/*********************************** Y.C ***********************************/

/* The program DYNAMICS.C is for plotting various maps on the screen(crt)
and printing contents of p[][] on printer in a highly interactive manner.
To compile it, Y.C must be compiled and linked to several other files;
the list of files to be linked is in file YS;
James Yorke
10/11/87
******************************* Routines in Y.C *****************************
main(argc, argv)
Trajectory()
plotSomething()
plotXX(),plotXY(),plotRY(),plotXR(),plotAll()
caseT()
circleImage(action,ddot)
checkFreq()
setTDTime() called using command "TDTime"
setRunTime() called using command "runtime"
initTime()
printTimes(fff) for DumpData() runtime and tdtime -- see YDISK.C
******************************************************************************/

/* Define all external symbols here. */
#define INITIAL(x) = x
#define EXTERN
#include "yinclud.h"

char DiskFileName[20]; /* for saving pictures on disk */

main(argc, argv)
int argc;
char *argv[];
{
char CodeName[MAXCHAR+1];

OpenFiles(argc, argv); /* in YFetch.c, opens files, displays title
page, sets video mode */

for(;;) {
PickMap(); /* in YPICKMAP.C */

select_items(CodeName);/* in YCOM.C */
}
}
/* the following are in ydefines.h:
#define PLOTXY 0
#define PLOTALL 2
#define PLOTXX 4
#define PLOTRY 6
#define PLOTXR 8
#define PLOTCIRC 100 */

extern long bifPreIterates; /* declared in ybifrcat.c */
static double Old; /* for plotXX() */
long initialdot;
static double delrho;
static long modulo; /* for plotXR and plotRY */
static long dotMOD;
static int numRhos;


Trajectory() { /* process for iterating; refreshFlag is set
using the command "cont"; when = YES, dot
does not have to start from 0 */
#ifndef MAINFRAME
int ChkKeyStatus();
#endif
int level0 = level;
int i;
int checkFreq();
int null(); /* needed for pointer that is not being used */
long savedots = dots;
int minimum = ((eqn1 < dim) ? eqn1 : dim);

scr_rowcol(0, 0);
if(TDFreq > 0)
PRINT
"WARNING: picture is stored to disk every %ld iterates.\n", TDFreq);

if(dot > 0 && dot < dots && refreshFlag == YES)
/* dot >0 is most likely to occur when using
command "cont" */
;
else {
dot = -preiter;
}
dotAtTime0 = dot;
initialdot = dot;

refreshFlag = NO;
stoplines(); /* stop drawing connected lines */
if(taskFlag < 100) { /* it can be set >= 100 for special tasks like
drawing circles */
if(X_coord >= 0 && Y_coord >= 0) {
if(X_coord != Y_coord) {
if(allSSFlag == NO)
taskFlag = PLOTXY;
else
taskFlag = PLOTALL;
}
else
if(X_coord == Y_coord)
taskFlag = PLOTXX;
}
else
if(X_coord == -1) {
taskFlag = PLOTRY;
numRhos = corecols;
setdots(numRhos);
/* defines dots; in YBIFRCAT.C */
modulo = dots / numRhos;
/* = the number of dots per rho value */
delrho = (X_upper - X_lower) / numRhos;
}
else
if(Y_coord == -1) {
taskFlag = PLOTXR;
numRhos = corerows * 8;
setdots(numRhos);
/* defines dots; in YBIFRCAT.C */
modulo = dots / numRhos;
/* = the number of dots per rho value */
delrho = (Y_upper - Y_lower) / numRhos;
}
}

#ifndef MAINFRAME
if(ChkKeyStatus() != 0 || cycle > 0)
Interrupt();
#endif
initTime(); /* see below */
for(; level == level0 && dot < dots; dot++) {
if(timeFlag == YES || TDFreq > 0)
if(checkFreq() == YES)
{ /* means terminate; checkFreq also handles
occasional transmissions of picture to disk
*/
PRINT "process termination: OUT OF TIME \n");
level = level0 - 1;
continue;
}

#ifndef MAINFRAME
if(ChkKeyStatus () != 0 || cycle > 0)
Interrupt();
#endif
/*if(printer == 3)PRINT "taskFlag = %d\n",taskFlag);*/

if(taskFlag == PLOTXY) {
plotX = *Xplot[ScrnSec];
plotY = *Yplot[ScrnSec];
if(dot >= 0)
(*plotPointer) (plotX, plotY);
(*iteratee) ();
}
else
plotSomething(1);

if(printer >= 4)
if((printer == 4) || (printer == 5)) {
/* print trajectory values every iterate if ==
5 */
fprintf(StPrint, "#%ld ", dot);
for(i = 0; i < minimum; i++)
fprintf(StPrint, "y[%d]=%lf ", i, y[i]);
fprintf(StPrint, "\n");
if(printer == 4)
printer = 2;
}
} /* end for(;... */
dots = savedots; /* restore value in case it has been changed */
if(level <= 2)
scr_clr(); /* in desmets pcio.a */
scr_rowcol(0, 0);
}


plotSomething(action) /* action = 0 means do not iterate process,
just plot */
int action;
{
switch(taskFlag) {
case PLOTXY:
plotXY(action);
break;
case PLOTALL:
plotALL(action);
break;
case PLOTXX:
plotXX(action);
break;
case PLOTRY:
plotRY(action);
break;
case PLOTXR:
plotXR(action);
break;
case PLOTCIRC:
circleImage(action, (double) dot);
break;
}
return;
}

plotXX(action) /* Old is a static double */
int action;
{
plotX = Old;
plotY = y[X_coord];
if(dot >= 1)
(*plotPointer) (plotX, plotY);
Old = y[X_coord];
if(action > 0)
(*iteratee) ();
}

plotXY(action)
int action;
{
plotX = *Xplot[ScrnSec];
plotY = *Yplot[ScrnSec];
if(dot >= 0)
(*plotPointer) (plotX, plotY);
if(action > 0)
(*iteratee) ();
}

circleImage(action, ddot)
int action;
double ddot;
{
int i;
double rot;
int levelc = level;

rot = ddot * twopi * (sqrt(5.) - 3.) / 2;
setequal(0, 1, eqn1); /* initialize y */
plotX = *Xplot[ScrnSec] += rad_attr * cos(rot);
plotY = *Yplot[ScrnSec] += rad_attr * sin(rot);
(*plotPointer) (plotX, plotY);
for(i = 0; i < images && levelc == level; i++) {
if(action > 0)
(*iteratee) ();
plotX = *Xplot[ScrnSec];
plotY = *Yplot[ScrnSec];
(*plotPointer) (plotX, plotY);
}
}

plotALL(action) /* cannot use 'k' to plot crosses in every
screen */
int action;
{
int ss;

turnoff(BIGCROSS);
cross0flag = OFF;
for(ss = 1; ss < 5; ss++)
if(xScrPix[ss] != -9999.) {
X_lower = X_Lo[ss];/* used by plot() */
X_upper = X_Up[ss];
Y_upper = Y_Up[ss];
Y_lower = Y_Lo[ss];
ScrnSec = ss;
plotX = *Xplot[ss];
plotY = *Yplot[ss];
(*plotPointer) (plotX, plotY);
}
if(action > 0)
(*iteratee) ();
}

plotXR(action)
int action;
{
/* We are going to compute for numRhos different values of rho; if InitFlag=ON
we initialize at the beginning of eah rho; notice modulo = dots/numRhos is
a(long) integer, the number of potential dots for each rho; we increment
rho by 1/numRhos of the X_range or y range every modulo dots; if preiter is
positive, the the first preiter(out of modulo potential dots) will not be
plotted; we do this by computing dotMOD = dot mod modulo. */

dotMOD = dot % modulo; /* =dot MOD modulo(integer mod) */
if(dotMOD == 0) {
if(InitFlag == ON)
setequal(0, 1, dim);/* initialize y */
rho = rho + delrho;
if(printer > 2) {
erase_line();
PRINT "dot=%ld;rho=%lf; rho value # %ld \r"
,dot, rho, dot / modulo);
}
}
else {
if(dotMOD >= bifPreIterates) {
/* this means we preiterate for each new rho
before plotting */
plotX = *Xplot[ScrnSec];
plotY = *Yplot[ScrnSec];
(*plotPointer) (plotX, plotY);
}
}
if(action > 0)
(*iteratee) ();
}

plotRY(action)
int action;
{
/* We are going to compute for numRhos different values of rho; if InitFlag=ON
we initialize at the beginning of eah rho; notice modulo = dots/numRhos is
a(long) integer, the number of potential dots for each rho; we increment
rho by 1/numRhos of the X_range or y range every modulo dots; if preiter is
positive, the the first preiter(out of modulo potential dots) will not be
plotted; we do this by computing dotMOD = dot mod modulo. */

dotMOD = dot % modulo; /* =dot MOD modulo(integer mod) */
if(dotMOD == 0) {
if(InitFlag == ON)
setequal(0, 1, dim);/* initialize y */
rho = rho + delrho;
if(printer > 2) {
erase_line();
PRINT "dot=%ld;rho=%lf; rho value # %ld \r"
,dot, rho, dot / modulo);
}
}
else {
if(dotMOD >= bifPreIterates) {
/* this means we preiterate for each new rho
before plotting */
plotX = *Xplot[ScrnSec];
plotY = *Yplot[ScrnSec];
if(dot >= 0)
(*plotPointer) (plotX, plotY);
}
}
if(action > 0)
(*iteratee) ();
}


caseT() { /* This routine does some house keeping before
and after calling trajectory(); these two
routines go together; call this one and it
calls trajectory() */
int level1;

max_error = 0;

(*init_process) (); /* this is determined in select_map in Ymaps
and possibly elsewhere. It is used to make
calculations that have to be made only at
the beginning of an iterative process. The
calculations might depend on constants like
C1 but not on rho(or y[]) because rho can
be changed while the map is being iterated.
Most often it is null(). */

if(preiter > 0 && refreshFlag == NO)
setequal(0, 1, dim);
if(X_coord == -1)
rho = X_lower +.0000000001 * (X_upper - X_lower);
if(Y_coord == -1)
rho = Y_lower +.0000000001 * (Y_upper - Y_lower);

level1 = ++level;
for(rho_begin = rho;
fabs(rho_begin - rho) *.9999999999 <= fabs (rho_begin - rho_final)
&& (level == level1); rho = rho + rho_step) {
/* fabs() = absolute value of a double
precision real */
if(level == PROCESS)
boot_crt();/* prepares the screen for graphics */



/* ** Beginning of routine for plotting attractor ** */
/* ** level == KILL will terminate program ** */

Trajectory();
#ifndef X11
if(onprint >= 1 && dot >= dots) {
pprint(onprint);
/* this sends picture to B: disk if disk = 1 */
}
#endif
} /* rho_step end */
rho = rho - rho_step; /* don't increment if rho would be too large */

level = level1 - 1;
if(SCREEN)
if(level == 2)
MainMenu();
}

int checkFreq() /* checks TDFREQ returns YES if current process
should be stopped; time0 & lastTDTime are
initiallized in initTime() which is called
in Trajectory(); TDFreq, timeFlag, and
TDTime are set to 0 when the screen is
cleared */
{
double timeofday();

if(TDFreq > 0) { /* if TDFreq != 0, td() to be called regularly
*/
if(dot % TDFreq == 0) {
if(dot > initialdot && dot > 0) {
checkTimeAndPrint();
} /* if dot > ... */
} /* if dot % ... */
} /* end if(TDFreq... */

if(timeFlag == YES) { /* this means the timer is running for either
termination of sending to disk or both; */
time1 = timeofday();
if(time1 < time0)/* can happen after passing midnight */
lastTDTime = time0 = time1;
if(TDTime > 0) {
if(time1 > time0 + TDTime
&& time1 > lastTDTime + TDTime) {
lastTDTime = time1;
td();/* = To DIsk in YPLOT */
}
}
if(runTime > 0)
if(time1 > time0 + runTime) {
time0 = timeofday();
/* this is reset so that lower level processes
will also have the same amount of time */
return(YES);
}
}
return(NO);
}

checkTimeAndPrint()
{
double timeofday();
time1 = timeofday();
/* don't send picture to disk if less than 100
seconds has elapsed since last setting time0
*/

if(time1 < time0) {
time0 = time1;
return;
}
if(time1 - time0 < 100.) {
scr_rowcol(10, 0);
PRINT
" ******* ALERT **** \n");
PRINT
"WARNING: Program is set to send picture to disk in less than 100 seconds.\n");
PRINT
" ***** use TDFREQ to set frequency, or risk destoying existing picture ****\n"
);

}
else {
td(); /* to disk in YPLOT.C */
}
}

setTDTime() { /* called using command "TDTime" */
double minval;

timeFlag = YES;
if(SCREEN)
PRINT "Enter a time in minutes >= 0 \n");
minval = TDTime / 60.;
minval = Entervalue(minval, CHECKSET);
if(minval >= 0)
TDTime = 60.* minval;
if(TDTime == 0 && runTime == 0)
timeFlag = NO;
}
setRunTime() { /* called using command "runtime" */
double minval;

timeFlag = YES;
if(SCREEN)
PRINT "Enter a time in minutes >= 0 \n");
minval = runTime / 60.;
minval = Entervalue(minval, CHECKSET);
if(minval >= 0)
runTime = 60.* minval;
if(TDTime == 0 && runTime == 0)
timeFlag = NO;
}

initTime() { /* records time for later comparison */

lastTDTime = time0 = timeofday();
}

printTimes(fff) /* for DumpData() runtime and tdtime -- see
YDISK.C; This is handled here because the
required variables are static, so they are
not accessible from YDISK */
FILE * fff;
{

if(TDTime > 0)
fprintf(fff,
"TDTIME %lf /* frequency in minutes for sending picture to disk */\n",
TDTime / 60.);/* TDTime is in seconds */
if(runTime > 0)
fprintf(fff,
"RUNTIME %lf /* frequency in minutes for sending picture to disk */\n",
runTime / 60.);/* runTime is in seconds */
}



  3 Responses to “Category : C Source Code
Archive   : DYNAM_S1.ZIP
Filename : Y.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/