Merge branch 'development' into polishing-for-release
This commit is contained in:
commit
958936c449
|
@ -223,25 +223,46 @@ class Colormap(mpl.colors.ListedColormap):
|
||||||
return Colormap(np.array(rev.colors),rev.name[:-4] if rev.name.endswith('_r_r') else rev.name)
|
return Colormap(np.array(rev.colors),rev.name[:-4] if rev.name.endswith('_r_r') else rev.name)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_file_handle(self,fname,extension):
|
||||||
|
"""
|
||||||
|
Provide file handle.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
fname : file, str, pathlib.Path, or None
|
||||||
|
Filename or filehandle, will be name of the colormap+extension if None.
|
||||||
|
|
||||||
|
extension: str
|
||||||
|
Extension of the filename.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
f
|
||||||
|
File handle
|
||||||
|
|
||||||
|
"""
|
||||||
|
if fname is None:
|
||||||
|
fhandle = open(self.name.replace(' ','_')+'.'+extension,'w',newline='\n')
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
fhandle = open(fname,'w',newline='\n')
|
||||||
|
except TypeError:
|
||||||
|
fhandle = fname
|
||||||
|
|
||||||
|
return fhandle
|
||||||
|
|
||||||
|
|
||||||
def save_paraview(self,fname=None):
|
def save_paraview(self,fname=None):
|
||||||
"""
|
"""
|
||||||
Save as JSON file for use in Paraview.
|
Save as JSON file for use in Paraview.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
fname : file, str, or pathlib.Path, optional.
|
fname : file, str, or pathlib.Path, optional
|
||||||
Filename to store results. If not given, the filename will
|
Filename to store results. If not given, the filename will
|
||||||
consist of the name of the colormap and extension '.json'.
|
consist of the name of the colormap and extension '.json'.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if fname is None:
|
|
||||||
fhandle = None
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
fhandle = open(fname,'w')
|
|
||||||
except TypeError:
|
|
||||||
fhandle = fname
|
|
||||||
|
|
||||||
colors = []
|
colors = []
|
||||||
for i,c in enumerate(np.round(self.colors,6).tolist()):
|
for i,c in enumerate(np.round(self.colors,6).tolist()):
|
||||||
colors+=[i]+c
|
colors+=[i]+c
|
||||||
|
@ -254,8 +275,7 @@ class Colormap(mpl.colors.ListedColormap):
|
||||||
'RGBPoints':colors
|
'RGBPoints':colors
|
||||||
}]
|
}]
|
||||||
|
|
||||||
with open(self.name.replace(' ','_')+'.json', 'w') if fhandle is None else fhandle as f:
|
json.dump(out,self._get_file_handle(fname,'json'),indent=4)
|
||||||
json.dump(out, f,indent=4)
|
|
||||||
|
|
||||||
|
|
||||||
def save_ASCII(self,fname=None):
|
def save_ASCII(self,fname=None):
|
||||||
|
@ -264,24 +284,14 @@ class Colormap(mpl.colors.ListedColormap):
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
fname : file, str, or pathlib.Path, optional.
|
fname : file, str, or pathlib.Path, optional
|
||||||
Filename to store results. If not given, the filename will
|
Filename to store results. If not given, the filename will
|
||||||
consist of the name of the colormap and extension '.txt'.
|
consist of the name of the colormap and extension '.txt'.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if fname is None:
|
|
||||||
fhandle = None
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
fhandle = open(fname,'w')
|
|
||||||
except TypeError:
|
|
||||||
fhandle = fname
|
|
||||||
|
|
||||||
labels = {'RGBA':4} if self.colors.shape[1] == 4 else {'RGB': 3}
|
labels = {'RGBA':4} if self.colors.shape[1] == 4 else {'RGB': 3}
|
||||||
t = Table(self.colors,labels,f'Creator: {util.execution_stamp("Colormap")}')
|
t = Table(self.colors,labels,f'Creator: {util.execution_stamp("Colormap")}')
|
||||||
|
t.save(self._get_file_handle(fname,'txt'))
|
||||||
with open(self.name.replace(' ','_')+'.txt', 'w') if fhandle is None else fhandle as f:
|
|
||||||
t.save(f)
|
|
||||||
|
|
||||||
|
|
||||||
def save_GOM(self,fname=None):
|
def save_GOM(self,fname=None):
|
||||||
|
@ -290,26 +300,19 @@ class Colormap(mpl.colors.ListedColormap):
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
fname : file, str, or pathlib.Path, optional.
|
fname : file, str, or pathlib.Path, optional
|
||||||
Filename to store results. If not given, the filename will
|
Filename to store results. If not given, the filename will
|
||||||
consist of the name of the colormap and extension '.legend'.
|
consist of the name of the colormap and extension '.legend'.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if fname is None:
|
|
||||||
fhandle = None
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
fhandle = open(fname,'w')
|
|
||||||
except TypeError:
|
|
||||||
fhandle = fname
|
|
||||||
# ToDo: test in GOM
|
# ToDo: test in GOM
|
||||||
GOM_str = '1 1 {name} 9 {name} '.format(name=self.name.replace(" ","_")) \
|
GOM_str = '1 1 {name} 9 {name} '.format(name=self.name.replace(" ","_")) \
|
||||||
+ '0 1 0 3 0 0 -1 9 \\ 0 0 0 255 255 255 0 0 255 ' \
|
+ '0 1 0 3 0 0 -1 9 \\ 0 0 0 255 255 255 0 0 255 ' \
|
||||||
+ f'30 NO_UNIT 1 1 64 64 64 255 1 0 0 0 0 0 0 3 0 {len(self.colors)}' \
|
+ f'30 NO_UNIT 1 1 64 64 64 255 1 0 0 0 0 0 0 3 0 {len(self.colors)}' \
|
||||||
+ ' '.join([f' 0 {c[0]} {c[1]} {c[2]} 255 1' for c in reversed((self.colors*255).astype(int))]) \
|
+ ' '.join([f' 0 {c[0]} {c[1]} {c[2]} 255 1' for c in reversed((self.colors*255).astype(int))]) \
|
||||||
+ '\n'
|
+ '\n'
|
||||||
with open(self.name.replace(' ','_')+'.legend', 'w') if fhandle is None else fhandle as f:
|
|
||||||
f.write(GOM_str)
|
self._get_file_handle(fname,'legend').write(GOM_str)
|
||||||
|
|
||||||
|
|
||||||
def save_gmsh(self,fname=None):
|
def save_gmsh(self,fname=None):
|
||||||
|
@ -318,24 +321,16 @@ class Colormap(mpl.colors.ListedColormap):
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
fname : file, str, or pathlib.Path, optional.
|
fname : file, str, or pathlib.Path, optional
|
||||||
Filename to store results. If not given, the filename will
|
Filename to store results. If not given, the filename will
|
||||||
consist of the name of the colormap and extension '.msh'.
|
consist of the name of the colormap and extension '.msh'.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if fname is None:
|
|
||||||
fhandle = None
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
fhandle = open(fname,'w')
|
|
||||||
except TypeError:
|
|
||||||
fhandle = fname
|
|
||||||
# ToDo: test in gmsh
|
# ToDo: test in gmsh
|
||||||
gmsh_str = 'View.ColorTable = {\n' \
|
gmsh_str = 'View.ColorTable = {\n' \
|
||||||
+'\n'.join([f'{c[0]},{c[1]},{c[2]},' for c in self.colors[:,:3]*255]) \
|
+'\n'.join([f'{c[0]},{c[1]},{c[2]},' for c in self.colors[:,:3]*255]) \
|
||||||
+'\n}\n'
|
+'\n}\n'
|
||||||
with open(self.name.replace(' ','_')+'.msh', 'w') if fhandle is None else fhandle as f:
|
self._get_file_handle(fname,'msh').write(gmsh_str)
|
||||||
f.write(gmsh_str)
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Config(dict):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
fhandle = open(fname,'w')
|
fhandle = open(fname,'w',newline='\n')
|
||||||
except TypeError:
|
except TypeError:
|
||||||
fhandle = fname
|
fhandle = fname
|
||||||
|
|
||||||
|
|
|
@ -1287,7 +1287,7 @@ class Result:
|
||||||
np.prod(shape))}
|
np.prod(shape))}
|
||||||
data_items[-1].text=f'{os.path.split(self.fname)[1]}:{name}'
|
data_items[-1].text=f'{os.path.split(self.fname)[1]}:{name}'
|
||||||
|
|
||||||
with open(self.fname.with_suffix('.xdmf').name,'w') as f:
|
with open(self.fname.with_suffix('.xdmf').name,'w',newline='\n') as f:
|
||||||
f.write(xml.dom.minidom.parseString(ET.tostring(xdmf).decode()).toprettyxml())
|
f.write(xml.dom.minidom.parseString(ET.tostring(xdmf).decode()).toprettyxml())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Table:
|
||||||
comments_ = [comments] if isinstance(comments,str) else comments
|
comments_ = [comments] if isinstance(comments,str) else comments
|
||||||
self.comments = [] if comments_ is None else [c for c in comments_]
|
self.comments = [] if comments_ is None else [c for c in comments_]
|
||||||
self.data = pd.DataFrame(data=data)
|
self.data = pd.DataFrame(data=data)
|
||||||
self.shapes = { k:(v,) if isinstance(v,(np.int,int)) else v for k,v in shapes.items() }
|
self.shapes = { k:(v,) if isinstance(v,(np.int64,np.int32,int)) else v for k,v in shapes.items() }
|
||||||
self._label_uniform()
|
self._label_uniform()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -380,7 +380,7 @@ class Table:
|
||||||
[f'# {comment}' for comment in self.comments]
|
[f'# {comment}' for comment in self.comments]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fhandle = open(fname,'w')
|
fhandle = open(fname,'w',newline='\n')
|
||||||
except TypeError:
|
except TypeError:
|
||||||
fhandle = fname
|
fhandle = fname
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Marc:
|
||||||
|
|
||||||
if logfile is not None:
|
if logfile is not None:
|
||||||
try:
|
try:
|
||||||
f = open(logfile,'w+')
|
f = open(logfile,'w+',newline='\n')
|
||||||
except TypeError:
|
except TypeError:
|
||||||
f = logfile
|
f = logfile
|
||||||
else:
|
else:
|
||||||
|
|
27
src/IO.f90
27
src/IO.f90
|
@ -65,8 +65,8 @@ end subroutine IO_init
|
||||||
function IO_readlines(fileName) result(fileContent)
|
function IO_readlines(fileName) result(fileContent)
|
||||||
|
|
||||||
character(len=*), intent(in) :: fileName
|
character(len=*), intent(in) :: fileName
|
||||||
|
|
||||||
character(len=pStringLen), dimension(:), allocatable :: fileContent !< file content, separated per lines
|
character(len=pStringLen), dimension(:), allocatable :: fileContent !< file content, separated per lines
|
||||||
|
|
||||||
character(len=pStringLen) :: line
|
character(len=pStringLen) :: line
|
||||||
character(len=:), allocatable :: rawData
|
character(len=:), allocatable :: rawData
|
||||||
integer :: &
|
integer :: &
|
||||||
|
@ -75,6 +75,7 @@ function IO_readlines(fileName) result(fileContent)
|
||||||
l
|
l
|
||||||
logical :: warned
|
logical :: warned
|
||||||
|
|
||||||
|
|
||||||
rawData = IO_read(fileName)
|
rawData = IO_read(fileName)
|
||||||
|
|
||||||
!--------------------------------------------------------------------------------------------------
|
!--------------------------------------------------------------------------------------------------
|
||||||
|
@ -112,16 +113,21 @@ end function IO_readlines
|
||||||
|
|
||||||
!--------------------------------------------------------------------------------------------------
|
!--------------------------------------------------------------------------------------------------
|
||||||
!> @brief Read whole file.
|
!> @brief Read whole file.
|
||||||
!> @details ensures that the string ends with a new line (expected UNIX behavior)
|
!> @details ensures that the string ends with a new line (expected UNIX behavior) and rejects
|
||||||
|
! windows (CRLF) line endings
|
||||||
!--------------------------------------------------------------------------------------------------
|
!--------------------------------------------------------------------------------------------------
|
||||||
function IO_read(fileName) result(fileContent)
|
function IO_read(fileName) result(fileContent)
|
||||||
|
|
||||||
character(len=*), intent(in) :: fileName
|
character(len=*), intent(in) :: fileName
|
||||||
character(len=:), allocatable :: fileContent
|
character(len=:), allocatable :: fileContent
|
||||||
|
|
||||||
integer :: &
|
integer :: &
|
||||||
fileLength, &
|
fileLength, &
|
||||||
fileUnit, &
|
fileUnit, &
|
||||||
myStat
|
myStat, &
|
||||||
|
firstEOL
|
||||||
|
character, parameter :: CR = achar(13)
|
||||||
|
|
||||||
|
|
||||||
inquire(file = fileName, size=fileLength)
|
inquire(file = fileName, size=fileLength)
|
||||||
open(newunit=fileUnit, file=fileName, access='stream',&
|
open(newunit=fileUnit, file=fileName, access='stream',&
|
||||||
|
@ -137,8 +143,12 @@ function IO_read(fileName) result(fileContent)
|
||||||
if(myStat /= 0) call IO_error(102,ext_msg=trim(fileName))
|
if(myStat /= 0) call IO_error(102,ext_msg=trim(fileName))
|
||||||
close(fileUnit)
|
close(fileUnit)
|
||||||
|
|
||||||
|
|
||||||
if(fileContent(fileLength:fileLength) /= IO_EOL) fileContent = fileContent//IO_EOL ! ensure EOL@EOF
|
if(fileContent(fileLength:fileLength) /= IO_EOL) fileContent = fileContent//IO_EOL ! ensure EOL@EOF
|
||||||
|
|
||||||
|
firstEOL = index(fileContent,IO_EOL)
|
||||||
|
if(scan(fileContent(firstEOL:firstEOL),CR) /= 0) call IO_error(115)
|
||||||
|
|
||||||
end function IO_read
|
end function IO_read
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,6 +161,7 @@ logical pure function IO_isBlank(string)
|
||||||
|
|
||||||
integer :: posNonBlank
|
integer :: posNonBlank
|
||||||
|
|
||||||
|
|
||||||
posNonBlank = verify(string,IO_WHITESPACE)
|
posNonBlank = verify(string,IO_WHITESPACE)
|
||||||
IO_isBlank = posNonBlank == 0 .or. posNonBlank == scan(string,IO_COMMENT)
|
IO_isBlank = posNonBlank == 0 .or. posNonBlank == scan(string,IO_COMMENT)
|
||||||
|
|
||||||
|
@ -170,6 +181,7 @@ pure function IO_stringPos(string)
|
||||||
|
|
||||||
integer :: left, right
|
integer :: left, right
|
||||||
|
|
||||||
|
|
||||||
allocate(IO_stringPos(1), source=0)
|
allocate(IO_stringPos(1), source=0)
|
||||||
right = 0
|
right = 0
|
||||||
|
|
||||||
|
@ -249,6 +261,7 @@ pure function IO_lc(string)
|
||||||
|
|
||||||
integer :: i,n
|
integer :: i,n
|
||||||
|
|
||||||
|
|
||||||
do i=1,len(string)
|
do i=1,len(string)
|
||||||
n = index(UPPER,string(i:i))
|
n = index(UPPER,string(i:i))
|
||||||
if(n/=0) then
|
if(n/=0) then
|
||||||
|
@ -271,6 +284,7 @@ function IO_rmComment(line)
|
||||||
character(len=:), allocatable :: IO_rmComment
|
character(len=:), allocatable :: IO_rmComment
|
||||||
integer :: split
|
integer :: split
|
||||||
|
|
||||||
|
|
||||||
split = index(line,IO_COMMENT)
|
split = index(line,IO_COMMENT)
|
||||||
|
|
||||||
if (split == 0) then
|
if (split == 0) then
|
||||||
|
@ -292,6 +306,7 @@ integer function IO_stringAsInt(string)
|
||||||
integer :: readStatus
|
integer :: readStatus
|
||||||
character(len=*), parameter :: VALIDCHARS = '0123456789+- '
|
character(len=*), parameter :: VALIDCHARS = '0123456789+- '
|
||||||
|
|
||||||
|
|
||||||
valid: if (verify(string,VALIDCHARS) == 0) then
|
valid: if (verify(string,VALIDCHARS) == 0) then
|
||||||
read(string,*,iostat=readStatus) IO_stringAsInt
|
read(string,*,iostat=readStatus) IO_stringAsInt
|
||||||
if (readStatus /= 0) call IO_error(111,ext_msg=string)
|
if (readStatus /= 0) call IO_error(111,ext_msg=string)
|
||||||
|
@ -313,6 +328,7 @@ real(pReal) function IO_stringAsFloat(string)
|
||||||
integer :: readStatus
|
integer :: readStatus
|
||||||
character(len=*), parameter :: VALIDCHARS = '0123456789eE.+- '
|
character(len=*), parameter :: VALIDCHARS = '0123456789eE.+- '
|
||||||
|
|
||||||
|
|
||||||
valid: if (verify(string,VALIDCHARS) == 0) then
|
valid: if (verify(string,VALIDCHARS) == 0) then
|
||||||
read(string,*,iostat=readStatus) IO_stringAsFloat
|
read(string,*,iostat=readStatus) IO_stringAsFloat
|
||||||
if (readStatus /= 0) call IO_error(112,ext_msg=string)
|
if (readStatus /= 0) call IO_error(112,ext_msg=string)
|
||||||
|
@ -331,6 +347,7 @@ logical function IO_stringAsBool(string)
|
||||||
|
|
||||||
character(len=*), intent(in) :: string !< string for conversion to int value
|
character(len=*), intent(in) :: string !< string for conversion to int value
|
||||||
|
|
||||||
|
|
||||||
if (trim(adjustl(string)) == 'True' .or. trim(adjustl(string)) == 'true') then
|
if (trim(adjustl(string)) == 'True' .or. trim(adjustl(string)) == 'true') then
|
||||||
IO_stringAsBool = .true.
|
IO_stringAsBool = .true.
|
||||||
elseif (trim(adjustl(string)) == 'False' .or. trim(adjustl(string)) == 'false') then
|
elseif (trim(adjustl(string)) == 'False' .or. trim(adjustl(string)) == 'false') then
|
||||||
|
@ -356,6 +373,7 @@ subroutine IO_error(error_ID,el,ip,g,instance,ext_msg)
|
||||||
character(len=:), allocatable :: msg
|
character(len=:), allocatable :: msg
|
||||||
character(len=pStringLen) :: formatString
|
character(len=pStringLen) :: formatString
|
||||||
|
|
||||||
|
|
||||||
select case (error_ID)
|
select case (error_ID)
|
||||||
|
|
||||||
!--------------------------------------------------------------------------------------------------
|
!--------------------------------------------------------------------------------------------------
|
||||||
|
@ -382,6 +400,9 @@ subroutine IO_error(error_ID,el,ip,g,instance,ext_msg)
|
||||||
msg = 'invalid character for logical:'
|
msg = 'invalid character for logical:'
|
||||||
case (114)
|
case (114)
|
||||||
msg = 'cannot decode base64 string:'
|
msg = 'cannot decode base64 string:'
|
||||||
|
case (115)
|
||||||
|
msg = 'found CR. Windows file endings (CRLF) are not supported.'
|
||||||
|
|
||||||
|
|
||||||
!--------------------------------------------------------------------------------------------------
|
!--------------------------------------------------------------------------------------------------
|
||||||
! lattice error messages
|
! lattice error messages
|
||||||
|
|
Loading…
Reference in New Issue