Gauges: change the number format and precision in the output file (code directions)

I would like to adjust the number format and precision of the csv file produced for water levels, velocity and forces with gauges. I presume this is not possible from the XML file, so I may want to edit the source code. (I am already aware that DualSPHysics computes velocity and density in float-type precision; corrections welcome.)

Would a developer please direct me towards the code lines where those formats are set? Thanks in advance.

Comments

  • Let us ask @jmdalonso

    Regards

  • The output format used in the CSV files can be modified in the methods called StoreResult() of each class (JGaugeVelocity, JGaugeSwl...) in the file JDsGaugeItem.cpp

    Best regards

  • edited December 2020

    To anyone interested in this topic in the future.

    To be even more precise, in the methods SaveResults() of each class mentioned by José, one can modify the format specifier %g in the lines:

    scsv << jcsv::Fmt(jcsv::TpFloat1,"%g") << jcsv::Fmt(jcsv::TpFloat3,"%g;%g;%g");
    

    They appear to set the notation for floats and triplet of floats: %g is a rather compact numerical notation. A lookup table for different format specifiers can be found at https://www.cplusplus.com/reference/cstdio/printf/ for example.

    And the default precision of C++ is just 6. If you want to use the exponential notation and use the maximum precision of a float, edit %g into %.9E. Take a look at https://www.cplusplus.com/reference/ios/ios_base/precision/ for guidance on precision.

    With the change above, you will see 0.123456789E+00 instead of 0.12345.

Sign In or Register to comment.