//--------------------------------------------------------------------------- 
// readSection: position to BOF for a new section,
// do continuous reads until len < 0 
//--------------------------------------------------------------------------- 
Int32 UdrCfgParser::readSection( const char *section, char *buf, Int32 bufLen
                              , NAString &errorText )
{
   Int32 len = -1;
   static NABoolean newSection = TRUE;                         

   if (cfgFile)
   {
      if (!newSection)
         len = readPair(cfgFile, buf, bufLen, errorText);
      else
      {
         fseek(cfgFile, 0, SEEK_SET);
         if( gotoSection( cfgFile, section, errorText ) )
            len = readPair(cfgFile, buf, bufLen, errorText);
         newSection = FALSE;
      }
   }

   if (len < 0)
      newSection = TRUE;

   return len;
}
Example #2
0
// Load translation from file
void Localization::loadFromFile(std::ifstream &f)
{
    if (f.fail())
    {
        dprintf("Failed to open translation, skip.\n");
        return;
    }
    dprintf("Read translation ...\n");
    string strKey, strValue;
    while (readPair(f, strKey, strValue))
    {
        set(strKey, strValue);
    }
    dprintf("Translation loaded to memory.\n");
}
Example #3
0
void loadTOP(char* filename){
	int i;
	printf("Reading topology.\n");
	FILE* topFile = fopen(filename, "r");
	char buffer[buf_size];
	if (topFile != NULL ){
		while(fgets(buffer, buf_size, topFile) != NULL){
			if(strncmp(buffer, "[ atoms ]", 9) == 0){
				printf("Counting atoms...\n");
				sop.aminoCount = countRows(topFile);
				printf("%d found.\n", sop.aminoCount);
			}
			if(strncmp(buffer, "[ bonds ]", 9) == 0){
				printf("Counting covalent bonds...\n");
				sop.bondCount = countRows(topFile);
				printf("%d found.\n", sop.bondCount);
			}
			if(strncmp(buffer, "[ native ]", 10) == 0){
				printf("Counting native contacts...\n");
				sop.nativeCount = countRows(topFile);
				printf("%d found.\n", sop.nativeCount);
			}
			if(strncmp(buffer, "[ pairs ]", 9) == 0){
				printf("Counting pairs...\n");
				sop.pairCount = countRows(topFile);
				printf("%d found.\n", sop.pairCount);
			}
		}
	} else {
		printf("ERROR: cant find topology file '%s'.\n", filename);
		exit(0);
	}


	sop.aminos = (Atom*)calloc(sop.aminoCount, sizeof(Atom));
	sop.bonds = (CovalentBond*)calloc(sop.bondCount, sizeof(CovalentBond));
	sop.natives = (NativeContact*)calloc(sop.nativeCount, sizeof(NativeContact));
	sop.pairs = (PossiblePair*)calloc(sop.pairCount, sizeof(PossiblePair));

	rewind(topFile);
	while(fgets(buffer, buf_size, topFile) != NULL){
		if(strncmp(buffer, "[ atoms ]", 9) == 0){
			fgets(buffer, buf_size, topFile);
			for(i = 0; i < sop.aminoCount; i++){
				readAtom(&sop.aminos[i], topFile);
			}
		}
		if(strncmp(buffer, "[ bonds ]", 9) == 0){
			fgets(buffer, buf_size, topFile);
			for(i = 0; i < sop.bondCount; i++){
				TOPPair pair = readPair(topFile);
				sop.bonds[i].i = pair.i;
				sop.bonds[i].j = pair.j;
				sop.bonds[i].r0 = pair.c0;
			}
		}
		if(strncmp(buffer, "[ native ]", 10) == 0){
			fgets(buffer, buf_size, topFile);
			for(i = 0; i < sop.nativeCount; i++){
				TOPPair pair = readPair(topFile);
				sop.natives[i].i = pair.i;
				sop.natives[i].j = pair.j;
				sop.natives[i].r0 = pair.c0;
				sop.natives[i].eh = pair.c1;

			}
		}
		if(strncmp(buffer, "[ pairs ]", 9) == 0){
			fgets(buffer, buf_size, topFile);
			for(i = 0; i < sop.pairCount; i++){
				TOPPair pair = readPair(topFile);
				sop.pairs[i].i = pair.i;
				sop.pairs[i].j = pair.j;
			}
		}
	}

	fclose(topFile);
	printf("Done reading topology.\n");
}