int LatexTables::getNumberOfColumns(QDocumentCursor &cur){
	QDocumentCursor c(cur);
	int result=findNextToken(c,QStringList(),false,true);
	if(result!=-2) return -1;
	QString line=c.line().text();
	int pos=line.indexOf("\\begin");
	if(pos>-1){
		QStringList values;
		LatexParser::resolveCommandOptions(line,pos,values);
		return getNumberOfColumns(values);
	}
	return -1;
}
Beispiel #2
0
void FileManager :: printHeader(){
    cout << "---------------------Header------------------------------------"<< endl;
      cout << "nombre de tabla : "<< getNameOfFile() << endl;
      cout << "tamaño archivo : "<< getSizeOfFile() << endl;
      cout << "num reg : "<< getNumberOfRegisters() << endl;
      cout << "num libres : "<< getNumberOfFreeRegisters() << endl;
      cout << "primer reg : "<< getPtrOfFirstRegister() << endl;
      cout << "primer libre : "<< getPtrToFirstRegisterFree() << endl;
      cout << "ultimo reg : "<< getPtrToLastRegister() << endl;
      cout << "tamañoRegistro : "<< getSizeOfRegister() << endl;
      cout << "num de columnas : "<< getNumberOfColumns() << endl;
       cout << "---------------------end-of-Header------------------------------------"<< endl;
}
Beispiel #3
0
/*-------------------------------------------------------------------------------------*/
static int *lengthEachString(int rhspos, int *sizeArrayReturned)
{
    int *StringsLength = NULL;

    if (VarType(rhspos) == sci_strings)
    {
        int m = 0, n = 0;       /* matrix size */
        int mn = 0;             /* m*n */

        int il = 0;
        int ilrd = 0;
        int l1 = 0;

        int x = 0;

        int lw = rhspos + Top - Rhs;

        l1 = *Lstk(lw);
        il = iadr(l1);

        if (*istk(il) < 0)
        {
            il = iadr(*istk(il + 1));
        }

        /* get dimensions */
        m = getNumberOfLines(il);   /* row */
        n = getNumberOfColumns(il); /* col */
        mn = m * n;
        ilrd = il + 4;

        StringsLength = (int *)MALLOC(sizeof(int) * mn);
        if (StringsLength == NULL)
        {
            return NULL;
        }

        *sizeArrayReturned = mn;

        for (x = 0; x < mn; x++)
        {
            StringsLength[x] = (int)(*istk(ilrd + x + 1) - *istk(ilrd + x));
        }
    }
    return StringsLength;
}
RcppModelData::RcppModelData(
        ModelType _modelType,
		const IntegerVector& _pid,
		const NumericVector& _y,
		const NumericVector& _z,
		const NumericVector& _time,
		const NumericVector& dxv, // dense
		const IntegerVector& siv, // sparse
		const IntegerVector& spv,
		const NumericVector& sxv,
		const IntegerVector& iiv, // indicator
		const IntegerVector& ipv,
		bool useTimeAsOffset
		) : ModelData(
                _modelType,
				_pid,
				_y,
				_z,
				_time,
				bsccs::make_shared<loggers::RcppProgressLogger>(),
				bsccs::make_shared<loggers::RcppErrorHandler>()
				) {
	if (useTimeAsOffset) {
	    // offset
//        real_vector* r = new real_vector();
        RealVectorPtr r = make_shared<RealVector>();
        push_back(NULL, r, DENSE);   
        r->assign(offs.begin(), offs.end()); // TODO Should not be necessary with shared_ptr
        setHasOffsetCovariate(true);
	    getColumn(0).add_label(-1);
	}			
				
	// Convert dense
	int nCovariates = static_cast<int>(dxv.size() / y.size());
	for (int i = 0; i < nCovariates; ++i) {
		push_back(
				static_cast<IntegerVector::iterator>(NULL), static_cast<IntegerVector::iterator>(NULL),
				dxv.begin() + i * y.size(), dxv.begin() + (i + 1) * y.size(),
				DENSE);
		getColumn(getNumberOfColumns() - 1).add_label(getNumberOfColumns() - (getHasOffsetCovariate() ? 1 : 0));
	}

	// Convert sparse
	nCovariates = spv.size() - 1;
	for (int i = 0; i < nCovariates; ++i) {

		int begin = spv[i];
		int end = spv[i + 1];

		push_back(
				siv.begin() + begin, siv.begin() + end,
				sxv.begin() + begin, sxv.begin() + end,
				SPARSE);
        getColumn(getNumberOfColumns() - 1).add_label(getNumberOfColumns() - (getHasOffsetCovariate() ? 1 : 0));				
	}

	// Convert indicator
	nCovariates = ipv.size() - 1;
	for (int i = 0; i < nCovariates; ++i) {

		int begin = ipv[i];
		int end = ipv[i + 1];

		push_back(
				iiv.begin() + begin, iiv.begin() + end,
				static_cast<NumericVector::iterator>(NULL), static_cast<NumericVector::iterator>(NULL),
				INDICATOR);
        getColumn(getNumberOfColumns() - 1).add_label(getNumberOfColumns() - (getHasOffsetCovariate() ? 1 : 0));				
	}

	this->nRows = y.size();
	
	// Clean out PIDs
	std::vector<int>& cpid = getPidVectorRef();
	
	if (cpid.size() == 0) {
	    for (size_t i = 0; i < nRows; ++i) {
	        cpid.push_back(i); // TODO These are not necessary; remove.
	    }
	    nPatients = nRows;
	} else {
    	int currentCase = 0;
    	int currentPID = cpid[0];
    	cpid[0] = currentCase;
    	for (size_t i = 1; i < pid.size(); ++i) {
    	    int nextPID = cpid[i];
    	    if (nextPID != currentPID) {
	            currentCase++;
	            currentPID = nextPID;
    	    }
	        cpid[i] = currentCase;
    	}
        nPatients = currentCase + 1;
    }    
}
Beispiel #5
0
extern "C" void * haloThread(void * id){
	char * HaloID = (char *)id;
	cout << "Analyzing halo with ID " << HaloID << endl;
	int numberOfParticles, nCols;
	double ** positionsArray;
	Particle ** particlesArray;
	FILE * output;
	double radius = 0;
	double u;

	FILE * positionFile = getPositionFile(HaloID);		//make the file path
	if (positionFile == NULL)
		printf("POSITION FILE NULL\n");
	numberOfParticles = getNumberOfRows(positionFile);	//count number of particles in file
	nCols = getNumberOfColumns(positionFile);			//get number of columns in file (3)
	particlesArray = new ParticleArray[numberOfParticles];	//make an array of particles
	for (int i = 0; i < numberOfParticles; i++){
		particlesArray[i] = new Particle();					//each location in the array is a particle (with positions)
	}
	positionsArray = assembleArray(positionFile,numberOfParticles,nCols);
	for (int i = 0; i<numberOfParticles;i++){
		particlesArray[i]->position.x = positionsArray[i][0];
		particlesArray[i]->position.y = positionsArray[i][1];
		particlesArray[i]->position.z = positionsArray[i][2];
		free(positionsArray[i]);
	}
	delete positionsArray;
       
	for(int i = 0; i < numberOfParticles; i++){

		for(int j = 0; j < numberOfParticles; j++){
				radius = sqrt(sq((particlesArray[i]->position.x)-(particlesArray[j]->position.x))+sq((particlesArray[i]->position.y)-(particlesArray[j]->position.y))+sq((particlesArray[i]->position.z)-(particlesArray[j]->position.z)));
				u = radius/EPSILON;
				if(u<0.5){
					particlesArray[i]->directPotential += GRAVITATIONAL_CONSTANT*PARTICLE_MASS*MASS_MULTIPLIER/EPSILON*(16.0/3.0*sq(u)-48.0/5.0*fourth(u)+32.0/5.0*fifth(u)-14.0/5.0);
				}
				else if(u<1){
					particlesArray[i]->directPotential += GRAVITATIONAL_CONSTANT*PARTICLE_MASS*MASS_MULTIPLIER/EPSILON*(1.0/(15.0*u)+32.0/3.0*sq(u)-16.0*third(u)+48.0/5.0*fourth(u)-32.0/15.0*fifth(u)-16.0/5.0);
				}
				else{
					particlesArray[i]->directPotential += GRAVITATIONAL_CONSTANT*PARTICLE_MASS*MASS_MULTIPLIER/EPSILON*(-1.0/u);
				}

		}
		if(i%100000==0){cout <<HaloID <<" - " <<i <<"th particle's potential calculated" <<endl;}
	}

	output = makeOutputFileName(HaloID);		//make output file

	//print output
	for(int i = 0; i<numberOfParticles; i++){
		fprintf(output,"%f%c\n",particlesArray[i]->directPotential,delimeter);
	}

	//free memory
	for (int i = 0; i < numberOfParticles; i++){
		delete particlesArray[i]; 
	}
	delete particlesArray;

	//close files
	fclose(positionFile);
	fclose(output);

		// Reduce our active threads count.
	pthread_mutex_lock(numberOfThreadsMutex);
	numberOfThreads--;
	pthread_mutex_unlock(numberOfThreadsMutex);
	pthread_cond_signal(threadAvailable);			// Signal to wake up main.

	cout <<"Halo " << HaloID <<" done." <<endl;

}
int main()
{

    FILE *myFile1;
    FILE *myFile2;
    FILE *myFile3;
    char *filename="c.txt";
    myFile1 = fopen(filename, "r");
    if (myFile1 == NULL)
    {
        printf("Error Reading File\n");
        exit (0);
    }
    printf("all is well \n");

    /*get number of lines in the file*/
    int r=getNumberOfLines(myFile1);
    fclose(myFile1);

    myFile2 = fopen(filename, "r");
    if (myFile2 == NULL)
    {
        printf("Error Reading File\n");
        exit (0);
    }
    int c=getNumberOfColumns(myFile2);
    fclose(myFile2);
    printf("r=%d and c=%d\n",r,c);
    char *line=NULL;
    char *word=NULL;
    int attr;
    int i,j;
    size_t len = 0;
    ssize_t read;
    printf("r=%d and c=%d\n",r,c);

    myFile3 = fopen(filename, "r");
    if (myFile3 == NULL)
    {
        printf("Error Reading File\n");
        exit (0);
    }
    float *dataset[r];
    for (i=0; i<r; i++)
         dataset[i] = (float *)malloc(c * sizeof(float));
    i=0;
    while ((read = getline(&line, &len, myFile3)) != -1) {
        
        j=0;

        do{
            word=strsep(&line,",");
            attr = atoi(word);
            dataset[i][j]=(float)attr;
            j++;
        }while(line!=NULL && word!=NULL);
        i++;           
        
    }
    fclose(myFile3);

    printMatrix(dataset, r,c);

    freeData(dataset, r,c);

    return 0;
}
template<typename X> rawData<X>* C_readDicomDiffData::getUnmosaicData_(unsigned short nb_slice_per_mosa)
{
    //returned pointer
    rawData<X>* rawDataX = NULL;

    if(mImage.GetNumberOfDimensions()!=2) return NULL;

    //get number of byte in image buffer
    unsigned long buffLen = mImage.GetBufferLength();

    //allocate a temporary buffer of buffLen bytes
    char* buff = new char[buffLen];
    if(buff==NULL) return NULL;

    //get image buffer into temporary buffer
    if(mImage.GetBuffer(buff))
    {
        ///get subimage dimension
        unsigned long subDimX, subDimY, squareDim;
        if(sqrt(nb_slice_per_mosa)==floor(sqrt(nb_slice_per_mosa)))
        {
            squareDim = (unsigned short) floor(sqrt(nb_slice_per_mosa));
        }
        else
        {
            squareDim = (unsigned short) floor(sqrt(nb_slice_per_mosa)) + 1;
        }
        //cout << "before getNumberOfColumns" << endl;
        subDimX = getNumberOfColumns()/squareDim;
        //cout << "after getNumberOfColumns" << endl;
        subDimY = getNumberOfRows()/squareDim;
        //cout << "after getNumberOfRows" << endl;

        ///allocate storage
        rawDataX = new rawData<X>(getPixelRepresentation(), 2+1, subDimY, subDimX, nb_slice_per_mosa);
        if(rawDataX==NULL)
        {
            delete buff;
            return NULL;
        }
        if(rawDataX->raw1D==NULL && rawDataX->raw2D==NULL && rawDataX->raw3D==NULL && rawDataX->raw4D==NULL)
        {
            delete buff;
            delete rawDataX;
            return NULL;
        }

        //reorganize buffer into rawData structure
        X* bufferX = (X*) buff;
        for(unsigned long i=0 ; i<rawDataX->DimX ; i++)
        {
            for(unsigned long j=0 ; j<rawDataX->DimY ; j++)
            {
                for(unsigned long k=0 ; k<rawDataX->DimZ ; k++)
                {
                    ///store data
                    rawDataX->raw3D[i][j][k] = bufferX[rawDataX->getIndex3DUnmosaic(i,j,k)];
                }
            }
        }



    }

    //cout << "before getPixelDimX" << endl;
    rawDataX->pixDimX = getPixelDimX();
    //cout << "after getPixelDimX" << endl;
    rawDataX->pixDimY = getPixelDimY();
    rawDataX->pixDimZ = getPixelDimZ(); ///may not be right
    rawDataX->pixDimT = 1.0;
    delete buff;
    return rawDataX;
}