Listing 3

/* header file to:
     aid in conversion of FORTRAN code to C
     perform a few useful functions in-line
from Handbook of C Tools for Scientists and Engineers
     by L. Baker

DEPENDENCIES: NONE

*/


/* in-line functions for use with 2D arrays: */

/* row major order as in C indices run 0..n-1 as in C*/
#define INDEX(i,j) [j+(i)*coln]

/*various loop constructors */
#define DOFOR(i,to) for(i=0;i<to;i++)
#define DFOR(i,from,to) for(i=from-1;i<to;i++)
#define DOBY(i,from,to,by) for(i=from-1;i<to;i+=by)
#define DOBYY(i,from,to,by) for(i=from;i<to;i+=by)
#define DOBYYY(i,from,to) for(i=from;i<to;i++)
#define DOV(i,to,by) for(i=0;i<to;i+=by)
/* row major order as in C indices run 1..n */
/*#define INDEX1(i,j) [j-1+(i-1)*n]
*/
/* column major order, as in fortran: */
#define INDEXC(i,j) [i-1+(j-1)*rown]

/* usage: if a(20,30) is matrix, then
a(i,j) in C will be a INDEX(i,j) if n=30. */

/* to index vectors starting with 1 */
#define VECTOR(i) [i-1]

#define min(a,b) (((a)<(b))? (a): (b))
#define max(a,b) (((a)<(b))? (b): (a))
#define abs(x) ( ((x)>0.)?(x):-(x))