home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- * *
- * Copyright (c) 1992, 1993 Ronald Joe Record *
- * *
- * All rights reserved. No part of this program or publication may be *
- * reproduced, transmitted, transcribed, stored in a retrieval system, *
- * or translated into any language or computer language, in any form or *
- * by any means, electronic, mechanical, magnetic, optical, chemical, *
- * biological, or otherwise, without the prior written permission of: *
- * *
- * Ronald Joe Record (408) 458-3718 *
- * 212 Owen St., Santa Cruz, California 95062 USA *
- * *
- *************************************************************************/
-
- #include <stdio.h>
- #include <values.h>
- #include "x.h"
-
- int **histarray;
- int maxhist = 0;
- int minhist = MAXINT;
-
- void
- FreeHist()
- {
- static int i, j;
-
- if (thermometer)
- j = trawidth - THERMWIDTH;
- else
- j = trawidth;
- for (i=0; i<j; i++)
- free(histarray[i]);
- free(histarray);
- maxhist = 0;
- minhist = MAXINT;
- }
-
- void
- FreeCrit()
- {
- if (crit_pts[0])
- free(crit_pts[0]);
- if (crit_pts[1])
- free(crit_pts[1]);
- if (crit_arc[0])
- free(crit_arc[0]);
- if (crit_arc[1])
- free(crit_arc[1]);
- if (n_crit_pts[0])
- free(n_crit_pts[0]);
- if (n_crit_pts[1])
- free(n_crit_pts[1]);
- if (n_crit_arc[0])
- free(n_crit_arc[0]);
- if (n_crit_arc[1])
- free(n_crit_arc[1]);
- }
-
- freemem()
- {
- static int i;
-
- freecoords();
- for (i=0; i<MAXFRAMES; i++) {
- free(indices[i]);
- free(periods[i]);
- free(basins[i]);
- }
- if (histogram)
- FreeHist();
- if (critical)
- FreeCrit();
- }
-
- void
- HistoMem()
- {
- static int i, j, k;
-
- if (thermometer)
- k = trawidth - THERMWIDTH;
- else
- k = trawidth;
- if ((histarray=
- (int **)malloc(sizeof(int)*k))==NULL){
- fprintf(stderr,"Error malloc'ing x histarray array.\n");
- fprintf(stderr,"trawidth=%d\n",k);
- exit(-1);
- }
- for (i=0;i<k;i++)
- if ((histarray[i]=
- (int *)malloc(sizeof(int)*traheight))==NULL){
- fprintf(stderr,"Error malloc'ing x histarray array.\n");
- fprintf(stderr,"traheight=%d\n",traheight);
- exit(-1);
- }
- for (i=0;i<traheight;i++)
- for (j=0;j<k;j++)
- histarray[j][i] = 0;
- }
-
- void
- CritiMem()
- {
- static int k;
-
- if (thermometer)
- k = criwidth - THERMWIDTH;
- else
- k = criwidth;
- if ((crit_pts[0]=
- (double *)malloc(sizeof(double)*k*criheight))==NULL){
- fprintf(stderr,"Error malloc'ing x crit_pts array.\n");
- fprintf(stderr,"criwidth=%d criheight=%d\n",k,criheight);
- exit(-1);
- }
- if ((crit_pts[1]=
- (double *)malloc(sizeof(double)*k*criheight))==NULL){
- fprintf(stderr,"Error malloc'ing y crit_pts array.\n");
- fprintf(stderr,"criwidth=%d criheight=%d\n",k,criheight);
- exit(-1);
- }
- if ((crit_arc[0]=
- (double *)malloc(sizeof(double)*k*criheight))==NULL){
- fprintf(stderr,"Error malloc'ing x crit_arc array.\n");
- fprintf(stderr,"criwidth=%d criheight=%d\n",k,criheight);
- exit(-1);
- }
- if ((crit_arc[1]=
- (double *)malloc(sizeof(double)*k*criheight))==NULL){
- fprintf(stderr,"Error malloc'ing y crit_arc array.\n");
- fprintf(stderr,"criwidth=%d criheight=%d\n",k,criheight);
- exit(-1);
- }
- if ((n_crit_pts[0]=
- (double *)malloc(sizeof(double)*k*criheight))==NULL){
- fprintf(stderr,"Error malloc'ing x n_crit_pts array.\n");
- fprintf(stderr,"criwidth=%d criheight=%d\n",k,criheight);
- exit(-1);
- }
- if ((n_crit_pts[1]=
- (double *)malloc(sizeof(double)*k*criheight))==NULL){
- fprintf(stderr,"Error malloc'ing y n_crit_pts array.\n");
- fprintf(stderr,"criwidth=%d criheight=%d\n",k,criheight);
- exit(-1);
- }
- if ((n_crit_arc[0]=
- (double *)malloc(sizeof(double)*k*criheight))==NULL){
- fprintf(stderr,"Error malloc'ing x n_crit_arc array.\n");
- fprintf(stderr,"criwidth=%d criheight=%d\n",k,criheight);
- exit(-1);
- }
- if ((n_crit_arc[1]=
- (double *)malloc(sizeof(double)*k*criheight))==NULL){
- fprintf(stderr,"Error malloc'ing y n_crit_arc array.\n");
- fprintf(stderr,"criwidth=%d criheight=%d\n",k,criheight);
- exit(-1);
- }
- }
-
- setupmem()
- {
- static int i, j;
-
- if (thermometer)
- j = width - THERMWIDTH;
- else
- j = width;
- for (i=0;i<MAXFRAMES;i++) {
- if((indices[i]=
- (int *)malloc(sizeof(int)*j*height))==NULL){
- fprintf(stderr,"Error malloc'ing indices array.\n");
- fprintf(stderr,"width=%d height=%d\n",j,height);
- exit(-1);
- }
- if((periods[i]=
- (int *)malloc(sizeof(int)*j*height))==NULL){
- fprintf(stderr,"Error malloc'ing periods array.\n");
- fprintf(stderr,"width=%d height=%d\n",j,height);
- exit(-1);
- }
- if((basins[i]=
- (int *)malloc(sizeof(int)*j*height))==NULL){
- fprintf(stderr,"Error malloc'ing basins array.\n");
- fprintf(stderr,"width=%d height=%d\n",j,height);
- exit(-1);
- }
- }
- setupcoords();
- if (histogram)
- HistoMem();
- if (critical)
- CritiMem();
- }
-
- setupcoords()
- {
- static int i;
-
- for (i=0;i<MAXFRAMES;i++) {
- if ((coords[i][0]=
- (double *)malloc(sizeof(double)*dwell))==NULL){
- fprintf(stderr,"Error malloc'ing x coords array.\n");
- fprintf(stderr,"dwell=%d\n",dwell);
- exit(-1);
- }
- if ((coords[i][1]=
- (double *)malloc(sizeof(double)*dwell))==NULL){
- fprintf(stderr,"Error malloc'ing y coords array.\n");
- fprintf(stderr,"dwell=%d\n",dwell);
- exit(-1);
- }
- }
- }
-
- freecoords()
- {
- static int i;
-
- for (i=0; i<MAXFRAMES; i++) {
- free(coords[i][0]);
- free(coords[i][1]);
- }
- }
-