\File{propagate.c},{10:59},{Jan  5 1998}
\L{\LB{\C{}\/* \$Source: \/mit\/bert\/Cvsroot\/Thesis\/src\/exact\/propagate.c,v \$}}
\L{\LB{ *}}
\L{\LB{ * propagate a 2\-dimensional wave packet}}
\L{\LB{ *\/\CE{}}}
\L{\LB{}}
\L{\LB{\K{\#include} \<stdio.h\>}}
\L{\LB{\K{\#include} \<stdlib.h\>}}
\L{\LB{\K{\#include} \<string.h\>}}
\L{\LB{\K{\#include} \<errno.h\>}}
\L{\LB{\K{\#include} \S{}\"complex.h\"\SE{}}}
\L{\LB{\K{\#include} \S{}\"fft.h\"\SE{}}}
\L{\LB{\K{\#include} \S{}\"errctl.h\"\SE{}}}
\L{\LB{\K{\#include} \S{}\"util.h\"\SE{}}}
\L{\LB{}}
\L{\LB{\K{\#ifdef} HAVE\_PROF\_H}}
\L{\LB{\K{\#include} \<prof.h\>}}
\L{\LB{\K{\#else}}}
\L{\LB{\K{\#define} MARK(a)}}
\L{\LB{\K{\#endif}}}
\L{\LB{}}
\L{\LB{\K{static} \K{char} rcsid[] = \S{}\"\$Id: propagate.c,v 1.12 1998\/01\/05 15:59:00 bert Exp \$\"\SE{};}}
\L{\LB{}}
\L{\LB{\K{\#define} DUMPDIR \S{}\"\/var\/tmp\/\"\SE{}}}
\L{\LB{\K{\#define} ERROR\_LIMIT 1e\-6}}
\L{\LB{}}
\L{\LB{\C{}\/** ugly macros for tracking execution progress **\/\CE{}}}
\L{\LB{}}
\L{\LB{\C{}\/* \#define TRACK(fd, foo...)  fprintf(fd, \#\# foo); fflush(fd) *\/\CE{}}}
\L{\LB{}}
\L{\LB{\C{}\/***** code *****\/\CE{}}}
\L{\LB{}}
\L{\LB{\C{}\/* oops!  calculation just blew up.  complain, write data out, exit.}}
\L{\LB{ *   data \-\-                 packet.}}
\L{\LB{ *   size \-\-                 size for packet and propagators.}}
\L{\LB{ *   description \-\-          a short description, such as \"position\".}}
\L{\LB{ *   file \-\-                 filename to write \|packet\| to.}}
\L{\LB{ *   fft\_dir \-\-              direction of FFT to apply}}
\L{\LB{ *   fft\_file \-\-             filename to write \| FFT(packet) \| to.}}
\L{\LB{ *\/\CE{}}}
\L{\LB{\K{void} die(\K{complex} *data, \K{unsigned} \K{long} size,}}
\L{\LB{}\Tab{8}{ \K{char} *description, \K{unsigned} \K{long} iter,}}
\L{\LB{}\Tab{8}{ \K{char} *file, \K{int} fft\_dir, \K{char} *fft\_file)}}
\L{\LB{\{}}
\L{\LB{  fprintf(stderr, \S{}\"need bigger grid!  [\%s, iter=\%ld]\!n\"\SE{}, description, iter);}}
\L{\LB{  dump\_absolute(data, size, file);}}
\L{\LB{  fprintf(stderr, \S{}\"absolute values written to \%s\!n\"\SE{}, file);}}
\L{\LB{  \K{if} (fft\_dir \> 0)}}
\L{\LB{    positive\_fft2(data, size);}}
\L{\LB{  \K{else}}}
\L{\LB{    negative\_fft2(data, size);}}
\L{\LB{  dump\_absolute(data, size, fft\_file);}}
\L{\LB{  fprintf(stderr, \S{}\"FFT written to \%s\!n\"\SE{}, fft\_file);}}
\L{\LB{  exit(10);}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\C{}\/* convenient suicide macros for position and momentum space data *\/\CE{}}}
\L{\LB{\K{\#define} die\_r(data,size,desc,i) \!}}
\L{\LB{\Proc{die}   die(data,size,desc,i, DUMPDIR \S{}\"overflow.r\"\SE{}, \-1, DUMPDIR \S{}\"overflow.r2k\"\SE{})}}
\L{\LB{\K{\#define} die\_k(data,size,desc,i) \!}}
\L{\LB{\Proc{die}   die(data,size,desc,i, DUMPDIR \S{}\"overflow.k\"\SE{}, +1, DUMPDIR \S{}\"overflow.k2r\"\SE{})}}
\L{\LB{}}
\L{\LB{\C{}\/* time\-propagates a packet, using given parameters.}}
\L{\LB{ *   data \-\-                 packet.}}
\L{\LB{ *   propV2, propV, propK \-\- propagator coefficient matrices.}}
\L{\LB{ *   size \-\-                 size for packet and propagators.}}
\L{\LB{ *   niter \-\-                number of iterations.}}
\L{\LB{ *   offset \-\-               \"offset\" for iteration numbering.}}
\L{\LB{ *\/\CE{}}}
\L{\LB{\K{void} propagate (\K{complex} *data, \K{complex} *propV2, \K{complex} *propV, \K{complex} *propK,}}
\L{\LB{}\Tab{16}{\K{unsigned} \K{long} size, \K{unsigned} \K{long} niter, \K{unsigned} \K{long} offset)}}
\L{\LB{\{}}
\L{\LB{  \K{unsigned} \K{long} i,j;}}
\L{\LB{}}
\L{\LB{  \C{}\/*** start by applying  exp(V\/2) ***\/\CE{}}}
\L{\LB{}}
\L{\LB{  \K{for} (j=0; j\< (size*size); j++) \{}}
\L{\LB{    data[j] *= propV2[j];}}
\L{\LB{  \}}}
\L{\LB{}}
\L{\LB{  \C{}\/*** iterate doing exp(K)exp(V) ***\/\CE{}}}
\L{\LB{}}
\L{\LB{  \K{for} (i = 1; i \< niter; i++) \{}}
\L{\LB{    \C{}\/* TRACK(stdout,\"[\%ld\", i+offset); *\/\CE{}}}
\L{\LB{    negative\_fft2(data, size);}}
\L{\LB{    \C{}\/* TRACK(stdout,\"p\"); *\/\CE{}}}
\L{\LB{}}
\L{\LB{    \C{}\/* apply exp(K) *\/\CE{}}}
\L{\LB{    \K{for} (j=0; j\<(size*size); j++) \{}}
\L{\LB{      data[j] *= propK[j]\/size;}}
\L{\LB{    \}}}
\L{\LB{}}
\L{\LB{\K{\#ifdef} EDGE\_OVERFLOW}}
\L{\LB{    \K{if} (edge\_overflow(data, size, ERROR\_LIMIT)) \{}}
\L{\LB{      die\_k(data, size, \S{}\"momentum\"\SE{}, i+offset);}}
\L{\LB{    \}}}
\L{\LB{\K{\#endif}}}
\L{\LB{}}
\L{\LB{    \C{}\/* TRACK(stdout,\"K\"); *\/\CE{}}}
\L{\LB{    positive\_fft2(data, size);}}
\L{\LB{    \C{}\/* TRACK(stdout,\"s\"); *\/\CE{}}}
\L{\LB{}}
\L{\LB{    \C{}\/* apply exp(V) *\/\CE{}}}
\L{\LB{    \K{for} (j=0; j\<(size*size); j++) \{}}
\L{\LB{      data[j] *= propV[j]\/size;}}
\L{\LB{    \}}}
\L{\LB{    \C{}\/* TRACK(stdout,\"V] \"); *\/\CE{}}}
\L{\LB{}}
\L{\LB{\K{\#ifdef} EDGE\_OVERFLOW}}
\L{\LB{    \K{if} (edge\_overflow(data, size, ERROR\_LIMIT)) \{}}
\L{\LB{      die\_r(data, size, \S{}\"position\"\SE{}, i+offset);}}
\L{\LB{    \} }}
\L{\LB{\K{\#endif}}}
\L{\LB{  \}}}
\L{\LB{}}
\L{\LB{  \C{}\/*** final exp(K)exp(V\/2) ***\/\CE{}}}
\L{\LB{}}
\L{\LB{  \C{}\/* TRACK(stdout,\"[\%ld\", i+offset); *\/\CE{}}}
\L{\LB{  negative\_fft2(data, size);}}
\L{\LB{  \C{}\/* TRACK(stdout,\"p\"); *\/\CE{}}}
\L{\LB{}}
\L{\LB{  \C{}\/* apply exp(K) *\/\CE{}}}
\L{\LB{  \K{for} (j=0; j\<(size*size); j++) \{}}
\L{\LB{    data[j] *= propK[j]\/size;}}
\L{\LB{  \}}}
\L{\LB{}}
\L{\LB{\K{\#ifdef} EDGE\_OVERFLOW}}
\L{\LB{  \K{if} (edge\_overflow(data, size, ERROR\_LIMIT)) \{}}
\L{\LB{    die\_k(data, size, \S{}\"momentum:last\"\SE{}, i+offset);}}
\L{\LB{  \}}}
\L{\LB{\K{\#endif}}}
\L{\LB{}}
\L{\LB{  \C{}\/* TRACK(stdout,\"K\"); *\/\CE{}}}
\L{\LB{  positive\_fft2(data, size);}}
\L{\LB{  \C{}\/* TRACK(stdout,\"s\"); *\/\CE{}}}
\L{\LB{}}
\L{\LB{  \C{}\/* apply exp(V\/2) *\/\CE{}}}
\L{\LB{  \K{for} (j=0; j\<(size*size); j++) \{}}
\L{\LB{    data[j] *= propV2[j]\/size;}}
\L{\LB{  \}}}
\L{\LB{}}
\L{\LB{  \C{}\/* TRACK(stdout,\"V\/2].\"); *\/\CE{}}}
\L{\LB{}}
\L{\LB{\K{\#ifdef} EDGE\_OVERFLOW}}
\L{\LB{  \K{if} (edge\_overflow(data, size, ERROR\_LIMIT)) \{}}
\L{\LB{    die\_r(data, size, \S{}\"position:last\"\SE{}, i+offset);}}
\L{\LB{  \}}}
\L{\LB{\K{\#endif}}}
\L{\LB{\}}}
