Writes bus data in MATPOWER format.

def write_bus_data(self, file):
        """ Writes bus data in MATPOWER format.
        """
        # I, 'NAME', BASKV, IDE, GL, BL, AREA, ZONE, VM, VA, OWNER
        bus_attrs = ["_i", "name", "v_base", "type", "g_shunt", "b_shunt",
                     "area", "zone",
                     "v_magnitude", "v_angle"]

        for bus in self.case.buses:
            vals = [getattr(bus, a) for a in bus_attrs]
            if float(vals[6]) == 0.0:
                vals[6] = 1  # default AREA: 1
            if float(vals[7])==0.0:
                vals[7] = 1  # default ZONE: 1
            d = {PQ: 1, PV: 2, REFERENCE: 3, ISOLATED: 4}
            vals[3] = d[vals[3]]
            vals.append(1)

#            print len(vals), vals

            file.write("%6d,'%-10s',%10.4f,%d,%10.3f,%10.3f,%4d,%4d,%10.3f,"
                       "%10.3f%4d\n" % tuple(vals))
        file.write(" 0 / END OF BUS DATA, BEGIN LOAD DATA\n")


        # I, ID, STATUS, AREA, ZONE, PL, QL, IP, IQ, YP, YQ, OWNER
        load_attrs = ["_i", "area", "zone", "p_demand", "q_demand"]

        for bus in self.case.buses:
            if bus.p_demand > 0.0 or bus.q_demand > 0.0:
                vals = [getattr(bus, a) for a in load_attrs]
                if float(vals[1])==0.0:
                    vals[1] = 1  # default AREA: 1
                if float(vals[2])==0.0:
                    vals[2] = 1  # default ZONE: 1
                vals.insert(1, 1) # STATUS
                vals.insert(1, "1 ") # ID
                vals.extend([0., 0., 0., 0.])
                vals.append(1) # OWNER

                file.write("%6d,'%s',%2d,%2d,%2d,%10.3f,%10.3f,%10.3f,%10.3f,"
                           "%10.3f,%10.3f,%4d\n" % tuple(vals))

        file.write(" 0 / END OF LOAD DATA, BEGIN GENERATOR DATA\n")