lenstool_tab                10/20/04
Notes for lenstool_tab...note that the program is still under
construction and may be modified significantly in the near future.  I
will report any changes.  There may be significant bugs since I have
not tested it thoroughly.

THE IMPORTANT STUFF:
The source code is in my directory:
/home/siabod/djs/newbin/biglens

If you think you will ever be interested in using this code, please
grab everything in all the subdirectories in the above directory.
****Note that I have modified slightly the functions that JP gave me,
but only those parts having to do with the declaration of functions,
since we apparently use two different versions of C.  So, if you want
to use this code, really just copy over everything in this directory
for everything to be consistent.****

It is easy to compile the code.  Just be in the directory where you
have copied the code to and type 'make'.  Feel free to
change/upgrade/fix the code if you see any obvious flaws, or just
report any problems to me.

There is an 'examples' directory, with an input file and a two-line
script that will remove any lingering output file from an old run and
run the code.  Just type: 'source runtest.sh' and the example program
with the given input file will run and produce a binary file.

Some explanation of the code:

Throughout x = r/r_sc and alpha is the inner logarithmic DM density
slope.  These are the two parameters we want to vary.

The program needs an input file specifying the range and step size of
alpha and x to take.  Also, an output file name is needed...the name
of the output binary file.  Here is a typical command line of the code:
~/newbin/biglens/lenstool_tab tab.in test.tab

Here are the guts of a sample input file:

1.0e0 1.03e0 1.0e-2 1.0e-1 1.0e0 1.01
 
which corresponds to: alpha_low alpha_high alpha_step x_low x_high astep

alpha is incremented with a 'for' loop as follows:
alpha_now = alphalow; alpha_now <= alpha_high; alpha_now=alpha_now+alpha_step

while 'x' is incremented as follows:
x_now=x_low; x_now<=x_high; x_now=x_now*astep

This should cause the two relevant parameters to be incremented as JP
and I discussed, and it allows the user control over what range and
how fine a grid one wants.  The main body of the code is less than 100
lines long...it should be easy to spot the two nested 'for' loops if
you want to know what was explicitly done.

The code writes 4 values for every value of x and alpha.  They are:
1. alpha
2. x
3. kappa
4. dpl

Where the last two are defined by JP's functions in: e_nfwg.c

To be explicit for JP, here are the exact lines of code so that you
can scale the results appropriately in lenstool (you can also look it
up in the source code):

     lensprop.kappa = nfwg_kappa(lensprop.x_now,1.0,1.0,lensprop.alpha_now);
      /*note that I set r_sc = 1.0, kappas = 1.0*/
      lensprop.dpl = lensprop.x_now*nfwg_dpl(lensprop.x_now,1.0,1.0,lensprop.alpha_now);
      /*note that I set r_sc = 1.0, kappas = 1.0*/
      /*not also the x_now out in front...this is to get rid 'r' dependenc in nfwg_dpl*/
      /*so entire scaling is 1.0...this must be corrected for in JP's code*/

I hope this is clear JP.  If not, we'll figure it out.

How to read the binary file:

I don't know how familiar you are with binary files.  

I have defined a C 'structure' which characterizes the data input into
the binary file.

  typedef struct{
    float alpha_now,x_now,kappa,dpl;
  } datagroup;
 datagroup lensprop;
 
You can stick in basically an identical set of 'for' loops as I did in
lenstool_tab and read out the binary file one step at a time and store
the values to a big array (or structure or whatever) you have set up.
Something like this, within the two 'for' loops:
for(alpha steps as above blah){
	for(x steps as above blah){
	fread(&lensprop,sizeof(datagroup),1,outf);
	alpha[i]=lensprop.alpha_now;
	x[i]=lensprop.x_now;
	kappa[i]=lensprop.kappa;
	dpl[i]=lensprop.dpl;	
	i=i+i;
}
}

Actually, maybe a higher dimensional array would be better, but
whatever, you get the point.  I hope.

outf is the file pointer to the binary file in the above.

To initialize a binary file to be read (only) in C, this will work:
    outf = fopen(outfile, "rb");
The "rb" is the important part.

I hope this is good enough to get you started.  I'm tired.
