Loading src/include/outputs.h +29 −1 Original line number Diff line number Diff line Loading @@ -46,6 +46,20 @@ protected: //! \brief Number of elevation directional calculations. int _num_phis; /*! \brief Write the output to a HDF5 file. * * \param output: `const string &` Path to the output to be written. * \return result: `int` Exit code (0 if successful). */ int write_hdf5(const std::string &output); /*! \brief Write the output to a legacy text file. * * \param output: `const string &` Path to the output to be written. * \return result: `int` Exit code (0 if successful). */ int write_legacy(const std::string &output); public: //! \brief Number of spheres in the aggregate. int nsph; Loading Loading @@ -343,5 +357,19 @@ public: ScattererConfiguration *sc, GeometryConfiguration *gc, int first_xi = 0, int xi_length = 0 ); /*! \brief Get the size of a `ClusterOutputInfo` instance in bytes. * * \return size: `long` Estimated instance size in bytes. */ long compute_size(); /*! \brief Write the output to a file. * * \param output: `const string &` Path to the output to be written. * \param format: `const string &` Output format (one of LEGACY or HDF5). * \return result: `int` Exit code (0 if successful). */ int write(const std::string &output, const std::string &format); }; #endif // INCLUDE_OUTPUTS_H_ src/libnptm/outputs.cpp +90 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,18 @@ * * \brief Implementation of the code output format system. */ #include <cstdio> #include <exception> #include <string> #include <hdf5.h> #ifndef INCLUDE_ERRORS_H_ #include "../include/errors.h" #endif #ifndef INCLUDE_LIST_H_ #include "../include/List.h" #endif #ifndef INCLUDE_TYPES_H_ #include "../include/types.h" Loading @@ -27,8 +39,12 @@ #include "../include/Configuration.h" #endif #ifndef INCLUDE_COMMONS_H_ #include "../include/Commons.h" // #ifndef INCLUDE_COMMONS_H_ // #include "../include/Commons.h" // #endif #ifndef INCLUDE_FILE_IO_H_ #include "../include/file_io.h" #endif #ifndef INCLUDE_OUTPUTS_H_ Loading Loading @@ -346,4 +362,76 @@ long ClusterOutputInfo::compute_size( return result; } long ClusterOutputInfo::compute_size() { long result = sizeof(np_int); result += 16 * sizeof(int); result += 14 * sizeof(double); result += 104 * sizeof(long); result += 3 * nsph * sizeof(double); // sphere coordinate vectors result += xi_block_size * sizeof(int); // scale index vector result += 2 * xi_block_size * sizeof(double); // scale vectors result += xi_block_size * configurations * sizeof(dcomplex); // refraction indices vector result += 5 * xi_block_size * configurations; // sphere sizes, albedos and cross-sections result += configurations * sizeof(double); // sphere geometric sections result += xi_block_size * configurations * sizeof(dcomplex); // fsas vector result += 9 * xi_block_size * configurations * sizeof(double); // up to tqsk2 vector result += xi_block_size * sizeof(dcomplex); // fsat vector result += 3 * xi_block_size * sizeof(double); // up to s0magt vector result += 14 * xi_block_size * sizeof(double); // up to excrtt vector result += 4 * xi_block_size * sizeof(dcomplex); // up to fsac12 vector result += 12 * xi_block_size * sizeof(double); // up to fkc vector result += 15 * ndirs * sizeof(double); // up to dir_uns vector result += 4 * ndirs * configurations * xi_block_size * sizeof(dcomplex); // up to dir_sas22 vector result += 32 * ndirs * configurations * xi_block_size * sizeof(double); // up to dir_mulslr vector result += 4 * ndirs * xi_block_size * sizeof(dcomplex); // up to dir_sat22 vector result += 14 * ndirs * xi_block_size * sizeof(double); // up to dir_excrt vector result += 8 * ndirs * xi_block_size * sizeof(dcomplex); // up to dir_sac22 vector result += 78 * ndirs * xi_block_size * sizeof(double); // up to dir_milclr vector return result; } int ClusterOutputInfo::write(const std::string &output, const std::string &format) { int result = 0; if (format.compare("LEGACY") == 0) { result = write_legacy(output); } else if (format.compare("HDF5") == 0) { result = write_hdf5(output); } else { string message = "Unknown format mode: \"" + format + "\""; throw UnrecognizedConfigurationException(message); } return result; } int ClusterOutputInfo::write_hdf5(const std::string &output) { return 0; } int ClusterOutputInfo::write_legacy(const std::string &output) { int result = 0; FILE *p_outfile = fopen(output.c_str(), "w"); if (p_outfile != NULL) { if (vec_jxi[0] == 1) { // Write the preamble of c_OCLU. fprintf(p_outfile, " READ(IR,*)NSPH,LI,LE,MXNDM,INPOL,NPNT,NPNTTS,IAVM,ISAM\n"); #ifdef USE_ILP64 fprintf( p_outfile, " %5d%5d%5d%5ld%5d%5d%5d%5d%5d\n", nsph, li, le, mxndm, inpol, npnt, npntts, iavm, isam ); #else fprintf( p_outfile, " %5d%5d%5d%5d%5d%5d%5d%5d%5d\n", nsph, li, le, mxndm, inpol, npnt, npntts, iavm, isam ); #endif // USE_ILP64 } fclose(p_outfile); } else { result = -1; } return result; } // >> END OF ClusterOutputInfo CLASS IMPLEMENTATION << Loading
src/include/outputs.h +29 −1 Original line number Diff line number Diff line Loading @@ -46,6 +46,20 @@ protected: //! \brief Number of elevation directional calculations. int _num_phis; /*! \brief Write the output to a HDF5 file. * * \param output: `const string &` Path to the output to be written. * \return result: `int` Exit code (0 if successful). */ int write_hdf5(const std::string &output); /*! \brief Write the output to a legacy text file. * * \param output: `const string &` Path to the output to be written. * \return result: `int` Exit code (0 if successful). */ int write_legacy(const std::string &output); public: //! \brief Number of spheres in the aggregate. int nsph; Loading Loading @@ -343,5 +357,19 @@ public: ScattererConfiguration *sc, GeometryConfiguration *gc, int first_xi = 0, int xi_length = 0 ); /*! \brief Get the size of a `ClusterOutputInfo` instance in bytes. * * \return size: `long` Estimated instance size in bytes. */ long compute_size(); /*! \brief Write the output to a file. * * \param output: `const string &` Path to the output to be written. * \param format: `const string &` Output format (one of LEGACY or HDF5). * \return result: `int` Exit code (0 if successful). */ int write(const std::string &output, const std::string &format); }; #endif // INCLUDE_OUTPUTS_H_
src/libnptm/outputs.cpp +90 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,18 @@ * * \brief Implementation of the code output format system. */ #include <cstdio> #include <exception> #include <string> #include <hdf5.h> #ifndef INCLUDE_ERRORS_H_ #include "../include/errors.h" #endif #ifndef INCLUDE_LIST_H_ #include "../include/List.h" #endif #ifndef INCLUDE_TYPES_H_ #include "../include/types.h" Loading @@ -27,8 +39,12 @@ #include "../include/Configuration.h" #endif #ifndef INCLUDE_COMMONS_H_ #include "../include/Commons.h" // #ifndef INCLUDE_COMMONS_H_ // #include "../include/Commons.h" // #endif #ifndef INCLUDE_FILE_IO_H_ #include "../include/file_io.h" #endif #ifndef INCLUDE_OUTPUTS_H_ Loading Loading @@ -346,4 +362,76 @@ long ClusterOutputInfo::compute_size( return result; } long ClusterOutputInfo::compute_size() { long result = sizeof(np_int); result += 16 * sizeof(int); result += 14 * sizeof(double); result += 104 * sizeof(long); result += 3 * nsph * sizeof(double); // sphere coordinate vectors result += xi_block_size * sizeof(int); // scale index vector result += 2 * xi_block_size * sizeof(double); // scale vectors result += xi_block_size * configurations * sizeof(dcomplex); // refraction indices vector result += 5 * xi_block_size * configurations; // sphere sizes, albedos and cross-sections result += configurations * sizeof(double); // sphere geometric sections result += xi_block_size * configurations * sizeof(dcomplex); // fsas vector result += 9 * xi_block_size * configurations * sizeof(double); // up to tqsk2 vector result += xi_block_size * sizeof(dcomplex); // fsat vector result += 3 * xi_block_size * sizeof(double); // up to s0magt vector result += 14 * xi_block_size * sizeof(double); // up to excrtt vector result += 4 * xi_block_size * sizeof(dcomplex); // up to fsac12 vector result += 12 * xi_block_size * sizeof(double); // up to fkc vector result += 15 * ndirs * sizeof(double); // up to dir_uns vector result += 4 * ndirs * configurations * xi_block_size * sizeof(dcomplex); // up to dir_sas22 vector result += 32 * ndirs * configurations * xi_block_size * sizeof(double); // up to dir_mulslr vector result += 4 * ndirs * xi_block_size * sizeof(dcomplex); // up to dir_sat22 vector result += 14 * ndirs * xi_block_size * sizeof(double); // up to dir_excrt vector result += 8 * ndirs * xi_block_size * sizeof(dcomplex); // up to dir_sac22 vector result += 78 * ndirs * xi_block_size * sizeof(double); // up to dir_milclr vector return result; } int ClusterOutputInfo::write(const std::string &output, const std::string &format) { int result = 0; if (format.compare("LEGACY") == 0) { result = write_legacy(output); } else if (format.compare("HDF5") == 0) { result = write_hdf5(output); } else { string message = "Unknown format mode: \"" + format + "\""; throw UnrecognizedConfigurationException(message); } return result; } int ClusterOutputInfo::write_hdf5(const std::string &output) { return 0; } int ClusterOutputInfo::write_legacy(const std::string &output) { int result = 0; FILE *p_outfile = fopen(output.c_str(), "w"); if (p_outfile != NULL) { if (vec_jxi[0] == 1) { // Write the preamble of c_OCLU. fprintf(p_outfile, " READ(IR,*)NSPH,LI,LE,MXNDM,INPOL,NPNT,NPNTTS,IAVM,ISAM\n"); #ifdef USE_ILP64 fprintf( p_outfile, " %5d%5d%5d%5ld%5d%5d%5d%5d%5d\n", nsph, li, le, mxndm, inpol, npnt, npntts, iavm, isam ); #else fprintf( p_outfile, " %5d%5d%5d%5d%5d%5d%5d%5d%5d\n", nsph, li, le, mxndm, inpol, npnt, npntts, iavm, isam ); #endif // USE_ILP64 } fclose(p_outfile); } else { result = -1; } return result; } // >> END OF ClusterOutputInfo CLASS IMPLEMENTATION <<