Skip to content

Commit

Permalink
Merge pull request #176 from NCAR/main-formatting
Browse files Browse the repository at this point in the history
Auto-format code changes
  • Loading branch information
boulderdaze authored Jul 9, 2024
2 parents 583162b + 6e6df7b commit b7d41cd
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 42 deletions.
17 changes: 11 additions & 6 deletions include/musica/tuvx/grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <musica/util.hpp>
#include <musica/tuvx/grid.hpp>
#include <musica/util.hpp>

#include <memory>
#include <string>
Expand All @@ -17,7 +17,6 @@ namespace musica
/// @brief A grid struct used to access grid information in tuvx
struct Grid
{

/// @brief Creates a grid instance
/// @param grid_name The name of the grid
/// @param units The units of the grid
Expand Down Expand Up @@ -52,7 +51,7 @@ namespace musica
void GetMidpoints(double midpoints[], std::size_t num_midpoints, Error *error);

private:
void *grid_; // A valid pointer to a grid instance indicates ownership by this wrapper
void *grid_; // A valid pointer to a grid instance indicates ownership by this wrapper
void *updater_;

friend class GridMap;
Expand Down Expand Up @@ -80,7 +79,7 @@ namespace musica
/// @param units The units of the grid
/// @param num_sections The number of sections in the grid
/// @param error The error struct to indicate success or failure
Grid* CreateGrid(const char* grid_name, const char* units, std::size_t num_sections, Error *error);
Grid *CreateGrid(const char *grid_name, const char *units, std::size_t num_sections, Error *error);

/// @brief Deletes a TUV-x grid instance
/// @param grid The grid to delete
Expand Down Expand Up @@ -118,9 +117,15 @@ namespace musica
// INTERNAL USE. If tuvx ever gets rewritten in C++, these functions will
// go away but the C API will remain the same and downstream projects (like CAM-SIMA) will
// not need to change
void* InternalCreateGrid(const char *grid_name, std::size_t grid_name_length, const char *units, std::size_t units_length, std::size_t num_sections, int *error_code);
void *InternalCreateGrid(
const char *grid_name,
std::size_t grid_name_length,
const char *units,
std::size_t units_length,
std::size_t num_sections,
int *error_code);
void InternalDeleteGrid(void *grid, int *error_code);
void* InternalGetGridUpdater(void *grid, int *error_code);
void *InternalGetGridUpdater(void *grid, int *error_code);
void InternalDeleteGridUpdater(void *updater, int *error_code);
std::string InternalGetGridName(void *grid, int *error_code);
std::string InternalGetGridUnits(void *grid, int *error_code);
Expand Down
4 changes: 2 additions & 2 deletions include/musica/tuvx/grid_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <musica/util.hpp>
#include <musica/tuvx/grid_map.hpp>
#include <musica/tuvx/grid.hpp>
#include <musica/tuvx/grid_map.hpp>
#include <musica/util.hpp>

#include <memory>
#include <string>
Expand Down
17 changes: 11 additions & 6 deletions include/musica/tuvx/profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <musica/util.hpp>
#include <musica/tuvx/grid.hpp>
#include <musica/tuvx/profile.hpp>
#include <musica/util.hpp>

#include <memory>
#include <string>
Expand All @@ -17,7 +17,6 @@ namespace musica
/// @brief A struct used to interact with TUV-x profiles (properties with values on a grid)
struct Profile
{

/// @brief Creates a profile instance
/// @param profile_name The name of the profile
/// @param units The units of the profile
Expand Down Expand Up @@ -79,11 +78,11 @@ namespace musica
double GetExoLayerDensity(Error *error);

private:
void *profile_; // A valid pointer to a profile instance indicates ownership by this wrapper
void *profile_; // A valid pointer to a profile instance indicates ownership by this wrapper
void *updater_;

friend class ProfileMap;

/// @brief Wraps an existing profile instance
/// @param updater The updater for the profile
Profile(void *updater)
Expand Down Expand Up @@ -176,7 +175,13 @@ namespace musica
// INTERNAL USE. If tuvx ever gets rewritten in C++, these functions will
// go away but the C API will remain the same and downstream projects (like CAM-SIMA) will
// not need to change
void *InternalCreateProfile(const char *profile_name, std::size_t profile_name_length, const char *units, std::size_t units_length, void *grid, int *error_code);
void *InternalCreateProfile(
const char *profile_name,
std::size_t profile_name_length,
const char *units,
std::size_t units_length,
void *grid,
int *error_code);
void InternalDeleteProfile(void *profile, int *error_code);
void *InternalGetProfileUpdater(void *profile, int *error_code);
void InternalDeleteProfileUpdater(void *updater, int *error_code);
Expand All @@ -190,7 +195,7 @@ namespace musica
void InternalGetLayerDensities(void *profile, double layer_densities[], std::size_t num_values, int *error_code);
void InternalSetExoLayerDensity(void *profile, double exo_layer_density, int *error_code);
void InternalCalculateExoLayerDensity(void *profile, double scale_height, int *error_code);
double InternalGetExoLayerDensity(void *profile, int *error_code);
double InternalGetExoLayerDensity(void *profile, int *error_code);

#ifdef __cplusplus
}
Expand Down
8 changes: 4 additions & 4 deletions include/musica/tuvx/profile_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <musica/util.hpp>
#include <musica/tuvx/profile_map.hpp>
#include <musica/tuvx/profile.hpp>
#include <musica/tuvx/profile_map.hpp>
#include <musica/util.hpp>

#include <memory>
#include <string>
Expand Down Expand Up @@ -33,8 +33,8 @@ namespace musica
/// @param error The error struct to indicate success or failure
void AddProfile(Profile *profile, Error *error);

/// @brief Returns a profile. For now, this calls the interal tuvx fortran api, but will allow the change to c++ later on to
/// be transparent to downstream projects
/// @brief Returns a profile. For now, this calls the interal tuvx fortran api, but will allow the change to c++ later on
/// to be transparent to downstream projects
/// @param profile_name The name of the profile we want
/// @param profile_units The units of the profile we want
/// @param error The error struct to indicate success or failure
Expand Down
8 changes: 4 additions & 4 deletions include/musica/tuvx/tuvx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// It also includes functions for creating and deleting TUVX instances with c binding.
#pragma once

#include <musica/util.hpp>
#include <musica/tuvx/grid_map.hpp>
#include <musica/tuvx/profile_map.hpp>
#include <musica/util.hpp>

#include <memory>
#include <string>
Expand All @@ -22,7 +22,7 @@ namespace musica
TUVX();

/// @brief Create an instance of tuvx from a configuration file
/// @param config_path Path to configuration file
/// @param config_path Path to configuration file
/// @param error Error struct to indicate success or failure
void Create(const char *config_path, Error *error);

Expand All @@ -32,8 +32,8 @@ namespace musica
/// @return a grid map pointer
GridMap *CreateGridMap(Error *error);

/// @brief Create a profile map. For now, this calls the interal tuvx fortran api, but will allow the change to c++ later on
/// to be transparent to downstream projects
/// @brief Create a profile map. For now, this calls the interal tuvx fortran api, but will allow the change to c++ later
/// on to be transparent to downstream projects
/// @param error The error struct to indicate success or failure
/// @return a profile map pointer
ProfileMap *CreateProfileMap(Error *error);
Expand Down
8 changes: 4 additions & 4 deletions src/test/unit/tuvx/tuvx_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TEST_F(TuvxCApiTest, CannotGetConfiguredGrid)
ASSERT_TRUE(IsSuccess(error));
ASSERT_NE(grid_map, nullptr);
Grid* grid = GetGrid(grid_map, "height", "km", &error);
ASSERT_FALSE(IsSuccess(error)); // non-host grid
ASSERT_FALSE(IsSuccess(error)); // non-host grid
ASSERT_EQ(grid, nullptr);
DeleteGridMap(grid_map, &error);
ASSERT_TRUE(IsSuccess(error));
Expand Down Expand Up @@ -153,7 +153,7 @@ TEST_F(TuvxCApiTest, CanCreateGridMap)
ASSERT_TRUE(IsSuccess(error));
ASSERT_EQ(midpoint_values[0], 0.5);
ASSERT_EQ(midpoint_values[1], 1.5);
Grid *foo_copy = GetGrid(grid_map, "foo", "m", &error);
Grid* foo_copy = GetGrid(grid_map, "foo", "m", &error);
ASSERT_TRUE(IsSuccess(error));
ASSERT_NE(foo_copy, nullptr);
for (auto& edge : edge_values)
Expand Down Expand Up @@ -193,7 +193,7 @@ TEST_F(TuvxCApiTest, CannotGetConfiguredProfile)
ASSERT_TRUE(IsSuccess(error));
ASSERT_NE(profile_map, nullptr);
Profile* profile = GetProfile(profile_map, "air", "molecule cm-3", &error);
ASSERT_FALSE(IsSuccess(error)); // non-host profile
ASSERT_FALSE(IsSuccess(error)); // non-host profile
ASSERT_EQ(profile, nullptr);
DeleteProfileMap(profile_map, &error);
ASSERT_TRUE(IsSuccess(error));
Expand Down Expand Up @@ -311,7 +311,7 @@ TEST_F(TuvxCApiTest, CanCreateProfileMap)
ASSERT_TRUE(IsSuccess(error));
ASSERT_EQ(midpoint_values[0], 0.5);
ASSERT_EQ(midpoint_values[1], 1.5);
Profile *foo_copy = GetProfile(profile_map, "foo", "molecule cm-3", &error);
Profile* foo_copy = GetProfile(profile_map, "foo", "molecule cm-3", &error);
for (auto& edge : edge_values)
{
edge = -100.0;
Expand Down
2 changes: 1 addition & 1 deletion src/tuvx/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace musica

// Grid external C API functions

Grid *CreateGrid(const char* grid_name, const char* units, std::size_t num_sections, Error *error)
Grid *CreateGrid(const char *grid_name, const char *units, std::size_t num_sections, Error *error)
{
DeleteError(error);
return new Grid(grid_name, units, num_sections, error);
Expand Down
21 changes: 14 additions & 7 deletions src/tuvx/grid_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace musica
DeleteError(error);
return new GridMap(error);
}

void DeleteGridMap(GridMap *grid_map, Error *error)
{
DeleteError(error);
Expand Down Expand Up @@ -98,17 +98,23 @@ namespace musica
InternalDeleteGridUpdater(grid->updater_, &error_code);
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to delete updater after transfer of ownership to grid map") };
*error = Error{ 1,
CreateString(MUSICA_ERROR_CATEGORY),
CreateString("Failed to delete updater after transfer of ownership to grid map") };
}
grid->updater_ = InternalGetGridUpdaterFromMap(grid_map_, grid->grid_, &error_code);
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to get updater after transfer of ownership to grid map") };
*error = Error{ 1,
CreateString(MUSICA_ERROR_CATEGORY),
CreateString("Failed to get updater after transfer of ownership to grid map") };
}
InternalDeleteGrid(grid->grid_, &error_code);
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to delete grid during transfer of ownership to grid map") };
*error = Error{ 1,
CreateString(MUSICA_ERROR_CATEGORY),
CreateString("Failed to delete grid during transfer of ownership to grid map") };
}
grid->grid_ = nullptr;
}
Expand Down Expand Up @@ -136,13 +142,13 @@ namespace musica
try
{
int error_code = 0;
void* grid_ptr = InternalGetGrid(grid_map_, grid_name, strlen(grid_name), grid_units, strlen(grid_units), &error_code);
void *grid_ptr = InternalGetGrid(grid_map_, grid_name, strlen(grid_name), grid_units, strlen(grid_units), &error_code);
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to get grid from grid map") };
return nullptr;
}
void* updater_ptr = InternalGetGridUpdaterFromMap(grid_map_, grid_ptr, &error_code);
void *updater_ptr = InternalGetGridUpdaterFromMap(grid_map_, grid_ptr, &error_code);
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to get updater") };
Expand All @@ -152,7 +158,8 @@ namespace musica
InternalDeleteGrid(grid_ptr, &error_code);
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to delete grid after getting updater") };
*error =
Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to delete grid after getting updater") };
InternalDeleteGridUpdater(updater_ptr, &error_code);
return nullptr;
}
Expand Down
5 changes: 2 additions & 3 deletions src/tuvx/profile.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2023-2024 National Center for Atmospheric Research
// SPDX-License-Identifier: Apache-2.0
#include <musica/tuvx/profile.hpp>
#include <musica/tuvx/grid.hpp>
#include <musica/tuvx/profile.hpp>

#include <cstring>
#include <filesystem>
Expand Down Expand Up @@ -92,8 +92,7 @@ namespace musica
Profile::Profile(const char *profile_name, const char *units, Grid *grid, Error *error)
{
int error_code = 0;
profile_ = InternalCreateProfile(profile_name, strlen(profile_name), units, strlen(units),
grid->updater_, &error_code);
profile_ = InternalCreateProfile(profile_name, strlen(profile_name), units, strlen(units), grid->updater_, &error_code);
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to create profile") };
Expand Down
11 changes: 8 additions & 3 deletions src/tuvx/profile_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ namespace musica
InternalDeleteProfile(profile->profile_, &error_code);
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to delete profile after transfer of ownership to profile map") };
*error = Error{ 1,
CreateString(MUSICA_ERROR_CATEGORY),
CreateString("Failed to delete profile after transfer of ownership to profile map") };
}
profile->profile_ = nullptr;
}
Expand Down Expand Up @@ -136,7 +138,8 @@ namespace musica
try
{
int error_code = 0;
void* profile_ptr = InternalGetProfile(profile_map_, profile_name, strlen(profile_name), profile_units, strlen(profile_units), &error_code);
void *profile_ptr = InternalGetProfile(
profile_map_, profile_name, strlen(profile_name), profile_units, strlen(profile_units), &error_code);
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to get profile") };
Expand All @@ -152,7 +155,9 @@ namespace musica
InternalDeleteProfile(profile_ptr, &error_code);
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to delete profile during transfer of ownership to profile map") };
*error = Error{ 1,
CreateString(MUSICA_ERROR_CATEGORY),
CreateString("Failed to delete profile during transfer of ownership to profile map") };
InternalDeleteProfileUpdater(updater_ptr, &error_code);
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions src/tuvx/tuvx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace musica
{
*error = NoError();
int error_code = 0;
GridMap* grid_map = new GridMap(InternalGetGridMap(tuvx_, &error_code));
GridMap *grid_map = new GridMap(InternalGetGridMap(tuvx_, &error_code));
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to create grid map") };
Expand All @@ -122,7 +122,7 @@ namespace musica
{
*error = NoError();
int error_code = 0;
ProfileMap* profile_map = new ProfileMap(InternalGetProfileMap(tuvx_, &error_code));
ProfileMap *profile_map = new ProfileMap(InternalGetProfileMap(tuvx_, &error_code));
if (error_code != 0)
{
*error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to create profile map") };
Expand Down

0 comments on commit b7d41cd

Please sign in to comment.