#include #include #include #include #include #include "xpplim.h" #include "fftn.h" double evaluate(); double ndrand48(); void mycor(); float *get_data_col(); extern int DCURY,MAXSTOR; extern char uvar_names[MAXODE][12]; typedef struct { int nbins,nbins2,type,col,col2; double xlo,xhi; double ylo,yhi; char cond[80]; } HIST_INFO; int spec_col=1,spec_wid=256,spec_win=0; HIST_INFO hist_inf = {10,10,0,0,0,0,1,0,1,""}; extern int NCON,NSYM,NCON_START,NSYM_START; extern float **storage; extern int storind; int hist_len,four_len; float *my_hist[MAXODE+1]; float *my_four[MAXODE+1]; int HIST_HERE,FOUR_HERE; extern int NEQ,NODE,NMarkov,FIX_VAR; extern char *no_hint[],*info_message; int two_d_hist(int col1,int col2,int ndat,int n1,int n2,double xlo,double xhi,double ylo,double yhi) /* col1,2 are the data you want to histogram ndat - number of points in the data n1,2 number of bins for two data streams xlo,xhi - range of first column ylo,yhi - range of second column val[0] = value of first data val[1] = value of second data val[3] = number of points - which will be normalized by ndat EXAMPLE of binning if xl0 = 0 and xhi=1 and nbin=10 dx=1/10 then bins are [0,1/10), [1/10,2/10), ....,[9/10,1) thus bin j = int ((x-xlo)/dx) bin k = int ((y-ylo)/dy) if j<0 or j>=nxbin then skip etc */ { int i,j,k; double dx,dy,norm; double x,y; dx=(xhi-xlo)/(double) n1; dy=(yhi-ylo)/(double) n2; norm=1./(double)ndat; /* now fill the data with the bin values - take the midpoints of each bin */ for(i=0;i=0)&&(i=0)&&(j=hist_inf.xhi){ err_msg("Low must be less than hi"); return(0); } if(get_col_info(&hist_inf.col2,"Variable 2 ")==0)return; new_int("Number of bins ",&hist_inf.nbins2); new_float("Low ",&hist_inf.ylo); new_float("Hi ",&hist_inf.yhi); if(hist_inf.nbins2<2){ err_msg("At least 2 bins\n"); return(0); } if(hist_inf.ylo>=hist_inf.yhi){ err_msg("Low must be less than hi"); return(0); } length=hist_inf.nbins*hist_inf.nbins2; if(length>=MAXSTOR) length=MAXSTOR-1; if(HIST_HERE){ data_back(); free(my_hist[0]); free(my_hist[1]); if(HIST_HERE==2) free(my_hist[2]); HIST_HERE=0; } hist_len=length; my_hist[0]=(float *)malloc(sizeof(float)*length); my_hist[1]=(float *)malloc(sizeof(float)*length); my_hist[2]=(float *)malloc(sizeof(float)*length); if(my_hist[2]==NULL){ free(my_hist[0]); free(my_hist[1]); err_msg("Cannot allocate enough..."); return; } HIST_HERE=2; for(i=3;i<=NEQ;i++)my_hist[i]=storage[i]; hist_len=length; two_d_hist(hist_inf.col,hist_inf.col2,storind, hist_inf.nbins,hist_inf.nbins2, hist_inf.xlo,hist_inf.xhi,hist_inf.ylo,hist_inf.yhi); hist_back(); ping(); } new_hist(nbins,zlo,zhi,col,col2,condition,which) int nbins; int col,col2,which; double zlo,zhi; char *condition; { int i,j,n=2,index; int command[256]; int cond=0,flag=1; double z,y; double dz; int length=nbins+1; int count=0; if(length>=MAXSTOR) length=MAXSTOR-1; dz=(zhi-zlo)/(double)(length-1); if(HIST_HERE){ data_back(); free(my_hist[0]); free(my_hist[1]); if(HIST_HERE==2) free(my_hist[2]); HIST_HERE=0; } hist_len=length; my_hist[0]=(float *)malloc(sizeof(float)*length); my_hist[1]=(float *)malloc(sizeof(float)*length); if(my_hist[1]==NULL){ free(my_hist[0]); err_msg("Cannot allocate enough..."); return; } HIST_HERE=1; for(i=2;i<=NEQ;i++)my_hist[i]=storage[i]; for(i=0;i0.0)flag=1; else flag=0; } z=(storage[col][i]-zlo)/dz; index=(int)z; if(index>=0&&index=0&&index=0)&&(k0) sum=sum/count; z[j]=sum; } } compute_hist() { new_int("Number of bins ",&hist_inf.nbins); new_float("Low ",&hist_inf.xlo); new_float("Hi ",&hist_inf.xhi); if(get_col_info(&hist_inf.col,"Variable ")==0)return; new_string("Condition ",hist_inf.cond); new_hist(hist_inf.nbins,hist_inf.xlo, hist_inf.xhi,hist_inf.col,0,hist_inf.cond,0); } sft(data,ct,st,nmodes,grid) int grid,nmodes; float *data,*ct,*st; { int i,j; double sums,sumc; double tpi=6.28318530717959; double dx,xi,x; dx=tpi/(grid); for(j=0;j