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

Skip RAPRS field when parsing CLUSTER output from multiple scattered directions

parent e54ebe1d
Loading
Loading
Loading
Loading
+229 −222
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@
#  The script execution requires python3.
#  The script execution requires python3.


import math
import math
import pdb
from sys import argv
from sys import argv


## \brief Main execution code
## \brief Main execution code
@@ -66,11 +67,7 @@ def main():
                        print(ex)
                        print(ex)
                        errors += 1
                        errors += 1
                elif (config['application'] == 'CLU'):
                elif (config['application'] == 'CLU'):
                    try:
                    errors += parse_legacy_oclu(config)
                    errors += parse_legacy_oclu(config)
                    except Exception as ex:
                        print(ex)
                        errors += 1
                elif (config['application'] == 'SPH'):
                elif (config['application'] == 'SPH'):
                    try:
                    try:
                        errors += parse_legacy_osph(config)
                        errors += parse_legacy_osph(config)
@@ -142,7 +139,6 @@ def parse_legacy_oclu(config):
    out40 = None # Cluster integrated asymmetry parameter and radiation pressure
    out40 = None # Cluster integrated asymmetry parameter and radiation pressure
    out51 = None # Cluster differential asymmetry parameter and radiation pressure forces in state -1
    out51 = None # Cluster differential asymmetry parameter and radiation pressure forces in state -1
    out52 = None # Cluster differential asymmetry parameter and radiation pressure forces in state +1
    out52 = None # Cluster differential asymmetry parameter and radiation pressure forces in state +1
    try:
    oclu_file = open(oclu_name, "r") # open the OCLU file for reading
    oclu_file = open(oclu_name, "r") # open the OCLU file for reading
    file_line = "first line" # a string to parse the OCLU file lines
    file_line = "first line" # a string to parse the OCLU file lines
    if ('ALL' in config['selection'] or 'ICS' in config['selection']):
    if ('ALL' in config['selection'] or 'ICS' in config['selection']):
@@ -171,6 +167,7 @@ def parse_legacy_oclu(config):
    for i in range(2):
    for i in range(2):
        file_line = oclu_file.readline()
        file_line = oclu_file.readline()
    nsph = int(file_line[0:6])
    nsph = int(file_line[0:6])
    iavm = int(file_line[36:41])
    for i in range(nsph + 3):
    for i in range(nsph + 3):
        file_line = oclu_file.readline()
        file_line = oclu_file.readline()
    thifirst = float(file_line[0:11].replace("D", "E"))
    thifirst = float(file_line[0:11].replace("D", "E"))
@@ -192,6 +189,7 @@ def parse_legacy_oclu(config):
    nphi = 1 if phistep == 0.0 else 1 + int((philast - phifirst) / phistep)
    nphi = 1 if phistep == 0.0 else 1 + int((philast - phifirst) / phistep)
    nphs = 1 if phsstep == 0.0 else 1 + int((phslast - phsfirst) / phsstep)
    nphs = 1 if phsstep == 0.0 else 1 + int((phslast - phsfirst) / phsstep)
    ndirs = nthi * nths * nphi * nphs
    ndirs = nthi * nths * nphi * nphs
    nscas = nths * nphs
    
    
    while ("JXI =" not in file_line):
    while ("JXI =" not in file_line):
        file_line = oclu_file.readline() # read the next OSPH file line
        file_line = oclu_file.readline() # read the next OSPH file line
@@ -213,18 +211,17 @@ def parse_legacy_oclu(config):
                # replacing FORTRAN's D with E
                # replacing FORTRAN's D with E
                vk = float(file_line[5:20].replace("D", "E"))
                vk = float(file_line[5:20].replace("D", "E"))
                alam = 2.0 * math.pi / vk
                alam = 2.0 * math.pi / vk
            if ("CLUSTER (ENSEMBLE AVERAGE, MODE 0)" in file_line):
        if ("CLUSTER (ENSEMBLE AVERAGE, " in file_line):
                # we are in average section. We start a nested loop to
            # we are in average section. We know the average cross-sections
                # extract the average values
            # are after 3 more lines.
                found_averages = False
            for i in range(3):
                while (not found_averages):
                file_line = oclu_file.readline()
                # the following check is needed to parse C++ output
                if ("INSERTION" in file_line):
                    file_line = oclu_file.readline()
                    file_line = oclu_file.readline()
                    if ("----- SCC ----- ABC ----- EXC ----- ALBEDC --" in file_line):
            # we know we are in LIN -1 because it is the first one
            # we know we are in LIN -1 because it is the first one
            # we also know that the next line contains the values
            # we also know that the next line contains the values
            # we are looking for, so we read it
            # we are looking for, so we read it
                        file_line = oclu_file.readline()
                        # we now extract the values from string sections
            scasm = float(file_line[1:15].replace("D", "E"))
            scasm = float(file_line[1:15].replace("D", "E"))
            abssm = float(file_line[17:30].replace("D", "E"))
            abssm = float(file_line[17:30].replace("D", "E"))
            extsm = float(file_line[32:45].replace("D", "E"))
            extsm = float(file_line[32:45].replace("D", "E"))
@@ -240,11 +237,7 @@ def parse_legacy_oclu(config):
            rapr = float(file_line[31:46].replace("D", "E"))
            rapr = float(file_line[31:46].replace("D", "E"))
            output_line = "{0:.7E},{1:.7E},{2:.7E}\n".format(alam, cosav, rapr)
            output_line = "{0:.7E},{1:.7E},{2:.7E}\n".format(alam, cosav, rapr)
            if (out40 is not None): out40.write(output_line)
            if (out40 is not None): out40.write(output_line)
                        found_averages = True # terminate the inner loop
            # the averages were written. We look for differential section
                # the averages were written. We look for CLUSTER section
                # using another inner loop
                found_differentials = False
                while (not found_differentials):
            for di in range(ndirs):
            for di in range(ndirs):
                while ("JTH =" not in file_line):
                while ("JTH =" not in file_line):
                    file_line = oclu_file.readline()
                    file_line = oclu_file.readline()
@@ -255,20 +248,22 @@ def parse_legacy_oclu(config):
                psdg = float(file_line[58:68].replace("D", "E"))
                psdg = float(file_line[58:68].replace("D", "E"))
                while ("     CLUSTER" not in file_line):
                while ("     CLUSTER" not in file_line):
                    file_line = oclu_file.readline()
                    file_line = oclu_file.readline()
                        if ("     CLUSTER" in file_line):
                # we found CLUSTER. We know cross-sections for
                # we found CLUSTER. We know cross-sections for
                            # polarization state -1 will be after 2 more lines
                # polarization state -1 will be after 3 more lines
                for i in range(3):
                for i in range(3):
                    file_line = oclu_file.readline()
                    file_line = oclu_file.readline()
                    # the following check is needed to parse C++ output
                    # the following check is needed to parse C++ output
                    if ("INSERTION" in file_line):
                    if ("INSERTION" in file_line):
                        file_line = oclu_file.readline()
                        file_line = oclu_file.readline()
                # breakpoint()
                scc31 = float(file_line[1:15].replace("D", "E"))
                scc31 = float(file_line[1:15].replace("D", "E"))
                abc31 = float(file_line[17:30].replace("D", "E"))
                abc31 = float(file_line[17:30].replace("D", "E"))
                exc31 = float(file_line[32:45].replace("D", "E"))
                exc31 = float(file_line[32:45].replace("D", "E"))
                # we can write the differential values, similarly to fort.31
                # we can write the differential values, similarly to fort.31
                output_line = "{0:.7E},{1:.3E},{2:.3E},{3:.3E},{4:.3E},{5:.7E},{6:.7E},{7:.7E}\n".format(alam, tidg, tsdg, pidg, psdg, scc31, abc31, exc31)
                output_line = "{0:.7E},{1:.3E},{2:.3E},{3:.3E},{4:.3E},{5:.7E},{6:.7E},{7:.7E}\n".format(alam, tidg, tsdg, pidg, psdg, scc31, abc31, exc31)
                if (out31 is not None): out31.write(output_line)
                if (out31 is not None): out31.write(output_line)
                if (di % nscas == 0):
                    #
                    # we know that RAPRS values for polarization state -1
                    # we know that RAPRS values for polarization state -1
                    # are after 9 more lines
                    # are after 9 more lines
                    for i in range(9):
                    for i in range(9):
@@ -356,7 +351,22 @@ def parse_legacy_oclu(config):
                    # we can write the RAPRS values
                    # we can write the RAPRS values
                    output_line = "{0:.7E},{1:.3E},{2:.3E},{3:.3E},{4:.3E},{5:.7E},{6:.7E},{7:.7E},{8:.7E},{9:.7E},{10:.7E},{11:.7E},{12:.7E},{13:.7E},{14:.7E},{15:.7E},{16:.7E},{17:.7E},{18:.7E},{19:.7E},{20:.7E},{21:.7E},{22:.7E},{23:.7E},{24:.7E}\n".format(alam, tidg, tsdg, pidg, psdg, cosav, rapr, fl, fr, fk, fx, fy, fx, TQEl, TQEr, TQEk, TQEx, TQEy, TQEz, TQSl, TQSr, TQSk, TQSx, TQSy, TQSz)
                    output_line = "{0:.7E},{1:.3E},{2:.3E},{3:.3E},{4:.3E},{5:.7E},{6:.7E},{7:.7E},{8:.7E},{9:.7E},{10:.7E},{11:.7E},{12:.7E},{13:.7E},{14:.7E},{15:.7E},{16:.7E},{17:.7E},{18:.7E},{19:.7E},{20:.7E},{21:.7E},{22:.7E},{23:.7E},{24:.7E}\n".format(alam, tidg, tsdg, pidg, psdg, cosav, rapr, fl, fr, fk, fx, fy, fx, TQEl, TQEr, TQEk, TQEx, TQEy, TQEz, TQSl, TQSr, TQSk, TQSx, TQSy, TQSz)
                    if (out52 is not None): out52.write(output_line)
                    if (out52 is not None): out52.write(output_line)
                    found_differentials = True # terminate the inner loop
                else: # di % nscas != 0: skip COSAV & RAPRS
                    # polarization state 1 will be after 11 more lines
                    for i in range(11):
                        file_line = oclu_file.readline()
                        # the following check is needed to parse C++ output
                        if ("INSERTION" in file_line):
                            file_line = oclu_file.readline()
                    # breakpoint()
                    scc32 = float(file_line[1:15].replace("D", "E"))
                    abc32 = float(file_line[17:30].replace("D", "E"))
                    exc32 = float(file_line[32:45].replace("D", "E"))
                    # we can write the differential values, similarly to fort.32
                    output_line = "{0:.7E},{1:.3E},{2:.3E},{3:.3E},{4:.3E},{5:.7E},{6:.7E},{7:.7E}\n".format(alam, tidg, tsdg, pidg, psdg, scc31, abc31, exc31)
                    if (out32 is not None): out32.write(output_line)
                # closes if (di % nscas == 0)
            # closes di for loop
        # The parsing loop ends here
        # The parsing loop ends here


    if (out20 is not None): out20.close()
    if (out20 is not None): out20.close()
@@ -366,9 +376,6 @@ def parse_legacy_oclu(config):
    if (out51 is not None): out51.close()
    if (out51 is not None): out51.close()
    if (out52 is not None): out52.close()
    if (out52 is not None): out52.close()
    oclu_file.close() # close the OCLU file
    oclu_file.close() # close the OCLU file
    except Exception as ex:
        print(ex)
        errors += 1
    return errors
    return errors


## \brief Parse a legacy output file of np_inclusion.
## \brief Parse a legacy output file of np_inclusion.