/*! \fn void RoutingNode::Print() * \brief to write the RoutingNode features */ void RoutingNode::Print() { std::cerr << "The routing node has the following features \n"; PrintId(); PrintHost(); PrintSource(); PrintPrevious(); PrintType(); PrintFull(); }
int ETISource::Main() { int file_no; if(!input_file) { if(filename.empty()) { input_file = stdin; filename = "stdin"; } else { input_file = fopen(filename.c_str(), "rb"); if(!input_file) { perror("ETISource: error opening input file"); return 1; } } } file_no = fileno(input_file); PrintSource(); // set non-blocking mode int old_flags = fcntl(file_no, F_GETFL); if(old_flags == -1) { perror("ETISource: error getting socket flags"); return 1; } if(fcntl(file_no, F_SETFL, (old_flags == -1 ? 0 : old_flags) | O_NONBLOCK)) { perror("ETISource: error setting socket flags"); return 1; } fd_set fds; timeval select_timeval; size_t filled = 0; for(;;) { { std::lock_guard<std::mutex> lock(status_mutex); if(do_exit) break; } FD_ZERO(&fds); FD_SET(file_no, &fds); select_timeval.tv_sec = 0; select_timeval.tv_usec = 100 * 1000; int ready_fds = select(file_no + 1, &fds, NULL, NULL, &select_timeval); if(!(ready_fds && FD_ISSET(file_no, &fds))) continue; ssize_t bytes = read(file_no, eti_frame + filled, sizeof(eti_frame) - filled); if(bytes > 0) filled += bytes; if(bytes == 0) { fprintf(stderr, "ETISource: EOF reached!\n"); break; } if(bytes == -1) { perror("ETISource: error while read"); return 1; } if(filled < sizeof(eti_frame)) continue; observer->ETIProcessFrame(eti_frame); filled = 0; } return 0; }
int main(int argc, char *argv[]) { std::ostream & output = std::cout; std::string in; //============================================================================== // Parsing arguments //============================================================================== if( argc == 2 ) { in = argv[1]; if( in == "h" || in == "-h" || in == "--h" || in == "--help" || in == "-help" ) { DisplayHelp( output ); return 0; } } else { DisplayHelp( output ); return 0; } const std::string filename = in; try { const sofa::File theFile( filename ); const bool isSOFA = theFile.IsValid(); if( isSOFA == true ) { output << filename << " is a valid SOFA file" << std::endl; } else { output << filename << " is not a valid SOFA file" << std::endl; return 0; } const bool paddingForDisplay = true; sofa::String::PrintSeparationLine( output ); theFile.PrintAllAttributes( output , paddingForDisplay ); output << std::endl; sofa::String::PrintSeparationLine( output ); theFile.PrintSOFADimensions( output , paddingForDisplay ); output << std::endl << std::endl; output << std::endl << std::endl; output << std::endl << std::endl; output << std::endl << std::endl; const sofa::SimpleFreeFieldHRIR hrir( filename ); const bool isHRIR = hrir.IsValid(); if( isHRIR == true ) { output << filename << " is a valid 'SimpleFreeFieldHRIR' file" << std::endl; } else { output << filename << " is not a valid 'SimpleFreeFieldHRIR' file" << std::endl; return 0; } double sr = 0.0; const bool ok = hrir.GetSamplingRate( sr ); SOFA_ASSERT( ok == true ); sofa::Units::Type units; hrir.GetSamplingRateUnits( units ); output << sofa::String::PadWith( "Data.SamplingRate" ) << " = " << sr << std::endl; output << sofa::String::PadWith( "Data.SamplingRate:Units" ) << " = " << sofa::Units::GetName( units ) << std::endl; const unsigned int M = (unsigned int) hrir.GetNumMeasurements(); const unsigned int R = (unsigned int) hrir.GetNumReceivers(); const unsigned int N = (unsigned int) hrir.GetNumDataSamples(); /// change this according to your needs const bool printListenerInfos = true; const bool printReceiverInfos = true; const bool printSourceInfos = true; const bool printEmitterInfos = true; const bool printData = false; if( printListenerInfos == true ) { output << std::endl; PrintListener( theFile, output ); } if( printReceiverInfos == true ) { output << std::endl; PrintReceiver( theFile, output ); } if( printSourceInfos == true ) { output << std::endl; PrintSource( theFile, output ); } if( printEmitterInfos == true ) { output << std::endl; PrintEmitter( theFile, output ); } if( printData == true ) { std::vector< double > data; hrir.GetDataIR( data ); for( std::size_t i = 0; i < M; i++ ) { for( std::size_t j = 0; j < R; j++ ) { for( std::size_t k = 0; k < N; k++ ) { const std::size_t index = array3DIndex( i, j, k, M, R, N ); output << data[ index ] << std::endl; } } } } } catch( sofa::Exception &e ) { /// the description of the exception will be printed when raised exit(1); } catch( std::exception &e ) { std::cerr << "unknown exception occured : " << e.what() << std::endl; exit(1); } catch( ... ) { std::cerr << "unknown exception occured" << std::endl; exit(1); } return 0; }