Esempio n. 1
0
// Open a glf file for writing with the specified filename.
bool GlfFile::openForWrite(const char * filename, bool compressed)
{
    // Reset for any previously operated on files.
    resetFile();

    if(compressed)
    {
        myFilePtr = ifopen(filename, "wb", InputFile::BGZF);
    }
    else
    {
        myFilePtr = ifopen(filename, "wb", InputFile::UNCOMPRESSED);
    }

    if (myFilePtr == NULL)
    {
        std::string errorMessage = "Failed to Open ";
        errorMessage += filename;
        errorMessage += " for writing";
        myStatus.setStatus(GlfStatus::FAIL_IO, errorMessage.c_str());
        throw(GlfException(myStatus));
        return(false);
    }
   
    myIsOpenForWrite = true;

    // Successfully opened the file.
    myStatus = GlfStatus::SUCCESS;
    return(true);
}
Esempio n. 2
0
// Constructor, init variables and open the specified file based on the
// specified mode (READ/WRITE).  Default is READ..
GlfFile::GlfFile(const char* filename, OpenType mode)
    : myFilePtr(NULL),
      myEndMarker()
{
    resetFile();

    bool openStatus = true;
    if(mode == READ)
    {
        // open the file for read.
        openStatus = openForRead(filename);
    }
    else
    {
        // open the file for write.
        openStatus = openForWrite(filename);
    }
    if(!openStatus)
    {
        // Failed to open the file - print error and abort.
        fprintf(stderr, "%s\n", getStatusMessage());
        std::cerr << "FAILURE - EXITING!!!" << std::endl;
        exit(-1);
    }
}
Esempio n. 3
0
void SamFile::init(const char* filename, OpenType mode, SamFileHeader* header)
{
    init();
        
    resetFile();

    bool openStatus = true;
    if(mode == READ)
    {
        // open the file for read.
        openStatus = OpenForRead(filename, header);
    }
    else
    {
        // open the file for write.
        openStatus = OpenForWrite(filename, header);
    }
    if(!openStatus)
    {
        // Failed to open the file - print error and abort.
        fprintf(stderr, "%s\n", GetStatusMessage());
        std::cerr << "FAILURE - EXITING!!!" << std::endl;
        exit(-1);
    }
}
Esempio n. 4
0
SamFile::~SamFile()
{
    resetFile();
    if(myStatistics != NULL)
    {
        delete myStatistics;
    }
}
Esempio n. 5
0
void resetServer(){
	for(int i=0;i<MAXSESSION;i++){
		width[i] = height[i] = page[i] = -1;
		zoom[i] = 0;
	}
	sessionCount = 0;
	resetFile("list.txt");
	return;
}
Esempio n. 6
0
/*
Saída: Gera os arquivos temporários que serão utilizados pelo BucketSort
Custo : O(1) Todas as variáveis são constantes
*/
void createTemporaryFiles()
{
    int i;

    char * path = (char *) malloc(strlen(DIR)*sizeof(char));

    for(i=0; i < TOTAL_INTERVAL/BUCKET_INTERVAL ; i++)
    {
        strcat(strcpy(path,DIR),itoa_lock(i,LOCK));
        resetFile(path);
    }
}
Esempio n. 7
0
void VcfFile::reset()
{
    // Reset the child class.
    resetFile();

    // Close the file.
    if (myFilePtr != NULL)
    {
        // If we already have an open file, close it.
        ifclose(myFilePtr);
        myFilePtr = NULL;
    }
    myNumRecords = 0;
}
Esempio n. 8
0
/*
Entrada: Caminho do arquivo a ser gerado com os arquivos concatenados
Saída: Gera o arquivo final ordenado
Custo : O(n) Concatena os arquivos temporários, logo, n
*/
void concatTempFiles(char * path)
{
    resetFile(path);

    int i;
    FILE * concatFile = fopen(path,"ab+"), *temp;
    char * pathTemp = (char *) malloc(strlen(DIR)*sizeof(char));

    for(i=0; i < TOTAL_INTERVAL/BUCKET_INTERVAL ; i++)
    {
        strcat(strcpy(pathTemp,DIR),itoa_lock(i,LOCK));
        temp = fopen(pathTemp,"rb");
        filecat(concatFile,temp);
        fclose(temp);
    }
    fclose(concatFile);
}
Esempio n. 9
0
int createSession(const char *file){
	// creates and initiates a new session
	if(sessionCount==MAXSESSION){
		printf("\nCANT HAVE ANYMORE STATUS !!\n");
		return 0;
	}
	if(isExist(file)!=1){
		printf("\nCANT CREATE NEW SESSION : FILE {%s} NOT FOUND !!",file);
		return 0;
	}
	int session = sessionCount;
	sessionCount++;
	addNewSession(session,file);
	char statusFile[100];
	sprintf(statusFile,"status_%i.txt",session);
	resetFile(statusFile);
	char line[1000];
	// launch the session and store windowid in windowId
	char windowID[100];
	windowID[0] = '\0';
	launchPdf(file,windowID);
	// initialize the new openned session
	initializeWindow(windowID);
	sprintf(line,"%s",windowID);
	addLine(statusFile,line);
	sprintf(line,"%s",file);
	addLine(statusFile,line);
	sprintf(line,"%d",PAGE_DEFAULT);
	addLine(statusFile,line);
	sprintf(line,"%d",ZOOM_DEFAULT);
	addLine(statusFile,line);
	sprintf(line,"%d",WIDTH_DEFAULT);
	addLine(statusFile,line);
	sprintf(line,"%d",HEIGHT_DEFAULT);
	addLine(statusFile,line);
	page[session] = PAGE_DEFAULT;
	zoom[session] = ZOOM_DEFAULT;
	width[session] = WIDTH_DEFAULT;
	height[session] = HEIGHT_DEFAULT;
	return 1;
}
Esempio n. 10
0
// Open a glf file for reading with the specified filename.
bool GlfFile::openForRead(const char * filename)
{
    // Reset for any previously operated on files.
    resetFile();

    myFilePtr = ifopen(filename, "rb");
   
    if (myFilePtr == NULL)
    {
        std::string errorMessage = "Failed to Open ";
        errorMessage += filename;
        errorMessage += " for reading";
        myStatus.setStatus(GlfStatus::FAIL_IO, errorMessage.c_str());
        throw(GlfException(myStatus));
        return(false);
    }

    myIsOpenForRead = true;
    // Successfully opened the file.
    myStatus = GlfStatus::SUCCESS;
    return(true);
}
Esempio n. 11
0
FileEditionWidget::FileEditionWidget(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::FileEditionWidget),  _askFileContext(None), _gridEditor(nullptr), _propertiesBrowser(nullptr),
    _propertyDialog(nullptr), _plainTextEditor(nullptr), _textDialog(nullptr),
	_nsEditor(nullptr), _nsDialog(nullptr)
{
	ui->setupUi(this);

	_editMapper = new QSignalMapper(this);
    connect(_editMapper, SIGNAL(mapped(QString)), this, SLOT(editFile(QString)));
	connect(ui->tableWidget, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(rowDoubleClicked(int)));

	_exportMapper = new QSignalMapper(this);
    connect(_exportMapper, SIGNAL(mapped(QString)), this, SLOT(exportFile(QString)));

	_importMapper = new QSignalMapper(this);
    connect(_importMapper, SIGNAL(mapped(QString)), this, SLOT(importFile(QString)));

	_resetMapper = new QSignalMapper(this);
    connect(_resetMapper, SIGNAL(mapped(QString)), this, SLOT(resetFile(QString)));

    connect(ui->btnImportFile, SIGNAL(clicked()), this, SLOT(importFromDisk()));
    connect(ui->btnNewFile, SIGNAL(clicked()), this, SLOT(newFile()));
}
Esempio n. 12
0
//====================================
int main(int argc, char *argv[])
//====================================
{
  char syscom[120];
  int ch,i,x;

  currentStep = 1;
  currentLoop = 0;



  strcpy(gplFile,"gpl.txt");

  inrpt[0] = IR0;
  inrpt[1] = IR1;
  inrpt[2] = IR2;
  inrpt[3] = IR3;
  inrpt[4] = IR4;
  inrpt[5] = IR5;


  sprintf(syscom,"ls *.conf > %s;",fileProjList);
  x=system(syscom);
  sprintf(syscom,"rm %s;touch %s;",fileTemp,fileTemp);
  x=system(syscom);
  sprintf(syscom,"rm %s;touch %s;",fileError,fileError);
  x=system(syscom);
  sprintf(syscom,"rm %s;touch %s;",fileServError,fileServError);
  x=system(syscom);
  sprintf(syscom,"rm %s;touch %s;",fileCopyError,fileCopyError);
  x=system(syscom);

  err = fopen(fileError,"w"); // Issue 15

  readSetting();
  readConfig(currentConf);


  initSim();

  resetSim();

  readSimulation();

  readSketchInfo();

  setRange(confBoardType);

  init(confWinMode);

  unoInfo();
  show(slog);

  if(confLogFile == S_YES)resetFile("log.txt");

  readMsg(gplFile);

  openCommand();
  
  delwin(uno);
  delwin(ser);
  delwin(slog);
  delwin(msg);
  endwin();

  fclose(err);

}
Esempio n. 13
0
GlfFile::~GlfFile()
{
    resetFile();
}
Esempio n. 14
0
// Constructor, init variables.
GlfFile::GlfFile()
    : myFilePtr(NULL),
      myEndMarker()
{
    resetFile();
}
Esempio n. 15
0
// Open a sam/bam file for reading with the specified filename.
bool SamFile::OpenForRead(const char * filename, SamFileHeader* header)
{
    // Reset for any previously operated on files.
    resetFile();

    int lastchar = 0;

    while (filename[lastchar] != 0) lastchar++;

    // If at least one character, check for '-'.
    if((lastchar >= 1) && (filename[0] == '-'))
    {
        // Read from stdin - determine type of file to read.
        // Determine if compressed bam.
        if(strcmp(filename, "-.bam") == 0)
        {
            // Compressed bam - open as bgzf.
            // -.bam is the filename, read compressed bam from stdin
            filename = "-";

            myFilePtr = new InputFile;
            // support recover mode - this switches in a reader
            // capable of recovering from bad BGZF compression blocks.
            myFilePtr->setAttemptRecovery(myAttemptRecovery);
            myFilePtr->openFile(filename, "rb", InputFile::BGZF);

            myInterfacePtr = new BamInterface;

            // Read the magic string.
            char magic[4];
            ifread(myFilePtr, magic, 4);
        }
        else if(strcmp(filename, "-.ubam") == 0)
        {
            // uncompressed BAM File.
            // -.ubam is the filename, read uncompressed bam from stdin.
            // uncompressed BAM is still compressed with BGZF, but using
            // compression level 0, so still open as BGZF since it has a
            // BGZF header.
            filename = "-";

            // Uncompressed, so do not require the eof block.
#ifdef __ZLIB_AVAILABLE__
            BgzfFileType::setRequireEofBlock(false);
#endif
            myFilePtr = ifopen(filename, "rb", InputFile::BGZF);
        
            myInterfacePtr = new BamInterface;

            // Read the magic string.
            char magic[4];
            ifread(myFilePtr, magic, 4);
        }
        else if((strcmp(filename, "-") == 0) || (strcmp(filename, "-.sam") == 0))
        {
            // SAM File.
            // read sam from stdin
            filename = "-";
            myFilePtr = ifopen(filename, "rb", InputFile::UNCOMPRESSED);
            myInterfacePtr = new SamInterface;
        }
        else
        {
            std::string errorMessage = "Invalid SAM/BAM filename, ";
            errorMessage += filename;
            errorMessage += ".  From stdin, can only be '-', '-.sam', '-.bam', or '-.ubam'";
            myStatus.setStatus(SamStatus::FAIL_IO, errorMessage.c_str());
            delete myFilePtr;
            myFilePtr = NULL;
            return(false);          
        }
    }
    else
    {
        // Not from stdin.  Read the file to determine the type.

        myFilePtr = new InputFile;

        // support recovery mode - this conditionally enables a reader
        // capable of recovering from bad BGZF compression blocks.
        myFilePtr->setAttemptRecovery(myAttemptRecovery);
        bool rc = myFilePtr->openFile(filename, "rb", InputFile::DEFAULT);

        if (rc == false)
        {
            std::string errorMessage = "Failed to Open ";
            errorMessage += filename;
            errorMessage += " for reading";
            myStatus.setStatus(SamStatus::FAIL_IO, errorMessage.c_str());
            delete myFilePtr;
            myFilePtr = NULL;
            return(false);
        }
        
        char magic[4];
        ifread(myFilePtr, magic, 4);
        
        if (magic[0] == 'B' && magic[1] == 'A' && magic[2] == 'M' &&
            magic[3] == 1)
        {
            myInterfacePtr = new BamInterface;
            // Set that it is a bam file open for reading.  This is needed to
            // determine if an index file can be used.
            myIsBamOpenForRead = true;
        }
        else
        {
            // Not a bam, so rewind to the beginning of the file so it
            // can be read.
            ifrewind(myFilePtr);
            myInterfacePtr = new SamInterface;
        }
    }

    // File is open for reading.
    myIsOpenForRead = true;

    // Read the header if one was passed in.
    if(header != NULL)
    {
        return(ReadHeader(*header));
    }

    // Successfully opened the file.
    myStatus = SamStatus::SUCCESS;
    return(true);
}
Esempio n. 16
0
VcfFileReader::~VcfFileReader() 
{
    resetFile();
}
Esempio n. 17
0
// Close the file if there is one open.
void SamFile::Close()
{
    // Resetting the file will close it if it is open, and
    // will reset all other variables.
    resetFile();
}
Esempio n. 18
0
File: RpiTx.c Progetto: JE6HBC/rpitx
int main(int argc, char* argv[])
{
	int a;
	int anyargs = 0;
	char Mode = MODE_IQ;  // By default
	int SampleRate=48000;
	float SetFrequency=1e6;//1MHZ
	float ppmpll=0.0;
	char NoUsePwmFrequency=0;

	while(1)
	{
		a = getopt(argc, argv, "i:f:m:s:p:hld:w:c:");
	
		if(a == -1) 
		{
			if(anyargs) break;
			else a='h'; //print usage and exit
		}
		anyargs = 1;	

		switch(a)
		{
		case 'i': // File name
			FileName = optarg;
			break;
		case 'f': // Frequency
			SetFrequency = atof(optarg);
			break;
		case 'm': // Mode (IQ,IQFLOAT,RF,RFA)
			if(strcmp("IQ",optarg)==0) Mode=MODE_IQ;
			if(strcmp("RF",optarg)==0) Mode=MODE_RF;	
			if(strcmp("RFA",optarg)==0) Mode=MODE_RFA;
			if(strcmp("IQFLOAT",optarg)==0) Mode=MODE_IQ_FLOAT;
			if(strcmp("VFO",optarg)==0) Mode=MODE_VFO;
			break;
		case 's': // SampleRate (Only needeed in IQ mode)
			SampleRate = atoi(optarg);
			break;
		case 'p':  //	ppmcorrection
			ppmpll = atof(optarg);
			
			break;
		case 'h': // help
			print_usage();
			exit(1);
			break;
		case 'l': // loop mode
			loop_mode_flag = 1;
			break;
		case 'd': // loop mode
			DmaSampleBurstSize = atoi(optarg);
			NUM_SAMPLES=4*DmaSampleBurstSize;
			break;
		case 'c': // Use clock instead of PWM pin
			UsePCMClk = atoi(optarg);
			if(UsePCMClk==1) printf("Use GPCLK Pin instead of PWM\n");
			break;
		case 'w': // No use pwmfrequency 
			NoUsePwmFrequency = atoi(optarg);
			
			break;
        	case -1:
        	break;
		case '?':
			if (isprint(optopt) )
 			{
 				fprintf(stderr, "rpitx: unknown option `-%c'.\n", optopt);
 			}
			else
			{
				fprintf(stderr, "rpitx: unknown option character `\\x%x'.\n", optopt);
			}
			print_usage();

			exit(1);
			break;			
		default:
			print_usage();
			exit(1);
			break;
		}/* end switch a */
	}/* end while getopt() */

	//Open File Input for modes which need it
	if((Mode==MODE_IQ)||(Mode==MODE_IQ_FLOAT)||(Mode==MODE_RF)||(Mode==MODE_RFA))
	{
		if(FileName && strcmp(FileName,"-")==0)
		{
			FileInHandle = STDIN_FILENO;
			useStdin = 1;
		}
		else FileInHandle = open(FileName, O_RDONLY);
		if (FileInHandle < 0)
		{
			fatal("Failed to read Filein %s\n",FileName);
		}
	}

	resetFile();
	return pitx_run(Mode, SampleRate, SetFrequency, ppmpll, NoUsePwmFrequency, readFile, resetFile, NULL);
}
Esempio n. 19
0
// Constructor, init variables.
SamFile::SamFile(ErrorHandler::HandlingType errorHandlingType)
    : myStatus(errorHandlingType)
{
    init();
    resetFile();
}
Esempio n. 20
0
// Constructor, init variables.
SamFile::SamFile()
    : myStatus()
{
    init();
    resetFile();
}
Esempio n. 21
0
// Open a sam/bam file for writing with the specified filename.
bool SamFile::OpenForWrite(const char * filename, SamFileHeader* header)
{
    // Reset for any previously operated on files.
    resetFile();
    
    int lastchar = 0;
    while (filename[lastchar] != 0) lastchar++;   
    if (lastchar >= 4 && 
        filename[lastchar - 4] == 'u' &&
        filename[lastchar - 3] == 'b' &&
        filename[lastchar - 2] == 'a' &&
        filename[lastchar - 1] == 'm')
    {
        // BAM File.
        // if -.ubam is the filename, write uncompressed bam to stdout
        if((lastchar == 6) && (filename[0] == '-') && (filename[1] == '.'))
        {
            filename = "-";
        }

        myFilePtr = ifopen(filename, "wb0", InputFile::BGZF);

        myInterfacePtr = new BamInterface;
    }
    else if (lastchar >= 3 && 
             filename[lastchar - 3] == 'b' &&
             filename[lastchar - 2] == 'a' &&
             filename[lastchar - 1] == 'm')
    {
        // BAM File.
        // if -.bam is the filename, write compressed bam to stdout
        if((lastchar == 5) && (filename[0] == '-') && (filename[1] == '.'))
        {
            filename = "-";
        }
        myFilePtr = ifopen(filename, "wb", InputFile::BGZF);
        
        myInterfacePtr = new BamInterface;
    }
    else
    {
        // SAM File
        // if - (followed by anything is the filename,
        // write uncompressed sam to stdout
        if((lastchar >= 1) && (filename[0] == '-'))
        {
            filename = "-";
        }
        myFilePtr = ifopen(filename, "wb", InputFile::UNCOMPRESSED);
   
        myInterfacePtr = new SamInterface;
    }

    if (myFilePtr == NULL)
    {
        std::string errorMessage = "Failed to Open ";
        errorMessage += filename;
        errorMessage += " for writing";
        myStatus.setStatus(SamStatus::FAIL_IO, errorMessage.c_str());
        return(false);
    }
   
    myIsOpenForWrite = true;

    // Write the header if one was passed in.
    if(header != NULL)
    {
        return(WriteHeader(*header));
    }

    // Successfully opened the file.
    myStatus = SamStatus::SUCCESS;
    return(true);
}
Esempio n. 22
0
void ExperimentReport::generateQualityIndicators() {


  if ((!isSingleObjective_) && (paretoFrontDirectory_.empty())) {
    generateReferenceFronts();
  }

  // TODO: Check if it is possible to use QualityIndicator class instead each independent class.
  // Problem: knowing number of objectives of each problem

  if (indicatorList_.size() > 0) {

    cout << "PF file: " << paretoFrontDirectory_ << endl;

    for (int algorithmIndex=0; algorithmIndex<algorithmNameList_.size(); algorithmIndex++) {

      string algorithmDirectory;
      algorithmDirectory = experimentBaseDirectory_ + "/data/" + algorithmNameList_[algorithmIndex] + "/";

      for (int problemIndex=0; problemIndex<problemList_.size(); problemIndex++) {

        string problemDirectory = algorithmDirectory + problemList_[problemIndex];
        string paretoFrontPath;

        if (!isSingleObjective_) {

          if (paretoFrontDirectory_.empty()) {

            string referenceFrontDirectory = experimentBaseDirectory_ + "/referenceFronts";
            paretoFrontPath = referenceFrontDirectory + "/" + problemList_[problemIndex] + ".rf";

          } else {
            paretoFrontPath = paretoFrontDirectory_ + "/" + paretoFrontFile_[problemIndex];
          } // if

        } // if

        for (int indicatorIndex = 0; indicatorIndex < indicatorList_.size(); indicatorIndex++) {


          resetFile(problemDirectory + "/" + indicatorList_[indicatorIndex]);

          if (indicatorList_[indicatorIndex].compare("FIT")==0) {

            string solutionFrontFile = problemDirectory + "/FUN";
            string qualityIndicatorFile = problemDirectory;

            Fitness * indicators = new Fitness();
            vector< vector<double> > solutionFront =
                indicators->utils_->readFront(solutionFrontFile);
            qualityIndicatorFile = qualityIndicatorFile + "/FIT";
            indicators->fitness(solutionFront, qualityIndicatorFile);
            delete indicators;

          } else {

            for (int numRun=0; numRun<independentRuns_; numRun++) {

              stringstream outputParetoFrontFilePath;
              outputParetoFrontFilePath << problemDirectory << "/FUN_" << numRun;
              string solutionFrontFile = outputParetoFrontFilePath.str();
              string qualityIndicatorFile = problemDirectory;
              double value;

              cout << "ExperimentReport: Quality indicator: " << indicatorList_[indicatorIndex] << endl;

              if (indicatorList_[indicatorIndex].compare("HV")==0) {

                Hypervolume * indicators = new Hypervolume();
                vector< vector<double> > solutionFront =
                    indicators->utils_->readFront(solutionFrontFile);
                vector< vector<double> > trueFront =
                    indicators->utils_->readFront(paretoFrontPath);
                value = indicators->hypervolume(solutionFront, trueFront, trueFront[0].size());
                delete indicators;
                qualityIndicatorFile = qualityIndicatorFile + "/HV";
              }
              if (indicatorList_[indicatorIndex].compare("SPREAD")==0) {
                Spread * indicators = new Spread();
                vector< vector<double> > solutionFront =
                    indicators->utils_->readFront(solutionFrontFile);
                vector< vector<double> > trueFront =
                    indicators->utils_->readFront(paretoFrontPath);
                value = indicators->spread(solutionFront, trueFront, trueFront[0].size());
                delete indicators;
                qualityIndicatorFile = qualityIndicatorFile + "/SPREAD";
              }
              if (indicatorList_[indicatorIndex].compare("IGD")==0) {
                InvertedGenerationalDistance * indicators = new InvertedGenerationalDistance();
                vector< vector<double> > solutionFront =
                    indicators->utils_->readFront(solutionFrontFile);
                vector< vector<double> > trueFront =
                    indicators->utils_->readFront(paretoFrontPath);
                value = indicators->invertedGenerationalDistance(solutionFront, trueFront, trueFront[0].size());
                delete indicators;
                qualityIndicatorFile = qualityIndicatorFile + "/IGD";
              }
              if (indicatorList_[indicatorIndex].compare("EPSILON")==0) {
                Epsilon * indicators = new Epsilon();
                vector< vector<double> > solutionFront =
                    indicators->utils_->readFront(solutionFrontFile);
                vector< vector<double> > trueFront =
                    indicators->utils_->readFront(paretoFrontPath);
                value = indicators->epsilon(solutionFront, trueFront, trueFront[0].size());
                delete indicators;
                qualityIndicatorFile = qualityIndicatorFile + "/EPSILON";
              }

              cout << "ExperimentReport: Quality indicator file: " << qualityIndicatorFile << endl;

              if (qualityIndicatorFile.compare(problemDirectory)!=0) {
                std::fstream out(qualityIndicatorFile.c_str(),
                    std::ios::out | std::ios::app);
                out << value << endl;
                out.close();
              } // if

            } // for

          } // if
        } // for
      } // for
    } // for
  } // if
} // generateQualityIndicators
Esempio n. 23
0
Loader::Impl::~Impl()
{
	resetFile(FileName());
}