Skip to content

Commit

Permalink
Merge pull request #35 from USEPA/release-5.1.14
Browse files Browse the repository at this point in the history
Release 5.1.14
  • Loading branch information
michaeltryby authored Mar 26, 2020
2 parents 0ab0021 + 87281a8 commit ce668c6
Show file tree
Hide file tree
Showing 110 changed files with 2,899 additions and 2,926 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

# Eclipse Stuff
.metadata/
.settings/
.settings/

build/
nrtests/
32 changes: 32 additions & 0 deletions Build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!---
Build.md
Created: Dec 2, 2019
Updated:
Author: Michael E. Tryby
US EPA - ORD/CESER
--->


## Building SWMM Locally on Windows


### Dependencies

Before the project can be built the required dependencies must be installed.

**Summary of Build Dependencies: Windows**

- Build
- Build Tools for Visual Studio 2017
- CMake 3.13


### Build

SWMM can be built with one simple command.
```
\> cd swmm
\swmm>tools\make.cmd
```
87 changes: 87 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#
# CMakeLists.txt - CMake configuration file for swmm-solver
#
# Created: July 11, 2019
# Modified: Nov 25, 2019
#
# Author: Michael E. Tryby
# US EPA ORD/CESER
#


cmake_minimum_required (VERSION 3.13)

if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message(FATAL_ERROR "In-source builds are disabled.")
endif()


project(swmm-solver
VERSION 5.1.14
LANGUAGES C CXX
)

# Append local dir to module search path
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# Sets the position independent code property for all targets
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Sets default install prefix when cmakecache is initialized for first time
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "..." FORCE)
endif()


# Define install locations (will be prepended by install prefix)
set(TOOL_DIST "bin")
set(INCLUDE_DIST "include")
set(LIBRARY_DIST "lib")
set(CONFIG_DIST "cmake")


option(BUILD_TESTS "Builds component tests (requires Boost)" OFF)
option(BUILD_DEF "Builds library with def file interface" OFF)


# Add project subdirectories
add_subdirectory(src/outfile)
add_subdirectory(src/solver)
add_subdirectory(src/run)

if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()


# Create target import scripts so other cmake projects can use swmm libraries
install(
EXPORT
swmm5Targets
DESTINATION
"${CONFIG_DIST}"
FILE
swmm5-config.cmake
)

install(
EXPORT
swmm-outputTargets
DESTINATION
"${CONFIG_DIST}"
FILE
swmm-output-config.cmake
)

# Create install rules for vcruntime.dll, msvcp.dll, vcomp.dll etc.
set(CMAKE_INSTALL_OPENMP_LIBRARIES TRUE)
include(InstallRequiredSystemLibraries)


# Configure CPack driven installer package
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_VENDOR "US_EPA")
set(CPACK_ARCHIVE_FILE_NAME "swmm")

include(CPack)
File renamed without changes.
61 changes: 61 additions & 0 deletions src/outfile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# CMakeLists.txt - CMake configuration file for swmm/outfile
#
# Created: July 11, 2019
#
# Author: Michael E. Tryby
# US EPA ORD/CESER
#

# configure file groups
set(SWMM_OUT_PUBLIC_HEADERS
include/swmm_output.h
include/swmm_output_enums.h
include/swmm_output_export.h
)


# the binary output file API
add_library(swmm-output
SHARED
swmm_output.c
errormanager.c
)

target_include_directories(swmm-output
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INCLUDE_DIST}>
)

include(GenerateExportHeader)
generate_export_header(swmm-output
BASE_NAME swmm_output
EXPORT_MACRO_NAME EXPORT_OUT_API
EXPORT_FILE_NAME swmm_output_export.h
STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC
)

file(COPY ${CMAKE_CURRENT_BINARY_DIR}/swmm_output_export.h
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/include
)


install(TARGETS swmm-output EXPORT swmm-outputTargets
RUNTIME DESTINATION "${TOOL_DIST}"
LIBRARY DESTINATION "${TOOL_DIST}"
ARCHIVE DESTINATION "${LIBRARY_DIST}"
FRAMEWORK DESTINATION "${TOOL_DIST}"
)

install(FILES ${SWMM_OUT_PUBLIC_HEADERS} DESTINATION "${INCLUDE_DIST}")


# copy epanet-output to build tree for testing
if(BUILD_TESTS)
add_custom_command(TARGET swmm-output POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:swmm-output>
${CMAKE_BINARY_DIR}/bin/$<CONFIGURATION>/$<TARGET_FILE_NAME:swmm-output>
)
endif()
74 changes: 74 additions & 0 deletions src/outfile/errormanager.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//-----------------------------------------------------------------------------
//
// errormanager.c
//
// Purpose: Provides a simple interface for managing runtime error messages.
//
// Date 08/25/2017
//
// Author: Michael E. Tryby
// US EPA - ORD/NRMRL
//-----------------------------------------------------------------------------
#include <stdlib.h>
#include <string.h>
#include "errormanager.h"

error_handle_t* new_errormanager(void (*p_error_message)(int, char*, int))
//
// Purpose: Constructs a new error handle.
//
{
error_handle_t* error_handle;
error_handle = (error_handle_t*)calloc(1, sizeof(error_handle_t));

error_handle->p_msg_lookup = p_error_message;

return error_handle;
}

void dst_errormanager(error_handle_t* error_handle)
//
// Purpose: Destroys the error handle.
//
{
free(error_handle);
}

int set_error(error_handle_t* error_handle, int errorcode)
//
// Purpose: Sets an error code in the handle.
//
{
// If the error code is 0 no action is taken and 0 is returned.
// This is a feature not a bug.
if (errorcode)
error_handle->error_status = errorcode;

return errorcode;
}

char* check_error(error_handle_t* error_handle)
//
// Purpose: Returns the error message or NULL.
//
// Note: Caller must free memory allocated by check_error
//
{
char* temp = NULL;

if (error_handle->error_status != 0) {
temp = (char*) calloc(ERR_MAXMSG, sizeof(char));

if (temp)
error_handle->p_msg_lookup(error_handle->error_status, temp, ERR_MAXMSG);
}
return temp;
}

void clear_error(error_handle_t* error_handle)
//
// Purpose: Clears the error from the handle.
//
{
error_handle->error_status = 0;
}
27 changes: 27 additions & 0 deletions src/outfile/errormanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* errormanager.h
*
* Created on: Aug 25, 2017
*
* Author: Michael E. Tryby
* US EPA - ORD/NRMRL
*/

#ifndef ERRORMANAGER_H_
#define ERRORMANAGER_H_

#define ERR_MAXMSG 256

typedef struct error_s {
int error_status;
void (*p_msg_lookup)(int, char*, int);
} error_handle_t;

error_handle_t* new_errormanager(void (*p_error_message)(int, char*, int));
void dst_errormanager(error_handle_t* error_handle);

int set_error(error_handle_t* error_handle, int errorcode);
char* check_error(error_handle_t* error_handle);
void clear_error(error_handle_t* error_handle);

#endif /* ERRORMANAGER_H_ */
65 changes: 65 additions & 0 deletions src/outfile/include/swmm_output.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* swmm_output.c - SWMM Output API
*
* Author: Colleen Barr
* US EPA - ORD/NHEERL
*
* Modified by: Michael E. Tryby,
* Bryant McDonnell
*
*/

#ifndef SWMM_OUTPUT_H_
#define SWMM_OUTPUT_H_

#define MAXFILENAME 259 // Max characters in file path
#define MAXELENAME 31 // Max characters in element name

// This is an opaque pointer to struct. Do not access variables.
typedef void *SMO_Handle;


#include "swmm_output_enums.h"
#include "swmm_output_export.h"

#ifdef __cplusplus
extern "C" {
#endif

int EXPORT_OUT_API SMO_init(SMO_Handle *p_handle);
int EXPORT_OUT_API SMO_close(SMO_Handle *p_handle);
int EXPORT_OUT_API SMO_open(SMO_Handle p_handle, const char *path);
int EXPORT_OUT_API SMO_getVersion(SMO_Handle p_handle, int *version);
int EXPORT_OUT_API SMO_getProjectSize(SMO_Handle p_handle, int **elementCount, int *length);

int EXPORT_OUT_API SMO_getUnits(SMO_Handle p_handle, int **unitFlag, int *length);
int EXPORT_OUT_API SMO_getFlowUnits(SMO_Handle p_handle, int *unitFlag);
int EXPORT_OUT_API SMO_getPollutantUnits(SMO_Handle p_handle, int **unitFlag, int *length);
int EXPORT_OUT_API SMO_getStartDate(SMO_Handle p_handle, double *date);
int EXPORT_OUT_API SMO_getTimes(SMO_Handle p_handle, SMO_time code, int *time);
int EXPORT_OUT_API SMO_getElementName(SMO_Handle p_handle, SMO_elementType type, int elementIndex, char **elementName, int *size);

int EXPORT_OUT_API SMO_getSubcatchSeries(SMO_Handle p_handle, int subcatchIndex, SMO_subcatchAttribute attr, int startPeriod, int endPeriod, float **outValueArray, int *length);
int EXPORT_OUT_API SMO_getNodeSeries(SMO_Handle p_handle, int nodeIndex, SMO_nodeAttribute attr, int startPeriod, int endPeriod, float **outValueArray, int *length);
int EXPORT_OUT_API SMO_getLinkSeries(SMO_Handle p_handle, int linkIndex, SMO_linkAttribute attr, int startPeriod, int endPeriod, float **outValueArray, int *length);
int EXPORT_OUT_API SMO_getSystemSeries(SMO_Handle p_handle, SMO_systemAttribute attr, int startPeriod, int endPeriod, float **outValueArray, int *length);

int EXPORT_OUT_API SMO_getSubcatchAttribute(SMO_Handle p_handle, int timeIndex, SMO_subcatchAttribute attr, float **outValueArray, int *length);
int EXPORT_OUT_API SMO_getNodeAttribute(SMO_Handle p_handle, int timeIndex, SMO_nodeAttribute attr, float **outValueArray, int *length);
int EXPORT_OUT_API SMO_getLinkAttribute(SMO_Handle p_handle, int timeIndex, SMO_linkAttribute attr, float **outValueArray, int *length);
int EXPORT_OUT_API SMO_getSystemAttribute(SMO_Handle p_handle, int timeIndex, SMO_systemAttribute attr, float **outValueArray, int *length);

int EXPORT_OUT_API SMO_getSubcatchResult(SMO_Handle p_handle, int timeIndex, int subcatchIndex, float **outValueArray, int *length);
int EXPORT_OUT_API SMO_getNodeResult(SMO_Handle p_handle, int timeIndex, int nodeIndex, float **outValueArray, int *length);
int EXPORT_OUT_API SMO_getLinkResult(SMO_Handle p_handle, int timeIndex, int linkIndex, float **outValueArray, int *length);
int EXPORT_OUT_API SMO_getSystemResult(SMO_Handle p_handle, int timeIndex, int dummyIndex, float **outValueArray, int *length);

void EXPORT_OUT_API SMO_free(void **array);
void EXPORT_OUT_API SMO_clearError(SMO_Handle p_handle_in);
int EXPORT_OUT_API SMO_checkError(SMO_Handle p_handle_in, char **msg_buffer);

#ifdef __cplusplus
}
#endif

#endif /* SWMM_OUTPUT_H_ */
Loading

0 comments on commit ce668c6

Please sign in to comment.