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

Support for printing vlasiator version and config info from VLSV files #163

Merged
merged 3 commits into from
Feb 17, 2022
Merged
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
68 changes: 68 additions & 0 deletions pyVlsv/vlsvreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,74 @@ def get_cellid_locations(self):
self.__read_fileindex_for_cellid()
return self.__fileindex_for_cellid

def print_version(self):
'''
Prints version information from VLSV file.
TAG is hardcoded to VERSION

:returns True if version is found otherwise returns False
'''
import sys
tag="VERSION"
# Seek for requested data in VLSV file
for child in self.__xml_root:
if child.tag != tag:
continue
if child.tag == tag:
# Found the requested data entry in the file
array_size = ast.literal_eval(child.attrib["arraysize"])
variable_offset = ast.literal_eval(child.text)

if self.__fptr.closed:
fptr = open(self.file_name,"rb")
else:
fptr = self.__fptr

fptr.seek(variable_offset)
info = fptr.read(array_size).decode("utf-8")

# info=data.decode("utf-8")
print("Version Info for ",self.file_name,file=sys.stdout)
print(info,file=sys.stdout)
return True

#if we end up here the file does not contain any version info
print("File ",self.file_name," contains no version information",file=sys.stderr)
return False

def print_config(self):
'''
Prints config information from VLSV file.
TAG is hardcoded to CONFIG

:returns True if config is found otherwise returns False
'''
import sys
tag="CONFIG"
# Seek for requested data in VLSV file
for child in self.__xml_root:
if child.tag != tag:
continue
if child.tag == tag:
# Found the requested data entry in the file
array_size = ast.literal_eval(child.attrib["arraysize"])
variable_offset = ast.literal_eval(child.text)

if self.__fptr.closed:
fptr = open(self.file_name,"rb")
else:
fptr = self.__fptr

fptr.seek(variable_offset)
info = fptr.read(array_size).decode("utf-8")

print(info,file=sys.stdout)
return True

#if we end up here the file does not contain any config info
print("File ",self.file_name," contains no config information",file=sys.stderr)
return False

def read(self, name="", tag="", mesh="", operator="pass", cellids=-1):
''' Read data from the open vlsv file.

Expand Down