001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 package graphlab.plugins.main.saveload.matrix; 005 006 import graphlab.graph.graph.GraphModel; 007 import graphlab.plugins.main.saveload.core.GraphIOException; 008 import graphlab.plugins.main.saveload.core.extension.GraphWriterExtension; 009 010 import java.io.File; 011 import java.io.FileWriter; 012 import java.io.IOException; 013 014 /** 015 * @author Azin Azadi 016 */ 017 public class SaveMatrix implements GraphWriterExtension { 018 019 /** 020 * saves g as matrix in file 021 */ 022 public static void saveMatrix(GraphModel g, File file) throws IOException { 023 FileWriter output = new FileWriter(file); 024 output.write(Matrix.Matrix2String(Matrix.graph2Matrix(g))); 025 output.close(); 026 } 027 028 public String getName() { 029 return "Matrix"; 030 } 031 032 public String getExtension() { 033 return "mat"; 034 } 035 036 public void write(File file, GraphModel graph) throws GraphIOException { 037 try { 038 saveMatrix(graph, file); 039 } catch (IOException e) { 040 throw new GraphIOException(e.getMessage()); 041 } 042 043 } 044 045 public String getDescription() { 046 return "0-1 Matrix File Format"; 047 } 048 } 049 050