Writes branch data to file.

def write_branch_data(self, file):
        """ Writes branch data to file.
        """
        # I,J,CKT,R,X,B,RATEA,RATEB,RATEC,GI,BI,GJ,BJ,ST,LEN,O1,F1,...,O4,F4
        branch_attr = ["r", "x", "b", "rate_a", "rate_b", "rate_c"]

        for branch in self.case.branches:
            if feq(branch.ratio, 0.0):
                vals = [getattr(branch, a) for a in branch_attr]
                if float(vals[1])<0.001:
                    vals[1] = 0.001  # small reactance, todo: increase decimal
                vals.insert(0, "1 ")
                vals.insert(0, branch.to_bus._i)
                vals.insert(0, branch.from_bus._i)
                vals.extend([0., 0., 0., 0.])
                vals.append(branch.online)
                vals.extend([0.0, 1, 1.0,])

                file.write("%6d,%6d,'%s',%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,"
                    "%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%d,%10.3f,%4d,%6.4f\n" %
                    tuple(vals))
        file.write(" 0 / END OF NON-TRANSFORMER BRANCH DATA, BEGIN TRANSFORMER DATA\n")

        # I,J,K,CKT,CW,CZ,CM,MAG1,MAG2,NMETR,'NAME',STAT,O1,F1,...,O4,F4
        # R1-2,X1-2,SBASE1-2
        # WINDV1,NOMV1,ANG1,RATA1,RATB1,RATC1,COD1,CONT1,RMA1,RMI1,VMA1,VMI1,NTP1,TAB1,CR1,CX1
        # WINDV2,NOMV2
        for branch in self.case.branches:
            if not feq(branch.ratio, 0.0):
                vals = []
                vals.append(branch.from_bus._i)
                vals.append(branch.to_bus._i)
                # K,CKT,CW,CZ,CM,MAG1,MAG2,NMETR
                vals.extend([0, "1 ", 1, 1, 1, 0.0, 0.0, 2])
                vals.append(branch.name)
                vals.append(branch.online)
                vals.extend([1, 1.0]) # O1,F1

                file.write("%6d,%6d,%6d,'%2s',%d,%d,%d,%10.3f,%10.3f,%d,"
                           "'%-12s',%d,%4d,%6.4f\n" % tuple(vals))
                file.write("%8.3f,%8.3f,%10.2f\n" % (branch.r, branch.x,
                                                   self.case.base_mva))

                line3 = []
                line3.append(branch.ratio) # Winding-1 RATIO
                line3.append(0.0)
                line3.append(branch.phase_shift)
                line3.append(branch.rate_a)
                line3.append(branch.rate_b)
                line3.append(branch.rate_c)
                # COD1,CONT1,RMA1,RMI1,VMA1,VMI1,NTP1,TAB1,CR1,CX1
                line3.extend([0, 0, 1.1, 0.9, 1.1, 0.9, 33, 0, 0.0, 0.0])

                file.write("%7.5f,%8.3f,%8.3f,%8.2f,%8.2f,%8.2f,%d,%7d,%8.5f,"
                    "%8.5f,%8.5f,%8.5f,%4d,%2d,%8.5f,%8.5f\n" % tuple(line3))

                file.write("%7.5f,%8.3f\n" % (1.0, 0.0))  # Winding-2 RATIO: 1

        file.write(""" 0 / END OF TRANSFORMER DATA, BEGIN AREA INTERCHANGE DATA
 0 / END OF AREA INTERCHANGE DATA, BEGIN TWO-TERMINAL DC DATA
 0 / END OF TWO-TERMINAL DC DATA, BEGIN VSC DC LINE DATA
 0 / END OF VSC DC LINE DATA, BEGIN SWITCHED SHUNT DATA
 0 / END OF SWITCHED SHUNT DATA, BEGIN TRANS. IMP. CORR. TABLE DATA
 0 / END OF TRANS. IMP. CORR. TABLE DATA, BEGIN MULTI-TERMINAL DC LINE DATA
 0 / END OF MULTI-TERMINAL DC LINE DATA, BEGIN MULTI-SECTION LINE DATA
 0 / END OF MULTI-SECTION LINE DATA, BEGIN ZONE DATA
 0 / END OF ZONE DATA, BEGIN INTERAREA TRANSFER DATA
 0 / END OF INTERAREA TRANSFER DATA, BEGIN OWNER DATA
 0 / END OF OWNER DATA, BEGIN FACTS DEVICE DATA
 0 / END OF FACTS DEVICE DATA, END OF CASE DATA
""")