# Path: pyteltools/slf/variable/variables_2d.py
# VARIABLES_2D = build_variables(spec)
# 
# Path: pyteltools/slf/util.py



import copy
import numpy as np
import os
import struct
from shapely.geometry import LinearRing
from pyteltools.conf import settings
from pyteltools.slf.variable.variables_2d import VARIABLES_2D
from pyteltools.slf.variable.variables_3d import VARIABLES_3D
from .util import logger
SLF_EIT = 'iso-8859-1'


VARIABLES_ID_2D, VARIABLES_ID_3D = {'fr': {}, 'en': {}}, {'fr': {}, 'en': {}}


def build_variables_table():
    base_folder = os.path.dirname(os.path.realpath(__file__))
    for dic, name in zip([VARIABLES_ID_2D, VARIABLES_ID_3D], ['Serafin_var2D.csv', 'Serafin_var3D.csv']):
        with open(os.path.join(base_folder, 'data', name), 'r') as f:
            f.readline()  # header
            for line in f.readlines():
                var_id, var_name_fr, var_name_en, _ = line.rstrip().split(';')
                dic['fr'][var_name_fr] = var_id
                dic['en'][var_name_en] = var_id


build_variables_table()


class SerafinValidationError(Exception):
    """!
    @brief Custom exception for Serafin file content check
    """
    def __init__(self, message):
        """!
        @param message <str>: error message description
        """
        super().__init__(message)
        self.message = message

# Path: pyteltools/slf/variable/variables_2d.py
# VARIABLES_2D = build_variables(spec)
# 
# Path: pyteltools/slf/util.py



# Path: pyteltools/slf/Serafin.py
import copy
import numpy as np
import os
import struct
from shapely.geometry import LinearRing
from pyteltools.conf import settings
from pyteltools.slf.variable.variables_2d import VARIABLES_2D
from pyteltools.slf.variable.variables_3d import VARIABLES_3D
from .util import logger

SLF_EIT = 'iso-8859-1'


VARIABLES_ID_2D, VARIABLES_ID_3D = {'fr': {}, 'en': {}}, {'fr': {}, 'en': {}}


def build_variables_table():
    base_folder = os.path.dirname(os.path.realpath(__file__))
    for dic, name in zip([VARIABLES_ID_2D, VARIABLES_ID_3D], ['Serafin_var2D.csv', 'Serafin_var3D.csv']):
        with open(os.path.join(base_folder, 'data', name), 'r') as f:
            f.readline()  # header
            for line in f.readlines():
                var_id, var_name_fr, var_name_en, _ = line.rstrip().split(';')
                dic['fr'][var_name_fr] = var_id
                dic['en'][var_name_en] = var_id


build_variables_table()


class SerafinValidationError(Exception):
    """!
    @brief Custom exception for Serafin file content check
    """
    def __init__(self, message):
        """!
        @param message <str>: error message description
        """
        super().__init__(message)
        self.message = message

        logger.error('SERAFIN VALIDATION ERROR: %s' % message)