Zero offset in C routines


junderwood
06-09-2002, 03:45 PM
Hi

I see that the C++ version of the NR routines have adopted the zero offset for vectors and arrays (yay!). I was wondering if there was any plan to offer a version of the C routines with zero offset.

Another thought - currently i use a script which calls sed to convert all the NR routines to double precision, i wonder if it would be possible to somehow conjour a script to use sed to convert all the functions to zero offset.

jonathan

Bill Press
06-10-2002, 12:57 PM
No, there are no plans to change the C code. In part this is because -- the C book having been in print for so many years in a succession of updates -- it would introduce too much confusion to have both zero-based and unit-based incompatible versions floating around.

I assume that you are familiar with the discussion on pp. 18-19 in the C book, about how to call the unit-based Recipes from your own zero-based routines.

By the way, Cambridge University Press has not decided whether to keep both the C and C++ books in print indefinitely, or whether to let the C book go out of print at some point (keeping the C++). In the latter case, we (Numerical Recipes Software) would likely still distribute both C and C++ code in the machine-readable formats, but there would be no separate documentation of the C version.

William Vetterling
06-10-2002, 10:10 PM
Jonathan,

On the question of writing an automatic converter using sed (or perl):

It would be great if you could figure out a way to do this. I think you will find it very tricky. Here are a couple examples of things that cause trouble:

1. Some routines have arrays, usually with names like index[i] or indx[i], in which not only the indices have to be 0-based, but the array values as well (since they represent indices of other arrays). An interesting case is the routine eclazz, which has a statement

if (*equiv(jj,kk)) nf[nf[nf[kk]]]=jj;

where jj, kk, and the elements of nf[] all need to be shifted.

2. Sometimes arrays like index[i] are passed as arguments to functions, and you have to follow the array-value shifts through the function call and into the body of the called function.

3. In some cases, a loop index (which is looping over array elements) has a limit like

for(i=1; i <= k; i++) {

where k is another loop index that also loops over array elements. This, in itself, is not too tricky, but sometimes the index k is not from an enclosing loop, but from a prior loop that was terminated prematurely by a break statement, as in:


for (k=1; k <= M; k++) {
...
if (a[k] < MIN) break;
...
}
... some other code ...
for (i=1; i <= k; i++) {
...
}


The processing rules for this type of thing could get a little complicated.

Maybe you should give it a try, and see what you can do!