Ejemplo n.º 1
0
        private static Matrix ReadMatrixFromMatrixFile(BufferedFileReader reader, int networkId)
        {
            networkId = reader.JumpToNetworkId(networkId, true);
            if (networkId == -1)
            {
                throw new Exception("Network ID does not exist!");
            }
            reader.ReadLine(); // Skip first line with the network id

            string[] colLabels = reader.ReadLine().Split(',');
            //Yushan
            List <string> rowLabels = new List <string>();
            //string[] colLabels = tempLabels.Split(',');
            int rows = reader.CountLines(networkId) - 2; // Subtract off header columns
            //int rows = reader.CountLinesAlt(tempIdStr) - 2;
            int cols = colLabels.Length - 1;

            Matrix matrix = new Matrix(rows, cols);

            matrix.NetworkId    = networkId;
            matrix.NetworkIdStr = reader.GetNetworkRealId(networkId);
            matrix.ColLabels.SetLabels(colLabels);

            for (int row = 0; row < rows; ++row)
            {
                string temp = reader.ReadLine();
                if (temp == null)
                {
                    break;
                }
                //string[] parts = reader.ReadLine().Split(',');
                string[] parts = temp.Split(',');

                if (parts.Length > cols + 1) // one extra for header
                {
                    throw new FileLoadException("Matrix file has too many entries for network id: " + matrix.NetworkIdStr + ", row " + parts[0]);
                }

                if (parts.Length == 0)
                {
                    throw new FileLoadException("Matrix file has no entries for network id: " + matrix.NetworkIdStr);
                }

                //matrix.RowLabels[row] = parts[0];
                rowLabels.Add(parts[0]);

                for (int i = 1; i < parts.Length; ++i)
                {
                    matrix[row, i - 1] = ExtractDouble(parts[i]);
                }
            }
            matrix.RowLabels.SetLabels(rowLabels);
            reader.closeStream();
            reader.Dispose(); /* Change made 12/3/2010 - PM */

            return(matrix);
        }
Ejemplo n.º 2
0
        private static Matrix ReadMatrixFromMatrixFile(BufferedFileReader reader, int networkId)
        {
            networkId = reader.JumpToNetworkId(networkId, true);
            reader.ReadLine(); // Skip first line with the network id
            /*
            string tempLabels = reader.ReadLine();
            if (tempLabels == null)
                return null;
            */

            string[] colLabels = reader.ReadLine().Split(',');
            //string[] colLabels = tempLabels.Split(',');
            int rows = reader.CountLines(networkId) - 2; // Subtract off header columns
            int cols = colLabels.Length - 1;

            Matrix matrix = new Matrix(rows, cols);
            matrix.NetworkId = networkId;
            matrix.ColLabels.SetLabels(colLabels);

            for (int row = 0; row < rows; ++row)
            {
                string temp = reader.ReadLine();
                if (temp == null)
                    break;
                //string[] parts = reader.ReadLine().Split(',');
                string[] parts = temp.Split(',');

                if (parts.Length > cols + 1) // one extra for header
                    throw new FileLoadException("Matrix file has too many entries for network id: " + networkId.ToString() + ", row " + parts[0]);

                if (parts.Length == 0)
                    throw new FileLoadException("Matrix file has no entries for network id: " + networkId.ToString());

                matrix.RowLabels[row] = parts[0];

                for (int i = 1; i < parts.Length; ++i)
                    matrix[row, i - 1] = ExtractDouble(parts[i]);
            }

            reader.closeStream();
            reader.Dispose(); /* Change made 12/3/2010 - PM */

            return matrix;
        }