示例#1
0
main() 
{
  char *name, *password, *short_desc, *long_desc ;
  char *choices, *day_str, *month_str, *year_str ;
  char *anon_post_str, *secret_ballot_str, *constant_update_str ;
  char *can_change_vote_str, *multiple_choice_str ;

  decode_query_string(15, "set_id", &set_id, "sets_list", &sets_list,
		      "name", &name, "password", &password,
		      "shortdesc", &short_desc, "longdesc", &long_desc,
		      "choices", &choices, "countday", &day_str,
		      "countmo", &month_str, "countyr", &year_str,
		      "anon_post", &anon_post_str,
		      "secret_ballot", &secret_ballot_str,
		      "constant_update", &constant_update_str,
		      "can_change_vote", &can_change_vote_str,
		      "multiple_choice", &multiple_choice_str) ;

  strip_trailing_spaces(name) ;
  strip_trailing_spaces(short_desc) ;
  strip_trailing_spaces(long_desc) ;
  strip_trailing_spaces(choices) ;

  if (!nonempty(name) || !nonempty(password) || !nonempty(short_desc) ||
      !nonempty(long_desc) || !nonempty(choices) || 
      !nonempty(day_str) || !nonempty(month_str) || !nonempty(year_str)) {
    return_nothing() ;
  }
  else {
    return_header("text/html") ;

    if (!verify_password(set_id, name, password)) {
      printf("<title>Sorry! Invalid user name/password pair</title>\n") ;
      printf("<h1>Sorry! Invalid user name/password pair</h1>\n") ;
      printf("The password you entered did not match the user name ") ;
      printf("you entered.\n") ;
    }
    else if (!date_ok(day_str, month_str, year_str)) {
      printf("<title>Sorry! Invalid date</title>\n") ;
      printf("<h1>Sorry! Invalid date</h1>\n") ;
      printf("The date you entered made no sense (for example, ") ;
      printf("you entered a day number that was invalid for the ") ;
      printf("month you chose) or was not a future date.\n") ;
    }
    else {
      char id_str[64], fname[FILENAME_MAX] ;
      struct tm count_time ;
      long count_time_val ;
      int num_choices, i ;
      char *new_choices ;
      FILE *fp ;

      if (!strcmp(anon_post_str, "0"))
	sprintf(id_str, "%s.%d", name, (long)time(NULL)) ;
      else
	sprintf(id_str, "anonymous.%d", (long)time(NULL)) ;

      count_time.tm_sec = 1 ;
      count_time.tm_min = 0 ;
      count_time.tm_hour = 0 ;
      count_time.tm_mday = atoi(day_str) ;
      count_time.tm_mon = atoi(month_str) ;
      count_time.tm_year = atoi(year_str)-1900 ;
      count_time.tm_isdst = -1 ;
      count_time_val = (long)mktime(&count_time) ;

      /* remove "blank" choice lines */

      {
	char *s, *t ;
	new_choices = (char *)malloc(sizeof(char) * (strlen(choices)+1)) ;
	s = choices ;
	t = new_choices ;
	while (*s != '\0') {
	  while (isspace(*s)) s++ ;
	  while (*s != '\n' && *s != '\0') {
	    *t = *s ; t++ ; s++ ;
	  }
	  *t = *s ; 
	  if (*s != '\0') {
	    s++ ; t++ ;
	  }
	}
	if (new_choices[(int)strlen(new_choices)-1] == '\n')
	  new_choices[(int)strlen(new_choices)-1] = '\0' ;
      }

      for (i=0, num_choices=1 ; i < (int)strlen(new_choices) ; i++)
	if (new_choices[i] == '\n') num_choices++ ;

      sprintf(fname, "%s/%s.issues", file_prefix, set_id) ;
      fp = fopen(fname, "a") ;
      lock_file(fp) ;
      fprintf(fp, "%s\n%d\n%d\n", 
	      id_str, count_time_val, num_choices) ;
      fprintf(fp, "%s\n", multiple_choice_str) ;
      fprintf(fp, "%d\n",
	      atoi(secret_ballot_str) << 3 |
	      atoi(anon_post_str) << 2 |
	      atoi(can_change_vote_str) << 1 |
	      atoi(constant_update_str) << 0) ;
      fprintf(fp, "%s\n", short_desc) ;
      fclose(fp) ;

      sprintf(fname, "%s/%s.descriptions", file_prefix, set_id) ;
      fp = fopen(fname, "a") ;
      lock_file(fp) ;
      fprintf(fp, "BEGIN %s\n", id_str) ;
      fprintf(fp, "%s\n", long_desc) ;
      fprintf(fp, "END %s\n", id_str) ;
      fclose(fp) ;

      sprintf(fname, "%s/%s.choices", file_prefix, set_id) ;
      fp = fopen(fname, "a") ;
      lock_file(fp) ;
      fprintf(fp, "BEGIN %s\n", id_str) ;
      fprintf(fp, "%s\n", new_choices) ;
      fprintf(fp, "END %s\n", id_str) ;
      fclose(fp) ;

      printf("<title>Issue added</title>\n") ;
      printf("<h1>Issue added</h1>\n") ;

      printf("Your new issue has been added to the voting system. ") ;
      printf("You may now go to: <ul>") ;
      printf("<li>The overall ") ;
      printf("<a href=\"/FLORA/cgi/voting_list?sets_list=%s&set_id=%s\">issue list</a>",
	     sets_list, set_id) ;
      printf("<li>The new issue's ") ;
      printf("<a href=\"/FLORA/cgi/voting_issue?set_id=%s&issue_id=%s\">issue page</a>",
	     set_id, id_str) ;
      printf("</ul>") ;
      printf("or use your browser's \"back\" function to return to ") ;
      printf("where you came from.") ;
      send_mail(name, anon_post_str, count_time_val, short_desc, id_str) ;
    }
  }
}
示例#2
0
void DRP2FD(SCAN *s, XSCAN *x, FDATA *fd)
{
    int i, odin=0;
    double *pa, cp, sp, sqrBt;
#ifdef SISYFOS
    int arr_no=0;
    double NorthAz, RAOffset, DecOffset;
#endif
#ifdef ONTHEFLY
    double NorthAz, RAOffset, DecOffset;
#endif
    
    double *CheckPosAngle();
    void SetCoordType();
    int CheckCRVALType();
    void GetEquOffsets(DATE *, double, double, double, double, double, double,
                       double *, double *);
    
    if (strncmp(s->Project, "Odin", 4)==0) odin=1;
    
    strncpy(fd->sname, s->Name, 12);
    fd->sname[12] = '\0';
    strip_trailing_spaces(fd->sname);
    strncpy(fd->molecule, s->Molecule, 18);
    fd->molecule[18] = '\0';
    strip_trailing_spaces(fd->molecule);
    fd->n = (int)x->NChannel;
    fd->sno = (int)s->ScanNo;
    fd->subno = (int)s->SubScan;
    fd->coordType = s->CSystem;
    SetCoordType(s->CSystem);
    if ((pa = CheckPosAngle()))
        fd->posang = (*pa)*PI/180.0;
    else
        fd->posang = (double)s->PosAngle;
    cp = cos(fd->posang);
    sp = sin(fd->posang);
    fd->xoff = rta(s->LMapOff)*cp - rta(s->BMapOff)*sp;
    fd->yoff = rta(s->BMapOff)*cp + rta(s->LMapOff)*sp;
    fd->equinox = s->Equinox;
    if (fd->equinox <= 1950.1) {
        fd->epoch = 'B';
    } else {
        fd->epoch = 'J';
    }
    fd->y0 = s->Latitude;
    fd->x0 = s->Longitude;
    if (CheckCRVALType()) {
        fd->y0 -= s->BMapOff;
        fd->x0 -= s->LMapOff/cos(fd->y0);
    }
    fd->scanType = s->ObsMode;
    fd->tsys = (double)s->Tsys;
    fd->tau  = (double)s->Tau;
    fd->int_time = (double)s->IntTime;
    fd->vlsr = s->VSource;
    fd->date.Year  = s->Year;
    fd->date.Month = s->Month;
    fd->date.Day   = s->Day;
    fd->date.Hour  = s->UTHour;
    fd->date.Min   = s->UTMin;
    fd->date.Sec   = s->UTSec;
    fd->LST = fd->date;
    fd->LST.Hour   = s->STHour;
    fd->LST.Min    = s->STMin;
    fd->LST.Sec    = s->STSec;
    fd->az = s->Azimuth * RADTODEG;
    fd->el = s->Elevation * RADTODEG;
    fd->aoff = rta(s->AzMapOff)*cp - rta(s->ElMapOff)*sp;
    fd->eoff = rta(s->ElMapOff)*cp + rta(s->AzMapOff)*sp;
#ifdef SISYFOS
    if (sscanf(s->Program, "COR%d", &arr_no) == 1) {
        if (arr_no >=1 && arr_no <= 4) {
            fd->aoff += (SisyfosAz[arr_no] - SisyfosAz[0]);
            fd->eoff += (SisyfosEl[arr_no] - SisyfosEl[0]);
            NorthAz = s->Azimuth + PI;
            GetEquOffsets(&(fd->LST), NorthAz, s->Elevation,
                          fd->aoff, fd->eoff,
                          s->Longitude, s->Latitude,
                          &RAOffset, &DecOffset);
            fd->xoff += RAOffset;
            fd->yoff += DecOffset;
        }
    }
#endif
#ifdef ONTHEFLY
    NorthAz = s->Azimuth + PI;
    GetEquOffsets(&(fd->LST), NorthAz, s->Elevation,
                  fd->aoff, fd->eoff,
                  s->Longitude, s->Latitude,
                  &RAOffset, &DecOffset);
    fd->xoff += RAOffset;
    fd->yoff += DecOffset;
#endif
    fd->b.maj = s->StepX;
    fd->b.min = s->StepY;
    fd->b.PA  = s->ParAngle;
    fd->beameff = s->RefCorr;
    fd->pol     = s->flag[0];
    fd->TAir = s->AirTemp; 
    fd->PAir = s->Pressure; 
    fd->RAir = s->Humidity; 
    
    fd->firstIF = s->FirstIF/1000.0;
    if (x) {
        fd->lofreq = x->LOFreq/1000.0;
    } else { /* Assume OSO */
        if (s->RestFreq < 105000.0) {
            fd->lofreq = (s->RestFreq + s->FirstIF)/1000.0;
	} else {
            fd->lofreq = (s->RestFreq - s->FirstIF)/1000.0;
	}
    }
    fd->skyfreq = s->SkyFreq/1000.0;
    
    if (s->FreqRes < 0.0) {
        fd->f0 = Frequency(x->NChannel-1, s, x)/1000.;
        fd->fn = Frequency(0, s, x)/1000.;
/*         printf("f0, fn=%f,%f  RF=%f  res=%f\n", fd->f0, fd->fn, s->RestFreq, s->FreqRes);
 */
        if (odin) {
            fd->v0 = VelOdin(x->NChannel-1, s, x);
        } else {
            fd->v0 = Velocity(x->NChannel-1, s, x);
        }
        fd->fres = -s->FreqRes;
        fd->vres = -s->VelRes;
        sqrBt = sqrt(fabs(fd->fres) * fd->int_time)*1000.0;
        for (i=x->NChannel-1; i>=0; i--) {
            fd->d[x->NChannel-1-i] = (double)(s->c[i]);
            if (sqrBt > 0.0 && fd->tsys > 0.0)
                fd->e[x->NChannel-1-i] = 2.0*fd->tsys/sqrBt;
            else
                fd->e[x->NChannel-1-i] = 1.0;
        }
    } else {
        fd->fn = Frequency(x->NChannel-1, s, x)/1000.;
        fd->f0 = Frequency(0, s, x)/1000.;
        if (odin) {
            fd->v0 = VelOdin(0, s, x);
        } else {
            fd->v0 = Velocity(0, s, x);
        }
        fd->fres = s->FreqRes;
        fd->vres = s->VelRes;
        sqrBt = sqrt(fabs(fd->fres) * fd->int_time)*1000.0;
        for (i=0; i<x->NChannel; i++) {
          fd->d[i] = (double)(s->c[i]);
          if (sqrBt > 0.0 && fd->tsys > 0.0)
              fd->e[i] = 2.0*fd->tsys/sqrBt;
          else
              fd->e[i] = 1.0;
        }
    }
}