\File{errctl.c},{02:25},{Jan  4 1998}
\L{\LB{\C{}\/* \$Source: \/mit\/bert\/Cvsroot\/Thesis\/src\/exact\/errctl.c,v \$}}
\L{\LB{ *}}
\L{\LB{ * Error control functions}}
\L{\LB{ *\/\CE{}}}
\L{\LB{}}
\L{\LB{\K{\#include} \<stdio.h\>}}
\L{\LB{\K{\#include} \S{}\"errctl.h\"\SE{}}}
\L{\LB{\K{\#include} \S{}\"expect.h\"\SE{}}}
\L{\LB{}}
\L{\LB{\K{static} \K{char} rcsid[] = \S{}\"\$Id: errctl.c,v 1.6 1998\/01\/04 07:25:39 bert Exp \$\"\SE{};}}
\L{\LB{}}
\L{\LB{\C{}\/* Check the edges of a packet for possible overflow.  The squares of}}
\L{\LB{ * absolute values of edge elements must be less than \'limit\'.}}
\L{\LB{ * (Since half the array indices are \"negative\", the \"edges\" are really at}}
\L{\LB{ * +\-(NN\/2), ie in the middle of the array.)}}
\L{\LB{ *\/\CE{}}}
\L{\LB{\K{int} edge\_overflow(\K{complex} data[], \K{unsigned} \K{long} nn, \K{real} limit)}}
\L{\LB{\{}}
\L{\LB{  \K{unsigned} \K{long} i;}}
\L{\LB{  \K{unsigned} \K{long} col = nn\/2;}}
\L{\LB{  \K{unsigned} \K{long} row = nn*nn\/2;}}
\L{\LB{\K{\#ifdef} DEBUG\_MAX\_EDGE}}
\L{\LB{  \K{real} max = 0;}}
\L{\LB{\K{\#endif} \C{}\/* DEBUG\_MAX\_EDGE *\/\CE{}}}
\L{\LB{  }}
\L{\LB{  \K{for} (i=0; i \< nn; i++) \{}}
\L{\LB{\K{\#ifdef} DEBUG\_MAX\_EDGE}}
\L{\LB{    \K{if} (Csqabs(data[row+i]) \> max)}}
\L{\LB{      max = Csqabs(data[row+i]);}}
\L{\LB{    \K{if} (Csqabs(data[col+i*nn]) \> max)}}
\L{\LB{      max = Csqabs(data[col+i*nn]);}}
\L{\LB{\K{\#endif} \C{}\/* DEBUG\_MAX\_EDGE *\/\CE{}}}
\L{\LB{    \K{if} ((Csqabs(data[row+i]) \> limit) \|\| (Csqabs(data[col+i*nn]) \> limit))}}
\L{\LB{      \K{return} 1;}}
\L{\LB{  \}}}
\L{\LB{}}
\L{\LB{\K{\#ifdef} DEBUG\_MAX\_EDGE}}
\L{\LB{  fprintf(stderr, \S{}\"max edge = \%.30g\!n\"\SE{}, sqrt(max));}}
\L{\LB{  \K{if} (max \> limit)}}
\L{\LB{    \K{return} 1;}}
\L{\LB{\K{\#endif} \C{}\/* DEBUG\_MAX\_EDGE *\/\CE{}}}
\L{\LB{  \K{return} 0;}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\C{}\/* Check two packets for discrepancies.}}
\L{\LB{ *\/\CE{}}}
\L{\LB{\K{int} packet\_error(\K{complex} data1[], \K{complex} data2[], \K{unsigned} \K{long} nn,}}
\L{\LB{}\Tab{16}{ \K{real} limit)}}
\L{\LB{\{}}
\L{\LB{  \K{unsigned} \K{long} i;}}
\L{\LB{\K{\#ifdef} DEBUG\_MAX\_DIFF}}
\L{\LB{  \K{real} max = 0;}}
\L{\LB{\K{\#endif} \C{}\/* DEBUG\_MAX\_DIFF *\/\CE{}}}
\L{\LB{}}
\L{\LB{  \K{for} (i=0; i \< nn*nn; i++) \{}}
\L{\LB{\K{\#ifdef} DEBUG\_MAX\_DIFF}}
\L{\LB{    \K{if} (Cabs(data1[i]\-data2[i]) \> max)}}
\L{\LB{      max = Cabs(data1[i]\-data2[i]);}}
\L{\LB{\K{\#endif} \C{}\/* DEBUG\_MAX\_DIFF *\/\CE{}}}
\L{\LB{    \K{if} (Cabs(data1[i]\-data2[i]) \> limit)}}
\L{\LB{      \K{return} 1;}}
\L{\LB{  \}}}
\L{\LB{}}
\L{\LB{\K{\#ifdef} DEBUG\_MAX\_DIFF}}
\L{\LB{  fprintf(stderr, \S{}\"max diff = \%g\!n\"\SE{}, max);}}
\L{\LB{\K{\#endif} \C{}\/* DEBUG\_MAX\_DIFF *\/\CE{}}}
\L{\LB{  \K{return} 0;}}
\L{\LB{\}}}
