mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-23 03:00:17 -04:00
Merge pull request #546 from JonWel/master
Small speed enhancement for Julia wrapper
This commit is contained in:
@@ -2,6 +2,9 @@ module CoolProp
|
||||
|
||||
export F2K, K2F, HAPropsSI, PropsSI, PhaseSI, get_global_param_string, get_param_index, get_input_pair_index, AbstractState_factory, AbstractState_free, AbstractState_update, AbstractState_keyed_output
|
||||
|
||||
const buffer_length = 255
|
||||
message_buffer = Array(Uint8, buffer_length)
|
||||
|
||||
function F2K(TF::Number)
|
||||
return ccall( (:F2K, "CoolProp"), Cdouble, (Cdouble,), TF)
|
||||
end
|
||||
@@ -35,16 +38,14 @@ function PropsSI(FluidName::String, Output::String)
|
||||
end
|
||||
|
||||
function PhaseSI(Name1::String, Value1::Number, Name2::String, Value2::Number, Fluid::String)
|
||||
outstring = Array(Uint8, 255)
|
||||
val = ccall( (:PhaseSI, "CoolProp"), Int32, (Ptr{Uint8},Float64,Ptr{Uint8},Float64,Ptr{Uint8}, Ptr{Uint8}, Int), Name1,Value1,Name2,Value2,Fluid,outstring,length(outstring))
|
||||
return bytestring(convert(Ptr{Uint8}, pointer(outstring)))
|
||||
val = ccall( (:PhaseSI, "CoolProp"), Int32, (Ptr{Uint8},Float64,Ptr{Uint8},Float64,Ptr{Uint8}, Ptr{Uint8}, Int), Name1,Value1,Name2,Value2,Fluid,message_buffer::Array{Uint8,1},buffer_length)
|
||||
return bytestring(convert(Ptr{Uint8}, pointer(message_buffer::Array{Uint8,1})))
|
||||
end
|
||||
|
||||
# This function returns the output string in pre-allocated char buffer. If buffer is not large enough, no copy is made
|
||||
function get_global_param_string(Key::String)
|
||||
Outstring = Array(Uint8, 255)
|
||||
val = ccall( (:get_global_param_string, "CoolProp"), Clong, (Ptr{Uint8},Ptr{Uint8},Int), Key,Outstring,length(Outstring))
|
||||
return bytestring(convert(Ptr{Uint8}, pointer(Outstring)))
|
||||
val = ccall( (:get_global_param_string, "CoolProp"), Clong, (Ptr{Uint8},Ptr{Uint8},Int), Key,message_buffer::Array{Uint8,1},buffer_length)
|
||||
return bytestring(convert(Ptr{Uint8}, pointer(message_buffer::Array{Uint8,1})))
|
||||
end
|
||||
|
||||
# Get the index for a parameter "T", "P", etc.
|
||||
@@ -72,15 +73,13 @@ end
|
||||
# ---------------------------------
|
||||
|
||||
errcode = Array(Clong, 1)
|
||||
buffer_length = 255
|
||||
message_buffer = Array(Uint8, buffer_length)
|
||||
|
||||
# Generate an AbstractState instance, return an integer handle to the state class generated to be used in the other low-level accessor functions
|
||||
# param backend The backend you will use, "HEOS", "REFPROP", etc.
|
||||
# param fluids '&' delimited list of fluids
|
||||
# return A handle to the state class generated
|
||||
function AbstractState_factory(backend::String, fluids::String)
|
||||
AbstractState = ccall( (:AbstractState_factory, "CoolProp"), Clong, (Ptr{Uint8},Ptr{Uint8},Ptr{Clong},Ptr{Uint8},Clong), backend,fluids,errcode,message_buffer,buffer_length)
|
||||
AbstractState = ccall( (:AbstractState_factory, "CoolProp"), Clong, (Ptr{Uint8},Ptr{Uint8},Ptr{Clong},Ptr{Uint8},Clong), backend,fluids,errcode::Array{Clong,1},message_buffer::Array{Uint8,1},buffer_length)
|
||||
if errcode[] != 0
|
||||
if errcode[] == 1
|
||||
error("CoolProp: ", bytestring(convert(Ptr{Uint8}, pointer(message_buffer))))
|
||||
@@ -96,7 +95,7 @@ end
|
||||
# Release a state class generated by the low-level interface wrapper
|
||||
# param handle The integer handle for the state class stored in memory
|
||||
function AbstractState_free(handle::Clong)
|
||||
ccall( (:AbstractState_free, "CoolProp"), Void, (Clong,Ptr{Clong},Ptr{Uint8},Clong), handle,errcode,message_buffer,buffer_length)
|
||||
ccall( (:AbstractState_free, "CoolProp"), Void, (Clong,Ptr{Clong},Ptr{Uint8},Clong), handle,errcode::Array{Clong,1},message_buffer::Array{Uint8,1},buffer_length)
|
||||
if errcode[] != 0
|
||||
if errcode[] == 1
|
||||
error("CoolProp: ", bytestring(convert(Ptr{Uint8}, pointer(message_buffer))))
|
||||
@@ -113,7 +112,7 @@ end
|
||||
# param handle The integer handle for the state class stored in memory
|
||||
# param fractions The array of fractions
|
||||
function AbstractState_set_fractions(handle::Clong,fractions::Array)
|
||||
ccall( (:AbstractState_set_fractions, "CoolProp"), Void, (Clong,Ptr{Cdouble},Clong,Ptr{Clong},Ptr{Uint8},Clong), handle,fractions,length(fractions),errcode,message_buffer,buffer_length)
|
||||
ccall( (:AbstractState_set_fractions, "CoolProp"), Void, (Clong,Ptr{Cdouble},Clong,Ptr{Clong},Ptr{Uint8},Clong), handle,fractions,length(fractions),errcode::Array{Clong,1},message_buffer::Array{Uint8,1},buffer_length)
|
||||
if errcode[] != 0
|
||||
if errcode[] == 1
|
||||
error("CoolProp: ", bytestring(convert(Ptr{Uint8}, pointer(message_buffer))))
|
||||
@@ -132,7 +131,7 @@ end
|
||||
# param value1 The first input value
|
||||
# param value2 The second input value
|
||||
function AbstractState_update(handle::Clong,input_pair::Clong,value1::Number,value2::Number)
|
||||
ccall( (:AbstractState_update, "CoolProp"), Void, (Clong,Clong,Cdouble,Cdouble,Ptr{Clong},Ptr{Uint8},Clong), handle,input_pair,value1,value2,errcode,message_buffer,buffer_length)
|
||||
ccall( (:AbstractState_update, "CoolProp"), Void, (Clong,Clong,Cdouble,Cdouble,Ptr{Clong},Ptr{Uint8},Clong), handle,input_pair,value1,value2,errcode::Array{Clong,1},message_buffer::Array{Uint8,1},buffer_length)
|
||||
if errcode[] != 0
|
||||
if errcode[] == 1
|
||||
error("CoolProp: ", bytestring(convert(Ptr{Uint8}, pointer(message_buffer))))
|
||||
@@ -149,7 +148,7 @@ end
|
||||
# param handle The integer handle for the state class stored in memory
|
||||
# param param The integer value for the parameter you want
|
||||
function AbstractState_keyed_output(handle::Clong, param::Clong)
|
||||
output = ccall( (:AbstractState_keyed_output, "CoolProp"), Cdouble, (Clong,Clong,Ptr{Clong},Ptr{Uint8},Clong), handle,param,errcode,message_buffer,buffer_length)
|
||||
output = ccall( (:AbstractState_keyed_output, "CoolProp"), Cdouble, (Clong,Clong,Ptr{Clong},Ptr{Uint8},Clong), handle,param,errcode::Array{Clong,1},message_buffer::Array{Uint8,1},buffer_length)
|
||||
if errcode[] != 0
|
||||
if errcode[] == 1
|
||||
error("CoolProp: ", bytestring(convert(Ptr{Uint8}, pointer(message_buffer))))
|
||||
|
||||
@@ -2,6 +2,9 @@ module CoolProp
|
||||
|
||||
export F2K, K2F, HAPropsSI, PropsSI, PhaseSI, get_global_param_string, get_param_index, get_input_pair_index, AbstractState_factory, AbstractState_free, AbstractState_update, AbstractState_keyed_output
|
||||
|
||||
const buffer_length = 255
|
||||
message_buffer = Array(UInt8, buffer_length)
|
||||
|
||||
function F2K(TF::Number)
|
||||
return ccall( (:F2K, "CoolProp"), Cdouble, (Cdouble,), TF)
|
||||
end
|
||||
@@ -35,18 +38,14 @@ function PropsSI(FluidName::String, Output::String)
|
||||
end
|
||||
|
||||
function PhaseSI(Name1::String, Value1::Number, Name2::String, Value2::Number, Fluid::String)
|
||||
len = 255
|
||||
outstring = Array(UInt8, len)
|
||||
val = ccall( (:PhaseSI, "CoolProp"), Int32, (Ptr{UInt8},Float64,Ptr{UInt8},Float64,Ptr{UInt8}, Ptr{UInt8}, Int), Name1,Value1,Name2,Value2,Fluid,outstring,len)
|
||||
return bytestring(convert(Ptr{UInt8}, pointer(outstring)))
|
||||
val = ccall( (:PhaseSI, "CoolProp"), Int32, (Ptr{UInt8},Float64,Ptr{UInt8},Float64,Ptr{UInt8}, Ptr{UInt8}, Int), Name1,Value1,Name2,Value2,Fluid,message_buffer::Array{Uint8,1},buffer_length)
|
||||
return bytestring(convert(Ptr{UInt8}, pointer(message_buffer::Array{Uint8,1})))
|
||||
end
|
||||
|
||||
# This function returns the output string in pre-allocated char buffer. If buffer is not large enough, no copy is made
|
||||
function get_global_param_string(Key::String)
|
||||
len = 255
|
||||
Outstring = Array(UInt8, len)
|
||||
val = ccall( (:get_global_param_string, "CoolProp"), Clong, (Ptr{UInt8},Ptr{UInt8},Int), Key,Outstring,len)
|
||||
return bytestring(convert(Ptr{UInt8}, pointer(Outstring)))
|
||||
val = ccall( (:get_global_param_string, "CoolProp"), Clong, (Ptr{UInt8},Ptr{UInt8},Int), Key,message_buffer::Array{Uint8,1},buffer_length)
|
||||
return bytestring(convert(Ptr{UInt8}, pointer(message_buffer::Array{Uint8,1})))
|
||||
end
|
||||
|
||||
# Get the index for a parameter "T", "P", etc.
|
||||
@@ -74,15 +73,13 @@ end
|
||||
# ---------------------------------
|
||||
|
||||
errcode = Ref{Clong}(0)
|
||||
const buffer_length = 255
|
||||
message_buffer = Array(UInt8, buffer_length)
|
||||
|
||||
# Generate an AbstractState instance, return an integer handle to the state class generated to be used in the other low-level accessor functions
|
||||
# param backend The backend you will use, "HEOS", "REFPROP", etc.
|
||||
# param fluids '&' delimited list of fluids
|
||||
# return A handle to the state class generated
|
||||
function AbstractState_factory(backend::String, fluids::String)
|
||||
AbstractState = ccall( (:AbstractState_factory, "CoolProp"), Clong, (Ptr{UInt8},Ptr{UInt8},Ref{Clong},Ptr{UInt8},Clong), backend,fluids,errcode,message_buffer::Array{Uint8,1},buffer_length)
|
||||
AbstractState = ccall( (:AbstractState_factory, "CoolProp"), Clong, (Ptr{UInt8},Ptr{UInt8},Ref{Clong},Ptr{UInt8},Clong), backend,fluids,errcode::Base.RefValue{Clong},message_buffer::Array{Uint8,1},buffer_length)
|
||||
if errcode[] != 0
|
||||
if errcode[] == 1
|
||||
error("CoolProp: ", bytestring(convert(Ptr{UInt8}, pointer(message_buffer))))
|
||||
@@ -98,7 +95,7 @@ end
|
||||
# Release a state class generated by the low-level interface wrapper
|
||||
# param handle The integer handle for the state class stored in memory
|
||||
function AbstractState_free(handle::Clong)
|
||||
ccall( (:AbstractState_free, "CoolProp"), Void, (Clong,Ref{Clong},Ptr{UInt8},Clong), handle,errcode,message_buffer::Array{Uint8,1},buffer_length)
|
||||
ccall( (:AbstractState_free, "CoolProp"), Void, (Clong,Ref{Clong},Ptr{UInt8},Clong), handle,errcode::Base.RefValue{Clong},message_buffer::Array{Uint8,1},buffer_length)
|
||||
if errcode[] != 0
|
||||
if errcode[] == 1
|
||||
error("CoolProp: ", bytestring(convert(Ptr{UInt8}, pointer(message_buffer))))
|
||||
@@ -115,7 +112,7 @@ end
|
||||
# param handle The integer handle for the state class stored in memory
|
||||
# param fractions The array of fractions
|
||||
function AbstractState_set_fractions(handle::Clong,fractions::Array)
|
||||
ccall( (:AbstractState_set_fractions, "CoolProp"), Void, (Clong,Ptr{Cdouble},Clong,Ref{Clong},Ptr{UInt8},Clong), handle,fractions,length(fractions),errcode,message_buffer::Array{Uint8,1},buffer_length)
|
||||
ccall( (:AbstractState_set_fractions, "CoolProp"), Void, (Clong,Ptr{Cdouble},Clong,Ref{Clong},Ptr{UInt8},Clong), handle,fractions,length(fractions),errcode::Base.RefValue{Clong},message_buffer::Array{Uint8,1},buffer_length)
|
||||
if errcode[] != 0
|
||||
if errcode[] == 1
|
||||
error("CoolProp: ", bytestring(convert(Ptr{UInt8}, pointer(message_buffer))))
|
||||
@@ -134,7 +131,7 @@ end
|
||||
# param value1 The first input value
|
||||
# param value2 The second input value
|
||||
function AbstractState_update(handle::Clong,input_pair::Clong,value1::Number,value2::Number)
|
||||
ccall( (:AbstractState_update, "CoolProp"), Void, (Clong,Clong,Cdouble,Cdouble,Ref{Clong},Ptr{UInt8},Clong), handle,input_pair,value1,value2,errcode,message_buffer::Array{Uint8,1},buffer_length)
|
||||
ccall( (:AbstractState_update, "CoolProp"), Void, (Clong,Clong,Cdouble,Cdouble,Ref{Clong},Ptr{UInt8},Clong), handle,input_pair,value1,value2,errcode::Base.RefValue{Clong},message_buffer::Array{Uint8,1},buffer_length)
|
||||
if errcode[] != 0
|
||||
if errcode[] == 1
|
||||
error("CoolProp: ", bytestring(convert(Ptr{UInt8}, pointer(message_buffer))))
|
||||
@@ -151,7 +148,7 @@ end
|
||||
# param handle The integer handle for the state class stored in memory
|
||||
# param param The integer value for the parameter you want
|
||||
function AbstractState_keyed_output(handle::Clong, param::Clong)
|
||||
output = ccall( (:AbstractState_keyed_output, "CoolProp"), Cdouble, (Clong,Clong,Ref{Clong},Ptr{UInt8},Clong), handle,param,errcode,message_buffer::Array{Uint8,1},buffer_length)
|
||||
output = ccall( (:AbstractState_keyed_output, "CoolProp"), Cdouble, (Clong,Clong,Ref{Clong},Ptr{UInt8},Clong), handle,param,errcode::Base.RefValue{Clong},message_buffer::Array{Uint8,1},buffer_length)
|
||||
if errcode[] != 0
|
||||
if errcode[] == 1
|
||||
error("CoolProp: ", bytestring(convert(Ptr{UInt8}, pointer(message_buffer))))
|
||||
|
||||
Reference in New Issue
Block a user