/*ptrcer show continuum pointers in real time following drive pointers command */ #include "cddefines.h" #include "rfield.h" #include "fillnu.h" #include "ipoint.h" #include "ffmtread.h" #include "ptrcer.h" void ptrcer(void) { char chCard[81]; /* in case of checking everything, will write errors to this file */ FILE * ioERRORS=NULL; int lgEOL; char chKey; long int i, ipnt, j; double pnt, t1, t2; # ifdef DEBUG_FUN fputs( "<+>ptrcer()\n", debug_fp ); # endif fprintf( ioQQQ, " There are two ways to do this:\n"); fprintf( ioQQQ, " do you want me to test all the pointers (enter y)\n"); fprintf( ioQQQ, " or do you want to enter energies yourself? (enter n)\n" ); if( fgets( chCard , sizeof(chCard) , stdin ) == NULL ) { fprintf( ioQQQ, " error getting input \n" ); puts( "[Stop in ptrcer]" ); exit(1); } /* this must be either y or n */ chKey = chCard[0]; if( chKey == 'n' ) { /* this branck, enter energies by hand, and see what happens */ fprintf( ioQQQ, " Enter energy (Ryd); 0 to stop; negative is log.\n" ); pnt = 1.; while( pnt!=0. ) { if( fgets( chCard , sizeof(chCard) , stdin ) == NULL ) { fprintf( ioQQQ, " error getting input2 \n" ); puts( "[Stop in ptrcer]" ); exit(1); } /* now get the number off the line */ i = 1; pnt = FFmtRead(chCard,&i,76,&lgEOL); /* bail if no number at all, or it is zero*/ if( lgEOL || pnt==0. ) { break; } /* if number negative then interpret as log */ if( pnt < 0. ) { pnt = pow(10.,pnt); } /* get pointer to call */ ipnt = ipoint(pnt); fprintf( ioQQQ, " Cell num%4ld center:%10.2e width:%10.2e low:%10.2e hi:%10.2e convoc:%10.2e\n", ipnt, rfield.anu[ipnt-1], rfield.widflx[ipnt-1], rfield.anu[ipnt-1] - rfield.widflx[ipnt-1]/2., rfield.anu[ipnt-1] + rfield.widflx[ipnt-1]/2., rfield.convoc[ipnt-1] ); } } else if( chKey == 'y' ) { /* first check that ipoint will not crash due to out of range call*/ if( rfield.anu[0] - rfield.widflx[0]/2.*0.9 < fillnu.filbnd[0] ) { fprintf( ioQQQ," ipoint would crash since lowest desired energy of %e ryd is below limit of %e\n", rfield.anu[0] - rfield.widflx[0]/2.*0.9 , fillnu.filbnd[0] ); fprintf( ioQQQ," width of cell is %e\n",rfield.widflx[0]); puts( "[Stop in ptrcer]" ); exit(1); } else if( rfield.anu[rfield.nflux-1] + rfield.widflx[rfield.nflux-1]/2.*0.9 > fillnu.filbnd[fillnu.nrange] ) { fprintf( ioQQQ," ipoint would crash since highest desired energy of %e ryd is above limit of %e\n", rfield.anu[rfield.nflux-1] + rfield.widflx[rfield.nflux-1]/2.*0.9 , fillnu.filbnd[fillnu.nrange=1] ); fprintf( ioQQQ," width of cell is %e\n",rfield.widflx[rfield.nflux]); fprintf( ioQQQ," this, previous cells are %e %e\n", rfield.anu[rfield.nflux-1],rfield.anu[rfield.nflux-2]); puts( "[Stop in ptrcer]" ); exit(1); } /* this branch check everything, write errors to error file */ fprintf( ioQQQ, " errors output on errors.txt\n"); fprintf( ioQQQ, " IP(cor),IP(fount),nu lower, upper of found, desired cell.\n" ); /* error file not open, set to null so we can check later */ ioERRORS = NULL; for( i=0; i < rfield.nflux-1; i++ ) { t1 = rfield.anu[i] - rfield.widflx[i]/2.*0.9; t2 = rfield.anu[i] + rfield.widflx[i]/2.*0.9; j = ipoint(t1); if( j != i+1 ) { /* open file for errors if not already open */ if( ioERRORS == NULL ) { ioERRORS = fopen("errors.txt" , "w" ); if( ioERRORS==NULL ) { fprintf( ioQQQ," could not create1 errors.txt file\n"); puts( "[Stop in ptrcer]" ); exit(1); } else { fprintf( ioQQQ," created errors.txt file with error summary\n"); } } fprintf( ioQQQ, " Pointers do not agree for lower bound of cell%4ld, %e\n", i, rfield.anu[i]); fprintf( ioERRORS, " Pointers do not agree for lower bound of cell%4ld, %e\n", i, rfield.anu[i] ); } j = ipoint(t2); if( j != i+1 ) { /* open file for errors if not already open */ if( ioERRORS == NULL ) { ioERRORS = fopen("errors.txt" , "w" ); if( ioERRORS==NULL ) { fprintf( ioQQQ," could not create2 errors.txt file\n"); puts( "[Stop in ptrcer]" ); exit(1); } else { fprintf( ioQQQ," created errors.txt file with error summary\n"); } } fprintf( ioQQQ, " Pointers do not agree for upper bound of cell%4ld, %e\n", i , rfield.anu[i]); fprintf( ioERRORS, " Pointers do not agree for upper bound of cell%4ld, %e\n", i , rfield.anu[i]); } } } else { fprintf( ioQQQ, " This key is not understood, sorry. %c\n", chKey ); puts( "[Stop in ptrcer]" ); exit(1); } if( ioERRORS!=NULL ) fclose( ioERRORS ); puts( "[Stop in ptrcer]" ); exit(1); }