Пример #1
0
int init_xrandom(string init)
{
#ifdef HAVE_GSL
    char my_gsl_type[64], my_gsl_seed[64], *cp;     /* need two strings, bug in putenv? */
    string *is;
    int nis, iseed;

    is = burststring(init,", ");                      /* parse init as "[seed[,name]]"  */
    nis = xstrlen(is,sizeof(string))-1;
    if (nis > 0) {                                          /* seed is first, but optional */
        iseed = natoi(is[0]);
	if (iseed > 0 || streq(is[0],"+0")) {
	  sprintf(my_gsl_seed,"%s=%s",env_seed,is[0]);
	} else {
	  iseed = set_xrandom(iseed);
	  sprintf(my_gsl_seed,"%s=%u",env_seed,iseed);
	}
	putenv(my_gsl_seed);
	dprintf(1,"putenv: %s\n",my_gsl_seed);
        if (nis > 1) {                                      /* name is second, also optional */
            sprintf(my_gsl_type,"%s=%s",env_type,is[1]);
            putenv(my_gsl_type);
	    dprintf(1,"putenv: %s\n",my_gsl_type);
        }
    }

    gsl_rng_env_setup();                          /* initialize the rng (name/seed) setup */
    my_T = gsl_rng_default;
    my_r = gsl_rng_alloc(my_T);


    dprintf(1,"GSL generator type: %s\n",gsl_rng_name(my_r));
    dprintf(1,"GSL seed = %u\n",gsl_rng_default_seed);
    dprintf(1,"GSL first value = %u\n",gsl_rng_get(my_r));

    return (int) gsl_rng_default_seed;
#else
    return set_xrandom(init? natoi(init) : 0);     /*  18/06/2008: allow for init=0 WD */
#endif
}
Пример #2
0
void nemo_main(void){
   int i,numwritten=0,nummissed=0;
   int numimages=0;
   stream fp_in,fp,fp2;
   string *sp,logic;
   int count,n;
   int edge_dist;             /* exclude sources this many pixels from the edge */
   string inFile;             /* name of input file */
   char line[MAX_LINELEN];    /* a line of text from the inFile */
   int racol,deccol,maxcol;   /* column numbers for ra/dec in file */
   double ra,dec;             /* the values of ra/dec for a given line */
   int nentries;              /* number of valid entries, used for progress tracking */

   inFile    = getparam("in");
   edge_dist = getiparam("edge");
   logic     = getparam("logic");

   sp = burststring(getparam("col"),", \n");
   n  = xstrlen(sp,sizeof(string)) - 1;
   if (n != 2) error("You must specify ra,dec columns for col keyword!");
   racol = natoi(sp[0]) - 1;
   deccol = natoi(sp[1]) - 1;
   freestrings(sp);
   if (racol >= deccol)
      maxcol = racol;
   else
      maxcol = deccol;


   sp = burststring(getparam("fits"),", \n");
   n  = xstrlen(sp,sizeof(string))-1;
   for (i=0; i<n; i++){
      ini_mask(sp[i],i);
      numimages++;
   }
   freestrings(sp);
   
   sp = burststring(getparam("out"),", \n");
   n  = xstrlen(sp,sizeof(string))-1;
   if (n == 1){
      fp  = stropen(sp[0],"w");
      fp2 = stropen("/dev/null","w!");
   } else if (n == 2){
      fp  = stropen(sp[0],"w");
      fp2 = stropen(sp[1],"w");
   }else
      error("You must give one or two output files!\n");
   freestrings(sp);

   nentries = nemo_file_lines(inFile,0);
   progress_init("overlap percent complete:",nentries);
   nentries = 0;
   
   fp_in = stropen(inFile,"r");
   while (fgets(line,MAX_LINELEN,fp_in)){
      progress_update(nentries);
      if (line[0] != '#'){
         nentries += 1;
         sp = burststring(line," \t\n");
         n  = xstrlen(sp,sizeof(string)) - 2; /* zero based */
         if (n < maxcol)
            error("Insufficient columns on line!");
         ra  = natof(sp[racol]);
         dec = natof(sp[deccol]);
         freestrings(sp);
         count = 0;
         for (i=0; i< numimages; i++)
            count+= is_edge(ra,dec,edge_dist,i);
         if(streq(logic,"or") && (count<numimages)){
            fprintf(fp,line);
            numwritten++;
         }
         else if(streq(logic,"and") && (count==0) && (numimages > 0)){
            fprintf(fp,line);
            numwritten++;
         }
         else {
            fprintf(fp2,line);
            nummissed++;
         }
      }
   }
   strclose(fp_in);
   strclose(fp);
   strclose(fp2);
   progress_finish();

   printf("Sources outside regions: %d\n",nummissed);
   printf("Sources inside regions: %d\n",numwritten);
   printf("Number of images: %d\n",numimages);
}
Пример #3
0
void nemo_main() {
   int i,j,nentries,ncol,nsp;
   FILE *fp;               /* File pointer for output file */
   string outfile;         /* name of output file */
   string *sp;             /* used to read the command line argument "col" */
   string wcs_type;        /* WCS projection type (can be XXX or -XXX) */
   char type[5];           /* the real WCS for worldpos() ; needs to be '-XXX' */
   int nx,ny;              /* size of map in pixels for x,y directions */
   double index,rzero;     /* parameters for powerlaw */
   double crval1,crval2;   /* center RA and DEC */
   double cdelt1,cdelt2;   /* delta RA and delta DEC for pixels */
   double crpix1,crpix2;   /* reference pixel */
   double xpix, ypix;      /* current x and y pixel position in map */
   double ra,dec;          /* ra,dec of current pixel position in map */
   double flux;            /* computed flux for each pixel */
   double radius;          /* radius, in pixels */

   /* Read command line */
   index    = getdparam("index");
   rzero    = getdparam("rzero");
   outfile  = getparam("out");
   wcs_type = getparam("type");
   if (strlen(wcs_type)==3) { /* make sure type is '-XXX' */
      type[0] = '-';
      strcpy(&type[1],wcs_type);
   } else if (strlen(wcs_type)==4) {
      if (*wcs_type == '-')
         strcpy(type,wcs_type);
      else
         error("type=%s probably not legal, should be -XXX",wcs_type);
   } else
      error("type=%s must be a valid -XXX or XXX   WCS descriptor",wcs_type);
	 
   sp  = burststring(getparam("crval")," ,");
   nsp = xstrlen(sp,sizeof(string))-1;
   if (nsp != 2)
      error("You must specify two values for the crval keyword!");
   crval1 = natof(sp[0]);
   crval2 = natof(sp[1]);
   freestrings(sp);

   sp  = burststring(getparam("naxis")," ,");
   nsp = xstrlen(sp,sizeof(string))-1;
   if (nsp != 2)
      error("You must specify two values for the naxis keyword!");
   nx = natoi(sp[0]);
   ny = natoi(sp[1]);
   freestrings(sp);
   crpix1 = nx/2.0+1;
   crpix2 = ny/2.0+1;
   
   cdelt2 = getdparam("cdelt")/3600.; 
   cdelt1 = -cdelt2;

   /* Test to make sure we can write to output file */
   fp = stropen(outfile,"w");
   strclose(fp);
   
   fprintf(stderr,"nx,ny = %d,%d\n",nx,ny);
   fprintf(stderr,"crval1,crval2=%lf,%lf\n",crval1,crval2);
   fprintf(stderr,"crpix1,crpix2=%lf,%lf\n",crpix1,crpix2);
   fprintf(stderr,"wcs: %s\n",type);

   xpix=1.0;
   ypix=1.0;
   worldpos(xpix,ypix,crval1,crval2,crpix1,crpix2,cdelt1,cdelt2,0.0,type,&ra,&dec);
   dprintf(1,"LL corner: %g %g\n",ra,dec);
   xpix=nx;
   worldpos(xpix,ypix,crval1,crval2,crpix1,crpix2,cdelt1,cdelt2,0.0,type,&ra,&dec);
   dprintf(1,"LR corner: %g %g\n",ra,dec);
   ypix=ny;
   worldpos(xpix,ypix,crval1,crval2,crpix1,crpix2,cdelt1,cdelt2,0.0,type,&ra,&dec);
   dprintf(1,"UR corner: %g %g\n",ra,dec);
   xpix=1.0;
   worldpos(xpix,ypix,crval1,crval2,crpix1,crpix2,cdelt1,cdelt2,0.0,type,&ra,&dec);
   dprintf(1,"UL corner: %g %g\n",ra,dec);


   /* Write header for TABFITS to file */
   fp = stropen(getparam("out"),"w!");
   fprintf(fp,"# NAXIS1 = %d\n",nx);
   fprintf(fp,"# NAXIS2 = %d\n",ny);
   fprintf(fp,"# NAXIS3 = 1\n");
   fprintf(fp,"# CDELT1 = %lf\n",cdelt1);
   fprintf(fp,"# CDELT2 = %lf\n",cdelt2);
   fprintf(fp,"# CRVAL1 = %lf\n",crval1);
   fprintf(fp,"# CRVAL2 = %lf\n",crval2);
   fprintf(fp,"# CRPIX1 = %f\n",crpix1);
   fprintf(fp,"# CRPIX2 = %f\n",crpix2);
   fprintf(fp,"# CTYPE1 = 'RA--%s'\n",type);
   fprintf(fp,"# CTYPE2 = 'DEC-%s'\n",type);
   fprintf(fp,"# COMMENT index=%g / powerlaw index\n",index);
   fprintf(fp,"# COMMENT rzero=%g / rzero parameter\n",rzero);
   fprintf(fp,"# COMMENT out=%s   / output table\n",outfile);
   fprintf(fp,"# COMMENT crval=%f,%f / Center WCS coordinates\n",crval1,crval2);
   fprintf(fp,"# COMMENT naxis=%d,%d / Image size in pixels\n",nx,ny);
   fprintf(fp,"# COMMENT cdelt=%f    / pixel size in arcseconds\n",cdelt2*3600);
   fprintf(fp,"# COMMENT type=%s     / Projection type\n",type);
   fprintf(fp,"# COMMENT VERSION=%s  / Version number\n",getparam("VERSION"));


   for (i=0; i< ny; i++){
      ypix = i + 1.0;
      for (j=0; j< nx; j++){
         xpix = j + 1.0;
         worldpos(xpix,ypix,crval1,crval2,crpix1,crpix2,cdelt1,cdelt2,0.0,
            type,&ra,&dec);
         radius = sqrt((xpix-crpix1)*(xpix-crpix1) + (ypix-crpix2)*(ypix-crpix2));
         flux = 1.0/(1.0 + pow(radius/rzero,index));
/*         if (radius <= 4)
            flux = 1.0;
         else
            flux = 1.0/(1.0 + pow(radius-4,index)); */
         fprintf(fp,"%lf  %lf %4.2e\n",ra,dec,flux);
      }
   }
   strclose(fp);
}