mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Updated ERT to 315ceeee250808ea6a6530233dd5125f9f76f06c
Support of reading LGR dimensions Close file handles between access to files, keep ERT file-related cache to speed up reading of many files multiple times p4#: 21477
This commit is contained in:
parent
fad4761bc4
commit
ca856f7603
@ -308,14 +308,27 @@ void RifEclipseOutputFileTools::findKeywordsAndDataItemCounts(ecl_file_type* ecl
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifEclipseOutputFileTools::readGridDimensions(const QString& gridFileName, std::vector< std::vector<int> >& gridDimensions)
|
||||
{
|
||||
int gridDims[3];
|
||||
ecl_grid_type * grid = ecl_grid_alloc(gridFileName.toAscii().data()); // bootstrap ecl_grid instance
|
||||
stringlist_type * lgr_names = ecl_grid_alloc_lgr_name_list( grid ); // get a list of all the lgr names.
|
||||
|
||||
bool ret = ecl_grid_file_dims(gridFileName.toAscii().data(), NULL, gridDims);
|
||||
if (ret)
|
||||
//printf("grid:%s has %d a total of %d lgr's \n", grid_filename , stringlist_get_size( lgr_names ));
|
||||
for (int lgr_nr = 0; lgr_nr < stringlist_get_size( lgr_names); lgr_nr++)
|
||||
{
|
||||
gridDimensions.resize(1);
|
||||
gridDimensions[0].push_back(gridDims[0]);
|
||||
gridDimensions[0].push_back(gridDims[1]);
|
||||
gridDimensions[0].push_back(gridDims[2]);
|
||||
ecl_grid_type * lgr_grid = ecl_grid_get_lgr( grid , stringlist_iget( lgr_names , lgr_nr )); // get the ecl_grid instance of the lgr - by name.
|
||||
|
||||
int nx,ny,nz,active_size;
|
||||
ecl_grid_get_dims( lgr_grid , &nx , &ny , &nz , &active_size); // get some size info from this lgr.
|
||||
|
||||
std::vector<int> values;
|
||||
values.push_back(nx);
|
||||
values.push_back(ny);
|
||||
values.push_back(nz);
|
||||
values.push_back(active_size);
|
||||
|
||||
gridDimensions.push_back(values);
|
||||
}
|
||||
|
||||
ecl_grid_free( grid );
|
||||
stringlist_free( lgr_names );
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,17 @@ RifEclipseRestartFilesetAccess::RifEclipseRestartFilesetAccess()
|
||||
RifEclipseRestartFilesetAccess::~RifEclipseRestartFilesetAccess()
|
||||
{
|
||||
close();
|
||||
|
||||
for (size_t i = 0; i < m_ecl_files.size(); i++)
|
||||
{
|
||||
if (m_ecl_files[i])
|
||||
{
|
||||
ecl_file_close(m_ecl_files[i]);
|
||||
}
|
||||
|
||||
m_ecl_files[i] = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -84,15 +95,6 @@ void RifEclipseRestartFilesetAccess::setRestartFiles(const QStringList& fileSet)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifEclipseRestartFilesetAccess::close()
|
||||
{
|
||||
for (size_t i = 0; i < m_ecl_files.size(); i++)
|
||||
{
|
||||
if (m_ecl_files[i])
|
||||
{
|
||||
ecl_file_close(m_ecl_files[i]);
|
||||
}
|
||||
|
||||
m_ecl_files[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -232,7 +234,7 @@ void RifEclipseRestartFilesetAccess::openTimeStep(size_t timeStep)
|
||||
if (m_ecl_files[timeStep] == NULL)
|
||||
{
|
||||
int index = static_cast<int>(timeStep);
|
||||
ecl_file_type* ecl_file = ecl_file_open(m_fileNames[index].toAscii().data());
|
||||
ecl_file_type* ecl_file = ecl_file_open(m_fileNames[index].toAscii().data(), ECL_FILE_CLOSE_STREAM);
|
||||
|
||||
m_ecl_files[timeStep] = ecl_file;
|
||||
}
|
||||
|
@ -38,7 +38,10 @@ RifEclipseUnifiedRestartFileAccess::RifEclipseUnifiedRestartFileAccess()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifEclipseUnifiedRestartFileAccess::~RifEclipseUnifiedRestartFileAccess()
|
||||
{
|
||||
close();
|
||||
if (m_ecl_file)
|
||||
{
|
||||
ecl_file_close(m_ecl_file);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -56,7 +59,7 @@ bool RifEclipseUnifiedRestartFileAccess::openFile()
|
||||
{
|
||||
if (!m_ecl_file)
|
||||
{
|
||||
m_ecl_file = ecl_file_open(m_filename.toAscii().data());
|
||||
m_ecl_file = ecl_file_open(m_filename.toAscii().data(), ECL_FILE_CLOSE_STREAM);
|
||||
}
|
||||
|
||||
if (!m_ecl_file) return false;
|
||||
@ -69,12 +72,6 @@ bool RifEclipseUnifiedRestartFileAccess::openFile()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifEclipseUnifiedRestartFileAccess::close()
|
||||
{
|
||||
if (m_ecl_file)
|
||||
{
|
||||
ecl_file_close(m_ecl_file);
|
||||
}
|
||||
|
||||
m_ecl_file = NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -208,14 +208,7 @@ RifReaderEclipseOutput::RifReaderEclipseOutput()
|
||||
RifReaderEclipseOutput::~RifReaderEclipseOutput()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Close interface (for now, no files are kept open after calling methods, so just clear members)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifReaderEclipseOutput::close()
|
||||
{
|
||||
if (m_ecl_init_file)
|
||||
{
|
||||
ecl_file_close(m_ecl_init_file);
|
||||
@ -226,6 +219,15 @@ void RifReaderEclipseOutput::close()
|
||||
{
|
||||
m_dynamicResultsAccess->close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Close interface (for now, no files are kept open after calling methods, so just clear members)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifReaderEclipseOutput::close()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -442,7 +444,7 @@ bool RifReaderEclipseOutput::readActiveCellInfo()
|
||||
QString egridFileName = RifEclipseOutputFileTools::firstFileNameOfType(m_filesWithSameBaseName, ECL_EGRID_FILE);
|
||||
if (egridFileName.size() > 0)
|
||||
{
|
||||
ecl_file_type* ecl_file = ecl_file_open(egridFileName.toAscii().data());
|
||||
ecl_file_type* ecl_file = ecl_file_open(egridFileName.toAscii().data(), ECL_FILE_CLOSE_STREAM);
|
||||
if (!ecl_file) return false;
|
||||
|
||||
int actnumKeywordCount = ecl_file_get_num_named_kw(ecl_file, ACTNUM_KW);
|
||||
@ -1010,7 +1012,7 @@ void RifReaderEclipseOutput::openInitFile()
|
||||
QString initFileName = RifEclipseOutputFileTools::firstFileNameOfType(m_filesWithSameBaseName, ECL_INIT_FILE);
|
||||
if (initFileName.size() > 0)
|
||||
{
|
||||
m_ecl_init_file = ecl_file_open(initFileName.toAscii().data());
|
||||
m_ecl_init_file = ecl_file_open(initFileName.toAscii().data(), ECL_FILE_CLOSE_STREAM);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,12 +108,15 @@ bool RigGridManager::isGridDimensionsEqual(const std::vector< std::vector<int> >
|
||||
|
||||
for (size_t j = 0; j < mainCaseGridDimensions.size(); j++)
|
||||
{
|
||||
if (mainCaseGridDimensions[j].size() != 3) return false;
|
||||
if (caseGridDimensions[j].size() != 3) return false;
|
||||
if (mainCaseGridDimensions[j].size() != 4) return false;
|
||||
if (caseGridDimensions[j].size() != 4) return false;
|
||||
|
||||
if (mainCaseGridDimensions[j][0] != caseGridDimensions[j][0]) return false; // nx
|
||||
if (mainCaseGridDimensions[j][1] != caseGridDimensions[j][1]) return false; // ny
|
||||
if (mainCaseGridDimensions[j][2] != caseGridDimensions[j][2]) return false; // nz
|
||||
|
||||
if (mainCaseGridDimensions[j][3] != caseGridDimensions[j][3]) return false; // active_cells
|
||||
|
||||
if (mainCaseGridDimensions[j][0] != caseGridDimensions[j][0]) return false;
|
||||
if (mainCaseGridDimensions[j][1] != caseGridDimensions[j][1]) return false;
|
||||
if (mainCaseGridDimensions[j][2] != caseGridDimensions[j][2]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
19
ThirdParty/Ert/devel/CMakeLists.txt
vendored
19
ThirdParty/Ert/devel/CMakeLists.txt
vendored
@ -19,20 +19,17 @@ ENABLE_TESTING()
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set(ERT_LINUX TRUE )
|
||||
add_definitions( -DERT_LINUX )
|
||||
set( CMAKE_C_FLAGS "-g -O2 -Wall -std=gnu99" )
|
||||
set( CMAKE_CXX_FLAGS "-g -O2 -Wall" )
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
set(ERT_WINDOWS TRUE)
|
||||
add_definitions( -DERT_WINDOWS )
|
||||
set( CMAKE_C_FLAGS "-O2" )
|
||||
set( CMAKE_CXX_FLAGS "-O2" )
|
||||
endif()
|
||||
|
||||
set( CMAKE_C_FLAGS "-g -O2 -Wall -std=gnu99" )
|
||||
set( CMAKE_CXX_FLAGS "-g -O2 -Wall" )
|
||||
|
||||
include(cmake/ert_check.cmake)
|
||||
include(cmake/ert_find.cmake)
|
||||
include(cmake/Modules/UseMultiArch.cmake)
|
||||
include(cmake/python.cmake)
|
||||
|
||||
set( INSTALL_GROUP "" CACHE STRING "Group to install as - blank to install as current group")
|
||||
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
@ -42,14 +39,9 @@ if (MSVC)
|
||||
set( LIBRARY_TYPE STATIC )
|
||||
set( SHARED_LIB OFF )
|
||||
else()
|
||||
if (INSTALL_ERT)
|
||||
set( LIBRARY_TYPE SHARED )
|
||||
set( SHARED_LIB ON )
|
||||
else()
|
||||
set( LIBRARY_TYPE STATIC )
|
||||
set( SHARED_LIB OFF )
|
||||
endif(INSTALL_ERT)
|
||||
endif(MSVC)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
@ -62,8 +54,8 @@ endif()
|
||||
if (ERT_LINUX)
|
||||
set( NEED_LIBM TRUE )
|
||||
set( LINK_STATIC FALSE )
|
||||
add_definitions( -DHAVE_PROC )
|
||||
set( NEED_LIBDL ON )
|
||||
add_definitions( -DHAVE_PROC )
|
||||
else()
|
||||
set( NEED_LIBM FALSE )
|
||||
set( LINK_STATIC TRUE )
|
||||
@ -119,10 +111,13 @@ if (BUILD_ERT)
|
||||
|
||||
include_directories( ${PROJECT_SOURCE_DIR}/libenkf/include )
|
||||
add_subdirectory( libenkf )
|
||||
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/share DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
endif()
|
||||
|
||||
|
||||
if (BUILD_PYTHON)
|
||||
include(cmake/python.cmake2)
|
||||
add_subdirectory( python )
|
||||
endif()
|
||||
|
||||
|
27
ThirdParty/Ert/devel/cmake/cmake_pyc2
vendored
Normal file
27
ThirdParty/Ert/devel/cmake/cmake_pyc2
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
import py_compile
|
||||
import os
|
||||
import os.path
|
||||
import sys
|
||||
import shutil
|
||||
|
||||
|
||||
src_file = sys.argv[1]
|
||||
target_file = sys.argv[2]
|
||||
|
||||
(target_path , tail) = os.path.split( target_file )
|
||||
if not os.path.exists( target_path ):
|
||||
os.makedirs( target_path )
|
||||
|
||||
shutil.copyfile( src_file , target_file )
|
||||
try:
|
||||
py_compile.compile( target_file , doraise = True)
|
||||
except Exception,error:
|
||||
sys.exit("py_compile(%s) failed:%s" % (target_file , error))
|
||||
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
|
20
ThirdParty/Ert/devel/cmake/cmake_pyc_file
vendored
Normal file
20
ThirdParty/Ert/devel/cmake/cmake_pyc_file
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
import py_compile
|
||||
import os
|
||||
import sys
|
||||
import os.path
|
||||
|
||||
# Small 'python compiler' used in the build system for ert.
|
||||
|
||||
for file in sys.argv[1:]:
|
||||
try:
|
||||
py_compile.compile( file , doraise = True )
|
||||
except Exception,error:
|
||||
sys.exit("py_compile(%s) failed:%s" % (file , error))
|
||||
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
|
31
ThirdParty/Ert/devel/cmake/cmake_pyc_tree
vendored
Normal file
31
ThirdParty/Ert/devel/cmake/cmake_pyc_tree
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python
|
||||
import py_compile
|
||||
import os
|
||||
import sys
|
||||
import os.path
|
||||
|
||||
# Small 'python compiler' used in the build system for ert. The
|
||||
# commandline argument should be the top level name of directory
|
||||
# containing python source code. The 'compiler' will walk through the
|
||||
# tree and in-place compile all the python files.
|
||||
|
||||
|
||||
root_path = sys.argv[1]
|
||||
for (root , dir_list , file_list) in os.walk( root_path ):
|
||||
for file in file_list:
|
||||
full_path = os.path.join( root , file )
|
||||
(tmp , ext) = os.path.splitext( full_path )
|
||||
if ext == ".py":
|
||||
py_file = full_path
|
||||
try:
|
||||
print "Compiling: %s" % py_file
|
||||
py_compile.compile( py_file , doraise = True )
|
||||
except Exception,error:
|
||||
sys.exit("py_compile(%s) failed:%s" % (py_file , error))
|
||||
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
|
19
ThirdParty/Ert/devel/cmake/python.cmake
vendored
19
ThirdParty/Ert/devel/cmake/python.cmake
vendored
@ -1,6 +1,6 @@
|
||||
macro(add_python_target tgt PYTHON_INSTALL_PATH ARGN)
|
||||
macro(add_python_target tgt PYTHON_INSTALL_PATH)
|
||||
SET(OUT_FILES "")
|
||||
foreach(file ${ARGN})
|
||||
foreach(file ${python_source_files})
|
||||
set(OUT ${CMAKE_CURRENT_BINARY_DIR}/${file}.pyc)
|
||||
list(APPEND OUT_FILES ${OUT})
|
||||
#------------------------------------------------------
|
||||
@ -8,15 +8,18 @@ macro(add_python_target tgt PYTHON_INSTALL_PATH ARGN)
|
||||
OUTPUT ${OUT}
|
||||
COMMAND ${PROJECT_SOURCE_DIR}/cmake/cmake_pyc
|
||||
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PATH}
|
||||
)
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.py)
|
||||
#------------------------------------------------------
|
||||
if (INSTALL_ERT)
|
||||
install(FILES ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PATH}/${file}.pyc DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PATH})
|
||||
install(FILES ${PROJECT_BINARY_DIR}/${PYTHON}/${file}.pyc DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PATH})
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${file}.py DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PATH})
|
||||
endif()
|
||||
endforeach(file)
|
||||
list(REMOVE_DUPLICATES OUT_FILES)
|
||||
ADD_CUSTOM_TARGET(
|
||||
${tgt} ALL
|
||||
DEPENDS ${OUT_FILES})
|
||||
list(REMOVE_DUPLICATES OUT_FILES)
|
||||
|
||||
ADD_CUSTOM_TARGET(
|
||||
${tgt} ALL DEPENDS ${OUT_FILES})
|
||||
|
||||
endmacro()
|
||||
|
||||
|
||||
|
26
ThirdParty/Ert/devel/cmake/python.cmake2
vendored
Normal file
26
ThirdParty/Ert/devel/cmake/python.cmake2
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
function(add_python_package target package_path source_files install_package)
|
||||
|
||||
set(build_files "")
|
||||
|
||||
foreach (file ${source_files} )
|
||||
set( source_file ${CMAKE_CURRENT_SOURCE_DIR}/${file} )
|
||||
set( build_file ${PROJECT_BINARY_DIR}/${package_path}/${file} )
|
||||
set( install_file ${CMAKE_INSTALL_PREFIX}/${package_path}/${file} )
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${build_file}
|
||||
COMMAND ${PROJECT_SOURCE_DIR}/cmake/cmake_pyc2
|
||||
ARGS ${source_file} ${build_file}
|
||||
DEPENDS ${source_file} )
|
||||
|
||||
list(APPEND build_files ${build_file} )
|
||||
|
||||
if (install_package)
|
||||
install(FILES ${build_file} DESTINATION ${CMAKE_INSTALL_PREFIX}/${package_path})
|
||||
install(CODE "execute_process(COMMAND ${PROJECT_SOURCE_DIR}/cmake/cmake_pyc_file ${install_file})")
|
||||
endif()
|
||||
|
||||
endforeach()
|
||||
add_custom_target( ${target} ALL DEPENDS ${build_files})
|
||||
|
||||
endfunction()
|
12
ThirdParty/Ert/devel/debian/changelog
vendored
12
ThirdParty/Ert/devel/debian/changelog
vendored
@ -1,10 +1,16 @@
|
||||
libert.ecl (1.0-2) precise; urgency=low
|
||||
ert.ecl (1.0-4) precise; urgency=low
|
||||
|
||||
* Unmark -dev package as architecture independent due to library symlink
|
||||
|
||||
-- Arne Morten Kvarving <arne.morten.kvarving@sintef.no> Wed, 03 Apr 2013 17:49:24 +0200
|
||||
|
||||
ert.ecl (1.0-2) precise; urgency=low
|
||||
|
||||
* Mark -dev package as architecture independent
|
||||
|
||||
-- Arne Morten Kvarving <akva@SINTEFPC4169> Tue, 19 Feb 2013 10:03:04 +0100
|
||||
-- Arne Morten Kvarving <arne.morten.kvarving@sintef.no> Tue, 19 Feb 2013 10:03:04 +0100
|
||||
|
||||
libert.ecl (1.0-1) unstable; urgency=low
|
||||
ert.ecl (1.0-1) unstable; urgency=low
|
||||
|
||||
* Initial release
|
||||
|
||||
|
7
ThirdParty/Ert/devel/debian/control
vendored
7
ThirdParty/Ert/devel/debian/control
vendored
@ -1,7 +1,8 @@
|
||||
Source: libert.ecl
|
||||
Source: ert.ecl
|
||||
Priority: extra
|
||||
Maintainer: Arne Morten Kvarving <arne.morten.kvarving@sintef.no>
|
||||
Build-Depends: debhelper (>= 8.0.0), cmake, liblapack-dev, libquadmath0
|
||||
Build-Depends: debhelper (>= 8.0.0), cmake, liblapack-dev, libquadmath0,
|
||||
iputils-ping, zlib1g-dev
|
||||
Standards-Version: 3.9.2
|
||||
Section: libs
|
||||
Homepage: http://ert.nr.no
|
||||
@ -10,7 +11,7 @@ Vcs-Browser: https://github.com/Ensembles/ert
|
||||
|
||||
Package: libert.ecl-dev
|
||||
Section: libdevel
|
||||
Architecture: all
|
||||
Architecture: any
|
||||
Depends: libert.ecl1 (= ${binary:Version})
|
||||
Description: The Ensemble based Reservoir Tool -- Development files
|
||||
ERT - Ensemble based Reservoir Tool is a tool for managing en ensemble
|
||||
|
@ -30,10 +30,7 @@ void install_SIGNALS(void) {
|
||||
|
||||
|
||||
int test_ecl_file_save() {
|
||||
ecl_file_type * ecl_file = ecl_file_open_writable( "/tmp/ECLIPSE.UNRST" );
|
||||
ecl_kw_type * swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 );
|
||||
ecl_file_save_kw( ecl_file , swat );
|
||||
ecl_file_close( ecl_file );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,7 +55,9 @@ int main(int argc, char ** argv) {
|
||||
bool fmt_src , fmt_target;
|
||||
set_type * kw_set = set_alloc( num_kw , kw_list );
|
||||
|
||||
fmt_src = ecl_util_fmt_file(src_file);
|
||||
if (!ecl_util_fmt_file(src_file, &fmt_src))
|
||||
util_exit("Hmm - could not determine formatted/unformatted status for:%s \n",src_file);
|
||||
|
||||
fmt_target = fmt_src; /* Can in principle be different */
|
||||
fortio_src = fortio_open_reader(src_file , fmt_src , ECL_ENDIAN_FLIP);
|
||||
fortio_target = fortio_open_writer(target_file , fmt_target , ECL_ENDIAN_FLIP);
|
||||
|
@ -29,18 +29,21 @@
|
||||
|
||||
void kw_list(const char *filename) {
|
||||
fortio_type *fortio;
|
||||
bool fmt_file = ecl_util_fmt_file(filename);
|
||||
ecl_kw_type * ecl_kw = ecl_kw_alloc_empty();
|
||||
bool fmt_file;
|
||||
if (ecl_util_fmt_file(filename , &fmt_file)) {
|
||||
|
||||
printf("-----------------------------------------------------------------\n");
|
||||
printf("%s: \n",filename);
|
||||
fortio = fortio_open_reader(filename , fmt_file , ECL_ENDIAN_FLIP);
|
||||
while( ecl_kw_fread_realloc(ecl_kw , fortio) )
|
||||
ecl_kw_summarize(ecl_kw);
|
||||
printf("-----------------------------------------------------------------\n");
|
||||
printf("-----------------------------------------------------------------\n");
|
||||
printf("%s: \n",filename);
|
||||
fortio = fortio_open_reader(filename , fmt_file , ECL_ENDIAN_FLIP);
|
||||
while( ecl_kw_fread_realloc(ecl_kw , fortio) )
|
||||
ecl_kw_summarize(ecl_kw);
|
||||
printf("-----------------------------------------------------------------\n");
|
||||
|
||||
ecl_kw_free(ecl_kw);
|
||||
fortio_fclose(fortio);
|
||||
ecl_kw_free(ecl_kw);
|
||||
fortio_fclose(fortio);
|
||||
} else
|
||||
fprintf(stderr,"Could not determine formatted/unformatted status of:%s - skipping \n",filename);
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,13 +45,13 @@ void test_case( const char * base , bool load_all) {
|
||||
timer_stop( tg );
|
||||
|
||||
timer_start( ti );
|
||||
init = ecl_file_open( init_file );
|
||||
init = ecl_file_open( init_file , 0);
|
||||
if (load_all)
|
||||
ecl_file_load_all( init );
|
||||
timer_stop( ti );
|
||||
|
||||
timer_start( tr );
|
||||
restart = ecl_file_open( restart_file );
|
||||
restart = ecl_file_open( restart_file , 0);
|
||||
if (load_all)
|
||||
ecl_file_load_all( restart );
|
||||
timer_stop( tr );
|
||||
|
@ -32,14 +32,35 @@ extern "C" {
|
||||
#include <ert/ecl/fortio.h>
|
||||
#include <ert/ecl/ecl_util.h>
|
||||
|
||||
typedef enum {
|
||||
ECL_FILE_CLOSE_STREAM = 1 , /*
|
||||
This flag will close the underlying FILE object between each access; this is
|
||||
mainly to save filedescriptors in cases where many ecl_file instances are open at
|
||||
the same time. */
|
||||
//
|
||||
ECL_FILE_WRITABLE = 2 /*
|
||||
This flag opens the file in a mode where it can be updated and modified, but it
|
||||
must still exist and be readable. I.e. this should not compared with the normal:
|
||||
fopen(filename , "w") where an existing file is truncated to zero upon successfull
|
||||
open.
|
||||
*/
|
||||
} ecl_file_flag_type;
|
||||
|
||||
|
||||
#define ECL_FILE_FLAGS_ENUM_DEFS \
|
||||
{.value = 1 , .name="ECL_FILE_CLOSE_STREAM"}, \
|
||||
{.value = 2 , .name="ECL_FILE_WRITABLE"}
|
||||
#define ECL_FILE_FLAGS_ENUM_SIZE 2
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct ecl_file_struct ecl_file_type;
|
||||
void ecl_file_load_all( ecl_file_type * ecl_file );
|
||||
bool ecl_file_load_all( ecl_file_type * ecl_file );
|
||||
void ecl_file_push_block( ecl_file_type * ecl_file );
|
||||
void ecl_file_pop_block( ecl_file_type * ecl_file );
|
||||
ecl_file_type * ecl_file_open( const char * filename );
|
||||
ecl_file_type * ecl_file_try_open( const char * filename);
|
||||
ecl_file_type * ecl_file_open_writable( const char * filename );
|
||||
ecl_file_type * ecl_file_open( const char * filename , int flags);
|
||||
ecl_file_type * ecl_file_try_open( const char * filename , int flags);
|
||||
void ecl_file_close( ecl_file_type * ecl_file );
|
||||
void ecl_file_fortio_detach( ecl_file_type * ecl_file );
|
||||
void ecl_file_free__(void * arg);
|
||||
@ -60,6 +81,11 @@ extern "C" {
|
||||
int ecl_file_get_phases( const ecl_file_type * init_file );
|
||||
void ecl_file_fprintf_kw_list( const ecl_file_type * ecl_file , FILE * stream );
|
||||
|
||||
bool ecl_file_writable( const ecl_file_type * ecl_file );
|
||||
int ecl_file_get_flags( const ecl_file_type * ecl_file );
|
||||
bool ecl_file_flags_set( const ecl_file_type * ecl_file , int flags);
|
||||
|
||||
|
||||
|
||||
ecl_file_kw_type * ecl_file_iget_file_kw( const ecl_file_type * file , int global_index);
|
||||
ecl_file_kw_type * ecl_file_iget_named_file_kw( const ecl_file_type * file , const char * kw, int ith);
|
||||
@ -75,8 +101,8 @@ extern "C" {
|
||||
bool ecl_file_subselect_block( ecl_file_type * ecl_file , const char * kw , int occurence);
|
||||
bool ecl_file_select_block( ecl_file_type * ecl_file , const char * kw , int occurence);
|
||||
void ecl_file_select_global( ecl_file_type * ecl_file );
|
||||
bool ecl_file_writable( const ecl_file_type * ecl_file );
|
||||
void ecl_file_save_kw( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_kw);
|
||||
//bool ecl_file_writable( const ecl_file_type * ecl_file );
|
||||
bool ecl_file_save_kw( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_kw);
|
||||
bool ecl_file_has_kw_ptr( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_kw);
|
||||
|
||||
/*****************************************************************/
|
||||
@ -92,19 +118,16 @@ extern "C" {
|
||||
bool ecl_file_select_rstblock_report_step( ecl_file_type * ecl_file , int report_step);
|
||||
bool ecl_file_iselect_rstblock( ecl_file_type * ecl_file , int seqnum_index );
|
||||
|
||||
ecl_file_type * ecl_file_open_rstblock_report_step( const char * filename , int report_step );
|
||||
ecl_file_type * ecl_file_open_rstblock_sim_time( const char * filename , time_t sim_time);
|
||||
ecl_file_type * ecl_file_iopen_rstblock( const char * filename , int seqnum_index);
|
||||
ecl_file_type * ecl_file_open_rstblock_report_step( const char * filename , int report_step , int flags);
|
||||
ecl_file_type * ecl_file_open_rstblock_sim_time( const char * filename , time_t sim_time , int flags);
|
||||
ecl_file_type * ecl_file_iopen_rstblock( const char * filename , int seqnum_index , int flags);
|
||||
|
||||
ecl_file_type * ecl_file_open_rstblock_report_step_writable( const char * filename , int report_step );
|
||||
ecl_file_type * ecl_file_open_rstblock_sim_time_writable( const char * filename , time_t sim_time);
|
||||
ecl_file_type * ecl_file_iopen_rstblock_writable( const char * filename , int seqnum_index);
|
||||
|
||||
/*****************************************************************/
|
||||
/* SUMMARY FILES */
|
||||
|
||||
bool ecl_file_select_smryblock( ecl_file_type * ecl_file , int ministep_nr );
|
||||
ecl_file_type * ecl_file_open_smryblock( const char * filename , int ministep_nr );
|
||||
ecl_file_type * ecl_file_open_smryblock( const char * filename , int ministep_nr , int flags);
|
||||
|
||||
|
||||
UTIL_IS_INSTANCE_HEADER( ecl_file );
|
||||
|
@ -39,6 +39,7 @@ typedef struct inv_map_struct inv_map_type;
|
||||
void ecl_file_kw_free( ecl_file_kw_type * file_kw );
|
||||
void ecl_file_kw_free__( void * arg );
|
||||
ecl_kw_type * ecl_file_kw_get_kw( ecl_file_kw_type * file_kw , fortio_type * fortio, inv_map_type * inv_map);
|
||||
ecl_kw_type * ecl_file_kw_get_kw_ptr( ecl_file_kw_type * file_kw , fortio_type * fortio , inv_map_type * inv_map );
|
||||
ecl_file_kw_type * ecl_file_kw_alloc_copy( const ecl_file_kw_type * src );
|
||||
const char * ecl_file_kw_get_header( const ecl_file_kw_type * file_kw );
|
||||
int ecl_file_kw_get_size( const ecl_file_kw_type * file_kw );
|
||||
|
@ -29,6 +29,7 @@ extern "C" {
|
||||
|
||||
#include <ert/ecl/ecl_coarse_cell.h>
|
||||
#include <ert/ecl/ecl_kw.h>
|
||||
#include <ert/ecl/grid_dims.h>
|
||||
|
||||
|
||||
typedef double (block_function_ftype) ( const double_vector_type *);
|
||||
@ -79,7 +80,6 @@ extern "C" {
|
||||
ecl_grid_type * ecl_grid_alloc_GRDECL_data(int , int , int , const float * , const float * , const int * , const float * mapaxes);
|
||||
ecl_grid_type * ecl_grid_alloc_GRID_data(int num_coords , int nx, int ny , int nz , int coords_size , int ** coords , float ** corners , const float * mapaxes);
|
||||
ecl_grid_type * ecl_grid_alloc(const char * );
|
||||
bool ecl_grid_file_dims( const char * grid_filename , const char * init_restart_filename , int * dims);
|
||||
ecl_grid_type * ecl_grid_load_case( const char * case_input );
|
||||
ecl_grid_type * ecl_grid_alloc_rectangular( int nx , int ny , int nz , double dx , double dy , double dz , const int * actnum);
|
||||
ecl_grid_type * ecl_grid_alloc_regular( int nx, int ny , int nz , const double * ivec, const double * jvec , const double * kvec , const int * actnum);
|
||||
@ -89,6 +89,7 @@ extern "C" {
|
||||
|
||||
void ecl_grid_free(ecl_grid_type * );
|
||||
void ecl_grid_free__( void * arg );
|
||||
grid_dims_type ecl_grid_iget_dims( const ecl_grid_type * grid , int grid_nr);
|
||||
void ecl_grid_get_dims(const ecl_grid_type * , int *, int * , int * , int *);
|
||||
int ecl_grid_get_nz( const ecl_grid_type * grid );
|
||||
int ecl_grid_get_nx( const ecl_grid_type * grid );
|
||||
|
37
ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_grid_dims.h
vendored
Normal file
37
ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_grid_dims.h
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright (C) 2013 Statoil ASA, Norway.
|
||||
|
||||
The file 'ecl_grid_dims.h' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
|
||||
#ifndef __ECL_GRID_DIMS_H__
|
||||
#define __ECL_GRID_DIMS_H__
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <ert/ecl/grid_dims.h>
|
||||
|
||||
typedef struct ecl_grid_dims_struct ecl_grid_dims_type;
|
||||
|
||||
ecl_grid_dims_type * ecl_grid_dims_alloc( const char * grid_file , const char * data_file);
|
||||
void ecl_grid_dims_free( ecl_grid_dims_type * grid_dims );
|
||||
int ecl_grid_dims_get_num_grids( const ecl_grid_dims_type * grid_dims);
|
||||
const grid_dims_type * ecl_grid_dims_iget_dims( const ecl_grid_dims_type * grid_dims , int grid_nr );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -169,7 +169,7 @@ void ecl_util_alloc_summary_data_files(const char * path , const char
|
||||
void ecl_util_alloc_restart_files(const char * , const char * , char *** , int * , bool * , bool *);
|
||||
time_t ecl_util_get_start_date(const char * );
|
||||
int ecl_util_get_num_cpu(const char * data_file);
|
||||
bool ecl_util_fmt_file(const char *);
|
||||
bool ecl_util_fmt_file(const char * filename , bool * __fmt_file);
|
||||
char * ecl_util_alloc_exfilename_anyfmt(const char * path, const char * base , ecl_file_enum file_type , bool start_fmt , int report_nr);
|
||||
int ecl_util_get_month_nr(const char * month_name);
|
||||
int ecl_util_fname_report_cmp(const void *f1, const void *f2);
|
||||
|
@ -35,8 +35,6 @@ typedef enum {
|
||||
FORTIO_HEADER_MISMATCH = 5
|
||||
} fortio_status_type;
|
||||
|
||||
#define FORTIO_READ 1
|
||||
#define FORTIO_WRITE 2
|
||||
|
||||
typedef struct fortio_struct fortio_type;
|
||||
|
||||
@ -70,9 +68,13 @@ typedef struct fortio_struct fortio_type;
|
||||
bool fortio_fmt_file(const fortio_type *);
|
||||
long fortio_ftell( const fortio_type * fortio );
|
||||
int fortio_fseek( fortio_type * fortio , long offset , int whence);
|
||||
int fortio_get_mode( const fortio_type * fortio );
|
||||
int fortio_fileno( fortio_type * fortio );
|
||||
|
||||
bool fortio_fclose_stream( fortio_type * fortio );
|
||||
bool fortio_fopen_stream( fortio_type * fortio );
|
||||
bool fortio_stream_is_open( const fortio_type * fortio );
|
||||
bool fortio_assert_stream_open( fortio_type * fortio );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
37
ThirdParty/Ert/devel/libecl/include/ert/ecl/grid_dims.h
vendored
Normal file
37
ThirdParty/Ert/devel/libecl/include/ert/ecl/grid_dims.h
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright (C) 2013 Statoil ASA, Norway.
|
||||
|
||||
The file 'grid_dims.h' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
|
||||
#ifndef __GRID_DIMS_H__
|
||||
#define __GRID_DIMS_H__
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int nx,ny,nz,nactive;
|
||||
} grid_dims_type;
|
||||
|
||||
void grid_dims_init( grid_dims_type * dims , int nx, int ny , int nz , int nactive);
|
||||
grid_dims_type * grid_dims_alloc( int nx, int ny , int nz , int nactive);
|
||||
void grid_dims_free( grid_dims_type * dims );
|
||||
void grid_dims_free__( void * arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -2,9 +2,9 @@ include_directories( ext )
|
||||
file(GLOB ext_source "ext/*.c" )
|
||||
file(GLOB ext_header "ext/*.h" )
|
||||
|
||||
set( source_files ecl_rsthead.c ecl_sum_tstep.c ecl_rst_file.c ecl_init_file.c ecl_grid_cache.c smspec_node.c ecl_kw_grdecl.c ecl_file_kw.c ecl_grav.c ecl_grav_calc.c ecl_smspec.c ecl_sum_data.c ecl_util.c ecl_kw.c ecl_sum.c fortio.c ecl_rft_file.c ecl_rft_node.c ecl_grid.c ecl_coarse_cell.c ecl_box.c ecl_io_config.c ecl_file.c ecl_region.c point.c tetrahedron.c ecl_subsidence.c ecl_grav_common.c ${ext_source})
|
||||
set( source_files ecl_rsthead.c ecl_sum_tstep.c ecl_rst_file.c ecl_init_file.c ecl_grid_cache.c smspec_node.c ecl_kw_grdecl.c ecl_file_kw.c ecl_grav.c ecl_grav_calc.c ecl_smspec.c ecl_sum_data.c ecl_util.c ecl_kw.c ecl_sum.c fortio.c ecl_rft_file.c ecl_rft_node.c ecl_grid.c ecl_coarse_cell.c ecl_box.c ecl_io_config.c ecl_file.c ecl_region.c point.c tetrahedron.c ecl_subsidence.c ecl_grid_dims.c grid_dims.c ecl_grav_common.c ${ext_source})
|
||||
|
||||
set( header_files ecl_rsthead.h ecl_sum_tstep.h ecl_rst_file.h ecl_init_file.h smspec_node.h ecl_grid_cache.h ecl_kw_grdecl.h ecl_file_kw.h ecl_grav.h ecl_grav_calc.h ecl_endian_flip.h ecl_smspec.h ecl_sum_data.h ecl_util.h ecl_kw.h ecl_sum.h fortio.h ecl_rft_file.h ecl_rft_node.h ecl_box.h ecl_coarse_cell.h ecl_grid.h ecl_io_config.h ecl_file.h ecl_region.h ecl_kw_magic.h ecl_subsidence.h ${ext_header} ecl_grav_common.h)
|
||||
set( header_files ecl_rsthead.h ecl_sum_tstep.h ecl_rst_file.h ecl_init_file.h smspec_node.h ecl_grid_cache.h ecl_kw_grdecl.h ecl_file_kw.h ecl_grav.h ecl_grav_calc.h ecl_endian_flip.h ecl_smspec.h ecl_sum_data.h ecl_util.h ecl_kw.h ecl_sum.h fortio.h ecl_rft_file.h ecl_rft_node.h ecl_box.h ecl_coarse_cell.h ecl_grid.h ecl_io_config.h ecl_file.h ecl_region.h ecl_kw_magic.h ecl_subsidence.h ecl_grid_dims.h grid_dims.h ${ext_header} ecl_grav_common.h)
|
||||
|
||||
|
||||
|
||||
|
182
ThirdParty/Ert/devel/libecl/src/ecl_file.c
vendored
182
ThirdParty/Ert/devel/libecl/src/ecl_file.c
vendored
@ -131,7 +131,8 @@ struct file_map_struct {
|
||||
stringlist_type * distinct_kw; /* A stringlist of the keywords occuring in the file - each string occurs ONLY ONCE. */
|
||||
fortio_type * fortio; /* The same fortio instance pointer as in the ecl_file styructure. */
|
||||
bool owner; /* Is this map the owner of the ecl_file_kw instances; only true for the global_map. */
|
||||
inv_map_type * inv_map; /* Shared reference owned by the ecl_file structure. */
|
||||
inv_map_type * inv_map; /* Shared reference owned by the ecl_file structure. */
|
||||
int flags;
|
||||
};
|
||||
|
||||
|
||||
@ -144,6 +145,7 @@ struct ecl_file_struct {
|
||||
file_map_type * active_map; /* The currently active index. */
|
||||
vector_type * map_list; /* Storage container for the map instances. */
|
||||
bool read_only;
|
||||
int flags;
|
||||
vector_type * map_stack;
|
||||
inv_map_type * inv_map;
|
||||
};
|
||||
@ -180,7 +182,16 @@ struct ecl_file_struct {
|
||||
*/
|
||||
|
||||
|
||||
static file_map_type * file_map_alloc( fortio_type * fortio , inv_map_type * inv_map , bool owner ) {
|
||||
static bool FILE_FLAGS_SET( int state_flags , int query_flags) {
|
||||
if ((state_flags & query_flags) == query_flags)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static file_map_type * file_map_alloc( fortio_type * fortio , int flags , inv_map_type * inv_map , bool owner ) {
|
||||
file_map_type * file_map = util_malloc( sizeof * file_map );
|
||||
file_map->kw_list = vector_alloc_new();
|
||||
file_map->kw_index = hash_alloc();
|
||||
@ -188,6 +199,7 @@ static file_map_type * file_map_alloc( fortio_type * fortio , inv_map_type * inv
|
||||
file_map->owner = owner;
|
||||
file_map->fortio = fortio;
|
||||
file_map->inv_map = inv_map;
|
||||
file_map->flags = flags;
|
||||
return file_map;
|
||||
}
|
||||
|
||||
@ -257,10 +269,19 @@ static ecl_file_kw_type * file_map_iget_named_file_kw( const file_map_type * fil
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ecl_kw_type * file_map_iget_kw( const file_map_type * file_map , int index) {
|
||||
ecl_file_kw_type * file_kw = file_map_iget_file_kw( file_map , index );
|
||||
ecl_kw_type * ecl_kw = ecl_file_kw_get_kw( file_kw , file_map->fortio , file_map->inv_map);
|
||||
ecl_kw_type * ecl_kw = ecl_file_kw_get_kw_ptr( file_kw , file_map->fortio , file_map->inv_map);
|
||||
if (!ecl_kw) {
|
||||
if (fortio_assert_stream_open( file_map->fortio )) {
|
||||
|
||||
ecl_kw = ecl_file_kw_get_kw( file_kw , file_map->fortio , file_map->inv_map);
|
||||
|
||||
if (FILE_FLAGS_SET( file_map->flags , ECL_FILE_CLOSE_STREAM))
|
||||
fortio_fclose_stream( file_map->fortio );
|
||||
}
|
||||
}
|
||||
return ecl_kw;
|
||||
}
|
||||
|
||||
@ -313,7 +334,17 @@ static const char * file_map_iget_header( const file_map_type * file_map , int i
|
||||
|
||||
static ecl_kw_type * file_map_iget_named_kw( const file_map_type * file_map , const char * kw, int ith) {
|
||||
ecl_file_kw_type * file_kw = file_map_iget_named_file_kw( file_map , kw , ith);
|
||||
return ecl_file_kw_get_kw( file_kw , file_map->fortio , file_map->inv_map );
|
||||
ecl_kw_type * ecl_kw = ecl_file_kw_get_kw_ptr( file_kw , file_map->fortio , file_map->inv_map );
|
||||
if (!ecl_kw) {
|
||||
if (fortio_assert_stream_open( file_map->fortio )) {
|
||||
|
||||
ecl_kw = ecl_file_kw_get_kw( file_kw , file_map->fortio , file_map->inv_map);
|
||||
|
||||
if (FILE_FLAGS_SET( file_map->flags , ECL_FILE_CLOSE_STREAM))
|
||||
fortio_fclose_stream( file_map->fortio );
|
||||
}
|
||||
}
|
||||
return ecl_kw;
|
||||
}
|
||||
|
||||
static ecl_type_enum file_map_iget_named_type( const file_map_type * file_map , const char * kw , int ith) {
|
||||
@ -351,12 +382,22 @@ static void file_map_replace_kw( file_map_type * file_map , ecl_kw_type * old_kw
|
||||
}
|
||||
|
||||
|
||||
static void file_map_load_all( file_map_type * file_map ) {
|
||||
int index;
|
||||
for (index = 0; index < vector_get_size( file_map->kw_list); index++) {
|
||||
ecl_file_kw_type * ikw = vector_iget( file_map->kw_list , index );
|
||||
ecl_file_kw_get_kw( ikw , file_map->fortio , file_map->inv_map);
|
||||
static bool file_map_load_all( file_map_type * file_map ) {
|
||||
bool loadOK = false;
|
||||
|
||||
if (fortio_assert_stream_open( file_map->fortio )) {
|
||||
int index;
|
||||
for (index = 0; index < vector_get_size( file_map->kw_list); index++) {
|
||||
ecl_file_kw_type * ikw = vector_iget( file_map->kw_list , index );
|
||||
ecl_file_kw_get_kw( ikw , file_map->fortio , file_map->inv_map);
|
||||
}
|
||||
loadOK = true;
|
||||
}
|
||||
|
||||
if (FILE_FLAGS_SET( file_map->flags , ECL_FILE_CLOSE_STREAM))
|
||||
fortio_fclose_stream( file_map->fortio );
|
||||
|
||||
return loadOK;
|
||||
}
|
||||
|
||||
|
||||
@ -439,7 +480,7 @@ static void file_map_fprintf_kw_list(const file_map_type * file_map , FILE * str
|
||||
*/
|
||||
static file_map_type * file_map_alloc_blockmap(const file_map_type * file_map , const char * header, int occurence) {
|
||||
if (file_map_get_num_named_kw( file_map , header ) > occurence) {
|
||||
file_map_type * block_map = file_map_alloc( file_map->fortio , file_map->inv_map , false);
|
||||
file_map_type * block_map = file_map_alloc( file_map->fortio , file_map->flags , file_map->inv_map , false);
|
||||
if (file_map_has_kw( file_map , header )) {
|
||||
int kw_index = file_map_get_global_index( file_map , header , occurence );
|
||||
ecl_file_kw_type * file_kw = vector_iget( file_map->kw_list , kw_index );
|
||||
@ -473,13 +514,13 @@ UTIL_IS_INSTANCE_FUNCTION( ecl_file , ECL_FILE_ID)
|
||||
|
||||
|
||||
|
||||
ecl_file_type * ecl_file_alloc_empty( bool read_only ) {
|
||||
ecl_file_type * ecl_file_alloc_empty( int flags ) {
|
||||
ecl_file_type * ecl_file = util_malloc( sizeof * ecl_file );
|
||||
UTIL_TYPE_ID_INIT(ecl_file , ECL_FILE_ID);
|
||||
ecl_file->map_list = vector_alloc_new();
|
||||
ecl_file->map_stack = vector_alloc_new();
|
||||
ecl_file->read_only = read_only;
|
||||
ecl_file->inv_map = inv_map_alloc( );
|
||||
ecl_file->flags = flags;
|
||||
return ecl_file;
|
||||
}
|
||||
|
||||
@ -825,49 +866,64 @@ void ecl_file_select_global( ecl_file_type * ecl_file ) {
|
||||
*/
|
||||
|
||||
|
||||
static ecl_file_type * ecl_file_open__( const char * filename , bool read_only) {
|
||||
bool fmt_file = ecl_util_fmt_file( filename );
|
||||
ecl_file_type * ecl_file = ecl_file_alloc_empty( read_only );
|
||||
static ecl_file_type * ecl_file_open__( const char * filename , int flags) {
|
||||
fortio_type * fortio;
|
||||
bool fmt_file;
|
||||
|
||||
ecl_util_fmt_file( filename , &fmt_file);
|
||||
//flags |= ECL_FILE_CLOSE_STREAM; // DEBUG DEBUG DEBUG
|
||||
|
||||
if (ecl_file->read_only)
|
||||
ecl_file->fortio = fortio_open_reader( filename , fmt_file , ECL_ENDIAN_FLIP);
|
||||
if (FILE_FLAGS_SET(flags , ECL_FILE_WRITABLE))
|
||||
fortio = fortio_open_readwrite( filename , fmt_file , ECL_ENDIAN_FLIP);
|
||||
else
|
||||
ecl_file->fortio = fortio_open_readwrite( filename , fmt_file , ECL_ENDIAN_FLIP);
|
||||
fortio = fortio_open_reader( filename , fmt_file , ECL_ENDIAN_FLIP);
|
||||
|
||||
ecl_file->global_map = file_map_alloc( ecl_file->fortio , ecl_file->inv_map , true );
|
||||
if (fortio) {
|
||||
ecl_file_type * ecl_file = ecl_file_alloc_empty( flags );
|
||||
ecl_file->fortio = fortio;
|
||||
ecl_file->global_map = file_map_alloc( ecl_file->fortio , ecl_file->flags , ecl_file->inv_map , true );
|
||||
|
||||
ecl_file_add_map( ecl_file , ecl_file->global_map );
|
||||
ecl_file_scan( ecl_file );
|
||||
ecl_file_select_global( ecl_file );
|
||||
ecl_file_add_map( ecl_file , ecl_file->global_map );
|
||||
ecl_file_scan( ecl_file );
|
||||
ecl_file_select_global( ecl_file );
|
||||
|
||||
return ecl_file;
|
||||
}
|
||||
if (FILE_FLAGS_SET( ecl_file->flags , ECL_FILE_CLOSE_STREAM))
|
||||
fortio_fclose_stream( ecl_file->fortio );
|
||||
|
||||
|
||||
ecl_file_type * ecl_file_open( const char * filename ) {
|
||||
return ecl_file_open__(filename , true );
|
||||
}
|
||||
|
||||
ecl_file_type * ecl_file_try_open( const char * filename) {
|
||||
if (util_entry_readable( filename ))
|
||||
return ecl_file_open( filename );
|
||||
else
|
||||
return ecl_file;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
This function opens the file in a mode where it can be updated and
|
||||
modified, but it must still exist and be readable. I.e. this should
|
||||
not compared with the normal: fopen(filename , "w") where an
|
||||
existing file is truncated to zero upon successfull open.
|
||||
*/
|
||||
|
||||
ecl_file_type * ecl_file_open_writable( const char * filename ) {
|
||||
if (util_entry_readable( filename ) && util_entry_writable( filename ))
|
||||
return ecl_file_open__(filename , false );
|
||||
else
|
||||
ecl_file_type * ecl_file_open( const char * filename , int flags) {
|
||||
ecl_file_type * ecl_file = ecl_file_open__(filename , flags );
|
||||
if (ecl_file)
|
||||
return ecl_file;
|
||||
else {
|
||||
util_abort("%s: failed to open ECLIPSE file:%s \n",__func__ , filename);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ecl_file_type * ecl_file_try_open( const char * filename, int flags) {
|
||||
return ecl_file_open__(filename , flags );
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ecl_file_get_flags( const ecl_file_type * ecl_file ) {
|
||||
return ecl_file->flags;
|
||||
}
|
||||
|
||||
|
||||
bool ecl_file_flags_set( const ecl_file_type * ecl_file , int flags) {
|
||||
return FILE_FLAGS_SET( ecl_file->flags , flags );
|
||||
}
|
||||
|
||||
bool ecl_file_writable( const ecl_file_type * ecl_file ) {
|
||||
return FILE_FLAGS_SET( ecl_file->flags , ECL_FILE_WRITABLE );
|
||||
}
|
||||
|
||||
|
||||
@ -933,8 +989,8 @@ void ecl_file_fortio_detach( ecl_file_type * ecl_file ) {
|
||||
}
|
||||
|
||||
|
||||
void ecl_file_load_all( ecl_file_type * ecl_file ) {
|
||||
file_map_load_all( ecl_file->active_map );
|
||||
bool ecl_file_load_all( ecl_file_type * ecl_file ) {
|
||||
return file_map_load_all( ecl_file->active_map );
|
||||
}
|
||||
|
||||
|
||||
@ -998,12 +1054,11 @@ int ecl_file_get_phases( const ecl_file_type * init_file ) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
bool ecl_file_writable( const ecl_file_type * ecl_file ) {
|
||||
if (fortio_get_mode( ecl_file->fortio ) & FORTIO_WRITE)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return fortio_writable( ecl_file->fortio );
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
Checks if the ecl_file contains ecl_kw; this check is based on
|
||||
@ -1040,14 +1095,33 @@ bool ecl_file_has_kw_ptr( const ecl_file_type * ecl_file , const ecl_kw_type * e
|
||||
open functions.
|
||||
*/
|
||||
|
||||
void ecl_file_save_kw( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_kw) {
|
||||
bool ecl_file_save_kw( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_kw) {
|
||||
ecl_file_kw_type * file_kw = inv_map_get_file_kw( ecl_file->inv_map , ecl_kw ); // We just verify that the input ecl_kw points to an ecl_kw
|
||||
if (file_kw != NULL) // we manage; from then on we use the reference contained in
|
||||
ecl_file_kw_inplace_fwrite( file_kw , ecl_file->fortio ); // the corresponding ecl_file_kw instance.
|
||||
else
|
||||
if (file_kw != NULL) { // we manage; from then on we use the reference contained in
|
||||
if (fortio_assert_stream_open( ecl_file->fortio )) { // the corresponding ecl_file_kw instance.
|
||||
|
||||
ecl_file_kw_inplace_fwrite( file_kw , ecl_file->fortio );
|
||||
|
||||
if (FILE_FLAGS_SET( ecl_file->flags , ECL_FILE_CLOSE_STREAM))
|
||||
fortio_fclose_stream( ecl_file->fortio );
|
||||
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
} else {
|
||||
util_abort("%s: keyword pointer:%p not found in ecl_file instance. \n",__func__ , ecl_kw);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Small function to support Python based enum introspection. */
|
||||
|
||||
#ifdef HAVE_FORK
|
||||
|
||||
const char * ecl_util_file_flags_enum_iget( int index , int * value) {
|
||||
return util_enum_iget( index , ECL_FILE_FLAGS_ENUM_SIZE , (const util_enum_element_type []) { ECL_FILE_FLAGS_ENUM_DEFS }, value);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -228,6 +228,9 @@ static void ecl_file_kw_load_kw( ecl_file_kw_type * file_kw , fortio_type * fort
|
||||
}
|
||||
}
|
||||
|
||||
ecl_kw_type * ecl_file_kw_get_kw_ptr( ecl_file_kw_type * file_kw , fortio_type * fortio , inv_map_type * inv_map ) {
|
||||
return file_kw->kw;
|
||||
}
|
||||
|
||||
/*
|
||||
Will return the ecl_kw instance of this file_kw; if it is not
|
||||
|
127
ThirdParty/Ert/devel/libecl/src/ecl_grid.c
vendored
127
ThirdParty/Ert/devel/libecl/src/ecl_grid.c
vendored
@ -38,6 +38,7 @@
|
||||
#include <ert/ecl/ecl_grid.h>
|
||||
#include <ert/ecl/point.h>
|
||||
#include <ert/ecl/tetrahedron.h>
|
||||
#include <ert/ecl/grid_dims.h>
|
||||
|
||||
|
||||
/*
|
||||
@ -2055,7 +2056,7 @@ static ecl_grid_type * ecl_grid_alloc_EGRID(const char * grid_file) {
|
||||
if (file_type != ECL_EGRID_FILE)
|
||||
util_abort("%s: %s wrong file type - expected .EGRID file - aborting \n",__func__ , grid_file);
|
||||
{
|
||||
ecl_file_type * ecl_file = ecl_file_open( grid_file );
|
||||
ecl_file_type * ecl_file = ecl_file_open( grid_file , 0);
|
||||
int num_grid = ecl_file_get_num_named_kw( ecl_file , GRIDHEAD_KW );
|
||||
ecl_grid_type * main_grid = ecl_grid_alloc_EGRID__( NULL , ecl_file , 0 );
|
||||
int grid_nr;
|
||||
@ -2283,7 +2284,7 @@ static ecl_grid_type * ecl_grid_alloc_GRID(const char * grid_file) {
|
||||
|
||||
{
|
||||
int cell_offset = 0;
|
||||
ecl_file_type * ecl_file = ecl_file_open( grid_file );
|
||||
ecl_file_type * ecl_file = ecl_file_open( grid_file , 0);
|
||||
int num_grid = ecl_file_get_num_named_kw( ecl_file , DIMENS_KW);
|
||||
ecl_grid_type * main_grid;
|
||||
int grid_nr;
|
||||
@ -2395,108 +2396,6 @@ ecl_grid_type * ecl_grid_alloc(const char * grid_file ) {
|
||||
return ecl_grid;
|
||||
}
|
||||
|
||||
static void ecl_grid_file_nactive_dims( fortio_type * data_fortio , int * dims) {
|
||||
if (data_fortio) {
|
||||
if (ecl_kw_fseek_kw( INTEHEAD_KW , false , false , data_fortio )) {
|
||||
ecl_kw_type * intehead_kw = ecl_kw_fread_alloc( data_fortio );
|
||||
dims[3] = ecl_kw_iget_int( intehead_kw , INTEHEAD_NACTIVE_INDEX );
|
||||
ecl_kw_free( intehead_kw );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool ecl_grid_file_EGRID_dims( fortio_type * grid_fortio , fortio_type * data_fortio , int * dims ) {
|
||||
|
||||
if (ecl_kw_fseek_kw( GRIDHEAD_KW , false , false , grid_fortio)) {
|
||||
{
|
||||
ecl_kw_type * gridhead_kw = ecl_kw_fread_alloc( grid_fortio );
|
||||
dims[0] = ecl_kw_iget_int( gridhead_kw , GRIDHEAD_NX_INDEX );
|
||||
dims[1] = ecl_kw_iget_int( gridhead_kw , GRIDHEAD_NY_INDEX );
|
||||
dims[2] = ecl_kw_iget_int( gridhead_kw , GRIDHEAD_NZ_INDEX );
|
||||
|
||||
ecl_kw_free( gridhead_kw );
|
||||
}
|
||||
ecl_grid_file_nactive_dims( data_fortio , dims );
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
static bool ecl_grid_file_GRID_dims( fortio_type * grid_fortio , fortio_type * data_fortio , int * dims ) {
|
||||
|
||||
if (ecl_kw_fseek_kw( DIMENS_KW , false , false , grid_fortio)) {
|
||||
{
|
||||
ecl_kw_type * dimens_kw = ecl_kw_fread_alloc( grid_fortio );
|
||||
dims[0] = ecl_kw_iget_int( dimens_kw , DIMENS_NX_INDEX );
|
||||
dims[1] = ecl_kw_iget_int( dimens_kw , DIMENS_NY_INDEX );
|
||||
dims[2] = ecl_kw_iget_int( dimens_kw , DIMENS_NZ_INDEX );
|
||||
|
||||
ecl_kw_free( dimens_kw );
|
||||
}
|
||||
|
||||
ecl_grid_file_nactive_dims( data_fortio , dims );
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Will check the grid dimensions from the input grid file
|
||||
@grid_filename; the input file must be a GRID/EGRID file. On exit
|
||||
the dims array will be filled as:
|
||||
|
||||
dims[0] = nx;
|
||||
dims[1] = ny;
|
||||
dims[2] = nz;
|
||||
|
||||
Optionally you can in addition supply the name of a restart or INIT
|
||||
file in the second file argument - if-and-only-if, that filename
|
||||
points to an existing file the fourth element in the dims array
|
||||
will be set as:
|
||||
|
||||
dims[3] = nactive;
|
||||
|
||||
The function as a whole will return true if the grid dimensions
|
||||
(nx,ny,nz) are sucessfully set. If the dimensions are not set the
|
||||
dims vector is not touched.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
bool ecl_grid_file_dims( const char * grid_filename , const char * init_restart_filename , int * dims) {
|
||||
bool input_file_OK = false;
|
||||
bool grid_fmt_file;
|
||||
ecl_file_enum grid_file_type = ecl_util_get_file_type( grid_filename , &grid_fmt_file , NULL );
|
||||
|
||||
if ((grid_file_type == ECL_GRID_FILE) || (grid_file_type == ECL_EGRID_FILE)) {
|
||||
fortio_type * grid_fortio = fortio_open_reader( grid_filename , grid_fmt_file , ECL_ENDIAN_FLIP );
|
||||
if (grid_fortio) {
|
||||
fortio_type * data_fortio = NULL;
|
||||
bool data_fmt_file;
|
||||
|
||||
if (init_restart_filename) {
|
||||
ecl_file_enum data_file_type = ecl_util_get_file_type( init_restart_filename , &data_fmt_file , NULL );
|
||||
data_fortio = fortio_open_reader( init_restart_filename , data_fmt_file , ECL_ENDIAN_FLIP );
|
||||
}
|
||||
|
||||
|
||||
if (grid_file_type == ECL_GRID_FILE)
|
||||
input_file_OK = ecl_grid_file_GRID_dims( grid_fortio , data_fortio , dims );
|
||||
else
|
||||
input_file_OK = ecl_grid_file_EGRID_dims( grid_fortio , data_fortio , dims );
|
||||
|
||||
if (data_fortio)
|
||||
fortio_fclose( data_fortio );
|
||||
|
||||
fortio_fclose( grid_fortio );
|
||||
}
|
||||
}
|
||||
|
||||
return input_file_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3019,6 +2918,26 @@ int ecl_grid_get_nactive( const ecl_grid_type * grid ) {
|
||||
return grid->total_active;
|
||||
}
|
||||
|
||||
|
||||
grid_dims_type ecl_grid_iget_dims( const ecl_grid_type * grid , int grid_nr) {
|
||||
grid_dims_type dims;
|
||||
ecl_grid_type * lgr;
|
||||
|
||||
if (grid_nr == 0)
|
||||
lgr = grid;
|
||||
else
|
||||
lgr = ecl_grid_iget_lgr( grid , grid_nr - 1 );
|
||||
|
||||
dims.nx = lgr->nx;
|
||||
dims.ny = lgr->ny;
|
||||
dims.nz = lgr->nz;
|
||||
dims.nactive = lgr->total_active;
|
||||
|
||||
return dims;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ecl_grid_get_nactive_fracture( const ecl_grid_type * grid ) {
|
||||
return grid->total_active_fracture;
|
||||
}
|
||||
|
149
ThirdParty/Ert/devel/libecl/src/ecl_grid_dims.c
vendored
Normal file
149
ThirdParty/Ert/devel/libecl/src/ecl_grid_dims.c
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
/*
|
||||
Copyright (C) 2013 Statoil ASA, Norway.
|
||||
|
||||
The file 'ecl_grid_dims.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <ert/util/util.h>
|
||||
#include <ert/util/vector.h>
|
||||
|
||||
#include <ert/ecl/ecl_grid_dims.h>
|
||||
#include <ert/ecl/ecl_util.h>
|
||||
#include <ert/ecl/fortio.h>
|
||||
#include <ert/ecl/ecl_endian_flip.h>
|
||||
#include <ert/ecl/ecl_kw_magic.h>
|
||||
#include <ert/ecl/ecl_kw.h>
|
||||
|
||||
|
||||
struct ecl_grid_dims_struct {
|
||||
vector_type * dims_list;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void ecl_grid_dims_read_EGRID( ecl_grid_dims_type * grid_dims , fortio_type * grid_fortio , fortio_type * data_fortio ) {
|
||||
while (ecl_kw_fseek_kw( GRIDHEAD_KW , false , false , grid_fortio)) {
|
||||
grid_dims_type * dims;
|
||||
{
|
||||
ecl_kw_type * gridhead_kw = ecl_kw_fread_alloc( grid_fortio );
|
||||
|
||||
int nx = ecl_kw_iget_int( gridhead_kw , GRIDHEAD_NX_INDEX );
|
||||
int ny = ecl_kw_iget_int( gridhead_kw , GRIDHEAD_NY_INDEX );
|
||||
int nz = ecl_kw_iget_int( gridhead_kw , GRIDHEAD_NZ_INDEX );
|
||||
|
||||
dims = grid_dims_alloc( nx , ny , nz , 0 );
|
||||
ecl_kw_free( gridhead_kw );
|
||||
}
|
||||
|
||||
if (data_fortio) {
|
||||
if (ecl_kw_fseek_kw( INTEHEAD_KW , false , false , data_fortio )) {
|
||||
ecl_kw_type * intehead_kw = ecl_kw_fread_alloc( data_fortio );
|
||||
dims->nactive = ecl_kw_iget_int( intehead_kw , INTEHEAD_NACTIVE_INDEX );
|
||||
ecl_kw_free( intehead_kw );
|
||||
}
|
||||
}
|
||||
|
||||
vector_append_owned_ref( grid_dims->dims_list , dims, grid_dims_free__ );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void ecl_grid_dims_read_GRID( ecl_grid_dims_type * grid_dims , fortio_type * grid_fortio , fortio_type * data_fortio ) {
|
||||
while (ecl_kw_fseek_kw( DIMENS_KW , false , false , grid_fortio)) {
|
||||
grid_dims_type * dims;
|
||||
{
|
||||
ecl_kw_type * dimens_kw = ecl_kw_fread_alloc( grid_fortio );
|
||||
|
||||
int nx = ecl_kw_iget_int( dimens_kw , DIMENS_NX_INDEX );
|
||||
int ny = ecl_kw_iget_int( dimens_kw , DIMENS_NY_INDEX );
|
||||
int nz = ecl_kw_iget_int( dimens_kw , DIMENS_NZ_INDEX );
|
||||
|
||||
dims = grid_dims_alloc( nx , ny , nz , 0 );
|
||||
ecl_kw_free( dimens_kw );
|
||||
}
|
||||
|
||||
if (data_fortio) {
|
||||
if (ecl_kw_fseek_kw( INTEHEAD_KW , false , false , data_fortio )) {
|
||||
ecl_kw_type * intehead_kw = ecl_kw_fread_alloc( data_fortio );
|
||||
dims->nactive = ecl_kw_iget_int( intehead_kw , INTEHEAD_NACTIVE_INDEX );
|
||||
ecl_kw_free( intehead_kw );
|
||||
}
|
||||
}
|
||||
|
||||
vector_append_owned_ref( grid_dims->dims_list , dims, grid_dims_free__ );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ecl_grid_dims_type * ecl_grid_dims_alloc( const char * grid_file , const char * data_file) {
|
||||
ecl_grid_dims_type * grid_dims = NULL;
|
||||
bool grid_fmt_file;
|
||||
ecl_file_enum grid_file_type = ecl_util_get_file_type( grid_file , &grid_fmt_file , NULL );
|
||||
|
||||
|
||||
if ((grid_file_type == ECL_GRID_FILE) || (grid_file_type == ECL_EGRID_FILE)) {
|
||||
fortio_type * grid_fortio = fortio_open_reader( grid_file , grid_fmt_file , ECL_ENDIAN_FLIP );
|
||||
if (grid_fortio) {
|
||||
grid_dims = util_malloc( sizeof * grid_dims );
|
||||
grid_dims->dims_list = vector_alloc_new( );
|
||||
|
||||
{
|
||||
fortio_type * data_fortio = NULL;
|
||||
bool data_fmt_file;
|
||||
|
||||
if (data_file) {
|
||||
ecl_util_get_file_type( data_file , &data_fmt_file , NULL );
|
||||
data_fortio = fortio_open_reader( data_file , data_fmt_file , ECL_ENDIAN_FLIP );
|
||||
}
|
||||
|
||||
|
||||
if (grid_file_type == ECL_EGRID_FILE)
|
||||
ecl_grid_dims_read_EGRID( grid_dims , grid_fortio , data_fortio );
|
||||
else
|
||||
ecl_grid_dims_read_GRID( grid_dims , grid_fortio , data_fortio );
|
||||
|
||||
if (data_fortio)
|
||||
fortio_fclose( data_fortio );
|
||||
|
||||
}
|
||||
fortio_fclose( grid_fortio );
|
||||
}
|
||||
}
|
||||
|
||||
return grid_dims;
|
||||
}
|
||||
|
||||
|
||||
void ecl_grid_dims_free( ecl_grid_dims_type * grid_dims ) {
|
||||
vector_free( grid_dims->dims_list );
|
||||
free( grid_dims );
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ecl_grid_dims_get_num_grids( const ecl_grid_dims_type * grid_dims ) {
|
||||
return vector_get_size( grid_dims->dims_list );
|
||||
}
|
||||
|
||||
|
||||
const grid_dims_type * ecl_grid_dims_iget_dims( const ecl_grid_dims_type * grid_dims , int grid_nr ) {
|
||||
return vector_iget_const( grid_dims->dims_list , grid_nr );
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ static void ecl_rft_file_add_node(ecl_rft_file_type * rft_vector , const ecl_rft
|
||||
|
||||
ecl_rft_file_type * ecl_rft_file_alloc(const char * filename) {
|
||||
ecl_rft_file_type * rft_vector = ecl_rft_file_alloc_empty( filename );
|
||||
ecl_file_type * ecl_file = ecl_file_open( filename );
|
||||
ecl_file_type * ecl_file = ecl_file_open( filename , 0);
|
||||
int global_index = 0;
|
||||
int block_nr = 0;
|
||||
|
||||
|
13
ThirdParty/Ert/devel/libecl/src/ecl_rst_file.c
vendored
13
ThirdParty/Ert/devel/libecl/src/ecl_rst_file.c
vendored
@ -44,13 +44,18 @@ struct ecl_rst_file_struct {
|
||||
|
||||
|
||||
static ecl_rst_file_type * ecl_rst_file_alloc( const char * filename ) {
|
||||
bool fmt_file = ecl_util_fmt_file( filename );
|
||||
bool unified = ecl_util_unified_file( filename );
|
||||
bool fmt_file;
|
||||
ecl_rst_file_type * rst_file = util_malloc( sizeof * rst_file );
|
||||
|
||||
rst_file->unified = unified;
|
||||
rst_file->fmt_file = fmt_file;
|
||||
return rst_file;
|
||||
if (ecl_util_fmt_file( filename , &fmt_file)) {
|
||||
rst_file->unified = unified;
|
||||
rst_file->fmt_file = fmt_file;
|
||||
return rst_file;
|
||||
} else {
|
||||
util_abort("%s: invalid restart filename:%s - could not determine formatted/unformatted status\n",__func__ , filename);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
36
ThirdParty/Ert/devel/libecl/src/ecl_rstfile.c
vendored
36
ThirdParty/Ert/devel/libecl/src/ecl_rstfile.c
vendored
@ -398,8 +398,8 @@ bool ecl_file_select_rstblock_report_step( ecl_file_type * ecl_file , int report
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
static ecl_file_type * ecl_file_open_rstblock_report_step__( const char * filename , int report_step , bool read_only) {
|
||||
ecl_file_type * ecl_file = ecl_file_open__( filename , read_only);
|
||||
static ecl_file_type * ecl_file_open_rstblock_report_step__( const char * filename , int report_step , int flags) {
|
||||
ecl_file_type * ecl_file = ecl_file_open__( filename , flags );
|
||||
if (!ecl_file_select_rstblock_report_step( ecl_file , report_step )) {
|
||||
ecl_file_close( ecl_file );
|
||||
ecl_file = NULL;
|
||||
@ -407,18 +407,15 @@ static ecl_file_type * ecl_file_open_rstblock_report_step__( const char * filena
|
||||
return ecl_file;
|
||||
}
|
||||
|
||||
ecl_file_type * ecl_file_open_rstblock_report_step( const char * filename , int report_step ) {
|
||||
return ecl_file_open_rstblock_report_step__(filename , report_step , true );
|
||||
ecl_file_type * ecl_file_open_rstblock_report_step( const char * filename , int report_step , int flags) {
|
||||
return ecl_file_open_rstblock_report_step__(filename , report_step , flags );
|
||||
}
|
||||
|
||||
ecl_file_type * ecl_file_open_rstblock_report_step_writable( const char * filename , int report_step ) {
|
||||
return ecl_file_open_rstblock_report_step__(filename , report_step , false);
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
static ecl_file_type * ecl_file_open_rstblock_sim_time__( const char * filename , time_t sim_time, bool read_only) {
|
||||
ecl_file_type * ecl_file = ecl_file_open__( filename , read_only);
|
||||
static ecl_file_type * ecl_file_open_rstblock_sim_time__( const char * filename , time_t sim_time, int flags ) {
|
||||
ecl_file_type * ecl_file = ecl_file_open__( filename , flags );
|
||||
if (!ecl_file_select_rstblock_sim_time( ecl_file , sim_time)) {
|
||||
ecl_file_close( ecl_file );
|
||||
ecl_file = NULL;
|
||||
@ -426,18 +423,14 @@ static ecl_file_type * ecl_file_open_rstblock_sim_time__( const char * filename
|
||||
return ecl_file;
|
||||
}
|
||||
|
||||
ecl_file_type * ecl_file_open_rstblock_sim_time( const char * filename , time_t sim_time) {
|
||||
return ecl_file_open_rstblock_sim_time__( filename , sim_time , true );
|
||||
}
|
||||
|
||||
ecl_file_type * ecl_file_open_rstblock_sim_time_writable( const char * filename , time_t sim_time) {
|
||||
return ecl_file_open_rstblock_sim_time__( filename , sim_time , false );
|
||||
ecl_file_type * ecl_file_open_rstblock_sim_time( const char * filename , time_t sim_time, int flags) {
|
||||
return ecl_file_open_rstblock_sim_time__( filename , sim_time , flags );
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
static ecl_file_type * ecl_file_iopen_rstblock__( const char * filename , int seqnum_index, bool read_only) {
|
||||
ecl_file_type * ecl_file = ecl_file_open__( filename , read_only);
|
||||
static ecl_file_type * ecl_file_iopen_rstblock__( const char * filename , int seqnum_index, int flags ) {
|
||||
ecl_file_type * ecl_file = ecl_file_open__( filename , flags );
|
||||
if (!ecl_file_iselect_rstblock( ecl_file , seqnum_index )) {
|
||||
ecl_file_close( ecl_file );
|
||||
ecl_file = NULL;
|
||||
@ -446,13 +439,8 @@ static ecl_file_type * ecl_file_iopen_rstblock__( const char * filename , int se
|
||||
}
|
||||
|
||||
|
||||
ecl_file_type * ecl_file_iopen_rstblock( const char * filename , int seqnum_index) {
|
||||
return ecl_file_iopen_rstblock__(filename , seqnum_index , true);
|
||||
}
|
||||
|
||||
|
||||
ecl_file_type * ecl_file_iopen_rstblock_writable( const char * filename , int seqnum_index) {
|
||||
return ecl_file_iopen_rstblock__(filename , seqnum_index , false);
|
||||
ecl_file_type * ecl_file_iopen_rstblock( const char * filename , int seqnum_index , int flags) {
|
||||
return ecl_file_iopen_rstblock__(filename , seqnum_index , flags );
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,9 +26,8 @@ bool ecl_file_select_smryblock( ecl_file_type * ecl_file , int report_step ) {
|
||||
}
|
||||
|
||||
|
||||
ecl_file_type * ecl_file_open_smryblock( const char * filename , int report_step ) {
|
||||
bool read_only = true;
|
||||
ecl_file_type * ecl_file = ecl_file_open__( filename , read_only );
|
||||
ecl_file_type * ecl_file_open_smryblock( const char * filename , int report_step , int flags) {
|
||||
ecl_file_type * ecl_file = ecl_file_open__( filename , flags );
|
||||
if (!ecl_file_select_smryblock( ecl_file , report_step )) {
|
||||
ecl_file_close( ecl_file );
|
||||
ecl_file = NULL;
|
||||
|
4
ThirdParty/Ert/devel/libecl/src/ecl_smspec.c
vendored
4
ThirdParty/Ert/devel/libecl/src/ecl_smspec.c
vendored
@ -919,7 +919,7 @@ static void ecl_smspec_load_restart( ecl_smspec_type * ecl_smspec , const ecl_fi
|
||||
nevertheless prevents against a recursive death.
|
||||
*/
|
||||
if (!stringlist_contains( ecl_smspec->restart_list , restart_base)) {
|
||||
ecl_file_type * restart_header = ecl_file_open( smspec_header );
|
||||
ecl_file_type * restart_header = ecl_file_open( smspec_header , 0);
|
||||
|
||||
if (ecl_smspec_file_equal( header , restart_header)) {
|
||||
stringlist_insert_copy( ecl_smspec->restart_list , 0 , restart_base );
|
||||
@ -1034,7 +1034,7 @@ const int_vector_type * ecl_smspec_get_index_map( const ecl_smspec_type * smspec
|
||||
|
||||
|
||||
static void ecl_smspec_fread_header(ecl_smspec_type * ecl_smspec, const char * header_file , bool include_restart) {
|
||||
ecl_file_type * header = ecl_file_open( header_file );
|
||||
ecl_file_type * header = ecl_file_open( header_file , 0);
|
||||
{
|
||||
ecl_kw_type *wells = ecl_file_iget_named_kw(header, WGNAMES_KW , 0);
|
||||
ecl_kw_type *keywords = ecl_file_iget_named_kw(header, KEYWORDS_KW , 0);
|
||||
|
@ -949,13 +949,13 @@ static void ecl_sum_data_fread__( ecl_sum_data_type * data , time_t load_end , c
|
||||
if (file_type != ECL_SUMMARY_FILE)
|
||||
util_abort("%s: file:%s has wrong type \n",__func__ , data_file);
|
||||
{
|
||||
ecl_file_type * ecl_file = ecl_file_open( data_file );
|
||||
ecl_file_type * ecl_file = ecl_file_open( data_file , 0);
|
||||
ecl_sum_data_add_ecl_file( data , load_end , report_step , ecl_file , data->smspec);
|
||||
ecl_file_close( ecl_file );
|
||||
}
|
||||
}
|
||||
} else if (file_type == ECL_UNIFIED_SUMMARY_FILE) {
|
||||
ecl_file_type * ecl_file = ecl_file_open( stringlist_iget(filelist ,0 ));
|
||||
ecl_file_type * ecl_file = ecl_file_open( stringlist_iget(filelist ,0 ) , 0);
|
||||
int report_step = 1; /* <- ECLIPSE numbering - starting at 1. */
|
||||
while (true) {
|
||||
/*
|
||||
|
13
ThirdParty/Ert/devel/libecl/src/ecl_util.c
vendored
13
ThirdParty/Ert/devel/libecl/src/ecl_util.c
vendored
@ -702,29 +702,31 @@ bool ecl_util_unified_file(const char *filename) {
|
||||
}
|
||||
|
||||
|
||||
bool ecl_util_fmt_file(const char *filename) {
|
||||
bool ecl_util_fmt_file(const char *filename , bool * __fmt_file) {
|
||||
/*const int min_size = 32768;*/
|
||||
const int min_size = 256; /* Veeeery small */
|
||||
|
||||
int report_nr;
|
||||
ecl_file_enum file_type;
|
||||
|
||||
bool status = true;
|
||||
bool fmt_file;
|
||||
|
||||
if (util_file_exists(filename)) {
|
||||
file_type = ecl_util_get_file_type(filename , &fmt_file , &report_nr);
|
||||
if (file_type == ECL_OTHER_FILE) {
|
||||
if (util_file_size(filename) > min_size)
|
||||
fmt_file = util_fmt_bit8(filename);
|
||||
else
|
||||
util_abort("%s: sorry could not determine formatted|unformatted of file:%s file_size:%d - aborting \n",__func__ , filename , util_file_size(filename));
|
||||
status = false; // Do not know ??
|
||||
}
|
||||
} else {
|
||||
file_type = ecl_util_get_file_type(filename , &fmt_file , &report_nr);
|
||||
if (file_type == ECL_OTHER_FILE)
|
||||
util_abort("%s: sorry could not determine formatted|unformatted of file:%s - aborting \n",__func__ , filename);
|
||||
status = false; // Do not know ??
|
||||
}
|
||||
|
||||
return fmt_file;
|
||||
*__fmt_file = fmt_file;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -1401,4 +1403,5 @@ const char * ecl_util_phase_enum_iget( int index, int * value) {
|
||||
const char * ecl_util_type_enum_iget( int index, int * value) {
|
||||
return util_enum_iget( index , ECL_TYPE_ENUM_SIZE , (const util_enum_element_type []) { ECL_TYPE_ENUM_DEFS }, value);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
259
ThirdParty/Ert/devel/libecl/src/fortio.c
vendored
259
ThirdParty/Ert/devel/libecl/src/fortio.c
vendored
@ -71,22 +71,26 @@ fwrite() from the standard library.
|
||||
struct fortio_struct {
|
||||
FILE * stream;
|
||||
char * filename;
|
||||
int active_header;
|
||||
int rec_nr;
|
||||
bool endian_flip_header;
|
||||
bool fmt_file; /* This is not really used by the fortio instance - but it is very convenient to store it here. */
|
||||
int mode;
|
||||
const char * fopen_mode;
|
||||
bool stream_owner;
|
||||
|
||||
/* Internal variables used during partial read.*/
|
||||
int active_header;
|
||||
int rec_nr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static fortio_type * fortio_alloc__(const char *filename , bool fmt_file , bool endian_flip_header) {
|
||||
fortio_type * fortio = (fortio_type *) util_malloc(sizeof * fortio );
|
||||
static fortio_type * fortio_alloc__(const char *filename , bool fmt_file , bool endian_flip_header , bool stream_owner) {
|
||||
fortio_type * fortio = util_malloc(sizeof * fortio );
|
||||
fortio->filename = util_alloc_string_copy(filename);
|
||||
fortio->endian_flip_header = endian_flip_header;
|
||||
fortio->active_header = 0;
|
||||
fortio->rec_nr = 0;
|
||||
fortio->fmt_file = fmt_file;
|
||||
fortio->stream_owner = stream_owner;
|
||||
return fortio;
|
||||
}
|
||||
|
||||
@ -218,65 +222,187 @@ bool fortio_guess_endian_flip(const char * filename , bool * _endian_flip) {
|
||||
|
||||
|
||||
fortio_type * fortio_alloc_FILE_wrapper(const char *filename , bool endian_flip_header , bool fmt_file , FILE * stream) {
|
||||
fortio_type * fortio = fortio_alloc__(filename , fmt_file , endian_flip_header);
|
||||
fortio_type * fortio = fortio_alloc__(filename , fmt_file , endian_flip_header , false);
|
||||
fortio->stream = stream;
|
||||
return fortio;
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
/*
|
||||
Observe that the stream open functions accept a failure, and call
|
||||
the fopen() function driectly.
|
||||
*/
|
||||
|
||||
static const char * fortio_fopen_read_mode( bool fmt_file ) {
|
||||
if (fmt_file)
|
||||
return READ_MODE_TXT;
|
||||
else
|
||||
return READ_MODE_BINARY;
|
||||
}
|
||||
|
||||
static FILE * fortio_fopen_read( const char * filename , bool fmt_file ) {
|
||||
FILE * stream;
|
||||
const char * mode = fortio_fopen_read_mode( fmt_file );
|
||||
stream = fopen(filename , mode);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
static const char * fortio_fopen_write_mode( bool fmt_file ) {
|
||||
if (fmt_file)
|
||||
return WRITE_MODE_TXT;
|
||||
else
|
||||
return WRITE_MODE_BINARY;
|
||||
}
|
||||
|
||||
static FILE * fortio_fopen_write( const char * filename , bool fmt_file ) {
|
||||
FILE * stream;
|
||||
const char * mode = fortio_fopen_write_mode( fmt_file );
|
||||
stream = fopen(filename , mode);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static const char * fortio_fopen_readwrite_mode( bool fmt_file ) {
|
||||
if (fmt_file)
|
||||
return READ_WRITE_MODE_TXT;
|
||||
else
|
||||
return READ_WRITE_MODE_BINARY;
|
||||
}
|
||||
|
||||
static FILE * fortio_fopen_readwrite( const char * filename , bool fmt_file ) {
|
||||
FILE * stream;
|
||||
const char * mode = fortio_fopen_readwrite_mode( fmt_file );
|
||||
stream = fopen(filename , mode);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
static const char * fortio_fopen_append_mode( bool fmt_file ) {
|
||||
if (fmt_file)
|
||||
return APPEND_MODE_TXT;
|
||||
else
|
||||
return APPEND_MODE_BINARY;
|
||||
}
|
||||
|
||||
|
||||
static FILE * fortio_fopen_append( const char * filename , bool fmt_file ) {
|
||||
FILE * stream;
|
||||
const char * mode = fortio_fopen_append_mode( fmt_file );
|
||||
stream = fopen(filename , mode);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
|
||||
|
||||
fortio_type * fortio_open_reader(const char *filename , bool fmt_file , bool endian_flip_header) {
|
||||
fortio_type *fortio = fortio_alloc__(filename , fmt_file , endian_flip_header);
|
||||
|
||||
if (fmt_file)
|
||||
fortio->stream = util_fopen(fortio->filename , READ_MODE_TXT);
|
||||
else
|
||||
fortio->stream = util_fopen(fortio->filename , READ_MODE_BINARY);
|
||||
fortio->mode = FORTIO_READ;
|
||||
return fortio;
|
||||
FILE * stream = fortio_fopen_read( filename , fmt_file );
|
||||
if (stream) {
|
||||
fortio_type *fortio = fortio_alloc__(filename , fmt_file , endian_flip_header , true);
|
||||
fortio->stream = stream;
|
||||
fortio->fopen_mode = fortio_fopen_read_mode( fmt_file );
|
||||
return fortio;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fortio_type * fortio_open_writer(const char *filename , bool fmt_file , bool endian_flip_header ) {
|
||||
fortio_type *fortio = fortio_alloc__(filename , fmt_file , endian_flip_header);
|
||||
|
||||
if (fmt_file)
|
||||
fortio->stream = util_fopen(fortio->filename , WRITE_MODE_TXT);
|
||||
else
|
||||
fortio->stream = util_fopen(fortio->filename , WRITE_MODE_BINARY);
|
||||
fortio->mode = FORTIO_WRITE;
|
||||
|
||||
return fortio;
|
||||
FILE * stream = fortio_fopen_write( filename , fmt_file );
|
||||
if (stream) {
|
||||
fortio_type *fortio = fortio_alloc__(filename , fmt_file , endian_flip_header, true);
|
||||
fortio->stream = stream;
|
||||
fortio->fopen_mode = fortio_fopen_write_mode( fmt_file );
|
||||
return fortio;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
fortio_type * fortio_open_readwrite(const char *filename , bool fmt_file , bool endian_flip_header) {
|
||||
fortio_type *fortio = fortio_alloc__(filename , fmt_file , endian_flip_header);
|
||||
|
||||
if (fmt_file)
|
||||
fortio->stream = util_fopen(fortio->filename , READ_WRITE_MODE_TXT);
|
||||
else
|
||||
fortio->stream = util_fopen(fortio->filename , READ_WRITE_MODE_BINARY);
|
||||
|
||||
fortio->mode = FORTIO_READ + FORTIO_WRITE;
|
||||
return fortio;
|
||||
FILE * stream = fortio_fopen_readwrite( filename , fmt_file );
|
||||
if (stream) {
|
||||
fortio_type *fortio = fortio_alloc__(filename , fmt_file , endian_flip_header , true);
|
||||
fortio->stream = stream;
|
||||
fortio->fopen_mode = fortio_fopen_readwrite_mode( fmt_file );
|
||||
return fortio;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
fortio_type * fortio_open_append(const char *filename , bool fmt_file , bool endian_flip_header) {
|
||||
fortio_type *fortio = fortio_alloc__(filename , fmt_file , endian_flip_header);
|
||||
FILE * stream = fortio_fopen_append( filename , fmt_file );
|
||||
if (stream) {
|
||||
fortio_type *fortio = fortio_alloc__(filename , fmt_file , endian_flip_header , true);
|
||||
fortio->stream = stream;
|
||||
fortio->fopen_mode = fortio_fopen_append_mode( fmt_file );
|
||||
return fortio;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
/*****************************************************************/
|
||||
|
||||
if (fmt_file)
|
||||
fortio->stream = util_fopen(fortio->filename , APPEND_MODE_TXT);
|
||||
else
|
||||
fortio->stream = util_fopen(fortio->filename , APPEND_MODE_BINARY);
|
||||
|
||||
fortio->mode = FORTIO_WRITE;
|
||||
return fortio;
|
||||
bool fortio_fclose_stream( fortio_type * fortio ) {
|
||||
if (fortio->stream_owner) {
|
||||
if (fortio->stream) {
|
||||
int fclose_return = fclose( fortio->stream );
|
||||
fortio->stream = NULL;
|
||||
if (fclose_return == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
} else
|
||||
return false; // Already closed.
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool fortio_fopen_stream( fortio_type * fortio ) {
|
||||
if (fortio->stream == NULL) {
|
||||
fortio->stream = fopen( fortio->filename , fortio->fopen_mode );
|
||||
if (fortio->stream)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool fortio_stream_is_open( const fortio_type * fortio ) {
|
||||
if (fortio->stream)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool fortio_assert_stream_open( fortio_type * fortio ) {
|
||||
if (fortio->stream)
|
||||
return true;
|
||||
else {
|
||||
fortio_fopen_stream( fortio );
|
||||
return fortio_stream_is_open( fortio );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
|
||||
static void fortio_free__(fortio_type * fortio) {
|
||||
if (fortio->filename != NULL) free(fortio->filename);
|
||||
util_safe_free(fortio->filename);
|
||||
free(fortio);
|
||||
}
|
||||
|
||||
@ -286,7 +412,11 @@ void fortio_free_FILE_wrapper(fortio_type * fortio) {
|
||||
|
||||
|
||||
void fortio_fclose(fortio_type *fortio) {
|
||||
fclose(fortio->stream);
|
||||
if (fortio->stream) {
|
||||
fclose(fortio->stream);
|
||||
fortio->stream = NULL;
|
||||
}
|
||||
|
||||
fortio_free__(fortio);
|
||||
}
|
||||
|
||||
@ -341,40 +471,6 @@ int fortio_init_read(fortio_type *fortio) {
|
||||
|
||||
|
||||
|
||||
// util_fread_int: read failed: No such file or directory
|
||||
//
|
||||
// ****************************************************************************
|
||||
// ** **
|
||||
// ** A fatal error occured, and we have to abort. **
|
||||
// ** **
|
||||
// ** We now *try* to provide a backtrace, which would be very useful **
|
||||
// ** when debugging. The process of making a (human readable) backtrace **
|
||||
// ** is quite complex, among other things it involves several calls to the **
|
||||
// ** external program addr2line. We have arrived here because the program **
|
||||
// ** state is already quite broken, so the backtrace might be (seriously) **
|
||||
// ** broken as well. **
|
||||
// ** **
|
||||
// ****************************************************************************
|
||||
// Current executable : /private/joaho/EnKF/devel/EnKF/libecl/applications/summary.x
|
||||
// --------------------------------------------------------------------------------
|
||||
// #00 util_abort (..) in /private/joaho/EnKF/devel/EnKF/libutil/src/util.c:4604
|
||||
// #01 util_fread_int (..) in /private/joaho/EnKF/devel/EnKF/libutil/src/util.c:3423
|
||||
// #02 fortio_complete_read (..) in libecl/src/fortio.c:275
|
||||
// #03 fortio_fread_record (..) in libecl/src/fortio.c:297
|
||||
// #04 fortio_fread_buffer (..) in libecl/src/fortio.c:313
|
||||
// #05 ecl_kw_fread_data (..) in libecl/src/ecl_kw.c:745
|
||||
// #06 ecl_kw_fread_realloc (..) in libecl/src/ecl_kw.c:996
|
||||
// #07 ecl_kw_fread_alloc (..) in libecl/src/ecl_kw.c:1017
|
||||
// #08 ecl_file_fread_alloc_fortio(..) in /private/joaho/EnKF/devel/EnKF/libecl/src/ecl_file.c:206
|
||||
// #09 ecl_file_fread_alloc (..) in /private/joaho/EnKF/devel/EnKF/libecl/src/ecl_file.c:265
|
||||
// #10 ecl_sum_data_fread__ (..) in /private/joaho/EnKF/devel/EnKF/libecl/src/ecl_sum_data.c:693
|
||||
// #11 ecl_sum_data_fread_alloc (..) in /private/joaho/EnKF/devel/EnKF/libecl/src/ecl_sum_data.c:733
|
||||
// #12 ecl_sum_fread_alloc__ (..) in libecl/src/ecl_sum.c:58
|
||||
// #13 ecl_sum_fread_alloc_case__ (..) in libecl/src/ecl_sum.c:149
|
||||
// #14 main (..) in /private/joaho/EnKF/devel/EnKF/libecl/applications/view_summary.c:144
|
||||
// #15 ?? (..) in ??:0
|
||||
// #16 _start (..) in ??:0
|
||||
|
||||
|
||||
|
||||
void fortio_complete_read(fortio_type *fortio) {
|
||||
@ -400,10 +496,10 @@ void fortio_complete_read(fortio_type *fortio) {
|
||||
int fortio_fread_record(fortio_type *fortio, char *buffer) {
|
||||
fortio_init_read(fortio);
|
||||
{
|
||||
int record_size = fortio->active_header; /* This is reset in fortio_complete_read - must store it for the return. */
|
||||
util_fread(buffer , 1 , fortio->active_header , fortio->stream , __func__);
|
||||
fortio_complete_read(fortio);
|
||||
return record_size;
|
||||
int record_size = fortio->active_header; /* This is reset in fortio_complete_read - must store it for the return. */
|
||||
util_fread(buffer , 1 , fortio->active_header , fortio->stream , __func__);
|
||||
fortio_complete_read(fortio);
|
||||
return record_size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -620,6 +716,7 @@ int fortio_fileno( fortio_type * fortio ) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
void fortio_fflush(fortio_type * fortio) { fflush( fortio->stream); }
|
||||
FILE * fortio_get_FILE(const fortio_type *fortio) { return fortio->stream; }
|
||||
@ -628,4 +725,4 @@ int fortio_get_record_size(const fortio_type *fortio) { return fortio-
|
||||
bool fortio_fmt_file(const fortio_type *fortio) { return fortio->fmt_file; }
|
||||
void fortio_rewind(const fortio_type *fortio) { rewind(fortio->stream); }
|
||||
const char * fortio_filename_ref(const fortio_type * fortio) { return (const char *) fortio->filename; }
|
||||
int fortio_get_mode( const fortio_type * fortio ) { return fortio->mode; }
|
||||
|
||||
|
51
ThirdParty/Ert/devel/libecl/src/grid_dims.c
vendored
Normal file
51
ThirdParty/Ert/devel/libecl/src/grid_dims.c
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright (C) 2013 Statoil ASA, Norway.
|
||||
|
||||
The file 'grid_dims.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <ert/util/util.h>
|
||||
|
||||
#include <ert/ecl/grid_dims.h>
|
||||
|
||||
|
||||
void grid_dims_init( grid_dims_type * dims , int nx, int ny , int nz , int nactive) {
|
||||
dims->nx = nx;
|
||||
dims->ny = ny;
|
||||
dims->nz = nz;
|
||||
dims->nactive = nactive;
|
||||
}
|
||||
|
||||
|
||||
|
||||
grid_dims_type * grid_dims_alloc( int nx, int ny , int nz , int nactive) {
|
||||
grid_dims_type * dims = util_malloc( sizeof * dims );
|
||||
grid_dims_init( dims , nx , ny , nz , nactive );
|
||||
return dims;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void grid_dims_free( grid_dims_type * dims ) {
|
||||
free( dims );
|
||||
}
|
||||
|
||||
|
||||
void grid_dims_free__( void * arg) {
|
||||
grid_dims_type * grid_dims = (grid_dims_type * ) arg;
|
||||
grid_dims_free( grid_dims );
|
||||
}
|
38
ThirdParty/Ert/devel/libecl/tests/CMakeLists.txt
vendored
38
ThirdParty/Ert/devel/libecl/tests/CMakeLists.txt
vendored
@ -20,6 +20,21 @@ target_link_libraries( ecl_grid_simple ecl )
|
||||
add_test( ecl_grid_simple ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_simple ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID )
|
||||
|
||||
|
||||
add_executable( ecl_grid_dims ecl_grid_dims.c )
|
||||
target_link_libraries( ecl_grid_dims ecl )
|
||||
|
||||
add_test( ecl_grid_dims0 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims )
|
||||
add_test( ecl_grid_dims1 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.INIT )
|
||||
add_test( ecl_grid_dims2 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.INIT)
|
||||
add_test( ecl_grid_dims3 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID )
|
||||
add_test( ecl_grid_dims4 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID )
|
||||
add_test( ecl_grid_dims5 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID
|
||||
${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.INIT )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
add_executable( ecl_kw_grdecl ecl_kw_grdecl.c )
|
||||
target_link_libraries( ecl_kw_grdecl ecl )
|
||||
add_test( ecl_kw_grdecl ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_grdecl )
|
||||
@ -41,11 +56,25 @@ add_executable( ecl_sum_test ecl_sum_test.c )
|
||||
target_link_libraries( ecl_sum_test ecl )
|
||||
add_test( ecl_sum_test ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE )
|
||||
|
||||
add_executable( ecl_fortio ecl_fortio.c )
|
||||
target_link_libraries( ecl_fortio ecl )
|
||||
add_test( ecl_fortio ${EXECUTABLE_OUTPUT_PATH}/ecl_fortio ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST )
|
||||
|
||||
add_executable( ecl_file ecl_file.c )
|
||||
target_link_libraries( ecl_file ecl )
|
||||
add_test( ecl_file ${EXECUTABLE_OUTPUT_PATH}/ecl_file ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ECLIPSE.UNRST)
|
||||
|
||||
add_executable( ecl_fmt ecl_fmt.c )
|
||||
target_link_libraries( ecl_fmt ecl )
|
||||
add_test( ecl_fmt ${EXECUTABLE_OUTPUT_PATH}/ecl_fmt ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.DATA)
|
||||
|
||||
|
||||
add_executable( ecl_rsthead ecl_rsthead.c )
|
||||
target_link_libraries( ecl_rsthead ecl )
|
||||
add_test( ecl_rsthead ${EXECUTABLE_OUTPUT_PATH}/ecl_rsthead ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST
|
||||
${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/DualPoro/DUALPORO.X0005 )
|
||||
|
||||
set_property( TEST ecl_fmt PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_coarse_test PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_restart_test PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_lgr_test1 PROPERTY LABELS Statoil )
|
||||
@ -53,3 +82,12 @@ set_property( TEST ecl_lgr_test2 PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_grid_simple PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_dualp PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_sum_test PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_fortio PROPERTY LABELS Statoil)
|
||||
|
||||
set_property( TEST ecl_grid_dims1 PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_grid_dims2 PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_grid_dims3 PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_grid_dims4 PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_grid_dims5 PROPERTY LABELS Statoil )
|
||||
set_property( TEST ecl_file PROPERTY LABELS Statoil)
|
||||
set_property( TEST ecl_rsthead PROPERTY LABELS Statoil)
|
||||
|
@ -69,8 +69,8 @@ int main(int argc , char ** argv) {
|
||||
char * init_file = ecl_util_alloc_filename( NULL , case_path , ECL_INIT_FILE , false , 0 );
|
||||
|
||||
ecl_grid_type * GRID = ecl_grid_alloc(egrid_file );
|
||||
ecl_file_type * RST_file = ecl_file_open( rst_file );
|
||||
ecl_file_type * INIT_file = ecl_file_open( init_file );
|
||||
ecl_file_type * RST_file = ecl_file_open( rst_file , 0);
|
||||
ecl_file_type * INIT_file = ecl_file_open( init_file , 0);
|
||||
|
||||
{
|
||||
test_assert_true( ecl_grid_have_coarse_cells( GRID ) );
|
||||
|
@ -32,9 +32,9 @@ int main(int argc , char ** argv) {
|
||||
char * rst_file = ecl_util_alloc_filename( NULL , case_path , ECL_RESTART_FILE , false , 0 );
|
||||
|
||||
ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_file );
|
||||
ecl_file_type * RST_file = ecl_file_open( rst_file );
|
||||
ecl_file_type * INIT_file = ecl_file_open( init_file );
|
||||
ecl_file_type * GRID_file = ecl_file_open( grid_file );
|
||||
ecl_file_type * RST_file = ecl_file_open( rst_file , 0);
|
||||
ecl_file_type * INIT_file = ecl_file_open( init_file , 0 );
|
||||
ecl_file_type * GRID_file = ecl_file_open( grid_file , 0);
|
||||
|
||||
{
|
||||
ecl_kw_type * actnum = ecl_file_iget_named_kw( GRID_file , "ACTNUM" , 0 );
|
||||
|
139
ThirdParty/Ert/devel/libecl/tests/ecl_file.c
vendored
Normal file
139
ThirdParty/Ert/devel/libecl/tests/ecl_file.c
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
Copyright (C) 2013 Statoil ASA, Norway.
|
||||
|
||||
The file 'ecl_file.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <ert/util/test_util.h>
|
||||
#include <ert/util/util.h>
|
||||
|
||||
#include <ert/ecl/ecl_file.h>
|
||||
#include <ert/ecl/ecl_endian_flip.h>
|
||||
|
||||
|
||||
void test_flags( const char * filename) {
|
||||
int FLAG1 = 1;
|
||||
int FLAG2 = 2;
|
||||
int FLAG3 = 4;
|
||||
int FLAG4 = 8;
|
||||
|
||||
int FLAGS = FLAG1 + FLAG2 + FLAG3;
|
||||
|
||||
|
||||
ecl_file_type * ecl_file = ecl_file_open( filename , FLAGS );
|
||||
|
||||
test_assert_int_equal( ecl_file_get_flags( ecl_file ) , FLAGS );
|
||||
test_assert_true( ecl_file_flags_set( ecl_file , FLAG1 ));
|
||||
test_assert_true( ecl_file_flags_set( ecl_file , FLAG1 | FLAG2));
|
||||
test_assert_true( ecl_file_flags_set( ecl_file , FLAG1 | FLAG3 ));
|
||||
test_assert_true( ecl_file_flags_set( ecl_file , FLAG1 | FLAG3 | FLAG2 ));
|
||||
test_assert_false( ecl_file_flags_set( ecl_file , FLAG1 | FLAG3 | FLAG4 ));
|
||||
ecl_file_close( ecl_file );
|
||||
}
|
||||
|
||||
|
||||
void test_close_stream2(const char * src_file , const char * target_file ) {
|
||||
util_copy_file( src_file , target_file );
|
||||
ecl_file_type * ecl_file = ecl_file_open( target_file , ECL_FILE_CLOSE_STREAM );
|
||||
|
||||
ecl_file_load_all( ecl_file );
|
||||
unlink( target_file );
|
||||
ecl_kw_type * kw2 = ecl_file_iget_kw( ecl_file , 2 );
|
||||
test_assert_not_NULL( kw2 );
|
||||
ecl_file_close( ecl_file );
|
||||
}
|
||||
|
||||
|
||||
void test_loadall(const char * src_file , const char * target_file ) {
|
||||
util_copy_file( src_file , target_file );
|
||||
{
|
||||
ecl_file_type * ecl_file = ecl_file_open( target_file , ECL_FILE_CLOSE_STREAM );
|
||||
|
||||
test_assert_true( ecl_file_load_all( ecl_file ) );
|
||||
ecl_file_close( ecl_file );
|
||||
}
|
||||
|
||||
{
|
||||
ecl_file_type * ecl_file = ecl_file_open( target_file , ECL_FILE_CLOSE_STREAM );
|
||||
unlink( target_file );
|
||||
|
||||
test_assert_false( ecl_file_load_all( ecl_file ) );
|
||||
ecl_file_close( ecl_file );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void test_close_stream1(const char * src_file , const char * target_file ) {
|
||||
util_copy_file( src_file , target_file );
|
||||
|
||||
ecl_file_type * ecl_file = ecl_file_open( target_file , ECL_FILE_CLOSE_STREAM );
|
||||
ecl_kw_type * kw0 = ecl_file_iget_kw( ecl_file , 0 );
|
||||
ecl_kw_type * kw1 = ecl_file_iget_kw( ecl_file , 1 );
|
||||
unlink( target_file );
|
||||
ecl_kw_type * kw1b = ecl_file_iget_kw( ecl_file , 1 );
|
||||
|
||||
test_assert_not_NULL( kw0 );
|
||||
test_assert_not_NULL( kw1 );
|
||||
test_assert_ptr_equal( kw1 , kw1b );
|
||||
|
||||
ecl_kw_type * kw2 = ecl_file_iget_kw( ecl_file , 2 );
|
||||
test_assert_NULL( kw2 );
|
||||
|
||||
test_assert_false( ecl_file_writable( ecl_file ));
|
||||
|
||||
ecl_file_close( ecl_file );
|
||||
|
||||
}
|
||||
|
||||
|
||||
void test_writable(const char * src_file ) {
|
||||
util_copy_file( src_file , "/tmp/ECL.UNRST" );
|
||||
{
|
||||
ecl_file_type * ecl_file = ecl_file_open( "/tmp/ECL.UNRST" , ECL_FILE_WRITABLE);
|
||||
ecl_kw_type * swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 );
|
||||
ecl_kw_type * swat0 = ecl_kw_alloc_copy( swat );
|
||||
test_assert_true( ecl_kw_equal( swat , swat0 ));
|
||||
ecl_kw_iset_float( swat , 0 , 1000.0 );
|
||||
ecl_file_save_kw( ecl_file , swat );
|
||||
test_assert_true( ecl_file_writable( ecl_file ));
|
||||
ecl_file_close( ecl_file );
|
||||
|
||||
ecl_file = ecl_file_open( "/tmp/ECL.UNRST" , 0);
|
||||
swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 );
|
||||
test_assert_true( util_double_approx_equal( ecl_kw_iget_float( swat , 0 ) , 1000 ));
|
||||
}
|
||||
util_unlink_existing( "/tmp/ECL.UNRST" );
|
||||
}
|
||||
|
||||
|
||||
int main( int argc , char ** argv) {
|
||||
|
||||
const char * src_file = argv[1];
|
||||
const char * filename = argv[2];
|
||||
char * target_file = util_alloc_filename("/tmp" , filename , NULL );
|
||||
|
||||
test_flags( src_file );
|
||||
test_loadall(src_file , target_file );
|
||||
test_close_stream1( src_file , target_file );
|
||||
test_close_stream2( src_file , target_file );
|
||||
test_writable( src_file );
|
||||
util_unlink_existing( target_file );
|
||||
|
||||
exit(0);
|
||||
}
|
82
ThirdParty/Ert/devel/libecl/tests/ecl_fmt.c
vendored
Normal file
82
ThirdParty/Ert/devel/libecl/tests/ecl_fmt.c
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
Copyright (C) 2012 Statoil ASA, Norway.
|
||||
|
||||
The file 'ecl_fmt.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <ert/util/util.h>
|
||||
#include <ert/util/test_util.h>
|
||||
|
||||
#include <ert/ecl/ecl_util.h>
|
||||
|
||||
void test_content( const char * src_file , bool fmt_file ) {
|
||||
char * base_name , *path;
|
||||
char * target_file;
|
||||
bool fmt;
|
||||
util_alloc_file_components( src_file , &path , &base_name , NULL);
|
||||
target_file = util_alloc_filename( "/tmp" , base_name , NULL );
|
||||
util_copy_file( src_file , target_file);
|
||||
|
||||
test_assert_true( ecl_util_fmt_file( target_file , &fmt ));
|
||||
test_assert_bool_equal( fmt , fmt_file );
|
||||
unlink( target_file );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void test_small( ) {
|
||||
bool fmt;
|
||||
|
||||
FILE * stream = util_fopen("/tmp/small.txt" , "w");
|
||||
fprintf(stream , "Some bytes\n");
|
||||
fclose( stream );
|
||||
|
||||
test_assert_false( ecl_util_fmt_file( "/tmp/small.txt" , &fmt ));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc , char ** argv) {
|
||||
const char * binary_file = argv[1];
|
||||
const char * text_file = argv[2];
|
||||
|
||||
|
||||
bool fmt_file;
|
||||
|
||||
test_assert_true( ecl_util_fmt_file( binary_file , &fmt_file ));
|
||||
test_assert_false( fmt_file );
|
||||
|
||||
test_assert_true( ecl_util_fmt_file( text_file , &fmt_file ));
|
||||
test_assert_true( fmt_file );
|
||||
|
||||
test_assert_true( ecl_util_fmt_file( "TEST.EGRID" , &fmt_file ));
|
||||
test_assert_false( fmt_file );
|
||||
|
||||
test_assert_true( ecl_util_fmt_file( "TEST.FEGRID" , &fmt_file ));
|
||||
test_assert_true( fmt_file );
|
||||
|
||||
test_assert_false(ecl_util_fmt_file( "TEST_DOES_NOT_EXIST" , &fmt_file ));
|
||||
|
||||
test_content( binary_file , false );
|
||||
test_content( text_file , true );
|
||||
test_small( );
|
||||
|
||||
exit(0);
|
||||
}
|
88
ThirdParty/Ert/devel/libecl/tests/ecl_fortio.c
vendored
Normal file
88
ThirdParty/Ert/devel/libecl/tests/ecl_fortio.c
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright (C) 2013 Statoil ASA, Norway.
|
||||
|
||||
The file 'ecl_fortio.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <ert/util/test_util.h>
|
||||
#include <ert/util/util.h>
|
||||
|
||||
#include <ert/ecl/fortio.h>
|
||||
#include <ert/ecl/ecl_endian_flip.h>
|
||||
|
||||
void test_existing_read(const char * filename) {
|
||||
fortio_type * fortio = fortio_open_reader( filename , false , ECL_ENDIAN_FLIP);
|
||||
test_assert_not_NULL( fortio );
|
||||
fortio_fclose( fortio );
|
||||
}
|
||||
|
||||
|
||||
void test_not_existing_read() {
|
||||
fortio_type * fortio = fortio_open_reader( "/does/not/exist" , false , ECL_ENDIAN_FLIP);
|
||||
test_assert_NULL( fortio );
|
||||
}
|
||||
|
||||
|
||||
void test_write( const char * filename , bool path_exists) {
|
||||
fortio_type * fortio = fortio_open_writer( filename , false , ECL_ENDIAN_FLIP);
|
||||
if (path_exists) {
|
||||
test_assert_not_NULL( fortio );
|
||||
fortio_fclose( fortio );
|
||||
} else
|
||||
test_assert_NULL( fortio );
|
||||
}
|
||||
|
||||
void test_wrapper( const char * filename ) {
|
||||
FILE * stream = util_fopen( filename , "r");
|
||||
fortio_type * fortio = fortio_alloc_FILE_wrapper( filename , false , false , stream );
|
||||
test_assert_not_NULL( fortio );
|
||||
test_assert_false( fortio_fclose_stream( fortio ));
|
||||
test_assert_false( fortio_fopen_stream( fortio ));
|
||||
test_assert_true( fortio_stream_is_open( fortio ));
|
||||
fortio_free_FILE_wrapper( fortio );
|
||||
fclose( stream );
|
||||
}
|
||||
|
||||
|
||||
void test_open_close_read( const char * filename ) {
|
||||
fortio_type * fortio = fortio_open_reader( filename , false , ECL_ENDIAN_FLIP);
|
||||
test_assert_not_NULL( fortio );
|
||||
|
||||
test_assert_true( fortio_stream_is_open( fortio ));
|
||||
test_assert_true( fortio_fclose_stream( fortio ));
|
||||
test_assert_false( fortio_stream_is_open( fortio ));
|
||||
test_assert_false( fortio_fclose_stream( fortio ));
|
||||
test_assert_true( fortio_fopen_stream( fortio ));
|
||||
test_assert_true( fortio_stream_is_open( fortio ));
|
||||
test_assert_false( fortio_fopen_stream( fortio ));
|
||||
|
||||
fortio_fclose( fortio );
|
||||
}
|
||||
|
||||
|
||||
int main( int argc , char ** argv) {
|
||||
const char * file = argv[1];
|
||||
|
||||
test_existing_read( file );
|
||||
test_not_existing_read( );
|
||||
test_write( "/tmp/file.x" , true );
|
||||
test_write( "/tmp/path/does/not/exist" , false );
|
||||
test_open_close_read( file );
|
||||
test_wrapper( file );
|
||||
|
||||
exit(0);
|
||||
}
|
87
ThirdParty/Ert/devel/libecl/tests/ecl_grid_dims.c
vendored
Normal file
87
ThirdParty/Ert/devel/libecl/tests/ecl_grid_dims.c
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
Copyright (C) 2013 Statoil ASA, Norway.
|
||||
|
||||
The file 'ecl_grid_dims.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <ert/util/test_util.h>
|
||||
#include <ert/util/util.h>
|
||||
|
||||
#include <ert/ecl/ecl_grid.h>
|
||||
#include <ert/ecl/ecl_grid_dims.h>
|
||||
|
||||
|
||||
|
||||
void test_grid( const char * grid_filename , const char * data_filename) {
|
||||
ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_filename );
|
||||
ecl_grid_dims_type * grid_dims = ecl_grid_dims_alloc( grid_filename, data_filename);
|
||||
|
||||
test_assert_not_NULL( grid_dims );
|
||||
test_assert_int_equal( ecl_grid_get_num_lgr( ecl_grid ) + 1 , ecl_grid_dims_get_num_grids( grid_dims ));
|
||||
for (int i=0; i < ecl_grid_dims_get_num_grids( grid_dims ); i++) {
|
||||
|
||||
grid_dims_type d1 = ecl_grid_iget_dims( ecl_grid , i);
|
||||
grid_dims_type * d2 = ecl_grid_dims_iget_dims( grid_dims , i );
|
||||
|
||||
test_assert_int_equal( d1.nx , d2->nx );
|
||||
test_assert_int_equal( d1.ny , d2->ny );
|
||||
test_assert_int_equal( d1.nz , d2->nz );
|
||||
|
||||
if (data_filename)
|
||||
test_assert_int_equal( d1.nactive , d2->nactive );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_dims() {
|
||||
grid_dims_type d1;
|
||||
grid_dims_type * d2 = grid_dims_alloc( 100 , 100 , 100 , 0);
|
||||
|
||||
grid_dims_init(&d1 , 100 , 100 , 100 , 0 );
|
||||
|
||||
test_assert_int_equal( d1.nx , d2->nx );
|
||||
test_assert_int_equal( d1.ny , d2->ny );
|
||||
test_assert_int_equal( d1.nz , d2->nz );
|
||||
test_assert_int_equal( d1.nactive , d2->nactive );
|
||||
|
||||
grid_dims_free( d2 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc , char ** argv) {
|
||||
signal(SIGSEGV , util_abort_signal); /* Segmentation violation, i.e. overwriting memory ... */
|
||||
|
||||
if (argc == 1) {
|
||||
ecl_grid_dims_type * grid_dims = ecl_grid_dims_alloc( argv[0] , NULL );
|
||||
test_assert_NULL( grid_dims );
|
||||
test_dims();
|
||||
} else {
|
||||
const char * GRID_file = argv[1];
|
||||
char * data_file;
|
||||
|
||||
if (argc == 3)
|
||||
data_file = argv[2];
|
||||
else
|
||||
data_file = NULL;
|
||||
|
||||
test_grid( GRID_file , data_file );
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
@ -40,7 +40,7 @@ int main(int argc , char ** argv) {
|
||||
bool OK = true;
|
||||
const char * unrst_file = argv[1];
|
||||
|
||||
ecl_file_type * rst_file = ecl_file_open( unrst_file );
|
||||
ecl_file_type * rst_file = ecl_file_open( unrst_file , 0);
|
||||
|
||||
OK = OK && test_get( rst_file , 1 , 1 , 1998 , -1 );
|
||||
OK = OK && test_get( rst_file , 17 , 9 , 2003 , -1 );
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
|
||||
void test_file( const char * filename , int occurence , bool exists , const ecl_rsthead_type * true_header) {
|
||||
ecl_file_type * rst_file = ecl_file_open( filename );
|
||||
ecl_file_type * rst_file = ecl_file_open( filename , 0);
|
||||
ecl_rsthead_type * rst_head = ecl_rsthead_ialloc( rst_file , occurence);
|
||||
|
||||
if (exists) {
|
||||
|
@ -334,7 +334,7 @@ void well_info_load_rstfile( well_info_type * well_info , const char * filename)
|
||||
ecl_file_enum file_type = ecl_util_get_file_type( filename , NULL , &report_nr);
|
||||
if ((file_type == ECL_RESTART_FILE) || (file_type == ECL_UNIFIED_RESTART_FILE))
|
||||
{
|
||||
ecl_file_type * ecl_file = ecl_file_open( filename );
|
||||
ecl_file_type * ecl_file = ecl_file_open( filename , 0);
|
||||
|
||||
if (file_type == ECL_RESTART_FILE)
|
||||
well_info_add_wells( well_info , ecl_file , report_nr );
|
||||
|
@ -173,7 +173,6 @@ static int well_state_get_lgr_well_nr( const well_state_type * well_state , cons
|
||||
well_nr = 0;
|
||||
while (true) {
|
||||
bool found = false;
|
||||
|
||||
{
|
||||
char * lgr_well_name = util_alloc_strip_copy( ecl_kw_iget_ptr( zwel_kw , well_nr * header->nzwelz) );
|
||||
|
||||
@ -184,6 +183,7 @@ static int well_state_get_lgr_well_nr( const well_state_type * well_state , cons
|
||||
|
||||
free( lgr_well_name );
|
||||
}
|
||||
|
||||
if (found)
|
||||
break;
|
||||
else if (well_nr == num_wells) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
add_executable( well_ts well_ts.c )
|
||||
target_link_libraries( well_ts ecl_well )
|
||||
add_test( well_ts ${EXECUTABLE_OUTPUT_PATH}/well_ts ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/CO2case/BASE_CASE )
|
||||
set_property( TEST well_ts PROPERTY LABELS Statoil )
|
||||
|
||||
|
||||
add_executable( well_dualp well_dualp.c )
|
||||
@ -12,5 +11,9 @@ add_test( well_dualp ${EXECUTABLE_OUTPUT_PATH}/well_dualp ${PROJECT_SOURCE_DIR}
|
||||
|
||||
add_executable( well_lgr_load well_lgr_load.c )
|
||||
target_link_libraries( well_lgr_load ecl_well )
|
||||
add_test( well_lgr_load ${EXECUTABLE_OUTPUT_PATH}/well_lgr_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003)
|
||||
set_property( TEST well_lgr_load PROPERTY LABELS Statoil )
|
||||
|
||||
add_test( well_lgr_load1 ${EXECUTABLE_OUTPUT_PATH}/well_lgr_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003)
|
||||
add_test( well_lgr_load2 ${EXECUTABLE_OUTPUT_PATH}/well_lgr_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.X0016)
|
||||
set_property( TEST well_lgr_load1 PROPERTY LABELS Statoil )
|
||||
set_property( TEST well_lgr_load2 PROPERTY LABELS Statoil )
|
||||
set_property( TEST well_ts PROPERTY LABELS Statoil )
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
|
||||
void test_rstfile( const char * filename , bool fracture_connection) {
|
||||
ecl_file_type * rst_file = ecl_file_open( filename );
|
||||
ecl_file_type * rst_file = ecl_file_open( filename , 0);
|
||||
const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0);
|
||||
ecl_rsthead_type * header = ecl_rsthead_alloc( rst_file );
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __CONFIG_KEYS_H__
|
||||
@ -23,7 +23,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* These keys are used as options in KEY:VALUE statements */
|
||||
/* These keys are used as options in KEY:VALUE statements */
|
||||
#define MIN_STD_KEY "MIN_STD"
|
||||
#define INIT_FILES_KEY "INIT_FILES"
|
||||
#define KEY_KEY "KEY"
|
||||
@ -104,10 +104,12 @@ extern "C" {
|
||||
#define LSF_QUEUE_KEY "LSF_QUEUE"
|
||||
#define LSF_RESOURCES_KEY "LSF_RESOURCES"
|
||||
#define LSF_SERVER_KEY "LSF_SERVER"
|
||||
#define TORQUE_QUEUE_KEY "TORQUE_QUEUE"
|
||||
#define MAX_RESAMPLE_KEY "MAX_RESAMPLE"
|
||||
#define MAX_RUNNING_LOCAL_KEY "MAX_RUNNING_LOCAL"
|
||||
#define MAX_RUNNING_LSF_KEY "MAX_RUNNING_LSF"
|
||||
#define MAX_RUNNING_RSH_KEY "MAX_RUNNING_RSH"
|
||||
#define MAX_RUNNING_TORQUE_KEY "MAX_RUNNING_TORQUE"
|
||||
#define MAX_SUBMIT_KEY "MAX_SUBMIT"
|
||||
#define NUM_REALIZATIONS_KEY "NUM_REALIZATIONS"
|
||||
#define OBS_CONFIG_KEY "OBS_CONFIG"
|
||||
|
@ -58,6 +58,8 @@ typedef struct site_config_struct site_config_type;
|
||||
int site_config_get_max_running_rsh( const site_config_type * site_config);
|
||||
void site_config_set_max_running_local( site_config_type * site_config , int max_running_local);
|
||||
int site_config_get_max_running_local( const site_config_type * site_config );
|
||||
void site_config_set_max_running_torque( site_config_type * site_config , int max_running_torque);
|
||||
int site_config_get_max_running_torque( const site_config_type * site_config );
|
||||
void site_config_setenv( site_config_type * site_config , const char * variable, const char * value);
|
||||
hash_type * site_config_get_env_hash( const site_config_type * site_config );
|
||||
void site_config_clear_env( site_config_type * site_config );
|
||||
|
@ -27,6 +27,15 @@ void enkf_main_exit_JOB(void * self , const stringlist_type * args ) {
|
||||
}
|
||||
|
||||
|
||||
void enkf_main_assimilation_JOB( void * self , const stringlist_type * args ) {
|
||||
enkf_main_type * enkf_main = enkf_main_safe_cast( self );
|
||||
int ens_size = enkf_main_get_ensemble_size( enkf_main );
|
||||
bool_vector_type * iactive = bool_vector_alloc( 0 , true );
|
||||
|
||||
bool_vector_iset( iactive , ens_size - 1 , true );
|
||||
enkf_main_run_assimilation( enkf_main , iactive , 0 , 0 , ANALYZED );
|
||||
}
|
||||
|
||||
|
||||
void enkf_main_ensemble_run_JOB( void * self , const stringlist_type * args ) {
|
||||
enkf_main_type * enkf_main = enkf_main_safe_cast( self );
|
||||
|
@ -121,7 +121,7 @@ typedef struct run_info_struct {
|
||||
typedef struct shared_info_struct {
|
||||
const model_config_type * model_config; /* .... */
|
||||
ext_joblist_type * joblist; /* The list of external jobs which are installed - and *how* they should be run (with Python code) */
|
||||
job_queue_type * job_queue; /* The queue handling external jobs. (i.e. LSF / rsh / local / ... )*/
|
||||
job_queue_type * job_queue; /* The queue handling external jobs. (i.e. LSF / TORQUE / rsh / local / ... )*/
|
||||
const site_config_type * site_config;
|
||||
log_type * logh; /* The log handle. */
|
||||
ert_templates_type * templates;
|
||||
@ -817,7 +817,7 @@ static void enkf_state_internalize_eclipse_state(enkf_state_type * enkf_state ,
|
||||
{
|
||||
char * filename = ecl_util_alloc_exfilename(run_info->run_path , member_config_get_eclbase(enkf_state->my_config) , ECL_RESTART_FILE , fmt_file , report_step);
|
||||
if (filename != NULL) {
|
||||
restart_file = ecl_file_open( filename );
|
||||
restart_file = ecl_file_open( filename , 0 );
|
||||
free(filename);
|
||||
} else
|
||||
restart_file = NULL; /* No restart information was found; if that is expected the program will fail hard in the enkf_node_forward_load() functions. */
|
||||
|
14
ThirdParty/Ert/devel/libenkf/src/field.c
vendored
14
ThirdParty/Ert/devel/libenkf/src/field.c
vendored
@ -1040,11 +1040,15 @@ void field_fload_ecl_kw(field_type * field , const char * filename ) {
|
||||
ecl_kw_type * ecl_kw;
|
||||
|
||||
{
|
||||
bool fmt_file = ecl_util_fmt_file(filename);
|
||||
fortio_type * fortio = fortio_open_reader(filename , fmt_file , ECL_ENDIAN_FLIP);
|
||||
ecl_kw_fseek_kw(key , true , true , fortio);
|
||||
ecl_kw = ecl_kw_fread_alloc( fortio );
|
||||
fortio_fclose(fortio);
|
||||
bool fmt_file;
|
||||
|
||||
if (ecl_util_fmt_file( filename , &fmt_file)) {
|
||||
fortio_type * fortio = fortio_open_reader(filename , fmt_file , ECL_ENDIAN_FLIP);
|
||||
ecl_kw_fseek_kw(key , true , true , fortio);
|
||||
ecl_kw = ecl_kw_fread_alloc( fortio );
|
||||
fortio_fclose(fortio);
|
||||
} else
|
||||
util_abort("%s: could not determine formatted/unformatted status of file:%s \n",filename);
|
||||
}
|
||||
|
||||
|
||||
|
@ -90,7 +90,7 @@ void local_context_create_surface_region( local_context_type * context , const c
|
||||
/*************************/
|
||||
|
||||
void local_context_load_file( local_context_type * context , const char * filename , const char * file_key ) {
|
||||
ecl_file_type * ecl_file = ecl_file_open( filename );
|
||||
ecl_file_type * ecl_file = ecl_file_open( filename , 0);
|
||||
hash_insert_hash_owned_ref( context->files , file_key , ecl_file , ecl_file_free__);
|
||||
}
|
||||
|
||||
|
12
ThirdParty/Ert/devel/libenkf/src/qc_module.c
vendored
12
ThirdParty/Ert/devel/libenkf/src/qc_module.c
vendored
@ -32,7 +32,7 @@
|
||||
#include <ert/enkf/runpath_list.h>
|
||||
|
||||
#define QC_WORKFLOW_NAME "QC"
|
||||
#define RUNPATH_LIST_FILE "/tmp/ert_runpath_list"
|
||||
#define RUNPATH_LIST_FILE ".ert_runpath_list"
|
||||
|
||||
|
||||
struct qc_module_struct {
|
||||
@ -54,7 +54,15 @@ qc_module_type * qc_module_alloc( ert_workflow_list_type * workflow_list , const
|
||||
qc_module->runpath_list = runpath_list_alloc();
|
||||
qc_module->runpath_list_file = NULL;
|
||||
qc_module_set_path( qc_module , qc_path );
|
||||
qc_module_set_runpath_list_file( qc_module , RUNPATH_LIST_FILE );
|
||||
{
|
||||
char * cwd = util_alloc_cwd();
|
||||
char * runpath_list_file = util_alloc_filename( cwd , RUNPATH_LIST_FILE , NULL);
|
||||
|
||||
qc_module_set_runpath_list_file( qc_module , runpath_list_file );
|
||||
|
||||
free( runpath_list_file );
|
||||
free( cwd );
|
||||
}
|
||||
return qc_module;
|
||||
}
|
||||
|
||||
|
1077
ThirdParty/Ert/devel/libenkf/src/site_config.c
vendored
1077
ThirdParty/Ert/devel/libenkf/src/site_config.c
vendored
File diff suppressed because it is too large
Load Diff
@ -3,4 +3,4 @@ STORE_SEED /tmp/seed2
|
||||
LOAD_SEED /tmp/seed2
|
||||
|
||||
-- The settings below here are artifacts which should not be necessary ...
|
||||
JOB_SCRIPT /private/joaho/ERT/Statoil/etc/ERT/Scripts/job_dispatch.py
|
||||
JOB_SCRIPT script.sh
|
||||
|
2
ThirdParty/Ert/devel/libenkf/tests/data/config/script.sh
vendored
Normal file
2
ThirdParty/Ert/devel/libenkf/tests/data/config/script.sh
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
#Dummy script
|
@ -26,6 +26,7 @@
|
||||
#include <ert/enkf/enkf_state.h>
|
||||
#include <ert/enkf/rng_config.h>
|
||||
|
||||
|
||||
int main(int argc , char ** argv) {
|
||||
unsigned int rand1,rand2;
|
||||
{
|
||||
@ -87,6 +88,7 @@ int main(int argc , char ** argv) {
|
||||
enkf_main_free( enkf_main );
|
||||
}
|
||||
test_assert_uint_equal( rand1 , rand2 );
|
||||
util_unlink_existing( seed_file );
|
||||
}
|
||||
/*****************************************************************/
|
||||
{
|
||||
|
@ -32,6 +32,10 @@ extern "C" {
|
||||
bool string_util_update_active_mask( const char * range_string , bool_vector_type * active_mask);
|
||||
bool_vector_type * string_util_alloc_active_mask( const char * range_string );
|
||||
|
||||
bool string_util_update_value_list( const char * range_string , int_vector_type * value_list);
|
||||
bool string_util_init_value_list( const char * range_string , int_vector_type * value_list );
|
||||
int_vector_type * string_util_alloc_value_list(const char * range_string);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -26,9 +26,12 @@ extern "C" {
|
||||
|
||||
|
||||
|
||||
|
||||
void test_error_exit( const char * fmt , ...);
|
||||
bool test_string_equal( const char * s1 , const char * s2 );
|
||||
|
||||
#define test_exit( fmt, ...) test_exit__( __FILE__ , __LINE__ , fmt , __VA_ARGS__);
|
||||
|
||||
#define test_assert_string_equal( s1 , s2 ) test_assert_string_equal__(s1 , s2 , __FILE__ , __LINE__)
|
||||
void test_assert_string_equal__( const char * s1 , const char * s2 , const char * file , int line);
|
||||
|
||||
|
@ -81,6 +81,7 @@ typedef @TYPE@ (@TYPE@_ftype) (@TYPE@);
|
||||
void @TYPE@_vector_set_many(@TYPE@_vector_type * , int , const @TYPE@ * , int );
|
||||
void @TYPE@_vector_set_all(@TYPE@_vector_type * vector , @TYPE@ value);
|
||||
void @TYPE@_vector_append_many(@TYPE@_vector_type * vector , const @TYPE@ * data , int length);
|
||||
void @TYPE@_vector_append_vector(@TYPE@_vector_type * vector , const @TYPE@_vector_type * other);
|
||||
void @TYPE@_vector_shrink(@TYPE@_vector_type * );
|
||||
@TYPE@ @TYPE@_vector_sum(const @TYPE@_vector_type * );
|
||||
@TYPE@ @TYPE@_vector_get_default(const @TYPE@_vector_type * );
|
||||
|
24
ThirdParty/Ert/devel/libert_util/src/hash.c
vendored
24
ThirdParty/Ert/devel/libert_util/src/hash.c
vendored
@ -94,31 +94,15 @@ static void __hash_deadlock_abort(hash_type * hash) {
|
||||
|
||||
static void __hash_rdlock(hash_type * hash) {
|
||||
int lock_error = pthread_rwlock_tryrdlock( &hash->rwlock );
|
||||
if (lock_error != 0) {
|
||||
/* We did not get the lock - let us check why: */
|
||||
if (lock_error == EDEADLK)
|
||||
/* A deadlock is detected - we just abort. */
|
||||
__hash_deadlock_abort(hash);
|
||||
else
|
||||
/* We ignore all other error conditions than DEADLOCK and just try again. */
|
||||
pthread_rwlock_rdlock( &hash->rwlock );
|
||||
}
|
||||
/* Ok - when we are here - we are guranteed to have the lock. */
|
||||
if (lock_error != 0)
|
||||
util_abort("%s: did not get hash->read_lock - fix locking in calling scope\n",__func__);
|
||||
}
|
||||
|
||||
|
||||
static void __hash_wrlock(hash_type * hash) {
|
||||
int lock_error = pthread_rwlock_trywrlock( &hash->rwlock );
|
||||
if (lock_error != 0) {
|
||||
/* We did not get the lock - let us check why: */
|
||||
if (lock_error == EDEADLK)
|
||||
/* A deadlock is detected - we just abort. */
|
||||
__hash_deadlock_abort(hash);
|
||||
else
|
||||
/* We ignore all other error conditions than DEADLOCK and just try again. */
|
||||
pthread_rwlock_wrlock( &hash->rwlock );
|
||||
}
|
||||
/* Ok - when we are here - we are guranteed to have the lock. */
|
||||
if (lock_error != 0)
|
||||
util_abort("%s: did not get hash->write_lock - fix locking in calling scope\n",__func__);
|
||||
}
|
||||
|
||||
|
||||
|
@ -206,3 +206,31 @@ bool_vector_type * string_util_alloc_active_mask( const char * range_string ) {
|
||||
string_util_init_active_mask( range_string , mask );
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
|
||||
bool string_util_update_value_list( const char * range_string , int_vector_type * value_list) {
|
||||
int_vector_type * new_values = string_util_sscanf_alloc_active_list( range_string );
|
||||
if (new_values) {
|
||||
int_vector_append_vector( value_list , new_values);
|
||||
int_vector_free( new_values );
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool string_util_init_value_list( const char * range_string , int_vector_type * value_list ) {
|
||||
int_vector_reset( value_list );
|
||||
return string_util_update_value_list( range_string , value_list );
|
||||
}
|
||||
|
||||
|
||||
int_vector_type * string_util_alloc_value_list(const char * range_string) {
|
||||
int_vector_type * value_list = int_vector_alloc(0,0);
|
||||
string_util_init_value_list( range_string , value_list);
|
||||
return value_list;
|
||||
}
|
||||
|
18
ThirdParty/Ert/devel/libert_util/src/test_util.c
vendored
18
ThirdParty/Ert/devel/libert_util/src/test_util.c
vendored
@ -26,18 +26,32 @@
|
||||
#include <ert/util/util.h>
|
||||
#include <ert/util/test_util.h>
|
||||
|
||||
|
||||
void test_error_exit( const char * fmt , ...) {
|
||||
char * s;
|
||||
va_list ap;
|
||||
va_start(ap , fmt);
|
||||
s = util_alloc_sprintf_va(fmt , ap);
|
||||
va_end(ap);
|
||||
|
||||
fprintf( stderr , s );
|
||||
fprintf(stderr , s );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
void test_exit__(const char * file , int line , const char * fmt , ...) {
|
||||
fprintf(stderr , "Error at %s:%d:\n",file,line);
|
||||
{
|
||||
char * s;
|
||||
va_list ap;
|
||||
va_start(ap , fmt);
|
||||
s = util_alloc_sprintf_va(fmt , ap);
|
||||
va_end(ap);
|
||||
fprintf(stderr , s );
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool test_string_equal( const char * s1 , const char * s2 ) {
|
||||
bool equal = true;
|
||||
if (s1 == NULL && s2 == NULL)
|
||||
|
@ -801,6 +801,10 @@ void @TYPE@_vector_append_many(@TYPE@_vector_type * vector , const @TYPE@ * data
|
||||
@TYPE@_vector_set_many( vector , @TYPE@_vector_size( vector ) , data , length);
|
||||
}
|
||||
|
||||
void @TYPE@_vector_append_vector(@TYPE@_vector_type * vector , const @TYPE@_vector_type * other) {
|
||||
@TYPE@_vector_append_many( vector , @TYPE@_vector_get_const_ptr( other ), @TYPE@_vector_size( other ));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This will realloc the vector so that alloc_size exactly matches
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <ert/util/int_vector.h>
|
||||
#include <ert/util/bool_vector.h>
|
||||
@ -24,6 +25,22 @@
|
||||
#include <ert/util/string_util.h>
|
||||
|
||||
|
||||
void test_int_vector(const int_vector_type * list , int length , ...) {
|
||||
va_list ap;
|
||||
int i;
|
||||
va_start(ap , length);
|
||||
test_assert_int_equal( length , int_vector_size( list ));
|
||||
|
||||
for (i =0; i < int_vector_size( list ); i++) {
|
||||
int value = va_arg(ap , int);
|
||||
test_assert_int_equal( int_vector_iget( list , i ) , value);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void test1( const int_vector_type * active_list ) {
|
||||
test_assert_int_equal( int_vector_size( active_list ), 10 );
|
||||
test_assert_int_equal( int_vector_iget( active_list , 0 ) , 1 );
|
||||
@ -36,29 +53,22 @@ static void test1( const int_vector_type * active_list ) {
|
||||
void test_active_list() {
|
||||
int_vector_type * active_list = string_util_alloc_active_list("1,3- 10,15");
|
||||
test_assert_true( string_util_init_active_list("1,3- 10,15" , active_list) );
|
||||
test1( active_list );
|
||||
test_int_vector( active_list , 10 , 1,3,4,5,6,7,8,9,10,15);
|
||||
|
||||
test_assert_true( string_util_update_active_list("1,3- 10,15,8" , active_list) );
|
||||
test1( active_list );
|
||||
test_int_vector( active_list , 10 , 1,3,4,5,6,7,8,9,10,15);
|
||||
|
||||
test_assert_false( string_util_update_active_list("1,X" , active_list) );
|
||||
test1( active_list );
|
||||
test_int_vector( active_list , 10 , 1,3,4,5,6,7,8,9,10,15);
|
||||
|
||||
test_assert_true( string_util_update_active_list("14-16" , active_list) );
|
||||
test_assert_int_equal( int_vector_size( active_list ) , 12);
|
||||
test_assert_int_equal( int_vector_iget( active_list , 9 ) ,14 );
|
||||
test_assert_int_equal( int_vector_iget( active_list , 11 ) ,16 );
|
||||
test_int_vector( active_list , 12 , 1,3,4,5,6,7,8,9,10,14,15,16);
|
||||
|
||||
test_assert_true( string_util_update_active_list("0" , active_list) );
|
||||
test_assert_int_equal( int_vector_size( active_list ) , 13);
|
||||
test_assert_int_equal( int_vector_iget( active_list , 0 ) ,0 );
|
||||
test_assert_int_equal( int_vector_iget( active_list , 10 ) ,14 );
|
||||
test_assert_int_equal( int_vector_iget( active_list , 12 ) ,16 );
|
||||
test_int_vector( active_list , 13 , 0,1,3,4,5,6,7,8,9,10,14,15,16);
|
||||
|
||||
test_assert_true( string_util_update_active_list("4-6" , active_list) );
|
||||
test_assert_int_equal( int_vector_size( active_list ) , 13);
|
||||
test_assert_int_equal( int_vector_iget( active_list , 0 ) ,0 );
|
||||
test_assert_int_equal( int_vector_iget( active_list , 10 ) ,14 );
|
||||
test_assert_int_equal( int_vector_iget( active_list , 12 ) ,16 );
|
||||
test_int_vector( active_list , 13 , 0,1,3,4,5,6,7,8,9,10,14,15,16);
|
||||
}
|
||||
|
||||
|
||||
@ -91,9 +101,48 @@ void test_active_mask() {
|
||||
test2( active_mask );
|
||||
|
||||
bool_vector_free( active_mask );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void test_value_list() {
|
||||
{
|
||||
int_vector_type * int_vector = string_util_alloc_value_list("1,2,4-7");
|
||||
test_int_vector( int_vector , 6 , 1,2,4,5,6,7);
|
||||
int_vector_free( int_vector );
|
||||
}
|
||||
|
||||
{
|
||||
int_vector_type * int_vector = string_util_alloc_value_list("1,2,X");
|
||||
test_int_vector( int_vector , 0);
|
||||
int_vector_free( int_vector );
|
||||
}
|
||||
|
||||
{
|
||||
int_vector_type * int_vector = string_util_alloc_value_list("1,2,4-7");
|
||||
test_int_vector( int_vector , 6 , 1,2,4,5,6,7);
|
||||
test_assert_false( string_util_update_value_list("1,2,X" , int_vector ));
|
||||
int_vector_free( int_vector );
|
||||
}
|
||||
|
||||
{
|
||||
int_vector_type * int_vector = string_util_alloc_value_list("5,5,5,5");
|
||||
test_int_vector( int_vector , 4,5,5,5,5);
|
||||
test_assert_true( string_util_update_value_list("1-5" , int_vector ));
|
||||
test_int_vector( int_vector , 9,5,5,5,5,1,2,3,4,5 );
|
||||
test_assert_true( string_util_update_value_list("1-5" , int_vector ));
|
||||
test_int_vector( int_vector , 14,5,5,5,5,1,2,3,4,5,1,2,3,4,5 );
|
||||
int_vector_free( int_vector );
|
||||
}
|
||||
|
||||
{
|
||||
int_vector_type * int_vector = int_vector_alloc(0 , 77 );
|
||||
int_vector_append(int_vector , 125 );
|
||||
string_util_init_value_list("1-5" , int_vector );
|
||||
test_int_vector( int_vector , 5,1,2,3,4,5);
|
||||
int_vector_free( int_vector );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -102,5 +151,6 @@ void test_active_mask() {
|
||||
int main(int argc , char ** argv) {
|
||||
test_active_list();
|
||||
test_active_mask();
|
||||
test_value_list();
|
||||
exit(0);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2012 Statoil ASA, Norway.
|
||||
Copyri ght (C) 2012 Statoil ASA, Norway.
|
||||
|
||||
The file 'ert_util_type_vector_test.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
@ -75,5 +75,30 @@ int main(int argc , char ** argv) {
|
||||
test_assert_int_equal( int_vector_iget( int_vector , 3 ) , 445);
|
||||
test_assert_int_equal( int_vector_get_last( int_vector ) , 1000);
|
||||
|
||||
{
|
||||
int_vector_type * v1 = int_vector_alloc(0,0);
|
||||
int_vector_type * v2 = int_vector_alloc(0,0);
|
||||
int_vector_append(v1 , 10);
|
||||
int_vector_append(v1 , 15);
|
||||
int_vector_append(v1 , 20);
|
||||
|
||||
int_vector_append(v2 , 1);
|
||||
int_vector_append(v2 , 2);
|
||||
int_vector_append(v2 , 3);
|
||||
|
||||
int_vector_append_vector( v1 , v2 );
|
||||
test_assert_int_equal( int_vector_size( v1 ) , 6 );
|
||||
test_assert_int_equal( int_vector_iget (v1 , 0 ), 10 );
|
||||
test_assert_int_equal( int_vector_iget (v1 , 1 ), 15 );
|
||||
test_assert_int_equal( int_vector_iget (v1 , 2 ), 20 );
|
||||
|
||||
test_assert_int_equal( int_vector_iget (v1 , 3 ), 1 );
|
||||
test_assert_int_equal( int_vector_iget (v1 , 4 ), 2 );
|
||||
test_assert_int_equal( int_vector_iget (v1 , 5 ), 3 );
|
||||
|
||||
int_vector_free( v1 );
|
||||
int_vector_free( v2 );
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ extern "C" {
|
||||
void job_queue_submit_complete( job_queue_type * queue );
|
||||
job_driver_type job_queue_get_driver_type( const job_queue_type * queue );
|
||||
void job_queue_set_driver(job_queue_type * queue , queue_driver_type * driver);
|
||||
bool job_queue_has_driver(const job_queue_type * queue );
|
||||
//void job_queue_set_size( job_queue_type * job_queue , int size );
|
||||
void job_queue_set_runpath_fmt(job_queue_type * , const path_fmt_type * );
|
||||
job_queue_type * job_queue_alloc( int , const char * ok_file , const char * exit_file);
|
||||
|
@ -42,7 +42,6 @@ extern "C" {
|
||||
void local_driver_free__(void * __driver );
|
||||
job_status_type local_driver_get_job_status(void * __driver , void * __job);
|
||||
void local_driver_free_job(void * __job);
|
||||
bool local_driver_set_option( void * __driver , const char * option_key , const void * value);
|
||||
|
||||
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef __QUEUE_DRIVER_H__
|
||||
#define __QUEUE_DRIVER_H__
|
||||
@ -24,37 +24,42 @@ extern "C" {
|
||||
|
||||
#include <ert/util/hash.h>
|
||||
|
||||
typedef enum { NULL_DRIVER = 0,
|
||||
LSF_DRIVER = 1,
|
||||
LOCAL_DRIVER = 2,
|
||||
RSH_DRIVER = 3} job_driver_type;
|
||||
typedef enum {
|
||||
NULL_DRIVER = 0,
|
||||
LSF_DRIVER = 1,
|
||||
LOCAL_DRIVER = 2,
|
||||
RSH_DRIVER = 3,
|
||||
TORQUE_DRIVER = 4
|
||||
} job_driver_type;
|
||||
|
||||
#define JOB_DRIVER_ENUM_DEFS \
|
||||
{.value = 0 , .name = "NULL_DRIVER"}, \
|
||||
{.value = 1 , .name = "LSF_DRIVER"}, \
|
||||
{.value = 2 , .name = "LOCAL_DRIVER"}, \
|
||||
{.value = 3 , .name = "RSH_DRIVER"}
|
||||
#define JOB_DRIVER_ENUM_SIZE 4
|
||||
{.value = 3 , .name = "RSH_DRIVER"}, \
|
||||
{.value = 4 , .name = "TORQUE_DRIVER"}
|
||||
|
||||
#define JOB_DRIVER_ENUM_SIZE 5
|
||||
|
||||
|
||||
typedef enum { JOB_QUEUE_NOT_ACTIVE = 1 , /* This value is used in external query routines - for jobs which are (currently) not active. */
|
||||
//JOB_QUEUE_LOADING = 2 , /* This value is used by external routines. Not used in the libjob_queue implementation. */
|
||||
JOB_QUEUE_WAITING = 4 , /* A node which is waiting in the internal queue. */
|
||||
JOB_QUEUE_SUBMITTED = 8 , /* Internal status: It has has been submitted - the next status update will (should) place it as pending or running. */
|
||||
JOB_QUEUE_PENDING = 16 , /* A node which is pending - a status returned by the external system. I.e LSF */
|
||||
JOB_QUEUE_RUNNING = 32 , /* The job is running */
|
||||
JOB_QUEUE_DONE = 64 , /* The job is done - but we have not yet checked if the target file is produced */
|
||||
JOB_QUEUE_EXIT = 128 , /* The job has exited - check attempts to determine if we retry or go to complete_fail */
|
||||
//JOB_QUEUE_RUN_OK = 256 , /* The job has completed - and all checks performed by the queue layer indicate success. */
|
||||
//JOB_QUEUE_RUN_FAIL = 512 , /* The job has completed - but the queue system has detected that it has failed. */
|
||||
//JOB_QUEUE_ALL_OK = 1024 , /* The job has loaded OK - observe that it is the calling scope which will set the status to this. */
|
||||
//JOB_QUEUE_ALL_FAIL = 2048 , /* The job has failed completely - the calling scope must set this status. */
|
||||
JOB_QUEUE_USER_KILLED = 4096 , /* The job has been killed by the user - can restart. */
|
||||
JOB_QUEUE_USER_EXIT = 8192 , /* The whole job_queue has been exited by the user - the job can NOT be restarted. */
|
||||
JOB_QUEUE_SUCCESS = 16384 ,
|
||||
JOB_QUEUE_RUNNING_CALLBACK = 32768 ,
|
||||
JOB_QUEUE_FAILED = 65536 } job_status_type;
|
||||
typedef enum {
|
||||
JOB_QUEUE_NOT_ACTIVE = 1, /* This value is used in external query routines - for jobs which are (currently) not active. */
|
||||
//JOB_QUEUE_LOADING = 2 , /* This value is used by external routines. Not used in the libjob_queue implementation. */
|
||||
JOB_QUEUE_WAITING = 4, /* A node which is waiting in the internal queue. */
|
||||
JOB_QUEUE_SUBMITTED = 8, /* Internal status: It has has been submitted - the next status update will (should) place it as pending or running. */
|
||||
JOB_QUEUE_PENDING = 16, /* A node which is pending - a status returned by the external system. I.e LSF */
|
||||
JOB_QUEUE_RUNNING = 32, /* The job is running */
|
||||
JOB_QUEUE_DONE = 64, /* The job is done - but we have not yet checked if the target file is produced */
|
||||
JOB_QUEUE_EXIT = 128, /* The job has exited - check attempts to determine if we retry or go to complete_fail */
|
||||
//JOB_QUEUE_RUN_OK = 256 , /* The job has completed - and all checks performed by the queue layer indicate success. */
|
||||
//JOB_QUEUE_RUN_FAIL = 512 , /* The job has completed - but the queue system has detected that it has failed. */
|
||||
//JOB_QUEUE_ALL_OK = 1024 , /* The job has loaded OK - observe that it is the calling scope which will set the status to this. */
|
||||
//JOB_QUEUE_ALL_FAIL = 2048 , /* The job has failed completely - the calling scope must set this status. */
|
||||
JOB_QUEUE_USER_KILLED = 4096, /* The job has been killed by the user - can restart. */
|
||||
JOB_QUEUE_USER_EXIT = 8192, /* The whole job_queue has been exited by the user - the job can NOT be restarted. */
|
||||
JOB_QUEUE_SUCCESS = 16384,
|
||||
JOB_QUEUE_RUNNING_CALLBACK = 32768,
|
||||
JOB_QUEUE_FAILED = 65536
|
||||
} job_status_type;
|
||||
|
||||
#define JOB_QUEUE_MAX_STATE 12
|
||||
|
||||
@ -79,20 +84,20 @@ typedef enum { JOB_QUEUE_NOT_ACTIVE = 1 , /* This value is used in
|
||||
#define JOB_STATUS_ENUM_SIZE JOB_QUEUE_MAX_STATE
|
||||
|
||||
|
||||
/*
|
||||
All jobs which are in the status set defined by
|
||||
JOB_QUEUE_CAN_RESTART can be restarted based on external
|
||||
user-input. It is OK to try to restart a job which is not in this
|
||||
state - basically nothing should happen.
|
||||
*/
|
||||
/*
|
||||
All jobs which are in the status set defined by
|
||||
JOB_QUEUE_CAN_RESTART can be restarted based on external
|
||||
user-input. It is OK to try to restart a job which is not in this
|
||||
state - basically nothing should happen.
|
||||
*/
|
||||
#define JOB_QUEUE_CAN_RESTART (JOB_QUEUE_FAILED + JOB_QUEUE_USER_KILLED + JOB_QUEUE_SUCCESS)
|
||||
|
||||
|
||||
/*
|
||||
These are the jobs which can be killed. It is OK to try to kill a
|
||||
job which is not in this state, the only thing happening is that the
|
||||
function job_queue_kill_simulation() wil return false.
|
||||
*/
|
||||
/*
|
||||
These are the jobs which can be killed. It is OK to try to kill a
|
||||
job which is not in this state, the only thing happening is that the
|
||||
function job_queue_kill_simulation() wil return false.
|
||||
*/
|
||||
#define JOB_QUEUE_CAN_KILL (JOB_QUEUE_WAITING + JOB_QUEUE_RUNNING + JOB_QUEUE_PENDING + JOB_QUEUE_SUBMITTED)
|
||||
|
||||
|
||||
@ -103,38 +108,38 @@ typedef enum { JOB_QUEUE_NOT_ACTIVE = 1 , /* This value is used in
|
||||
|
||||
typedef struct queue_driver_struct queue_driver_type;
|
||||
|
||||
typedef void * (submit_job_ftype) (void * data , const char * cmd , int num_cpu , const char * run_path , const char * job_name , int argc , const char ** argv);
|
||||
typedef void (kill_job_ftype) (void * , void * );
|
||||
typedef job_status_type (get_status_ftype) (void * , void * );
|
||||
typedef void (free_job_ftype) (void * );
|
||||
typedef void (free_queue_driver_ftype) (void *);
|
||||
typedef bool (set_option_ftype) (void * , const char* , const void * );
|
||||
typedef const void * (get_option_ftype) (const void * , const char * );
|
||||
typedef bool (has_option_ftype) (const void * , const char * );
|
||||
typedef void * (submit_job_ftype) (void * data, const char * cmd, int num_cpu, const char * run_path, const char * job_name, int argc, const char ** argv);
|
||||
typedef void (kill_job_ftype) (void *, void *);
|
||||
typedef job_status_type(get_status_ftype) (void *, void *);
|
||||
typedef void (free_job_ftype) (void *);
|
||||
typedef void (free_queue_driver_ftype) (void *);
|
||||
typedef bool (set_option_ftype) (void *, const char*, const void *);
|
||||
typedef const void * (get_option_ftype) (const void *, const char *);
|
||||
typedef bool (has_option_ftype) (const void *, const char *);
|
||||
|
||||
|
||||
queue_driver_type * queue_driver_alloc_RSH( const char * rsh_cmd , const hash_type * rsh_hostlist);
|
||||
queue_driver_type * queue_driver_alloc_LSF(const char * queue_name , const char * resource_request , const char * remote_lsf_server);
|
||||
queue_driver_type * queue_driver_alloc_local( );
|
||||
queue_driver_type * queue_driver_alloc( job_driver_type type );
|
||||
queue_driver_type * queue_driver_alloc_RSH(const char * rsh_cmd, const hash_type * rsh_hostlist);
|
||||
queue_driver_type * queue_driver_alloc_LSF(const char * queue_name, const char * resource_request, const char * remote_lsf_server);
|
||||
queue_driver_type * queue_driver_alloc_TORQUE();
|
||||
queue_driver_type * queue_driver_alloc_local();
|
||||
queue_driver_type * queue_driver_alloc(job_driver_type type);
|
||||
|
||||
void * queue_driver_submit_job( queue_driver_type * driver, const char * run_cmd , int num_cpu , const char * run_path , const char * job_name , int argc , const char ** argv);
|
||||
void queue_driver_free_job( queue_driver_type * driver , void * job_data );
|
||||
void queue_driver_kill_job( queue_driver_type * driver , void * job_data );
|
||||
job_status_type queue_driver_get_status( queue_driver_type * driver , void * job_data);
|
||||
void * queue_driver_submit_job(queue_driver_type * driver, const char * run_cmd, int num_cpu, const char * run_path, const char * job_name, int argc, const char ** argv);
|
||||
void queue_driver_free_job(queue_driver_type * driver, void * job_data);
|
||||
void queue_driver_kill_job(queue_driver_type * driver, void * job_data);
|
||||
job_status_type queue_driver_get_status(queue_driver_type * driver, void * job_data);
|
||||
|
||||
void queue_driver_set_max_running( queue_driver_type * driver , int max_running);
|
||||
int queue_driver_get_max_running( const queue_driver_type * driver );
|
||||
const char * queue_driver_get_name( const queue_driver_type * driver );
|
||||
void queue_driver_set_max_running(queue_driver_type * driver, int max_running);
|
||||
int queue_driver_get_max_running(const queue_driver_type * driver);
|
||||
const char * queue_driver_get_name(const queue_driver_type * driver);
|
||||
|
||||
bool queue_driver_set_option( queue_driver_type * driver , const char * option_key , const void * value);
|
||||
bool queue_driver_set_int_option( queue_driver_type * driver , const char * option_key , int int_value);
|
||||
const void * queue_driver_get_option( queue_driver_type * driver , const char * option_key );
|
||||
bool queue_driver_set_option(queue_driver_type * driver, const char * option_key, const void * value);
|
||||
const void * queue_driver_get_option(queue_driver_type * driver, const char * option_key);
|
||||
|
||||
void queue_driver_free( queue_driver_type * driver );
|
||||
void queue_driver_free__( void * driver );
|
||||
const char * queue_driver_type_enum_iget( int index, int * value);
|
||||
const char * queue_driver_status_emun_iget( int index, int * value);
|
||||
void queue_driver_free(queue_driver_type * driver);
|
||||
void queue_driver_free__(void * driver);
|
||||
const char * queue_driver_type_enum_iget(int index, int * value);
|
||||
const char * queue_driver_status_emun_iget(int index, int * value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
78
ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/torque_driver.h
vendored
Normal file
78
ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/torque_driver.h
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
Copyright (C) 2013 Statoil ASA, Norway.
|
||||
|
||||
The file 'torque_driver.h' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
#ifndef TORQUE_DRIVER_H
|
||||
#define TORQUE_DRIVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <ert/util/type_macros.h>
|
||||
#include <ert/job_queue/queue_driver.h>
|
||||
|
||||
/*
|
||||
The options supported by the Torque driver.
|
||||
*/
|
||||
#define TORQUE_QSUB_CMD "QSUB_CMD"
|
||||
#define TORQUE_QSTAT_CMD "QSTAT_CMD"
|
||||
#define TORQUE_QDEL_CMD "QDEL_CMD"
|
||||
#define TORQUE_QUEUE "QUEUE"
|
||||
#define TORQUE_NUM_CPUS_PER_NODE "NUM_CPUS_PER_NODE"
|
||||
#define TORQUE_NUM_NODES "NUM_NODES"
|
||||
#define TORQUE_KEEP_QSUB_OUTPUT "KEEP_QSUB_OUTPUT"
|
||||
|
||||
#define TORQUE_DEFAULT_QSUB_CMD "qsub"
|
||||
#define TORQUE_DEFAULT_QSTAT_CMD "qstat"
|
||||
#define TORQUE_DEFAULT_QDEL_CMD "qdel"
|
||||
|
||||
|
||||
typedef struct torque_driver_struct torque_driver_type;
|
||||
typedef struct torque_job_struct torque_job_type;
|
||||
|
||||
|
||||
void * torque_driver_alloc();
|
||||
|
||||
|
||||
void * torque_driver_submit_job(void * __driver,
|
||||
const char * submit_cmd,
|
||||
int num_cpu,
|
||||
const char * run_path,
|
||||
const char * job_name,
|
||||
int argc,
|
||||
const char ** argv);
|
||||
|
||||
void torque_driver_kill_job(void * __driver, void * __job);
|
||||
void torque_driver_free__(void * __driver);
|
||||
void torque_driver_free(torque_driver_type * driver);
|
||||
job_status_type torque_driver_get_job_status(void * __driver, void * __job);
|
||||
void torque_driver_free_job(void * __job);
|
||||
void torque_driver_set_qstat_refresh_interval(torque_driver_type * driver, int refresh_interval);
|
||||
|
||||
const void * torque_driver_get_option(const void * __driver, const char * option_key);
|
||||
bool torque_driver_set_option(void * __driver, const char * option_key, const void * value);
|
||||
|
||||
void torque_job_create_submit_script(const char * run_path, const char * submit_cmd, int argc, const char ** job_argv);
|
||||
|
||||
UTIL_SAFE_CAST_HEADER(torque_driver);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TORQUE_DRIVER_H */
|
||||
|
@ -1,7 +1,7 @@
|
||||
#configure_file (${CMAKE_CURRENT_SOURCE_DIR}/CMake/include/libjob_queue_build_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/libjob_queue_build_config.h)
|
||||
|
||||
set(source_files forward_model.c queue_driver.c job_queue.c local_driver.c rsh_driver.c ext_job.c ext_joblist.c workflow_job.c workflow.c workflow_joblist.c)
|
||||
set(header_files job_queue.h queue_driver.h local_driver.h rsh_driver.h ext_job.h ext_joblist.h forward_model.h workflow_job.h workflow.h workflow_joblist.h)
|
||||
set(source_files forward_model.c queue_driver.c job_queue.c local_driver.c rsh_driver.c torque_driver.c ext_job.c ext_joblist.c workflow_job.c workflow.c workflow_joblist.c)
|
||||
set(header_files job_queue.h queue_driver.h local_driver.h rsh_driver.h torque_driver.h ext_job.h ext_joblist.h forward_model.h workflow_job.h workflow.h workflow_joblist.h)
|
||||
|
||||
if (USE_LSF)
|
||||
list( APPEND source_files lsf_driver.c)
|
||||
|
@ -194,14 +194,6 @@ void * local_driver_alloc() {
|
||||
return local_driver;
|
||||
}
|
||||
|
||||
|
||||
bool local_driver_set_option( void * __driver , const char * option_key , const void * value){
|
||||
local_driver_type * driver = local_driver_safe_cast( __driver );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#undef LOCAL_DRIVER_ID
|
||||
#undef LOCAL_JOB_ID
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
Copyright (C) 2011 Statoil ASA, Norway.
|
||||
|
||||
The file 'lsf_driver_impl.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
The file 'lsf_driver.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -668,9 +668,9 @@ void * lsf_driver_submit_job(void * __driver ,
|
||||
pthread_mutex_lock( &driver->submit_lock );
|
||||
|
||||
if (submit_method == LSF_SUBMIT_INTERNAL) {
|
||||
job->lsf_jobnr = lsf_driver_submit_internal_job( driver , run_path , job_name , submit_cmd , num_cpu , argc, argv);
|
||||
job->lsf_jobnr = lsf_driver_submit_internal_job( driver , lsf_stdout , job_name , submit_cmd , num_cpu , argc, argv);
|
||||
} else {
|
||||
job->lsf_jobnr = lsf_driver_submit_shell_job( driver , run_path , job_name , submit_cmd , num_cpu , argc, argv);
|
||||
job->lsf_jobnr = lsf_driver_submit_shell_job( driver , lsf_stdout , job_name , submit_cmd , num_cpu , argc, argv);
|
||||
job->lsf_jobnr_char = util_alloc_sprintf("%ld" , job->lsf_jobnr);
|
||||
hash_insert_ref( driver->my_jobs , job->lsf_jobnr_char , NULL );
|
||||
}
|
||||
|
@ -1,867 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2011 Statoil ASA, Norway.
|
||||
|
||||
The file 'lsf_driver_impl.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <ert/util/util.h>
|
||||
#include <ert/util/hash.h>
|
||||
#include <ert/util/stringlist.h>
|
||||
|
||||
|
||||
#include <lsf/lsbatch.h>
|
||||
|
||||
#include <ert/job_queue/queue_driver.h>
|
||||
#include <ert/job_queue/lsf_driver.h>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Documentation/examples of programming towards the lsf libraries can
|
||||
be found in /prog/LSF/7.0/misc/examples
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
How to call the lsf commands bsub/bjobs/bkill:
|
||||
----------------------------------------------
|
||||
|
||||
The commands to submit, monitor and modify LSF jobs are available
|
||||
through library calls through the lsf library. This is a good
|
||||
solution which works well.
|
||||
|
||||
Unfortunately only quite few of the workstations in Statoil are
|
||||
"designated LSF machines", meaning that they are allowed to talk to
|
||||
the LIM servers, to be able to use the low-level lsb_xxx() function
|
||||
calls the host making the calls must configured (by an LSF
|
||||
administrator) to be a LSF client.
|
||||
|
||||
The lsf_driver can either make use of the proper lsf library calls
|
||||
(lsb_submit(), lsb_openjobinfo(), ...) or alternatively it can issue
|
||||
ssh calls to an external LSF_SERVER and call up the bsub/bkill/bjob
|
||||
executables on the remote server.
|
||||
|
||||
All the functions with 'library' in the name are based on library
|
||||
calls, and the functions with 'shell' in the name are based on
|
||||
external functions (the actual calls are through the
|
||||
util_fork_exec() function).
|
||||
|
||||
By default the driver will use the library, but if a value is
|
||||
provided with the LSF_SERVER option, the shell based functions will
|
||||
be used. Internally this is goverened by the boolean flag
|
||||
'use_library_calls'.
|
||||
|
||||
Even though you only intend to submit through the shell commands
|
||||
bsub / bjobs / bkill the build process still requires access to the
|
||||
lsf headers and the lsf library; that is probably not optimal.
|
||||
|
||||
|
||||
Remote login shell
|
||||
------------------
|
||||
|
||||
When submitting with LSF the job will inherit the current
|
||||
environment on the submitting host, and not read the users login
|
||||
files on the remote host where the job is actually executed. E.g. in
|
||||
situations where submitting host and executing host are
|
||||
e.g. different operating system versions this might be
|
||||
unfortunate. The '-L @shell' switch can used with bsub to force lsf
|
||||
to source schell specific input files prior to executing your
|
||||
job. This can be achieved with the LSF_LOGIN_SHELL option:
|
||||
|
||||
lsf_driver_set_option( driver , LSF_LOGIN_SHELL , "/bin/csh" );
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define LSF_DRIVER_TYPE_ID 10078365
|
||||
#define LSF_JOB_TYPE_ID 9963900
|
||||
#define BJOBS_REFRESH_TIME 10
|
||||
#define DEFAULT_RSH_CMD "/usr/bin/ssh"
|
||||
#define DEFAULT_BSUB_CMD "bsub"
|
||||
#define DEFAULT_BJOBS_CMD "bjobs"
|
||||
#define DEFAULT_BKILL_CMD "bkill"
|
||||
|
||||
|
||||
struct lsf_job_struct {
|
||||
UTIL_TYPE_ID_DECLARATION;
|
||||
long int lsf_jobnr;
|
||||
int num_exec_host;
|
||||
char **exec_host;
|
||||
char * lsf_jobnr_char; /* Used to look up the job status in the bjobs_cache hash table */
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct lsf_driver_struct {
|
||||
UTIL_TYPE_ID_DECLARATION;
|
||||
char * queue_name;
|
||||
char * resource_request;
|
||||
char * login_shell;
|
||||
pthread_mutex_t submit_lock;
|
||||
|
||||
lsf_submit_method_enum submit_method;
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
/* Fields used by the lsf library functions */
|
||||
struct submit lsf_request;
|
||||
struct submitReply lsf_reply;
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
/* Fields used by the shell based functions */
|
||||
|
||||
int bjobs_refresh_interval;
|
||||
time_t last_bjobs_update;
|
||||
hash_type * my_jobs; /* A hash table of all jobs submitted by this ERT instance -
|
||||
to ensure that we do not check status of old jobs in e.g. ZOMBIE status. */
|
||||
hash_type * status_map;
|
||||
hash_type * bjobs_cache; /* The output of calling bjobs is cached in this table. */
|
||||
pthread_mutex_t bjobs_mutex; /* Only one thread should update the bjobs_chache table. */
|
||||
char * remote_lsf_server;
|
||||
char * rsh_cmd;
|
||||
char * bsub_cmd;
|
||||
char * bjobs_cmd;
|
||||
char * bkill_cmd;
|
||||
};
|
||||
|
||||
|
||||
void init_lsf_driver() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
UTIL_SAFE_CAST_FUNCTION( lsf_driver , LSF_DRIVER_TYPE_ID)
|
||||
static UTIL_SAFE_CAST_FUNCTION_CONST( lsf_driver , LSF_DRIVER_TYPE_ID)
|
||||
static UTIL_SAFE_CAST_FUNCTION( lsf_job , LSF_JOB_TYPE_ID)
|
||||
|
||||
lsf_job_type * lsf_job_alloc() {
|
||||
lsf_job_type * job;
|
||||
job = util_malloc(sizeof * job);
|
||||
job->num_exec_host = 0;
|
||||
job->exec_host = NULL;
|
||||
|
||||
job->lsf_jobnr_char = NULL;
|
||||
UTIL_TYPE_ID_INIT( job , LSF_JOB_TYPE_ID);
|
||||
return job;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void lsf_job_free(lsf_job_type * job) {
|
||||
util_safe_free(job->lsf_jobnr_char);
|
||||
util_free_stringlist(job->exec_host , job->num_exec_host);
|
||||
free(job);
|
||||
}
|
||||
|
||||
|
||||
static int lsf_job_parse_bsub_stdout(const lsf_driver_type * driver , const char * stdout_file) {
|
||||
int jobid = -1;
|
||||
FILE * stream = util_fopen(stdout_file , "r");
|
||||
if (util_fseek_string(stream , "<" , true , true)) {
|
||||
char * jobid_string = util_fscanf_alloc_upto(stream , ">" , false);
|
||||
if (jobid_string != NULL) {
|
||||
jobid = atoi( jobid_string );
|
||||
free( jobid_string );
|
||||
}
|
||||
}
|
||||
fclose( stream );
|
||||
|
||||
if (jobid == -1) {
|
||||
char * file_content = util_fread_alloc_file_content( stdout_file , NULL );
|
||||
fprintf(stderr,"Failed to get lsf job id from file: %s \n",stdout_file );
|
||||
fprintf(stderr,"bsub command : %s \n",driver->bsub_cmd );
|
||||
fprintf(stderr,"%s\n", file_content);
|
||||
free( file_content );
|
||||
util_exit("%s: \n",__func__);
|
||||
}
|
||||
return jobid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
stringlist_type * lsf_driver_alloc_cmd(lsf_driver_type * driver ,
|
||||
const char * lsf_stdout ,
|
||||
const char * job_name ,
|
||||
const char * submit_cmd ,
|
||||
int num_cpu ,
|
||||
int job_argc,
|
||||
const char ** job_argv) {
|
||||
|
||||
stringlist_type * argv = stringlist_alloc_new();
|
||||
char * num_cpu_string = util_alloc_sprintf("%d" , num_cpu);
|
||||
char * quoted_resource_request = NULL;
|
||||
|
||||
/*
|
||||
The resource request string contains spaces, and when passed
|
||||
through the shell it must be protected with \"..\"; this applies
|
||||
when submitting to a remote lsf server with ssh. However when
|
||||
submitting to the local workstation using a bsub command the
|
||||
command will be invoked with the util_fork_exec() command - and no
|
||||
shell is involved. In this latter case we must avoid the \"...\"
|
||||
quoting.
|
||||
*/
|
||||
|
||||
if (driver->resource_request != NULL) {
|
||||
if (driver->submit_method == LSF_SUBMIT_REMOTE_SHELL)
|
||||
quoted_resource_request =util_alloc_sprintf("\"%s\"" , driver->resource_request);
|
||||
else
|
||||
quoted_resource_request = util_alloc_string_copy( driver->resource_request );
|
||||
}
|
||||
|
||||
if (driver->submit_method == LSF_SUBMIT_REMOTE_SHELL)
|
||||
stringlist_append_ref( argv , driver->bsub_cmd);
|
||||
|
||||
stringlist_append_ref( argv , "-o" );
|
||||
stringlist_append_copy( argv , lsf_stdout );
|
||||
if (driver->queue_name != NULL) {
|
||||
stringlist_append_ref( argv , "-q" );
|
||||
stringlist_append_ref( argv , driver->queue_name );
|
||||
}
|
||||
stringlist_append_ref( argv , "-J" );
|
||||
stringlist_append_ref( argv , job_name );
|
||||
stringlist_append_ref( argv , "-n" );
|
||||
stringlist_append_copy( argv , num_cpu_string );
|
||||
|
||||
if (quoted_resource_request != NULL) {
|
||||
stringlist_append_ref( argv , "-R");
|
||||
stringlist_append_copy( argv , quoted_resource_request );
|
||||
}
|
||||
|
||||
if (driver->login_shell != NULL) {
|
||||
stringlist_append_ref( argv , "-L");
|
||||
stringlist_append_ref( argv , driver->login_shell );
|
||||
}
|
||||
|
||||
stringlist_append_ref( argv , submit_cmd);
|
||||
{
|
||||
int iarg;
|
||||
for (iarg = 0; iarg < job_argc; iarg++)
|
||||
stringlist_append_ref( argv , job_argv[ iarg ]);
|
||||
}
|
||||
free( num_cpu_string );
|
||||
util_safe_free( quoted_resource_request );
|
||||
return argv;
|
||||
}
|
||||
|
||||
|
||||
static int lsf_driver_submit_internal_job( lsf_driver_type * driver ,
|
||||
const char * lsf_stdout ,
|
||||
const char * job_name ,
|
||||
const char * submit_cmd ,
|
||||
int num_cpu ,
|
||||
int argc,
|
||||
const char ** argv) {
|
||||
|
||||
char * command;
|
||||
{
|
||||
buffer_type * command_buffer = buffer_alloc( 256 );
|
||||
buffer_fwrite_char_ptr( command_buffer , submit_cmd );
|
||||
for (int iarg = 0; iarg < argc; iarg++) {
|
||||
buffer_fwrite_char( command_buffer , ' ');
|
||||
buffer_fwrite_char_ptr( command_buffer , argv[ iarg ]);
|
||||
}
|
||||
buffer_terminate_char_ptr( command_buffer );
|
||||
command = buffer_get_data( command_buffer );
|
||||
buffer_free_container( command_buffer );
|
||||
}
|
||||
|
||||
{
|
||||
int options = SUB_JOB_NAME + SUB_OUT_FILE;
|
||||
|
||||
if (driver->queue_name != NULL)
|
||||
options += SUB_QUEUE;
|
||||
|
||||
if (driver->resource_request != NULL)
|
||||
options += SUB_RES_REQ;
|
||||
|
||||
if (driver->login_shell != NULL)
|
||||
options += SUB_LOGIN_SHELL;
|
||||
|
||||
driver->lsf_request.options = options;
|
||||
}
|
||||
|
||||
driver->lsf_request.resReq = driver->resource_request;
|
||||
driver->lsf_request.loginShell = driver->login_shell;
|
||||
driver->lsf_request.queue = driver->queue_name;
|
||||
driver->lsf_request.jobName = (char *) job_name;
|
||||
driver->lsf_request.outFile = lsf_stdout;
|
||||
driver->lsf_request.command = command;
|
||||
driver->lsf_request.numProcessors = num_cpu;
|
||||
|
||||
{
|
||||
int lsf_jobnr = lsb_submit( &driver->lsf_request , &driver->lsf_reply );
|
||||
free( command ); /* I trust the lsf layer is finished with the command? */
|
||||
return lsf_jobnr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int lsf_driver_submit_shell_job(lsf_driver_type * driver ,
|
||||
const char * lsf_stdout ,
|
||||
const char * job_name ,
|
||||
const char * submit_cmd ,
|
||||
int num_cpu ,
|
||||
int job_argc,
|
||||
const char ** job_argv) {
|
||||
int job_id;
|
||||
char * tmp_file = util_alloc_tmp_file("/tmp" , "enkf-submit" , true);
|
||||
|
||||
printf("remote_lsf_server: %s \n",driver->remote_lsf_server);
|
||||
if (driver->remote_lsf_server != NULL) {
|
||||
stringlist_type * remote_argv = lsf_driver_alloc_cmd( driver , lsf_stdout , job_name , submit_cmd , num_cpu , job_argc , job_argv);
|
||||
if (driver->submit_method == LSF_SUBMIT_REMOTE_SHELL) {
|
||||
char ** argv = util_calloc( 2 , sizeof * argv );
|
||||
argv[0] = driver->remote_lsf_server;
|
||||
argv[1] = stringlist_alloc_joined_string( remote_argv , " ");
|
||||
util_fork_exec(driver->rsh_cmd , 2 , (const char **) argv , true , NULL , NULL , NULL , tmp_file , NULL);
|
||||
free( argv[1] );
|
||||
free( argv );
|
||||
} else if (driver->submit_method == LSF_SUBMIT_LOCAL_SHELL) {
|
||||
char ** argv = stringlist_alloc_char_ref( remote_argv );
|
||||
util_fork_exec(driver->bsub_cmd , stringlist_get_size( remote_argv) , (const char **) argv , true , NULL , NULL , NULL , tmp_file , NULL);
|
||||
free( argv );
|
||||
}
|
||||
stringlist_free( remote_argv );
|
||||
}
|
||||
|
||||
job_id = lsf_job_parse_bsub_stdout(driver , tmp_file);
|
||||
util_unlink_existing( tmp_file );
|
||||
free(tmp_file);
|
||||
return job_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int lsf_driver_get_status__(lsf_driver_type * driver , const char * status, const char * job_id) {
|
||||
if (hash_has_key( driver->status_map , status))
|
||||
return hash_get_int( driver->status_map , status);
|
||||
else {
|
||||
util_exit("The lsf_status:%s for job:%s is not recognized; call your LSF administrator - sorry :-( \n", status , job_id);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void lsf_driver_update_bjobs_table(lsf_driver_type * driver) {
|
||||
char * tmp_file = util_alloc_tmp_file("/tmp" , "enkf-bjobs" , true);
|
||||
|
||||
if (driver->submit_method == LSF_SUBMIT_REMOTE_SHELL) {
|
||||
char ** argv = util_calloc( 2 , sizeof * argv);
|
||||
argv[0] = driver->remote_lsf_server;
|
||||
argv[1] = util_alloc_sprintf("%s -a" , driver->bjobs_cmd);
|
||||
util_fork_exec(driver->rsh_cmd , 2 , (const char **) argv , true , NULL , NULL , NULL , tmp_file , NULL);
|
||||
free( argv[1] );
|
||||
free( argv );
|
||||
} else if (driver->submit_method == LSF_SUBMIT_LOCAL_SHELL) {
|
||||
char ** argv = util_calloc( 1 , sizeof * argv);
|
||||
argv[0] = "-a";
|
||||
util_fork_exec(driver->bjobs_cmd , 1 , (const char **) argv , true , NULL , NULL , NULL , tmp_file , NULL);
|
||||
free( argv );
|
||||
}
|
||||
|
||||
{
|
||||
char user[32];
|
||||
char status[16];
|
||||
FILE *stream = util_fopen(tmp_file , "r");;
|
||||
bool at_eof = false;
|
||||
hash_clear(driver->bjobs_cache);
|
||||
util_fskip_lines(stream , 1);
|
||||
while (!at_eof) {
|
||||
char * line = util_fscanf_alloc_line(stream , &at_eof);
|
||||
if (line != NULL) {
|
||||
int job_id_int;
|
||||
|
||||
if (sscanf(line , "%d %s %s", &job_id_int , user , status) == 3) {
|
||||
char * job_id = util_alloc_sprintf("%d" , job_id_int);
|
||||
|
||||
if (hash_has_key( driver->my_jobs , job_id )) /* Consider only jobs submitted by this ERT instance - not old jobs lying around from the same user. */
|
||||
hash_insert_int(driver->bjobs_cache , job_id , lsf_driver_get_status__( driver , status , job_id));
|
||||
|
||||
free(job_id);
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
fclose(stream);
|
||||
}
|
||||
util_unlink_existing(tmp_file);
|
||||
free(tmp_file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int lsf_driver_get_job_status_libary(void * __driver , void * __job) {
|
||||
if (__job == NULL)
|
||||
/* the job has not been registered at all ... */
|
||||
return JOB_QUEUE_NOT_ACTIVE;
|
||||
else {
|
||||
lsf_job_type * job = lsf_job_safe_cast( __job );
|
||||
{
|
||||
int status;
|
||||
struct jobInfoEnt *job_info;
|
||||
if (lsb_openjobinfo(job->lsf_jobnr , NULL , NULL , NULL , NULL , ALL_JOB) != 1) {
|
||||
/*
|
||||
Failed to get information about the job - we boldly assume
|
||||
the following situation has occured:
|
||||
|
||||
1. The job is running happily along.
|
||||
2. The lsf deamon is not responding for a long time.
|
||||
3. The job finishes, and is eventually expired from the LSF job database.
|
||||
4. The lsf deamon answers again - but can not find the job...
|
||||
|
||||
*/
|
||||
fprintf(stderr,"Warning: failed to get status information for job:%ld - assuming it is finished. \n", job->lsf_jobnr);
|
||||
status = JOB_QUEUE_DONE;
|
||||
} else {
|
||||
job_info = lsb_readjobinfo( NULL );
|
||||
lsb_closejobinfo();
|
||||
if (job->num_exec_host == 0) {
|
||||
job->num_exec_host = job_info->numExHosts;
|
||||
job->exec_host = util_alloc_stringlist_copy( (const char **) job_info->exHosts , job->num_exec_host);
|
||||
}
|
||||
status = job_info->status;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static int lsf_driver_get_job_status_shell(void * __driver , void * __job) {
|
||||
int status = JOB_STAT_NULL;
|
||||
|
||||
if (__job != NULL) {
|
||||
lsf_job_type * job = lsf_job_safe_cast( __job );
|
||||
lsf_driver_type * driver = lsf_driver_safe_cast( __driver );
|
||||
|
||||
{
|
||||
/**
|
||||
Updating the bjobs_table of the driver involves a significant change in
|
||||
the internal state of the driver; that is semantically a bit
|
||||
unfortunate because this is clearly a get() function; to protect
|
||||
against concurrent updates of this table we use a mutex.
|
||||
*/
|
||||
pthread_mutex_lock( &driver->bjobs_mutex );
|
||||
{
|
||||
if (difftime(time(NULL) , driver->last_bjobs_update) > driver->bjobs_refresh_interval) {
|
||||
lsf_driver_update_bjobs_table(driver);
|
||||
driver->last_bjobs_update = time( NULL );
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock( &driver->bjobs_mutex );
|
||||
|
||||
|
||||
if (hash_has_key( driver->bjobs_cache , job->lsf_jobnr_char) )
|
||||
status = hash_get_int(driver->bjobs_cache , job->lsf_jobnr_char);
|
||||
else
|
||||
/*
|
||||
It might be running - but since job != NULL it is at least in the queue system.
|
||||
*/
|
||||
status = JOB_STAT_PEND;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
job_status_type lsf_driver_convert_status( int lsf_status ) {
|
||||
job_status_type job_status;
|
||||
switch (lsf_status) {
|
||||
case JOB_STAT_NULL:
|
||||
job_status = JOB_QUEUE_NOT_ACTIVE;
|
||||
break;
|
||||
case JOB_STAT_PEND:
|
||||
job_status = JOB_QUEUE_PENDING;
|
||||
break;
|
||||
case JOB_STAT_SSUSP:
|
||||
job_status = JOB_QUEUE_RUNNING;
|
||||
break;
|
||||
case JOB_STAT_USUSP:
|
||||
job_status = JOB_QUEUE_RUNNING;
|
||||
break;
|
||||
case JOB_STAT_PSUSP:
|
||||
job_status = JOB_QUEUE_RUNNING;
|
||||
break;
|
||||
case JOB_STAT_RUN:
|
||||
job_status = JOB_QUEUE_RUNNING;
|
||||
break;
|
||||
case JOB_STAT_DONE:
|
||||
job_status = JOB_QUEUE_DONE;
|
||||
break;
|
||||
case JOB_STAT_EXIT:
|
||||
job_status = JOB_QUEUE_EXIT;
|
||||
break;
|
||||
case JOB_STAT_UNKWN: // Have lost contact with one of the daemons.
|
||||
job_status = JOB_QUEUE_EXIT;
|
||||
break;
|
||||
case 192: /* this 192 seems to pop up - where the fuck does it come frome ?? _pdone + _ususp ??? */
|
||||
job_status = JOB_QUEUE_DONE;
|
||||
break;
|
||||
default:
|
||||
job_status = JOB_QUEUE_NOT_ACTIVE;
|
||||
util_abort("%s: unrecognized lsf status code:%d \n",__func__ , lsf_status );
|
||||
}
|
||||
return job_status;
|
||||
}
|
||||
|
||||
|
||||
int lsf_driver_get_job_status_lsf(void * __driver , void * __job) {
|
||||
int lsf_status;
|
||||
lsf_driver_type * driver = lsf_driver_safe_cast( __driver );
|
||||
|
||||
if (driver->submit_method == LSF_SUBMIT_INTERNAL)
|
||||
lsf_status = lsf_driver_get_job_status_libary(__driver , __job);
|
||||
else
|
||||
lsf_status = lsf_driver_get_job_status_shell(__driver , __job);
|
||||
|
||||
return lsf_status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
job_status_type lsf_driver_get_job_status(void * __driver , void * __job) {
|
||||
int lsf_status = lsf_driver_get_job_status_lsf( __driver , __job );
|
||||
return lsf_driver_convert_status( lsf_status );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void lsf_driver_free_job(void * __job) {
|
||||
lsf_job_type * job = lsf_job_safe_cast( __job );
|
||||
lsf_job_free(job);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void lsf_driver_kill_job(void * __driver , void * __job) {
|
||||
lsf_driver_type * driver = lsf_driver_safe_cast( __driver );
|
||||
lsf_job_type * job = lsf_job_safe_cast( __job );
|
||||
{
|
||||
if (driver->submit_method == LSF_SUBMIT_INTERNAL)
|
||||
lsb_forcekilljob(job->lsf_jobnr);
|
||||
else {
|
||||
if (driver->submit_method == LSF_SUBMIT_REMOTE_SHELL) {
|
||||
char ** argv = util_calloc( 2, sizeof * argv );
|
||||
argv[0] = driver->remote_lsf_server;
|
||||
argv[1] = util_alloc_sprintf("%s %s" , driver->bkill_cmd , job->lsf_jobnr_char);
|
||||
|
||||
util_fork_exec(driver->rsh_cmd , 2 , (const char **) argv , true , NULL , NULL , NULL , NULL , NULL);
|
||||
|
||||
free( argv[1] );
|
||||
free( argv );
|
||||
} else if (driver->submit_method == LSF_SUBMIT_LOCAL_SHELL)
|
||||
util_fork_exec(driver->bkill_cmd , 1 , (const char **) &job->lsf_jobnr_char , true , NULL , NULL , NULL , NULL , NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void * lsf_driver_submit_job(void * __driver ,
|
||||
const char * submit_cmd ,
|
||||
int num_cpu ,
|
||||
const char * run_path ,
|
||||
const char * job_name ,
|
||||
int argc,
|
||||
const char ** argv ) {
|
||||
lsf_driver_type * driver = lsf_driver_safe_cast( __driver );
|
||||
{
|
||||
lsf_job_type * job = lsf_job_alloc();
|
||||
{
|
||||
char * lsf_stdout = util_alloc_filename(run_path , job_name , "LSF-stdout");
|
||||
pthread_mutex_lock( &driver->submit_lock );
|
||||
|
||||
if (driver->submit_method == LSF_SUBMIT_INTERNAL) {
|
||||
job->lsf_jobnr = lsf_driver_submit_internal_job( driver , run_path , job_name , submit_cmd , num_cpu , argc, argv);
|
||||
} else {
|
||||
job->lsf_jobnr = lsf_driver_submit_shell_job( driver , run_path , job_name , submit_cmd , num_cpu , argc, argv);
|
||||
job->lsf_jobnr_char = util_alloc_sprintf("%ld" , job->lsf_jobnr);
|
||||
hash_insert_ref( driver->my_jobs , job->lsf_jobnr_char , NULL );
|
||||
}
|
||||
|
||||
pthread_mutex_unlock( &driver->submit_lock );
|
||||
free( lsf_stdout );
|
||||
}
|
||||
|
||||
if (job->lsf_jobnr > 0)
|
||||
return job;
|
||||
else {
|
||||
/*
|
||||
The submit failed - the queue system shall handle
|
||||
NULL return values.
|
||||
*/
|
||||
if (driver->submit_method == LSF_SUBMIT_INTERNAL)
|
||||
fprintf(stderr,"%s: ** Warning: lsb_submit() failed: %s/%d \n",__func__ , lsb_sysmsg() , lsberrno);
|
||||
lsf_job_free(job);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void lsf_driver_free(lsf_driver_type * driver ) {
|
||||
util_safe_free(driver->login_shell);
|
||||
util_safe_free(driver->queue_name);
|
||||
util_safe_free(driver->resource_request );
|
||||
util_safe_free(driver->remote_lsf_server );
|
||||
util_safe_free(driver->rsh_cmd );
|
||||
free( driver->bkill_cmd );
|
||||
free( driver->bjobs_cmd );
|
||||
free( driver->bsub_cmd );
|
||||
|
||||
hash_free(driver->status_map);
|
||||
hash_free(driver->bjobs_cache);
|
||||
hash_free(driver->my_jobs);
|
||||
|
||||
free(driver);
|
||||
driver = NULL;
|
||||
}
|
||||
|
||||
void lsf_driver_free__(void * __driver ) {
|
||||
lsf_driver_type * driver = lsf_driver_safe_cast( __driver );
|
||||
lsf_driver_free( driver );
|
||||
}
|
||||
|
||||
|
||||
static void lsf_driver_set_queue( lsf_driver_type * driver, const char * queue ) {
|
||||
driver->queue_name = util_realloc_string_copy( driver->queue_name , queue);
|
||||
}
|
||||
|
||||
|
||||
static void lsf_driver_set_login_shell( lsf_driver_type * driver, const char * login_shell ) {
|
||||
driver->login_shell = util_realloc_string_copy( driver->login_shell , login_shell);
|
||||
}
|
||||
|
||||
static void lsf_driver_set_rsh_cmd( lsf_driver_type * driver , const char * rsh_cmd) {
|
||||
driver->rsh_cmd = util_realloc_string_copy( driver->rsh_cmd , rsh_cmd );
|
||||
}
|
||||
|
||||
static void lsf_driver_set_bsub_cmd( lsf_driver_type * driver , const char * bsub_cmd) {
|
||||
driver->bsub_cmd = util_realloc_string_copy( driver->bsub_cmd , bsub_cmd );
|
||||
}
|
||||
|
||||
static void lsf_driver_set_bjobs_cmd( lsf_driver_type * driver , const char * bjobs_cmd) {
|
||||
driver->bjobs_cmd = util_realloc_string_copy( driver->bjobs_cmd , bjobs_cmd );
|
||||
}
|
||||
|
||||
static void lsf_driver_set_bkill_cmd( lsf_driver_type * driver , const char * bkill_cmd) {
|
||||
driver->bkill_cmd = util_realloc_string_copy( driver->bkill_cmd , bkill_cmd );
|
||||
}
|
||||
|
||||
static void lsf_driver_set_remote_server( lsf_driver_type * driver , const char * remote_server) {
|
||||
driver->remote_lsf_server = util_realloc_string_copy( driver->remote_lsf_server , remote_server );
|
||||
if (driver->remote_lsf_server == NULL) {
|
||||
/* No remote server has been set - assuming we can issue proper library calls. */
|
||||
/* The BSUB_QUEUE variable must NOT be set when using the shell
|
||||
function, because then stdout is redirected and read. */
|
||||
util_setenv("BSUB_QUIET" , "yes");
|
||||
driver->submit_method = LSF_SUBMIT_INTERNAL;
|
||||
} else {
|
||||
util_unsetenv( "BSUB_QUIET" );
|
||||
{
|
||||
char * tmp_server = util_alloc_strupr_copy( remote_server );
|
||||
|
||||
if (strcmp(tmp_server , LOCAL_LSF_SERVER) == 0)
|
||||
driver->submit_method = LSF_SUBMIT_LOCAL_SHELL;
|
||||
else
|
||||
driver->submit_method = LSF_SUBMIT_REMOTE_SHELL;
|
||||
|
||||
free( tmp_server );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lsf_submit_method_enum lsf_driver_get_submit_method( const lsf_driver_type * driver ) {
|
||||
return driver->submit_method;
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
/* Generic functions for runtime manipulation of options.
|
||||
|
||||
LSF_SERVER
|
||||
LSF_QUEUE
|
||||
LSF_RESOURCE
|
||||
*/
|
||||
|
||||
bool lsf_driver_set_option( void * __driver , const char * option_key , const void * value) {
|
||||
lsf_driver_type * driver = lsf_driver_safe_cast( __driver );
|
||||
bool has_option = true;
|
||||
{
|
||||
if (strcmp( LSF_RESOURCE , option_key ) == 0)
|
||||
driver->resource_request = util_realloc_string_copy( driver->resource_request , value );
|
||||
else if (strcmp( LSF_SERVER , option_key) == 0)
|
||||
lsf_driver_set_remote_server( driver , value );
|
||||
else if (strcmp( LSF_QUEUE , option_key) == 0)
|
||||
lsf_driver_set_queue( driver , value );
|
||||
else if (strcmp( LSF_LOGIN_SHELL , option_key) == 0)
|
||||
lsf_driver_set_login_shell( driver , value );
|
||||
else if (strcmp( LSF_RSH_CMD , option_key) == 0)
|
||||
lsf_driver_set_rsh_cmd( driver , value );
|
||||
else if (strcmp( LSF_BSUB_CMD , option_key) == 0)
|
||||
lsf_driver_set_bsub_cmd( driver , value );
|
||||
else if (strcmp( LSF_BJOBS_CMD , option_key) == 0)
|
||||
lsf_driver_set_bjobs_cmd( driver , value );
|
||||
else if (strcmp( LSF_BKILL_CMD , option_key) == 0)
|
||||
lsf_driver_set_bkill_cmd( driver , value );
|
||||
else
|
||||
has_option = false;
|
||||
}
|
||||
return has_option;
|
||||
}
|
||||
|
||||
|
||||
const void * lsf_driver_get_option( const void * __driver , const char * option_key) {
|
||||
const lsf_driver_type * driver = lsf_driver_safe_cast_const( __driver );
|
||||
{
|
||||
if (strcmp( LSF_RESOURCE , option_key ) == 0)
|
||||
return driver->resource_request;
|
||||
else if (strcmp( LSF_SERVER , option_key ) == 0)
|
||||
return driver->remote_lsf_server;
|
||||
else if (strcmp( LSF_QUEUE , option_key ) == 0)
|
||||
return driver->queue_name;
|
||||
else if (strcmp( LSF_LOGIN_SHELL , option_key ) == 0)
|
||||
return driver->login_shell;
|
||||
else if (strcmp( LSF_RSH_CMD , option_key ) == 0)
|
||||
return driver->rsh_cmd;
|
||||
else if (strcmp( LSF_BJOBS_CMD , option_key ) == 0)
|
||||
return driver->bjobs_cmd;
|
||||
else if (strcmp( LSF_BSUB_CMD , option_key ) == 0)
|
||||
return driver->bsub_cmd;
|
||||
else if (strcmp( LSF_BKILL_CMD , option_key ) == 0)
|
||||
return driver->bkill_cmd;
|
||||
else {
|
||||
util_abort("%s: option_id:%s not recognized for LSF driver \n",__func__ , option_key);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool lsf_driver_has_option( const void * __driver , const char * option_key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
/*
|
||||
Observe that this driver IS not properly initialized when returning
|
||||
from this function, the option interface must be used to set the
|
||||
keys:
|
||||
*/
|
||||
|
||||
void lsf_driver_set_bjobs_refresh_interval( lsf_driver_type * driver , int refresh_interval) {
|
||||
driver->bjobs_refresh_interval = refresh_interval;
|
||||
|
||||
}
|
||||
|
||||
void * lsf_driver_alloc( ) {
|
||||
lsf_driver_type * lsf_driver = util_malloc(sizeof * lsf_driver );
|
||||
lsf_driver->login_shell = NULL;
|
||||
lsf_driver->queue_name = NULL;
|
||||
lsf_driver->remote_lsf_server = NULL;
|
||||
lsf_driver->rsh_cmd = NULL;
|
||||
lsf_driver->resource_request = NULL;
|
||||
lsf_driver_set_bjobs_refresh_interval( lsf_driver , BJOBS_REFRESH_TIME );
|
||||
UTIL_TYPE_ID_INIT( lsf_driver , LSF_DRIVER_TYPE_ID);
|
||||
pthread_mutex_init( &lsf_driver->submit_lock , NULL );
|
||||
|
||||
/* Library initialisation */
|
||||
/*****************************************************************/
|
||||
memset(&lsf_driver->lsf_request , 0 , sizeof (lsf_driver->lsf_request));
|
||||
lsf_driver->lsf_request.beginTime = 0;
|
||||
lsf_driver->lsf_request.termTime = 0;
|
||||
lsf_driver->lsf_request.numProcessors = 1;
|
||||
lsf_driver->lsf_request.maxNumProcessors = 1;
|
||||
{
|
||||
int i;
|
||||
for (i=0; i < LSF_RLIM_NLIMITS; i++)
|
||||
lsf_driver->lsf_request.rLimits[i] = DEFAULT_RLIMIT;
|
||||
}
|
||||
lsf_driver->lsf_request.options2 = 0;
|
||||
|
||||
|
||||
/*
|
||||
The environment variable LSF_ENVDIR must be set to point the
|
||||
directory containing LSF configuration information, the whole
|
||||
thing will crash and burn if this is not properly set.
|
||||
*/
|
||||
if ( lsb_init(NULL) != 0 ) {
|
||||
fprintf(stderr,"LSF_ENVDIR: ");
|
||||
if (getenv("LSF_ENVDIR") != NULL)
|
||||
fprintf(stderr,"%s\n", getenv("LSF_ENVDIR"));
|
||||
else
|
||||
fprintf(stderr, "not set\n");
|
||||
|
||||
util_abort("%s failed to initialize LSF environment : %s/%d \n",__func__ , lsb_sysmsg() , lsberrno);
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
/* Shell initialization */
|
||||
lsf_driver->last_bjobs_update = time( NULL );
|
||||
lsf_driver->bjobs_cache = hash_alloc();
|
||||
lsf_driver->my_jobs = hash_alloc();
|
||||
lsf_driver->status_map = hash_alloc();
|
||||
lsf_driver->bsub_cmd = NULL;
|
||||
lsf_driver->bjobs_cmd = NULL;
|
||||
lsf_driver->bkill_cmd = NULL;
|
||||
|
||||
|
||||
hash_insert_int(lsf_driver->status_map , "PEND" , JOB_STAT_PEND);
|
||||
hash_insert_int(lsf_driver->status_map , "SSUSP" , JOB_STAT_SSUSP);
|
||||
hash_insert_int(lsf_driver->status_map , "PSUSP" , JOB_STAT_PSUSP);
|
||||
hash_insert_int(lsf_driver->status_map , "USUSP" , JOB_STAT_USUSP);
|
||||
hash_insert_int(lsf_driver->status_map , "RUN" , JOB_STAT_RUN);
|
||||
hash_insert_int(lsf_driver->status_map , "EXIT" , JOB_STAT_EXIT);
|
||||
hash_insert_int(lsf_driver->status_map , "DONE" , JOB_STAT_DONE);
|
||||
hash_insert_int(lsf_driver->status_map , "UNKWN" , JOB_STAT_UNKWN); /* Uncertain about this one */
|
||||
pthread_mutex_init( &lsf_driver->bjobs_mutex , NULL );
|
||||
|
||||
lsf_driver_set_option( lsf_driver , LSF_SERVER , NULL );
|
||||
lsf_driver_set_option( lsf_driver , LSF_RSH_CMD , DEFAULT_RSH_CMD );
|
||||
lsf_driver_set_option( lsf_driver , LSF_BSUB_CMD , DEFAULT_BSUB_CMD );
|
||||
lsf_driver_set_option( lsf_driver , LSF_BJOBS_CMD , DEFAULT_BJOBS_CMD );
|
||||
lsf_driver_set_option( lsf_driver , LSF_BKILL_CMD , DEFAULT_BKILL_CMD );
|
||||
return lsf_driver;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
|
264
ThirdParty/Ert/devel/libjob_queue/src/queue_driver.c
vendored
264
ThirdParty/Ert/devel/libjob_queue/src/queue_driver.c
vendored
@ -14,7 +14,7 @@
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
@ -25,6 +25,7 @@
|
||||
#include <ert/job_queue/lsf_driver.h>
|
||||
#include <ert/job_queue/local_driver.h>
|
||||
#include <ert/job_queue/rsh_driver.h>
|
||||
#include <ert/job_queue/torque_driver.h>
|
||||
|
||||
|
||||
/**
|
||||
@ -50,41 +51,38 @@
|
||||
|
||||
3. Some data fields which are common to all driver types.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
#define QUEUE_DRIVER_ID 86516032
|
||||
|
||||
|
||||
struct queue_driver_struct {
|
||||
UTIL_TYPE_ID_DECLARATION;
|
||||
/*
|
||||
Function pointers - pointing to low level functions in the implementations of
|
||||
e.g. lsf_driver.
|
||||
*/
|
||||
submit_job_ftype * submit;
|
||||
free_job_ftype * free_job;
|
||||
kill_job_ftype * kill_job;
|
||||
get_status_ftype * get_status;
|
||||
free_queue_driver_ftype * free_driver;
|
||||
set_option_ftype * set_option;
|
||||
get_option_ftype * get_option;
|
||||
has_option_ftype * has_option;
|
||||
*/
|
||||
submit_job_ftype * submit;
|
||||
free_job_ftype * free_job;
|
||||
kill_job_ftype * kill_job;
|
||||
get_status_ftype * get_status;
|
||||
free_queue_driver_ftype * free_driver;
|
||||
set_option_ftype * set_option;
|
||||
get_option_ftype * get_option;
|
||||
has_option_ftype * has_option;
|
||||
|
||||
void * data; /* Driver specific data - passed as first argument to the driver functions above. */
|
||||
void * data; /* Driver specific data - passed as first argument to the driver functions above. */
|
||||
|
||||
/*
|
||||
Generic data - common to all driver types.
|
||||
*/
|
||||
char * name; /* String name of driver. */
|
||||
job_driver_type driver_type; /* Enum value for driver. */
|
||||
int max_running; /* Possible to maintain different max_running values for different
|
||||
*/
|
||||
char * name; /* String name of driver. */
|
||||
job_driver_type driver_type; /* Enum value for driver. */
|
||||
int max_running; /* Possible to maintain different max_running values for different
|
||||
drivers; the value 0 is interpreted as no limit - i.e. the queue layer
|
||||
will (try) to send an unlimited number of jobs to the driver. */
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Observe that after the driver instance has been allocated it does
|
||||
NOT support modification of the common fields, only the data owned
|
||||
@ -93,28 +91,28 @@ struct queue_driver_struct {
|
||||
|
||||
The driver returned from the queue_driver_alloc_empty() function is
|
||||
NOT properly initialized and NOT ready for use.
|
||||
*/
|
||||
*/
|
||||
|
||||
static queue_driver_type * queue_driver_alloc_empty( ) {
|
||||
queue_driver_type * driver = util_malloc( sizeof * driver);
|
||||
UTIL_TYPE_ID_INIT( driver , QUEUE_DRIVER_ID );
|
||||
static queue_driver_type * queue_driver_alloc_empty() {
|
||||
queue_driver_type * driver = util_malloc(sizeof * driver);
|
||||
UTIL_TYPE_ID_INIT(driver, QUEUE_DRIVER_ID);
|
||||
driver->max_running = 0;
|
||||
driver->driver_type = NULL_DRIVER;
|
||||
driver->submit = NULL;
|
||||
driver->get_status = NULL;
|
||||
driver->kill_job = NULL;
|
||||
driver->free_job = NULL;
|
||||
driver->submit = NULL;
|
||||
driver->get_status = NULL;
|
||||
driver->kill_job = NULL;
|
||||
driver->free_job = NULL;
|
||||
driver->free_driver = NULL;
|
||||
driver->get_option = NULL;
|
||||
driver->set_option = NULL;
|
||||
driver->has_option = NULL;
|
||||
driver->name = NULL;
|
||||
driver->data = NULL;
|
||||
driver->get_option = NULL;
|
||||
driver->set_option = NULL;
|
||||
driver->has_option = NULL;
|
||||
driver->name = NULL;
|
||||
driver->data = NULL;
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
static UTIL_SAFE_CAST_FUNCTION( queue_driver , QUEUE_DRIVER_ID )
|
||||
static UTIL_SAFE_CAST_FUNCTION(queue_driver, QUEUE_DRIVER_ID)
|
||||
|
||||
|
||||
/**
|
||||
@ -122,92 +120,99 @@ static UTIL_SAFE_CAST_FUNCTION( queue_driver , QUEUE_DRIVER_ID )
|
||||
correctly initialized; but no options have been set. I.e. unless
|
||||
the driver in question needs no options (e.g. the LOCAL driver) the
|
||||
returned driver will NOT be ready for use.
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
queue_driver_type * queue_driver_alloc( job_driver_type type ) {
|
||||
queue_driver_type * queue_driver_alloc(job_driver_type type) {
|
||||
queue_driver_type * driver = queue_driver_alloc_empty();
|
||||
driver->driver_type = type;
|
||||
switch( type ) {
|
||||
case LSF_DRIVER:
|
||||
driver->submit = lsf_driver_submit_job;
|
||||
driver->get_status = lsf_driver_get_job_status;
|
||||
driver->kill_job = lsf_driver_kill_job;
|
||||
driver->free_job = lsf_driver_free_job;
|
||||
driver->free_driver = lsf_driver_free__;
|
||||
driver->set_option = lsf_driver_set_option;
|
||||
driver->get_option = lsf_driver_get_option;
|
||||
driver->has_option = lsf_driver_has_option;
|
||||
driver->name = util_alloc_string_copy("LSF");
|
||||
driver->data = lsf_driver_alloc( );
|
||||
break;
|
||||
case LOCAL_DRIVER:
|
||||
driver->submit = local_driver_submit_job;
|
||||
driver->get_status = local_driver_get_job_status;
|
||||
driver->kill_job = local_driver_kill_job;
|
||||
driver->free_job = local_driver_free_job;
|
||||
driver->free_driver = local_driver_free__;
|
||||
driver->name = util_alloc_string_copy("local");
|
||||
driver->data = local_driver_alloc( );
|
||||
break;
|
||||
case RSH_DRIVER:
|
||||
driver->submit = rsh_driver_submit_job;
|
||||
driver->get_status = rsh_driver_get_job_status;
|
||||
driver->kill_job = rsh_driver_kill_job;
|
||||
driver->free_job = rsh_driver_free_job;
|
||||
driver->free_driver = rsh_driver_free__;
|
||||
driver->set_option = rsh_driver_set_option;
|
||||
driver->get_option = rsh_driver_get_option;
|
||||
driver->name = util_alloc_string_copy("RSH");
|
||||
driver->data = rsh_driver_alloc( );
|
||||
break;
|
||||
default:
|
||||
util_abort("%s: unrecognized driver type:%d \n",type);
|
||||
driver->driver_type = type;
|
||||
switch (type) {
|
||||
case LSF_DRIVER:
|
||||
driver->submit = lsf_driver_submit_job;
|
||||
driver->get_status = lsf_driver_get_job_status;
|
||||
driver->kill_job = lsf_driver_kill_job;
|
||||
driver->free_job = lsf_driver_free_job;
|
||||
driver->free_driver = lsf_driver_free__;
|
||||
driver->set_option = lsf_driver_set_option;
|
||||
driver->get_option = lsf_driver_get_option;
|
||||
driver->has_option = lsf_driver_has_option;
|
||||
driver->name = util_alloc_string_copy("LSF");
|
||||
driver->data = lsf_driver_alloc();
|
||||
break;
|
||||
case LOCAL_DRIVER:
|
||||
driver->submit = local_driver_submit_job;
|
||||
driver->get_status = local_driver_get_job_status;
|
||||
driver->kill_job = local_driver_kill_job;
|
||||
driver->free_job = local_driver_free_job;
|
||||
driver->free_driver = local_driver_free__;
|
||||
driver->name = util_alloc_string_copy("local");
|
||||
driver->data = local_driver_alloc();
|
||||
break;
|
||||
case RSH_DRIVER:
|
||||
driver->submit = rsh_driver_submit_job;
|
||||
driver->get_status = rsh_driver_get_job_status;
|
||||
driver->kill_job = rsh_driver_kill_job;
|
||||
driver->free_job = rsh_driver_free_job;
|
||||
driver->free_driver = rsh_driver_free__;
|
||||
driver->set_option = rsh_driver_set_option;
|
||||
driver->get_option = rsh_driver_get_option;
|
||||
driver->name = util_alloc_string_copy("RSH");
|
||||
driver->data = rsh_driver_alloc();
|
||||
break;
|
||||
case TORQUE_DRIVER:
|
||||
driver->submit = torque_driver_submit_job;
|
||||
driver->get_status = torque_driver_get_job_status;
|
||||
driver->kill_job = torque_driver_kill_job;
|
||||
driver->free_job = torque_driver_free_job;
|
||||
driver->free_driver = torque_driver_free__;
|
||||
driver->set_option = torque_driver_set_option;
|
||||
driver->get_option = torque_driver_get_option;
|
||||
driver->name = util_alloc_string_copy("TORQUE");
|
||||
driver->data = torque_driver_alloc();
|
||||
break;
|
||||
default:
|
||||
util_abort("%s: unrecognized driver type:%d \n", type);
|
||||
}
|
||||
return driver;
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
/**
|
||||
Set option - can also be used to perform actions - not only setting
|
||||
of parameters. There is no limit :-)
|
||||
*/
|
||||
bool queue_driver_set_option( queue_driver_type * driver , const char * option_key , const void * value) {
|
||||
*/
|
||||
bool queue_driver_set_option(queue_driver_type * driver, const char * option_key, const void * value) {
|
||||
if (driver->set_option != NULL)
|
||||
/* The actual low level set functions can not fail! */
|
||||
return driver->set_option( driver->data , option_key , value );
|
||||
return driver->set_option(driver->data, option_key, value);
|
||||
else {
|
||||
util_abort("%s: driver:%s does not support run time setting of options\n",__func__ , driver->name );
|
||||
util_abort("%s: driver:%s does not support run time setting of options\n", __func__, driver->name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool queue_driver_set_int_option( queue_driver_type * driver , const char * option_key , int int_value) {
|
||||
const void * void_value = &int_value;
|
||||
return queue_driver_set_option( driver , option_key , void_value );
|
||||
}
|
||||
|
||||
bool queue_driver_set_string_option( queue_driver_type * driver , const char * option_key , const char * value) {
|
||||
return queue_driver_set_option( driver , option_key , value);
|
||||
bool queue_driver_set_string_option(queue_driver_type * driver, const char * option_key, const char * value) {
|
||||
return queue_driver_set_option(driver, option_key, value);
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
bool queue_driver_has_option( queue_driver_type * driver , const char * option_key ) {
|
||||
bool queue_driver_has_option(queue_driver_type * driver, const char * option_key) {
|
||||
if (driver->has_option != NULL)
|
||||
return driver->has_option( driver , option_key );
|
||||
return driver->has_option(driver, option_key);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
const void * queue_driver_get_option( queue_driver_type * driver , const char * option_key ) {
|
||||
const void * queue_driver_get_option(queue_driver_type * driver, const char * option_key) {
|
||||
if (driver->get_option != NULL)
|
||||
/* The actual low level set functions can not fail! */
|
||||
return driver->get_option( driver->data , option_key );
|
||||
return driver->get_option(driver->data, option_key);
|
||||
else {
|
||||
util_abort("%s: driver:%s does not support run time reading of options\n",__func__ , driver->name );
|
||||
util_abort("%s: driver:%s does not support run time reading of options\n", __func__, driver->name);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -215,95 +220,106 @@ const void * queue_driver_get_option( queue_driver_type * driver , const char *
|
||||
/*****************************************************************/
|
||||
|
||||
|
||||
queue_driver_type * queue_driver_alloc_LSF(const char * queue_name , const char * resource_request , const char * remote_lsf_server) {
|
||||
queue_driver_type * driver = queue_driver_alloc( LSF_DRIVER );
|
||||
queue_driver_type * queue_driver_alloc_LSF(const char * queue_name, const char * resource_request, const char * remote_lsf_server) {
|
||||
queue_driver_type * driver = queue_driver_alloc(LSF_DRIVER);
|
||||
|
||||
queue_driver_set_option( driver , LSF_QUEUE , queue_name );
|
||||
queue_driver_set_option( driver , LSF_RESOURCE , resource_request );
|
||||
queue_driver_set_option( driver , LSF_SERVER , remote_lsf_server );
|
||||
queue_driver_set_option(driver, LSF_QUEUE, queue_name);
|
||||
queue_driver_set_option(driver, LSF_RESOURCE, resource_request);
|
||||
queue_driver_set_option(driver, LSF_SERVER, remote_lsf_server);
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
queue_driver_type * queue_driver_alloc_TORQUE() {
|
||||
queue_driver_type * driver = queue_driver_alloc(TORQUE_DRIVER);
|
||||
return driver;
|
||||
}
|
||||
|
||||
queue_driver_type * queue_driver_alloc_RSH( const char * rsh_cmd , const hash_type * rsh_hostlist) {
|
||||
queue_driver_type * driver = queue_driver_alloc( RSH_DRIVER );
|
||||
queue_driver_type * queue_driver_alloc_RSH(const char * rsh_cmd, const hash_type * rsh_hostlist) {
|
||||
queue_driver_type * driver = queue_driver_alloc(RSH_DRIVER);
|
||||
|
||||
queue_driver_set_option( driver , RSH_HOSTLIST , rsh_hostlist );
|
||||
queue_driver_set_option( driver , RSH_CMD , rsh_cmd );
|
||||
queue_driver_set_option(driver, RSH_HOSTLIST, rsh_hostlist);
|
||||
queue_driver_set_option(driver, RSH_CMD, rsh_cmd);
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
|
||||
queue_driver_type * queue_driver_alloc_local( ) {
|
||||
queue_driver_type * driver = queue_driver_alloc( LOCAL_DRIVER );
|
||||
queue_driver_type * queue_driver_alloc_local() {
|
||||
queue_driver_type * driver = queue_driver_alloc(LOCAL_DRIVER);
|
||||
|
||||
/* No options set for the local driver. */
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
void queue_driver_set_max_running( queue_driver_type * driver , int max_running) {
|
||||
void queue_driver_set_max_running(queue_driver_type * driver, int max_running) {
|
||||
driver->max_running = max_running;
|
||||
}
|
||||
|
||||
int queue_driver_get_max_running( const queue_driver_type * driver ) {
|
||||
int queue_driver_get_max_running(const queue_driver_type * driver) {
|
||||
return driver->max_running;
|
||||
}
|
||||
|
||||
const char * queue_driver_get_name( const queue_driver_type * driver ) {
|
||||
const char * queue_driver_get_name(const queue_driver_type * driver) {
|
||||
return driver->name;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
/* These are the functions used by the job_queue layer. */
|
||||
|
||||
void * queue_driver_submit_job( queue_driver_type * driver, const char * run_cmd , int num_cpu , const char * run_path , const char * job_name , int argc , const char ** argv) {
|
||||
return driver->submit( driver->data , run_cmd , num_cpu , run_path , job_name , argc , argv );
|
||||
void * queue_driver_submit_job(queue_driver_type * driver, const char * run_cmd, int num_cpu, const char * run_path, const char * job_name, int argc, const char ** argv) {
|
||||
return driver->submit(driver->data, run_cmd, num_cpu, run_path, job_name, argc, argv);
|
||||
}
|
||||
|
||||
void queue_driver_free_job( queue_driver_type * driver , void * job_data ) {
|
||||
driver->free_job( job_data );
|
||||
void queue_driver_free_job(queue_driver_type * driver, void * job_data) {
|
||||
driver->free_job(job_data);
|
||||
}
|
||||
|
||||
void queue_driver_kill_job( queue_driver_type * driver , void * job_data ) {
|
||||
driver->kill_job( driver->data , job_data );
|
||||
void queue_driver_kill_job(queue_driver_type * driver, void * job_data) {
|
||||
driver->kill_job(driver->data, job_data);
|
||||
}
|
||||
|
||||
job_status_type queue_driver_get_status( queue_driver_type * driver , void * job_data) {
|
||||
job_status_type status = driver->get_status( driver->data , job_data );
|
||||
job_status_type queue_driver_get_status(queue_driver_type * driver, void * job_data) {
|
||||
job_status_type status = driver->get_status(driver->data, job_data);
|
||||
return status;
|
||||
}
|
||||
|
||||
void queue_driver_free_driver( queue_driver_type * driver ) {
|
||||
driver->free_driver( driver->data );
|
||||
void queue_driver_free_driver(queue_driver_type * driver) {
|
||||
driver->free_driver(driver->data);
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
void queue_driver_free( queue_driver_type * driver ) {
|
||||
queue_driver_free_driver( driver );
|
||||
util_safe_free( driver->name );
|
||||
free( driver );
|
||||
void queue_driver_free(queue_driver_type * driver) {
|
||||
queue_driver_free_driver(driver);
|
||||
util_safe_free(driver->name);
|
||||
free(driver);
|
||||
}
|
||||
|
||||
|
||||
void queue_driver_free__( void * driver ) {
|
||||
queue_driver_type * queue_driver = queue_driver_safe_cast( driver );
|
||||
queue_driver_free( queue_driver );
|
||||
void queue_driver_free__(void * driver) {
|
||||
queue_driver_type * queue_driver = queue_driver_safe_cast(driver);
|
||||
queue_driver_free(queue_driver);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
/* Small functions to support enum introspection. */
|
||||
|
||||
const char * queue_driver_type_enum_iget( int index, int * value) {
|
||||
return util_enum_iget( index , JOB_DRIVER_ENUM_SIZE , (const util_enum_element_type []) { JOB_DRIVER_ENUM_DEFS }, value);
|
||||
const char * queue_driver_type_enum_iget(int index, int * value) {
|
||||
|
||||
return util_enum_iget(index, JOB_DRIVER_ENUM_SIZE, (const util_enum_element_type []) {
|
||||
JOB_DRIVER_ENUM_DEFS
|
||||
}, value);
|
||||
}
|
||||
|
||||
const char * queue_driver_status_emun_iget( int index, int * value) {
|
||||
return util_enum_iget( index , JOB_STATUS_ENUM_SIZE , (const util_enum_element_type []) { JOB_STATUS_ENUM_DEFS }, value);
|
||||
const char * queue_driver_status_emun_iget(int index, int * value) {
|
||||
|
||||
return util_enum_iget(index, JOB_STATUS_ENUM_SIZE, (const util_enum_element_type []) {
|
||||
JOB_STATUS_ENUM_DEFS
|
||||
}, value);
|
||||
}
|
||||
|
411
ThirdParty/Ert/devel/libjob_queue/src/torque_driver.c
vendored
Normal file
411
ThirdParty/Ert/devel/libjob_queue/src/torque_driver.c
vendored
Normal file
@ -0,0 +1,411 @@
|
||||
/*
|
||||
Copyright (C) 2013 Statoil ASA, Norway.
|
||||
|
||||
The file 'torque_driver.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <ert/util/util.h>
|
||||
#include <ert/util/type_macros.h>
|
||||
#include <ert/job_queue/torque_driver.h>
|
||||
|
||||
|
||||
#define TORQUE_DRIVER_TYPE_ID 34873653
|
||||
#define TORQUE_JOB_TYPE_ID 12312312
|
||||
|
||||
struct torque_driver_struct {
|
||||
UTIL_TYPE_ID_DECLARATION;
|
||||
char * queue_name;
|
||||
char * qsub_cmd;
|
||||
char * qstat_cmd;
|
||||
char * qdel_cmd;
|
||||
char * num_cpus_per_node_char;
|
||||
char * num_nodes_char;
|
||||
bool keep_qsub_output;
|
||||
int num_cpus_per_node;
|
||||
int num_nodes;
|
||||
|
||||
};
|
||||
|
||||
struct torque_job_struct {
|
||||
UTIL_TYPE_ID_DECLARATION;
|
||||
long int torque_jobnr;
|
||||
char * torque_jobnr_char;
|
||||
};
|
||||
|
||||
UTIL_SAFE_CAST_FUNCTION(torque_driver, TORQUE_DRIVER_TYPE_ID);
|
||||
|
||||
static UTIL_SAFE_CAST_FUNCTION_CONST(torque_driver, TORQUE_DRIVER_TYPE_ID)
|
||||
static UTIL_SAFE_CAST_FUNCTION(torque_job, TORQUE_JOB_TYPE_ID)
|
||||
|
||||
void * torque_driver_alloc() {
|
||||
torque_driver_type * torque_driver = util_malloc(sizeof * torque_driver);
|
||||
UTIL_TYPE_ID_INIT(torque_driver, TORQUE_DRIVER_TYPE_ID);
|
||||
|
||||
torque_driver->queue_name = NULL;
|
||||
torque_driver->qsub_cmd = NULL;
|
||||
torque_driver->qstat_cmd = NULL;
|
||||
torque_driver->qdel_cmd = NULL;
|
||||
torque_driver->num_cpus_per_node_char = NULL;
|
||||
torque_driver->num_nodes_char = NULL;
|
||||
torque_driver->keep_qsub_output = false;
|
||||
torque_driver->num_cpus_per_node = 1;
|
||||
torque_driver->num_nodes = 1;
|
||||
|
||||
torque_driver_set_option(torque_driver, TORQUE_QSUB_CMD, TORQUE_DEFAULT_QSUB_CMD);
|
||||
torque_driver_set_option(torque_driver, TORQUE_QSTAT_CMD, TORQUE_DEFAULT_QSTAT_CMD);
|
||||
torque_driver_set_option(torque_driver, TORQUE_QDEL_CMD, TORQUE_DEFAULT_QDEL_CMD);
|
||||
torque_driver_set_option(torque_driver, TORQUE_NUM_CPUS_PER_NODE, "1");
|
||||
torque_driver_set_option(torque_driver, TORQUE_NUM_NODES, "1");
|
||||
|
||||
return torque_driver;
|
||||
}
|
||||
|
||||
static void torque_driver_set_qsub_cmd(torque_driver_type * driver, const char * qsub_cmd) {
|
||||
driver->qsub_cmd = util_realloc_string_copy(driver->qsub_cmd, qsub_cmd);
|
||||
}
|
||||
|
||||
static void torque_driver_set_qstat_cmd(torque_driver_type * driver, const char * qstat_cmd) {
|
||||
driver->qstat_cmd = util_realloc_string_copy(driver->qstat_cmd, qstat_cmd);
|
||||
}
|
||||
|
||||
static void torque_driver_set_qdel_cmd(torque_driver_type * driver, const char * qdel_cmd) {
|
||||
driver->qdel_cmd = util_realloc_string_copy(driver->qdel_cmd, qdel_cmd);
|
||||
}
|
||||
|
||||
static void torque_driver_set_queue_name(torque_driver_type * driver, const char * queue_name) {
|
||||
driver->queue_name = util_realloc_string_copy(driver->queue_name, queue_name);
|
||||
}
|
||||
|
||||
static bool torque_driver_set_num_nodes(torque_driver_type * driver, const char* num_nodes_char) {
|
||||
int num_nodes = 0;
|
||||
if (util_sscanf_int(num_nodes_char, &num_nodes)) {
|
||||
driver->num_nodes = num_nodes;
|
||||
driver->num_nodes_char = util_realloc_string_copy(driver->num_nodes_char, num_nodes_char);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool torque_driver_set_keep_qsub_output(torque_driver_type * driver, const char* keep_output_bool_as_char) {
|
||||
bool keep_output_parsed;
|
||||
|
||||
if (util_sscanf_bool(keep_output_bool_as_char, &keep_output_parsed)) {
|
||||
driver->keep_qsub_output = keep_output_parsed;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool torque_driver_set_num_cpus_per_node(torque_driver_type * driver, const char* num_cpus_per_node_char) {
|
||||
int num_cpus_per_node = 0;
|
||||
if (util_sscanf_int(num_cpus_per_node_char, &num_cpus_per_node)) {
|
||||
driver->num_cpus_per_node = num_cpus_per_node;
|
||||
driver->num_cpus_per_node_char = util_realloc_string_copy(driver->num_cpus_per_node_char, num_cpus_per_node_char);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool torque_driver_set_option(void * __driver, const char * option_key, const void * value) {
|
||||
torque_driver_type * driver = torque_driver_safe_cast(__driver);
|
||||
bool option_set = true;
|
||||
{
|
||||
if (strcmp(TORQUE_QSUB_CMD, option_key) == 0)
|
||||
torque_driver_set_qsub_cmd(driver, value);
|
||||
else if (strcmp(TORQUE_QSTAT_CMD, option_key) == 0)
|
||||
torque_driver_set_qstat_cmd(driver, value);
|
||||
else if (strcmp(TORQUE_QDEL_CMD, option_key) == 0)
|
||||
torque_driver_set_qdel_cmd(driver, value);
|
||||
else if (strcmp(TORQUE_QUEUE, option_key) == 0)
|
||||
torque_driver_set_queue_name(driver, value);
|
||||
else if (strcmp(TORQUE_NUM_CPUS_PER_NODE, option_key) == 0)
|
||||
option_set = torque_driver_set_num_cpus_per_node(driver, value);
|
||||
else if (strcmp(TORQUE_NUM_NODES, option_key) == 0)
|
||||
option_set = torque_driver_set_num_nodes(driver, value);
|
||||
else if (strcmp(TORQUE_KEEP_QSUB_OUTPUT, option_key) == 0)
|
||||
option_set = torque_driver_set_keep_qsub_output(driver, value);
|
||||
else
|
||||
option_set = false;
|
||||
}
|
||||
return option_set;
|
||||
}
|
||||
|
||||
const void * torque_driver_get_option(const void * __driver, const char * option_key) {
|
||||
const torque_driver_type * driver = torque_driver_safe_cast_const(__driver);
|
||||
{
|
||||
if (strcmp(TORQUE_QSUB_CMD, option_key) == 0)
|
||||
return driver->qsub_cmd;
|
||||
else if (strcmp(TORQUE_QSTAT_CMD, option_key) == 0)
|
||||
return driver->qstat_cmd;
|
||||
else if (strcmp(TORQUE_QDEL_CMD, option_key) == 0)
|
||||
return driver->qdel_cmd;
|
||||
else if (strcmp(TORQUE_QUEUE, option_key) == 0)
|
||||
return driver->queue_name;
|
||||
else if (strcmp(TORQUE_NUM_CPUS_PER_NODE, option_key) == 0)
|
||||
return driver->num_cpus_per_node_char;
|
||||
else if (strcmp(TORQUE_NUM_NODES, option_key) == 0)
|
||||
return driver->num_nodes_char;
|
||||
else if (strcmp(TORQUE_KEEP_QSUB_OUTPUT, option_key) == 0)
|
||||
return driver->keep_qsub_output ? "1" : "0";
|
||||
else {
|
||||
util_abort("%s: option_id:%s not recognized for TORQUE driver \n", __func__, option_key);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
torque_job_type * torque_job_alloc() {
|
||||
torque_job_type * job;
|
||||
job = util_malloc(sizeof * job);
|
||||
job->torque_jobnr_char = NULL;
|
||||
job->torque_jobnr = 0;
|
||||
UTIL_TYPE_ID_INIT(job, TORQUE_JOB_TYPE_ID);
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
stringlist_type * torque_driver_alloc_cmd(torque_driver_type * driver,
|
||||
const char * job_name,
|
||||
const char * submit_script) {
|
||||
|
||||
|
||||
stringlist_type * argv = stringlist_alloc_new();
|
||||
|
||||
if (driver->keep_qsub_output) {
|
||||
stringlist_append_ref(argv, "-k");
|
||||
stringlist_append_ref(argv, "oe");
|
||||
}
|
||||
|
||||
{
|
||||
char * resource_string = util_alloc_sprintf("nodes=%d:ppn=%d", driver->num_nodes, driver->num_cpus_per_node);
|
||||
stringlist_append_ref(argv, "-l");
|
||||
stringlist_append_copy(argv, resource_string);
|
||||
free(resource_string);
|
||||
}
|
||||
|
||||
if (driver->queue_name != NULL) {
|
||||
stringlist_append_ref(argv, "-q");
|
||||
stringlist_append_ref(argv, driver->queue_name);
|
||||
}
|
||||
|
||||
if (job_name != NULL) {
|
||||
stringlist_append_ref(argv, "-N");
|
||||
stringlist_append_ref(argv, job_name);
|
||||
}
|
||||
|
||||
stringlist_append_ref(argv, submit_script);
|
||||
|
||||
return argv;
|
||||
}
|
||||
|
||||
static int torque_job_parse_qsub_stdout(const torque_driver_type * driver, const char * stdout_file) {
|
||||
int jobid;
|
||||
{
|
||||
FILE * stream = util_fopen(stdout_file, "r");
|
||||
char * jobid_string = util_fscanf_alloc_upto(stream, ".", false);
|
||||
|
||||
if (jobid_string == NULL || !util_sscanf_int(jobid_string, &jobid)) {
|
||||
|
||||
char * file_content = util_fread_alloc_file_content(stdout_file, NULL);
|
||||
fprintf(stderr, "Failed to get torque job id from file: %s \n", stdout_file);
|
||||
fprintf(stderr, "qsub command : %s \n", driver->qsub_cmd);
|
||||
fprintf(stderr, "File content: [%s]\n", file_content);
|
||||
free(file_content);
|
||||
util_exit("%s: \n", __func__);
|
||||
}
|
||||
free(jobid_string);
|
||||
fclose(stream);
|
||||
}
|
||||
return jobid;
|
||||
}
|
||||
|
||||
void torque_job_create_submit_script(const char * script_filename, const char * submit_cmd, int argc, const char ** job_argv) {
|
||||
if (submit_cmd == NULL) {
|
||||
util_abort("%s: cannot create submit script, because there is no executing commmand specified.", __func__);
|
||||
}
|
||||
|
||||
FILE* script_file = util_fopen(script_filename, "w");
|
||||
fprintf(script_file, "#!/bin/sh\n");
|
||||
|
||||
fprintf(script_file, "%s", submit_cmd);
|
||||
for (int i = 0; i < argc; i++) {
|
||||
|
||||
fprintf(script_file, " %s", job_argv[i]);
|
||||
}
|
||||
|
||||
util_fclose(script_file);
|
||||
}
|
||||
|
||||
static int torque_driver_submit_shell_job(torque_driver_type * driver,
|
||||
const char * run_path,
|
||||
const char * job_name,
|
||||
const char * submit_cmd,
|
||||
int num_cpu,
|
||||
int job_argc,
|
||||
const char ** job_argv) {
|
||||
int job_id;
|
||||
char * tmp_file = util_alloc_tmp_file("/tmp", "enkf-submit", true);
|
||||
char * script_filename = util_alloc_filename(run_path, "qsub_script", "sh");
|
||||
torque_job_create_submit_script(script_filename, submit_cmd, job_argc, job_argv);
|
||||
{
|
||||
int p_units_from_driver = driver->num_cpus_per_node * driver->num_nodes;
|
||||
if (num_cpu != p_units_from_driver) {
|
||||
util_abort("%s: Error in config, job's config requires %d processing units, but config says %s: %d, and %s: %d, which multiplied becomes: %d \n",
|
||||
__func__, num_cpu, TORQUE_NUM_CPUS_PER_NODE, driver->num_cpus_per_node, TORQUE_NUM_NODES, driver->num_nodes, p_units_from_driver);
|
||||
}
|
||||
stringlist_type * remote_argv = torque_driver_alloc_cmd(driver, job_name, script_filename);
|
||||
char ** argv = stringlist_alloc_char_ref(remote_argv);
|
||||
util_fork_exec(driver->qsub_cmd, stringlist_get_size(remote_argv), (const char **) argv, true, NULL, NULL, NULL, tmp_file, NULL);
|
||||
|
||||
free(argv);
|
||||
stringlist_free(remote_argv);
|
||||
}
|
||||
|
||||
job_id = torque_job_parse_qsub_stdout(driver, tmp_file);
|
||||
|
||||
util_unlink_existing(tmp_file);
|
||||
free(tmp_file);
|
||||
|
||||
return job_id;
|
||||
}
|
||||
|
||||
void torque_job_free(torque_job_type * job) {
|
||||
|
||||
util_safe_free(job->torque_jobnr_char);
|
||||
free(job);
|
||||
}
|
||||
|
||||
void torque_driver_free_job(void * __job) {
|
||||
|
||||
torque_job_type * job = torque_job_safe_cast(__job);
|
||||
torque_job_free(job);
|
||||
}
|
||||
|
||||
void * torque_driver_submit_job(void * __driver,
|
||||
const char * submit_cmd,
|
||||
int num_cpu,
|
||||
const char * run_path,
|
||||
const char * job_name,
|
||||
int argc,
|
||||
const char ** argv) {
|
||||
torque_driver_type * driver = torque_driver_safe_cast(__driver);
|
||||
torque_job_type * job = torque_job_alloc();
|
||||
{
|
||||
job->torque_jobnr = torque_driver_submit_shell_job(driver, run_path, job_name, submit_cmd, num_cpu, argc, argv);
|
||||
job->torque_jobnr_char = util_alloc_sprintf("%ld", job->torque_jobnr);
|
||||
}
|
||||
|
||||
if (job->torque_jobnr > 0)
|
||||
return job;
|
||||
else {
|
||||
/*
|
||||
The submit failed - the queue system shall handle
|
||||
NULL return values.
|
||||
*/
|
||||
torque_job_free(job);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static char* torque_driver_get_qstat_status(torque_driver_type * driver, char * jobnr_char) {
|
||||
char * status = util_malloc(sizeof (char)*2);
|
||||
char * tmp_file = util_alloc_tmp_file("/tmp", "enkf-qstat", true);
|
||||
|
||||
{
|
||||
char ** argv = util_calloc(1, sizeof * argv);
|
||||
argv[0] = jobnr_char;
|
||||
|
||||
util_fork_exec(driver->qstat_cmd, 1, (const char **) argv, true, NULL, NULL, NULL, tmp_file, NULL);
|
||||
free(argv);
|
||||
}
|
||||
|
||||
FILE *stream = util_fopen(tmp_file, "r");
|
||||
bool at_eof = false;
|
||||
util_fskip_lines(stream, 2);
|
||||
char * line = util_fscanf_alloc_line(stream, &at_eof);
|
||||
fclose(stream);
|
||||
|
||||
if (line != NULL) {
|
||||
char job_id_full_string[32];
|
||||
if (sscanf(line, "%s %*s %*s %*s %s %*s", job_id_full_string, status) == 2) {
|
||||
char *dotPtr = strchr(job_id_full_string, '.');
|
||||
int dotPosition = dotPtr - job_id_full_string;
|
||||
char* job_id_as_char_ptr = util_alloc_substring_copy(job_id_full_string, 0, dotPosition);
|
||||
if (strcmp(job_id_as_char_ptr, jobnr_char) != 0) {
|
||||
util_abort("%s: Job id input (%d) does not match the one found by qstat (%d)\n", __func__, jobnr_char, job_id_as_char_ptr);
|
||||
}
|
||||
free(job_id_as_char_ptr);
|
||||
}
|
||||
free(line);
|
||||
} else {
|
||||
util_abort("%s: Unable to read qstat's output line number 3 from file: %s", __func__, tmp_file);
|
||||
}
|
||||
|
||||
util_unlink_existing(tmp_file);
|
||||
free(tmp_file);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
job_status_type torque_driver_get_job_status(void * __driver, void * __job) {
|
||||
torque_driver_type * driver = torque_driver_safe_cast(__driver);
|
||||
torque_job_type * job = torque_job_safe_cast(__job);
|
||||
char * status = torque_driver_get_qstat_status(driver, job->torque_jobnr_char);
|
||||
int result = JOB_QUEUE_FAILED;
|
||||
if (strcmp(status, "R") == 0) {
|
||||
result = JOB_QUEUE_RUNNING;
|
||||
} else if (strcmp(status, "E") == 0) {
|
||||
result = JOB_QUEUE_DONE;
|
||||
} else if (strcmp(status, "C") == 0) {
|
||||
result = JOB_QUEUE_DONE;
|
||||
} else if (strcmp(status, "Q") == 0) {
|
||||
result = JOB_QUEUE_PENDING;
|
||||
} else {
|
||||
util_abort("%s: Unknown status found (%s), expecting one of R, E, C and Q.\n", __func__, status);
|
||||
}
|
||||
free(status);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void torque_driver_kill_job(void * __driver, void * __job) {
|
||||
|
||||
torque_driver_type * driver = torque_driver_safe_cast(__driver);
|
||||
torque_job_type * job = torque_job_safe_cast(__job);
|
||||
util_fork_exec(driver->qdel_cmd, 1, (const char **) &job->torque_jobnr_char, true, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void torque_driver_free(torque_driver_type * driver) {
|
||||
|
||||
util_safe_free(driver->queue_name);
|
||||
free(driver->qdel_cmd);
|
||||
free(driver->qstat_cmd);
|
||||
free(driver->qsub_cmd);
|
||||
free(driver->num_cpus_per_node_char);
|
||||
free(driver->num_nodes_char);
|
||||
|
||||
free(driver);
|
||||
driver = NULL;
|
||||
}
|
||||
|
||||
void torque_driver_free__(void * __driver) {
|
||||
torque_driver_type * driver = torque_driver_safe_cast(__driver);
|
||||
torque_driver_free(driver);
|
||||
}
|
||||
|
@ -256,6 +256,7 @@ workflow_job_type * workflow_job_config_alloc( const char * name , config_type *
|
||||
config_clear( config );
|
||||
if (config_parse( config , config_file , "--", NULL , NULL , CONFIG_UNRECOGNIZED_WARN , true)) {
|
||||
bool internal = DEFAULT_INTERNAL;
|
||||
printf("Parse OK \n");
|
||||
if (config_item_set( config , INTERNAL_KEY))
|
||||
internal = config_iget_as_bool( config , INTERNAL_KEY , 0 , 0 );
|
||||
|
||||
@ -284,8 +285,11 @@ workflow_job_type * workflow_job_config_alloc( const char * name , config_type *
|
||||
if (config_item_set( config , FUNCTION_KEY))
|
||||
workflow_job_set_function( workflow_job , config_get_value( config , FUNCTION_KEY));
|
||||
|
||||
if (config_item_set( config , EXECUTABLE_KEY))
|
||||
if (config_item_set( config , EXECUTABLE_KEY)) {
|
||||
workflow_job_set_executable( workflow_job , config_get_value_as_abspath( config , EXECUTABLE_KEY));
|
||||
printf("Setting executable:%s \n",config_get_value_as_abspath( config , EXECUTABLE_KEY));
|
||||
} else
|
||||
printf("EXECUTABLE key not set ??? \n");
|
||||
|
||||
workflow_job_validate( workflow_job );
|
||||
|
||||
|
@ -51,4 +51,15 @@ endif()
|
||||
add_test( job_lsf_test ${EXECUTABLE_OUTPUT_PATH}/job_lsf_test )
|
||||
if (LSF_SERVERS)
|
||||
add_test( job_lsf_submit_test ${EXECUTABLE_OUTPUT_PATH}/job_lsf_submit_test ${EXECUTABLE_OUTPUT_PATH}/job_program ${LSF_SERVERS})
|
||||
set_property( TEST job_lsf_submit_test PROPERTY LABELS LSF)
|
||||
endif()
|
||||
|
||||
add_executable( job_torque_test job_torque_test.c )
|
||||
target_link_libraries( job_torque_test job_queue util )
|
||||
add_test( job_torque_test ${EXECUTABLE_OUTPUT_PATH}/job_torque_test )
|
||||
|
||||
add_executable( job_torque_submit_test job_torque_submit_test.c )
|
||||
target_link_libraries( job_torque_submit_test job_queue util )
|
||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data/qsub_emulators/ DESTINATION ${EXECUTABLE_OUTPUT_PATH})
|
||||
add_test(NAME job_torque_submit_test WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${EXECUTABLE_OUTPUT_PATH}/job_torque_submit_test dummyparam)
|
||||
set_property(TEST job_torque_submit_test PROPERTY ENVIRONMENT “setenv PATH ${EXECUTABLE_OUTPUT_PATH}:$PATH”)
|
||||
|
3
ThirdParty/Ert/devel/libjob_queue/tests/data/qsub_emulators/qdel
vendored
Normal file
3
ThirdParty/Ert/devel/libjob_queue/tests/data/qsub_emulators/qdel
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
echo "echo \"Job id Name User Time Use S Queue\"" > qstat
|
||||
echo "echo \"------------------------- ---------------- --------------- -------- - -----\"" >> qstat
|
||||
echo "echo \"1612427.st-lcmm ...130getupdates fama 00:00:01 E normal\"" >> qstat
|
1
ThirdParty/Ert/devel/libjob_queue/tests/data/qsub_emulators/qstat
vendored
Normal file
1
ThirdParty/Ert/devel/libjob_queue/tests/data/qsub_emulators/qstat
vendored
Normal file
@ -0,0 +1 @@
|
||||
Content will be piped into this file
|
4
ThirdParty/Ert/devel/libjob_queue/tests/data/qsub_emulators/qsub
vendored
Normal file
4
ThirdParty/Ert/devel/libjob_queue/tests/data/qsub_emulators/qsub
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
echo 1612427.greier.og.greier
|
||||
echo "echo \"Job id Name User Time Use S Queue\"" > qstat
|
||||
echo "echo \"------------------------- ---------------- --------------- -------- - -----\"" >> qstat
|
||||
echo "echo \"1612427.st-lcmm ...130getupdates fama 00:00:01 R normal\"" >> qstat
|
@ -28,13 +28,17 @@
|
||||
#include <ert/job_queue/job_queue.h>
|
||||
|
||||
|
||||
|
||||
int main( int argc , char ** argv) {
|
||||
void job_queue_set_driver_(job_driver_type driver_type) {
|
||||
job_queue_type * queue = job_queue_alloc( 10 , "OK" , "ERROR");
|
||||
queue_driver_type * driver = queue_driver_alloc( LSF_DRIVER );
|
||||
queue_driver_type * driver = queue_driver_alloc( driver_type );
|
||||
test_assert_false( job_queue_has_driver( queue ));
|
||||
|
||||
job_queue_set_driver( queue , driver );
|
||||
test_assert_true( job_queue_has_driver( queue ));
|
||||
}
|
||||
|
||||
int main( int argc , char ** argv) {
|
||||
job_queue_set_driver_(LSF_DRIVER);
|
||||
job_queue_set_driver_(TORQUE_DRIVER);
|
||||
exit(0);
|
||||
}
|
||||
|
78
ThirdParty/Ert/devel/libjob_queue/tests/job_torque_submit_test.c
vendored
Normal file
78
ThirdParty/Ert/devel/libjob_queue/tests/job_torque_submit_test.c
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
Copyright (C) 2013 Statoil ASA, Norway.
|
||||
|
||||
The file 'job_torque_submit_test.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <ert/util/util.h>
|
||||
#include <ert/util/test_util.h>
|
||||
|
||||
#include <ert/job_queue/torque_driver.h>
|
||||
|
||||
void test_submit(torque_driver_type * driver, const char * cmd) {
|
||||
char * run_path = util_alloc_cwd();
|
||||
torque_job_type * job = torque_driver_submit_job(driver, cmd, 1, run_path, "TEST-TORQUE-SUBMIT", 0, NULL);
|
||||
|
||||
if (job != NULL) {
|
||||
int torque_status = torque_driver_get_job_status(driver, job);
|
||||
if (!((torque_status == JOB_QUEUE_RUNNING) || (torque_status == JOB_QUEUE_PENDING))) {
|
||||
test_exit("After start of job, the status is %d, it should have been JOB_QUEUE_RUNNING(%d) or JOB_QUEUE_PENDING (%d). Other statuses are JOB_QUEUE_EXIT(%d) and JOB_QUEUE_FAILED(%d)\n", torque_status, JOB_QUEUE_RUNNING, JOB_QUEUE_PENDING, JOB_QUEUE_EXIT, JOB_QUEUE_FAILED);
|
||||
}
|
||||
|
||||
torque_driver_kill_job(driver, job);
|
||||
printf("Waiting 5 seconds");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
sleep(1);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
torque_status = torque_driver_get_job_status(driver, job);
|
||||
if (torque_status != JOB_QUEUE_EXIT && torque_status != JOB_QUEUE_DONE) {
|
||||
exit(1);
|
||||
test_exit("After kill of job, the status is %d, it should have been JOB_QUEUE_EXIT, which is %d\n", torque_status, JOB_QUEUE_EXIT);
|
||||
}
|
||||
} else {
|
||||
exit(1);
|
||||
test_exit("Function %s returned null-pointer to job, terminating test.", "torque_driver_submit_job");
|
||||
}
|
||||
|
||||
free(run_path);
|
||||
torque_driver_free_job(job);
|
||||
}
|
||||
|
||||
void test_submit_nocommand(torque_driver_type * driver) {
|
||||
test_submit(driver, NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
torque_driver_type * driver = torque_driver_alloc();
|
||||
if (argc == 1) {
|
||||
test_submit_nocommand(driver);
|
||||
} else if (argc == 2) {
|
||||
test_submit(driver, argv[1]);
|
||||
} else {
|
||||
printf("Only accepts zero or one arguments (the job script to run)\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("Submit, status and kill OK\n");
|
||||
torque_driver_free(driver);
|
||||
|
||||
exit(0);
|
||||
}
|
105
ThirdParty/Ert/devel/libjob_queue/tests/job_torque_test.c
vendored
Normal file
105
ThirdParty/Ert/devel/libjob_queue/tests/job_torque_test.c
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
Copyright (C) 2012 Statoil ASA, Norway.
|
||||
|
||||
The file 'job_lsf_test.c' is part of ERT - Ensemble based Reservoir Tool.
|
||||
|
||||
ERT is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
for more details.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <ert/util/test_util.h>
|
||||
#include <ert/job_queue/torque_driver.h>
|
||||
|
||||
#include "ert/util/util.h"
|
||||
|
||||
void test_option(torque_driver_type * driver, const char * option, const char * value) {
|
||||
test_assert_true(torque_driver_set_option(driver, option, value));
|
||||
test_assert_string_equal(torque_driver_get_option(driver, option), value);
|
||||
}
|
||||
|
||||
void setoption_setalloptions_optionsset() {
|
||||
torque_driver_type * driver = torque_driver_alloc();
|
||||
test_option(driver, TORQUE_QSUB_CMD, "XYZaaa");
|
||||
test_option(driver, TORQUE_QSTAT_CMD, "xyZfff");
|
||||
test_option(driver, TORQUE_QDEL_CMD, "ZZyfff");
|
||||
test_option(driver, TORQUE_QUEUE, "superhigh");
|
||||
test_option(driver, TORQUE_NUM_CPUS_PER_NODE, "42");
|
||||
test_option(driver, TORQUE_NUM_NODES, "36");
|
||||
test_option(driver, TORQUE_KEEP_QSUB_OUTPUT, "1");
|
||||
test_option(driver, TORQUE_KEEP_QSUB_OUTPUT, "0");
|
||||
|
||||
printf("Options OK\n");
|
||||
torque_driver_free(driver);
|
||||
}
|
||||
|
||||
void setoption_set_typed_options_wrong_format_returns_false() {
|
||||
torque_driver_type * driver = torque_driver_alloc();
|
||||
test_assert_false(torque_driver_set_option(driver, TORQUE_NUM_CPUS_PER_NODE, "42.2"));
|
||||
test_assert_false(torque_driver_set_option(driver, TORQUE_NUM_CPUS_PER_NODE, "fire"));
|
||||
test_assert_false(torque_driver_set_option(driver, TORQUE_NUM_NODES, "42.2"));
|
||||
test_assert_false(torque_driver_set_option(driver, TORQUE_NUM_NODES, "fire"));
|
||||
test_assert_true(torque_driver_set_option(driver, TORQUE_KEEP_QSUB_OUTPUT, "true"));
|
||||
test_assert_true(torque_driver_set_option(driver, TORQUE_KEEP_QSUB_OUTPUT, "1"));
|
||||
test_assert_false(torque_driver_set_option(driver, TORQUE_KEEP_QSUB_OUTPUT, "ja"));
|
||||
test_assert_false(torque_driver_set_option(driver, TORQUE_KEEP_QSUB_OUTPUT, "22"));
|
||||
test_assert_false(torque_driver_set_option(driver, TORQUE_KEEP_QSUB_OUTPUT, "1.1"));
|
||||
}
|
||||
|
||||
void getoption_nooptionsset_defaultoptionsreturned() {
|
||||
torque_driver_type * driver = torque_driver_alloc();
|
||||
test_assert_string_equal(torque_driver_get_option(driver, TORQUE_QSUB_CMD), TORQUE_DEFAULT_QSUB_CMD);
|
||||
test_assert_string_equal(torque_driver_get_option(driver, TORQUE_QSTAT_CMD), TORQUE_DEFAULT_QSTAT_CMD);
|
||||
test_assert_string_equal(torque_driver_get_option(driver, TORQUE_QDEL_CMD), TORQUE_DEFAULT_QDEL_CMD);
|
||||
test_assert_string_equal(torque_driver_get_option(driver, TORQUE_KEEP_QSUB_OUTPUT), "0");
|
||||
test_assert_string_equal(torque_driver_get_option(driver, TORQUE_NUM_CPUS_PER_NODE), "1");
|
||||
test_assert_string_equal(torque_driver_get_option(driver, TORQUE_NUM_NODES), "1");
|
||||
|
||||
printf("Default options OK\n");
|
||||
torque_driver_free(driver);
|
||||
}
|
||||
|
||||
void create_submit_script_script_according_to_input() {
|
||||
char ** args = util_calloc(2, sizeof * args);
|
||||
args[0] = "/tmp/jaja/";
|
||||
args[1] = "number2arg";
|
||||
char * script_filename = util_alloc_filename("/tmp/", "qsub_script", "sh");
|
||||
torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args);
|
||||
printf("Create submit script OK\n");
|
||||
|
||||
FILE* file_stream = util_fopen(script_filename, "r");
|
||||
bool at_eof = false;
|
||||
|
||||
char * line = util_fscanf_alloc_line(file_stream, &at_eof);
|
||||
test_assert_string_equal("#!/bin/sh", line);
|
||||
free(line);
|
||||
|
||||
line = util_fscanf_alloc_line(file_stream, &at_eof);
|
||||
test_assert_string_equal("job_program.py /tmp/jaja/ number2arg", line);
|
||||
free(line);
|
||||
|
||||
line = util_fscanf_alloc_line(file_stream, &at_eof);
|
||||
free(line);
|
||||
test_assert_true(at_eof);
|
||||
|
||||
fclose(file_stream);
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
getoption_nooptionsset_defaultoptionsreturned();
|
||||
setoption_setalloptions_optionsset();
|
||||
setoption_set_typed_options_wrong_format_returns_false();
|
||||
create_submit_script_script_according_to_input();
|
||||
exit(0);
|
||||
}
|
@ -75,7 +75,12 @@ int main( int argc , char ** argv) {
|
||||
workflow_joblist_type * joblist = workflow_joblist_alloc();
|
||||
|
||||
if (!workflow_joblist_add_job_from_file( joblist , "CREATE_FILE" , exworkflow)) {
|
||||
remove( exworkflow );
|
||||
//remove( exworkflow );
|
||||
{
|
||||
config_type * workflow_compiler = workflow_joblist_get_compiler( joblist );
|
||||
printf("Compiler errors: \n");
|
||||
config_fprintf_errors( workflow_compiler , true , stdout );
|
||||
}
|
||||
test_error_exit("Loading job CREATE_FILE failed\n");
|
||||
} else
|
||||
remove( exworkflow );
|
||||
@ -85,7 +90,6 @@ int main( int argc , char ** argv) {
|
||||
|
||||
{
|
||||
config_type * workflow_compiler = workflow_joblist_get_compiler( joblist );
|
||||
|
||||
if (config_get_schema_size( workflow_compiler ) != 2)
|
||||
test_error_exit("Config compiler - wrong size \n");
|
||||
}
|
||||
|
22408
ThirdParty/Ert/devel/libsched/src/tests/sched_test_05.SCH
vendored
22408
ThirdParty/Ert/devel/libsched/src/tests/sched_test_05.SCH
vendored
File diff suppressed because it is too large
Load Diff
1
ThirdParty/Ert/devel/python/CMakeLists.txt
vendored
1
ThirdParty/Ert/devel/python/CMakeLists.txt
vendored
@ -1,2 +1,3 @@
|
||||
set(PYTHON_INSTALL_PREFIX "python")
|
||||
add_subdirectory( test )
|
||||
add_subdirectory( python )
|
@ -1,2 +1 @@
|
||||
set(PYTHON_INSTALL_PREFIX "python")
|
||||
add_subdirectory( ert )
|
||||
|
@ -1,4 +1,5 @@
|
||||
add_python_target( python_ert ${PYTHON_INSTALL_PREFIX}/ert __init__ )
|
||||
add_python_package("Python ert" ${PYTHON_INSTALL_PREFIX}/ert "__init__.py" T)
|
||||
|
||||
add_subdirectory( config )
|
||||
add_subdirectory( cwrap )
|
||||
add_subdirectory( ecl )
|
||||
@ -9,3 +10,4 @@ add_subdirectory( rms )
|
||||
add_subdirectory( sched )
|
||||
add_subdirectory( util )
|
||||
add_subdirectory( well )
|
||||
|
||||
|
@ -1 +1 @@
|
||||
add_python_target(python_config ${PYTHON_INSTALL_PREFIX}/ert/config "config;__init__;libconfig;config_enums;config_parser")
|
||||
add_python_package("Python ert.config" ${PYTHON_INSTALL_PREFIX}/ert/config "config.py;__init__.py;libconfig.py;config_enums.py;config_parser.py" True)
|
||||
|
@ -1 +1 @@
|
||||
add_python_target(python_cwrap ${PYTHON_INSTALL_PREFIX}/ert/cwrap "cclass;cenum;cfile;clib;cwrap;__init__")
|
||||
add_python_package("Python ert.cwrap" ${PYTHON_INSTALL_PREFIX}/ert/cwrap "cclass.py;cenum.py;cfile.py;clib.py;cwrap.py;__init__.py" True)
|
||||
|
@ -1,5 +1,5 @@
|
||||
add_python_target(python_ecl ${PYTHON_INSTALL_PREFIX}/ert/ecl "ecl_case;ecl_default;ecl_file;ecl_grav_calc;ecl_grav;ecl_grid;ecl_kw;ecl;ecl_queue;ecl_region;ecl_rft;ecl_subsidence;ecl_sum;ecl_util;fortio;__init__;libecl")
|
||||
add_python_package("Python ert.ecl" ${PYTHON_INSTALL_PREFIX}/ert/ecl "ecl_case.py;ecl_default.py;ecl_file.py;ecl_grav_calc.py;ecl_grav.py;ecl_grid.py;ecl_kw.py;ecl.py;ecl_queue.py;ecl_region.py;ecl_rft.py;ecl_subsidence.py;ecl_sum.py;ecl_util.py;fortio.py;__init__.py;libecl.py" True)
|
||||
|
||||
if (EXISTS "ecl_local.py")
|
||||
add_python_target( python_ecl_local ${PYTHON_INSTALL_PREFIX}/ert/ecl "ecl_local")
|
||||
add_python_file( "Python ert.ecl.ecl_local" ${PYTHON_INSTALL_PREFIX}/ert/ecl "ecl_local.py" True)
|
||||
endif()
|
||||
|
@ -173,7 +173,7 @@ class EclFile(CClass):
|
||||
return "EclFile: %s" % self.name
|
||||
|
||||
|
||||
def __init__( self , filename , read_only = True):
|
||||
def __init__( self , filename , flags = 0):
|
||||
"""
|
||||
Loads the complete file @filename.
|
||||
|
||||
@ -181,23 +181,23 @@ class EclFile(CClass):
|
||||
@filename. The file @filename must be in 'restart format' -
|
||||
otherwise it will be crash and burn.
|
||||
|
||||
The optional argument @kw_list can be used to limit the
|
||||
loading to only some of the keywords in the file, @kw_list
|
||||
should be a an ordinary Python list of strings. To load only
|
||||
the solution data from a restart file:
|
||||
The optional argument flags can be an or'ed combination of the
|
||||
flags:
|
||||
|
||||
sol_data = ecl.EclFile("ECLIPSE.UNRST" , kw_list = ["PRESSURE" , "SWAT" , "SGAS"])
|
||||
ecl.ECL_FILE_WRITABLE : It is possible to update the
|
||||
content of the keywords in the file.
|
||||
|
||||
ecl.ECL_FILE_CLOSE_STREAM : The underlying FILE * is closed
|
||||
when not used; to save number of open file descriptors
|
||||
in cases where a high number of EclFile instances are
|
||||
open concurrently.
|
||||
|
||||
When the file has been loaded the EclFile instance can be used
|
||||
to query for and get reference to the EclKW instances
|
||||
constituting the file, like e.g. SWAT from a restart file or
|
||||
FIPNUM from an INIT file.
|
||||
"""
|
||||
if read_only:
|
||||
c_ptr = cfunc.open( filename )
|
||||
else:
|
||||
c_ptr = cfunc.open_writable( filename )
|
||||
|
||||
c_ptr = cfunc.open( filename , flags )
|
||||
self.init_cobj( c_ptr , cfunc.close )
|
||||
if c_ptr is None:
|
||||
raise IOError("Failed to open file file:%s" % filename)
|
||||
@ -227,7 +227,7 @@ class EclFile(CClass):
|
||||
keyword you got from this EclFile instance, otherwise the
|
||||
function will fail.
|
||||
"""
|
||||
if cfunc.is_writable( self ):
|
||||
if cfunc.writable( self ):
|
||||
cfunc.save_kw( self , kw )
|
||||
else:
|
||||
raise IOError("save_kw: the file:%s has been opened read only." % self.name)
|
||||
@ -712,9 +712,8 @@ cwrapper.registerType( "ecl_file" , EclFile )
|
||||
# used outside this scope.
|
||||
cfunc = CWrapperNameSpace("ecl_file")
|
||||
|
||||
cfunc.open = cwrapper.prototype("c_void_p ecl_file_try_open( char* )")
|
||||
cfunc.open_writable = cwrapper.prototype("c_void_p ecl_file_open_writable( char* )")
|
||||
cfunc.is_writable = cwrapper.prototype("bool ecl_file_writable( ecl_file )")
|
||||
cfunc.open = cwrapper.prototype("c_void_p ecl_file_try_open( char* , int )")
|
||||
cfunc.writable = cwrapper.prototype("bool ecl_file_writable( ecl_file )")
|
||||
cfunc.new = cwrapper.prototype("c_void_p ecl_file_alloc_empty( )")
|
||||
cfunc.save_kw = cwrapper.prototype("void ecl_file_save_kw( ecl_file , ecl_kw )")
|
||||
|
||||
|
@ -772,3 +772,4 @@ cfunc.fwrite_GRID = cwrapper.prototype("void ecl_grid_fwrite_
|
||||
cfunc.fwrite_EGRID = cwrapper.prototype("void ecl_grid_fwrite_EGRID( ecl_grid , char* )")
|
||||
cfunc.equal = cwrapper.prototype("bool ecl_grid_compare(ecl_grid , ecl_grid , bool, bool)")
|
||||
cfunc.dual_grid = cwrapper.prototype("bool ecl_grid_dual_grid( ecl_grid )")
|
||||
|
||||
|
@ -33,7 +33,7 @@ class EclRFTFile(CClass):
|
||||
c_ptr = cfunc_file.load( case )
|
||||
if c_ptr:
|
||||
obj = object.__new__( cls )
|
||||
self.init_cobj( c_ptr , cfunc_file.free )
|
||||
obj.init_cobj( c_ptr , cfunc_file.free )
|
||||
return obj
|
||||
else:
|
||||
return None
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user