CCL Home Page
Up Directory CCL mapprof.c
/* program to translate cylindrical coords to cartesian coords */

#include 
#include 
#include 

#define CART 1       /* convert to true cartesian */
#define PERS 2       /* use perspective mode as output by steric */
#define ROTA 0.0     /* default rotation about phi to perform */
#define STEP 50      /* default number of steps in angular array */
#define BIG  1000.0

#ifndef PI
#define PI       3.14159265358979323846
#endif
#ifndef PI_2
#define PI_2     1.57079632679489661923
#endif

int main(int argc, char *argv[])
{
  char line[255];
  char card[100];
  char field[100];
  char type='c';
  double x,y,z;
  double theta,phi;
  int step=STEP;
  double rotation=ROTA;
  char mode=CART;
  int i;
  for(i=1;i2*PI) rotation=ROTA;

  do
  {
    if(fgets(line,254,stdin)==NULL) break;
    if(line[0]=='q') break;
    if((strncmp(line,"#STERIC",7)==0)&&(sscanf(line,"%s%s",card,field)==2))
    {
      sscanf(field,"%c",&type);
      if((type=='o')||(type=='r')||(type=='g')||(type=='n')||(type=='s'))
        type='s';
      else type='c';
    }
    if((line[0]!='#')&&(strlen(line)>4))
    {
      if((sscanf(line,"%lf%lf",&z,&theta)==2)&&(fabs(theta)>0.0001))
      {
        if(type=='s') theta=(acos( 1-(theta/(2*PI)) ));
        else theta/=2.0;
        phi=rotation;
        for(i=0;i<=step;i++)
        {
          phi+=2*PI/step;
          if(mode!=CART)
          {
            x=sin(theta)*cos(phi);
            y=sin(theta)*sin(phi);
            if((fabs(x)>BIG)||(fabs(y)>BIG)) 
              fprintf(stderr,"# PERS ERROR: phi=%f theta=%f x=%f y=%f z=%f\n"
                            ,phi,theta,x,y,z);
          }
          else
          {
            x=z*tan(theta)*cos(phi);
            y=z*tan(theta)*sin(phi);
            if((fabs(x)>BIG)||(fabs(y)>BIG)) 
              fprintf(stderr,"# CART ERROR: phi=%f theta=%f x=%f y=%f z=%f\n"
                            ,phi,theta,x,y,z);
          }
          fprintf(stdout,"%10.6f %10.6f %10.6f\n",x,y,z);
        }
      }
      line[0]=0;
    }
    fprintf(stdout,"%s\n",line);
  } while(!feof(stdin));
  return(1);
}

Modified: Fri Dec 8 17:00:00 1995 GMT
Page accessed 4689 times since Sat Apr 17 21:59:46 1999 GMT