void ModelInput::readInputFile(){ // Unwrap the reference: auto &domain = domainRef.get(); auto &solver = domain.getSolver(); if (not ifs.is_open()){ openInputFile(); } std::string dummy = ""; // header readParams(ifs, dummy); // gravitational acceleration readParams(ifs, solver->g); // total number of timesteps readParams(ifs, solver->tnts); // one timestep in seconds readParams(ifs, solver->dt); // output parameters: readParams(ifs, dummy, domain.qOutput->qts, domain.pts); closeInputFile(); }
void testInputFiles(int numFilenames, char* filename[]) { inputFilenames = (const char**)malloc((numFilenames+1)*sizeof(char*)); int i; char achar; for (i = 0; i < numFilenames; i++) { if (!isRecognizedSource(filename[i])) { USR_FATAL(astr("file '", filename[i], "' does not have a recognized suffix")); } // WE SHOULDN"T TRY TO OPEN .h files, just .c and .chpl and .o if (!isCHeader(filename[i])) { FILE* testfile = openInputFile(filename[i]); if (fscanf(testfile, "%c", &achar) != 1) { USR_FATAL(astr("source file '", filename[i], "' is either empty or a directory")); } closeInputFile(testfile); } inputFilenames[i] = astr(filename[i]); } inputFilenames[i] = NULL; if (!foundChplSource) USR_FATAL("Command line contains no .chpl source files"); }
int main(int argc, char* argv[]) { parseArgs(argc, argv); openInputFile(); openOutputFiles(); skipLines(); splitFile(); fprintf(stdout, "Lines Skipped: %ld / Lines Processed: %llu\n", _linesSkipped, _linesProcessed); closeOutputFiles(); closeInputFile(); exit(EXIT_SUCCESS); }
void addSourceFiles(int numNewFilenames, const char* filename[]) { static int numInputFiles = 0; int cursor = numInputFiles; char achar; numInputFiles += numNewFilenames; inputFilenames = (const char**)realloc(inputFilenames, (numInputFiles+1)*sizeof(char*)); for (int i = 0; i < numNewFilenames; i++) { if (!isRecognizedSource(filename[i])) { USR_FATAL(astr("file '", filename[i], "' does not have a recognized suffix")); } // WE SHOULDN"T TRY TO OPEN .h files, just .c and .chpl and .o if (!isCHeader(filename[i])) { FILE* testfile = openInputFile(filename[i]); if (fscanf(testfile, "%c", &achar) != 1) { USR_FATAL(astr("source file '", filename[i], "' is either empty or a directory")); } closeInputFile(testfile); } // // Don't add the same file twice -- it's unnecessary and can mess // up things like unprotected headers // bool duplicate = false; const char* newFilename = astr(filename[i]); for (int j = 0; j < cursor; j++) { if (inputFilenames[j] == newFilename) { // legal due to astr() duplicate = true; break; } } if (duplicate) { numInputFiles--; } else { inputFilenames[cursor++] = newFilename; } } inputFilenames[cursor] = NULL; if (!foundChplSource && fUseIPE == false) USR_FATAL("Command line contains no .chpl source files"); }
bool DataSource::open() { if (av_open_input_file(&m_formatCtx, qPrintable(m_filename), NULL, 0, NULL) != 0) { DPRINT("can not open file."); return false; } if(av_find_stream_info(m_formatCtx) < 0) { DPRINT("can not find stream info."); return false; } dump_format(m_formatCtx, 0, 0, 0); AVCodecContext *codecCtx = NULL; for (uint i = 0; i < m_formatCtx->nb_streams; i++) { codecCtx = m_formatCtx->streams[i]->codec; if (codecCtx->codec_type == CODEC_TYPE_VIDEO) { m_videoStream = i; //DPRINT("video stream index: %d - %dx%d", m_videoStream, codecCtx->width, codecCtx->height); if (!this->openCodec(codecCtx, &m_videoCodec)) { closeInputFile(); DPRINT("can not open video codec."); return false; } this->m_swsCtx = sws_getContext(codecCtx->width, codecCtx->height, codecCtx->pix_fmt, codecCtx->width, codecCtx->height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL); if (this->m_swsCtx == NULL) { closeInputFile(); DPRINT("can not get swscale context"); return false; } m_timeBase = av_q2d(m_formatCtx->streams[m_videoStream]->time_base); m_rawFrame = avcodec_alloc_frame(); } else if (codecCtx->codec_type == CODEC_TYPE_AUDIO) { m_audioStream = i; if (!this->openCodec(codecCtx, &m_audioCodec)) { closeInputFile(); DPRINT("can not open audio codec."); return false; } } } return true; }
void DataSource::close() { av_free(m_rawFrame); closeCodec(); closeInputFile(); }
bool EfmProcess::process(QString inputEfmFilename, QString outputAudioFilename, QString outputDataFilename, bool verboseDebug) { // Open the input file if (!openInputFile(inputEfmFilename)) { qCritical("Could not open input file!"); return false; } bool processAudio = false; bool processData = false; if (!outputAudioFilename.isEmpty()) processAudio = true; if (!outputDataFilename.isEmpty()) processData = true; qint64 inputFileSize = inputFileHandle->size(); qint64 inputBytesProcessed = 0; qint32 lastPercent = 0; // Open the audio output file if (processAudio) f2FramesToAudio.openOutputFile(outputAudioFilename); // Open the data decode output file if (processData) sectorsToData.openOutputFile(outputDataFilename); // Open the metadata JSON file if (processAudio) sectionToMeta.openOutputFile(outputAudioFilename + ".subcode.json"); if (processData) sectorsToMeta.openOutputFile(outputDataFilename + ".data.json"); // Turn on verbose debug if required if (verboseDebug) efmToF3Frames.setVerboseDebug(true); QByteArray efmBuffer; while ((efmBuffer = readEfmData()).size() != 0) { inputBytesProcessed += efmBuffer.size(); // Convert the EFM buffer data into F3 frames QVector<F3Frame> f3Frames = efmToF3Frames.convert(efmBuffer); // Convert the F3 frames into F2 frames QVector<F2Frame> f2Frames = f3ToF2Frames.convert(f3Frames); // Convert the F2 frames into F1 frames QVector<F1Frame> f1Frames = f2ToF1Frames.convert(f2Frames); if (processData) { // Convert the F1 frames to data sectors QVector<Sector> sectors = f1ToSectors.convert(f1Frames); // Write the sectors as data sectorsToData.convert(sectors); // Process the sector meta data sectorsToMeta.process(sectors); } // Convert the F2 frames into audio if (processAudio) f2FramesToAudio.convert(f2Frames); // Convert the F3 frames into subcode sections QVector<Section> sections = f3ToSections.convert(f3Frames); // Process the sections to audio metadata if (processAudio) sectionToMeta.process(sections); // Show EFM processing progress update to user qreal percent = (100.0 / static_cast<qreal>(inputFileSize)) * static_cast<qreal>(inputBytesProcessed); if (static_cast<qint32>(percent) > lastPercent) qInfo().nospace() << "Processed " << static_cast<qint32>(percent) << "% of the input EFM"; lastPercent = static_cast<qint32>(percent); } // Report on the status of the various processes reportStatus(processAudio, processData); // Close the input file closeInputFile(); // Close the output files if (processAudio) f2FramesToAudio.closeOutputFile(); if (processAudio) sectionToMeta.closeOutputFile(); if (processData) sectorsToData.closeOutputFile(); if (processData) sectorsToMeta.closeOutputFile(); return true; }
FileManager::~FileManager() { closeInputFile(); closeOutputFile(); }