Commit d6e28991 authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Use exception handling in optical constant file management

parent a0d40d53
Loading
Loading
Loading
Loading
+136 −120
Original line number Diff line number Diff line
@@ -69,11 +69,14 @@ def main():
#  \return result: `int` An exit code (0 if successful).
def interpolate_constants(sconf):
    result = 0
    err_arg = ""
    try:
        for i in range(sconf['configurations']):
            for j in range(sconf['nshl'][i]):
                file_idx = sconf['dielec_id'][i][j]
                dielec_path = Path(sconf['dielec_path'], sconf['dielec_file'][int(file_idx) - 1])
            file_name = str(dielec_path)
                err_arg = str(dielec_path)
                file_name = err_arg
                dielec_file = open(file_name, 'r')
                wavelengths = []
                rpart = []
@@ -126,6 +129,9 @@ def interpolate_constants(sconf):
                        else:
                            print("ERROR: file %s does not cover requested wavelengths!"%file_name)
                            return 2
    except FileNotFoundError as ex:
        print("ERROR: file not found %s!"%err_arg)
        return 3
    return result

## \brief Create tha calculation configuration structure from YAML input.
@@ -262,12 +268,16 @@ def load_model(model_file):
                            [0.0 for k in range(sconf['nxi'])] for j in range(sconf['configurations'])
                        ] for i in range(max_layers)
                    ]
                    interpolate_constants(sconf)
                    check = interpolate_constants(sconf)
                    if (check != 0):
                        return (None, None)
                else: # sconf[idfc] != 0 and scaling on wavelength
                    print("ERROR: for wavelength scaling, optical constants must be tabulated!")
                    return (None, None)
            elif (model['material_settings']['match_mode'] == "GRID"):
                match_grid(sconf)
                check = match_grid(sconf)
                if (check != 0):
                    return(None, None)
            else:
                print("ERROR: %s is not a recognized match mode!"%(model['material_settings']['match_mode']))
                return (None, None)
@@ -466,6 +476,8 @@ def match_grid(sconf):
    max_layers = 0
    nxi = 0
    sconf['vec_xi'] = []
    err_arg = ""
    try:
        for i in range(sconf['configurations']):
            layers = sconf['nshl'][i]
            if (sconf['application'] == "INCLUSION" and i == 0):
@@ -473,7 +485,8 @@ def match_grid(sconf):
            for j in range(layers):
                file_idx = sconf['dielec_id'][i][j]
                dielec_path = Path(sconf['dielec_path'], sconf['dielec_file'][int(file_idx) - 1])
            file_name = str(dielec_path)
                err_arg = str(dielec_path)
                file_name = err_arg
                dielec_file = open(file_name, 'r')
                wavelengths = []
                rpart = []
@@ -532,6 +545,9 @@ def match_grid(sconf):
                        wi += 1
                    sconf['rdc0'][j][i][dci] = ry
                    sconf['idc0'][j][i][dci] = iy
    except FileNotFoundError as ex:
        print("ERROR: file not found %s!"%err_arg)
        return 3
    return result

## \brief Parse the command line arguments.