Esempio n. 1
0
bool RINEX::get4DParams(ifstream *fin,
	double *darg1,double *darg2,double *darg3,double *darg4,
	unsigned int *lineCount)
{
	string line;
	(*lineCount)++;
	if (fin->good()) 
		getline(*fin,line);
	else{
		return false;
	}
	
	if (line.length() < 79){
		return false;
	}
	
	std::replace( line.begin(), line.end(), 'D', 'E'); // filthy FORTRAN
	
	// Format is 3X,4D19.12
	parseParam(line,4,19,darg1);
	parseParam(line,23,19,darg2);
	parseParam(line,42,19,darg3);
	parseParam(line,61,19,darg4);
	
	return true;
	
}
Esempio n. 2
0
void EdLevelPropertyMatrix3Field::doWriteParams(void)
{
    Matrix3 val;
    val._m11 = MoreStrings::cast_from_string<DTfloat>(parseParam(_value_11->text().toUtf8().data()));
    val._m12 = MoreStrings::cast_from_string<DTfloat>(parseParam(_value_12->text().toUtf8().data()));
    val._m13 = MoreStrings::cast_from_string<DTfloat>(parseParam(_value_13->text().toUtf8().data()));

    val._m21 = MoreStrings::cast_from_string<DTfloat>(parseParam(_value_21->text().toUtf8().data()));
    val._m22 = MoreStrings::cast_from_string<DTfloat>(parseParam(_value_22->text().toUtf8().data()));
    val._m23 = MoreStrings::cast_from_string<DTfloat>(parseParam(_value_23->text().toUtf8().data()));
    
    val._m31 = MoreStrings::cast_from_string<DTfloat>(parseParam(_value_31->text().toUtf8().data()));
    val._m32 = MoreStrings::cast_from_string<DTfloat>(parseParam(_value_32->text().toUtf8().data()));
    val._m33 = MoreStrings::cast_from_string<DTfloat>(parseParam(_value_33->text().toUtf8().data()));

	TextBufferStream stream;
    stream << val;

    TextBufferStream oldstream;
	_data->value(oldstream);
    
    // Only if value changed
    if (stream.buffer() != oldstream.buffer()) {
        emit doCommand(QString("SetProp \"") + _node->full_name().c_str() + "." + _data->title().c_str() + "\" (" + stream.buffer().c_str() + ")", _data->flags() & DATA_FLUSH_UI);
    }
}
Esempio n. 3
0
FResult ImageReader::openImage(std::string filePath) {
	// Try to read file
	int error = fopen_s(&m_fp ,filePath.c_str(), "rb");

	// If there have any error
	if (m_fp == NULL) {
		printf("<ERRROR> Cannot open file \"%s\"\n", filePath.c_str());
		m_isFileOpened = false;
		return FResult::FILE_OPEN_FAIL;
	}

	m_isFileOpened = true;

	if (parseParam() != FResult::FILE_READ_SUCCESS)
		return FResult::FILE_PARSE_FAIL;
	else {
		m_isFileParsed = true;
		
		m_imgInfoHeader.bits_per_pixel;
		// Alloc image data buffer with corrbound width and height
		m_p_imageData = 
			new TImage<uint8_t>(m_imgInfoHeader.width, m_imgInfoHeader.height, m_imgInfoHeader.bits_per_pixel / 8);

		return FResult::FILE_OPEN_SUCCESS;
	}
}
Esempio n. 4
0
list<Param*> Parser::parseParams()
{
	Param* param = parseParam();
	list<Param*> paramRest = parseParamRest();
	paramRest.push_front( param );
	return paramRest;
}
Esempio n. 5
0
static inline BOOL parseParamLine(const char *line)
{
	int i=0;
	while(line[i] != '=') i++;
	if(!parseParam(substr(line, 0, i), substr(line, i+1, strlen(line) - i + 1))) return FALSE;		
	return TRUE;	
}
void parseMeta(MFILE *mfout, const char *toparse)
{
	char *tagend=strchr(toparse, ' ');
	int taglen=tagend-toparse;
	
	fprintf(stderr, "Parsing: %s\n", toparse);

	if(!strcmp(toparse, "/*")){
		commdepth++;
		return;
	}
	
	if(!strcmp(toparse, "*/")){
		commdepth--;
		if(commdepth<0)
			pexit("comment to deep - to many '*/' found - exiting\n", "");
		return;
	}

	if(commdepth>0) return;

	if(taglen<0)
		pexit("tag wrong - ' ' expected - exiting\n", toparse);
	
	if(!strncasecmp(toparse, "section", strlen("section")))
		return parseSection(mfout, tagend+1);
	if(!strncasecmp(toparse, "param", strlen("param")))
		return (void)parseParam(mfout, secakt->list, tagend+1, false);
	if(!strncasecmp(toparse, "slink", strlen("slink")))
		return parseSLink(mfout, tagend+1);	
}
Esempio n. 7
0
void EdLevelPropertyVector2Field::doWriteParams(void)
{
    Vector2 val;
    val.x = MoreStrings::cast_from_string<DTfloat>(parseParam(_value_x->text().toUtf8().data()));
    val.y = MoreStrings::cast_from_string<DTfloat>(parseParam(_value_y->text().toUtf8().data()));

    TextBufferStream stream;
    stream << val;

    TextBufferStream oldstream;
    _data->value(oldstream);

    // Only if value changed
    if (stream.buffer() != oldstream.buffer()) {
        emit doCommand(QString("SetProp \"") + _node->full_name().c_str() + "." + _data->title().c_str() + "\" (" + stream.buffer().c_str() + ")", _data->flags() & DATA_FLUSH_UI);
    }
}
Esempio n. 8
0
void EdLevelPropertyTitleField::doWriteParams(void)
{
	TextBufferStream stream(parseParam(_value->text().toUtf8().data()));

    TextBufferStream oldstream;
	_data->value(oldstream);
    
    // Only if value changed
    if (stream.buffer() != oldstream.buffer()) {
        emit doCommand(QString("SetName \"") + _node->full_name().c_str() + "\" \"" + stream.buffer().c_str() + "\"", _data->flags() & DATA_FLUSH_UI);
    }
}
Esempio n. 9
0
void RenJS::parseMove(const CString& strMove)
{
	Node node(this);

	int left  = 0;
	int right = strMove.Find(";");

	while (left < right)
	{
		CString strParam(strMove.Mid(left, right - left));

		parseParam(strParam, node);
		
		left  = right + 1;
		right = strMove.Find(";", left);
	}

	mMoves.push_back(node);
}
void parseSLink(MFILE *mfout, const char *params)
{
	Content *c;
	char *p=(char*)params, *comment, *cend;
	if(secakt==NULL) pexit("SLink: tried to insert, but no section found\n", params);
	
	if(*params!='\'') comment=(char*)strdup("");
	else{
		comment=(char*)(params+1);
		cend=strchr(comment, '\'');
		if(cend==NULL) pexit("SLink: comment not ended with ' - exiting\n", params);
		*cend=0; cend++;
		while(*cend==' ') cend++;
		p=cend;
	}
			
	c=listInsertContent(secakt->list, "", "***SCRIPT LINK***", comment);
	listInsertContent(c->sub, "s", "script", "Script Name");

	mfprintf(mfout, "%%s?");
	while((p=parseParam(mfout, c->sub, p, true))!=NULL)
		mfputc('&', mfout);
}
Esempio n. 11
0
	//----------------------------------------------------------------------------//
	void D3D9Shader::buildConstantDefs()
	{
		if(!mpConstTable)
		{
			TITAN_EXCEPT_API("Shader not loaded correctly");
			return ;
		}

		D3DXCONSTANTTABLE_DESC desc;
		HRESULT hr = mpConstTable->GetDesc(&desc);

		if(FAILED(hr))
		{
			TITAN_EXCEPT_API("we can not get constants descriptions from shader");
			return ;
		}

		createParamMappingBuffer(true);
		//parse every constant
		for (uint i = 0; i < desc.Constants; ++i)
		{
			parseParam(NULL, "", i);
		}
	}
Esempio n. 12
0
bool RINEX::readNavigationFile(Receiver *rx,int constellation,string fname){
	
	unsigned int lineCount=0;
	
	ifstream fin(fname.c_str());
	string line;
				 
	if (!fin.good()){
		app->logMessage("Unable to open the navigation file " + fname);
		return false;
	}

	// First, determine the version
	double RINEXver;
	
	while (!fin.eof()){
		getline(fin,line);
		lineCount++;
		if (string::npos != line.find("RINEX VERSION")){
			parseParam(line,1,12,&RINEXver);
			break;
		}
	}

	if (fin.eof()){
		app->logMessage("Unable to determine RINEX version in " + fname);
		return false;
	}
	
	DBGMSG(debugStream,TRACE,"RINEX version is" << RINEXver);
	
	while (!fin.eof()){
		getline(fin,line);
		lineCount++;
		if (RINEXver <3){
			if (constellation == GNSSSystem::GPS){
				if (string::npos != line.find("ION ALPHA")){
					std::replace( line.begin(), line.end(), 'D', 'E');
					parseParam(line,3,14, &(rx->gps.ionoData.a0));
					parseParam(line,15,26,&(rx->gps.ionoData.a1));
					parseParam(line,27,38,&(rx->gps.ionoData.a2));
					parseParam(line,39,50,&(rx->gps.ionoData.a3));
					DBGMSG(debugStream,TRACE,"read ION ALPHA " << rx->gps.ionoData.a0 << " " << rx->gps.ionoData.a1 << " " << rx->gps.ionoData.a2 << " " << rx->gps.ionoData.a3);
					
				}
				else if (string::npos != line.find("ION BETA")){
					std::replace( line.begin(), line.end(), 'D', 'E');
					parseParam(line,3,14, &(rx->gps.ionoData.B0));
					parseParam(line,15,26,&(rx->gps.ionoData.B1));
					parseParam(line,27,38,&(rx->gps.ionoData.B2));
					parseParam(line,39,50,&(rx->gps.ionoData.B3));
					DBGMSG(debugStream,TRACE,"read ION BETA " << rx->gps.ionoData.B0 << " " << rx->gps.ionoData.B1 << " " << rx->gps.ionoData.B2 << " " << rx->gps.ionoData.B3);
				}
				else if (string::npos != line.find("DELTA-UTC:")){
					std::replace( line.begin(), line.end(), 'D', 'E');
					parseParam(line,4,22,&(rx->gps.UTCdata.A0));
					parseParam(line,23,41,&(rx->gps.UTCdata.A1));
					parseParam(line,42,50,&(rx->gps.UTCdata.t_ot));
				}
				else if  (string::npos != line.find("LEAP SECONDS")){
					parseParam(line,1,6,&(rx->leapsecs));
					DBGMSG(debugStream,TRACE,"read LEAP SECONDS=" << rx->leapsecs);
				}
				else if (string::npos != line.find("END OF HEADER")) 
					break;
			} // if constellation == GNSSSystem::GPS
			else if (constellation == GNSSSystem::GLONASS){
				// FIXME coming soon
			}
		} // if (RINEXver == 2)
	}
	
	if (fin.eof()){
		app->logMessage("Format error (no END OF HEADER) in " + fname);
		return false;
	}
	
	while (!fin.eof()){
		
		switch (constellation){
			case GNSSSystem::GPS:
			{
				GPS::EphemerisData *ed = getGPSEphemeris(&fin,&lineCount);
				if (NULL != ed) rx->gps.addEphemeris(ed);
				break;
			}
			case GNSSSystem::GLONASS:
			{
				// FIXME coming soon
				break;
			}
			default:
				break;
		}
		
	}
	
	fin.close();
	
	//if (ephemeris.size() == 0){
	//	app->logMessage("Empty navigation file " + fname);
	//	return false;
	//}
	DBGMSG(debugStream,INFO,"Read " << rx->gps.ephemeris.size() << " GPS entries");
	return true;
}
void *predictModelWholeGenome(void *arg) {
  thread_data_t *data = (thread_data_t *) arg;

  printf("data->trainedModel is %s\n", data->trainedModel);
  printf("data->coverageFileList is %s\n", data->coverageFileList);
  printf("data->trainFile %s\n", data->trainFile);
  printf("data->paramFile %s\n", data->paramFile);
  printf("data->chr is %d\n", data->chr);

  char *trainedModel = data->trainedModel;
  char *coverageFileList = data->coverageFileList;
  // char *trainFile = data->trainFile;
  char *paramFile = data->paramFile;
  int chr = data->chr;

  // utility var
  int i,j,k;
  
  // trainedModel
  struct model *mymodel;
  if( (mymodel = load_model(trainedModel)) == 0) {
    printf("cannot load model from file %s\n", trainedModel);
    return EXIT_SUCCESS;
  }

  // coverageFileList
  int totalCoverageFiles;
  FILE *coverageFileListFp = NULL;
  if( (coverageFileListFp = fopen(coverageFileList, "r") ) == NULL) {
    printf("Cannot open file %s\n", coverageFileList);
    return EXIT_SUCCESS;
  }
  char **coverageFiles = (char **)calloc(MAX_BAM_FILES,sizeof(char *));
  for(i = 0; i < MAX_BAM_FILES; i++) {
    coverageFiles[i] = (char *)calloc(MAX_DIR_LEN, sizeof(char));
  }
  
  i = 0;
  while (!feof(coverageFileListFp)) {
    if (i >= MAX_BAM_FILES) {
      printf("Error: the number of input coverages files exceeds the limit %d\n", i);
      return EXIT_SUCCESS;
    }
    if( ( fscanf(coverageFileListFp, "%s\n", coverageFiles[i]) ) != 1) {
      printf("Error: reading %dth from %s\n", i, coverageFileList);
      return EXIT_SUCCESS;
    }
    i++;
  }
  totalCoverageFiles = i;
  fclose(coverageFileListFp);

  // open coverage Files
  FILE *coverageFps[totalCoverageFiles];
  for(i = 0; i < totalCoverageFiles; i++) {
    if( (coverageFps[i] = fopen(coverageFiles[i], "rb")) == NULL ) {
      printf("Error opening coverage file %s\n", coverageFiles[i]);
      return EXIT_SUCCESS;
    }
  }

  // paramFile
  struct extractFeatureParam *param = (struct extractFeatureParam *)calloc(1, sizeof(struct extractFeatureParam));
  parseParam(paramFile, param);

  // predict model: by default: predict probability
  int nr_class = get_nr_class(mymodel);
  double *prob_estimates = (double *)calloc(nr_class, sizeof(double));

  // predResult for storing results
  int totalBins = 0;
  int cumBins[NUM_SEQ];
  for (i = 0; i < NUM_SEQ; i++) {
    totalBins += (int)(chrlen[i] / param->resolution) + 1;
    cumBins[i] = totalBins;
  }

  // allocate memory for result based on thread data chr
  // as we are using one thread for each chr
  float *predResult = (float *)calloc( (int)(chrlen[chr] / param->resolution) + 1, sizeof(float));

  // read in feature for each bin and do prediction
  for(j = 0; j < (int)(chrlen[chr] / param->resolution) + 1; j++) {
    if(j % 100000 == 0) {
      printf("Predicting chr%d:%dth bin\n", chr,j);
      fflush(stdout);
    }
    int max_nr_feature = 100;
    struct feature_node *myX = (struct feature_node *)calloc(max_nr_feature, sizeof(struct feature_node));
    int idx = 0;
    for(k = 0; k < totalCoverageFiles; k++) {
      float *buffer = (float *)calloc( param->windowSize/param->resolution,sizeof(float));
      int offset = j;
      offset += -(int)((float)(param->windowSize / 2) / (float)param->resolution + 0.5);
      if(offset < 0 || offset + (int)((float)(param->windowSize) / (float)param->resolution + 0.5) > (int)(chrlen[i] / param->resolution) + 1) {
        // printf("offset is %d\n", offset);
        free(buffer);
        continue;
      }
      if(chr != 0) offset += cumBins[chr-1];
      // printf("offset is %d\n", offset);
      fseek(coverageFps[k], offset*sizeof(float), SEEK_SET);
      fread(buffer, sizeof(float), param->windowSize/param->resolution, coverageFps[k]);
      int l;
      // printf("buffer[%d] is:",l);
      for(l = 0; l < param->windowSize/param->resolution; l++) {
        // if(j == 289540) printf("%f,",buffer[l]);
        if(buffer[l] != 0) {
          myX[idx].index = k*(param->windowSize/param->resolution) + l + 1;
          myX[idx].value = buffer[l];
          idx++;
        }
        if(idx >= max_nr_feature -2) { // feature_node is not long enough
          max_nr_feature *= 2;
          myX = (struct feature_node *)realloc(myX, max_nr_feature*sizeof(struct feature_node));
        }
      }
      free(buffer);
    } // end of loop through coverageFiles
    // printf("\n");
    myX[idx].index = -1; // a flag for end of features
    if(idx == 0) {
      // printf("idx is %d\n",idx);
      predResult[j] = 0.0;
      free(myX);
      continue;
    }
    // printf("nr_feature is %d\n", idx);
    predict_probability(mymodel, myX, prob_estimates);
    // printf("num of feature is %d\n", get_nr_feature(mymodel));
    // printf("num of class is %d\n", get_nr_class(mymodel));
    int *mylabel = (int *)calloc(10, sizeof(int));
    // added, in order to get the correct label
    get_labels(mymodel, mylabel);
    if(mylabel[0] == 1) {
      predResult[j] = prob_estimates[0];
    } else {
      predResult[j] = prob_estimates[1];
    }
 
    free(myX);
    free(mylabel);
  }


  for(i = 0; i < totalCoverageFiles; i++) {
    fclose(coverageFps[i]);
  }
  // free pointers
  for(i = 0; i < MAX_BAM_FILES; i++) {
    free(coverageFiles[i]);
  }
  free(coverageFiles);
  free(param);
  free(prob_estimates);
  // give address of pointer to this function, so that the function can free the pointer.
  free_and_destroy_model(&mymodel); 
  pthread_exit((void *) predResult);
}
Esempio n. 14
0
GPS::EphemerisData* RINEX::getGPSEphemeris(ifstream *fin,unsigned int *lineCount){
	GPS::EphemerisData *ed = NULL;
	
	string line;
	
	(*lineCount)++;
	if (!fin->eof()){ 
		getline(*fin,line);
	}
	
	string tst(line); 
	boost::trim(tst);
	if (tst.empty()) {return NULL;} // skip blank lines
	
	if (line.length() < 79){
		return NULL;
	}
	
	ed = new GPS::EphemerisData();
	
	int ibuf;
	double dbuf;
	
	// Line 1: format is I2,5I3,F5.1,3D19.12
	parseParam(line,1,2,&ibuf); ed->SVN = ibuf;
	int year,mon,mday,hour,mins;
	double secs;
	parseParam(line,3,3,&year);
	parseParam(line,6,3,&mon);
	parseParam(line,9,3,&mday);
	parseParam(line,12,3,&hour);
	parseParam(line,15,3,&mins);
	std::replace(line.begin(), line.end(), 'D', 'E'); // only floats left
	parseParam(line,18,5,&secs);
	
	parseParam(line,23,19,&dbuf);ed->a_f0=dbuf;
	parseParam(line,42,19,&dbuf);ed->a_f1=dbuf;
	parseParam(line,61,19,&dbuf);ed->a_f2=dbuf;
	
	DBGMSG(debugStream,TRACE,"ephemeris for SVN " << (int) ed->SVN << " " << hour << ":" << mins << ":" <<  secs);
	
	// Lines 2-8: 3X,4D19.12
	double dbuf1,dbuf2,dbuf3,dbuf4;
	get4DParams(fin,&dbuf1,&dbuf2,&dbuf3,&dbuf4,lineCount);
	ed->IODE=dbuf1; ed->C_rs=dbuf2; ed->delta_N=dbuf3; ed->M_0=dbuf4;
	
	get4DParams(fin,&dbuf1,&dbuf2,&dbuf3,&dbuf4,lineCount);
	ed->C_uc=dbuf1; ed->e=dbuf2; ed->C_us=dbuf3; ed->sqrtA=dbuf4;;
	
	get4DParams(fin,&dbuf1,&dbuf2,&dbuf3,&dbuf4,lineCount);
	ed->t_oe=dbuf1; ed->C_ic=dbuf2; ed->OMEGA_0=dbuf3; ed->C_is=dbuf4;
	
	get4DParams(fin,&dbuf1,&dbuf2,&dbuf3,&dbuf4,lineCount);
	ed->i_0=dbuf1; ed->C_rc=dbuf2; ed->OMEGA=dbuf3; ed->OMEGADOT=dbuf4;
	
	get4DParams(fin,&dbuf1,&dbuf2,&dbuf3,&dbuf4,lineCount);
	ed->IDOT=dbuf1; ed->week_number= dbuf3; // don't truncate WN just yet
	
	get4DParams(fin,&dbuf1,&dbuf2,&dbuf3,&dbuf4,lineCount);
	ed->SV_health=dbuf2; ed->t_GD=dbuf3; ed->IODC=dbuf4;
	int i=0;
	ed->SV_accuracy_raw=0.0;
	while (URA[i] > 0){
		if (URA[i] == dbuf1){
			ed->SV_accuracy_raw=i;
			break;
		}
		i++;
	}
	get4DParams(fin,&dbuf1,&dbuf2,&dbuf3,&dbuf4,lineCount);
	ed->t_ephem=dbuf1;
	
	// Calculate t_OC - the clock data reference time
	
	// First, work out the century.
	struct tm tmGPS; // origin of GPS time
	tmGPS.tm_sec=tmGPS.tm_min=tmGPS.tm_hour=0;
	tmGPS.tm_mday=6;tmGPS.tm_mon=0;tmGPS.tm_year=1980-1900,tmGPS.tm_isdst=0;
	time_t tGPS0=mktime(&tmGPS);
	time_t ttmp= tGPS0 + ed->week_number*7*86400;
	struct tm *tmtmp=gmtime(&ttmp);
	int century=(tmtmp->tm_year/100)*100+1900;
	
	// Then, 'full' t_OC so we can get wday
	tmGPS.tm_sec=(int) secs; 
	tmGPS.tm_min=mins;
	tmGPS.tm_hour=hour;
	tmGPS.tm_mday=mday;
	tmGPS.tm_mon=mon-1;
	tmGPS.tm_year=year+century-1900;
	tmGPS.tm_isdst=0;
	mktime(&tmGPS); // this sets wday
	
	// Then 
	ed->t_OC = secs+mins*60+hour*3600+tmGPS.tm_wday*86400;
	
	// Now truncate WN
	ed->week_number = ed->week_number - 1024*(ed->week_number/1024);
	
	return ed;
}
Esempio n. 15
0
bool parseOpcode(uint8_t opcode) {
    // MISCELLANEOUS BLOCK
    if (opcode <= 0b00001111 && opcode >= 0b00001000) {
        switch(opcode) {
            default: return false;
            case 0b00001000:    // NOP
                break;
            case 0b00001001:    // HLT
                break;
            case 0b00001010:    // CLC
                regFlags.carry = false;
                break;
            case 0b00001011:    // STC
                regFlags.carry = true;
                break;
            case 0b00001100:    // CMP
                pTypeA.imm = true;
                pTypeA.immPtr = false;
                pTypeA.reg = true;
                pTypeA.regPtr = false;
                pTypeB = pTypeA;
                parseParam(2);
                break;
            case 0b00001101:    // REP
                break;
        } return true;
    }

    // DATA MANIPULATION BLOCK
    else if (opcode <= 0b00011111 && opcode >= 0b00010000) {
        switch(opcode) {
            default: return false;
            case 0b00010000:    // MOV
                break;
            case 0b00010001:    // XCHG
                break;
            case 0b00010010:    // LOADP
                break;
            case 0b00010011:    // STOREP
                break;
            case 0b00010100:    // MOVEP
                break;
        } return true;
    }

    // BITWISE MANIPULATION BLOCK
    else if (opcode <= 0b00101111 && opcode >= 0b00100000) {
        switch(opcode) {
            default: return false;
            case 0b00100000:    // SHR
                break;
            case 0b00100001:    // SHL
                break;
            case 0b00100010:    // ROR
                break;
            case 0b00100011:    // ROL
                break;
            case 0b00100100:    // AND
                break;
            case 0b00100101:    // OR
                break;
            case 0b00100110:    // NOT
                break;
            case 0b00100111:    // NAND
                break;
            case 0b00101000:    // NOR
                break;
            case 0b00101001:    // XOR
                break;
            case 0b00101010:    // XNOR
                break;
        } return true;
    }

    // JUMP BLOCK
    else if (opcode <= 0b00111111 && opcode >= 0b00110000) {
        switch(opcode) {
            default: return false;
            case 0b00110000:    // JMP
                break;
            case 0b00110001:    // JC
                break;
            case 0b00110010:    // JNC
                break;
            case 0b00110011:    // JG
                break;
            case 0b00110100:    // JLE
                break;
            case 0b00110101:    // JL
                break;
            case 0b00110110:    // JGE
                break;
            case 0b00110111:    // JE
                break;
            case 0b00111000:    // JNE
                break;
            case 0b00111001:    // LOOP
                break;
            case 0b00111010:    // LOOPE
                break;
            case 0b00111011:    // LOOPNE
                break;
        } return true;
    }

    // MATH BLOCK
    else if (opcode <= 0b01011111 && opcode >= 0b01000000) {
        switch(opcode) {
            default: return false;
            case 0b01000000:    // INC
                break;
            case 0b01000001:    // DEC
                break;
            case 0b01000010:    // ADD
                break;
            case 0b01000011:    // ADC
                break;
            case 0b01000100:    // SUB
                break;
            case 0b01000101:    // SBB
                break;
            case 0b01000110:    // MUL
                break;
            case 0b01000111:    // DIV
                break;
        } return true;
    }

    // STACK BLOCK
    else if (opcode <= 0b01100111 && opcode >= 0b01100000) {
        switch(opcode) {
            default: return false;
            case 0b01100000:    // PUSHA
                break;
            case 0b01100001:    // PUSH
                break;
            case 0b01100010:    // POPA
                break;
            case 0b01100011:    // POP
                break;
            case 0b01100100:    // CALL
                break;
            case 0b01100101:    // RET
                break;
        } return true;
    }

    // PERIPHERIAL I/O BLOCK
    else if (opcode <= 0b01101111 && opcode >= 0b01101000) {
        switch(opcode) {
            default: return false;
            case 0b01101000:    // IN
                break;
            case 0b01101001:    // OUT
                break;
        } return true;
    }

    // INTERRUPT BLOCK
    else if (opcode <= 0b01110111 && opcode >= 0b01110000) {
        switch(opcode) {
            default: return false;
            case 0b01110000:    // STI
                regFlags.intupt = true;
                break;
            case 0b01110001:    // CLI
                regFlags.intupt = false;
                break;
            case 0b01110010:    // IRET
                break;
            case 0b01110011:    // INT
                break;
        } return true;
    }
    
    else return false;
}
int menu_predictModelWholeGenome(int argc, char **argv) {

	/* ------------------------------- */
	/*        predictModel             */
	/* -m method name                  */
  /* -tm trainedModel                */
  /* -train trainingFile             */
  /* do not need testing file, as    */
  /* it is assumed whole genome      */
  /* -coverage coverageFileList      */
	/* -o output results               */
	/* ------------------------------- */

	if (argc == 1) {
		printf("/*------------------------------------*/\n");
		printf("/*    menu_predictModelGenomeWide     */\n");
		printf("/* -m method name                     */\n");
		printf("/*    LogisticRegressionL1            */\n");
		printf("/*    LogisticRegressionL2            */\n");
		printf("/*    SVM                             */\n");
		printf("/*    RandomFores                     */\n");
    printf("/* -tm trainedModel                   */\n");
    printf("/* -train trainFile                   */\n");
    printf("/* -coverage coverageFileList         */\n");
		printf("/* -o output results                  */\n");
    printf("/* -p param                           */\n");
		printf("/*------------------------------------*/\n");
		return(EXIT_SUCCESS);
	}


  char *method = (char *)calloc(MAX_DIR_LEN, sizeof(char));
	char *trainedModel = (char *)calloc(MAX_DIR_LEN, sizeof(char));
	char *trainFile = (char *)calloc(MAX_DIR_LEN, sizeof(char)); 
  char *coverageFileList = (char *)calloc(MAX_DIR_LEN, sizeof(char));
	char *outputFile = (char *)calloc(MAX_DIR_LEN, sizeof(char));
  char *paramFile = (char *)calloc(MAX_DIR_LEN, sizeof(char));

	int ni;
	int mOK = 0, tmOK = 0, trainOK = 0, coverageOK = 0, oOK = 0, pOK = 0;

	ni = 1;
	while (ni < argc) {
		if (strcmp(argv[ni], "-m") == 0) {
			ni++;
			strcpy(method, argv[ni]);
			mOK = 1;
		}
		else if (strcmp(argv[ni], "-tm") == 0){
			ni++;
			strcpy(trainedModel, argv[ni]);
			tmOK = 1;
		}
		else if (strcmp(argv[ni], "-train") == 0){
			ni++;
			strcpy(trainFile, argv[ni]);
			trainOK = 1;
		}
		else if (strcmp(argv[ni], "-coverage") == 0){
			ni++;
			strcpy(coverageFileList, argv[ni]);
			coverageOK = 1;
		}
		else if (strcmp(argv[ni], "-o") == 0){
			ni++;
			strcpy(outputFile, argv[ni]);
			oOK = 1;
		}
		else if (strcmp(argv[ni], "-p") == 0){
			ni++;
			strcpy(paramFile, argv[ni]);
      pOK = 1;
    }
		else {
			printf("Error: unkown parameters!\n");
			return(EXIT_FAILURE);
		}
		ni++;
	}

	/* check args */
	if ((mOK + tmOK + trainOK + coverageOK + oOK + pOK) < 6){
		printf("Error: input arguments not correct!\n");
		exit(EXIT_FAILURE);
	}

  // init thr
  pthread_t thr[NUM_THREADS];
  // thread_data_t to be passed to each thread
  thread_data_t thr_data[NUM_THREADS];
  
  /* creat thread */
  int i, rc; // rc for holding error code
  for(i = 0; i < NUM_THREADS; i++) {
    thr_data[i].chr = i;
    thr_data[i].method = method;
    thr_data[i].trainedModel = trainedModel;
    thr_data[i].trainFile = trainFile;
    thr_data[i].coverageFileList = coverageFileList;
    thr_data[i].paramFile = paramFile;
    printf("creating %dth thread\n", i);
    fflush(stdout); // flush stdout
    if( (rc = pthread_create(&thr[i], NULL, predictModelWholeGenome, &thr_data[i])) ) {
      printf("error: pthread_create, rc:%d\n", rc);
      return EXIT_SUCCESS;
    }
  }

  /* block until all threads complete */
  /* then write to output in sequential order */
  float **predResult = (float **)calloc(NUM_THREADS, sizeof(float *));
  for(i = 0; i < NUM_THREADS; i++) {
    pthread_join(thr[i], (void **) &predResult[i]);
  }

  /* write to output */
  struct extractFeatureParam *param = (struct extractFeatureParam *)calloc(1,sizeof(struct extractFeatureParam));
  parseParam(paramFile,param);

  FILE *outputFileFp = NULL;
  if( (outputFileFp = fopen(outputFile, "wb")) == NULL ) {
    printf("Error: cannot write to outputFile %s\n", outputFile);
    return EXIT_SUCCESS;
  }
  printf("writing to output %s\n", outputFile);
  for(i = 0; i < NUM_THREADS; i++) {
    fwrite(predResult[i], sizeof(float),(int)(chrlen[i] / param->resolution)+1 , outputFileFp);
    free(predResult[i]);
  }
  fclose(outputFileFp);
  
	/* free pointers */
  free(method);
	free(trainedModel);
	free(trainFile);
  free(coverageFileList);
	free(outputFile);
  free(paramFile);
  free(param);
  free(predResult);

	return 0;
}
Esempio n. 17
0
bool parseMainConfig(const char* path, const char* file)
{
	FILE* fp = fopen(path, "rt");

	if (!fp)
		return false;

	char buf[8192];
	size_t line_number = 0;
	section_e section = st_unknown;
	CFields fields;

	while (fgets(buf, sizeof buf, fp)) {
		char* line = trimbuf(buf);
		line_number++;

		if (line[0] == '\xEF' && line[1] == '\xBB' && line[2] == '\xBF') // BOM
			line += 3;

		if (!line[0] || line[0] == '#')
			continue;

		if (line[0] == '[') {
			line++;

			if (nullLast(line, ']'))
				section = getSection(line);

			if (section != st_unknown && section < arraysize(section_default_format)) {
				char temp[256];
				strcpy(temp, section_default_format[section]);
				fields.parseFormat(temp);
			}

			continue;
		}

		if (section == st_unknown)
			continue;

		if (!parseLineToFields(line, fields, file, line_number))
			continue;

		if (!fields.getCount())
			continue;

		translation_t translations[16];
		size_t translations_count = fields.getTranslations(translations, arraysize(translations));

		switch (section) {
			case st_main:
			{
				auto param = fields.getField(dt_param);
				auto value = fields.getField(dt_value);

				if (!param || !value || !parseParam(param->string, value->string))
					LCPrintf("Invalid or unknown parameter at line %i in %s\n", line_number, file);
				break;
			}

			case st_hud:
			{
				if (!translations_count) {
					LCPrintf("Invalid hud mode name at line %i in %s\n", line_number, file);
					break;
				}

				auto x = fields.getField(dt_xcoord);
				auto y = fields.getField(dt_ycoord);
				auto r = fields.getField(dt_red);
				auto g = fields.getField(dt_green);
				auto b = fields.getField(dt_blue);

				if (x && y && r && g && b)
					addHudparms(translations, translations_count, x->float_number, y->float_number, r->int_number, g->int_number, b->int_number);
				else
					LCPrintf("Invalid hud parameters at line %i in %s\n", line_number, file);
				break;
			}

			case st_lang:
			{
				if (!translations_count) {
					LCPrintf("Invalid phrase without translations at line %i in %s\n", line_number, file);
					break;
				}

				auto phrase = fields.getField(dt_phrase);
				if(!phrase) {
					LCPrintf("Invalid phrase at line %i in %s\n", line_number, file);
					break;
				}

				g_lang.addPhrase(phrase->string, translations, translations_count);
				break;
			}

			case st_radio:
			{
				if (!translations_count) {
					LCPrintf("Invalid radio without translations at line %i in %s\n", line_number, file);
					break;
				}

				auto menuid = fields.getField(dt_menuid);
				if (!menuid) {
					LCPrintf("Invalid radio menu number at line %i in %s\n", line_number, file);
					break;
				}

				auto radio = fields.getField(dt_radio);
				if (!radio) {
					LCPrintf("Unknown radio command at line %i in %s\n", line_number, file);
					break;
				}

				translation_t phrase_translations[5][16];
				memset(phrase_translations, 0, sizeof phrase_translations);
				bool mult = false;

				for (size_t i = 0; i < translations_count; i++) {
					auto lang = translations[i].lang;
					char* argv[6];

					size_t phrases_count = parse((char *)translations[i].text, argv, arraysize(argv), ";\t", false);

					if (phrases_count != 3 && phrases_count != 5) {
						LCPrintf("Invalid radio phrases count at line %i in %s\n", line_number, file);
						continue;
					}

					if (phrases_count == 5) {
						mult = true;
					}

					for (size_t j = 0; j < phrases_count; j++) {
						phrase_translations[j][i].lang = lang;
						phrase_translations[j][i].text = argv[j];
					}
				}

				g_game.addRadio(menuid->int_number, radio->string, phrase_translations, translations_count, mult);
				break;
			}

			default:
				break;
		}
	}

	return true;
}
Esempio n. 18
0
bool GUIPlugin::srvRaiseEvent(ed_msgs::RaiseEvent::Request& req, ed_msgs::RaiseEvent::Response& res)
{
    std::map<std::string, std::string> params;
    for(unsigned int i = 0; i < req.param_names.size(); ++i)
        params[req.param_names[i]] = req.param_values[i];

    if (req.name == "click")
    {
        float x, y;
        std::string type;
        if (parseParam(params, "x", x) && parseParam(params, "y", y) && parseParam(params, "type", type))
        {
            p_click_ = cv::Point2i(x, y);
            t_last_click_ = ros::Time::now();
            std::cout << "Detected click at " << params["x"] << ", " << params["y"] << std::endl;

            command_ = "";
            selected_id_ = getEntityFromClick(p_click_);

            if (type == "delete")
            {
                if (!selected_id_.empty())
                {
                    // TODO: implement deletion
                    res.msg = "Deletion not yet implemented";
                    std::cout << "[ED] GUI Plugin: " << res.msg << std::endl;


//                    world_model_->erase(selected_id_);
//                    res.msg = "Deleted object with id '" + selected_id_ + "'";
                }
            }
            else if (type == "navigate")
            {
                command_ = "navigate";
                command_params_["id"] = selected_id_;
                res.msg = "Navigating to '" + selected_id_ + "'";
            }
            else if (type == "select")
            {
                res.msg = "Selected '" + selected_id_ + "'";
            }
            else
            {
                res.msg = "Unknown click type: " + type;
            }

            if (!command_.empty())
            {
                t_command_ = ros::Time::now();
                command_id_ = ed::Entity::generateID();
            }
        }
        else
        {
            res.msg = "Could not parse click event";
        }
    }
    else if (req.name == "zoom")
    {
        float f;
        if (parseParam(params, "factor", f))
        {
            float z_current = projector_pose_.t.z;
            projector_pose_.t.z = z_current / f;
        }
    }
    else if (req.name == "pan")
    {
        float dx, dy;
        if (parseParam(params, "dx", dx) && parseParam(params, "dy", dy))
        {
            projector_pose_.t.x += dx;
            projector_pose_.t.y += dy;
        }
    }
    else if (req.name == "explore")
    {
        command_ = "explore";
        t_command_ = ros::Time::now();
        command_id_ = ed::Entity::generateID();
    }
    else if (req.name == "wait")
    {
        command_ = "wait";
        t_command_ = ros::Time::now();
        command_id_ = ed::Entity::generateID();
    }
    else
    {
        res.msg = "Unknown event received: " + req.name;
    }

    std::cout << "ServerGUI: RaiseEvent: " << res.msg << std::endl;

    return true;
}
Esempio n. 19
0
/*
 * Main parse routine.  Scans for '-', then scan for arguments and
 * delete from the argv[] array if so.
 */
BOOLEAN parse_args(int *argc, char *argv[], BOOLEAN case_sensitive)
{

    int pos = 0;
    BOOLEAN retval = TRUE;
    use_case = case_sensitive;

    while (++pos <  *argc)
    {
        if ((argv[pos][0] == ARG_SEPSWITCH) || (argv[pos][0] == ARG_SEPFALSE) 
            || (argv[pos][0] == ARG_SEPTRUE))
        {
            if (argv[pos][1] == '!')
            {
                // skip the silence arg
            }
            else
            {
                int argmode;
                int index = 1;
                BOOLEAN done = FALSE;
                do
                {
                    /* Scan the present arg */
                    if (pos <  *argc - 1)
                        argmode = scan_args(argv[pos], index, argv[pos + 1]);
                    else
                        argmode = scan_args(argv[pos], index, 0);
    
                    switch (argmode)
                    {
                        case ARG_NEXTCHAR:
                            /* If it was a char, go to the next one */
                            if (!argv[pos][++index])
                                done = TRUE;
                            break;
                        case ARG_NEXTNOCAT:
                            /* Otherwise if it was a nocat, remove the extra arg */
                            remove_arg(pos, argc, argv);
                            /* Fall through to NEXTARG */
                        case ARG_NEXTARG:
                            /* Just a next arg, go do it */
                            done = TRUE;
                            break;
                        case ARG_NOMATCH:
                            /* No such arg, spit an error  */
    #ifndef CPREPROCESSOR
    #ifdef XXXXX
                            switch( parseParam(argv[pos][index] != ARG_SEPFALSE, &argv[pos][index + 1])) {
                                case 0:
    #endif
    #endif
                                    fprintf(stderr, "Invalid Arg: %s\n", argv[pos]);
                                    retval = FALSE;
                                    done = TRUE;
    #ifndef CPREPROCESSORXX
    #ifdef XXXXX
                                    break ;
                                case 1:
                                    if (!argv[pos][++index])
                                        done = TRUE;
                                    break ;
                                case 2:
                                    done = TRUE;
                                    break;
                            }
    #endif
    #endif
                            break;
                        case ARG_NOARG:
                            /* Missing the arg for a CONCAT type, spit the error */
                            fprintf(stderr, "Missing string for Arg %s\n",
                                argv[pos]);
                            done = TRUE;
                            retval = FALSE;
                            break;
                    };

                }
                while (!done);
            }
            /* We'll always get rid of the present arg
             * And back up one
             */
            remove_arg(pos--, argc, argv);
        }
    }
    return (retval);
}
Esempio n. 20
0
	//----------------------------------------------------------------------------//
	void D3D9Shader::parseParam(D3DXHANDLE parent, String prefix, unsigned int index)
	{
		D3DXHANDLE hConst = mpConstTable->GetConstant(parent, index);

		D3DXCONSTANT_DESC desc;
		uint numParams = 1;
		HRESULT hr = mpConstTable->GetConstantDesc(hConst, &desc, &numParams);
		if(FAILED(hr))
		{
			TITAN_EXCEPT_API(
				"we can not get constants descriptions from shader");
		}

		String paramName = desc.Name;
		// trim the odd '$' which appears at the start of the names in HLSL
		if (paramName.at(0) == '$')
			paramName.erase(paramName.begin());

		// Also trim the '[0]' suffix if it exists, we will add our own indexing later
		if (StringUtil::endsWith(paramName, "[0]", false))
		{
			paramName.erase(paramName.size() - 3);
		}

		if (desc.Class == D3DXPC_STRUCT)
		{
			prefix = prefix + paramName + ".";
			for(uint i = 0;i < desc.StructMembers; ++i)
			{
				parseParam(hConst, prefix, i);
			}
		}
		else
		{
			if (desc.Type == D3DXPT_FLOAT || desc.Type == D3DXPT_INT || desc.Type == D3DXPT_BOOL)
			{
				size_t paramIndex = desc.RegisterIndex;
				String name = prefix + paramName;

				ShaderConstantDef def;
				def.registerIndex = paramIndex;
				populateDef(desc, def);
				if (def.isFloat())
				{
					def.physicalIndex = mFloatRegisterToPhysical->bufferSize;
					mFloatRegisterToPhysical->bufferMap.insert(ShaderRegisterIndexUseMap::value_type(
						paramIndex, 
						ShaderRegisterIndexUse(def.physicalIndex,def.arraySize * def.elementSize)));
					mFloatRegisterToPhysical->bufferSize += def.arraySize * def.elementSize;
					mConstantDefs->floatBufferSize = mFloatRegisterToPhysical->bufferSize;
				}
				else
				{
					def.physicalIndex = mIntRegisterToPhysical->bufferSize;
					mIntRegisterToPhysical->bufferMap.insert(ShaderRegisterIndexUseMap::value_type(
						paramIndex, 
						ShaderRegisterIndexUse(def.physicalIndex,def.arraySize * def.elementSize)));
					mIntRegisterToPhysical->bufferSize += def.arraySize * def.elementSize;
					mConstantDefs->intBufferSize = mIntRegisterToPhysical->bufferSize;
				}

				mConstantDefs->constantDefMap.insert(ShaderConstantDefMap::value_type(name, def));

				mConstantDefs->genConstantDefArrayEntries(name, def);
			}
		}

	}