Пример #1
0
static int SSL_TEST_CLIENT_CONF_equal(SSL_TEST_CLIENT_CONF *client,
                                      SSL_TEST_CLIENT_CONF *client2)
{
    if (client->verify_callback != client2->verify_callback) {
        fprintf(stderr, "ClientVerifyCallback mismatch: %s vs %s.\n",
                ssl_verify_callback_name(client->verify_callback),
                ssl_verify_callback_name(client2->verify_callback));
        return 0;
    }
    if (client->servername != client2->servername) {
        fprintf(stderr, "ServerName mismatch: %s vs %s.\n",
                ssl_servername_name(client->servername),
                ssl_servername_name(client2->servername));
        return 0;
    }
    if (!strings_equal("Client NPNProtocols", client->npn_protocols,
                       client2->npn_protocols))
        return 0;
    if (!strings_equal("Client ALPNProtocols", client->alpn_protocols,
                       client2->alpn_protocols))
        return 0;
    if (client->ct_validation != client2->ct_validation) {
        fprintf(stderr, "CTValidation mismatch: %s vs %s.\n",
                ssl_ct_validation_name(client->ct_validation),
                ssl_ct_validation_name(client2->ct_validation));
        return 0;
    }
    return 1;
}
Пример #2
0
static int SSL_TEST_SERVER_CONF_equal(SSL_TEST_SERVER_CONF *server,
                                      SSL_TEST_SERVER_CONF *server2)
{
    if (server->servername_callback != server2->servername_callback) {
        fprintf(stderr, "ServerNameCallback mismatch: %s vs %s.\n",
                ssl_servername_callback_name(server->servername_callback),
                ssl_servername_callback_name(server2->servername_callback));
        return 0;
    }
    if (!strings_equal("Server NPNProtocols", server->npn_protocols,
                       server2->npn_protocols))
        return 0;
    if (!strings_equal("Server ALPNProtocols", server->alpn_protocols,
                       server2->alpn_protocols))
        return 0;
    if (server->broken_session_ticket != server2->broken_session_ticket) {
        fprintf(stderr, "Broken session ticket mismatch: %d vs %d.\n",
                server->broken_session_ticket, server2->broken_session_ticket);
        return 0;
    }
    if (server->cert_status != server2->cert_status) {
        fprintf(stderr, "CertStatus mismatch: %s vs %s.\n",
                ssl_certstatus_name(server->cert_status),
                ssl_certstatus_name(server2->cert_status));
        return 0;
    }
    return 1;
}
Пример #3
0
static int check_alpn(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
{
    int ret = 1;
    ret &= strings_equal("ALPN Negotiated (client vs server)",
                         result->client_alpn_negotiated,
                         result->server_alpn_negotiated);
    ret &= strings_equal("ExpectedALPNProtocol",
                         test_ctx->expected_alpn_protocol,
                         result->client_alpn_negotiated);
    return ret;
}
Пример #4
0
int help_required(char *string)
{
	if (strings_equal(string, "help")) return(1);
	if (strings_equal(string, "HELP")) return(1);
	if (strings_equal(string, "-help")) return(1);
	if (strings_equal(string, "-HELP")) return (1);
	if (strings_equal(string, "--help")) return (1);
	if (strings_equal(string, "--HELP")) return (1);
	if (strings_equal(string, "-h")) return (1);
	if (strings_equal(string, "-H")) return (1);
	if (strings_equal(string, "--h")) return (1);
	if (strings_equal(string, "--H")) return (1);
	return(0);
}
Пример #5
0
void decimate_header() /* includefile */
{
  /* go no further here if not interested in header parameters */
  if (headerless) return;
  /* broadcast the header parameters to the output stream */
  send_string("HEADER_START");
  if (!strings_equal(source_name,"")) {
    send_string("source_name");
    send_string(source_name);
  }
  send_int("telescope_id",telescope_id); 
  send_int("machine_id",machine_id);
  send_coords(src_raj,src_dej,az_start,za_start);
  if (nchans/naddc==1) {
    send_int("data_type",2);
    //    send_double("refdm",0.0);
   
    send_double("refdm",refdm); 
    /*== MKEITH: A hack to stop the dminfo being lost when decimating after dedisperse! ==*/
  
  } else {
    send_int("data_type",1);
  }
  send_double("fch1",fch1);
  send_double("foff",foff*(double)naddc);
  send_int("nchans",nchans/naddc);
  send_int("nbits",obits);
  send_double ("tstart",tstart); 
  send_double("tsamp",tsamp*(double)naddt);
  send_int("nifs",nifs);
  send_int("barycentric",barycentric);
  send_string("HEADER_END");
}
Пример #6
0
int string_contains(char *pattern, char *str)
{
    while (*str != 0) {
        if (strings_equal(pattern, str))
            return 1;
        str++;
    }
    return 0;
}
Пример #7
0
// Helper for on_movlist_selection_changed to retrieve the filename / path from the list name
char *movie_get_path_by_name(char *name)
{
	int mnum = 0;
	while(movies[mnum].valid)
	{
		if (strings_equal(movies[mnum].name, name))
			return movies[mnum].path;
		++mnum;
	}

	return NULL;
}
Пример #8
0
void filterbank_header(FILE *outptr) /* includefile */
{
  int i,j;
  output=outptr;
  if (obits == -1) obits=nbits;
  /* go no further here if not interested in header parameters */
  if (headerless) return;
  /* broadcast the header parameters to the output stream */
  if (machine_id != 0) {
    send_string("HEADER_START");
    send_string("rawdatafile");
    send_string(inpfile);
    if (!strings_equal(source_name,"")) {
      send_string("source_name");
      send_string(source_name);
    }
    send_int("machine_id",machine_id);
    send_int("telescope_id",telescope_id);
    send_coords(src_raj,src_dej,az_start,za_start);
    if (zerolagdump) {
      /* time series data DM=0.0 */
      send_int("data_type",2);
      refdm=0.0;
      send_double("refdm",refdm);
      send_int("nchans",1);
    } else {
      /* filterbank data */
      send_int("data_type",1);
      send_double("fch1",fch1);
      send_double("foff",foff);
      send_int("nchans",nchans);
    }
    /* beam info */
    send_int("nbeams",nbeams);
    send_int("ibeam",ibeam);
    /* number of bits per sample */
    send_int("nbits",obits);
    /* start time and sample interval */
    send_double("tstart",tstart+(double)start_time/86400.0);
    send_double("tsamp",tsamp);
    if (sumifs) {
      send_int("nifs",1);
    } else {
      j=0;
      for (i=1;i<=nifs;i++) if (ifstream[i-1]=='Y') j++;
      if (j==0) error_message("no valid IF streams selected!");
      send_int("nifs",j);
    }
    send_string("HEADER_END");
  }
  
}
size_t products_equal(product_t *product_a, product_t *product_b)
{
  if (!strings_equal(product_a->color, product_b->color))
  {
    return 0;
  }

  if (product_a->id != product_b->id)
  {
    return 0;
  }

  return 1;
}
Пример #10
0
int equals(struct boot_option *left, struct boot_option *right)
{
	if (!strings_equal(left->label, right->label))
		return 0;
	if (!strings_equal(left->menu_label, right->menu_label))
		return 0;
	if (!strings_equal(left->image, right->image))
		return 0;
	if (!strings_equal(left->root, right->root))
		return 0;
	if (!strings_equal(left->initrd, right->initrd))
		return 0;
	if (!strings_equal(left->com32, right->com32))
		return 0;

	return 1;
}
// ⚠️ Note: This is placeholder target for installing the ipa file
//    DO NOT MODIFY.

//    This file is only for warning generation of unconfiguration build settings."

#ifndef ProjectConfigurationWarning_hpp
#define ProjectConfigurationWarning_hpp

#include <stdio.h>
#include <TargetConditionals.h>

// compares two strings in compile time constant fashion
constexpr bool strings_equal(char const * a, char const * b) {
    return *a == *b && (*a == '\0' || strings_equal(a + 1, b + 1));
}

#define STRINGIZE(x) #x
#define STRINGIZE2(x) STRINGIZE(x)
#define TARGET_BUNDLE_ID_STRING STRINGIZE2(TARGET_BUNDLE_ID)

static_assert(!strings_equal(TARGET_BUNDLE_ID_STRING, "com.00agency.facebk"), "You Should Update  the BundleID in Build Settings before Patching");

// ⚠️ Note: "com.wutian.example" is placeholder bundleID for the result app, you should change it to your own and fixes the signing issues (if any), in the "IPAPatch-DummyApp - Project - General tab"
// ⚠️ Note: The BundleDisplayName of DummyApp will used as prefix of the final name.

#if TARGET_OS_SIMULATOR
#error Simulators is not supported, Please select a real device from Xcode toolbar.
#endif

#endif /* ProjectConfigurationWarning_hpp */
Пример #12
0
int main (int argc, char *argv[]) 
{
  int ntimglobal=0;  // number of time samples in original
  int ngulp_original=0;       // number of time samples to look at at once
  int nskipstart=0;       // number skipped at start
  int nrejects; //ZAPPER
  int zapswitch = 0; //ZAPPER  
  double tsamp_orig=0;

  //gsearch setup & defaults
  float Gsigmacut=6.0;
  float delta, tstart;
  vector<Gpulse> * Giant = new vector<Gpulse>[MAXFILES];
  bool Gsearched=false;

  int i,ntim,headersize[MAXFILES],noff=0,gulp;
  float *time_series[MAXFILES],sum=0.0,sumsq=0.0,mean,meansq,sigma;
  int MAXMARKERS = 1024;
  int nfiles = 0;
  FILE *inputfile[MAXFILES];
  char filename[MAXFILES][256];
  int spectra=0;
  int powerspectra=0;
  double dmoffirstfile;
  char *killfile;
  bool dokill=false;
  bool ssigned=true;
  bool fsigned=false;
  int topfold=-1;
  int topgiant=-1;
  int toppeak=-1; //?!? sarah added this 
  bool askdevice=false;
  char devicename[200];

  if (argc<2 || help_required(argv[1])) {
      helpmenu();
//    fprintf(stderr,"Usage: giant filenames\n\t(e.g.>>  giant *.tim)\n\n\t-s  N\tskip N samples\n\t-n  N\tread N samples\n\t-S read spectra instead of amplitudes\n-i interpret signed chars as unsigned\n\t-z make a zap list of bad time samples\n");
      exit(0);
  }
  print_version(argv[0],argv[1]);
  i=1;
  while (i<argc) {
    if (file_exists(argv[i]))          {
      inputfile[nfiles]=open_file(argv[i],"r");
      strcpy(filename[nfiles],argv[i]);
      nfiles++;
    }
    if (strings_equal(argv[i],"-s"))       sscanf(argv[++i],"%d",&nskipstart);
    if (strings_equal(argv[i],"-S"))       spectra=1;
    if (strings_equal(argv[i],"-i"))       ssigned=false;
    if (strings_equal(argv[i],"-f"))      fsigned=true;
    if (strings_equal(argv[i],"-n"))       sscanf(argv[++i],"%d",&ngulp_original);
    if (strings_equal(argv[i],"-c"))       sscanf(argv[++i],"%f",&Gsigmacut);
    if (strings_equal(argv[i],"-z"))       zapswitch=1;
    if (strings_equal(argv[i],"-g"))       {askdevice=true;sscanf(argv[++i],"%s",&devicename);}
    if (strings_equal(argv[i],"-k"))       {killfile=(char*)malloc(strlen(argv[++i])+1); strcpy(killfile,argv[i]);dokill=true;}
    if (nfiles>MAXFILES) error_message("too many open files");
    i++;
  }


  int ntimglobal_smallest=0, nsamp;
  for (i=0; i<nfiles; i++) {

    if (spectra){
      int npf; 
      double rate;
      time_series[i]=Creadspec(filename[i],&npf,&rate);
      tsamp = 1.0/(rate);
      //normalise(npf,time_series[i]);
      nsamp = ntimglobal = ntimglobal_smallest = npf;
    }
    else
    {
    if ((headersize[i]=read_header(inputfile[i]))) {
	    if (! fsigned){
		    if (isign > 0) {
			    ssigned=false;
			    fprintf(stderr,"using signed header variable to set UNSIGNED\n");
		    }
		    if (isign < 0) {
			    ssigned=true;
			    fprintf(stderr,"using signed header variable to set SIGNED\n");
		    }
	    }
      if (i==0) dmoffirstfile = refdm;
      if (nbits!=8 && nbits!=32)
	    error_message("giant currently only works for 8- or 32-bit data");

      nsamp = nsamples(filename[i],headersize[i],nbits,nifs,nchans);
      if (i == 0) {
	ntimglobal_smallest=nsamp;
      } else {
	ntimglobal= nsamp;
	if (ntimglobal < ntimglobal_smallest) ntimglobal_smallest = ntimglobal;
      }
      
      // Space for data (time_series)
      time_series[i]=(float *) malloc((nsamp+2)*sizeof(float));
      if (time_series[i]==NULL){
	fprintf(stderr,"Error mallocing %d floats of %d size\n",nsamp,
		sizeof(float));
	exit(-1);
      }
      tsamp_orig = tsamp;
      
      // Skip data
      fprintf(stderr,"Skipping %d bytes\n",nskipstart*nbits/8);
      fseek(inputfile[i],nskipstart*nbits/8,SEEK_CUR);
      
    } // each file
    } // spectra or not
  }  // for (i...)
  puti(ntimglobal_smallest);
  if (ngulp_original==0) ngulp_original=ntimglobal_smallest;


// ****** SAM'S ZAP SWITCH ******
// Sam Bates 2009
// Integrated into new giant by SBS
// Switch to make a .killtchan file for time samples > 3.5 sigma
// SARAHZAP tag means addition was added later by Sarah
// ******************************
  int ngulp=ngulp_original;
//  int nrejects_max=ngulp_original/100;
  int * mown = new int[ngulp_original];
  int nstart=0;
  if (zapswitch){
    float dummy;
    int NActuallyRead;
    char *buffer;
    buffer = new char[ngulp*nbits/8];
    for (i=0; i<nfiles; i++){
      NActuallyRead = fread(buffer,nbits/8,ngulp,inputfile[i]);
      if (nbits==32){
	memcpy(time_series[i],buffer,sizeof(float)*ngulp);
      } else {
	for (int j=0;j<NActuallyRead;j++){
	  if (ssigned) time_series[i][j]=(float)buffer[j];
	  if (!ssigned) time_series[i][j]=(float)((unsigned char)buffer[j]);
	}
      }
      puti(ngulp);
      find_baseline(ngulp,time_series[i],10.0/tsamp,5.0);
      mowlawn(ngulp,time_series[i],5,256);
    }
    printf("%f\n",dummy);
    printf("Bad time samples found...\n");
    exit(0);
  }


  int pgpID;
  if (askdevice){
      pgpID = cpgbeg(0,devicename,1,1);
  } else {
      pgpID = cpgbeg(0,"/xs",1,1);
  }
  cpgsch(0.5);
  cpgtext(0.6,0.0,"Press 'h' over the main window for help and full options list.");
  cpgsch(1.0);
  /* create the dialog */
  dialog * d = new dialog();

  /* add the "action" buttons */
  int QUIT         = d->addbutton(0.02,0.95,"Quit");
  int POWER        = d->addbutton(0.07,0.85,"POWER");
  int SMHRM        = d->addbutton(0.075,0.80,"SMHRM");
  int FFT          = d->addbutton(0.02,0.85,"FFT");
  int PLOT         = d->addbutton(0.02,0.80,"Plot");
  int NEXT         = d->addbutton(0.02,0.75,"Next");
  int ZAPPEAK      = d->addbutton(0.075,0.75,"ZapPeak");
  int RESET        = d->addbutton(0.02,0.70,"Reset");
  int GLOBALRESET  = d->addbutton(0.02,0.65,"Global Reset");
  int HALVEPLOT    = d->addbutton(0.02,0.60,"Halve Plot");
  int BASELINE     = d->addbutton(0.02,0.50,"Baseline");
  int ZAPCOMMON    = d->addbutton(0.02,0.45,"Zap Common");
  int SUBTRACTMEAN = d->addbutton(0.02,0.40,"ZAP Mean");
  int BSCRUNCH     = d->addbutton(0.02,0.35,"Bscrunch");
  int NORMALISE    = d->addbutton(0.02,0.30,"Normalise"); 
  int HISTOGRAM    = d->addbutton(0.02,0.25,"Histogram"); 
  int GSEARCH      = d->addbutton(0.02,0.20,"Find Giants");
  int MOWLAWN      = d->addbutton(0.08,0.70,"LAWN");
  int SEEFIL       = d->addbutton(0.02,0.15,"View Band");
  int FWRITE       = d->addbutton(0.02,0.05,"Write File");
 

  /* add the plot regions */
  d->addplotregion(0.2,0.99,0.98,0.99);
  float deltay = 0.9/(float)nfiles;
  for (i=0; i<nfiles; i++) 
      d->addplotregion(0.2,0.99,0.95-deltay*(float)(i+1),0.95-deltay*(float)i);

  d->draw();

  float x,y;
  char ans;
  int button=-1; int plotno=-1;
  int NPIXELS = 1024;
  float * xaxis = new float[NPIXELS];
  float * ymaxes = new float[NPIXELS];
  float * ymins = new float[NPIXELS];

  int scrunch=1;
  int nmarkers=0;
  int * markers= new int[MAXMARKERS];
  int nfileptr=nskipstart;
  int nplot=ngulp_original;
  nstart=0;  //COMMENTED IN ZAPPER VERSION: MAY CAUSE CONFLICTS IN THIS VER.
  ngulp=ngulp_original;  //COMMENTED IN ZAPPER VERSION: MAY CAUSE CONFLICTS IN THIS VER.
  double trialperiod;
  int doperiod=-1;
  double xperiod;

  bool zoneplot=false;
  int ngates=0;
  float xgate=0.0;



  button=NEXT;
  if (spectra) button = PLOT;
  while (button!=QUIT){
    // Plot the zone
    // Entire file is white
    if (button!=NEXT)button=d->manage(&x,&y,&ans,&plotno);
    if (ans=='h'){
	buttonexplain();
	continue;
    }
//    printf("manage x %f y %f plotno %d\n",x,y,plotno);
    if (button==BASELINE) {
	for (i=0; i<nfiles; i++){
	    find_baseline(ngulp,time_series[i],10.0/tsamp,5.0);
	}
	button = PLOT;
	zoneplot=false;
        plotno = -1;
    }
    if (button==FWRITE) {
      // reread first header and close it. Sets globals.
      fclose(inputfile[0]);
      inputfile[0]=open_file(argv[1],"r");
      headersize[0]=read_header(inputfile[0]);
      output = open_file("giant.tim","w");
      nobits=32;
      nbands=1;
      dedisperse_header();
      fprintf(stderr,"Opened file, writing data\n");
      fwrite(time_series[0],sizeof(float),ngulp,output);
      fclose(output);
      button = -1;
      zoneplot=false;
      plotno =-1;
    }
    if (button==BSCRUNCH) {
	for (i=0; i<nfiles; i++){
	    bscrunch(ngulp,time_series[i]);
	}
	tsamp*=2;
	scrunch*=2;
      	ngulp/=2;
	nplot/=2;
	button = PLOT;
	zoneplot=false;
	Gsearched=false;
        plotno = -1;
    }
    if (button==FFT) {
	for (i=0; i<nfiles; i++){
	  ngulp = ngulp_original;
	  find_fft(&ngulp,time_series[i]);
	// Zap DC spike
	  time_series[i][0]=0.0;
	  time_series[i][1]=0.0;
	}
	spectra = 1;
	nplot = ngulp;
	button = PLOT;
	Gsearched=false;
        plotno = -1;
    }
    if (button==POWER) {
	for (i=0; i<nfiles; i++){
	  find_formspec(ngulp,time_series[i]);
	}
	ngulp/=2;
	powerspectra = 1;
	nplot = ngulp;
	button = PLOT;
        plotno = -1;
    }
    if (button==SMHRM) {
        nfiles = 6;
	for (i=1; i<nfiles; i++){
	  time_series[i]=(float *) malloc((ngulp+2)*sizeof(float));
	  if (time_series[i]==NULL){
	    fprintf(stderr,"Error allocating memory\n");
	    exit(-1);
	  }
	}
	for (i=1;i<nfiles;i++) memcpy(time_series[i],time_series[0],
				      (ngulp+2)*sizeof(float));
	d->nplotregion=1;
        float deltay = 0.9/(float)nfiles;
        for (i=0; i<nfiles; i++) 
          d->addplotregion(0.2,0.99,0.95-deltay*(float)(i+1),
			   0.95-deltay*(float)i);
	cpgeras();
	d->draw();

	float * workspace = new float[ngulp];

	// Set up space for data, now actually sumhrm
	int one=1;
			newoldsumhrm_(&time_series[0][1],workspace,&ngulp,&one,
	//		newoldsumhrm_(&time_series[0][0],workspace,&ngulp,&one,
		   time_series[1],time_series[2],time_series[3],
		   time_series[4],time_series[5]);
		/*	newnewsumhrm_(time_series[0],&ngulp,&one,
		   time_series[1],time_series[2],time_series[3],
		   time_series[4],time_series[5]);*/
		for (int iff=2;iff<6;iff++){
		  for (int i=0;i<ngulp;i++){
		    time_series[iff][i]/=sqrt(pow(2.0,(float)(iff-1)));
		  }
		}
	delete [] workspace;
	button = PLOT;
        plotno = -1;
    }
    if (button==NORMALISE) {
	for (i=0; i<nfiles; i++){
	  normalise(ngulp,time_series[i],5.0);
	}
	button = PLOT;
	Gsearched=false;
        plotno = -1;
    }
    if (button==HISTOGRAM) {
      float pdfs[nfiles][MAXSIGMA];
      //  create pdfs for each beam
      for (int i=0;i<nfiles;i++)
	formpdf(pdfs[i],MAXSIGMA,ngulp,time_series[i]);

      for (int i=0;i<nfiles;i++){
	for (int j=0;j<MAXSIGMA; j++){
	  fprintf(stderr, "pdfs[%d][%2d]=%8.0f %f \%\n", i, j+1, pdfs[i][j], 100*pdfs[i][j]/ngulp);
	}
      }
        button = PLOT;
        plotno = -1;
    }
    if (button==HALVEPLOT) {
	nplot/=2;
	button = PLOT;
	zoneplot=true;
	Gsearched=false;
        plotno = -1;
    }
    if (button==GLOBALRESET) {
      plotno = -1;
      nstart = 0;
      scrunch=1;
      tsamp = tsamp_orig;
      nplot=ngulp_original;
      ngulp=ngulp_original;
      button=PLOT;
      // Skip to end of skipped data
      for (i=0; i<nfiles; i++){
	fseek(inputfile[i],-(nfileptr-nskipstart)*nbits/8,SEEK_CUR);
	Giant[i].clear();
      }
      nfileptr=nskipstart;
      zoneplot=false;
      Gsearched=false;
      doperiod=-1;
      button=NEXT;
    }
    if (button==SUBTRACTMEAN && nfiles>1) {
      plotno = -1;
      nstart = 0;
      nplot=ngulp_original;
      ngulp=ngulp_original;
      button=PLOT;
      // Skip to end of skipped data
	for (int jj=0;jj<ngulp;jj++){
	  float sum;
	  sum=0.0;
	  for (i=1;i<nfiles;i++){
	    sum+=time_series[i][jj];
	  }
	  time_series[0][jj]-=sum/(float(nfiles-1));
	}
	Gsearched=false;
    }
    if (button==ZAPCOMMON && nfiles>1) {
      plotno = -1;
      nstart = 0;
      nplot=ngulp_original;
      ngulp=ngulp_original;
      button=PLOT;
      float pdfs[nfiles][MAXSIGMA];
      //  create pdfs for each beam
      for (int i=0;i<nfiles;i++)
	formpdf(pdfs[i],MAXSIGMA,ngulp,time_series[i]);
      //  for each point in each beam, mask if improbable
      float thresh = 3.0;
      int nbeammax = 5;
      zap_improbables(pdfs,time_series,nfiles,ngulp,MAXSIGMA,thresh,nbeammax);
      // Skip to end of skipped data
      //for (int jj=0;jj<ngulp;jj++){
      //  float sum;
      //  sum=0.0;
      //  for (i=1;i<nfiles;i++){
      //    sum+=time_series[i][jj];
      //  }
      //  time_series[0][jj]-=sum/(float(nfiles-1));
      //}
      //Gsearched=false;
    }
    if (button==NEXT) {
      ngulp=ngulp_original;
      nstart=0;
      nplot=ngulp_original;
      // Read the data
      int NActuallyRead;
      //      unsigned char *buffer;
      char *buffer;
      buffer = new char[ngulp*nbits/8];
      //buffer = new char[ngulp*nbits/8];
      for (i=0; i<nfiles; i++) {
//	NActuallyRead = fread(time_series[i],sizeof(float),ngulp,inputfile[i]);
	NActuallyRead = fread(buffer,nbits/8,ngulp,inputfile[i]);
	if (nbits==32){
	  memcpy(time_series[i],buffer,sizeof(float)*ngulp);
	} else {
	    for (int j=0;j<NActuallyRead;j++){
	      if (ssigned) time_series[i][j]=(float)buffer[j];
	      if (!ssigned) time_series[i][j]=(float)((unsigned char)buffer[j]);
	    }
	}
	
	puti(ngulp);
	if (NActuallyRead!=ngulp){
	  fprintf(stderr,"Could not read %d floats from file\n",ngulp);
	  ngulp = NActuallyRead;
	}
	if(nfiles==1){
	  // Add fake pulsar here....
	  //	  for (int ii=0;ii<ngulp;ii++) time_series[i][ii]+= 10.0*pow(sin(float(ii*2.0*M_PI/60.0)),250.0);
	}
	//normalise(ngulp,time_series[i]);
      }
      nfileptr+=ngulp;
      button = PLOT;
      plotno= -1;
      zoneplot=true;
    }
    if (button==RESET) {
      button = plotno = -1;
      nstart=0;
      nplot=ngulp;
      button=PLOT;
      zoneplot=true;
      Gsearched=false;
      if (ans=='p'){
	doperiod=-1;
      }
    }
    if (plotno>0){
/*      if (ans=='p'){  // hit p on a plot to type in a period
	d->plotregions[plotno].reset();
	//plot the thing;
	fprintf(stderr,"Please enter a period in seconds: ");
	cin>>trialperiod;
	xperiod = x;
	doperiod=plotno;
	button=PLOT;
	}*/
      if (ans=='p'){  // hit p on a plot to type in a period
	d->plotregions[plotno].reset();
	//plot the thing;
	fprintf(stderr,"Please enter a period in seconds: ");
	cin>>trialperiod;
	xperiod = (double)x;
	doperiod=plotno;
	button=PLOT;
      }
      if (ans=='m'){  // subtract 0.0000005 seconds from period
	d->plotregions[plotno].reset();
	trialperiod-=0.0000005;
	fprintf(stderr,"Trial period is now %lf\n",trialperiod);
	doperiod=plotno;
	button=PLOT;
      }
      if (ans=='/'){  // add 0.0000005 seconds to period
	d->plotregions[plotno].reset();
	trialperiod+=0.0000005;
	fprintf(stderr,"Trial period is now %lf\n",trialperiod);
	doperiod=plotno;
	button=PLOT;
      }
      if (ans==','){  // subtract 0.000005 seconds from period
	d->plotregions[plotno].reset();
	trialperiod-=0.000005;
	fprintf(stderr,"Trial period is now %lf\n",trialperiod);
	doperiod=plotno;
	button=PLOT;
      }
      if (ans=='.'){  // add 0.000005 seconds to period
	d->plotregions[plotno].reset();
	trialperiod+=0.000005;
	fprintf(stderr,"Trial period is now %lf\n",trialperiod);
	doperiod=plotno;
	button=PLOT;
      }
      if (ans=='<'){  // subtract 0.001 seconds from period
	d->plotregions[plotno].reset();
	trialperiod-=0.001;
	fprintf(stderr,"Trial period is now %lf\n",trialperiod);
	doperiod=plotno;
	button=PLOT;
      }
      if (ans=='>'){  // add 0.001 seconds to period
	d->plotregions[plotno].reset();
	trialperiod+=0.001;
	fprintf(stderr,"Trial period is now %lf\n",trialperiod);
	doperiod=plotno;
	button=PLOT;
      }
      if (ans=='X'){  // right click two points on a plot to calculate and plot a period
	d->plotregions[plotno].reset();
	cpgsci(3);
	cpgmove(x,-1000);
	cpgdraw(x,1000);
	if (ngates==0){
	  xgate=x;
	  ngates++;
	} else {
	  min_means_min(&x,&xgate);
	  printf("Period from %f to %f is %f\n",x,xgate,xgate-x);  
	  doperiod=plotno;
	  xperiod = (double)x;
	  trialperiod=(double)(xgate-x);
	  ngates=0;
	  button=PLOT;
	}
      }
      if (ans=='D'){
	markers[nmarkers]=(int)(x/NPIXELS)*nplot+nstart+nfileptr-ngulp;
	nmarkers++;
	zoneplot=true;
      }
      if (ans=='A'){
	d->plotregions[plotno].reset();
	cpgsci(2);
	cpgmove(x,-1000);
	cpgdraw(x,1000);
	if (ngates==0){
	  xgate=x;
	  ngates++;
	} else {
	  min_means_min(&x,&xgate);
//	  printf("x %f xgate %f tstart %f\n",x,xgate,tstart);
	  nstart=(int)((x-tstart)/delta)+nstart;
	  nplot=(int)((xgate-x)/delta);
	  //if (nplot<NPIXELS) nplot=NPIXELS;
	  ngates=0;
	  button=PLOT;
	  zoneplot=true;
//	  printf("nplot %d nstart %d\n",nplot,nstart);
	}
      }
      if (ans=='z'){
	if (NPIXELS>nplot) {
	  nstart+=(int)x;
	}else
	nstart=(int)(x/(float)NPIXELS*nplot)+nstart;
	printf("nstart %d\n",nstart);
	nplot/=4;
	printf("nplot %d\n",nplot);
	nstart-=nplot/2;
	printf("nstart %d\n",nstart);
	//if (nplot<NPIXELS){nplot=NPIXELS;}
	button=PLOT;
	zoneplot=true;
      }
    }
Пример #13
0
main (int argc, char *argv[])
{
  int i, nc, headersize, headerless=0;
  char string[80];

  /* set up default global variables */
  obits=headerless=naddc=naddt=nsamp=0;
  input=stdin;
  strcpy(inpfile,"stdin");
  output=stdout;
  strcpy(outfile,"stdout");

  if (argc > 1) {
    /* check command-line parameters */ 
    print_version(argv[0],argv[1]);
    i=1;
    while (i<argc) {
      if (strings_equal(argv[i],"-c")) {
	i++;
	naddc=atoi(argv[i]);
      } else if (strings_equal(argv[i],"-t")) {
	i++;
	naddt=atoi(argv[i]);
      } else if (strings_equal(argv[i],"-o")) {
	/* get and open file for output */
	output=fopen(argv[++i],"wb");
      } else if (strings_equal(argv[i],"-T")) {
	i++;
	nsamp=atoi(argv[i]);
      } else if (strings_equal(argv[i],"-n")) {
	i++;
	obits=atoi(argv[i]);
      } else if (strings_equal(argv[i],"-headerless")) {
	headerless=1;
      } else if (help_required(argv[1])) {
	decimate_help();
	exit(0);
      } else if (file_exists(argv[i])) {
	strcpy(inpfile,argv[i]);
	input=open_file(inpfile,"rb");
      } else {
	decimate_help();
	sprintf(string,"unknown argument (%s) passed to decimate",argv[i]);
	error_message(string);
      }
      i++;
    }
  }

  /* read in the header to establish what the input data are... */
  if ((headersize=read_header(input))) {
    if ( (nsamp > 0) && !strings_equal(inpfile,"stdin") ) {
      naddt=nsamples(inpfile,headersize,nbits,nifs,nchans)/nsamp;
      if (naddt%2) naddt--;
    }
    switch (data_type) {
    case 1:
      break;
    case 2:
      nchans=1;
      break;
    default:
      error_message("input data to decimate is not in filterbank format");
      break;
    }
    /* check number of time samples to add */
    if (naddt <= 1) naddt=1;
    /*if (naddt%2) error_message("time decimation must be a power of 2");*/
    /* check number of frequency channels to add (integer multiple) */
    if (naddc<1) naddc=nchans;
    nc=nchans/naddc;
    if ( (nc*naddc) != nchans ) 
      error_message("nchans must be integer multiple of decimation factor");
    if (obits == 0) obits=nbits;
    if (obits==1) error_message("output of 1-bit data will result in vastly reduced S/N!\nselect a higher output bit size with the -n option");
    /* all ok - broadcast the new header */
    if (!headerless) decimate_header();
  } else {
    error_message("input data file is of unknown origin!!!");
  }
  
  /* finally decimate and output the data */
  decimate_data(input,output);

  exit(0);
}
Пример #14
0
main(int argc, char **argv) 
{
  float tsec,fmhz,peak=1.0,sum,sumsq,sigma,sig2,mean,meansq,chi2,diff;
  float *pcopy,n;
  int hh,mm,i,j,row,dummy,mbins=64,obins,first=1,idx,nprof=1,display=0,rc2=0,flux=0;
  unsigned long *indx;
  char line[240], hash, gry[10], message[80];

  strcpy(gry,"   ,:o*@$#");
  input=stdin;

  if (argc > 1) {
    print_version(argv[0],argv[1]);
    if (help_required(argv[1])) {
      profile_help();
      exit(0);
    }
    i=1;
    while (i<argc) {
      if (file_exists(argv[i])) {
	input=open_file(argv[i],"r");
      } else if (strings_equal(argv[i],"-frequency")) {
	display=1;
      } else if (strings_equal(argv[i],"-chi2")) {
	rc2=1;
      } else if (strings_equal(argv[i],"-sum")) {
	flux=1;
      } else if (strings_equal(argv[i],"-p")) {
	peak=atof(argv[++i]);
      } else {
	sprintf(message,"command-line argument %s not recognized...",argv[i]);
	error_message(message);
      }
      i++;
    }
  }

  fgets(line,sizeof(line),input);
  sscanf(line,"%c %lf %lf %lf %ld %lf %lf %d",&hash,
	 &mjdobs,&tstart,&period,&np,&fch1,&refdm,&nbins);
  if (nbins > 0) {
    while (!feof(input)) {
      profile=(float *) malloc(sizeof(float)*nbins);
      for (i=0; i<nbins; i++) {
	fscanf(input,"%d %f",&dummy,&profile[i]);
      }
      if (rc2 || flux) {
	pcopy=(float *) malloc(sizeof(float)*nbins);
	for (i=0;i<nbins;i++) pcopy[i]=profile[i];
	indx=(unsigned long *) malloc(sizeof(unsigned long)*nbins);
	indexx((unsigned long)nbins,pcopy,indx);
	if (flux) {
	  n=sum=sumsq=0.0;
	  for (i=0;i<40;i++) {
	    sum+=profile[i];
	    sumsq+=profile[i]*profile[i];
	    n+=1.0;
	  }
	  mean=sum/n;
	  meansq=sumsq/n;
	  sigma=sqrt(meansq-mean*mean)/sqrt(n-1.0);
	  n=sum=sumsq=0.0;
	  for (i=43;i<52;i++) {
	    sum+=profile[i];
	    sumsq+=profile[i]*profile[i];
	    n+=1.0;
	  }
	  printf("%f %f\n",sum/n,sigma);
	  exit(0);
	}
	n=sum=sumsq=0.0;
	for (i=0;i<nbins/2;i++) {
	  j=indx[i];
	  sum+=profile[j];
	  sumsq+=profile[j]*profile[j];
	  n+=1.0;
	}
	mean=sum/n;
	meansq=sumsq/n;
	sigma=sqrt(meansq-mean*mean);
	sig2=sigma*sigma;
	sumsq=0.0;
	for (i=0;i<nbins;i++) {
	  diff=profile[i]-mean;
	  sumsq+=diff*diff;
	}
	//chi2=sumsq/sig2/(float)(nbins-1);
	chi2=sumsq/(float)(nbins-1);
	printf("%f %f\n",period,chi2);
	exit(0);
      }
      if (nbins>mbins) {
	add_channels(profile,nbins,nbins/mbins);
	nbins=mbins;
      }
      pmin=vmin(profile,nbins);
      pmax=vmax(profile,nbins)*peak;
      prng=pmax-pmin;
      for (i=0; i<nbins; i++) profile[i]=19.0*(profile[i]-pmin)/prng+1.0;
      for (row=20; row>=1; row--) {
	for (i=0; i<nbins; i++) {
	  if (profile[i]>=(float) row) 
	    printf("#");
	  else
	    printf(" ");
	}
	printf("\n");
      }
      free(profile);
      nbins=0;
      fgets(line,sizeof(line),input);
      fgets(line,sizeof(line),input);
      sscanf(line,"%c %lf %lf %lf %ld %lf %lf %d",&hash,
	 &mjdobs,&tstart,&period,&np,&fch1,&refdm,&nbins);
      if (nbins<=0) break;
    }
  } else {
    while (!feof(input)) {
      sscanf(line,"#START %d %f %f",&nbins,&tsec,&fmhz);
      if (nbins <=0) break;
      profile=(float *) malloc(sizeof(float)*nbins);
      for (i=0; i<nbins; i++) fscanf(input,"%d %f",&dummy,&profile[i]);
      fgets(line,sizeof(line),input);
      fgets(line,sizeof(line),input);
      if (nbins>mbins) {
	obins=nbins;
	add_channels(profile,nbins,nbins/mbins);
	nbins=mbins;
      }
      if (first) {
	pmin=vmin(profile,nbins);
	pmax=vmax(profile,nbins)*peak;
	prng=pmax-pmin;
	/*first=0;*/
      }
      if (display) {
	printf("|%04d|%11.6f|",nprof,fmhz);
      } else {
	hh=(int) tsec/3600.0;
	tsec-=(float) hh*3600.0;
	mm=(int) tsec/60.0;
	tsec-=(float) mm*60.0;
	printf("|%04d|%02d:%02d:%02d|",nprof,hh,mm,(int)tsec);
      }
      for (i=0; i<nbins; i++) {
	idx=(int) (9.0*(profile[i]-pmin)/prng);
	if (idx<0) idx=0;
	if (idx>9) idx=9;
	putchar(gry[idx]);
      }
      puts("|");
      free(profile);
      fgets(line,sizeof(line),input);
      nbins=0;
      nprof++;
    }
  }
}
Пример #15
0
main(int argc, char *argv[]) 
{
	FILE *fileptr[50];
	FILE *output;
    float buffer[4096];  //max channels 4096
    float spectra_sum[128];
    float scale_factor;
	char filename[80],*telescope,*backend,*datatype,message[80],unit[16], outfile[120];
	int i,j, k, year,month,day,check,rah,ram,ded,dem, nfiles, opened=0;
	double ras,des,frac,tobs;
	char sra[6],sde[6],decsign;
	int raw,uth,utm,uts;
	long long numsamps,datasize,headersize;
    long long mindatasize=0;
	int writeobsdbline;

	/* get these from first file on command line, apply to output file */
	int output_nchans=0, output_nbits=0, output_nifs=0;
	long long output_datasize=0;
    long long output_headersize=0;
    int output_ptr;
	char quantval;
    
    double mean=0.0, sigma=0.0;
    
    

    
  /* work out how many files are on the command line */
  i=1;
  nfiles=0;
  while(file_exists(argv[i]) && (i < argc)) {
        //printf("opening %s\n", argv[i]);
  	    nfiles++;
        i++;
  }
  if (!nfiles) {
	  error_message("no input files supplied on command line!");
	  exit(1);
  }

  if (nfiles > 50) {
      error_message("too many input files supplied on command line (max 50)!");
	  exit(1);
  }


  for(i = 0; i<nfiles; i++) {
			  fileptr[i]=open_file(argv[i+1],"rb");
  }


  if (argc>nfiles) {
	 i=nfiles+1;
	 while (i<argc) {
		if (strings_equal(argv[i],"-o")) {
		
		  /* get and open file for output */
		  strcpy(outfile,argv[++i]);
		  if(file_exists(outfile)) {
			  sprintf(message,"output file (%s) exists!",argv[i]);
			  error_message(message);
			  exit(1);
		  }
		  output=fopen(outfile,"wb");
		  opened=1;
		} else {
			/* unknown argument passed down - stop! */
			sprintf(message,"unknown argument (%s) passed to filterbank.",argv[i]);
			error_message(message);
			exit(1);
		}
		i++;
	  }
  }

  if (!opened) {
	  error_message("must have an output file (-o <output>)!");
	  exit(1);
  }


	pulsarcentric=barycentric=0;
	writeobsdbline=0;
	


    
  for(i = 0; i<nfiles; i++) {
		headersize=read_header(fileptr[i]);		
	    rewind(fileptr[i]);
		datasize=sizeof_file(argv[i+1])-headersize;
	    numsamps=nsamples(argv[i+1],headersize,nbits,nifs,nchans);
		if(output_datasize == 0 || datasize < output_datasize) {
			output_datasize = datasize;
		    output_headersize = headersize;
			output_ptr = i;
		}
		if(output_nchans == 0) {
		  output_nchans = nchans; 
		  output_nbits = nbits; 
		  output_nifs = nifs;		
		}
        if(nchans != output_nchans || nbits != output_nbits || nifs != output_nifs) {
			sprintf(message,"channel/if/bit mismatch, exiting...");
			error_message(message);
			exit(1);
        }
        
        //printf("file: %s headersize: %d nbits: %d nifs: %d nchans: %d\n", argv[i+1], headersize, nbits, nifs, nchans); 
  }


  if (output_nbits != 32) {
	  error_message("This routine only works on 32 bit (float) filterbank data!");
	  exit(1);
  }
  
 
  printf("minimum data size is: %d\n", output_datasize);
  
  printf("will dump: %d\n", (output_datasize / (long long) (output_nifs * output_nchans)));
  
  headersize=read_header(fileptr[output_ptr]);
  rewind(fileptr[output_ptr]);

  printf("header size lead file: %d\n", headersize); 
  fread(buffer, sizeof(char), headersize, fileptr[output_ptr]);
  fwrite(buffer, sizeof(char), headersize, output);
  rewind(fileptr[output_ptr]);

 /* bump past header for all input files */
   for(i = 0; i<nfiles; i++) {
		headersize=read_header(fileptr[i]);	
	}
  


 /* rewind and bump past header for all input files */
   for(i = 0; i<nfiles; i++) {
		rewind( fileptr[i] );
		headersize=read_header(fileptr[i]);	
	}

scale_factor = output_datasize / ((float) (output_nifs * output_nchans));

/* outer loop, read through all spectra, quantize to 8 bits, write to file */

  for (j = 0; j < (output_datasize / (long long) (output_nifs * output_nchans)); j++){
  
	 /* read n spectra (1 spectra x n files), sum */
	 for(i=0;i<128;i++) spectra_sum[i] = 0.0;
	 for(i = 0; i<nfiles; i++) {
	     fread(&buffer, sizeof(float), (output_nifs * output_nchans), fileptr[i]); 		

         for(k=0; k<128; k++) spectra_sum[k] = (spectra_sum[k] + (buffer[k] / scale_factor) );
	  }
	  fwrite(&spectra_sum, sizeof(float), 128, output); 		        

   }



/*
	if (argc>1) {
		print_version(argv[0],argv[1]);
		if (help_required(argv[1])) {
			header_help();
			exit(0);
		} else if (file_exists(argv[1])) {
			strcpy(filename,argv[1]);
			fileptr=open_file(filename,"rb");
		} else if (!file_exists(argv[1]) && (strncmp(argv[1],"-",1) !=0)) {
			sprintf(message,"Data file: %s not found...\n",argv[1]);
			error_message(message);
			exit(1);
		}
	}
*/

}
Пример #16
0
int read_header(FILE *inputfile, header *h) {
  char string[80], message[80];
  int itmp,nbytes,totalbytes,expecting_rawdatafile=0,expecting_source_name=0; 
  int expecting_frequency_table=0,channel_index;


  /* try to read in the first line of the header */
  get_string(inputfile,&nbytes,string);
  if (!strings_equal(string,"HEADER_START")) {
	/* the data file is not in standard format, rewind and return */
	rewind(inputfile);
	return 0;
  }
  /* store total number of bytes read so far */
  totalbytes=nbytes;

  /* loop over and read remaining header lines until HEADER_END reached */
  while (1) {
    get_string(inputfile,&nbytes,string);
    if (strings_equal(string,"HEADER_END")) break;
    totalbytes+=nbytes;
    if (strings_equal(string,"rawdatafile")) {
      expecting_rawdatafile=1;
    } else if (strings_equal(string,"source_name")) {
      expecting_source_name=1;
    } else if (strings_equal(string,"FREQUENCY_START")) {
      expecting_frequency_table=1;
      channel_index=0;
    } else if (strings_equal(string,"FREQUENCY_END")) {
      expecting_frequency_table=0;
    } else if (strings_equal(string,"az_start")) {
      fread(&h->az_start,sizeof(h->az_start),1,inputfile);
      totalbytes+=sizeof(h->az_start);
    } else if (strings_equal(string,"za_start")) {
      fread(&h->za_start,sizeof(h->za_start),1,inputfile);
      totalbytes+=sizeof(h->za_start);
    } else if (strings_equal(string,"src_raj")) {
      fread(&h->src_raj,sizeof(h->src_raj),1,inputfile);
      totalbytes+=sizeof(h->src_raj);
    } else if (strings_equal(string,"src_dej")) {
      fread(&h->src_dej,sizeof(h->src_dej),1,inputfile);
      totalbytes+=sizeof(h->src_dej);
    } else if (strings_equal(string,"tstart")) {
      fread(&h->tstart,sizeof(h->tstart),1,inputfile);
      totalbytes+=sizeof(h->tstart);
    } else if (strings_equal(string,"tsamp")) {
      fread(&h->tsamp,sizeof(h->tsamp),1,inputfile);
      totalbytes+=sizeof(h->tsamp);
    } else if (strings_equal(string,"period")) {
      fread(&h->period,sizeof(h->period),1,inputfile);
      totalbytes+=sizeof(h->period);
    } else if (strings_equal(string,"fch1")) {
      fread(&h->fch1,sizeof(h->fch1),1,inputfile);
      totalbytes+=sizeof(h->fch1);
    } else if (strings_equal(string,"foff")) {
      fread(&h->foff,sizeof(h->foff),1,inputfile);
      totalbytes+=sizeof(h->foff);
    } else if (strings_equal(string,"nchans")) {
      fread(&h->nchans,sizeof(h->nchans),1,inputfile);
      totalbytes+=sizeof(h->nchans);
    } else if (strings_equal(string,"telescope_id")) {
      fread(&h->telescope_id,sizeof(h->telescope_id),1,inputfile);
      totalbytes+=sizeof(h->telescope_id);
    } else if (strings_equal(string,"machine_id")) {
      fread(&h->machine_id,sizeof(h->machine_id),1,inputfile);
      totalbytes+=sizeof(h->machine_id);
    } else if (strings_equal(string,"data_type")) {
      fread(&h->data_type,sizeof(h->data_type),1,inputfile);
      totalbytes+=sizeof(h->data_type);
    } else if (strings_equal(string,"ibeam")) {
      fread(&h->ibeam,sizeof(h->ibeam),1,inputfile);
      totalbytes+=sizeof(h->ibeam);
    } else if (strings_equal(string,"nbeams")) {
      fread(&h->nbeams,sizeof(h->nbeams),1,inputfile);
      totalbytes+=sizeof(h->nbeams);
    } else if (strings_equal(string,"nbits")) {
      fread(&h->nbits,sizeof(h->nbits),1,inputfile);
      totalbytes+=sizeof(h->nbits);
    } else if (strings_equal(string,"barycentric")) {
      fread(&h->barycentric,sizeof(h->barycentric),1,inputfile);
      totalbytes+=sizeof(h->barycentric);
    } else if (strings_equal(string,"pulsarcentric")) {
      fread(&h->pulsarcentric,sizeof(h->pulsarcentric),1,inputfile);
      totalbytes+=sizeof(h->pulsarcentric);
    } else if (strings_equal(string,"nbins")) {
      fread(&h->nbins,sizeof(h->nbins),1,inputfile);
      totalbytes+=sizeof(h->nbins);
    } else if (strings_equal(string,"nsamples")) {
      /* read this one only for backwards compatibility */
      fread(&itmp,sizeof(itmp),1,inputfile);
      totalbytes+=sizeof(itmp);
    } else if (strings_equal(string,"nifs")) {
      fread(&h->nifs,sizeof(h->nifs),1,inputfile);
      totalbytes+=sizeof(h->nifs);
    } else if (strings_equal(string,"npuls")) {
      fread(&h->npuls,sizeof(h->npuls),1,inputfile);
      totalbytes+=sizeof(h->npuls);
    } else if (strings_equal(string,"refdm")) {
      fread(&h->refdm,sizeof(h->refdm),1,inputfile);
      totalbytes+=sizeof(h->refdm);
    } else if (expecting_rawdatafile) {
      strcpy(h->rawdatafile,string);
      expecting_rawdatafile=0;
    } else if (expecting_source_name) {
      strcpy(h->source_name,string);
      expecting_source_name=0;
    } else if (strings_equal(string,"smin")) {
      fread(&h->smin,sizeof(h->smin),1,inputfile);
      totalbytes+=sizeof(h->smin);
    } else if (strings_equal(string,"smax")) {
      fread(&h->smax,sizeof(h->smax),1,inputfile);
      totalbytes+=sizeof(h->smax);
    } else {
      sprintf(message,"read_header - unknown parameter: %s\n",string);
      fprintf(stderr,"ERROR: %s\n",message);
      exit(1);
    } 
  } 

  /* add on last header string */
  totalbytes+=nbytes;

  /* return total number of bytes read */
  return totalbytes;
}
Пример #17
0
int main (void)
{
	sei();
	uart_init(UART_BAUD_SELECT(9600, F_CPU));
	uart_puts("\r\n\r\nTHIS PROGRAM USES 57600 BAUD - PLEASE CHANGE\r\n\r\n");

	_delay_ms(100);
	uart_init(UART_BAUD_SELECT(57600, F_CPU));
	cmd_clear();

	uart_puts_P("\n\n\n\n\r");
	uart_puts_P("--------------------------\r\n");
	uart_puts_P("System                [OK]\r\n");
	systimer_init();
	uart_puts_P("System Timer          [OK]\r\n");

	/* SD Karte Initilisieren */
	cmd_init();

	uart_puts_P("--------------------------\r\n\r\n");

	_delay_ms(100);
	char input[50]={0};
	static char parameters[10][32];
	while(1)
	{
		for (uint8_t i = 0; i<=10; *parameters[++i]=0x00);

		// Input
		uart_puts_P("> ");
		uart_input(input);

		// Process Input
		getparams(input, 10, 32, parameters);
		char *cmd = parameters[0];

		// Call Functions
		if (strings_equal(cmd, "ls"))
		{
			uint32_t cluster = 0;
			if (parameters[1][0] != 0x00)
				cluster = str2num(parameters[1], 16);
			cmd_ls(cluster);
		}
		else if (strings_equal(cmd, "cat"))
		{
			if (parameters[1][0] == 0x00 || parameters[2][0] == 0x00)
				cmd_help("cat");
			else
			{
				uint64_t cluster	= str2num(parameters[1], 16);
				uint64_t size		= str2num(parameters[2], 16);
				cmd_cat(cluster, size);
			}
		}
		else if (strings_equal(cmd, "readtest"))
		{
			if (parameters[1][0] == 0x00 || parameters[2][0] == 0x00)
				cmd_help("readtest");
			else
			{
				uint64_t cluster	= str2num(parameters[1], 16);
				uint64_t size		= str2num(parameters[2], 16);
				cmd_readtest(cluster, size);
			}
		}
		else if (strings_equal(cmd, "write"))
		{
			if (parameters[1][0] == 0x00 || parameters[2][0] == 0x00)
				cmd_help("write");
			else
			{
				uint64_t cluster	= str2num(parameters[1], 16);
				uint8_t  adcport	= str2num(parameters[2], 10);
				uint64_t maxsize	= str2num(parameters[3], 16);
				uint8_t  speed		= str2num(parameters[4], 10);
				if (parameters[3][0] == 0x00)
					maxsize = 512;
				if (parameters[4][0] == 0x00)
					speed = 50;
				cmd_write(cluster, adcport, maxsize, speed);
			}
		}
		else if (strings_equal(cmd, "clear"))
			cmd_clear();
		else if (strings_equal(cmd, "time"))
			cmd_time();
		else if (strings_equal(cmd, "init"))
			cmd_init();
		else if (strings_equal(cmd, "help"))
			cmd_help(parameters[1]);
		else
			uart_puts_P("Error: Command not found\n\r");
	}

	while (1);
	return (1);
}
Пример #18
0
main (int argc, char **argv)
{
  int i=1, j, k, nfiles=0, *numbt, schans=0, nbytes, *nchan;
  FILE *input[32];
  char *block;
  double *stamp, *frch1, *froff, *frmhz;
  output=stdout;
  /* print help if necessary */
  if (argc<=1 || help_required(argv[1])) {
    /*splice_help();*/
    exit(0);
  } else {
    print_version(argv[0],argv[1]);
  }

  /* open up files */
  while (i<argc) {
    if (file_exists(argv[i])) {
      input[nfiles]=open_file(argv[i],"rb");
      nfiles++;
    } else if (strings_equal(argv[i],"-o")) {
      output=open_file(argv[++i],"wb");
    }
    i++;
  }

  /* read in headers and check time stamps */
  stamp = (double *) malloc(nfiles*sizeof(double));
  frch1 = (double *) malloc(nfiles*sizeof(double));
  froff = (double *) malloc(nfiles*sizeof(double));
  numbt = (int *) malloc(nfiles*sizeof(int));
  nchan = (int *) malloc(nfiles*sizeof(int));
  for (i=0; i<nfiles; i++) {
    if (read_header(input[i])) {
      stamp[i]=tstart;
      frch1[i]=fch1;
      froff[i]=foff;
      numbt[i]=nbits;
      nchan[i]=nchans;
      schans+=nchans;
    } else {
      error_message("problem reading header parameters");
    }
    if (data_type != 1) 
      error_message("input data are not in filterbank format!");
    if (stamp[i] != stamp[0]) 
      error_message("start times in input files are not identical!");
    if (numbt[i] != numbt[0])
      error_message("number of bits per sample in input files not identical!");
    if (i>0) {
      if (frch1[i] > frch1[i-1]) 
	error_message("input files not ordered in descending frequency!");
    }

  }


  send_string("HEADER_START");
  send_int("machine_id",machine_id);
  send_int("telescope_id",telescope_id);
  send_int("data_type",1);

  send_string("FREQUENCY_START");
  send_int("nchans",schans);
  frmhz = (double *) malloc(sizeof(double)*schans);
  k=0;
  for (i=0; i<nfiles; i++) {
    for (j=0; j<nchans; j++) {
      frmhz[k]=frch1[i]+j*froff[i];
      send_double("fchannel",frmhz[k++]);
    }
  }
  send_string("FREQUENCY_END");
  

  if (!strings_equal(source_name,"")) {
    send_string("source_name");
    send_string(source_name);
  }
  send_coords(src_raj,src_dej,az_start,za_start);
  send_int("nbits",nbits);
  send_double("tstart",tstart);
  send_double("tsamp",tsamp);
  send_int("nifs",nifs);
  send_string("HEADER_END");

  nbytes = nchans*nbits/8;
  block = (char *) malloc(nbytes);
  while (1) {
    for (i=0; i<nfiles; i++) {
      if (feof(input[i])) exit(0);
      fread(block,nbytes,1,input[i]);
      fwrite(block,nbytes,1,output);
    }
  }
}
Пример #19
0
main (int argc, char *argv[]) 
{
  float clip_level, *blk, sum, mean, blksum, blksum2, blkmean, blkmean2;
  unsigned char *cblk;
  unsigned short *sblk;
  float blksigma, dmean, dsigma;
  int blksize, nread, nsblk, i, headersize, c, s, offset, obits;
  long int isamp=0, seed=0, nclip=0;

  if (argc<2 || help_required(argv[1])) {
    //blanker_help();
    exit(0);
  }
  print_version(argv[0],argv[1]);
  if (!file_exists(argv[1]))
    error_message("input file does not exist!");

  strcpy(inpfile,argv[1]);
  input=open_file(inpfile,"r");
  strcpy(outfile,"stdout");
  output=stdout;
  nsblk=1024;
  clip_level=6.0;
  obits=32;

  i=2;
  while (i<argc) {
    if (strings_equal(argv[i],"-c"))       clip_level=atof(argv[++i]);
    if (strings_equal(argv[i],"-s"))       nsblk=atof(argv[++i]);
    if (strings_equal(argv[i],"-b"))       obits=atoi(argv[++i]);
    i++;
  }

  if ((headersize=read_header(input))) {

    if (nifs>1) error_message("blanker can only handle nifs=1");

    send_string("HEADER_START");
    if (!strings_equal(source_name,"")) {
      send_string("source_name");
      send_string(source_name);
    }
    send_int("telescope_id",telescope_id); 
    send_int("machine_id",machine_id);
    send_coords(src_raj,src_dej,az_start,za_start);
    send_int("data_type",data_type);
    send_double("fch1",fch1);
    send_double("foff",foff);
    send_int("barycentric",barycentric);
    send_int("nchans",nchans);
    send_int("nbits",obits);  
    send_double ("tstart",tstart); 
    send_double("tsamp",tsamp);
    send_int("nifs",nifs);
    send_string("HEADER_END");

    
    blksize=nchans*nsblk;
    blk = (float *) malloc(blksize*sizeof(float));
    cblk = (unsigned char *) malloc(blksize*sizeof(unsigned char));
    sblk = (unsigned short *) malloc(blksize*sizeof(unsigned short));
    
    while (nread=read_block(input,nbits,blk,blksize)) {

      /* calculate mean and sigma of the whole block */
      blksum=blksum2=0.0;
      for (i=0; i<nread; i++) {
	blksum+=blk[i];
	blksum2+=blk[i]*blk[i];
      }
      blkmean=blksum/(float)nread;
      blkmean2=blksum2/(float)nread;
      blksigma=sqrt(blkmean2-blkmean*blkmean);
      /* expected mean and sigma of a dedispersed sample in this block */
      dmean=blkmean*(float)nchans;
      dsigma=blksigma*sqrt((float)nchans);

      /* now work through each sample in the block */
      nsblk=nread/nchans;
      offset=0;
      for (s=0; s<nsblk; s++) {
	isamp++;
	sum=0.0;
	for (c=0; c<nchans; c++) sum+=blk[offset+c];
	if (abs(sum-dmean)>clip_level*dsigma) {
	  nclip++;
	  for (c=0; c<nchans; c++) 
	    blk[offset+c]=gasdev(&seed)*blksigma+blkmean;
	}
	offset+=nchans;
      }

      /* write out the clipped data (32 bit!) */
      if (obits == 32) 
	fwrite(blk,sizeof(float),nread,output);
      } else if (obits == 8) {
	for (i=0;i<nread;i++) cblk[i]=blk[i];
	fwrite(cblk,sizeof(unsigned char),nread,output);
      } else if (obits == 16) {
	for (i=0;i<nread;i++) sblk[i]=blk[i];
	fwrite(sblk,sizeof(unsigned short),nread,output);
      } else {
	error_message("only 8, 16 or 32 bit output modes supported");
      }
    }
Пример #20
0
int main(int argc, char* argv[]){

    char* taskfilename = "todo.txt";
//    char* donefile = "done.txt";

    //bool verbose = false;

    int status = EXIT_SUCCESS;

    // parse the command line arguments.
    if (argc < 2){
        print_short_help();
        exit(status);
    }
    int i;
		//start the loop at 1 because argv[0] refers to the binary file
    for (i = 1; i < argc; i++){
        // Add a new task.
        if (strings_equal(argv[i], "add", "-a")){
            if (add_task(taskfilename, argv[i+1]) != 0){
                status = EXIT_FAILURE;   // We done goofed.
            }
            i++;  // Skip the next argument.
            continue;
        }

        // Remove a task.
        if (strings_equal(argv[i], "rm", "-r")){
            int index = atoi(argv[i+1]);
            if (remove_task(taskfilename, index) != 0){
                status = EXIT_FAILURE;
            }
            i++;
            continue;
        }

        // Complete a task.
        if (strings_equal(argv[i], "do", "-d")){
            int index = atoi(argv[i+1]);
            set_complete_task(taskfilename, index, true);
            i++;
            continue;
        }

        // Uncomplete a task.
        if (strings_equal(argv[i], "undo", "-u")){
            int index = atoi(argv[i+1]);
            set_complete_task(taskfilename, index, false);
            i++;
            continue;
        }
        
        // List the tasks matching the string in the file.
        if (strings_equal(argv[i], "search", "-s")){
            list_tasks_matching(taskfilename, argv[i+1]);
            i++;
            continue;
        }
        
        // Show all the tasks in the file.
        if(strings_equal(argv[i], "ls", "-l")){
            list_tasks(taskfilename);
            continue;
        }
        
        // Show the help dialog.
        if (strcmp(argv[i], "-h") == 0){
            print_help();
        }

        // Set the taskfilename flag.
        if (strcmp(argv[i], "-f") == 0){
            taskfilename = argv[i+1]; 
            i++;
            continue;
        }

        // Set the verbosity flag.
        if (strcmp(argv[i], "-v") == 0){
            // verbose = true;
        }

    }

    return status;
}
Пример #21
0
/* Returns 1 if the contexts are equal, 0 otherwise. */
static int SSL_TEST_CTX_equal(SSL_TEST_CTX *ctx, SSL_TEST_CTX *ctx2)
{
    if (ctx->expected_result != ctx2->expected_result) {
        fprintf(stderr, "ExpectedResult mismatch: %s vs %s.\n",
                ssl_test_result_name(ctx->expected_result),
                ssl_test_result_name(ctx2->expected_result));
        return 0;
    }
    if (ctx->client_alert != ctx2->client_alert) {
        fprintf(stderr, "ClientAlert mismatch: %s vs %s.\n",
                ssl_alert_name(ctx->client_alert),
                ssl_alert_name(ctx2->client_alert));
        return 0;
    }
    if (ctx->server_alert != ctx2->server_alert) {
        fprintf(stderr, "ServerAlert mismatch: %s vs %s.\n",
                ssl_alert_name(ctx->server_alert),
                ssl_alert_name(ctx2->server_alert));
        return 0;
    }
    if (ctx->protocol != ctx2->protocol) {
        fprintf(stderr, "ClientAlert mismatch: %s vs %s.\n",
                ssl_protocol_name(ctx->protocol),
                ssl_protocol_name(ctx2->protocol));
        return 0;
    }
    if (ctx->client_verify_callback != ctx2->client_verify_callback) {
        fprintf(stderr, "ClientVerifyCallback mismatch: %s vs %s.\n",
                ssl_verify_callback_name(ctx->client_verify_callback),
                ssl_verify_callback_name(ctx2->client_verify_callback));
        return 0;
    }
    if (ctx->servername != ctx2->servername) {
        fprintf(stderr, "ServerName mismatch: %s vs %s.\n",
                ssl_servername_name(ctx->servername),
                ssl_servername_name(ctx2->servername));
        return 0;
    }
    if (ctx->expected_servername != ctx2->expected_servername) {
        fprintf(stderr, "ExpectedServerName mismatch: %s vs %s.\n",
                ssl_servername_name(ctx->expected_servername),
                ssl_servername_name(ctx2->expected_servername));
        return 0;
    }
    if (ctx->servername_callback != ctx2->servername_callback) {
        fprintf(stderr, "ServerNameCallback mismatch: %s vs %s.\n",
                ssl_servername_callback_name(ctx->servername_callback),
                ssl_servername_callback_name(ctx2->servername_callback));
        return 0;
    }
    if (ctx->session_ticket_expected != ctx2->session_ticket_expected) {
        fprintf(stderr, "SessionTicketExpected mismatch: %s vs %s.\n",
                ssl_session_ticket_name(ctx->session_ticket_expected),
                ssl_session_ticket_name(ctx2->session_ticket_expected));
        return 0;
    }
#ifndef OPENSSL_NO_NEXTPROTONEG
    if (!strings_equal("ClientNPNProtocols", ctx->client_npn_protocols,
                       ctx2->client_npn_protocols))
        return 0;
    if (ctx->method != ctx2->method) {
        fprintf(stderr, "Method mismatch: %s vs %s.\n",
                ssl_test_method_name(ctx->method),
                ssl_test_method_name(ctx2->method));
        return 0;
    }
    if (!strings_equal("ServerNPNProtocols", ctx->server_npn_protocols,
                       ctx2->server_npn_protocols))
        return 0;
    if (!strings_equal("Server2NPNProtocols", ctx->server_npn_protocols,
                       ctx2->server_npn_protocols))
        return 0;
    if (!strings_equal("ExpectedNPNProtocol", ctx->expected_npn_protocol,
                       ctx2->expected_npn_protocol))
        return 0;
    if (!strings_equal("ClientALPNProtocols", ctx->client_alpn_protocols,
                       ctx2->client_alpn_protocols))
        return 0;

    if (!strings_equal("ServerALPNProtocols", ctx->server_alpn_protocols,
                       ctx2->server_alpn_protocols))
        return 0;
    if (!strings_equal("Server2ALPNProtocols", ctx->server_alpn_protocols,
                       ctx2->server_alpn_protocols))
        return 0;
    if (!strings_equal("ExpectedALPNProtocol", ctx->expected_alpn_protocol,
                       ctx2->expected_alpn_protocol))
        return 0;
#endif
    if (ctx->handshake_mode != ctx2->handshake_mode) {
        fprintf(stderr, "HandshakeMode mismatch: %s vs %s.\n",
                ssl_handshake_mode_name(ctx->handshake_mode),
                ssl_handshake_mode_name(ctx2->handshake_mode));
        return 0;
    }
    if (ctx->resumption_expected != ctx2->resumption_expected) {
        fprintf(stderr, "ResumptionExpected mismatch: %d vs %d.\n",
                ctx->resumption_expected, ctx2->resumption_expected);
        return 0;
    }
    return 1;
}
// compares two strings in compile time constant fashion
constexpr bool strings_equal(char const * a, char const * b) {
    return *a == *b && (*a == '\0' || strings_equal(a + 1, b + 1));
}
Пример #23
0
main(int argc, char *argv[]) 
{
	FILE *fileptr;
	char filename[80],*telescope,*backend,*datatype,message[80],unit[16];
	int i,j,year,month,day,check,rah,ram,ded,dem;
	double ras,des,frac,tobs;
	char sra[6],sde[6],decsign;
	int raw,uth,utm,uts;
	long long numsamps,datasize,headersize;

	int writeobsdbline;

	fileptr=stdin;
	strcpy(filename,"stdin");
	strcpy(rawdatafile,"stdin");
	pulsarcentric=barycentric=0;

	writeobsdbline=0;

	if (argc>1) {
		print_version(argv[0],argv[1]);
		if (help_required(argv[1])) {
			header_help();
			exit(0);
		} else if (file_exists(argv[1])) {
			strcpy(filename,argv[1]);
			fileptr=open_file(filename,"rb");
		} else if (!file_exists(argv[1]) && (strncmp(argv[1],"-",1) !=0)) {
			sprintf(message,"Data file: %s not found...\n",argv[1]);
			error_message(message);
			exit(1);
		}
	}


	if (!(headersize=read_header(fileptr))) {
		rewind(fileptr);
		if ((raw=typeof_inputdata(fileptr,filename))) {
			data_type=0;
			switch (raw) {
				case 1:
					headersize=32768;
					break;
				case 5:
					headersize=32768;
					break;
				case 3:
					headersize=wapp_header_size+wapp_incfile_length;
					break;
				default:
					break;
			}
		} else {
			error_message("could not read header parameters!");
			exit(1);
		}
	}

	/* attempt to find number of bytes of data and number of samples */
	if (!strings_equal(filename,"stdin")) {
		datasize=sizeof_file(filename)-headersize;
		numsamps=nsamples(filename,headersize,nbits,nifs,nchans);
	} else if (!strings_equal(rawdatafile,"stdin")) {
		datasize=sizeof_file(rawdatafile)-headersize;
		numsamps=nsamples(rawdatafile,headersize,nbits,nifs,nchans);
	} else {
		datasize=numsamps=0;
	}

	telescope=telescope_name(telescope_id);
	backend=backend_name(machine_id);
	datatype=data_category(data_type);

	if (argc>2) {
		check=1;
		i=2;
	} else if ((argc>1) && strings_equal(filename,"stdin")) {
		check=1;
		i=1;
	} else {
		check=0;
	}

	angle_split(src_raj,&rah,&ram,&ras);
	if (ras<10.0) {
		sprintf(sra,"0%.1f",ras);
	} else {
		sprintf(sra,"%.1f",ras);
	}

	angle_split(src_dej,&ded,&dem,&des);
	if (src_dej > 0.0) 
		decsign = '+';
	else 
		decsign = '-';
	if (des<10.0) {
		sprintf(sde,"0%.1f",des);
	} else {
		sprintf(sde,"%.1f",des);
	}

	cal(tstart,&year,&month,&day);

	if (check) {
		/* check command-line parameters */ 
		while (i<argc) {
			if (strings_equal(argv[i],"-telescope")) {
				puts(telescope);
			} else if (strings_equal(argv[i],"-obsdb")) {
				writeobsdbline=1;
			} else if (strings_equal(argv[i],"-machine")) {
				puts(backend);
			} else if (strings_equal(argv[i],"-source_name")) {
				puts(source_name);
			} else if (strings_equal(argv[i],"-scan_number")) {
				puti(scan_number);
			} else if (strings_equal(argv[i],"-datatype")) {
				puts(datatype);
			} else if (strings_equal(argv[i],"-frame")) {
				if (pulsarcentric) 
					puts("pulsarcentric");
				else if (barycentric) 
					puts("barycentric");
				else 
					puts("topocentric");
			} else if (strings_equal(argv[i],"-barycentric")) {
				puti(barycentric);
			} else if (strings_equal(argv[i],"-pulsarcentric")) {
				puti(pulsarcentric);
			} else if (strings_equal(argv[i],"-data_type")) {
				puti(data_type);
			} else if (strings_equal(argv[i],"-headersize")) {
				printf("%d\n",headersize);
			} else if (strings_equal(argv[i],"-datasize")) {
				printf("%lld\n",datasize);
			} else if (strings_equal(argv[i],"-nsamples")) {
				printf("%lld\n",numsamps);
			} else if (strings_equal(argv[i],"-tobs")) {
				printf("%f\n",(double)numsamps*tsamp);
			} else if (strings_equal(argv[i],"-az_start")) {
				printf("%f\n",az_start);
			} else if (strings_equal(argv[i],"-za_start")) {
				printf("%f\n",za_start);
			} else if (strings_equal(argv[i],"-fch1")) {
				printf("%.3f\n",fch1);
			} else if (strings_equal(argv[i],"-bandwidth")) {
				printf("%.3f\n",fabs(foff)*(double)nchans);
			} else if (strings_equal(argv[i],"-fmid")) {
				printf("%.3f\n",fch1+foff*nchans/2);
			} else if (strings_equal(argv[i],"-foff")) {
				printf("%f\n",foff);
			} else if (strings_equal(argv[i],"-refdm")||strings_equal(argv[i],"-dm")) {
				printf("%f\n",refdm);
			} else if (strings_equal(argv[i],"-nchans")) {
				printf("%d\n",nchans);
			} else if (strings_equal(argv[i],"-tstart")) {
				printf("%.12f\n",tstart);
			} else if (strings_equal(argv[i],"-frequencies")) {
				for (j=0; j<nchans; j++) printf("%f\n",frequency_table[j]);
			} else if (strings_equal(argv[i],"-mjd")) {
				printf("%d\n",(int)floor(tstart));
			} else if (strings_equal(argv[i],"-date")) {
				printf("%4d/%02d/%02d\n",year,month,day);
			} else if (strings_equal(argv[i],"-utstart")) {
				frac=tstart-floor(tstart);
				uth=(int) floor(24.0*frac);
				frac-=(double)uth/24.0;
				utm=(int) floor(1440.0*frac);
				frac-=(double)utm/1440.0;
				uts=(int) floor(86400.0*frac);
				printf("%02d:%02d:%02d\n",uth,utm,uts);
			} else if (strings_equal(argv[i],"-tsamp")) {
				printf("%.5f\n",tsamp*1.0e6);
			} else if (strings_equal(argv[i],"-nbits")) {
				printf("%d\n",nbits);
			} else if (strings_equal(argv[i],"-nifs")) {
				printf("%d\n",nifs);
			} else if (strings_equal(argv[i],"-src_raj")) {
				printf("%02d:%02d:%s\n",rah,ram,sra);
			} else if (strings_equal(argv[i],"-src_dej")) {
				printf("%c%02d:%02d:%s\n",decsign,abs(ded),dem,sde);
			}else if (strings_equal(argv[i],"-ra_deg")) {
				printf("%f\n",rah*15+ram/4.0+ras/240.0);
			} else if (strings_equal(argv[i],"-dec_deg")) {
				printf("%c%f\n",decsign,abs(ded)+dem/60.0+des/3600.0);
			} else {
				header_help();
				sprintf(message,"unknown argument (%s) passed to header",argv[i]);
				error_message(message);
			}
			i++;
		}
		/* if we are doing a obs line do this... otherwise continue normaly
		 * MK 2006, for the MM survey bookkeeping.
		 */


		if(writeobsdbline){
			printf("%s ",source_name);
                        printf("%3.3lf %3.3lf ",gal_l,gal_b);
			printf("%s ",filename);
                        printf("%5.3lf %6.6lf ",header_tobs,tstart);
			printf("%6.3lf %6.3lf ",src_raj,src_dej);
                        printf("%5.3lf %3.3lf ",raw_fch1,raw_foff);
			printf("%d %d %5.3lf",nbeams,nchans,tsamp*1000);
			printf("\n");

		}

		exit(0);
	}


	/* no command-line flags were specified - display full output */

	printf("Data file                        : %s\n",filename);
	printf("Header size (bytes)              : %d\n",headersize);
	if (datasize) 
		printf("Data size (bytes)                : %lld\n",datasize);
	if (pulsarcentric) 
		printf("Data type                        : %s (pulsarcentric)\n",datatype);
	else if (barycentric) 
		printf("Data type                        : %s (barycentric)\n",datatype);
	else
		printf("Data type                        : %s (topocentric)\n",datatype);

	printf("Telescope                        : %s\n",telescope);
	printf("Datataking Machine               : %s\n",backend);


	if (!strings_equal(source_name,"")) 
		printf("Source Name                      : %s\n",source_name);
	if (src_raj != 0.0) 
		printf("Source RA (J2000)                : %02d:%02d:%s\n",rah,ram,sra);
	if (src_dej != 0.0)
		printf("Source DEC (J2000)               : %c%02d:%02d:%s\n",
				decsign,abs(ded),dem,sde);
	if ((az_start != 0.0) && (az_start != -1.0))
		printf("Start AZ (deg)                   : %f\n",az_start);
	if ((za_start != 0.0) && (za_start != -1.0))
		printf("Start ZA (deg)                   : %f\n",za_start);

	switch (data_type) {
		case 0:
		case 1:
			if ((fch1==0.0) && (foff==0.0)) {
				printf("Highest frequency channel (MHz)  : %f\n",
						frequency_table[0]);
				printf("Lowest frequency channel  (MHz)  : %f\n",
						frequency_table[nchans-1]);
			} else {
				printf("Frequency of channel 1 (MHz)     : %f\n",fch1);
				printf("Channel bandwidth      (MHz)     : %f\n",foff); 
				printf("Number of channels               : %d\n",nchans);
				printf("Number of beams                  : %d\n",nbeams);
				printf("Beam number                      : %d\n",ibeam); 
			}
			break;
		case 2:
			nchans=1;
			printf("Reference DM (pc/cc)             : %f\n",refdm);
			printf("Reference frequency    (MHz)     : %f\n",fch1);
			break;
		case 3:
			if (refdm > 0.0)
				printf("Reference DM (pc/cc)             : %f\n",refdm);
			printf("Frequency of channel 1 (MHz)     : %f\n",fch1);
			printf("Channel bandwidth      (MHz)     : %f\n",foff); 
			printf("Number of channels               : %d\n",nchans);
			printf("Number of phase bins             : %d\n",nbins);
			printf("Folding period  (s)              : %.12f\n",period);
			break;
		case 6:
			printf("Reference DM (pc/cc)             : %f\n",refdm);
			printf("Frequency of channel 1 (MHz)     : %f\n",fch1);
			printf("Channel bandwidth      (MHz)     : %f\n",foff); 
			printf("Number of channels               : %d\n",nchans);
			break;
	}

	printf("Time stamp of first sample (MJD) : %.12f\n",tstart);
	printf("Gregorian date (YYYY/MM/DD)      : %4d/%02d/%02d\n",year,month,day);

	if (data_type != 3) 
		printf("Sample time (us)                 : %.5f\n",tsamp*1.0e6); 

	if (datasize && data_type != 3) {
		printf("Number of samples                : %lld\n",numsamps);
		tobs=(double)numsamps*tsamp;
		strcpy(unit,"(seconds)   ");
		if (tobs>60.0) {
			tobs/=60.0;
			strcpy(unit,"(minutes)   ");
			if (tobs>60.0) {
				tobs/=60.0;
				strcpy(unit,"(hours)     ");
				if (tobs>24.0) {
					tobs/=24.0;
					strcpy(unit,"(days)      ");
				}
			}
		}
		printf("Observation length %s  : %.1f\n",unit,tobs);
	}
	printf("Number of bits per sample        : %d\n",nbits);
	printf("Number of IFs                    : %d\n",nifs);
	exit(0);
}
Пример #24
0
void cmd_help(char *topic)
{
	if (topic[0] == 0x00 || strings_equal(topic, "help"))
	{
		uart_puts_P("SD Card Tool\r\n");
		uart_puts_P("Version 1\r\n");
		uart_puts_P("Based on UlrichRadig's MMC-SD Library \r\n");
		uart_puts_P("------------------------------------- \r\n");
		uart_puts_P("____________          ________________\r\n");
		uart_puts_P("|       PB1 |--------| CS            |\r\n");
		uart_puts_P("|       PB5 |--------| MOSI = DO     |\r\n");
		uart_puts_P("|       PB6 |--------| MISO = DI     |\r\n");
		uart_puts_P("| AVR   PB7 |--------| SCLK  SD Card |\r\n");
		uart_puts_P("|       GND |--------| GND           |\r\n");
		uart_puts_P("|       +5V |--------| +5V           |\r\n");
		uart_puts_P("|___________|        |_______________|\r\n");
		uart_puts_P("\r\n");
		uart_puts_P("You don't need to connect any other wiring,\r\n");
		uart_puts_P("no need for a second GND or a +3.3V connection.\r\n");
		uart_puts_P("Actually MOSI = DI and MISO = DO, but it seems like\r\n");
		uart_puts_P("this is labelled the wrong way round on the\r\n");
		uart_puts_P("     Jiayuan JY-MCU SD Card Module V1.0\r\n");
		uart_puts_P("\r\n");
		uart_puts_P("\r\n");
		uart_puts_P("Software reference\r\n");
		uart_puts_P("Commands:\r\n");
		uart_puts_P("ls       - List all files in directory\r\n");
		uart_puts_P("cat      - Dump file to UART\r\n");
		uart_puts_P("write    - Write from ADC to a file\r\n");
		uart_puts_P("time     - Display time since system started in ms\r\n");
		uart_puts_P("readtest - Perform a read speed test on the SD Card\r\n");
		uart_puts_P("clear    - Clear the screen\r\n");
		uart_puts_P("init     - Initialize the SD Card. Only call this if it failed on boot.\r\n");
		uart_puts_P("help     - Display this help screen\r\n");
		uart_puts_P("\r\n");
		uart_puts_P("To get more information about a specific command, type\r\n");
		uart_puts_P("help [command]\r\n");		
	}
	else if (strings_equal(topic, "ls"))
	{
		uart_puts_P("ls [cluster]\r\n");
		uart_puts_P("List contents of directory at [cluster], cluster is hexadecimal.\r\n");
		uart_puts_P("Type ls without any parameter to list contents of root directory.\r\n");
	}
	else if (strings_equal(topic, "cat"))
	{
		uart_puts_P("cat [cluster] [filesize]\r\n");
		uart_puts_P("Output contents of file at [cluster] to the serial port.\r\n");
		uart_puts_P("Filesize must be provided, can also be lower than the actual\r\n");
		uart_puts_P("size of the file to not output everything, but mustn't be higher.\r\n");
		uart_puts_P("Cluster and filesize are both hexadecimal.\r\n");
	}
	else if (strings_equal(topic, "clear"))
	{
		uart_puts_P("clear\r\n");
		uart_puts_P("Clears the screen. 0x1b[2J sequence must be supported by your terminal.\r\n");
	}
	else if (strings_equal(topic, "time"))
	{
		uart_puts_P("time\r\n");
		uart_puts_P("Displays time since AVR OS boot in milliseconds.\r\n");
	}
	else if (strings_equal(topic, "write"))
	{
		uart_puts_P("write [cluster] [ADC] [maxsize] [speed]\r\n");
		uart_puts_P("Writes values from the ADC to a file at [cluster].\r\n");
		uart_puts_P("The file must be created before. [ADC] is the ADC port\r\n");
		uart_puts_P("from 1-8. If [maxsize] is provided, writing will stop after\r\n");
		uart_puts_P("the amount of clusters determined by it. [cluster] and [maxsize]\r\n");
		uart_puts_P("are both hexadecimal. [speed] is from fastest = 0 to 255 = slowest.\r\n");
		uart_puts_P("The files have to be created beforehand on a computer. The files\r\n");
		uart_puts_P("created there provide the space for the data. So make sure to create\r\n");
		uart_puts_P("large enough files on the card. If [maxsize] is not provided\r\n");
		uart_puts_P("the AVR will continue writing and may eventually erase all data\r\n");
		uart_puts_P("on the SD Card. Be beware of that and provide [maxsize]\r\n");
	}
	else if (strings_equal(topic, "init"))
	{
		uart_puts_P("init\r\n");
		uart_puts_P("Tries to initialize the SD Card and load the FAT16 filesystem.\r\n");
		uart_puts_P("Only needs to be called if it fails in the first place as it\r\n");
		uart_puts_P("is executed when booting. Will not reset any timers etc.\r\n");
	}
	else if (strings_equal(topic, "readtest"))
	{
		uart_puts_P("readtest [cluster] [filesize]\r\n");
		uart_puts_P("Just like cat. But instead of dumping the contents to the serial\r\n");
		uart_puts_P("port it will display the duration and the speed in kByte/s of the\r\n");
		uart_puts_P("read cycle. The larger the files, the more precise the measurement will be.\r\n");
	}
	else
	{
		uart_puts_P("Help topic not found. Call help for basic information.\r\n");
	}
}
Пример #25
0
main(int argc, char *argv[])
{
  int numerate,i,j,k,l,stream,nsperdmp,nsamps,indexing,indexnow;
  int ifchan[16],frchan[4096],ifnum,chnum,ns,charout,sample;
  float time_of_pulse, width_of_pulse, time, time_start, time_end;
  char message[80],byte;
  unsigned char c;
  unsigned short s;
  float f[8];

  /* zero IF and frequency channel arrays */
  for (i=0;i<16;i++)   ifchan[i]=0;
  for (i=0;i<4096;i++) frchan[i]=0;

  /* default case is to read from standard input */
  input=stdin;
  charout=numerate=stream=0;
  indexing=1;

  /* parse command line if arguments were given */
  if (argc>1) {
    i=1;
    while (i<argc) {
      if (strings_equal(argv[i],"help")) {
	reader_help();
	exit(0);
      } else if (strings_equal(argv[1],"version")) {
	printf("PROGRAM: %s SIGPROC version: %.1f\n",argv[0],SIGPROC_VERSION);
	exit(0);
      } else if (strings_equal(argv[i],"-i")) {
	i++;
	ifchan[atoi(argv[i])-1]=1;
      } else if (strings_equal(argv[i],"-c")) {
	i++;
	frchan[atoi(argv[i])-1]=1;
      } else if (strings_equal(argv[i],"-t")) {
        i++;
	time_of_pulse = atof(argv[i]);
	fprintf(stderr,"centering on time %f s\n",time_of_pulse); 
      } else if (strings_equal(argv[i],"-w")) {
        i++;
        width_of_pulse = atof(argv[i]);
        fprintf(stderr,"with width %f s\n",width_of_pulse); 
      } else if (strings_equal(argv[i],"-numerate")) {
	numerate=1;
      } else if (strings_equal(argv[i],"-noindex")) {
	indexing=0;
      } else if (strings_equal(argv[i],"-stream")) {
	stream=1;
      } else if (strings_equal(argv[i],"-byte")) {
	charout=1;
      } else if (file_exists(argv[i])) {
	input=open_file(argv[i],"rb");
      } else {
	reader_help();
	sprintf(message,"unknown argument (%s) passed to reader",argv[i]);
	error_message(message);
      }
      i++;
    }
  }

  time_start = time_of_pulse - width_of_pulse/2.;
  time_end = time_of_pulse + width_of_pulse/2.;
  sample = 0;
  /* try to read the header */
  if (!read_header(input)) error_message("error reading header\n");

  /* check what IF and frequency channels (if any the user has selected) */
  j=0;
  for (i=0; i<nifs; i++) if (ifchan[i]) j++;
  if (j==0) for (i=0; i<nifs; i++) ifchan[i]=1;
  j=0;
  for (i=0; i<nchans; i++) if (frchan[i]) j++;
  if (j==0) for (i=0; i<nchans; i++) frchan[i]=1;

  /* number of samples to read per dump */
  nsperdmp=nifs*nchans;
  /* initialize loop counters and flags */
  ifnum=chnum=nsamps=l=0;
  indexnow=1;
  if (stream && indexing) numerate=1;

  while (!feof(input)) {

    /* unpack the sample(s) if necessary */
    switch (nbits) {
    case 1:
      fread(&c,1,1,input);
      for (i=0;i<8;i++) {
	f[i]=c&1;
	c>>=1;
      }
      ns=8;
      break;
    case 4:
      fread(&c,1,1,input);
      char2ints(c,&j,&k);
      f[0]=(float) j;
      f[1]=(float) k;
      ns=2;
      break;
    case 8:
      fread(&c,nbits/8,1,input);
      f[0]=(float) c;
      ns=1;
      break;
    case 16:
      fread(&s,nbits/8,1,input);
      f[0]=(float) s;
      ns=1;
      break;
    case 32:
      fread(&f[0],nbits/8,1,input);
      ns=1;
      break;
    default:
      sprintf(message,"cannot read %d bits per sample...\n",nbits);
      error_message(message);
      break;
    }

    for (i=0; i<ns; i++) {
      if (charout) {
	byte=(char) f[i];
	putchar(byte);
      } else {
      /* time stamp or index the data if needed */
	time = (double) tsamp * (double) l;
	if (time > time_end) exit(0);
      if (indexnow && stream) {
	puts("#START");
      } else if (indexnow && indexing && time >= time_start && time <= time_end) {
	/* if (numerate) 
	  printf("%d ",l);
	else
	  printf("# %f\n",time); */
      }
      indexnow=0;
      /* print sample if it is one of the ones selected */
      if (ifchan[ifnum] && frchan[chnum] && time >= time_start && time <= time_end) {
	if (stream && numerate) printf("%d ",nsamps);
	printf("%d %d %f \n",l,chnum,f[i]);
      } 
      nsamps++;
      chnum++;
      if (chnum==nchans) {
	chnum=0;
	ifnum++;
	if (ifnum==nifs) ifnum=0;
      }
      /* put newline and terminator if in streaming mode */
      if (stream) {
	if ((nsamps%nchans)==0) puts("#STOP");
      } 
      /* put newline if this is the last sample of the dump */
      if ((nsamps%nsperdmp)==0) {
	nsamps=0;
	indexnow=1;
	l++;
      }
      }
    }
  }
}
Пример #26
0
main(int argc, char *argv[])
{
  FILE *output;
  int numerate,i,j,k,l,nsperdmp,nsamps,indexing,plot,indexnow;
  int ifchan[16],frchan[4096],ifnum,chnum,ns,sample,ntotal;
  float time_of_pulse, width_of_pulse, time, time_start, time_end;
  float series_amp[100000],series_time[100000],ampmin,ampmax;
  char message[80],outfile[80],filename[80],timestring[80],pgdev[80];
  unsigned char c;
  unsigned short s;
  float f[8];

    if (argc<2) {
    puts("");
    puts("getpulse - make and/or plot a time series from dedispersed file\n"); 
    puts("usage: getpulse {filename} -{options}\n");
    puts("filename is the dedispersed data file\n");
    puts("options:\n");
    puts("-t time - time (in seconds) on which to center time series (REQUIRED)\n");
    puts("-w width - width (in seconds) of time series to plot (def=1)\n");
    puts("-c fchan - to only output frequency channel fchan (def=all)\n");
    puts("-i ifchan - to only output IF channel ifchan (def=all)\n");
    puts("-p pgdev - pgplot device (def=/xs)\n");
    puts("-numerate - to precede each dump with sample number (def=time)\n");
    puts("-noindex - do not precede each dump with time/number\n");
    puts("-plot - PGPLOT the results\n");
    puts("");
    exit(0);
   }

  /* zero IF and frequency channel arrays */
  for (i=0;i<16;i++)   ifchan[i]=0;
  for (i=0;i<4096;i++) frchan[i]=0;

  /* default case is to read from standard input */
  input=stdin;
  numerate=0;
  ampmin = 1.e6;
  ampmax = -1.e6;
  plot=0;
  indexnow=0;
  indexing=1;
  strcpy(pgdev,"/xs");

  /* parse command line if arguments were given */
  if (argc>1) {
    i=1;
    while (i<argc) {
        if (strings_equal(argv[i],"-i")) {
	i++;
	ifchan[atoi(argv[i])-1]=1;
      } else if (strings_equal(argv[i],"-c")) {
	i++;
	frchan[atoi(argv[i])-1]=1;
      } else if (strings_equal(argv[i],"-t")) {
        i++;
	time_of_pulse = atof(argv[i]);
        strcpy(timestring,argv[i]);
	fprintf(stderr,"centering on time %f s\n",time_of_pulse); 
      } else if (strings_equal(argv[i],"-w")) {
        i++;
        width_of_pulse = atof(argv[i]);
        fprintf(stderr,"with width %f s\n",width_of_pulse);
      } else if (strings_equal(argv[i],"-p")) {
        i++;
        strcpy(pgdev,argv[i]); 
      } else if (strings_equal(argv[i],"-numerate")) {
	numerate=1;
      } else if (strings_equal(argv[i],"-noindex")) {
	indexing=0;
      } else if (strings_equal(argv[i],"-plot")) {
	plot=1;
      } else if (file_exists(argv[i])) {
	input=open_file(argv[i],"rb");
        strcpy(filename,argv[i]);
      } else {
	sprintf(message,"unknown argument (%s) passed to getpulse",argv[i]);
	error_message(message);
      }
      i++;
    }
  }

  strcat(filename,".pulse.");
  strcat(filename,timestring);
  strcpy(outfile,filename);
  output=fopen(outfile,"w");
  time_start = time_of_pulse - width_of_pulse/2.;
  time_end = time_of_pulse + width_of_pulse/2.;
  sample = 0;
  /* try to read the header */
  if (!read_header(input)) error_message("error reading header\n");

  /* check what IF and frequency channels (if any the user has selected) */
  j=0;
  for (i=0; i<nifs; i++) if (ifchan[i]) j++;
  if (j==0) for (i=0; i<nifs; i++) ifchan[i]=1;
  j=0;
  for (i=0; i<nchans; i++) if (frchan[i]) j++;
  if (j==0) for (i=0; i<nchans; i++) frchan[i]=1;

  /* number of samples to read per dump */
  nsperdmp=nifs*nchans;
  /* initialize loop counters and flags */
  ifnum=chnum=nsamps=l=0;

  while (!feof(input)) {

    /* unpack the sample(s) if necessary */
    switch (nbits) {
    case 1:
      fread(&c,1,1,input);
      for (i=0;i<8;i++) {
	f[i]=c&1;
	c>>=1;
      }
      ns=8;
      break;
    case 4:
      fread(&c,1,1,input);
      char2ints(c,&j,&k);
      f[0]=(float) j;
      f[1]=(float) k;
      ns=2;
      break;
    case 8:
      fread(&c,nbits/8,1,input);
      f[0]=(float) c;
      ns=1;
      break;
    case 16:
      fread(&s,nbits/8,1,input);
      f[0]=(float) s;
      ns=1;
      break;
    case 32:
      fread(&f[0],nbits/8,1,input);
      ns=1;
      break;
    default:
      sprintf(message,"cannot read %d bits per sample...\n",nbits);
      error_message(message);
      break;
    }

    if (plot) {
       ntotal = (time_end-time_start)/tsamp;
       if (ntotal > 100000) {
	  fprintf(stderr,"Too many samples to plot!\n");
	  plot=0;
	}
    }
    for (i=0; i<ns; i++) {
      /* time stamp or index the data */
      time = (double) tsamp * (double) l;
      if (time > time_end) {
         if (plot) {
	       indexnow=indexnow-1;
	       cpgbeg(0,pgdev,1,1);
               cpgsvp(0.1,0.9,0.1,0.9);
               cpgswin(series_time[0],series_time[indexnow],ampmin-0.1*ampmax,ampmax+0.1*ampmax);
               cpgbox("bcnst",0.0,0,"bcnst",0,0.0);
               cpgline(indexnow,series_time,series_amp);
               cpgscf(2);
	       cpgmtxt("B",2.5,0.5,0.5,"Time (s)");
	       cpgmtxt("L",1.8,0.5,0.5,"Amplitude");
               cpgend();}
	    exit(0);
      }
      /* print sample if it is one of the ones selected */
      if (ifchan[ifnum] && frchan[chnum] && time >= time_start && time <= time_end) {
	if (indexing) {
           if (numerate) fprintf(output,"%d %f\n",l,f[i]);
           else fprintf(output,"%f %f\n",time,f[i]);
        }	
	else {
	   fprintf(output,"%f\n",f[i]);
	}
	if (plot) {
	   series_amp[indexnow]=f[i];
	   series_time[indexnow]=time;
           if (f[i] < ampmin) ampmin = f[i];
           if (f[i] > ampmax) ampmax = f[i];
           indexnow++;
	}
      } 
      nsamps++;
      chnum++;
      if (chnum==nchans) {
	chnum=0;
	ifnum++;
	if (ifnum==nifs) ifnum=0;
      }
      if ((nsamps%nsperdmp)==0) {
	nsamps=0;
	l++;
      }
      }
	}
    fclose(output);

}
Пример #27
0
/* Returns 1 if the contexts are equal, 0 otherwise. */
static int SSL_TEST_CTX_equal(SSL_TEST_CTX *ctx, SSL_TEST_CTX *ctx2)
{
    if (ctx->method != ctx2->method) {
        fprintf(stderr, "Method mismatch: %s vs %s.\n",
                ssl_test_method_name(ctx->method),
                ssl_test_method_name(ctx2->method));
        return 0;
    }
    if (ctx->handshake_mode != ctx2->handshake_mode) {
        fprintf(stderr, "HandshakeMode mismatch: %s vs %s.\n",
                ssl_handshake_mode_name(ctx->handshake_mode),
                ssl_handshake_mode_name(ctx2->handshake_mode));
        return 0;
    }
    if (ctx->app_data_size != ctx2->app_data_size) {
        fprintf(stderr, "ApplicationData mismatch: %d vs %d.\n",
                ctx->app_data_size, ctx2->app_data_size);
        return 0;
    }

    if (ctx->max_fragment_size != ctx2->max_fragment_size) {
        fprintf(stderr, "MaxFragmentSize mismatch: %d vs %d.\n",
                ctx->max_fragment_size, ctx2->max_fragment_size);
        return 0;
    }

    if (!SSL_TEST_EXTRA_CONF_equal(&ctx->extra, &ctx2->extra)) {
        fprintf(stderr, "Extra conf mismatch.\n");
        return 0;
    }
    if (!SSL_TEST_EXTRA_CONF_equal(&ctx->resume_extra, &ctx2->resume_extra)) {
        fprintf(stderr, "Resume extra conf mismatch.\n");
        return 0;
    }

    if (ctx->expected_result != ctx2->expected_result) {
        fprintf(stderr, "ExpectedResult mismatch: %s vs %s.\n",
                ssl_test_result_name(ctx->expected_result),
                ssl_test_result_name(ctx2->expected_result));
        return 0;
    }
    if (ctx->expected_client_alert != ctx2->expected_client_alert) {
        fprintf(stderr, "ClientAlert mismatch: %s vs %s.\n",
                ssl_alert_name(ctx->expected_client_alert),
                ssl_alert_name(ctx2->expected_client_alert));
        return 0;
    }
    if (ctx->expected_server_alert != ctx2->expected_server_alert) {
        fprintf(stderr, "ServerAlert mismatch: %s vs %s.\n",
                ssl_alert_name(ctx->expected_server_alert),
                ssl_alert_name(ctx2->expected_server_alert));
        return 0;
    }
    if (ctx->expected_protocol != ctx2->expected_protocol) {
        fprintf(stderr, "ClientAlert mismatch: %s vs %s.\n",
                ssl_protocol_name(ctx->expected_protocol),
                ssl_protocol_name(ctx2->expected_protocol));
        return 0;
    }
    if (ctx->expected_servername != ctx2->expected_servername) {
        fprintf(stderr, "ExpectedServerName mismatch: %s vs %s.\n",
                ssl_servername_name(ctx->expected_servername),
                ssl_servername_name(ctx2->expected_servername));
        return 0;
    }
    if (ctx->session_ticket_expected != ctx2->session_ticket_expected) {
        fprintf(stderr, "SessionTicketExpected mismatch: %s vs %s.\n",
                ssl_session_ticket_name(ctx->session_ticket_expected),
                ssl_session_ticket_name(ctx2->session_ticket_expected));
        return 0;
    }
    if (!strings_equal("ExpectedNPNProtocol", ctx->expected_npn_protocol,
                       ctx2->expected_npn_protocol))
        return 0;
    if (!strings_equal("ExpectedALPNProtocol", ctx->expected_alpn_protocol,
                       ctx2->expected_alpn_protocol))
        return 0;
    if (ctx->resumption_expected != ctx2->resumption_expected) {
        fprintf(stderr, "ResumptionExpected mismatch: %d vs %d.\n",
                ctx->resumption_expected, ctx2->resumption_expected);
        return 0;
    }
    return 1;
}
Пример #28
0
main(int argc, char **argv) 
{
  char message[80];
  int i;
  float fmhz=430.0, bw=7.68, nch=128.0, dm=50.0, pms=150.0,
        wms=5.0, tms=0.08, tsc=0.0, mdm=0.0, nrm=100.0;
  float xdm, wef, snr, tdm, tdd, snrmax=0.0;
  FILE *input;
  if (argc > 1) {
    print_version(argv[0],argv[1]);
    if (help_required(argv[1])) {
      /*snrdm_help();*/
      exit(0);
    }
    i=1;
    while (i<argc) {
      if (file_exists(argv[i])) {
	input=open_file(argv[i],"r");
      } else if (strings_equal(argv[i],"-f")) {
        fmhz=atof(argv[++i]);
      } else if (strings_equal(argv[i],"-b")) {
        bw=atof(argv[++i]);
      } else if (strings_equal(argv[i],"-c")) {
        nch=atof(argv[++i]);
      } else if (strings_equal(argv[i],"-d")) {
        dm=atof(argv[++i]);
      } else if (strings_equal(argv[i],"-p")) {
        pms=atof(argv[++i]);
      } else if (strings_equal(argv[i],"-w")) {
        wms=atof(argv[++i]);
      } else if (strings_equal(argv[i],"-t")) {
        tms=atof(argv[++i]);
      } else if (strings_equal(argv[i],"-s")) {
        tsc=atof(argv[++i]);
      } else if (strings_equal(argv[i],"-m")) {
        mdm=atof(argv[++i]);
      } else if (strings_equal(argv[i],"-n")) {
        nrm=atof(argv[++i]);
      } else {
	sprintf(message,"command-line argument %s not recognized...",argv[i]);
	error_message(message);
      }
      i++;
    }
  }
  if (mdm == 0.0) mdm=2.0*dm;
  tdm=(float) dmdelay(fmhz-bw/nch,fmhz,dm)*1000.0;
  for (xdm=0.0;xdm<mdm;xdm+=0.1) {
    tdd=(float) dmdelay(fmhz-bw/2.0,fmhz+bw/2.0,abs(dm-xdm))*1000.0;
    wef=sqrt(wms*wms+tsc*tsc+tms*tms+tdm*tdm+tdd*tdd);
    snr=sqrt((pms-wef)/wef);
    snrmax=(snr>snrmax)?snr:snrmax;
  }
  printf("#Signal-to-noise/DM curve assuming following parameters:\n");
  fprintf(stderr,"#Pulse Period %.3f ms\n",pms);
  fprintf(stderr,"#Intrinsic Width %.3f ms\n",wms);
  fprintf(stderr,"#Scattering Time %.3f ms\n",tsc);
  fprintf(stderr,"#True DM %.3f pc/cc\n",dm);
  fprintf(stderr,"#Centre Frequency %.3f MHz\n",fmhz);
  fprintf(stderr,"#Bandwidth %.3f MHz\n",bw);
  fprintf(stderr,"#Number of Channels %d\n",nch);
  printf("#START\n");
  for (xdm=0.0;xdm<mdm;xdm+=0.1) {
    tdd=(float) dmdelay(fmhz-bw/2.0,fmhz+bw/2.0,abs(dm-xdm))*1000.0;
    wef=sqrt(wms*wms+tsc*tsc+tms*tms+tdm*tdm+tdd*tdd);
    if (wef>pms) 
      snr=0.0;
    else
      snr=nrm*sqrt((pms-wef)/wef)/snrmax;
    printf("%.2f %f\n",xdm,snr);
  }
  printf("#STOP\n");
  printf("#DONE\n");
}
Пример #29
0
char readmovies()
{
	int mnum;
	for (mnum = 0; mnum < MAX_MOVIES; mnum++)
		movies[mnum].valid = FALSE;

	FILE *stream;
	stream = fopen(CONFIG_FILE, "rb");

	if (!stream) return FALSE;

	char line[MAX_LINE_LEN];
	char basedir[MAX_LINE_LEN];
	char basedir_string[MAX_LINE_LEN];


	// Parse config file
	mnum = 0;
	while(getl(stream, line))
	{
		if (strings_equal(line, "__BASEDIR"))
		{
			assert(getl(stream, basedir_string));
			if (!strstr(basedir, "__CWD__"))
			{
				strcpy(basedir, getcwd(NULL, 0));
				strcat(basedir, basedir_string+7);
			}
			else
			{
				strcpy(basedir, basedir_string);
			}
		}

		if (strings_equal(line, "__MOVIE"))
		{
			assert(getl(stream, movies[mnum].name));
			assert(getl(stream, movies[mnum].filename));

			movies[mnum].valid = TRUE;
			++mnum;
		}
	}

	// Establish Paths to Files
	mnum = 0;
	while(movies[mnum].valid)
	{
		strcpy(movies[mnum].path, basedir);
		strcat(movies[mnum].path, movies[mnum].filename);
		++mnum;
	}

	// Dump Paths
	mnum = 0;
	while(movies[mnum].valid) fprintf(stderr, "Adding File: %s\n", movies[mnum++].path);

	fclose(stream);

	return TRUE;
}
Пример #30
0
/* attempt to read in the general header info from a pulsar data file */
int read_header(FILE *inputfile) /* includefile */
{
  char string[80], message[80];
  int itmp,nbytes,totalbytes,expecting_rawdatafile=0,expecting_source_name=0; 
  int expecting_frequency_table=0,channel_index;


  /* try to read in the first line of the header */
  get_string(inputfile,&nbytes,string);
  if (!strings_equal(string,"HEADER_START")) {
	/* the data file is not in standard format, rewind and return */
	rewind(inputfile);
	return 0;
  }
  /* store total number of bytes read so far */
  totalbytes=nbytes;

  /* loop over and read remaining header lines until HEADER_END reached */
  while (1) {
    get_string(inputfile,&nbytes,string);
    if (strings_equal(string,"HEADER_END")) break;
    totalbytes+=nbytes;
    if (strings_equal(string,"rawdatafile")) {
      expecting_rawdatafile=1;
    } else if (strings_equal(string,"source_name")) {
      expecting_source_name=1;
    } else if (strings_equal(string,"FREQUENCY_START")) {
      expecting_frequency_table=1;
      channel_index=0;
    } else if (strings_equal(string,"FREQUENCY_END")) {
      expecting_frequency_table=0;
    } else if (strings_equal(string,"az_start")) {
      fread(&az_start,sizeof(az_start),1,inputfile);
      totalbytes+=sizeof(az_start);
    } else if (strings_equal(string,"za_start")) {
      fread(&za_start,sizeof(za_start),1,inputfile);
      totalbytes+=sizeof(za_start);
    } else if (strings_equal(string,"src_raj")) {
      fread(&src_raj,sizeof(src_raj),1,inputfile);
      totalbytes+=sizeof(src_raj);
    } else if (strings_equal(string,"src_dej")) {
      fread(&src_dej,sizeof(src_dej),1,inputfile);
      totalbytes+=sizeof(src_dej);
    } else if (strings_equal(string,"tstart")) {
      fread(&tstart,sizeof(tstart),1,inputfile);
      totalbytes+=sizeof(tstart);
    } else if (strings_equal(string,"tsamp")) {
      fread(&tsamp,sizeof(tsamp),1,inputfile);
      totalbytes+=sizeof(tsamp);
    } else if (strings_equal(string,"period")) {
      fread(&period,sizeof(period),1,inputfile);
      totalbytes+=sizeof(period);
    } else if (strings_equal(string,"fch1")) {
      fread(&fch1,sizeof(fch1),1,inputfile);
      totalbytes+=sizeof(fch1);
    } else if (strings_equal(string,"fchannel")) {
      fread(&frequency_table[channel_index++],sizeof(double),1,inputfile);
      totalbytes+=sizeof(double);
      fch1=foff=0.0; /* set to 0.0 to signify that a table is in use */
    } else if (strings_equal(string,"foff")) {
      fread(&foff,sizeof(foff),1,inputfile);
      totalbytes+=sizeof(foff);
    } else if (strings_equal(string,"nchans")) {
      fread(&nchans,sizeof(nchans),1,inputfile);
      totalbytes+=sizeof(nchans);
    } else if (strings_equal(string,"telescope_id")) {
      fread(&telescope_id,sizeof(telescope_id),1,inputfile);
      totalbytes+=sizeof(telescope_id);
    } else if (strings_equal(string,"machine_id")) {
      fread(&machine_id,sizeof(machine_id),1,inputfile);
      totalbytes+=sizeof(machine_id);
    } else if (strings_equal(string,"data_type")) {
      fread(&data_type,sizeof(data_type),1,inputfile);
      totalbytes+=sizeof(data_type);
    } else if (strings_equal(string,"nbits")) {
      fread(&nbits,sizeof(nbits),1,inputfile);
      totalbytes+=sizeof(nbits);
    } else if (strings_equal(string,"barycentric")) {
      fread(&barycentric,sizeof(barycentric),1,inputfile);
      totalbytes+=sizeof(barycentric);
    } else if (strings_equal(string,"pulsarcentric")) {
      fread(&pulsarcentric,sizeof(pulsarcentric),1,inputfile);
      totalbytes+=sizeof(pulsarcentric);
    } else if (strings_equal(string,"nbins")) {
      fread(&nbins,sizeof(nbins),1,inputfile);
      totalbytes+=sizeof(nbins);
    } else if (strings_equal(string,"nsamples")) {
      /* read this one only for backwards compatibility */
      fread(&itmp,sizeof(itmp),1,inputfile);
      totalbytes+=sizeof(itmp);
    } else if (strings_equal(string,"nifs")) {
      fread(&nifs,sizeof(nifs),1,inputfile);
      totalbytes+=sizeof(nifs);
    } else if (strings_equal(string,"npuls")) {
      fread(&npuls,sizeof(npuls),1,inputfile);
      totalbytes+=sizeof(npuls);
    } else if (strings_equal(string,"refdm")) {
      fread(&refdm,sizeof(refdm),1,inputfile);
      totalbytes+=sizeof(refdm);
    } else if (expecting_rawdatafile) {
      strcpy(rawdatafile,string);
      expecting_rawdatafile=0;
    } else if (expecting_source_name) {
      strcpy(source_name,string);
      expecting_source_name=0;
    } else {
      sprintf(message,"read_header - unknown parameter: %s\n",string);
      fprintf(stderr,"ERROR: %s\n",message);
      exit(1);
    } 
  } 

  /* add on last header string */
  totalbytes+=nbytes;

  /* return total number of bytes read */
  return totalbytes;
}