next up previous
Next: The files used by Up: Updating magmax, filter and Previous: Calibration of new filters

  
Modifying magnitude.c and magmax.pro

Plugging in a new filter

Look at the file magnitude.c At the beginning of the source code, change the definition and initialisation of struct filterdat correction as you did before in norm_filter.c for struct correction norm (add the same line to the prototype declaration of the struct, add the new calibration number you obtained to the initialisation of struct filterdat correction). The two beginnings of the source codes norm_filter.c and magnitude.c should now look the same, except of the different names for the struct and the variable. Now search for the declaration of the function magnitude, ``double magnitude (int argc, void** argv)''. Add your path declaration for the new filter to the char array declarations at the beginning of ``magnitude'' like you've done before in norm_filter.c A little bit below you will find a switch-block starting with:


switch(fil)  /*read in the filterdata*/
{
	case 1:
Copy one entire case-block to the end of this switch-block and edit it like this:

 	case <A>:
		error=readtable(xpath,&x,&y,&max,spec);  /*read u filter*/
		if(error!=0)   /*if unable to read*/
		{
			switch(error)
			{
				case 1:
					fprintf(stderr,"Error while opening file for reading filter:$\backslash$n$\backslash$rpath: %s$\backslash$n$\backslash$r",xpath);

break; case 2: fprintf(stderr,"Error while reading filter: Out of memory!$\backslash$n$\backslash$rpath: %s$\backslash$n$\backslash$r",xpath); break; case 3: fprintf(stderr,"Error while reading filter: Wrong file structure!$\backslash$n$\backslash$rpath: %s$\backslash$n$\backslash$r",xpath); break; } } break;

The <A> has to be replaced by the next available number in the switch statement, e.g. if the last case-block in this entire switch-block was 8 then you replace <A> with 9. Again, if your filter is in nm, convert it to Ångstrom. You can copy one of the conversion statements from the J, H and K band filters:

for(i=1;i<=max;i++)      /*convert from angstrom to nm*/
	x[i]=x[i]*10;
into your case-block. Now you have to search for the function integrate, the declaration starts like
int integrate(double *xfil,double *yfil,double *xspec,double *yspec,int maxfil,int maxspec,double *result,long int filter)
{.....
Go to the end of the function and search a switch block like this one:

switch(filter)
{
	case 1:
		*result=*result+correction.u;
		break;
	case 2:
		*result=*result+correction.b;
		break;
	case 3:
		*result=*result+correction.v;
		break;
	case 4:
		*result=*result+correction.r;
		break;
	case 5:
		*result=*result+correction.i;
		break;
	case 6:
		*result=*result+correction.j;
		break;
	case 7:
		*result=*result+correction.h;
		break;
	case 8:
		*result=*result+correction.k;
		break;
}
It is similiar to the one in function integrate in norm_filter.c with the only exception that the characters in norm_filter now have been replaced by numbers. Append the same lines than in norm_filter.c at the end of the switch-block but this time replace the character after the case statement (e.g. 'x') with the same number you used before for <A> (see above). Recompile the surce code with the following command:
gcc -o magnitude.so -fpic -shared -O2 magnitude.c
The only thing left to do is changing the IDL function magmax.pro so that it takes the new filter as parameter and hands it on to magnitude.so So look at the source code of magmax.pro. First, add a new keyword for the new filter in the parameterlist, e.g. x=x. Now search for the first block of statements with call_external. It begins like:
if keyword_set(u) then flag = call_external('/home/astro10/mwetzste/cprogs/magnitude.so', 'magnitude', z, dm, long(n_elements(z)), long(1), result, /d_value)
Copy one of these statements so that it is the last one of this block and replace the argument of keyword_set (here u) with your new keyword (x) and edit the number in the second long() function (here 1) to the next available number. If the number used by the last statement in this block was e.g. 8 you use 9 for your new, now last statement of the block. After this has been done, search for the second block of call_external statements, it looks exactly like the first one. Make the same changes as to the first block. That's it.

Plugging in a new spectrum
Look at the source code of magnitude.so. Search for the beginning of the function magnitude, ``double magnitude (int argc, void** argv)''. In the declaration of the char arrays, edit the declaration of specpath in the same way you have done it before in norm_filter.c so that specpath contains the path of the new spectrum. Now search for the block:


factor=pow(10,(-20.01704286-mb)/2.5);
for(i=1;i<=maxspec0;i++) 
	yspec0[i]=yspec0[i]*factor; /*calib sn spec*/

a little bit below. Change the number (-20.01704286) in the second argument of the pow function to the same number you have in norm_filter.c before the 19.46 (here, the spectrum is no longer statically calibrated to -19.46 mag in B band but dynamically to the value of mb, this is the only difference, the first numbers in the second argument of pow must be identical). With this number, the integration in norm_filter.c resulted in -19.46 mag in B band. Again, if your spectrum is in nm, you have to convert it to Ångstrom. Edit the for-loop above so that it then includes the line:

 	xspec0[i]=xspec0[i]*10;

That's all.


next up previous
Next: The files used by Up: Updating magmax, filter and Previous: Calibration of new filters
Peter E. Nugent Jr.
1998-10-01