| 1 | #include <stdio.h>
|
|---|
| 2 | #include <string.h>
|
|---|
| 3 | #include <math.h>
|
|---|
| 4 | #include "diag.h"
|
|---|
| 5 | #include "atm.h"
|
|---|
| 6 | #include "init.h"
|
|---|
| 7 |
|
|---|
| 8 | /* random numbers */
|
|---|
| 9 | #define RandomNumber ranf()
|
|---|
| 10 |
|
|---|
| 11 | /* AM Nov 2002: atmModel is now an external variable: */
|
|---|
| 12 | int atmModel=0; /* current atm. model */
|
|---|
| 13 |
|
|---|
| 14 | /* Function declarations */
|
|---|
| 15 | static float atm(float wavelength, float height, float theta);
|
|---|
| 16 | void SetAtmModel(char *model);
|
|---|
| 17 | int absorption(float wlen, float height, float theta);
|
|---|
| 18 | extern void attenu_(float *, float *, float *, float *); /* in Fortran */
|
|---|
| 19 | extern float ranf(void);
|
|---|
| 20 |
|
|---|
| 21 | void SetAtmModel(char *model)
|
|---|
| 22 | {
|
|---|
| 23 | while (strcmp(model, AtmModelNames[atmModel]))
|
|---|
| 24 | if (++atmModel == sizeof(AtmModelNames)/sizeof(AtmModelNames[0]))
|
|---|
| 25 | { atmModel = 0;
|
|---|
| 26 | Error(ATM__NFND__ERR, model);
|
|---|
| 27 | break; }
|
|---|
| 28 |
|
|---|
| 29 | Log(ATM__SET___LOG, AtmModelNames[atmModel]);
|
|---|
| 30 |
|
|---|
| 31 | /* 'erfc' must be inited, so keep the following line. */
|
|---|
| 32 | Debug("Initing 'erfc': ret=%g\n", erfc(M_PI));
|
|---|
| 33 | } /* end of SetAtmModel */
|
|---|
| 34 |
|
|---|
| 35 | static float atm(float wavelength, float height, float theta)
|
|---|
| 36 | { float transmittance = 1.0; /* final atm transmittance (ret. value) */
|
|---|
| 37 |
|
|---|
| 38 | switch(atmModel)
|
|---|
| 39 | { case ATM_NOATMOSPHERE: /* no atm at all: transmittance = 100% */
|
|---|
| 40 | break;
|
|---|
| 41 | case ATM_90PERCENT: /* atm. with transmittance = 90% */
|
|---|
| 42 | transmittance = 0.9;
|
|---|
| 43 | break;
|
|---|
| 44 | case ATM_ISOTHERMAL: /* isothermal approximation */
|
|---|
| 45 | /********************/
|
|---|
| 46 | break;
|
|---|
| 47 | case ATM_CORSIKA: /* atmosphere as defined in CORSIKA */
|
|---|
| 48 | attenu_(&wavelength, &height, &theta, &transmittance);
|
|---|
| 49 | break;
|
|---|
| 50 | } /* end of atm switch */
|
|---|
| 51 |
|
|---|
| 52 | return transmittance;
|
|---|
| 53 | } /* end of atm */
|
|---|
| 54 |
|
|---|
| 55 | int absorption(float wlen, float height, float theta)
|
|---|
| 56 | { int ret = 0; /* 0: passed, 1: absorbed */
|
|---|
| 57 |
|
|---|
| 58 | if (RandomNumber > atm(wlen, height, theta)) ret=1;
|
|---|
| 59 |
|
|---|
| 60 | return ret;
|
|---|
| 61 | } /* end of absorption */
|
|---|