Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove broken replace_kw from ResdataFile #971

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 1 addition & 94 deletions python/resdata/resfile/rd_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
import ctypes
import datetime
import re
import types

from cwrap import BaseCClass
from resdata import FileMode, FileType, ResdataPrototype
from resdata.resfile import ResdataFileView, ResdataKW
from resdata.resfile import ResdataKW
from resdata.util.util import CTime, monkey_the_camel


Expand All @@ -51,9 +50,6 @@ class ResdataFile(BaseCClass):
"int rd_file_get_restart_index(rd_file, rd_time_t)"
)
_get_src_file = ResdataPrototype("char* rd_file_get_src_file(rd_file)")
_replace_kw = ResdataPrototype(
"void rd_file_replace_kw(rd_file, rd_kw, rd_kw, bool)"
)
_fwrite = ResdataPrototype("void rd_file_fwrite_fortio(rd_file, rd_fortio, int)")
_has_report_step = ResdataPrototype("bool rd_file_has_report_step(rd_file, int)")
_has_sim_time = ResdataPrototype("bool rd_file_has_sim_time(rd_file, rd_time_t)")
Expand Down Expand Up @@ -88,12 +84,6 @@ def get_filetype(filename):

return (file_type, report_step, fmt_file)

@classmethod
def restart_block(cls, filename, dtime=None, report_step=None):
raise NotImplementedError(
"The restart_block implementation has been removed - open file normally and use ResdataFileView."
)

@classmethod
def contains_report_step(cls, filename, report_step):
"""
Expand Down Expand Up @@ -261,55 +251,6 @@ def restart_view(
seqnum_index, report_step, sim_time, sim_days
)

def select_block(self, kw, kw_index):
raise NotImplementedError(
"The select_block implementation has been removed - use ResdataFileView"
)

def select_global(self):
raise NotImplementedError(
"The select_global implementation has been removed - use ResdataFileView"
)

def select_restart_section(self, index=None, report_step=None, sim_time=None):
raise NotImplementedError(
"The select_restart_section implementation has been removed - use ResdataFileView"
)
"""
Will select a restart section as the active section.

You must specify a report step with the @report_step argument,
a true time with the @sim_time argument or a plain index to
select restart block. If none of arguments are given exception
TypeError will be raised. If present the @sim_time argument
should be a datetime instance.

If the restart section you ask for can not be found the method
will raise a ValueError exeception. To protect against this
you can query first with the has_report_step(),
has_sim_time() or num_report_steps() methods.

This method should be used when you have already loaded the
complete file; if you only want to load a section from the
file you can use the classmethod restart_block().

The method will return 'self' which can be used to aid
readability.
"""

def select_last_restart(self):
raise NotImplementedError(
"The select_restart_section implementation has been removed - use ResdataFileView"
)
"""
Will select the last SEQNUM block in restart file.

Works by searching for the last SEQNUM keyword; the SEQNUM
Keywords are only present in unified restart files. If this
is a non-unified restart file (or not a restart file at all),
the method will do nothing and return False.
"""

def __getitem__(self, index):
"""
Implements [] operator; index can be integer or key.
Expand Down Expand Up @@ -435,40 +376,6 @@ def restart_get_kw(self, kw_name, dtime, copy=False):
'Does not have keyword "%s" at time:%s.' % (kw_name, dtime)
)

def replace_kw(self, old_kw, new_kw):
"""
Will replace @old_kw with @new_kw in current ResdataFile instance.

This method can be used to replace one of the ResdataKW instances
in the current ResdataFile. The @old_kw reference must be to the
actual ResdataKW instance in the current ResdataFile instance (the
final comparison is based on C pointer equality!), i.e. it
must be a reference (not a copy) from one of the ??get_kw??
methods of the ResdataFile class. In the example below we replace
the SWAT keyword from a restart file:

swat = file.iget_named_kw( "SWAT" , 0 )
new_swat = swat * 0.25
file.replace_kw( swat , new_swat )


The C-level rd_file_type structure takes full ownership of
all installed rd_kw instances; mixing the garbage collector
into it means that this is quite low level - and potentially
dangerous!
"""

# We ensure that this scope owns the new_kw instance; the
# new_kw will be handed over to the rd_file instance, and we
# can not give away something we do not alreeady own.
if not new_kw.data_owner:
new_kw = ResdataKW.copy(new_kw)

# The rd_file instance will take responsability for freeing
# this rd_kw instance.
new_kw.data_owner = False
self._replace_kw(old_kw, new_kw, False)

@property
def size(self):
"""
Expand Down
31 changes: 0 additions & 31 deletions python/tests/rd_tests/test_removed.py

This file was deleted.

Loading