Beispiel #1
0
   /**
    * \brief Safe main() implementation.
    */
   int safe_main(int argc, char **argv, bool noargs)
   {
      m_program_name = argv[0];

      // process command line options first

      boost::program_options::options_description cmdline_options;
      option_validator opt_validator;
      process_cmdline_options(cmdline_options, opt_validator, argc, argv);

      if (options().count("help") || (!noargs && argc == 1))
      {
         std::cout << help_header() << cmdline_options << std::endl;
         return 0; // nothing more to do here
      }

      if (options().count("version"))
      {
         std::cout << version() << std::endl;
         return 0; // nothing more to do here
      }

      // some basic command line options consistency checks

      if (running_as_daemon() && m_shell_port == 0)
      {
         throw std::runtime_error("please use --shell-port option when running with --daemon");
      }

      moost::utils::assert_absolute_path(m_pidfile, "pidfile");

      // service specific checks

      validator::constraints_map_t opt_constraints;

      if (running_as_daemon())
      {
         opt_constraints["absolute_filenames"] = "1";
      }

      opt_validator(options(), opt_constraints);
      m_ownership.validate_options(options());
      m_logging.validate_options(options());
      validate_options();

      // configure logging initialisation verbosity

      m_logging.set_init_verbose(!running_as_daemon());

      // change ownership according to policy

      m_ownership.change_ownership(options());

      run();

      return 0;  // apparently, we've managed to finish cleanly
   }
Beispiel #2
0
/*
char *telescope_name(int telescope_id);
char *data_category(int data_type);
char *backend_name(int machine_id);
void angle_split(double angle,int *dd,int *mm,double *ss);
void cal(double djm,int *year,int *month,int *day);
long numsamples(FILE *filename,int headersize,int nbits,int nifs,int nchans);
*/
int main(int argc,char *argv[]){

  FILE *fil;
  int i;
  char key_name[N]="";
  int key_length;
  int size_int=sizeof(int),size_double=sizeof(double);
  int nsamples=0;
  long numsamps;
  int size_header=0;
  long size_data;
  int dd,mm;
  double ss;
  int year,month,day;
  double total_obs;
  double low_channel,high_channel,total_bandwidth;
  char unit[N];
  int index_chan=0;

  if(help_required(argv[1])){
	  help_header();
	  exit(-1);
  }

//Default value of key parameters

//  rawdatafile="";
//  source_name="uknown";
  src_raj=0;
  src_dej=0;
  telescope_id=11; //Telescope="uknown"
  machine_id=11; //Datataking Machine="uknown"
  data_type=11; //Data file="uknown"
  barycentric=0; //Barycentric="No"
  pulsarcentric=0; //pulsarcentric="Yes"
  az_start=0;
  za_start=0;
  tstart=0;
  tsamp=0;
  nbits=0;
  nsamples=0;
  total_obs=0;
  ibeam=0;
  nbeams=0;
  nifs=0;
  low_channel=0;
  high_channel=0;
  foff=0;
  nchans=0;
  total_bandwidth=0;
  refdm=0;
  size_data=0;
  size_header=0; 

//END

  if((fil=fopen(argv[1],"rb")) == NULL){
    fprintf(stderr,"Error:Cannot open file!\n");
    exit(-1);
  }
//read HEADER_START of *.fil
  if(fread(&key_length,size_int,1,fil) < 1){
    fprintf(stderr,"Error read key_length\n");
    exit(-1);
  }
  
  size_header=size_header+size_int*1;

  if((fgets(key_name,key_length+1,fil)) == NULL){
    fprintf(stderr,"Error:Failed to read key_name\n");
    exit(-1);
  }

  size_header=size_header+key_length*1;
  
  if(strcmp(key_name,"HEADER_START")){
    fprintf(stderr,"Error:Failed to read header\n");
    exit(-1);
  }

//read HEADER of *.fil 
  while(1){

    if(fread(&key_length,size_int,1,fil) < 1){  
      fprintf(stderr,"Error read key_length\n");
      exit(-1);
    }

    size_header=size_header+size_int*1;

    if((fgets(key_name,key_length+1,fil)) == NULL){
      fprintf(stderr,"Error:Failed to read key_name\n");
      exit(-1);
    }

    size_header=size_header+key_length*1;
//find key_parameters
    if(strcmp(key_name,"telescope_id") == 0){
      if(fread(&telescope_id,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read telescope_id\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"FREQUENCY_START") == 0){
      index_chan=0;
    }
    else if(strcmp(key_name,"FREQUENCY_END") == 0){
      fch1=0;
      foff=0;
    }
    else if(strcmp(key_name,"fchannel") == 0){
      if(fread(&frequency_table[index_chan++],size_double,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read fchannel\n");
        exit(-1);
      }
      size_header=size_header+size_double*1;
    }
    else if(strcmp(key_name,"machine_id") == 0){
      if(fread(&machine_id,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read telescope_id\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"data_type") == 0){
      if(fread(&data_type,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read data_type\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"nchans") == 0){
      if(fread(&nchans,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read nchans\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"nbits") == 0){
      if(fread(&nbits,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read nbits\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"nifs") == 0){
      if(fread(&nifs,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read nifs\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"scan_number") == 0){
      if(fread(&scan_number,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read scan_number\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"barycentric") == 0){
      if(fread(&barycentric,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read barycentric\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"pulsarcentric") == 0){
      if(fread(&pulsarcentric,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read pulsarcentric\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"tstart") == 0){
      if(fread(&tstart,size_double,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read tstart\n");
        exit(-1);
      }
      size_header=size_header+size_double*1;
    }
    else if(strcmp(key_name,"mjdobs") == 0){
      if(fread(&mjdobs,size_double,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read mjdobs\n");
        exit(-1);
      }
      size_header=size_header+size_double*1;
    }
    else if(strcmp(key_name,"tsamp") == 0){
      if(fread(&tsamp,size_double,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read tsamp\n");
        exit(-1);
      }
      size_header=size_header+size_double*1;
    }
    else if(strcmp(key_name,"fch1") == 0){
      if(fread(&fch1,size_double,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read fch1\n");
        exit(-1);
      }
      size_header=size_header+size_double*1;
    }
    else if(strcmp(key_name,"foff") == 0){
      if(fread(&foff,size_double,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read foff\n");
        exit(-1);
      }
      size_header=size_header+size_double*1;
    }
    else if(strcmp(key_name,"refdm") == 0){
      if(fread(&refdm,size_double,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read refdm\n");
        exit(-1);
      }
      size_header=size_header+size_double*1;
    }
    else if(strcmp(key_name,"az_start") == 0){
      if(fread(&az_start,size_double,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read az_start\n");
        exit(-1);
      }
      size_header=size_header+size_double*1;
    }
    else if(strcmp(key_name,"za_start") == 0){
      if(fread(&za_start,size_double,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read za_start\n");
        exit(-1);
      }
      size_header=size_header+size_double*1;
    }
    else if(strcmp(key_name,"src_raj") == 0){
      if(fread(&src_raj,size_double,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read src_raj\n");
        exit(-1);
      }
      size_header=size_header+size_double*1;
    }
    else if(strcmp(key_name,"src_dej") == 0){
      if(fread(&src_dej,size_double,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read src_dej\n");
        exit(-1);
      }
      size_header=size_header+size_double*1;
    }
    else if(strcmp(key_name,"ibeam") == 0){
      if(fread(&ibeam,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read ibeam\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"nbeams") == 0){
      if(fread(&nbeams,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read nbeams\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"nsamples") == 0){
      if(fread(&nsamples,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read nsamples\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
    }
    else if(strcmp(key_name,"rawdatafile") == 0){
      if(fread(&key_length,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read rawdatafile_length\n");
        exit(-1);
      }  
      size_header=size_header+size_int*1;    
      if(fgets(rawdatafile,key_length+1,fil) ==NULL){
        fprintf(stderr,"Error:Failed to read rawdatafile\n");
      }
      size_header=size_header+key_length*1;
    }
    else if(strcmp(key_name,"source_name") == 0){
      if(fread(&key_length,size_int,1,fil) < 1){
        fprintf(stderr,"Error:Failed to read source_name_length\n");
        exit(-1);
      }
      size_header=size_header+size_int*1;
      if(fgets(source_name,key_length+1,fil) ==NULL){
        fprintf(stderr,"Error:Failed to read source_name\n");
      }
      size_header=size_header+key_length*1;
    }
    else if(strcmp(key_name,"HEADER_END") == 0) break;
    else{
      fprintf(stderr,"Error:Failed to recognize key parameter\n");
    }
  }
//Data file
  if(strcmp(rawdatafile,"") != 0)
    printf("%-38s : %s\n","Data file",rawdatafile);
  else
    printf("%-38s : %s\n","Data file",argv[1]);
//Source name
  printf("%-38s : %s\n","Source Name",source_name);
//Source RA (J2000)
  angle_split(src_raj,&dd,&mm,&ss);
  printf("%-38s : %d:%d:%.1lf\n","Source RA (J2000)",dd,mm,ss);
//Source DEC (J2000)
  angle_split(src_dej,&dd,&mm,&ss);
  printf("%-38s : %d:%d:%.1lf\n","Source DEC (J2000)",dd,mm,ss);
//Telescope
  printf("%-38s : %s\n","Telescope",telescope_name(telescope_id));
//Datataking Machine
  printf("%-38s : %s\n","Datataking Machine",backend_name(machine_id));
//Data type
  printf("%-38s : %s\n","Data type",data_category(data_type));
//Barycentric
  if(barycentric==1)
    printf("%-38s : %s\n","Barycentric","Yes");
  else
    printf("%-38s : %s\n","Barycentric","No");
//Pulsarcentric
  if(pulsarcentric==1)
    printf("%-38s : %s\n","Pulsarcentric","Yes");
  else
    printf("%-38s : %s\n","Pulsarcentric","No");
//Telescope azimuth angle (degrees)
    printf("%-38s : %lf\n","Telescope azimuth angle (degrees)",az_start);
//Telescope zenith angle (degrees)
    printf("%-38s : %lf\n","Telescope zenith angle (degrees)",za_start);
//Time stamp of first sample (MJD)
    printf("%-38s : %.12lf\n","Time stamp of first sample (MJD)",tstart);
//Gregorian date
  cal(tstart,&year,&month,&day);
  printf("%-38s : %d/%.2d/%.2d\n","Gregorian date",year,month,day);
//Sample time (us)
    printf("%-38s : %lf\n","Sample time (us)",tsamp*1.0e6);
//Number of bits per sample
    printf("%-38s : %d\n","Number of bits per sample",nbits);
//Number of samples //Warning:nifs*nchans*nsamples should be even;
  if(nsamples == 0){
    numsamps=numsamples(fil,size_header,nbits,nifs,nchans);
    size_data=(long)nifs*nchans*numsamps*nbits/8;
    total_obs=numsamps*tsamp;
    printf("%-38s : %ld\n","Number of samples",numsamps);
  }
  else{
    printf("%-38s : %d\n","Number of samples",nsamples);
    size_data=nifs*nchans*nsamples*nbits/8;
    total_obs=nsamples*tsamp;
  }
//Observation length
  strcpy(unit,"(s)");
  if(total_obs>60.0){
    total_obs/=60.0;
    strcpy(unit,"(m)");
    if(total_obs>60.0){
      total_obs/=60.0;
      strcpy(unit,"(h)");
      if(total_obs>24.0){
        total_obs/=24.0;
        strcpy(unit,"(d)");
      }
    }
  }
  printf("%s %-19s : %lf\n","Observation length",unit,total_obs);
//Beam number
  printf("%-38s : %d\n","Beam number",ibeam);
//Number of beams
  printf("%-38s : %d\n","Number of beams",nbeams);
//Number of IFs
  printf("%-38s : %d\n","Number of IFs",nifs);
//frequency table
  if(index_chan > 0){
    printf("%-38s : ","Frequency");
    for(i=0;i<index_chan;i++){
      printf("%lf ",frequency_table[i]);
    }
  }
  else{
//Low channel (MHz)
    if(foff < 0)
      low_channel=fch1+(nchans-1)*foff;
    else if(foff > 0)
      low_channel=fch1;
    printf("%-38s : %lf\n","Low channel (MHz)",low_channel);
//High channel (MHz)
    if(foff > 0)
      high_channel=fch1+(nchans-1)*foff;
    else if(foff < 0)
      high_channel=fch1;
    printf("%-38s : %lf\n","High channel (MHz)",high_channel);
//Central freq (MHz)
    printf("%-38s : %lf\n","Central freq (MHz)",(high_channel+low_channel)/2.);
//Channel bandwidth (MHz)
    printf("%-38s : %lf\n","Channel bandwidth (MHz)",foff);  
//Number of channels
    printf("%-38s : %d\n","Number of channels",nchans);
//Total Bandwidth (MHz)
    total_bandwidth=fabs(foff)*nchans;
    printf("%-38s : %lf\n","Total Bandwidth (MHz)",total_bandwidth);
  }
//Reference dispersion measure (cm-3 pc)
  printf("%-38s : %lf\n","Reference dispersion measure (cm-3 pc)",refdm);
//Data size (bytes)
  printf("%-38s : %ld\n","Data size (bytes)",size_data);
//Header size (bytes)
  printf("%-38s : %d\n","Header size (bytes)",size_header);


  fclose(fil);

return 0;
}