示例#1
0
char * testAzElRaDec()
/*  *    *    *    *    *    *    *    *    *    *    *    *    *    *    *  */
{ double az = 0., el = 0., ra = DEGREE, dec = DEGREE, 
    lst = 0, raOut = 0, decOut = 0,
    lat = (38.43330470*DEGREE), utc = 0;
  long i = 0;

  for (i = 0; i < 24; i++) {
    lst = i * TWOPI/24;
    radec2azel( ra, dec, lst, lat, &az, &el);

    fprintf ( stderr, "RA,Dec=%8.2lf,%8.2lf (lst=%8.2lf)",
	      ra/DEGREE, dec/DEGREE, lst*24./TWOPI);
    fprintf ( stderr, "=> Az,El=%8.2lf,%8.2lf", 
	      az/DEGREE, el/DEGREE);
  
    azel2radec( az, el,  lst, lat, &raOut, &decOut);

    fprintf ( stderr, "=> Ra,Dec=%8.2lf,%8.2lf\n", 
	      raOut/DEGREE, decOut/DEGREE);
  }

  return(NULL);
}
示例#2
0
文件: sched.c 项目: BlastTNG/flight
static void LoadSchedFile(const char* file, struct ScheduleType* S, int lband)
{
  FILE *fp;
  char line_in[MAX_LINE_LENGTH];
  char *token[MAX_N_PARAMS + 4];
  char *ptr;
  double hours;
  struct tm ts;
  double dt;
  double d_lon;
  int day, command, type;
  double check_lat = NOMINAL_LATITUDE + lband * (LATITUDE_BAND
      - LATITUDE_OVERLAP);

  double az1, az2, el1, el2, height;

  int i, j, k, entry_ok;
  int n_fields, mindex;
  int el_range_warning;
  int discarded_lines;

  blast_sched("********************************************\n"
          "*** Schedule: %s\n", file);
  /*******************************************/
  /*** Count number of schedule file lines ***/
  if ((fp = fopen(file, "r")) == NULL) {
    berror(err, "Scheduler: Unable to open schedule file %s", file);
    S->n_sched = 0;
    return;
  }

  while (GetLine(fp, line_in))
    S->n_sched++;

  S->n_sched--; /* don't count date line */

  if (S->n_sched > MAX_NSCHED) {
    berror(err, "Scheduler: schedule '%s' has too many commands", file);
    S->n_sched = MAX_NSCHED;
  }

  S->event = (struct ScheduleEvent*)balloc(fatal, S->n_sched *
      sizeof(struct ScheduleEvent));

  blast_sched("*** Lines: %i\n", S->n_sched);

  if (fclose(fp) == EOF)
    berror(err, "Scheduler: Error on close");

  /**************************/
  /*** Read Starting Time ***/
  if ((fp = fopen(file, "r")) == NULL) {
    berror(err, "Scheduler: Unable to open schedule file");
    S->n_sched = 0;
    return;
  }
  GetLine(fp, line_in);
  
  strncpy(lst0str, line_in, 80);
  
  sscanf(line_in, "%d-%d-%d %d:%d:%d", &(ts.tm_year), &(ts.tm_mon),
      &(ts.tm_mday), &(ts.tm_hour), &(ts.tm_min), &(ts.tm_sec));

  if (ts.tm_year < 50)
    ts.tm_year += 100;
  else
    ts.tm_year -= 1900;

  ts.tm_isdst = 0;
  ts.tm_mon--; /* Jan is 0 in struct tm.tm_mon, not 1 */

  S->t0 = mktime(&ts) - timezone;

  /*************************************************************/
  /** find local comoving siderial date (in siderial seconds) **/ //166 east lon
  dt = (mcp_systime(NULL) - S->t0) * 1.002737909; /* Ref Siderial Time */
  d_lon = CHECK_LON;
  while (d_lon < 0)
    d_lon += 360.0;
  while (d_lon >= 360.0)
    d_lon -= 360.0;
  dt -= (d_lon * 3600.00 * 24.00 / 360.0); /* add longitude correction */

  dt /= 3600.0;

  if (lband>-10) {
    blast_sched("*** Current LST (hours) %g\n"  //relative to schedule epoch
          "*** For checks: LAT=%g, LON=%g\n", dt, check_lat, CHECK_LON);
  }

  /***********************/
  /*** Read the events ***/
  discarded_lines = 0;
  for (i = j = 0; i < S->n_sched; i++) {
    entry_ok = 1;
    GetLine(fp, line_in);

    /* Tokenise the string */
    k = 0;
    n_fields = 1;
    ptr = line_in;
    token[0] = ptr;
    for (;;) {
      if (*ptr == ' ' || *ptr == '\t' || *ptr == '\n' || *ptr == '\r') {
        if (k)
          *(ptr - 1) = '\0';
        else
          k = 1;
      } else {
        if (k) {
          *(ptr - 1) = '\0';
          token[n_fields++] = ptr;
        }
        k = 0;
      }
      if (*ptr == '\0' || *ptr == '#' || *ptr == '\n')
        break;
      ++ptr;
    }

    /* decrypt tag to find command */
    command = MCommand(token[0]);
    if (command == -1) {
      S->event[j].is_multi = 0;
      command = SCommand(token[0]);
      if (command == -1) {
        blast_sched("Scheduler: *** ERROR: command not recognised: %s\n",
            token[0]);
        entry_ok = 0;
      }
    } else
      S->event[j].is_multi = 1;

    S->event[j].command = command;

    /* lst */
    if (n_fields < 3) {
      blast_sched("Scheduler: *** ERROR: cannot find lst!\n");
      entry_ok = 0;
    } else {
      day = atoi(token[1]);
      hours = atof(token[2]);
      S->event[j].t = day * 24l * 3600l + hours * 3600l;
    }

    /* Parameters */
    if (entry_ok && S->event[j].is_multi) {
      mindex = MIndex(command);
      if (n_fields < 3 + mcommands[mindex].numparams) {
        blast_sched("Scheduler: *** ERROR: insufficient parameters for "
            "command (wanted %i; got %i)\n", mcommands[mindex].numparams,
            n_fields - 3);
        entry_ok = 0;
      } else
        for (k = 0; k < mcommands[mindex].numparams; ++k) {
          type = mcommands[mindex].params[k].type;
          if (type == 'i')  /* 15 bit unsigned integer */
            S->event[j].ivalues[k] = atoi(token[k + 3]);
          else if (type == 'l')  /* 30 bit unsigned integer */
            S->event[j].ivalues[k] = atoi(token[k + 3]);
          else if (type == 'f')  /* 15 bit floating point */
            S->event[j].rvalues[k] = atof(token[k + 3]);
          else if (type == 'd') /* 30 bit floating point */
            S->event[j].rvalues[k] = atof(token[k + 3]);
        }
    }

    if (!entry_ok) {
      blast_sched(          "Scheduler: ****** Warning Line %i is Malformed: Skipping *****\n",
          i);
      discarded_lines++;
    } else
      j++;
  }
  S->n_sched -= discarded_lines;

  if (lband>-10) {
    for (i = 0; i < S->n_sched; i++) {
      if (S->event[i].command == box || S->event[i].command == vbox ||
        S->event[i].command == cap || S->event[i].command == vcap) {
        radec2azel(S->event[i].rvalues[0], S->event[i].rvalues[1], S->event[i].t,
                   check_lat, &az1, &el1);
        if (i == S->n_sched - 1)
          radec2azel(S->event[i].rvalues[0], S->event[i].rvalues[1],
                     S->event[i].t, check_lat, &az2, &el2);
          else
            radec2azel(S->event[i].rvalues[0], S->event[i].rvalues[1],
                       S->event[i + 1].t, check_lat, &az2, &el2);
            
            height = S->event[i].rvalues[3];
          if (S->event[i].command == box || S->event[i].command == vbox)
            height /= 2;
          
          el_range_warning = 0;
          if (el1 > el2) {
            el1 += height;
            el2 -= height;
            if (el1 > 60.0)
              el_range_warning = 1;
            if (el2 < 25.0)
              el_range_warning = 1;
          } else {
            el1 -= height;
            el2 += height;
            if (el2 > 60.0)
              el_range_warning = 1;
            if (el1 < 25.0)
              el_range_warning = 1;
          }
          if (el_range_warning && 0) { // FIXME: reenable
            blast_sched("Scheduler: ******************************************\n"
                           "Scheduler: *** Warning: El Range of Event %i (%s)\n", i,
                    CommandName(S->event[i].is_multi, S->event[i].command));
            blast_sched("Scheduler: *** LST: %i/%7.4f Ra: %8.3f  Dec: %8.3f\n",
                    (int)(S->event[i].t / 86400), fmod(S->event[i].t / 3600.0, 24),
                    S->event[i].rvalues[0], S->event[i].rvalues[1]);
            blast_sched("Scheduler: *** LST: %7.4f Az: %8.3f - %8.3f El: "
                           "%8.3f - %8.3f\n", S->event[i].t / 3600.0, az1, az2, el1, el2);
          } 
        }
    }
    bputs(sched, "********************************************\n");
  }
  
  if (discarded_lines)
    blast_warn("Discarded %i malformed lines from schedule file.",
        discarded_lines);

  if (fclose(fp) == EOF)
    berror(err, "Scheduler: Error on close");
}