@@ -913,7 +913,7 @@ namespace imc
913913 }
914914
915915 // print channel
916- void print (std::string filename, const char sep = ' ,' , int width = 25 , int yprec = 9 )
916+ void print (std::string filename, const char sep = ' ,' , int width = 25 , int yprec = 9 , unsigned long int chunk_size = 100000 )
917917 {
918918 std::ofstream fou (filename);
919919
@@ -930,21 +930,37 @@ namespace imc
930930 fou<<xname_<<sep<<yname_<<" \n " <<xunit_<<sep<<yunit_<<" \n " ;
931931 }
932932
933- for ( unsigned long int i = 0 ; i < xdata_.size (); i++ )
933+ // Stream data in chunks
934+ unsigned long int start = 0 ;
935+ while (start < number_of_samples_)
934936 {
935- if ( sep == ' ' )
936- {
937- fou<<std::setprecision (xprec_)<<std::fixed
938- <<std::setw (width)<<std::left<<xdata_[i]
939- <<std::setprecision (yprec)<<std::fixed
940- <<std::setw (width)<<std::left<<ydata_[i]<<" \n " ;
941- }
942- else
937+ channel_chunk chunk = read_chunk (start, chunk_size, true , false ); // include_x=true, raw_mode=false (scaled)
938+
939+ if (chunk.count == 0 ) break ;
940+
941+ // Extract x and y data from chunk
942+ const double * x_ptr = reinterpret_cast <const double *>(chunk.x_bytes .data ());
943+ const double * y_ptr = reinterpret_cast <const double *>(chunk.y_bytes .data ());
944+
945+ // Write chunk data
946+ for (unsigned long int i = 0 ; i < chunk.count ; i++)
943947 {
944- fou<<std::setprecision (xprec_)<<std::fixed<<xdata_[i]
945- <<sep
946- <<std::setprecision (yprec)<<std::fixed<<ydata_[i]<<" \n " ;
948+ if ( sep == ' ' )
949+ {
950+ fou<<std::setprecision (xprec_)<<std::fixed
951+ <<std::setw (width)<<std::left<<x_ptr[i]
952+ <<std::setprecision (yprec)<<std::fixed
953+ <<std::setw (width)<<std::left<<y_ptr[i]<<" \n " ;
954+ }
955+ else
956+ {
957+ fou<<std::setprecision (xprec_)<<std::fixed<<x_ptr[i]
958+ <<sep
959+ <<std::setprecision (yprec)<<std::fixed<<y_ptr[i]<<" \n " ;
960+ }
947961 }
962+
963+ start += chunk.count ;
948964 }
949965
950966 fou.close ();
0 commit comments