#include <stdio.h>
#include <stdlib.h>
#include <string.h>

main(argc,argv)
int argc;
char *argv[];
{

float x,y,major,minor,angle,scale,row;
FILE *sfp,
     *dfp;
char junk[1025]; 
char str[1025] = "dmlist \"";
scale = atoi(argv[3]);

if (argc == 1) {
 printf("***********************************\n");
 printf("ERROR: parameters required\n");
 printf("Please type \"marker -help\" for details\n");
 printf("***********************************\n"); 
 }
/* print help file */
else if (strcmp(argv[1],"-help") == 0) {
  system("/usr/bin/more /home/chashav/jbw/bin/marker.txt");
  }

else {

  if (argc == 5 && strcmp(argv[4],"-pixels") == 0) { /*write pixels*/
     /*set up the system call to dmlist*/
     strcat(str,argv[1]);
     strcat(str,"[columns x,y]\" outfile=asd.da opt=data rows=-");
     system("rm -f asd.da"); 
     system(str);
     
     /*for debugging*/
     /*system("more asd.da");*/
     
     /*pointers for input and output files*/
     sfp = fopen("asd.da","r");
     dfp = fopen(argv[2],"w");

     /*saotng wil need to know input is in degrees and not pixels*/
     fprintf(dfp,"# format:       pixels (physical)\n");

     /*skip through asd.da till "SRC_POS(X,Y)" 
       (next fscan will be first source)*/
 
     fscanf(sfp,"%s",junk);
     
     while(strcmp(junk,"SRC_POS(X,Y)") != 0)
       {
       fscanf(sfp,"%s",junk);
       }
     

     /*scan in data and print to output file*/
     while(fscanf(sfp,"%f %s %f %s %f %s",&row,&junk,&x,&junk,&y,&junk) != EOF)
       {
       fprintf(dfp,"circle(%f,%f,%f)\n",x,y,scale);
       }

   }

  else {  /*do same as above, but for ra,dec*/

     /*set up the system call to dmlist*/
     strcat(str,argv[1]);
     strcat(str,"[columns ra,dec]\" outfile=asd.da opt=data rows=-");
     system("rm -f asd.da"); 
     system(str);
     
     /*for debugging*/
     /*system("more asd.da");*/
     
     /*pointers for input and output files*/
     sfp = fopen("asd.da","r");
     dfp = fopen(argv[2],"w");

     /*saotng wil need to know input is in degrees and not pixels*/
     fprintf(dfp,"# format:        degrees (ICRS)\n");

     /*skip through asd.da till "DEC" 
       (next fscan will be first source)*/
 
     fscanf(sfp,"%s",junk);
     
     while(strcmp(junk,"DEC") != 0)
       {
       fscanf(sfp,"%s",junk);
       }
     

     /*scan in data and print to output file*/
     while(fscanf(sfp,"%f %f %f",&row,&x,&y) != EOF)
       {
       fprintf(dfp,"circle(%f,%f,%f)\n",x,y,scale);
       }
  }


(void) fclose(dfp);    
(void) fclose(sfp);
   
/*system("rm -f asd.da");*/
}
}


