12 #include <sys/types.h>
28 int nyrm1, ic, nadd, julday;
35 nadd = nyrm1 / 4 - ic + ic / 4;
37 julday = 365. * (nyrm1 - izero) + nadd;
53 void datj(
int id,
int im,
int iy,
int* jour)
56 int ideb[13] = {0,31,59,90,120,151,181,212,243,273,304,334,365};
58 if(im > 12 || im <= 0)
65 jour4 =
id + ideb[im-1];
69 jour4 = jour4 + ibiss;
73 if(id <= 0 || id > (ideb[im] - ideb[im-1] + ibiss))
82 if(id <= 0 || id > (ideb[im] - ideb[im-1]))
89 jour4 = jour4 +
julda(iy);
103 dd = pops_date + 0.00005;
113 datj(day, month, year, &jour);
125 st_fail(
"Scan header full, cannot add header section %d", type);
135 for(i= num - 2; i >= 0; i--)
137 *(info + 2 * num + i) = *(info + 2 * (num-1) + i);
139 for(i= num - 2; i >= 0; i--)
141 *(info + num + i) = *(info + (num-1) + i);
145 *(info + num - 1) = type;
147 *(info + 2 * num - 1) = length;
151 *(info + 3 * num - 1) = *(info+ 3 * num - 2) + *(info + 2 * num - 2);
157 int eqtogal(
double ra,
double dec,
double *glong,
double *glat)
159 double x, y, z, x0, z0, cosd;
160 static double sin626=0, cos626;
173 y = -cos626 * x0 + sin626 * z0;
174 z = sin626 * x0 + cos626 * z0;
176 *glat = (180./M_PI)*asin(z);
177 *glong = (180./M_PI)*atan2(y,x) + 33;
194 int fd, len_index, subscan;
195 long ent_off, scan_off, sect_off, data_off;
197 char *cp, sourcename[256], srctmp[256], tmp[256], freqname[256],
198 tbuf[256], telescope[256];
199 double glong_pos, glat_pos;
212 scanFraction = headp->
scan - floor(headp->
scan);
217 if(!strncmp(headp->
obsmode,
"LINEPCAL", 8))
220 if(scanFraction < 0.205)
222 st_report(
"Obs %8.8s not processed for class, skip %7.2f.",
233 st_fail(
"Can't open class file: %s", file);
238 lseek(fd, 0L, SEEK_SET);
239 len_index = read(fd, (
char *) &index,
sizeof (index));
250 if(strncmp(headp->
obsmode,
"LINE", 4) == 0)
252 if(strncmp(&headp->
obsmode[4],
"OTF", 3) == 0)
254 st_report(
"CLASS_WRITER: Obs type %8.8s not processed, skip scan %7.2f.",
268 st_fail(
"CLASS_WRITER: Unknown Obs type %8.8s, skip scan %7.2f.",
281 strncpy(srctmp, headp->
object, 16);
284 cp = strtok(srctmp,
" ");
287 sprintf(sourcename,
"%-12.12s", cp);
291 strcpy(sourcename,
"No Src Name ");
294 bcopy (sourcename, entry.
source, 12);
296 sprintf(freqname,
"%-12s", headp->
linename);
297 bcopy (freqname, entry.
line, 12);
299 subscan = (int)(((headp->
scan+0.005) - (
int)headp->
scan) * 100.0);
301 strncpy(tmp, headp->
backend, 8);
305 st_report(
"Backend = %s, subscan %d", tmp, subscan );
309 strcpy(telescope,
"SMT-");
312 if(subscan > 20 && subscan < 40)
314 strcpy(telescope,
"HOT-");
317 if(subscan > 40 && subscan < 60)
319 strcpy(telescope,
"SKY-");
322 if(subscan > 60 && subscan < 80)
324 strcpy(telescope,
"CLD-");
327 strcpy(telescope,
"UNK-");
329 sprintf(tbuf,
"%s ", cname+4);
331 strcat(telescope, tbuf);
333 bcopy((
char *)telescope, (
char *)&entry.
telescope, 12);
340 if(!strncmp(&headp->
coordcd[4],
"RADC", 4) || !strncmp(headp->
coordcd,
"APPRADC",7))
342 if(strncmp(headp->
frame,
"RA_DEC", 6) && strncmp(headp->
frame,
" ", 6))
346 strncpy( cd, headp->
coordcd, 8 );
349 strncpy( fr, headp->
frame, 8 );
358 if(!strncmp(&headp->
coordcd[0],
"GALACTIC", 8))
364 st_fail(
"CLASS_WRITER: Unknown coordinate system %8.8s.", headp->
coordcd);
385 sect.general.ut_time = 3600*headp->
ut;
386 sect.general.lst_time = 3600*headp->
lst;
390 sect.general.tsys = headp->
stsys;
391 sect.general.integration = headp->
inttime;
394 lseek(fd, sect_off, SEEK_SET);
402 bcopy(sourcename, sect.position.source, 12);
406 sect.position.epoch = 0;
410 if(strncmp(headp->
coordcd,
"APPRADC", 7) != 0 &&
415 strncpy( cd, headp->
coordcd, 8 );
418 st_fail(
"Inconsistent coordinate epochs: %6.1f and %s", headp->
epoch, cd);
421 sect.position.epoch = headp->
epoch;
426 sect.position.lambda_off =
429 sect.position.beta_off =
450 sect.position.lambda_off =
453 sect.position.beta_off =
465 sect.position.lambda_off =
468 sect.position.beta_off =
479 entry.
offsets[0] = sect.position.lambda_off;
480 entry.
offsets[1] = sect.position.beta_off;
481 sect.position.projection =
P_RADIO;
484 lseek (fd, sect_off, SEEK_SET);
492 bcopy(freqname, sect.spectro.line, 12);
493 sect.spectro.rest = headp->
restfreq;
495 sect.spectro.reference = headp->
refpt;
496 sect.spectro.fres = headp->
freqres;
497 sect.spectro.foff = 0 ;
498 sect.spectro.vres = headp->
deltax;
503 sect.spectro.voff = headp->
velocity;
510 sect.spectro.bad = headp->
badchv;
524 if(!strncmp(&headp->
veldef[4],
"LSR", 3))
526 sect.spectro.velocity =
VLSR;
529 if(!strncmp(&headp->
veldef[4],
"HELO", 4))
531 sect.spectro.velocity =
VHEL;
534 if(!strncmp(&headp->
veldef[4],
"EART", 4))
536 sect.spectro.velocity =
VEAR;
539 if(!strncmp(&headp->
veldef[4],
"OBS", 3))
541 sect.spectro.velocity =
VOBS;
545 st_fail(
"CLASS_WRITER: Unknown velocity reference %8.8s", headp->
veldef);
546 sect.spectro.velocity =
VUNK;
549 sect.spectro.sky = headp->
obsfreq;
550 sect.spectro.vteles = headp->
rvsys;
552 bcopy((
char *)§.spectro.line, sect_buf, 3*4);
553 bcopy((
char *)§.spectro.rest, §_buf[3*4], 2*4);
554 bcopy((
char *)§.spectro.nchan, §_buf[(3+2)*4], 7*4);
555 bcopy((
char *)§.spectro.image, §_buf[(3+2+7)*4], 3*4);
556 bcopy((
char *)§.spectro.sky, §_buf[(3+2+7+3)*4], 3*4);
559 lseek (fd, sect_off, SEEK_SET);
563 if(!strncmp(&headp->
obsmode[4],
"FS", 2))
571 sect.fswitch.nphase =
NPHASE;
572 sect.fswitch.decalage[0] = headp->
foffsig;
573 sect.fswitch.decalage[1] = headp->
foffref1;
576 sect.fswitch.poids[0] = 1;
577 sect.fswitch.poids[1] = -1;
579 sect.fswitch.lamoff[0] = 0;
580 sect.fswitch.betoff[0] = 0;
581 sect.fswitch.lamoff[1] = 0;
582 sect.fswitch.betoff[1] = 0;
585 bcopy((
char *)§.fswitch.nphase, sect_buf, 4);
586 bcopy((
char *)§.fswitch.decalage, §_buf[4], nf*2*4 );
587 bcopy((
char *)§.fswitch.duree, §_buf[(1+nf*2)*4], nf*4);
588 bcopy((
char *)§.fswitch.poids, §_buf[(1+nf*3)*4], nf*4);
589 bcopy((
char *)§.fswitch.mode, §_buf[(1+nf*4)*4], 4);
590 bcopy((
char *)§.fswitch.lamoff, §_buf[(2+nf*4)*4], nf*4);
591 bcopy((
char *)§.fswitch.betoff, §_buf[(2+nf*5)*4], nf*4);
594 lseek(fd, sect_off, SEEK_SET);
603 sect.calib.beam_eff = headp->
etal * headp->
etafss;
604 sect.calib.forw_eff = headp->
etal;
605 sect.calib.gain_im = headp->
gaini;
606 sect.calib.h2omm = headp->
mmh2o;
609 sect.calib.tatmsig = headp->
tatms;
610 sect.calib.tchop = headp->
tchop;
611 sect.calib.tcold = headp->
tcold;
612 sect.calib.tausig = headp->
taus;
613 sect.calib.tauima = headp->
taui;
614 sect.calib.tatmima = 0;
615 sect.calib.trec = headp->
trx;
617 sect.calib.factor = headp->
tcal;
619 if(!strncmp(headp->
telescop,
"NRAO 12M", 8))
620 sect.calib.altitude = 1914;
622 sect.calib.altitude = 3186;
624 sect.calib.counts[0] = headp->
count[0];
625 sect.calib.counts[1] = headp->
count[1];
626 sect.calib.counts[2] = headp->
count[2];
627 sect.calib.lamoff = 0;
628 sect.calib.betoff = 0;
631 lseek(fd, sect_off, SEEK_SET);
638 data_off = scan_off + (scan.
data_addr-1)*4;
639 lseek(fd, data_off, SEEK_SET);
640 write(fd, (
char *) datap, scan.
data_size*4);
646 lseek(fd, scan_off, SEEK_SET);
652 lseek(fd, ent_off, SEEK_SET);
655 lseek(fd, 0L, SEEK_SET);
677 st_fail(
"Can't open class file: %s", file);
682 lseek(fd, 0L, SEEK_SET);
683 len_index = read(fd, (
char *) &index,
sizeof (index));
699 if(len_index ==
sizeof(index) && !bcmp(index.
code,
EEEI_FILE, 4))
708 st_fail(
"File %s isn't an EEEI CLASS file", file);
723 bcopy( ix, &xx,
sizeof(
struct index_ent));
725 return( write( fd, &xx, len ));
737 return( write( fd, &xx, len ));
747 bcopy( scan, &ss,
sizeof(
struct scan_ent));
749 return( write( fd, &ss, len ));
761 return( write( fd, &gg, len ));
773 return( write( fd, &gg, len ));
double deg_cos(double angle)
#define DEGREES2RADIANS(x)
double deg_sin(double angle)