-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from FOSSEE/data_convertor
Data convertor
- Loading branch information
Showing
55 changed files
with
2,108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include pyvnt/Converter/Reader/cpp_src/dictionaryFile/lib/dictionaryFile.so | ||
include pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/bin/dictionaryFileChecker.so | ||
include pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/lib/dictionaryFileIterator.so | ||
include pyvnt/Converter/Reader/cpp_src/libOpenFOAM.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
import os | ||
from pyvnt.Container.node import Node_C | ||
from .dictionaryFileIterator import DictionaryFileIterator | ||
from .dictionaryFile import DictionaryFile | ||
|
||
|
||
def read(filepath : str, verifyFile: bool = True) -> Node_C: | ||
''' | ||
Reads dictionary file from the given filepath and returns a node tree | ||
representation of it. | ||
''' | ||
file = DictionaryFile(filepath, verifyFile) | ||
itr = DictionaryFileIterator(file) | ||
|
||
path = file.filepath | ||
|
||
root_name = path.split('/')[-1] | ||
# print(root_name) | ||
|
||
root = _createTree(root_name, itr) | ||
itr.close() | ||
file.close() | ||
|
||
return root | ||
|
||
|
||
def _createTree(parentName: str, itr: DictionaryFileIterator) -> Node_C: | ||
''' | ||
Recursively traverse the openfoam's dictionary data structure and create the | ||
node-tree structure. | ||
''' | ||
data = {} | ||
while itr.hasEntry(): | ||
key = itr.getCurrentEntryKeyword() | ||
value = None | ||
|
||
# print(f"{key}, {itr.isCurrentEntryList()}") | ||
|
||
if itr.isCurrentEntryDict(): | ||
# print(key) | ||
itr.stepIn() | ||
value = _createTree(key, itr) | ||
itr.stepOut() | ||
else: | ||
value = itr.getKeyData() | ||
# print(value) | ||
|
||
print(key) | ||
# print(f"{key}, {type(value)}") | ||
data[key] = value | ||
itr.step() | ||
|
||
# create node | ||
children = [] | ||
itms = [] | ||
|
||
for key, val in data.items(): | ||
if isinstance(val,Node_C): | ||
children.append(val) | ||
else: | ||
itms.append(val) | ||
|
||
node = Node_C(parentName, None, children, *itms) | ||
|
||
return node | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
dictionaryFile.C | ||
|
||
LIB = ./lib/dictionaryFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
LIB_LIBS = \ | ||
-L$FOAM_LIBBIN \ | ||
-lOpenFOAM |
48 changes: 48 additions & 0 deletions
48
pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile.C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
#include "fileName.H" | ||
#include "IFstream.H" | ||
#include "dictionary.H" | ||
|
||
#include "dictionaryFile.H" | ||
#include "dictionaryFile_PythonInterface.H" | ||
|
||
|
||
DictionaryFile::DictionaryFile(const char* filepath) | ||
{ | ||
Foam::fileName dictPath(filepath); | ||
Foam::IFstream dictFileStream(dictPath); | ||
mDictPtr = new Foam::dictionary(dictFileStream); | ||
} | ||
|
||
DictionaryFile::~DictionaryFile() | ||
{ | ||
delete mDictPtr; | ||
} | ||
|
||
// void DictionaryFile::printEntry(const char* key) | ||
// { | ||
// Foam::word keyname(key); | ||
// std::cout | ||
// << "dictionaryName : " << mDictPtr->name().toAbsolute() << " " | ||
// << mDictPtr->lookupEntry(keyname, false, false).keyword() | ||
// << std::endl; | ||
// } | ||
|
||
// API FUNCTIONS=============================================================== | ||
void* openDictionaryFile(const char* filepath) | ||
{ | ||
DictionaryFile* dictFile = new DictionaryFile(filepath); | ||
return dictFile; | ||
} | ||
|
||
void closeDictionaryFile(void* dictionaryFile) | ||
{ | ||
DictionaryFile* dictFile = static_cast<DictionaryFile*>(dictionaryFile); | ||
delete dictFile; | ||
} | ||
|
||
// void printDictionary(void* dictionaryFile) | ||
// { | ||
// DictionaryFile* dictFile = static_cast<DictionaryFile*>(dictionaryFile); | ||
// dictFile->printEntry("key1"); | ||
// } |
15 changes: 15 additions & 0 deletions
15
pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile.H
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
#pragma once | ||
|
||
|
||
class DictionaryFile | ||
{ | ||
public: | ||
Foam::dictionary* mDictPtr; | ||
|
||
DictionaryFile(const char* filepath); | ||
~DictionaryFile(); | ||
// void* getIterator(); | ||
// void printEntry(const char* key); | ||
}; | ||
|
14 changes: 14 additions & 0 deletions
14
pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile_PythonInterface.H
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
#pragma once | ||
|
||
|
||
extern "C" | ||
{ | ||
|
||
void* openDictionaryFile(const char* filepath); | ||
void closeDictionaryFile(void* dictionaryFile); | ||
// void* getIterator(void* dictionaryFile); | ||
// void printDictionary(void* dictionaryFile); | ||
} | ||
|
||
|
1 change: 1 addition & 0 deletions
1
pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile.C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../dictionaryFile.C |
1 change: 1 addition & 0 deletions
1
pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile.H
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../dictionaryFile.H |
1 change: 1 addition & 0 deletions
1
pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile_PythonInterface.H
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../dictionaryFile_PythonInterface.H |
4 changes: 4 additions & 0 deletions
4
pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
dictionaryFileChecker.C | ||
|
||
EXE = ./bin/dictionaryFileChecker |
Oops, something went wrong.