Exemple #1
0
void
print_radec(OBSERVATION *obs, FILE *fptr)
{
  /* Print out new observation */      
  /* Now transform to RA/DEC, via ecliptic*/
  double ra, dec, lat, lon;
  char rastring[20],decstring[20];
  void deghms(double degr,
	      char *outbuff);
  void degdms(double degr,
	      char *outbuff); 
  proj_to_ec(obs->thetax,obs->thetay,
	     &lat, &lon,
	     lat0, lon0, NULL);
  ec_to_eq(lat, lon, &ra, &dec, NULL);
  ra /= DTOR;
  if (ra<0.) ra+= 360.;
  dec /= DTOR;
  deghms(ra,rastring);
  degdms(dec,decstring);
  fprintf(fptr,"%.4f %s %s %5.2f %d\n", obs->obstime/DAY + jd0,
	 rastring,decstring,obs->dthetax/ARCSEC,
	 obs->obscode);
  return;
}
/******************************************************************************
MODULE:  setup_mapping

PURPOSE:  Sets up the geolocation data structure and initializes the forward
and inverse mapping functions via GCTP.

RETURN VALUE:
Type = Geoloc_t *
Value      Description
-----      -----------
NULL       Error occurred in the setup
not-NULL   Successful completion

PROJECT:  Land Satellites Data System Science Research and Development (LSRD)
at the USGS EROS

HISTORY:
Date          Programmer       Reason
----------    ---------------  -------------------------------------
1/23/2014     Gail Schmidt     Original Development (based on input routines
                               from the LEDAPS lndsr application)
4/25/2014     Gail Schmidt     Updated to support additional projections

NOTES:
1. Memory is allocated for the Geoloc_t pointer.  It is up to the calling
   routine to free the memory for this pointer.
2. Make sure the corners Space_def_t are reported as the upper left of the
   the since that's what the other routines are expecting.
******************************************************************************/
Geoloc_t *setup_mapping
(
    Space_def_t *space_def     /* I: space definition structure */
)
{
    char FUNC_NAME[] = "setup_mapping"; /* function name */
    char errmsg[STR_SIZE];              /* error message */
    char file27[] = "FILE27";           /* file for NAD27 (only for State Plane)
                                           so just use something fake for now */
    char file83[] = "FILE83";           /* file for NAD83 (only for State Plane)
                                           so just use something fake for now */
    Geoloc_t *this = NULL;              /* pointer to the space structure */
    double temp1, temp2;                /* temp variables for PS projection */
    int i;                              /* looping variable */
    int iflag;                          /* return status from GCTP */
    int (*for_trans[MAX_PROJ + 1])();   /* forward transformation function */
    int (*inv_trans[MAX_PROJ + 1])();   /* inverse transformation function */
  
    /* Verify some of the space definition parameters */
    if (space_def->img_size.l < 1) 
    {
        sprintf (errmsg, "Invalid number of lines: %d", space_def->img_size.l);
        error_handler (true, FUNC_NAME, errmsg);
        return (NULL);
    }
    if (space_def->img_size.s < 1) 
    {
        sprintf (errmsg, "Invalid number of samples per line: %d",
            space_def->img_size.s);
        error_handler (true, FUNC_NAME, errmsg);
        return (NULL);
    }

    if (space_def->pixel_size[0] <= 0.0 || space_def->pixel_size[1] <= 0.0)
    {
        sprintf (errmsg, "Invalid pixel size: %lf %lf",
            space_def->pixel_size[0], space_def->pixel_size[1]);
        error_handler (true, FUNC_NAME, errmsg);
        return (NULL);
    }

    if (space_def->proj_num < 0  ||  space_def->proj_num > MAX_PROJ)
    {
        sprintf (errmsg, "Invalid projection number: %d", space_def->proj_num);
        error_handler (true, FUNC_NAME, errmsg);
        return (NULL);
    }
  
    /* Create the geolocation data structure */
    this = malloc (sizeof (Geoloc_t));
    if (this == NULL) 
    {
        sprintf (errmsg, "Allocating geolocation data structure");
        error_handler (true, FUNC_NAME, errmsg);
        return (NULL);
    }
  
    /* Copy the space definition fields */
    this->def.pixel_size[0] = space_def->pixel_size[0];
    this->def.pixel_size[1] = space_def->pixel_size[1];
    this->def.ul_corner.x = space_def->ul_corner.x;
    this->def.ul_corner.y = space_def->ul_corner.y;
    this->def.img_size.l = space_def->img_size.l;
    this->def.img_size.s = space_def->img_size.s;
    this->def.proj_num = space_def->proj_num;
    this->def.zone = space_def->zone;
    this->def.spheroid = space_def->spheroid;
    this->def.orientation_angle = space_def->orientation_angle;
    for (i = 0; i < NPROJ_PARAM; i++) 
        this->def.proj_param[i] = space_def->proj_param[i];
  
    /* Calculate the orientation cosine/sine */
    this->sin_orien = sin (space_def->orientation_angle);
    this->cos_orien = cos (space_def->orientation_angle);
  
    /* Convert angular projection parameters to DMS the necessary projections */
    if (this->def.proj_num == GCTP_PS_PROJ ||
        this->def.proj_num == GCTP_ALBERS_PROJ)
    {
        if (!degdms (&this->def.proj_param[4], &temp1, "DEG", "LON" ) ||
            !degdms (&this->def.proj_param[5], &temp2, "DEG", "LAT" ))
        {
            free (this);
            sprintf (errmsg, "Converting PS or ALBERS angular parameters from "
                "degrees to DMS");
            error_handler (true, FUNC_NAME, errmsg);
            return (NULL);
        }
        this->def.proj_param[4] = temp1;
        this->def.proj_param[5] = temp2;
    }
    else if (this->def.proj_num == GCTP_SIN_PROJ)
    {
        if (!degdms (&this->def.proj_param[4], &temp1, "DEG", "LON" ))
        {
            free (this);
            sprintf (errmsg, "Converting SIN angular parameters from degrees "
                "to DMS");
            error_handler (true, FUNC_NAME, errmsg);
            return (NULL);
        }
        this->def.proj_param[4] = temp1;
    }
     
    /* Setup the forward transform */
    for_init (this->def.proj_num, this->def.zone, this->def.proj_param, 
        this->def.spheroid, file27, file83, &iflag, for_trans);
    if (iflag)
    {
        free (this);
        sprintf (errmsg, "Error returned from for_init");
        error_handler (true, FUNC_NAME, errmsg);
        return (NULL);
    }
    this->for_trans = for_trans[this->def.proj_num];
  
    /* Setup the inverse transform */
    inv_init (this->def.proj_num, this->def.zone, this->def.proj_param, 
        this->def.spheroid, file27, file83, &iflag, inv_trans);
    if (iflag)
    {
        free (this);
        sprintf (errmsg, "Error returned from for_init");
        error_handler (true, FUNC_NAME, errmsg);
        return (NULL);
    }
    this->inv_trans = inv_trans[this->def.proj_num];
  
    /* Successful completion */
    return (this);
}
Exemple #3
0
/******************************************************************************

MODULE:  Deg2DMS

PURPOSE:  Convert parameters from decimal degrees to DMS

RETURN VALUE:
Type = int
Value           Description
-----           -----------
TRUE            success
FALSE           failure

HISTORY:
Version  Date   Programmer       Code  Reason
-------  -----  ---------------  ----  -------------------------------------
         08/02  Gail Schmidt           Original Development

NOTES:

******************************************************************************/
int Deg2DMS
( 
    int projection_type,             /* I: see myproj_const.h for a list
                                            of projection numbers */
    double *projection_parameters    /* I/O: projection parameters */
)
{
    int status = false;              /* error status */
    double temp1, temp2, temp3, temp4, temp5;
                                     /* local temp storage for conversion */

    switch ( projection_type )
    {
        case PROJ_UTM:
            if ( degdms( &projection_parameters[0], &temp1, "DEG", "LON" )
                     != ERR_RESP &&
                 degdms( &projection_parameters[1], &temp2, "DEG", "LAT" )
                     != ERR_RESP )
            {
                projection_parameters[0] = temp1;
                projection_parameters[1] = temp2;
                status = true;
            }
            break;

        case PROJ_GEO:
        case PROJ_SPCS:
        case PROJ_IMOLL:
        case PROJ_ALASKA:
        case PROJ_GOODE:
            status = true;
            /* nothing to do */
            break;

        case PROJ_ISINUS:
        case PROJ_HAMMER:
        case PROJ_MOLL:
        case PROJ_SNSOID:
        case PROJ_MILLER:
        case PROJ_ROBIN:
        case PROJ_WAGIV:
        case PROJ_WAGVII:
            if ( degdms( &projection_parameters[4], &temp1, "DEG", "LON" )
                    != ERR_RESP )
            {
                projection_parameters[4] = temp1;
                status = true;
            }
            break;

        case PROJ_PS:
        case PROJ_LAMAZ:
        case PROJ_STEREO:
        case PROJ_MERCAT:
        case PROJ_POLYC:
        case PROJ_AZMEQD:
        case PROJ_GNOMON:
        case PROJ_ORTHO:
        case PROJ_GVNSP:
        case PROJ_EQRECT:
        case PROJ_VGRINT:
            if ( degdms( &projection_parameters[4], &temp1, "DEG", "LON" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[5], &temp2, "DEG", "LAT" )
                    != ERR_RESP )
            {
                projection_parameters[4] = temp1;
                projection_parameters[5] = temp2;
                status = true;
            }
            break;

        case PROJ_ALBERS:
        case PROJ_LAMCC:
            if ( degdms( &projection_parameters[2], &temp1, "DEG", "LAT" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[3], &temp2, "DEG", "LAT" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[4], &temp3, "DEG", "LON" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[5], &temp4, "DEG", "LAT" )
                    != ERR_RESP )
            {
                projection_parameters[2] = temp1;
                projection_parameters[3] = temp2;
                projection_parameters[4] = temp3;
                projection_parameters[5] = temp4;
                status = true;
            }
            break;

        case PROJ_TM:
            if ( degdms( &projection_parameters[4], &temp1, "DEG", "LON" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[5], &temp2, "DEG", "LAT" )
                    != ERR_RESP )
            {
                projection_parameters[4] = temp1;
                projection_parameters[5] = temp2;
                status = true;
            }
            break;

        case PROJ_EQUIDC: /* Equidistant Conic A */
            if ( degdms( &projection_parameters[2], &temp1, "DEG", "LAT" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[4], &temp2, "DEG", "LON" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[5], &temp3, "DEG", "LAT" )
                    != ERR_RESP )
            {
                projection_parameters[2] = temp1;
                projection_parameters[4] = temp2;
                projection_parameters[5] = temp3;
                status = true;
            }
            break;

        case PROJ_HOM: /* Hotin Oblique Mercator A */
            if ( degdms( &projection_parameters[5], &temp1, "DEG", "LAT" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[8], &temp2, "DEG", "LON" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[9], &temp3, "DEG", "LAT" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[10], &temp4, "DEG", "LON" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[11], &temp5, "DEG", "LAT" )
                    != ERR_RESP )
            {
                projection_parameters[5] = temp1;
                projection_parameters[8] = temp2;
                projection_parameters[9] = temp3;
                projection_parameters[10] = temp4;
                projection_parameters[11] = temp5;
                status = true;
            }
            break;

        case PROJ_SOM: /* SOM A */
            if ( degdms( &projection_parameters[3], &temp1, "DEG", "LAT" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[4], &temp2, "DEG", "LON" )
                    != ERR_RESP )
            {
                projection_parameters[3] = temp1;
                projection_parameters[4] = temp2;
                status = true;
            }
            break;

        case PROJ_OBEQA:
            if ( degdms( &projection_parameters[4], &temp1, "DEG", "LON" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[5], &temp2, "DEG", "LAT" )
                    != ERR_RESP &&
                 degdms( &projection_parameters[8], &temp3, "DEG", "LAT" )
                    != ERR_RESP )
            {
                projection_parameters[4] = temp1;
                projection_parameters[5] = temp2;
                projection_parameters[8] = temp3;
                status = true;
            }
            break;

        default:
            LOG_RETURN_ERROR("bad projection type", "Deg2DMS", false);
    }

    return (status);
}
Exemple #4
0
int
main(int argc, char *argv[])
{
  PBASIS p;
  OBSERVATION	futobs;
  struct date_time dt;
  char	inbuff[256],rastring[20],decstring[20];
  double **covar,**sigxy,a,b,PA,**derivs;
  double lat,lon,**covecl;
  double ra,dec, **coveq;
  double yr,mo,day,hr,mn,ss;
  double xx,yy,xy,bovasqrd,det;
  int i,nfields;

  int iarg=1;
  if (argc>1 && *argv[1]=='^') print_help();
  if (read_options(&iarg, argc, argv)) print_help();
  if (iarg>=argc) print_help();

  /* echo the command line to output */
  printf("#");
  for (i=0; i<argc; i++) printf(" %s",argv[i]);
  {
#include <time.h>
    time_t timettt;
    time(&timettt);
    /* note that ctime returns string with newline at end */
    printf("\n#---%s",ctime(&timettt));
  }

  sigxy = dmatrix(1,2,1,2);
  derivs = dmatrix(1,2,1,2);
  covar = dmatrix(1,6,1,6);
  covecl = dmatrix(1,2,1,2);
  coveq = dmatrix(1,2,1,2);

  if (read_abg(argv[iarg],&p,covar)) {
    fprintf(stderr, "Error input alpha/beta/gamma file %s\n",argv[iarg]);
    exit(1);
  }

  /* get observatory code */
  fprintf (stderr,"Enter observatory code:\n");
  if (fgets_nocomment(inbuff,255,stdin,NULL)==NULL
      || sscanf(inbuff,"%d",&futobs.obscode)!=1) {
    fprintf(stderr,"Error reading observatory code\n");
    exit(1);
  }
  printf("# For observations at site %d\n"
	 "#                 x/RA           y/DEC          "
	 "err_a    err_b  err_pa\n",futobs.obscode);

  fprintf (stderr,"Enter JD's or Y M D ... of observations, -1 to quit:\n");
  while ( fgets_nocomment(inbuff,255,stdin,NULL)!=NULL) {
    nfields=sscanf(inbuff,"%lf %lf %lf %lf %lf %lf",
		   &yr,&mo,&day,&hr,&mn,&ss);
    if (nfields==0 ) {
      fprintf(stderr,"Error on time spec:\n->%s\n",inbuff);
      exit(1);
    } else if (yr<0.) {
      /*done*/
      exit(0);
    } else if (nfields==1 || nfields==2) {
      /* Got a JD. (probably...)*/
      futobs.obstime = (yr-jd0)*DAY;
    } else {
      dt.y = yr;
      dt.mo = mo;
      dt.d = day;
      if (nfields>=4) dt.h = hr;  else dt.h=0.;
      if (nfields>=5) dt.mn = mn; else dt.mn=0.;
      if (nfields>=6) dt.s = ss;  else dt.s=0.;
      futobs.obstime = (date_to_jd(dt)-jd0)*DAY;
    }

    futobs.xe = -999.;		/* Force evaluation of earth3d */

    printf("At time= %s",inbuff);

    predict_posn(&p,covar,&futobs,sigxy);

    printf("# Solar Elongation = %.2f Opp angle = %.2f\n",
	   elongation(&futobs)/DTOR,opposition_angle(&futobs)/DTOR);

    /* Compute a, b, theta of error ellipse for output */
    xx = sigxy[1][1];
    yy = sigxy[2][2];
    xy = sigxy[1][2];
    PA = 0.5 * atan2(2.*xy,(xx-yy)) * 180./PI;	/*go right to degrees*/
    /* Adjust for PA to be N through E, */
    PA = PA-90;
    if (PA<-90.) PA += 180.;
    bovasqrd  = (xx+yy-sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) 
      / (xx+yy+sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) ;
    det = xx*yy-xy*xy;
    b = pow(det*bovasqrd,0.25);
    a = pow(det/bovasqrd,0.25);

    printf("Cum. ecliptic posn: %10.4f %10.4f   %8.2f %8.2f %7.2f\n",
	   futobs.thetax/ARCSEC, futobs.thetay/ARCSEC,
	   a/ARCSEC,b/ARCSEC,PA); 

    /* Now transform to RA/DEC, via ecliptic*/
    proj_to_ec(futobs.thetax,futobs.thetay,
	       &lat, &lon,
	       lat0, lon0, derivs);
    /* map the covariance */
    covar_map(sigxy, derivs, covecl, 2, 2);

    /* Now to ICRS: */
    ec_to_eq(lat, lon, &ra, &dec, derivs);
    /* map the covariance */
    covar_map(covecl, derivs, coveq, 2, 2);

    /* Compute a, b, theta of error ellipse for output */
    xx = coveq[1][1]*cos(dec)*cos(dec);
    xy = coveq[1][2]*cos(dec);
    yy = coveq[2][2];
    PA = 0.5 * atan2(2.*xy,(xx-yy)) * 180./PI;	/*go right to degrees*/
    /* Put PA N through E */
    PA = 90.-PA;
    bovasqrd  = (xx+yy-sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) 
      / (xx+yy+sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) ;
    det = xx*yy-xy*xy;
    b = pow(det*bovasqrd,0.25);
    a = pow(det/bovasqrd,0.25);

    ra /= DTOR;
    if (ra<0.) ra+= 360.;
    dec /= DTOR;
    deghms(ra,rastring);
    degdms(dec,decstring);
    printf("ICRS position: %s %s %10.4f %10.4f %7.2f\n",
	   rastring,decstring,a/ARCSEC,b/ARCSEC,PA); 
  }
  exit(0);
}