コード例 #1
0
int main(){
	int A1, A2, w0, w1;
	int R;

	time_t t;
	srand((unsigned) time(&t));

	// A1 = rand() % lim + 1;
	// A2 = rand() % lim + 1;
	// w0 = rand() % lim2 + 1;
	// w1 = rand() % lim2 + 1;
	A1 = 150;
	A2 = 250;
	w0 = 25;
	w1 = 50;
	R = 250;

	writeSample("./data/sig1.dat", A1, w0, R);
	plot("./data/sig1.dat",1,"Signal 1");

	writeSample("./data/sig2.dat", A2, w1, R);
	plot("./data/sig2.dat",1, "Signal 2");

	printf("Actual f for Signal 1: %lf\n",w0/6.283);
	printf("Observed f for Signal 1: %lf\n", freq("./data/sig1.dat",R));

	printf("\nActual f for Signal 2: %lf\n",w1/6.283);
	printf("Observed f for Signal 2: %lf\n", freq("./data/sig2.dat",R));
	
	rFile(A1,w0,1000,3000);
	return 0;
}
コード例 #2
0
    static bool compare_files_internal(const char* filename_1, const char* filename_2)
    {
        std::ifstream lFile(filename_1, std::ios::in | std::ios::binary);
        std::ifstream rFile(filename_2, std::ios::in | std::ios::binary);


        if(!lFile.good() || !rFile.good())
        {
            return false;
        }

        std::streamsize lReadBytesCount = 0;
        std::streamsize rReadBytesCount = 0;

        const int bufferSize = 100;
        char p_lBuffer[bufferSize];
        char p_rBuffer[bufferSize];

        do {
            lFile.read(p_lBuffer, bufferSize);
            rFile.read(p_rBuffer, bufferSize);
            lReadBytesCount = lFile.gcount();
            rReadBytesCount = rFile.gcount();

            if (lReadBytesCount != rReadBytesCount || std::memcmp(p_lBuffer, p_rBuffer, lReadBytesCount) != 0)
            {
                return false;
            }
        } while (lFile.good() || rFile.good());

        return true;
    }
コード例 #3
0
/// helper function to test writing into output file
bool isFilesEqual(const char* lFilePath, const char* rFilePath)
{
	std::ifstream lFile(lFilePath, std::ios::in | std::ios::binary);
	std::ifstream rFile(rFilePath, std::ios::in | std::ios::binary);

	if (!lFile.good() || !rFile.good())
		return false;

	std::streamsize lReadBytesCount = 0;
	std::streamsize rReadBytesCount = 0;

	int bufferSize = 8192;
	char* p_lBuffer = new char[bufferSize];
	char* p_rBuffer = new char[bufferSize];

	do {
		lFile.read(p_lBuffer, bufferSize);
		rFile.read(p_rBuffer, bufferSize);
		lReadBytesCount = lFile.gcount();
		rReadBytesCount = rFile.gcount();

		if (lReadBytesCount != rReadBytesCount || std::memcmp(p_lBuffer, p_rBuffer, (size_t)lReadBytesCount) != 0)
		{
			delete[] p_lBuffer;
			delete[] p_rBuffer;

			return false;
		}
	} while (lFile.good() || rFile.good());

	delete[] p_lBuffer;
	delete[] p_rBuffer;

	return true;
}
コード例 #4
0
ファイル: file_lexical.c プロジェクト: mck-dajiao/complier
void main(){
	
	int over = 1;
	WORD* oneword = NULL;
	// output stream pointer
	stream = fopen("e:\\newoutput.txt", "w+");
	//WORD* oneword = new WORD;
	printf("Enter Your words(end with #))");
	// read the source code into buffer , end with # , multiline is avaliable
	// scanf("%[^#]s", input);		
	rFile();
	p_input = 0;
	printf("Your words:\n%s\n", p);
	
	// analysis the source code end with #
	while(over<1000 && over!=-1){

		// get a new word
		oneword = scanner();
		if(oneword->typenum < 1000){
				// print the typenum and word
				fprintf(stream, "(%d, %s)\n", oneword->typenum, oneword->word);
		}

		over = oneword->typenum;
	}

	printf("\npress # to exit:");
	scanf("%[^#]s", input);
	fclose(stream);
     	free(p);

}
コード例 #5
0
ファイル: fileparse.cpp プロジェクト: CoolAs/Compoglot
int fileParse(int argc,char* argv[]){
	if (argc!=5)
	{
		std::cout << "Usage: " << argv[0] << " " << argv[1] <<" <language> <input-file> <output-file>" << std::endl;
		return -1;
	}

	std::ifstream rFile(argv[3]);
	std::ofstream wFile(argv[4]);
	if (!rFile.is_open())
	{
		std::cout << "Could not open input file" << std::endl;
		return -1;
	}
	if (!wFile.is_open())
	{
		std::cout << "Could not open output file" << std::endl;
		return -1;
	}

	char c = 0;
	while (rFile.get(c))
	{
		if (c!= '$')
			wFile.put(c);
		else
		{
			if (rFile.get(c) && c == '<')
				if (rFile.get(c) && c == 'L')
					if (rFile.get(c) && c == 'A')
						if (rFile.get(c) && c == 'N')
							if (rFile.get(c) && c == 'G')
							{
								std::string input;
								while (rFile.get(c) && c != '>')
								{
									input += c;
								}
								Parser parser;
								std::string output;

								try{
									output = parser.parse(argv[2],input);
								}
								catch(ParseException& e){
									std::cerr << e;
									return -1;
								}
								wFile << output;
							}else wFile << "$<LAN" << c;
						else wFile << "$<LA" << c;
					else wFile << "$<L" << c;
				else wFile << "$<" << c;
			else wFile << "$" << c;
		}
	}
 return 0;
}
コード例 #6
0
ファイル: client.c プロジェクト: dqhoang/schoolwork
main(int argc, char *argv[ ], char *env[])
{
  int n;
  char* result;
  char ** myargv;
  char line[MAX], ans[MAX];
  int x , y;

  if (argc < 3){
     printf("Usage : client ServerName SeverPort\n");
     exit(1);
  }

  client_init(argv);

  printf("********  processing loop  *********\n");
  while (1){
    printf("CMD: ");
    bzero(line, MAX);                // zero out line[ ]
    fgets(line, MAX, stdin);         // get a line (end with \n) from stdin

    line[strlen(line)-1] = 0;        // kill \n at end
    if (line[0]!=0)                  // exit if NULL line
    {
    	if ( !strcmp( line , "quit") ){ exit(0);}
    	if ( line[0] == 'l' && line[1] != 's' )       // Local command?
        {
            printf("Local command! %s\n" , &line[1]);
            myargv = getInput(&line[1]);

            runLocal(myargv, env);

            bzero(line, MAX);
        }
        else if(line[0] != '0'){
            // Send ENTIRE line to server
          n = write(sock, line, MAX);
          printf("client: wrote n=%d bytes; line=(%s)\n", n, line);

		  myargv = getInput(line);
		  pArgv(myargv);
		  
		if( !strcmp(myargv[0], "get" ) ) { wFile(sock, myargv[1]); }
		else if( !strcmp(myargv[0], "put") ){ rFile(sock, myargv[1]); }
		  else{
            // Read from sock and print till end command is received
            while( strcmp(line, "END STREAM") )
            {
            	n = read(sock, line , MAX);
            	printf("%s\n" , line);
            }
          }
        }
      }
   }
}
コード例 #7
0
ApolloStoryProducer :: ApolloStoryProducer (string dir)
{

	ifstream rFile(dir+string("/task_info.json"));
	
	if (!rFile)
	{
		cout << "task_info.json does not exist." << endl;
		candidate = false;
		return;
	}
	
	string line;
	getline (rFile, line);	

 	Reader reader;
    Value metaData;
    reader.parse(line, metaData);
    Value query = metaData["query"];
    Value analysisType = query["analysis_types"];

    for (unsigned int i=0; i<analysisType.size(); i++)
    {
    	if (analysisType[i].asString() == string("Diversity"))
    	{
    		candidate = true;    	
    		break;
    	}
    }

	Name nRoot = Name("Apollo");
	nRoot.append(Name(query["dataset"].asString()));
	
	this->storyName = query["dataset"].asString();
	this->producer = new InfoMaxProducer(nRoot);

    vector<Name> nameList;
	vector<Data> dataList;

	string subdir = string(dir+string("/analysis/Diversity"));	
    if (readDirintoNameAndData(subdir, &nameList, &dataList))  
    {
    	for(unsigned int i=0; i<nameList.size(); i++) {	
			producer->add(nameList[i], dataList[i]);
		}
	}	    

    if (!candidate)
    {
    	cout << "This folder doesn't have Diversity folder." << endl;
    	candidate = false;
    	return;
    }   
		
}
コード例 #8
0
ファイル: treeFromAscii.C プロジェクト: iLCSoft/GEAR
void treeFromAscii(const char* filen) {

//  Read data from an ascii file and create a root file with a tree

  std::string rFile( filen ) ;
  rFile += ".root" ;
  TFile *f = new TFile( rFile.c_str() ,"RECREATE");

  TTree*  ntuple = new TTree("ntuple","") ;
  ntuple->ReadFile( filen ) ;
  
  f->Write() ;
  f->Close() ;
}
コード例 #9
0
// ------------------------------------------------------------------------------------------------
//	Returns true, if the filename is part of the archive.
bool Q3BSPZipArchive::Exists(const char* pFile) const {
	ai_assert(pFile != NULL);

	bool exist = false;

	if (pFile != NULL) {
		std::string rFile(pFile);
		std::map<std::string, ZipFile*>::const_iterator it = m_ArchiveMap.find(rFile);

		if(it != m_ArchiveMap.end()) {
			exist = true;
		}
	}

	return exist;
}
コード例 #10
0
int main (){

    std::ifstream rFile("1-string-stream.txt");
    
    std::map<std::string,int> word_count;
    
    std::set<std::string> exclude_word = {"a","an","the","The","or","of","on","On"};
    
    read_text(rFile, word_count, exclude_word);
    
    std::ofstream wFile("output.txt");
    
    display(word_count, wFile);
    
    return 0;
}
コード例 #11
0
// ------------------------------------------------------------------------------------------------
//	Returns true, if the filename is part of the archive.
bool Q3BSPZipArchive::Exists( const char* pFile ) const
{
	ai_assert( NULL != pFile );
	if ( NULL == pFile )
	{
		return false;
	}

	std::string rFile( pFile );
	std::vector<std::string>::const_iterator it = std::find( m_FileList.begin(), m_FileList.end(), rFile );
	if ( m_FileList.end() == it )
	{
		return false;
	}

	return true;
}
コード例 #12
0
ファイル: cstester.cpp プロジェクト: crayonink/calligra-2
int main(int argc, char *argv[])
{
    KCmdLineArgs::init(argc, argv, "cstester", 0, KLocalizedString(), 0, KLocalizedString());

    KCmdLineOptions options;
    options.add("create", ki18n("create verification data for file"));
    options.add("indir <dir>", ki18n("directory to read the data from"));
    options.add("outdir <dir>", ki18n("directory to save the data to"));
    options.add("roundtrip", ki18n("load/save/load and check the document is the same after load and save/load"));
    options.add("verbose", ki18n("be verbose"));
    options.add("!verify", ki18n("verify the file"));
    options.add( "+file", ki18n("file to use"));
    KCmdLineArgs::addCmdLineOptions(options);

    QApplication app(argc, argv);

    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    bool create = false;
    bool roundtrip = false;
    bool verify = false;
    int optionCount = 0;

    if (args->isSet("create")) {
        create = true;
        optionCount++;
    }
    if (args->isSet("roundtrip")) {
        roundtrip = true;
        optionCount++;
    }
    if (args->isSet("verify")) {
        verify = true;
        optionCount++;
    }

    if (optionCount > 1) {
        kError() << "create, roundtrip and verify cannot be used the same time";
        exit(1);
    }
    else if (optionCount < 1) {
        kError() << "one of the options create, roundtrip or verify needs to be specified";
        exit(1);
    }

    QString outDir;
    if (args->isSet("outdir")) {
        // check if it is a directory
        QDir dir(args->getOption("outdir"));
        if (!dir.exists()) {
            kError() << "outdir" << args->getOption("outdir") << "does not exist";
            exit(1);
        }
        outDir = dir.path();
    }

    QString inDir;
    if (args->isSet("indir")) {
        // check if it is a directory
        QDir dir(args->getOption("indir"));
        if (!dir.exists()) {
            kError() << "indir" << args->getOption("indir") << "does not exist";
            exit(1);
        }
        inDir = dir.path();
    }

    bool verbose = args->isSet("verbose");

    int exitValue = 0;

    int successful = 0;
    int failed = 0;
    for (int i=0; i < args->count(); ++i) {
        QString filename(args->arg(i));
        QFileInfo file(filename);
        QString checkDir;
        if (!args->isSet("indir")) {
            checkDir = filename + ".check";
        }
        else {
            checkDir = inDir + '/' + file.fileName() + ".check";
        }

        // this is wrong for multiple files in different dirs
        if (!args->isSet("outdir")) {
            outDir = file.path();
        }

        qDebug() << "filename" << filename << "path" << file.path() << file.completeBaseName() << checkDir << file.absoluteFilePath();
        qDebug() << "inDir" << inDir << "outDir" << outDir << "checkDir" << checkDir;

        // filename must be a absolute path
        KoDocument* document = openFile(file.absoluteFilePath());
        if (!document) {
            exit(2);
        }

        QList<QImage> thumbnails(createThumbnails(document, QSize(800,800)));

        qDebug() << "created" << thumbnails.size() << "thumbnails";
        if (create) {
            saveThumbnails(file, thumbnails, outDir);
        }
        else if (verify) {
            if (args->isSet("outdir")) {
                saveThumbnails(file, thumbnails, outDir);
            }
            if (checkThumbnails(thumbnails, checkDir, verbose)) {
                ++successful;
            }
            else {
                ++failed;
                exitValue = 2;
            }
        }
        else if (roundtrip) {
            QString rFilename = saveFile(document, filename, "cstester-roundtrip");
            delete document;
            QFileInfo rFile(rFilename);
            qDebug() << roundtrip << "rFilename" << rFilename << rFile.absoluteFilePath();
            document = openFile(rFile.absoluteFilePath());
            QList<QImage> others(createThumbnails(document, QSize(800,800)));
            if (args->isSet("outdir")) {
                saveThumbnails(file, others, outDir);
                saveThumbnails(file, thumbnails, outDir + "/before");
            }
            if (checkThumbnails(thumbnails, others, verbose)) {
                ++successful;
            }
            else {
                ++failed;
                exitValue = 2;
            }
        }
        delete document;
    }

    if (verify || roundtrip) {
        qDebug() << "Totals:" << successful << "passed" << failed << "failed";
    }

    QTimer::singleShot(1, &app, SLOT(quit()));
    app.exec();
    return exitValue;
}
コード例 #13
0
ファイル: Gdocfile.cpp プロジェクト: karlnicholas/GeneThon
int   
CGenethonDoc::ReadGenbankFile( CPtrList *CommentList, CPtrList *SequenceList, const char * PathName )
{
	// Determine File Type.
	CString LOCUS;
	CString DEFINITION;
	CString ACCESSION;
	CString NID;
	CString PID;
	CString Trans;
	CString Origin;

TRY {

	CString tString;
	SeqNameStruct *tSNS;
	int i;

	CStdioFile rFile(PathName, CFile::modeRead );

	
	int EOFFLAG = 0;
	int gettingorigin = 0;
	int gettingtrans = 0;
	int Loc;

	// Now we are looking for data
	do {
		// clear out temp string.
		tString.Empty();
		char *tStr = tString.GetBuffer(1024);
		if ( rFile.ReadString( tStr, 1024 ) == NULL ) {
			// Done .. break out
			EOFFLAG = 1;
		}
		tString.ReleaseBuffer();
		tString = tString.SpanExcluding("\n\r");

		if ( !tString.GetLength() ) continue;

		if ( gettingtrans == 1 ) {
			Trans += tString;
			if ( Trans.Find( "\"" ) != -1 ) {
				gettingtrans = 0;
			}
		} else if ( gettingorigin == 1 ) {
			if ( Trans.Find( "//" ) != -1 ) {
				gettingorigin = 0;
			} else {
				Origin += tString;
			}
		}

		if ( tString.Find("LOCUS") != -1 ) {
			char *pc = LOCUS.GetBuffer(128);
			sscanf( (const char *)tString.Mid( 12 ), "%s", pc );
			LOCUS.ReleaseBuffer();
		} else if ( tString.Find("DEFINITION") != -1 ) {
			DEFINITION = tString.Mid( 12 );
		} else if ( tString.Find("ACCESSION") != -1 ) {
			char *pc = ACCESSION.GetBuffer(128);
			sscanf( (const char *)tString.Mid( 12 ), "%s", pc );
			ACCESSION.ReleaseBuffer();
		} else if ( tString.Find("NID") != -1 ) {
			char *pc = NID.GetBuffer(128);
			sscanf( (const char *)tString.Mid( 12 ), "%s", pc );
			NID.ReleaseBuffer();
		} else if ( tString.Find("PID") != -1 ) {
			char *pc = PID.GetBuffer(128);
			sscanf( (const char *)tString.Mid( 12 ), "%s", pc );
			PID.ReleaseBuffer();
		} else if ( (Loc = tString.Find("/translation=")) != -1 ) {
			Trans = tString.Mid( Loc + 14 );
			if ( Trans.Find( "\"" ) == -1 ) {
				gettingtrans = 1;
			}
		} else if ( (Loc = tString.Find("ORIGIN")) != -1 ) {
			gettingorigin = 1;
		}




	// Loop until end of file now.
	} while ( EOFFLAG == 0 );

	rFile.Close();

	gMaxStrSize = 0;

	CGenbank Dlg;
	Dlg.LOCUS = LOCUS;
	Dlg.ACCESSION = ACCESSION;
	Dlg.NID = NID;
	Dlg.PID = PID;
	if ( Dlg.DoModal() != IDOK ) return 0;

	tSNS = new SeqNameStruct;

	switch (Dlg.m_Locus) {
		case 0:
		tSNS->Name = LOCUS;
		break;
	case 1:
		tSNS->Name = ACCESSION;
		break;
	case 2:
		tSNS->Name = NID;
		break;
	case 3:
		tSNS->Name = PID;
		break;
	}

	// Lets check if name exists ..
	POSITION tPos = SequenceList->GetHeadPosition();
	while ( tPos != NULL ) {
		SeqNameStruct* tSNS1 = (SeqNameStruct*)SequenceList->GetNext(tPos);
		if ( CString(tSNS1->Name) == tSNS->Name ) {
			char ErrBuff[256];
			sprintf ( ErrBuff, "Sequence Name Duplicate Found!: %s", (const char *)tSNS->Name );
			delete tSNS;
			AfxMessageBox( ErrBuff );
			return 0;
		}
	}

	tSNS->Descr = DEFINITION;
	tSNS->Len = 0;
	tSNS->Start = 1;
	tSNS->Check = 1234;
	tSNS->Weight = 1.0;

	CString *data;
	switch ( Dlg.m_Trans ) {
	case 0:
		data = &Trans;
		break;
	case 1:
		data = &Origin;
		break;
	}
	CString dString;
	i = 0;
	int End = data->GetLength();
	while ( i < End ) {
		char tChar = toupper((*data)[i]);
		if ( tChar >= 'A' && tChar <= 'Z' ) dString += (*data)[i];
		i++;
	}
	if ( dString.GetLength() ) {
		tSNS->Len = dString.GetLength();
		tSNS->hText = GlobalAlloc( GMEM_FLAG, tSNS->Len);
		char *pRes = (char *)GlobalLock(tSNS->hText);
		char *pnRes = dString.GetBuffer(tSNS->Len);
		int MoveCount = tSNS->Len;
		while (MoveCount--) {
			*pRes++ = *pnRes++;
		}
		GlobalUnlock(tSNS->hText);
		dString.ReleaseBuffer();
	}

	gMaxStrSize = tSNS->Len;

	if ( gMaxStrSize == 0 ) {
		AfxMessageBox("TEXT Data not Found");
		return 0;
	}

	SequenceList->AddTail( tSNS );

} 
CATCH (CFileException, e ) {
    if( e->m_cause == CFileException::fileNotFound )
		AfxMessageBox( "File Not Found Error" );
	else
		AfxMessageBox( "File Error" );

	return 0;
}
AND_CATCH (CMemoryException, e ) {
	AfxMessageBox( "Memory Exception" );
	return 0;
}