int main (int argc, char ** argv) { int err; int steps = 0, curr_step; int retval = 0; MPI_Init (&argc, &argv); comm = MPI_COMM_WORLD; MPI_Comm_rank (comm, &rank); MPI_Comm_size (comm, &numproc); if (processArgs(argc, argv)) { return 1; } print0("Input stream = %s\n", infilename); print0("Output stream = %s\n", outfilename); print0("Read method = %s (id=%d)\n", rmethodname, read_method); print0("Read method parameters = \"%s\"\n", rmethodparams); print0("Write method = %s\n", wmethodname); print0("Write method parameters = \"%s\"\n", wmethodparams); err = adios_read_init_method(read_method, comm, "max_chunk_size=100; " "app_id =32767; \n" "verbose= 3;" "poll_interval = 100;" ); if (!err) { print0 ("%s\n", adios_errmsg()); } adios_init_noxml(comm); print0 ("Waiting to open stream %s...\n", infilename); f = adios_read_open_stream (infilename, read_method, comm, ADIOS_LOCKMODE_ALL, timeout_sec); if (adios_errno == err_file_not_found) { print ("rank %d: Stream not found after waiting %d seconds: %s\n", rank, timeout_sec, adios_errmsg()); retval = adios_errno; } else if (adios_errno == err_end_of_stream) { print ("rank %d: Stream terminated before open. %s\n", rank, adios_errmsg()); retval = adios_errno; } else if (f == NULL) { print ("rank %d: Error at opening stream: %s\n", rank, adios_errmsg()); retval = adios_errno; } else { // process steps here... if (f->current_step != 0) { print ("rank %d: WARNING: First %d steps were missed by open.\n", rank, f->current_step); } while (1) { steps++; // start counting from 1 print0 ("File info:\n"); print0 (" current step: %d\n", f->current_step); print0 (" last step: %d\n", f->last_step); print0 (" # of variables: %d:\n", f->nvars); retval = process_metadata(steps); if (retval) break; retval = read_write(steps); if (retval) break; // advance to 1) next available step with 2) blocking wait curr_step = f->current_step; // save for final bye print adios_advance_step (f, 0, timeout_sec); if (adios_errno == err_end_of_stream) { break; // quit while loop } else if (adios_errno == err_step_notready) { print ("rank %d: No new step arrived within the timeout. Quit. %s\n", rank, adios_errmsg()); break; // quit while loop } else if (f->current_step != curr_step+1) { // we missed some steps print ("rank %d: WARNING: steps %d..%d were missed when advancing.\n", rank, curr_step+1, f->current_step-1); } } adios_read_close (f); } print0 ("Bye after processing %d steps\n", steps); adios_read_finalize_method (read_method); adios_finalize (rank); MPI_Finalize (); return retval; }
int op1a_initialise_reader(MXFReader *reader, MXFPartition **headerPartition) { MXFFile *mxfFile = reader->mxfFile; EssenceReader *essenceReader = reader->essenceReader; EssenceReaderData *data; size_t i; size_t numPartitions; MXFPartition *partition; mxfKey key; uint8_t llen; uint64_t len; essenceReader->data = NULL; /* init essence reader */ CHK_MALLOC_OFAIL(essenceReader->data, EssenceReaderData); memset(essenceReader->data, 0, sizeof(EssenceReaderData)); essenceReader->data->headerPartition = *headerPartition; essenceReader->close = op1a_close; essenceReader->position_at_frame = op1a_position_at_frame; essenceReader->skip_next_frame = op1a_skip_next_frame; essenceReader->read_next_frame = op1a_read_next_frame; essenceReader->get_next_frame_number = op1a_get_next_frame_number; essenceReader->get_last_written_frame_number = op1a_get_last_written_frame_number; essenceReader->get_header_metadata = op1a_get_header_metadata; essenceReader->have_footer_metadata = op1a_have_footer_metadata; essenceReader->set_frame_rate = op1a_set_frame_rate; data = essenceReader->data; if (mxf_file_is_seekable(mxfFile)) { /* get the file partitions */ CHK_OFAIL(get_file_partitions(mxfFile, data->headerPartition, &data->partitions)); /* process the last instance of header metadata */ numPartitions = mxf_get_list_length(&data->partitions); for (i = numPartitions; i > 0; i--) { partition = (MXFPartition*)mxf_get_list_element(&data->partitions, i - 1); if (partition->headerByteCount != 0) { if (!mxf_partition_is_closed(&partition->key)) { mxf_log_warn("No closed partition with header metadata found" LOG_LOC_FORMAT, LOG_LOC_PARAMS); } if (!mxf_partition_is_complete(&partition->key)) { mxf_log_warn("No complete partition with header metadata found" LOG_LOC_FORMAT, LOG_LOC_PARAMS); } /* seek to start of partition and skip the partition pack */ CHK_OFAIL(mxf_file_seek(mxfFile, partition->thisPartition, SEEK_SET)); CHK_OFAIL(mxf_read_kl(mxfFile, &key, &llen, &len)); CHK_OFAIL(mxf_skip(mxfFile, len)); CHK_OFAIL(process_metadata(reader, partition)); if (mxf_is_footer_partition_pack(&partition->key)) { data->haveFooterMetadata = 1; } break; } } if (i == 0) { mxf_log_error("No partition with header metadata found" LOG_LOC_FORMAT, LOG_LOC_PARAMS); goto fail; } if (!reader->isMetadataOnly) { /* create file index */ CHK_OFAIL(create_index(mxfFile, &data->partitions, data->indexSID, data->bodySID, &data->index)); /* position at start of essence */ CHK_OFAIL(set_position(mxfFile, data->index, 0)); } } else { essenceReader->data->nsIndex.currentPosition = -1; /* process the header metadata */ if (!mxf_partition_is_closed(&data->headerPartition->key)) { mxf_log_warn("Header partition is not closed" LOG_LOC_FORMAT, LOG_LOC_PARAMS); } if (!mxf_partition_is_complete(&data->headerPartition->key)) { mxf_log_warn("Header partition is incomplete" LOG_LOC_FORMAT, LOG_LOC_PARAMS); } CHK_OFAIL(process_metadata(reader, data->headerPartition)); if (!reader->isMetadataOnly) { /* position at start of essence */ CHK_OFAIL(ns_position_at_first_frame(reader)); } } *headerPartition = NULL; /* take ownership */ return 1; fail: reader->essenceReader->data->headerPartition = NULL; /* release ownership */ /* essenceReader->close() will be called when closing the reader */ return 0; }