示例#1
0
void load_kv6(map_s *map, uint8_t *v, int len)
{
	kv6hdr *hdr = (kv6hdr *)v;
	uint32_t *xoffset = (uint32_t*)&hdr->blks[hdr->blklen];
	uint16_t *xyoffset = (uint16_t*)&xoffset[hdr->xsiz];
	kv6pal *pal = (kv6pal *)&xyoffset[hdr->xsiz*hdr->ysiz];
	init( map, hdr->xsiz, hdr->ysiz, hdr->zsiz );
	map->ofs[0] = hdr->xpivot;
	map->ofs[1] = hdr->ypivot;
	map->ofs[2] = hdr->zsiz - hdr->zpivot - 1;
	kv6block *block = hdr->blks;
	for ( int x=0; x<hdr->xsiz; x++ )
	{
		for ( int y=0; y<hdr->ysiz; y++ )
		{
			int num = xyoffset[x*hdr->ysiz+y];
			for ( int n=0; n<num; n++ )
			{
				setgeom( map, x, y, hdr->zsiz-block->zpos-1, 1 );
				setcolor( map, x, y, hdr->zsiz-block->zpos-1, block->color );
				block++;
			}
		}
	}
}
/* \fcnfh
   Obtains the quantity that is observable, but before being convolved
   to telescope resolution

   @returns 0 on success
            -1 if impact parameter sampling is not equispaced
 */
int
modulation(struct transit *tr)	/* Main structure */
{
    static struct outputray st_out;
    tr->ds.out=&st_out;

    transitcheckcalled(tr->pi,"modulation",3,
                       "tau",TRPI_TAU,
                       "makeipsample",TRPI_MAKEIP,
                       "makewnsample",TRPI_MAKEWN
                      );

    //initial variables and check that impact parameters was a monospaced
    //array. Stop otherwise.
    long w;
    prop_samp *ip=&tr->ips;
    prop_samp *wn=&tr->wns;
    transit_ray_solution *sol=tr->sol;
    if(ip->d==0&&sol->monoip) {
        transiterror(TERR_SERIOUS|TERR_ALLOWCONT,
                     "To compute %s modulation, the impact parameter has to\n"
                     "be an equispaced array\n"
                     ,sol->name);
        return -1;
    }

    //output and geometry variables.
    PREC_RES *out=st_out.o=(PREC_RES *)calloc(wn->n,sizeof(PREC_RES));
    struct geometry *sg=tr->ds.sg;
    struct optdepth *tau=tr->ds.tau;

    //set time to the user hinted default, and other user hints
    setgeom(sg,HUGE_VAL,&tr->pi);
    const int modlevel=tr->modlevel=tr->ds.th->modlevel;

    //integrate for each wavelength
    transitprint(1,verblevel,
                 "\nIntegrating for each wavelength...\n");

    int nextw=wn->n/10;

    for(w=0; w<wn->n; w++) {
        out[w]=sol->obsperwn(tau->t[w],tau->last[w],tau->toomuch,
                             ip,sg,modlevel);
        if(out[w]<0) {
            switch(-(int)out[w]) {
            case 1:
                if(modlevel==-1)
                    transiterror(TERR_SERIOUS,
                                 "Optical depth didn't reach limiting %g at wavenumber %g[cm-1]\n"
                                 " (Only reached %g)."
                                 " Cannot use critical radius technique (-1)\n"
                                 ,tau->toomuch,tau->t[w][tau->last[w]],wn->v[w]*wn->fct);
            default:
                transiterror(TERR_SERIOUS,
                             "There was a problem while calculating modulation\n"
                             " at wavenumber %g[cm-1]. Error code %i\n"
                             ,wn->v[w]*wn->fct,(int)out[w]);
                break;
            }
            exit(EXIT_FAILURE);
        }

        if(w==nextw) {
            nextw+=wn->n/10;
            transitprint(2,verblevel,
                         "%i%%\r"
                         ,(10*(int)(10*w/wn->n+0.9999999999)));
        }
    }
    transitprint(1,verblevel," done\n");

    //frees no longer needed memory.
    freemem_idexrefrac(tr->ds.ir,&tr->pi);
    freemem_extinction(tr->ds.ex,&tr->pi);
    freemem_tau(tr->ds.tau,&tr->pi);

    //set progress indicator, and print output
    tr->pi&=TRPI_MODULATION;
    printmod(tr);
    return 0;
}
示例#3
0
/* \fcnfh
   Calculate the transit modulation at each wavenumber
   Return: 0 on success, else
          -1 if impact parameter sampling is not equispaced                 */
int
modulation(struct transit *tr){
  struct optdepth *tau = tr->ds.tau;
  struct geometry *sg  = tr->ds.sg;
  static struct outputray st_out;
  tr->ds.out = &st_out;

  long w;
  prop_samp *ip = &tr->ips;
  prop_samp *wn = &tr->wns;
  ray_solution *sol = tr->sol;

  /* Check that impact parameter and wavenumber samples exist:              */
  transitcheckcalled(tr->pi, "modulation", 3, "tau",          TRPI_TAU,
                                              "makeipsample", TRPI_MAKEIP,
                                              "makewnsample", TRPI_MAKEWN);

  /* Allocate the modulation array:                                         */
  PREC_RES *out = st_out.o = (PREC_RES *)calloc(wn->n, sizeof(PREC_RES));

  /* Set time to the user hinted default, and other user hints:             */
  setgeom(sg, HUGE_VAL, &tr->pi);

  /* Integrate for each wavelength:                                         */
  transitprint(1, verblevel, "Integrating over wavelength.\n");

  int nextw = wn->n/10;

  /* Calculate the modulation spectrum at each wavenumber:                  */
  for(w=0; w < wn->n; w++){
    out[w] = sol->spectrum(tr, tau->t[w], wn->v[w], tau->last[w],
                           tau->toomuch, ip);
    if (out[w] < 0){
      switch(-(int)out[w]){
      case 1:
        if(tr->modlevel == -1)
          transiterror(TERR_SERIOUS, "Optical depth didn't reach limiting "
                       "%g at wavenumber %g cm-1 (only reached %g).  Cannot "
                       "use critical radius technique (-1).\n", tau->toomuch,
                       tau->t[w][tau->last[w]], wn->v[w]*wn->fct);
      default:
        transiterror(TERR_SERIOUS, "There was a problem while calculating "
                     "modulation at wavenumber %g cm-1. Error code %i.\n",
                     wn->v[w]*wn->fct, (int)out[w]);
        break;
      }
      exit(EXIT_FAILURE);
    }

    /* Print to screen the progress status:                                 */
    if(w==nextw){
      nextw += wn->n/10;
      transitprint(2, verblevel, "%i%% ", (10*(int)(10*w/wn->n+0.9999999999)));
    }
  }
  transitprint(1, verblevel, "\nDone.\n");

  /* Set progress indicator, and print output:                              */
  tr->pi |= TRPI_MODULATION;
  printmod(tr);  
  return 0;
}