60 #define SMT_ELEVATION (3.186)
61 #define KP_ELEVATION (1.914)
63 #define D2R (M_PI / 180.0)
86 #define MAX_ALMA_BANDS (sizeof(alma_bands) / sizeof(struct ALMA_BANDS))
88 #define MAX_ATM_ELEMENTS 10000
101 int atm_transm_(
float *mmwat,
float *am,
float *freqs,
float *tems,
float *tatms,
float *tauo,
float *tauwat,
float *tautots,
int *ier);
107 double fmin, fmax, fstep, pwv, gtemp, gpress, altitude, ymin;
110 char pbuf[1024], bbuf[256], vbuf[256], ebuf[256];
111 char *string, line[256];
113 double freq, dry, wet, sky, trans;
115 sprintf(bbuf,
"ssh %s \"/usr/local/bin/absorption ", which);
117 sprintf(vbuf,
"--fmin %.2f --fmax %.2f --fstep %.2f --pwv %.2f --gtemp %.1f --gpress %.0f --altitude %.0f",
118 fmin, fmax, fstep, pwv, gtemp, gpress, altitude);
122 sprintf(pbuf,
"%s %s %s", bbuf, vbuf, ebuf);
126 printf(
"%s\n", pbuf);
129 if( (fp = popen(pbuf,
"r") ) <= (FILE *)0 )
131 st_fail(
"Unable to open %s", pbuf);
138 st_report(
"Standby, as this may take a few seconds");
141 while((
string = fgets(line,
sizeof(line), fp)) != NULL)
143 n = sscanf(line,
"%le,\t%lf,\t%lf,\t%lf", &freq, &dry, &wet, &sky);
147 xdata[indx] = freq / 1e9;
151 bdata[indx] = wet+dry;
153 trans = 1.0 - (wet+dry);
155 if(trans < ymin || gsl_isnan(trans))
183 double airmass, hz, hz1, hz2, hz3, rzero,
hzero, eps, Gamma;
185 airmass = 1.0 / sin(elv *
D2R);
195 eps = asin(rzero / (rzero + hzero) * cos(elv * D2R));
202 Gamma = elv*D2R +eps;
209 hz1 = pow(rzero, 2.0);
216 hz2 = pow(rzero+hzero, 2.0);
223 hz3 = 2.0 * rzero * (rzero+
hzero) * sin(Gamma);
230 hz = hz1 + hz2 - hz3;
244 am = (float)(hz/hzero);
248 st_report(
"AM = %.3f; (1.0 / sin(%.1f)) = %.3f", am, elv, airmass);
260 double fn=0.0, fx=0.0;
264 st_report(
"findMinMax(): Enter %f %f", *fmin, *fmax);
380 st_report(
"findMinMax(): Leaving %f %f", *fmin, *fmax);
390 float mmwat, tamb, press, elev;
395 float tems, tatms, tauo, tauwat, tautots;
406 st_fail(
"mm H2O must be greater than 0.01");
410 st_report(
"Computing atm profile: f = %.1f to %.1f", fmin, fmax);
416 delta = (fmax - fmin) / 8192.0;
417 indx =
loadAtmFromServer(
"localhost", fmin, fmax, delta, mmwat, tamb, press, elev*1e3, 0.0);
421 st_fail(
"No ATM elements found");
425 st_report(
"Loaded %d ATM Elements", indx);
432 delta = (fmax - fmin) / 8192.0;
433 indx =
loadAtmFromServer(
"modelo", fmin, fmax, delta, mmwat, tamb, press, elev*1e3, 0.0);
437 st_fail(
"No ATM elements found");
441 st_report(
"Loaded %d ATM Elements", indx);
448 delta = (fmax - fmin) / 8192.0;
449 indx =
loadAtmFromServer(
"smtoast", fmin, fmax, delta, mmwat, tamb, press, elev*1e3, 0.0);
453 st_fail(
"No ATM elements found");
457 st_report(
"Loaded %d ATM Elements", indx);
465 delta = (fmax - fmin) / 8192.0;
468 atm_transm_(&mmwat, &am, &freqs, &tems, &tatms, &tauo, &tauwat, &tautots, &ier);
470 trans = 1.0 - tautots;
472 if(trans < 0.0 || gsl_isnan(trans))
478 tdata[indx] = tauwat;
480 bdata[indx] = tautots;
493 st_report(
"Loaded %d ATM Elements", indx);
512 int i, j, ret, abox, yscale = 0;;
513 char sysbuf[1024], demname[256], datname[256];
514 char *cp, *
site, plotfname[256], tbuf[256], pdfname[512];
515 double min = 1e9,
max = -1e9, freq, fmin, fmax, ymin, ymax,
516 freqDiffMin, freqdiff, freqVal, wl, x1;
518 double ofreq, ofreqDiffMin, ofreqdiff, ofreqVal, bw;
520 float tamb, press, elev;
545 st_report(
"ATM Model not generated yet");
569 st_fail(
"Must load scan first before using Auto Mode");
656 if(ymin > 0.0 || ymax > 0.0)
662 if(fmin > fmax || fmin < 1.0 || fmin > 1000.0 || fmax < 0.0 || fmax > 1000.0)
664 st_fail(
"fmin: %f > fmax: %f or out of range [1.0 - 1000.0]", ymin, ymax);
673 st_fail(
"ymin: %f > ymax: %f", ymin, ymax);
708 sprintf(datname,
"/tmp/%s/atm.dat",
session);
712 st_report(
"Opening ATM Dat File: %s", datname);
715 if((fp = fopen(datname,
"w") ) <= (FILE *)0)
717 st_fail(
"Unable to open file %s", datname);
752 for(i=0;i<
nAtm;i++,f++)
754 fprintf(fp,
"%f %f\n",
xdata[i], *f*100.0);
766 freqdiff = fabs(
xdata[i] - freq);
767 if(freqdiff < freqDiffMin)
769 freqDiffMin = freqdiff;
791 ofreqdiff = fabs(
xdata[i] - ofreq);
792 if(ofreqdiff < ofreqDiffMin)
794 ofreqDiffMin = ofreqdiff;
819 sprintf(demname,
"/tmp/%s/atm.dem",
session);
823 st_report(
"Opening ATM Dem File: %s", demname);
826 if((fp = fopen(demname,
"w") ) <= (FILE *)0)
828 st_fail(
"Unable to open file %s", demname);
833 fprintf(fp,
"reset\n");
837 fprintf(fp,
"set title 'Tau h2o @ %.2f mm H2O' tc rgb \"red\"\n",
mmh2oAtm);
838 fprintf(fp,
"set ylabel 'Atmospheric Tau (Water)' tc rgb \"red\"\n");
843 fprintf(fp,
"set title 'Tau O2 @ %.2f mm H2O' tc rgb \"red\"\n",
mmh2oAtm);
844 fprintf(fp,
"set ylabel 'Atmospheric Tau (O2)' tc rgb \"red\"\n");
849 fprintf(fp,
"set title 'Tau O2+Water @ %.2f mm H2O' tc rgb \"red\"\n",
mmh2oAtm);
850 fprintf(fp,
"set ylabel 'Atmospheric Tau (O2+Water)' tc rgb \"red\"\n");
854 fprintf(fp,
"set title 'Atmospheric Transmission: %s PWV: %.2f mm' tc rgb \"red\"\n",
siteAtm,
mmh2oAtm);
855 fprintf(fp,
"set ylabel 'Transmission (%%)' tc rgb \"red\"\n");
858 fprintf(fp,
"set xlabel 'Frequency (GHz)' tc rgb \"red\"\n");
860 fprintf(fp,
"set xrange [%.2f:%.2f]\n", fmin, fmax);
864 fprintf(fp,
"set yrange [%.2f:%.2f]\n", ymin*100.0, ymax*100.0);
869 fprintf(fp,
"set yrange [-5.0:100.0]\n");
873 fprintf(fp,
"set grid\n");
874 fprintf(fp,
"set key off\n");
878 st_report(
"Atm Transparency @ %f: %f", freq, freqVal);
880 fprintf(fp,
"set object 8 rect front from %f,%f to %f,%f fill transparent pattern 2 fc rgb 'green'\n",
881 freq - (bw/2.0), (freqVal-0.02)*100.0, freq + (bw/2.0), (freqVal+0.02)*100.0);
886 st_report(
"Atm Transparency @ %f: %f", ofreq, ofreqVal);
888 fprintf(fp,
"set object 9 rect front from %f,%f to %f,%f fill transparent pattern 2 fc rgb 'magenta'\n",
889 ofreq - (bw/2.0), (ofreqVal-0.02)*100.0, ofreq + (bw/2.0), (ofreqVal+0.02)*100.0);
901 fprintf(fp,
"set object %d rect %s from %f,%f to %f,%f fill transparent solid 0.6 fc rgb '%s'\n",
909 fprintf(fp,
"set object %d rect %s from %f,%f to %f,%f fill transparent solid 0.6 fc rgb '%s'\n",
917 fprintf(fp,
"set object %d rect %s from %f,%f to %f,%f fill transparent solid 0.6 fc rgb '%s'\n",
926 if(x1 > fmin && x1 < fmax)
929 sprintf(tbuf,
"%s %3.1fmm", p->
name, wl);
930 fprintf(fp,
"set label '%s' at %.6f, %.6f rotate by 90 tc rgb 'black' \n", tbuf, x1, (max-min) / 2.0);
940 fprintf(fp,
"set terminal postscript color solid enhanced landscape\n");
942 sprintf(plotfname,
"/tmp/%s/ccal_plot.ps",
session);
944 fprintf(fp,
"set out '%s'\n", plotfname);
948 fprintf(fp,
"set terminal x11 enhanced %d\n",
env->
plotwin+1 );
951 fprintf(fp,
"plot '%s' with lines lc rgb \"red\"", datname);
955 sprintf(sysbuf,
"xgraphic load '/tmp/%s/atm.dem'",
session);
962 sprintf(sysbuf,
"lpr /tmp/%s/ccal_plot.ps",
session);
971 cp = strchr(pdfname,
' ');
976 sprintf(sysbuf,
"cat /tmp/%s/ccal_plot.ps | /usr/bin/epstopdf -f --outfile=%s",
session, pdfname);
979 ret = system(sysbuf);
983 st_report(
"AMT Plot saved to %s", pdfname);
987 st_fail(
"Error creating PDF file");
struct LP_IMAGE_INFO * h0
#define ALMA_BAND_7_LOWER
int hzero(struct LP_IMAGE_INFO *image)
struct PARSE_STACK * args
#define ALMA_BAND_6_LOWER
int printH_FlagHelp(char *cmd)
#define ALMA_BAND_8_LOWER
#define ALMA_BAND_10_UPPER
int atm_transm_(float *mmwat, float *am, float *freqs, float *tems, float *tatms, float *tauo, float *tauwat, float *tautots, int *ier)
int setFlag(int flag, int state)
float tdata[MAX_ATM_ELEMENTS]
#define ALMA_BAND_10_LOWER
#define ALMA_BAND_8_UPPER
#define ALMA_BAND_1_LOWER
#define ALMA_BAND_1_UPPER
#define ALMA_BAND_5_LOWER
#define ALMA_BAND_6_UPPER
#define ALMA_BAND_4_UPPER
#define ALMA_BAND_4_LOWER
#define ALMA_BAND_3_UPPER
#define ALMA_BAND_2_UPPER
int loadAtmFromServer(char *which, double fmin, double fmax, double fstep, double pwv, double gtemp, double gpress, double altitude, double ymin)
#define ALMA_BAND_5_UPPER
float odata[MAX_ATM_ELEMENTS]
int atm_atmosp_(float *tamb, float *press, float *h0)
#define ALMA_BAND_2_LOWER
float bdata[MAX_ATM_ELEMENTS]
float xdata[MAX_ATM_ELEMENTS]
#define ALMA_BAND_7_UPPER
float computeAtmophers(float elv)
#define ALMA_BAND_9_LOWER
float ydata[MAX_ATM_ELEMENTS]
int findMinMax(double *fmin, double *fmax)
#define ALMA_BAND_3_LOWER
int generateAtm(double fmin, double fmax, float mmwat, float tamb, float press, float elev)
struct ALMA_BANDS alma_bands[]
#define ALMA_BAND_9_UPPER