Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add postgresql wrapper #31

Merged
merged 1 commit into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions wrapper/Postgresql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Wrapper of IF97 for postgreSQL
================================================

This wrapper will provide Functions in postgreSQL that provide thermodynamic and transport properties for water/steam at specified state points based on the IAPWS Industrial Formulation for the Properties of Water and Steam.

This wrapper been developed and tested on postgreSQL 9 and 10

------

To Use
======

* Build the wrapper as a shared lib

* Install .so file into the postgres external module directory (given by pg_config --pkglibdir)

* run the .sql file to notify you postgreSQL database to use the shared lib

* use provided function : if97_hmass_Tp() and if97_Tsat97() as SQL functions

------

To Build
========

Follow the build procedures below to create the IF97 module for postgreSQL.

Pre-Requisites
--------------

* You will need to have postgreSQL *server* installed
* You will need g++

Download the IF97 Repository
----------------------------

* Open a Git window at the drive location where you want to create your local IF97 repository

* Clone the CoolProp/IF97 repository to a local repository (If you haven't already cloned it recursively with CoolProp).::

git clone https://github.com/CoolProp/IF97

* Change directory (cd) to the IF97 directory you just created.::

cd IF97

Build and Install
-----------------------------

* Go to the wrapper/Postgresql directory run `build.sh`

* Connect to your postgreSQL server with your favorite client and execute if97.sql commands
4 changes: 4 additions & 0 deletions wrapper/Postgresql/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
g++ -c -fPIC -Wall -Werror -g3 -O0 -I`pg_config --includedir-server` -I`pg_config --includedir-server`/utils if97.c
g++ -shared -o if97.so if97.o
mkdir -p `pg_config --pkglibdir`/if97
cp ./if97.so `pg_config --pkglibdir`/if97
36 changes: 36 additions & 0 deletions wrapper/Postgresql/if97.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Filename: if97.c
*/

extern "C" {
#include <postgres.h>
#include <fmgr.h>
#include <utils/elog.h>
PG_MODULE_MAGIC;
}

#include "../../IF97.h"

extern "C" {
// double hmass(double T, double p)
PG_FUNCTION_INFO_V1(if97_hmass_Tp);
Datum if97_hmass_Tp(PG_FUNCTION_ARGS) {
try {
PG_RETURN_FLOAT8(IF97::hmass_Tp(PG_GETARG_FLOAT8(0),PG_GETARG_FLOAT8(1)));
} catch (const std::exception& e) {
elog(WARNING, "if97: %s",e.what());
PG_RETURN_NULL();
}
}

// double Tsat97(double p)
PG_FUNCTION_INFO_V1(if97_Tsat97);
Datum if97_Tsat97(PG_FUNCTION_ARGS) {
try {
PG_RETURN_FLOAT8(IF97::Tsat97(PG_GETARG_FLOAT8(0)));
} catch (const std::exception& e) {
elog(WARNING, "if97: %s",e.what());
PG_RETURN_NULL();
}
}
}
9 changes: 9 additions & 0 deletions wrapper/Postgresql/if97.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE OR REPLACE FUNCTION
if97_hmass_Tp(FLOAT8, FLOAT8)
RETURNS FLOAT8 AS '$libdir/if97/if97.so', 'if97_hmass_Tp'
LANGUAGE C WITH ( ISSTRICT );

CREATE OR REPLACE FUNCTION
if97_Tsat97(FLOAT8)
RETURNS FLOAT8 AS '$libdir/if97/if97.so', 'if97_Tsat97'
LANGUAGE C WITH ( ISSTRICT );