www.pudn.com > BackscatterMap.rar > readgrid.cs, change:2009-07-31,size:2802b


using System; 
using System.Drawing; 
using System.Drawing.Drawing2D; 
using System.Collections; 
using System.Collections.Generic; 
using System.Windows.Forms; 
using System.Text; 
using System.Data.SqlTypes; 
using System.IO; 
namespace WindowsApplication4 
{ 
    class readgrid 
    { 
        //   static int rowNum = 6001; 
        //   static int colNum = 6001; 
        static public int number = 2000; 
 
        public double[,] read() 
        { 
            readgrid myreadgrid = new readgrid(); 
            ArrayList array = new ArrayList(); 
            double[,] data = new double[number, number]; 
            string strFile = "D:\\dem\\dem\\srtm_59_06\\srtm_59_06.ASC"; 
            StreamReader str = new StreamReader(strFile); 
            string temp = ""; 
            while (temp != null) 
            { 
                temp = str.ReadLine(); 
                array.Add(temp); 
            } 
            //                 int row = array.Count; 
            for (int i = 6; i < number + 6; i++) 
            { 
 
                int col = myreadgrid.getcolnumber(array[i].ToString().TrimStart(' ')); 
                double[] tempData = new double[col]; 
                tempData = myreadgrid.returnresult(array[i].ToString().TrimStart(' '), col); 
                for (int j = 0; j < number; j++) 
                { 
                    data[i - 6, j] = tempData[j]; 
                } 
            } 
            return data; 
        } 
 
 
 
        public int getcolnumber(string temp) 
        { 
            string TransStr = temp.Trim(); 
            int result = 0; 
            int length = TransStr.Length; 
            int sign = 0; 
            for (int i = 0; i < length; i++) 
            { 
                if ((TransStr[i] != ' ') && (sign == 0)) 
                { 
                    result++; 
                    sign = 1; 
                } 
                if (TransStr[i] == ' ') 
                    sign = 0; 
            } 
            return result; 
        } 
 
        public double[] returnresult(string secondstr, int col) 
        { 
            double[] array1 = new double[col]; 
 
            for (int i = 0; i < col; i++) 
            { 
                int begin = 0; 
                string TempStr1 = ""; 
                while ((begin < secondstr.Length) && (secondstr[begin] != ' ') && (secondstr[begin] != ',') && (secondstr[begin] != '\t')) 
                { 
                    begin++; 
                } 
                TempStr1 = secondstr.Substring(0, begin); 
                array1[i] = Convert.ToDouble(TempStr1); 
                secondstr = secondstr.Substring(begin, secondstr.Length - begin); 
                secondstr = secondstr.TrimStart(' '); 
            } 
            return array1; 
        } 
    } 
}