示例#1
0
/* -------------------------------------------------------------------------- */
void set_proj()
{
  double psx;
  double cell;
  double cell2;
  double r;
  double phictr;

  dddd = cntrj0 * pj.cds;
  sign = (pj.cenlat >= 0.0) ? 1.0 : -1.0;
  xn = 0.0;
  psi1 = 0.0;
  pole = sign*90.0;
  psi0 = (pole - pj.cenlat) * DEG_TO_RAD;
  if (pj.code == LAMBERT)
  {
    xn = log10(cosd(pj.stdlat1)) - log10(cosd(pj.stdlat2));
    xn = xn/(log10(tand(45.0-sign*pj.stdlat1*0.50)) -
             log10(tand(45.0-sign*pj.stdlat2*0.50)));
    psi1 = (90.0-sign*pj.stdlat1) * DEG_TO_RAD;
    psi1 = sign*psi1;
  }
  else if (pj.code == POLAR)
  {
    xn = 1.0;
    psi1 = (90.0-sign*pj.stdlat1) * DEG_TO_RAD;
    psi1 = sign*psi1;
  }
  if (pj.code != MERCATOR)
  {
    psx = (pole-pj.cenlat) * DEG_TO_RAD;
    if (pj.code == LAMBERT)
    {
      cell = RADIUS_EARTH*sin(psi1)/xn;
      cell2 = tan(psx*0.50) / tan(psi1*0.50);
    }
    else
    {
      cell = RADIUS_EARTH*sin(psx)/xn;
      cell2 = (1.0 + cos(psi1))/(1.0 + cos(psx));
    }
    r = cell*pow(cell2,xn);
    xcntr = 0.0;
    ycntr = -r;
    xc = 0.0;
    yc = -RADIUS_EARTH/xn*sin(psi1)*pow(tan(psi0*0.5)/tan(psi1*0.5),xn);
  }
  else {
    c2 = RADIUS_EARTH*cos(psi1);
    xcntr = 0.0;
    phictr = pj.cenlat * DEG_TO_RAD;
    cell = cos(phictr)/(1.0+sin(phictr));
    ycntr = -c2*log(cell);
    xc = xcntr;
    yc = ycntr;
  }
  return;
}
示例#2
0
/*	FUNCTION:		GLCreatePerspectiveMatrix
	ARGUMENTS:		m			destination matrix
					fov			field of view
					aspect		aspect ratio
					znear		near plane
					zfar		far plane
	RETURN:			n/a
	DESCRIPTION:	Same as gluPerspective
*/
void GLCreatePerspectiveMatrix(float *m, float fov, float aspect, float znear, float zfar)
{
	const float h = 1.0f/tand(fov/2.0f);
	float neg_depth = znear-zfar;
	
	m[0] = h / aspect;
	m[1] = 0;
	m[2] = 0;
	m[3] = 0;

	m[4] = 0;
	m[5] = h;
	m[6] = 0;
	m[7] = 0;

	m[8] = 0;
	m[9] = 0;
	m[10] = (zfar + znear)/neg_depth;
	m[11] = -1;

	m[12] = 0;
	m[13] = 0;
	m[14] = 2.0f*(znear*zfar)/neg_depth;
	m[15] = 0;
}
示例#3
0
/*
** The HAE to HEEQ transformation is given by the matrix
**
** 	S2 = <theta0,Z>*<i,X>*<Omega,Z>
**
** where the rotation angle theta0 is the the longitude of the Sun's
** central meridian, i is the the inclination of the Sun's equator and
** Omega is the the ecliptic longitude of the ascending node of the Sun's
** equator. This transformation comprises a rotation in the plane of the
** ecliptic from the First Point of Aries to the ascending node of the
** solar equator, then a rotation from the plane of the ecliptic to the 
** plane of the equator and finally a rotation in the plane of the solar
** equator from the ascending node to the central meridian. 
**
** Implemented by Kristi Keller on 2/2/2004
*/
void
mat_S2(const double et, Mat mat)
{
  Mat mat_tmp;
  double Omega = 73.6667+0.013958*(MJD(et)+3242)/365.25;
  double theta0 = atand(cosd(7.25) * tand(lambda0(et)-Omega));
  double angle_1 = lambda0(et)-Omega;
  angle_1=fmod(angle_1,360.0);
  if (angle_1 < 0.0) angle_1+=360.0;

  theta0=fmod(theta0,360.0);
  if (theta0 < 0.0) theta0+=360.0;
  if (angle_1 < 180.0) {
      if (theta0 < 180.0) theta0+=180.0;
       }
  if (angle_1 > 180.0) {
      if (theta0 > 180.0) theta0-=180.0;
       }
  hapgood_matrix(theta0, Z, mat);

  hapgood_matrix(7.25, X, mat_tmp);
  mat_times_mat(mat, mat_tmp, mat);

  hapgood_matrix(Omega, Z, mat_tmp);
  mat_times_mat(mat, mat_tmp, mat);
}
/* p. 185, 28.3 */
double EquationOfTime( double centuryTime)
{
    double epsilon = ObliquityCorrection( centuryTime);
    double y = tand(epsilon/2.0);
    y *=y;

    double l0 = GeometricMeanLongitudeSun( centuryTime);
    double e = EccentricityEarth( centuryTime);
    double m = GeometricMeanAnomalySun( centuryTime);

    l0 = DEG2RAD(l0);
    double l0x2 = l0 + l0;
    double l0x4 = l0x2 + l0x2;

    m = DEG2RAD(m);
    double sinm = sin(m);
    double mx2 = m + m;

    double ex2 = e + e;

    double eRad = y * sin(l0x2) - ex2 * sinm + 2 * ex2 * y * sinm * cos(l0x2) -
        0.5 * y * y * sin(l0x4) - 1.25 * e * e * sin(mx2);

    /* convert radians to degrees to minutes of time */
    return DEG2MIN(RAD2DEG(eRad));
}
示例#5
0
void geodtgc(int iopt,double *gdlat,double *gdlon,
             double *grho,double *glat,
			 double *glon,double *del) {

   double a=6378.16;
   double f=1.0/298.25;
   double b,e2;

   b=a*(1.0-f);
   e2=(a*a)/(b*b)-1;
   if (iopt>0) {
     *glat=atand( (b*b)/(a*a)*tand(*gdlat));
     *glon=*gdlon;
     if (*glon > 180) *glon=*glon-360;
   } else {
     *gdlat=atand( (a*a)/(b*b)*tand(*glat));
     *gdlon=*glon;
   }
   *grho=a/sqrt(1.0+e2*sind(*glat)*sind(*glat));
   *del=*gdlat-*glat;
}
示例#6
0
static double* setMatPerspective(double *mat, double fov) {
	// http://stackoverflow.com/questions/6060169/is-this-a-correct-perspective-fov-matrix
	
	double ys = 1. / tand(fov/2.);
	double xs = ys*aspect;
	
	set16(mat,
		xs,0,0,0,
		0,ys,0,0,
		0,0,(far+near)/(near-far),2*far*near/(near-far),
		0,0,-1,0);
	
	return mat;	
}
示例#7
0
void scan_to_latlon(meta_parameters *meta,
        double x, double y, double z,
        double *lat_d, double *lon, double *height)
{
  double qlat, qlon;
  double lat,radius;
  vector pos;
  meta_projection *proj = meta->projection;

  if (z != 0.0) {
    // height correction applies directly to y (range direction)
    double line, samp;
    line = (y-proj->startY)/proj->perY - meta->general->start_line;
    samp = (x-proj->startX)/proj->perX - meta->general->start_sample;
    double sr = meta_get_slant(meta,line,samp);
    double er = proj->param.atct.rlocal;
    double ht = meta_get_sat_height(meta,line,samp);
    double cos_ang = (sr*sr + er*er - ht*ht)/(2.0*sr*er);
    if (cos_ang > 1) cos_ang = 1;
    if (cos_ang < -1) cos_ang = -1;
    double incid = PI-acos(cos_ang);
    x += z*tan(PI/2-incid);
  }

  if (meta->sar->look_direction=='R')
    qlat = -x/proj->param.atct.rlocal; /* Right looking sar */
  else
    qlat =  x/proj->param.atct.rlocal; /* Left looking sar */
  qlon = y/(proj->param.atct.rlocal*cos(qlat));

  sph2cart(proj->param.atct.rlocal, qlat, qlon, &pos);

  rotate_z(&pos,-proj->param.atct.alpha3);
  rotate_y(&pos,-proj->param.atct.alpha2);
  rotate_z(&pos,-proj->param.atct.alpha1);

  cart2sph(pos,&radius,&lat,lon);
  *lon *= R2D;
  lat *= R2D;
  *lat_d = atand(tand(lat) / (1-ecc2(proj->re_minor,proj->re_major)));
  *height = z;  // FIXME: Do we need to correct the height at all?
}
示例#8
0
int main (int argc, char *argv[]){
	if (argc != 2){
		printf("Give a parameter file.\n");
		exit(1);
	}
	int SpaceGrp;
	double LatC[6], wl, Lsd, MaxRingRad;
	char *ParamFN;
    FILE *fileParam;
    ParamFN = argv[1];
    char aline[1000];
    fileParam = fopen(ParamFN,"r");
    char *str, dummy[1000];
    int LowNr;
    while (fgets(aline,1000,fileParam)!=NULL){
        str = "SpaceGroup ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %d", dummy, &SpaceGrp);
            continue;
        }
        str = "LatticeConstant ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf %lf %lf %lf %lf %lf", dummy, &LatC[0],
					&LatC[1], &LatC[2], &LatC[3], &LatC[4], &LatC[5]);
            continue;
        }
        str = "LatticeParameter ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf %lf %lf %lf %lf %lf", dummy, &LatC[0],
					&LatC[1], &LatC[2], &LatC[3], &LatC[4], &LatC[5]);
            continue;
        }
        str = "Wavelength ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf", dummy, &wl);
            continue;
        }
        str = "Lsd ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf", dummy, &Lsd);
            continue;
        }
        str = "MaxRingRad ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf", dummy, &MaxRingRad);
            continue;
        }
	}
	printf("%f %f %f %d %f %f %f %f %f %f\n",wl,Lsd,MaxRingRad,SpaceGrp,LatC[0],LatC[1],LatC[2],LatC[3],LatC[4],LatC[5]);
	int h, k, l, iList, restriction, M, i, j;
	int Minh, Mink, Minl;
	int CCMx_PL[9], deterCCMx_LP = 0;
	double Epsilon = 0.0001;
	int Families[50000][3];
	T_SgInfo *SgInfo;
	char SgName[200]; 
	int F_Convention='A';
	const T_TabSgName *tsgn; 
	
	printf("Generating hkl's\n");
	if((SgInfo = (T_SgInfo *)malloc(sizeof(T_SgInfo)))==NULL){
		printf("Unable to allocate SgInfo\n");
		printf("Aborting\n");
		exit(1);
	}
	SgInfo->GenOption = 0;
	SgInfo->MaxList   = 192;
	if((SgInfo->ListSeitzMx = (T_RTMx*)malloc(SgInfo->MaxList * sizeof(T_RTMx)))==NULL){
		printf("Unable to allocate (SgInfo.ListSeitzMx\n");
		printf("Aborting\n");
		exit(1);
	}
	SgInfo->ListRotMxInfo = NULL;
	InitSgInfo(SgInfo);
	sprintf(SgName,"%d",SpaceGrp);
	tsgn = FindTabSgNameEntry(SgName, F_Convention);
	if (tsgn == NULL){
		printf("Error: Unknown Space Group Symbol\n");
		printf("Aborting\n");
		exit(1);
	}
	sprintf(SgName,"%s",tsgn->HallSymbol);
	SgInfo->TabSgName = tsgn;
	if (tsgn) SgInfo->GenOption = 1;
	{
		int pos_hsym;
		pos_hsym = ParseHallSymbol(SgName, SgInfo);
		
		if (SgError != NULL) {
			printf("Error: Unknown Space Group Symbol\n");
			printf("Aborting\n");
			exit(1);
		}
	}
	if(CompleteSgInfo(SgInfo)!=0) {
		printf("Error in Complete\n");
		printf("Aborting\n");
		exit(1);
	}
	if (SgInfo->LatticeInfo->Code != 'P')
	{
		deterCCMx_LP = deterRotMx(SgInfo->CCMx_LP);
		InverseRotMx(SgInfo->CCMx_LP, CCMx_PL);
		if (deterCCMx_LP < 1) {
			printf("deterCMM failed.\n");
			return 0;
		}
	}
	int Maxh, Maxk, Maxl;
	int nrFilled=0;
	Maxh = 10;
	Maxk = 10;
	Maxl = 10;
	SetListMin_hkl(SgInfo, Maxk, Maxl, &Minh, &Mink, &Minl);
	printf("Will go from %d to %d in h; %d to %d in k; %d to %d in l.\n",Minh, Maxh, Mink, Maxk, Minl, Maxl);
	for (h = Minh; h <= Maxh; h++){
		for (k = Mink; k <= Maxk; k++){
			for (l = Minl; l <= Maxl; l++){
				if (h==0 && k==0 && l==0){
					continue;
				}
				iList = IsSysAbsent_hkl(SgInfo, h, k, l, &restriction);
				if (SgError != NULL) {
					printf("IsSysAbsent_hkl failed.\n");
					return 0;
				}
				if (iList == 0){
					if ((iList = IsSuppressed_hkl(SgInfo, Minh, Mink, Minl,
						Maxk, Maxl, h, k, l)) != 0) {/* Suppressed reflections */
					} else {
						//printf("New plane.\n");
						T_Eq_hkl Eq_hkl;
						M = BuildEq_hkl(SgInfo, &Eq_hkl, h, k, l);
						if (SgError != NULL){
							return 0;
						}
						for (i=0;i<Eq_hkl.N;i++){
							for (j=-1;j<=1;j+=2){
								//printf("%d %d %d\n",Eq_hkl.h[i]*j,Eq_hkl.k[i]*j,Eq_hkl.l[i]*j);
								Families[nrFilled][0] = Eq_hkl.h[i]*j;
								Families[nrFilled][1] = Eq_hkl.k[i]*j;
								Families[nrFilled][2] = Eq_hkl.l[i]*j;
								nrFilled++;
							}
						}
					}
				}
			}
		}
	}
	int AreDuplicates[50000];
	double **UniquePlanes;
	UniquePlanes = allocMatrix(50000,3);
	for (i=0;i<50000;i++) AreDuplicates[i] = 0;
	int nrPlanes=0;
	for (i=0;i<nrFilled-1;i++){
		if (AreDuplicates[i] == 1){
			continue;
		}
		for (j=i+1;j<nrFilled;j++){
			if (Families[i][0] == Families[j][0] && 
				Families[i][1] == Families[j][1] && 
				Families[i][2] == Families[j][2] &&
				AreDuplicates[j] == 0){
					AreDuplicates[j] = 1;
			}
		}
		UniquePlanes[nrPlanes][0] = (double)Families[i][0];
		UniquePlanes[nrPlanes][1] = (double)Families[i][1];
		UniquePlanes[nrPlanes][2] = (double)Families[i][2];
		nrPlanes++;
	}
	double **hkls;
	hkls = allocMatrix(nrPlanes,12);
	CorrectHKLsLatC(LatC,UniquePlanes,nrPlanes,hkls);
	SortFunc(nrPlanes,11,hkls,3,-1);
	double DsMin = wl/(2*sind((atand(MaxRingRad/Lsd))/2));
	for (i=0;i<nrPlanes;i++){
		if (hkls[i][3] < DsMin){
			nrPlanes = i;
			break;
		}
	}
	int RingNr = 1;
	double DsTemp = hkls[0][3];
	hkls[0][4] = 1;
	hkls[0][8] = asind(wl/(2*(hkls[0][3])));
	hkls[0][9] = hkls[0][8]*2;
	hkls[0][10] = Lsd*tand(hkls[0][9]);
	for (i=1;i<nrPlanes;i++){
		if (fabs(hkls[i][3] - DsTemp) < Epsilon){
			hkls[i][4] = RingNr;
		}else{
			DsTemp = hkls[i][3];
			RingNr++;
			hkls[i][4] = RingNr;
		}
		hkls[i][8] = asind(wl/(2*(hkls[i][3])));
		hkls[i][9] = hkls[i][8]*2;
		hkls[i][10] = Lsd*tand(hkls[i][9]);
	}
	char *fn = "hkls.csv";
	FILE *fp;
	fp = fopen(fn,"w");
	fprintf(fp,"h k l D-spacing RingNr\n");
	for (i=0;i<nrPlanes;i++){
		fprintf(fp,"%.0f %.0f %.0f %f %.0f %f %f %f %f %f %f\n",hkls[i][0],
			hkls[i][1],hkls[i][2],hkls[i][3],hkls[i][4],
			hkls[i][5],hkls[i][6],hkls[i][7],hkls[i][8],
			hkls[i][9],hkls[i][10]);
	}
}
示例#9
0
文件: spc.c 项目: anizami/astropy
int spcs2x(
  struct spcprm *spc,
  int nspec,
  int sspec,
  int sx,
  const double spec[],
  double x[],
  int stat[])

{
  static const char *function = "spcs2x";

  int statP2X, status = 0, statS2P;
  double beta, s;
  register int ispec;
  register int *statp;
  register const double *specp;
  register double *xp;
  struct wcserr **err;

  /* Initialize. */
  if (spc == 0x0) return SPCERR_NULL_POINTER;
  err = &(spc->err);

  if (spc->flag == 0) {
    if ((status = spcset(spc))) return status;
  }

  /* Apply the linear step of the algorithm chain to convert the S-type */
  /* spectral variable to P-type intermediate spectral variable.        */
  if (spc->spxS2P) {
    if ((statS2P = spc->spxS2P(spc->w[0], nspec, sspec, sx, spec, x, stat))) {
      if (statS2P == SPXERR_BAD_INSPEC_COORD) {
        status = SPCERR_BAD_SPEC;
      } else if (statS2P == SPXERR_BAD_SPEC_PARAMS) {
        return wcserr_set(WCSERR_SET(SPCERR_BAD_SPEC_PARAMS),
          "Invalid spectral parameters: Frequency or wavelength is 0");
      } else {
        return wcserr_set(SPC_ERRMSG(spc_spxerr[statS2P]));
      }
    }

  } else {
    /* Just a copy. */
    xp = x;
    specp = spec;
    statp = stat;
    for (ispec = 0; ispec < nspec; ispec++, specp += sspec, xp += sx) {
      *xp = *specp;
      *(statp++) = 0;
    }
  }


  /* Apply the non-linear step of the algorithm chain to convert P-type */
  /* intermediate spectral variable to X-type spectral variable. */
  if (spc->spxP2X) {
    if ((statP2X = spc->spxP2X(spc->w[0], nspec, sx, sx, x, x, stat))) {
      if (statP2X == SPCERR_BAD_SPEC) {
        status = SPCERR_BAD_SPEC;
      } else if (statP2X == SPXERR_BAD_SPEC_PARAMS) {
        return wcserr_set(WCSERR_SET(SPCERR_BAD_SPEC_PARAMS),
          "Invalid spectral parameters: Frequency or wavelength is 0");
      } else {
        return wcserr_set(SPC_ERRMSG(spc_spxerr[statP2X]));
      }
    }
  }

  if (spc->isGrism) {
    /* Convert X-type spectral variable (wavelength) to grism parameter. */
    xp = x;
    statp = stat;
    for (ispec = 0; ispec < nspec; ispec++, xp += sx, statp++) {
      if (*statp) continue;

      s = *xp/spc->w[5] - spc->w[4];
      if (fabs(s) <= 1.0) {
        beta = asind(s);
        *xp = tand(beta - spc->w[3]);
      } else {
        *statp = 1;
      }
    }
  }


  /* Convert X-type spectral variable to intermediate world coordinate x. */
  xp = x;
  statp = stat;
  for (ispec = 0; ispec < nspec; ispec++, xp += sx) {
    if (*(statp++)) continue;

    *xp -= spc->w[1];
    *xp /= spc->w[2];
  }

  if (status) {
    wcserr_set(SPC_ERRMSG(status));
  }
  return status;
}
示例#10
0
文件: spc.c 项目: anizami/astropy
int spcset(struct spcprm *spc)

{
  static const char *function = "spcset";

  char   ctype[9], ptype, xtype;
  int    restreq, status;
  double alpha, beta_r, crvalX, dn_r, dXdS, epsilon, G, m, lambda_r, n_r,
         t, restfrq, restwav, theta;
  struct wcserr **err;

  if (spc == 0x0) return SPCERR_NULL_POINTER;
  err = &(spc->err);

  if (undefined(spc->crval)) {
    return wcserr_set(WCSERR_SET(SPCERR_BAD_SPEC_PARAMS),
      "Spectral crval is undefined");
  }

  memset((spc->type)+4, 0, 4);
  spc->code[3] = '\0';
  wcsutil_blank_fill(4, spc->type);
  wcsutil_blank_fill(3, spc->code);
  spc->w[0] = 0.0;


  /* Analyse the spectral axis type. */
  memset(ctype, 0, 9);
  strncpy(ctype, spc->type, 4);
  if (*(spc->code) != ' ') {
    sprintf(ctype+4, "-%s", spc->code);
  }
  restfrq = spc->restfrq;
  restwav = spc->restwav;
  if ((status = spcspxe(ctype, spc->crval, restfrq, restwav, &ptype, &xtype,
                        &restreq, &crvalX, &dXdS, &(spc->err)))) {
    return status;
  }

  /* Satisfy rest frequency/wavelength requirements. */
  if (restreq) {
    if (restreq == 3 && restfrq == 0.0 && restwav == 0.0) {
      /* VRAD-V2F, VOPT-V2W, and ZOPT-V2W require the rest frequency or */
      /* wavelength for the S-P and P-X transformations but not for S-X */
      /* so supply a phoney value. */
      restwav = 1.0;
    }

    if (restfrq == 0.0) {
      restfrq = C/restwav;
    } else {
      restwav = C/restfrq;
    }

    if (ptype == 'F') {
      spc->w[0] = restfrq;
    } else if (ptype != 'V') {
      spc->w[0] = restwav;
    } else {
      if (xtype == 'F') {
        spc->w[0] = restfrq;
      } else {
        spc->w[0] = restwav;
      }
    }
  }

  spc->w[1] = crvalX;
  spc->w[2] = dXdS;


  /* Set pointers-to-functions for the linear part of the transformation. */
  if (ptype == 'F') {
    if (strcmp(spc->type, "FREQ") == 0) {
      /* Frequency. */
      spc->flag = FREQ;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;

    } else if (strcmp(spc->type, "AFRQ") == 0) {
      /* Angular frequency. */
      spc->flag = AFRQ;
      spc->spxP2S = freqafrq;
      spc->spxS2P = afrqfreq;

    } else if (strcmp(spc->type, "ENER") == 0) {
      /* Photon energy. */
      spc->flag = ENER;
      spc->spxP2S = freqener;
      spc->spxS2P = enerfreq;

    } else if (strcmp(spc->type, "WAVN") == 0) {
      /* Wave number. */
      spc->flag = WAVN;
      spc->spxP2S = freqwavn;
      spc->spxS2P = wavnfreq;

    } else if (strcmp(spc->type, "VRAD") == 0) {
      /* Radio velocity. */
      spc->flag = VRAD;
      spc->spxP2S = freqvrad;
      spc->spxS2P = vradfreq;
    }

  } else if (ptype == 'W') {
    if (strcmp(spc->type, "WAVE") == 0) {
      /* Vacuum wavelengths. */
      spc->flag = WAVE;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;

    } else if (strcmp(spc->type, "VOPT") == 0) {
      /* Optical velocity. */
      spc->flag = VOPT;
      spc->spxP2S = wavevopt;
      spc->spxS2P = voptwave;

    } else if (strcmp(spc->type, "ZOPT") == 0) {
      /* Redshift. */
      spc->flag = ZOPT;
      spc->spxP2S = wavezopt;
      spc->spxS2P = zoptwave;
    }

  } else if (ptype == 'A') {
    if (strcmp(spc->type, "AWAV") == 0) {
      /* Air wavelengths. */
      spc->flag = AWAV;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;
    }

  } else if (ptype == 'V') {
    if (strcmp(spc->type, "VELO") == 0) {
      /* Relativistic velocity. */
      spc->flag = VELO;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;

    } else if (strcmp(spc->type, "BETA") == 0) {
      /* Velocity ratio (v/c). */
      spc->flag = BETA;
      spc->spxP2S = velobeta;
      spc->spxS2P = betavelo;
    }
  }


  /* Set pointers-to-functions for the non-linear part of the spectral */
  /* transformation.                                                   */
  spc->isGrism = 0;
  if (xtype == 'F') {
    /* Axis is linear in frequency. */
    if (ptype == 'F') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;

    } else if (ptype == 'W') {
      spc->spxX2P = freqwave;
      spc->spxP2X = wavefreq;

    } else if (ptype == 'A') {
      spc->spxX2P = freqawav;
      spc->spxP2X = awavfreq;

    } else if (ptype == 'V') {
      spc->spxX2P = freqvelo;
      spc->spxP2X = velofreq;
    }

    spc->flag += F2S;

  } else if (xtype == 'W' || xtype == 'w') {
    /* Axis is linear in vacuum wavelengths. */
    if (ptype == 'F') {
      spc->spxX2P = wavefreq;
      spc->spxP2X = freqwave;

    } else if (ptype == 'W') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;

    } else if (ptype == 'A') {
      spc->spxX2P = waveawav;
      spc->spxP2X = awavwave;

    } else if (ptype == 'V') {
      spc->spxX2P = wavevelo;
      spc->spxP2X = velowave;
    }

    if (xtype == 'W') {
      spc->flag += W2S;
    } else {
      /* Grism in vacuum. */
      spc->isGrism = 1;
      spc->flag += GRI;
    }

  } else if (xtype == 'A' || xtype == 'a') {
    /* Axis is linear in air wavelengths. */
    if (ptype == 'F') {
      spc->spxX2P = awavfreq;
      spc->spxP2X = freqawav;

    } else if (ptype == 'W') {
      spc->spxX2P = awavwave;
      spc->spxP2X = waveawav;

    } else if (ptype == 'A') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;

    } else if (ptype == 'V') {
      spc->spxX2P = awavvelo;
      spc->spxP2X = veloawav;
    }

    if (xtype == 'A') {
      spc->flag += A2S;
    } else {
      /* Grism in air. */
      spc->isGrism = 2;
      spc->flag += GRA;
    }

  } else if (xtype == 'V') {
    /* Axis is linear in relativistic velocity. */
    if (ptype == 'F') {
      spc->spxX2P = velofreq;
      spc->spxP2X = freqvelo;

    } else if (ptype == 'W') {
      spc->spxX2P = velowave;
      spc->spxP2X = wavevelo;

    } else if (ptype == 'A') {
      spc->spxX2P = veloawav;
      spc->spxP2X = awavvelo;

    } else if (ptype == 'V') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;
    }

    spc->flag += V2S;
  }


  /* Check for grism axes. */
  if (spc->isGrism) {
    /* Axis is linear in "grism parameter"; work in wavelength. */
    lambda_r = crvalX;

    /* Set defaults. */
    if (undefined(spc->pv[0])) spc->pv[0] = 0.0;
    if (undefined(spc->pv[1])) spc->pv[1] = 0.0;
    if (undefined(spc->pv[2])) spc->pv[2] = 0.0;
    if (undefined(spc->pv[3])) spc->pv[3] = 1.0;
    if (undefined(spc->pv[4])) spc->pv[4] = 0.0;
    if (undefined(spc->pv[5])) spc->pv[5] = 0.0;
    if (undefined(spc->pv[6])) spc->pv[6] = 0.0;

    /* Compute intermediaries. */
    G       = spc->pv[0];
    m       = spc->pv[1];
    alpha   = spc->pv[2];
    n_r     = spc->pv[3];
    dn_r    = spc->pv[4];
    epsilon = spc->pv[5];
    theta   = spc->pv[6];

    t = G*m/cosd(epsilon);
    beta_r = asind(t*lambda_r - n_r*sind(alpha));

    t -= dn_r*sind(alpha);

    spc->w[1] = -tand(theta);
    spc->w[2] *= t / (cosd(beta_r)*cosd(theta)*cosd(theta));
    spc->w[3] = beta_r + theta;
    spc->w[4] = (n_r - dn_r*lambda_r)*sind(alpha);
    spc->w[5] = 1.0 / t;
  }

  return 0;
}
示例#11
0
void GWcsMER::prj_s2x(int nphi, int ntheta, int spt, int sxy,
                      const double* phi, const double* theta,
                      double* x, double* y, int* stat) const
{
    // Initialize projection if required
    if (!m_prjset) {
        prj_set();
    }

    // Set value replication length mphi,mtheta
    int mphi;
    int mtheta;
    if (ntheta > 0) {
        mphi   = nphi;
        mtheta = ntheta;
    } 
    else {
        mphi   = 1;
        mtheta = 1;
        ntheta = nphi;
    }

    // Initialise status code and statistics
    int status    = 0;
    int n_invalid = 0;

    // Do phi dependence
    const double* phip   = phi;
    int           rowoff = 0;
    int           rowlen = nphi * sxy;
    for (int iphi = 0; iphi < nphi; ++iphi, rowoff += sxy, phip += spt) {
        double  xi = m_w[0] * (*phip) - m_x0;
        double* xp = x + rowoff;
        for (int itheta = 0; itheta < mtheta; ++itheta, xp += rowlen) {
            *xp = xi;
        }
    }


    // Do theta dependence
    const double* thetap = theta;
    double*       yp     = y;
    int*          statp  = stat;
    for (int itheta = 0; itheta < ntheta; ++itheta, thetap += spt) {
        double eta;
        int    istat = 0;
        if (*thetap <= -90.0 || *thetap >= 90.0) {
            eta    = 0.0;
            istat  = 1;
            status = 3;
            n_invalid++;
        } else {
            eta = m_r0 * std::log(tand((*thetap+90.0)/2.0)) - m_y0;
        }
        for (int iphi = 0; iphi < mphi; ++iphi, yp += sxy) {
            *yp = eta;
            *(statp++) = istat;
        }
    }
    
    // Return
    return;
}
示例#12
0
int spcs2x(
   struct spcprm *spc,
   int nspec,
   int sspec,
   int sx,
   const double spec[],
   double x[],
   int stat[])

{
   int statP2X, status = 0, statS2P;
   double beta, s;
   register int ispec;
   register int *statp;
   register const double *specp;
   register double *xp;


   /* Initialize. */
   if (spc == 0) return 1;
   if (spc->flag == 0) {
      if (spcset(spc)) return 2;
   }

   /* Apply the linear step of the algorithm chain to convert the S-type */
   /* spectral variable to P-type intermediate spectral variable.        */
   if (spc->spxS2P != 0) {
      if (statS2P = spc->spxS2P(spc->w[0], nspec, sspec, sx, spec, x, stat)) {
         if (statS2P == 4) {
            status = 4;
         } else {
            return statS2P;
         }
      }

   } else {
      /* Just a copy. */
      xp = x;
      specp = spec;
      statp = stat;
      for (ispec = 0; ispec < nspec; ispec++, specp += sspec, xp += sx) {
         *xp = *specp;
         *(statp++) = 0;
      }
   }


   /* Apply the non-linear step of the algorithm chain to convert P-type */
   /* intermediate spectral variable to X-type spectral variable. */
   if (spc->spxP2X != 0) {
      if (statP2X = spc->spxP2X(spc->w[0], nspec, sx, sx, x, x, stat)) {
         if (statP2X == 4) {
            status = 4;
         } else {
            return statP2X;
         }
      }
   }

   if (spc->isGrism) {
      /* Convert X-type spectral variable (wavelength) to grism parameter. */
      xp = x;
      statp = stat;
      for (ispec = 0; ispec < nspec; ispec++, xp += sx, statp++) {
         if (*statp) continue;

         s = *xp/spc->w[5] - spc->w[4];
         if (fabs(s) <= 1.0) {
            beta = asind(s);
            *xp = tand(beta - spc->w[3]);
         } else {
            *statp = 1;
         }
      }
   }


   /* Convert X-type spectral variable to intermediate world coordinate x. */
   xp = x;
   statp = stat;
   for (ispec = 0; ispec < nspec; ispec++, xp += sx) {
      if (*(statp++)) continue;

      *xp -= spc->w[1];
      *xp /= spc->w[2];
   }

   return status;
}
示例#13
0
void fps_camera::rotatePitch (float direction)
{
   pitch += 3*direction*rotateSpeed;
   ref.y = tand (pitch);
}