Skip to content
Snippets Groups Projects
Commit fd6f7801 authored by jacques.grelet_ird.fr's avatar jacques.grelet_ird.fr
Browse files

tested

parent 4af66dbb
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
file_extractor.py file_extractor.py
''' '''
import fileinput import fileinput
import toml
class FileExtractor: class FileExtractor:
...@@ -16,27 +17,35 @@ class FileExtractor: ...@@ -16,27 +17,35 @@ class FileExtractor:
# public: # public:
self.file = file self.file = file
# private: # private:
self.__hash = {} self.__headeer = {}
self.__data = {}
# constructor build objet by reading the file # constructor build objet by reading the file
self.read()
# overloading operators # overloading operators
def __str__(self): def __str__(self):
''' overload string representation ''' ''' overload string representation '''
return 'Class FileExtractor, file: %s, size = %d' % (self.file, len(self)) return 'Class FileExtractor, file: %s, size = %d' % (self.file, len(self))
# read code roscop file # read code roscop file
def read(self): def read(self, keys, dic):
for line in fileinput.input( for line in fileinput.input(
self.file, openhook=fileinput.hook_encoded("ISO-8859-1")): self.file, openhook=fileinput.hook_encoded("ISO-8859-1")):
if line[0] == '#' or line[0] == '*':
continue
# iterate over the lines of opened file "fileName" # iterate over the lines of opened file "fileName"
# ------------------------------------------------ # ------------------------------------------------
print(line) p = line.split()
for k in keys:
print("{} ".format(p[dic[k]]), end='')
print()
# for testing in standalone context # for testing in standalone context
# --------------------------------- # ---------------------------------
if __name__ == "__main__": if __name__ == "__main__":
fe = FileExtractor('data/cnv/fr29001.cnv') fe = FileExtractor('data/cnv/fr29001.cnv')
fe.read() cfg = toml.load('tests/test.toml')
dic = cfg['split']['ctd']
fe.read(['PRES', 'TEMP', 'PSAL', 'DOX2'], dic)
...@@ -43,7 +43,7 @@ class testRoscop(unittest.TestCase): ...@@ -43,7 +43,7 @@ class testRoscop(unittest.TestCase):
self.assertEqual(self.r.returnCode('PSAL')[ self.assertEqual(self.r.returnCode('PSAL')[
'standard_name'], 'sea_water_salinity') 'standard_name'], 'sea_water_salinity')
self.assertEqual(self.r.returnCode('PSAL')[ self.assertEqual(self.r.returnCode('PSAL')[
'units'], '1') 'conventions'], 'PSU')
self.assertEqual(self.r.returnCode('PSAL')[ self.assertEqual(self.r.returnCode('PSAL')[
'comment'], 'Ocean practical salinity (PSS-78)') 'comment'], 'Ocean practical salinity (PSS-78)')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment