File: magnitude.c

package info (click to toggle)
fitsh 0.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 2,768 kB
  • ctags: 4,050
  • sloc: ansic: 53,352; makefile: 1,120; sh: 25
file content (63 lines) | stat: -rw-r--r-- 1,505 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*****************************************************************************/
/* magnitude.c								     */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Some simple functions which converts between magnitudes and fluxes.	     */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* (c) 2006; Pal, A. (apal@szofi.elte.hu)				     */
/*****************************************************************************/

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#include "magnitude.h"

/*****************************************************************************/

double mag_to_flux(double mag,magflux *mf)
{
 double	flux;
 
 flux=mf->intensity*exp(-0.4*M_LN10*(mag-mf->magnitude));

 return(flux);
}

double flux_to_mag(double flux,magflux *mf)
{
 double	mag;

 if ( flux<=0.0 || mf->intensity<=0 )
	return(0.0);
 else
  {	mag=(-2.5*log10(flux/mf->intensity))+mf->magnitude;
	return(mag);
  }
}

/*****************************************************************************/

int flux_to_mag_magerr(double f,double fe,magflux *mf,double *rm,double *rme)
{
 double	mg,me;
 int	ret;

 if ( f <= 0.0 || mf->intensity <= 0.0 )
  {	mg=0.0,
	me=0.0;
	ret=1;
  }
 else
  {	mg=flux_to_mag(f,mf);
	me=1.08574 * (fabs(fe)/f);	/* 1.08574... = 5/ln(100)	*/
	ret=0;
  }

 if ( rm  != NULL )	*rm =mg;
 if ( rme != NULL )	*rme=me;

 return(ret);
}

/*****************************************************************************/