#include #include /* this has a bunch of numerical routines averaging adjoints transpose maximal liapunov exponent */ #include #include #include "xpplim.h" #define MAX_LEN_SBOX 25 #define READEM 1 double evaluate(); double ndrand48(); extern double MyData[MAXODE]; int (*rhs)(); extern float **storage; extern int storind,FOUR_HERE; extern int NODE,INFLAG,NEQ,NJMP,FIX_VAR,NMarkov,nvec; extern char uvar_names[MAXODE][12]; float **my_adj; int adj_len; float **my_h; float *my_liap[2]; extern char *info_message; struct { int here,col0,ncol,colskip; int row0,nrow,rowskip; float **data; char firstcol[11]; } my_trans; int TRANPOSE_HERE=0; int LIAP_FLAG=0; int LIAP_N,LIAP_I; extern double NEWT_ERR; double ADJ_EPS=1.e-8,ADJ_ERR=1.e-3; int ADJ_MAXIT=20,ADJ_HERE=0,H_HERE=0,h_len,HODD_EV=0; extern double DELTA_T,BOUND; int *coup_fun[MAXODE]; char *coup_string[MAXODE]; extern int *my_ode[]; extern int NSYM,NSYM_START,NCON,NCON_START; /* extern Window main_win; */ extern int DCURY; init_trans() { my_trans.here=0; strcpy(my_trans.firstcol,uvar_names[0]); my_trans.ncol=2; my_trans.nrow=1; my_trans.rowskip=1; my_trans.colskip=1; my_trans.row0=1; my_trans.col0=2; } dump_transpose_info(fp,f) FILE *fp; int f; { char bob[256]; if(f==READEM) fgets(bob,255,fp); else fprintf(fp,"# Transpose variables etc\n"); io_string(my_trans.firstcol,11,fp,f); io_int(&my_trans.ncol,fp,f,"n columns"); io_int(&my_trans.nrow,fp,f,"n rows"); io_int(&my_trans.rowskip,fp,f,"row skip"); io_int(&my_trans.colskip,fp,f,"col skip"); io_int(&my_trans.row0,fp,f,"row 0"); } do_transpose() { int i,status; static char *n[]={"*0Column 1","NCols","ColSkip","Row 1","NRows","RowSkip"}; char values[6][MAX_LEN_SBOX]; sprintf(values[0],"%s",my_trans.firstcol); sprintf(values[1],"%d",my_trans.ncol); sprintf(values[2],"%d",my_trans.colskip); sprintf(values[3],"%d",my_trans.row0); sprintf(values[4],"%d",my_trans.nrow); sprintf(values[5],"%d",my_trans.rowskip); if(my_trans.here){ for(i=0;i<=my_trans.nrow;i++)free(my_trans.data[i]); free(my_trans.data); my_trans.here=0; data_back(); } status=do_string_box(6,6,1,"Transpose Data",n,values,33); if(status!=0){ find_variable(values[0],&i); if(i>-1) my_trans.col0=i+1; else { err_msg("No such columns"); return 0; } strcpy(my_trans.firstcol,values[0]); i=atoi(values[4]); if(i>=NEQ)i=NEQ-1; my_trans.nrow=i; my_trans.ncol=atoi(values[1]); my_trans.colskip=atoi(values[2]); my_trans.row0=atoi(values[3]); my_trans.rowskip=atoi(values[5]); return (create_transpose()); } return 0; } create_transpose() { int i,j; int inrow,incol; my_trans.data=(float **)malloc(sizeof(float *)*(NEQ+1)); for(i=0;i<=my_trans.nrow;i++) my_trans.data[i]=(float *)malloc(sizeof(float)*my_trans.ncol); for(i=my_trans.nrow+1;i<=NEQ;i++)my_trans.data[i]=storage[i]; for(j=0;jNEQ) incol=NEQ; for(j=0;jstorind) inrow=storind; my_trans.data[j+1][i]=storage[incol][inrow]; } } set_browser_data(my_trans.data,1); /* my_browser.data=my_trans.data; my_browser.col0=1; */ refresh_browser(my_trans.ncol); my_trans.here=1; return 1; } alloc_h_stuff() { int i; for(i=0;i2){ HODD_EV=1; n=4; } h_len=storind; data_back(); my_h=(float **)malloc(sizeof(float*)*(NEQ+1)); for(i=0;i=nt)k2=k2-nt+1; for(i=0;i=nt)k2=k2-nt; if(step_eul(jac,k,k2,yold,work,node,dt)==0){ rval=0; goto bye; } /* rk_interp(jac,k,k2,yold,work,node,dt,5); */ } ytemp=0.0; error=0.0; for(i=0;iBOUND){ rval=0; err_msg("Out of bounds"); goto bye; } error+=fabs(yold[i]-fdev[i]); ytemp+=fabs(yold[i]); } for(i=0;i=nt)k2-=nt; if(step_eul(jac,k,k2,yold,work,node,dt)==0){ rval=0; goto bye; } /* rk_interp(jac,k,k2,yold,work,node,dt,5); */ } prod=prod/t; printf(" Multiplying the adjoint by 1/%g to normalize\n",prod); for(k=0;k0) for(i=0;i