java - How to sort a large text file's data into a multi-dimensional array? -


i have large data file. starts off big paragraph want ignore or remove equation, has year e.g. 1974, 6 spaces, number represent month, e.g. 1, has 31 data entries want sort 3d array.

i think i'm close solving it, keep getting exception java.lang.arrayindexoutofboundsexception.

full error is:

exception in thread "main" java.lang.arrayindexoutofboundsexception: 31 @ pkg110_term3.getdata.readfile(getdata.java:48) @ pkg110_term3.main.main(main.java:25) java result: 1

here code:

public class getdata {      public string[][][] sorteddata = new string[34][12][31];      int = 0;     int b = 0;     int c = 0;      private scanner rainfile;      //method opening file     public void openfile() {          try{             rainfile = new scanner(new file("c:\\\\users\\\\admin\\\\documents\\\\netbeansprojects\\\\110_term3\\\\weatherdatafiles\\\\rainfall.txt"));         }         catch(exception e){             joptionpane.showmessagedialog(null, "check file path correct.", "no file found!", joptionpane.error_message);         }     }      //method reading file     public void readfile(){          if(rainfile.equals("daily rainfall totals (mm), hazelrigg weather station, lancaster university (meteorological office climatological station number 7236) \n" + "brian davison, lec, lancaster university, data obtained march 2012 \n" + "format=year, month, 1-31 daily precipitation values. entry set -99.99 means no data exists day. ")){             rainfile.remove();         }         while(rainfile.hasnext()){             rainfile.next();             a++;             while(rainfile.hasnext()){                 rainfile.next();                 b++;                 for(int = 0; < 31; i++){                     string day = rainfile.next();                     sorteddata[a][b][c] = day;                     c++;                 }             }         }                    }          //close file once it's been used         public void closefile(){             rainfile.close();         }           //test method see if array full         public void arraytest(){             system.out.print(sorteddata[0][0][0]);             system.out.print("\n");             system.out.print(sorteddata[0][1][0]);             system.out.print("\n");         }  } 

i did ask similar question code has changed quite bit since.

thanks in advance.

first 2 years of rainfall data + paragraph want rid of:

daily rainfall totals (mm), hazelrigg weather station, lancaster university (meteorological office climatological station number 7236)  brian davison, lec, lancaster university, data obtained march 2012  format=year, month, 1-31 daily precipitation values. entry set -99.99 means no data exists day.  1974      1   0.00   0.00   1.70   3.30   8.70   2.30  12.70  13.10   0.01  13.50   1.50   5.50   1.90  15.40   6.50   7.70   4.00   0.10   0.00   0.00   0.00   8.00   0.20   0.01   0.01   7.00   8.00   0.20   2.30   7.00   0.20 1974      2   6.60  14.90   0.70   5.00   7.30   0.80   0.20   9.40   5.50  10.50   5.50   2.50   0.80   6.90   2.50   0.30   0.00   0.01   0.00   1.80   0.40   0.00   0.00   0.20   0.01   0.01   0.01   7.40 -99.99 -99.99 -99.99 1974      3   2.20   0.00   0.60   0.60   0.00  12.80   0.01   0.01   0.01   0.10   0.01   0.00   0.50   3.70   6.80   2.50   9.10   1.50   0.01   0.01   0.00   0.00   0.00   0.20   0.20   0.00   0.00   0.00   0.00   0.00   0.00 1974      4   0.00   0.01   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.70   0.80   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.01   0.00   0.00   0.00   0.00   0.00   0.00   0.01   0.00   0.01   0.00   0.00 -99.99 1974      5  35.60   0.90   0.60   0.00   0.01   0.00   0.00   0.10   4.50   2.40   0.01   2.70   3.00   0.00   0.00   0.01   0.01   1.20   1.30   3.10   1.00   7.40   7.30   0.01   0.01   0.01   1.00   4.10   0.00   0.00   0.01 1974      6   1.80   0.01   0.00   0.01  15.50   8.80   3.90   3.50   2.20   5.90   0.00   0.00   0.00   0.00   5.20   4.00   0.01   6.20   0.01   0.00   0.00   0.00   0.00   0.00   0.00   0.01   0.00   0.00   0.00  16.70 -99.99 1974      7   0.01  32.30   3.70  16.40   0.01   1.70   0.10   0.20   2.90   1.80   0.01   0.00   0.10  11.50  16.00   2.20   0.01   0.80   5.20   0.00   0.01  10.00   0.10   0.00   6.80   0.00   4.00   1.30  15.00   9.20   4.20 1974      8   0.00   0.00   0.00   0.00   0.00   0.00   0.10   7.30  19.40   4.40  16.40   0.01   0.10   5.60   0.00   1.20   0.00   0.00   0.00   0.00   1.00   1.70   0.10   0.20   3.80   7.60   0.01   0.00   0.01   0.00   5.50 1974      9   1.40   7.60   3.90  29.80  12.90  12.80  16.80  22.40   1.10   0.01   0.50  12.00   0.01   0.50   0.20   8.50   0.01   0.00   1.20   8.80   1.40  12.70   7.90  19.80   2.20   0.70  16.40   0.00   0.01   0.01 -99.99 1974     10  12.30   0.20   6.20   0.01   0.01  11.30   0.20   0.00   0.00   0.10   0.00   0.00   0.00   0.01   5.10   0.01   4.20  16.80   8.30   0.50   0.01   0.01   0.00   0.70   0.20   2.70   1.10   0.00   0.00   4.30   2.40 1974     11   0.01   8.40   0.80   0.00   0.90   0.20   9.10   2.60   6.00  11.60   6.00   2.30  15.60   6.40   3.20   0.01   0.00   0.00   2.50   0.01   0.30   1.60   5.60  11.50   2.30   0.90   3.40   0.01   8.10   2.10 -99.99 1974     12   0.80   0.30   2.30   0.90   0.01   0.60   7.80   1.20   5.90   8.70   4.80   1.20   4.00   0.00   7.80   5.20   5.20   1.80   0.00   4.30   2.30   0.01   7.80   2.70  10.00   2.00   3.80   1.60   0.50   1.50   0.00 1975      1   3.30   1.40   0.01   2.20   0.10  16.80   4.70   0.40   0.10   5.70   1.60   7.60   1.80   4.00   2.10  10.70   7.20   1.00   6.80   4.30  25.10  10.20   0.20  13.20   3.30   6.70   2.10   0.70   2.10   8.20   5.90 1975      2   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.00   3.10   0.80   1.60   6.80   1.70   0.00  16.00   0.20   0.00   0.00   0.90   0.00   0.00   2.50   0.00   0.00   0.00   0.00   0.00 -99.99 -99.99 -99.99 1975      3   0.50   2.20   0.50   9.90   0.00   6.90   0.00   0.00   0.01   0.10   0.10   0.00   0.00   0.01   0.00   0.01   0.01   0.01   0.00   0.00  15.60   0.01   0.00   0.01   8.80   1.10   0.01   0.00   0.20   1.00   0.00 1975      4   2.80   0.01   0.01   0.01   0.01   3.10   0.01   0.01   0.40   4.40   2.40   1.20   2.00   7.80   0.10   5.40   3.60   6.20   1.80   7.60   2.80   0.10   0.10   0.00   0.00   0.00   0.00   5.40   0.30   8.00 -99.99 1975      5   2.10   0.01   0.00   0.00   0.00   0.00   1.20   4.80   1.80   0.80   0.10   2.10   5.20   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.01   0.00   0.01   0.01   0.00   0.00   0.00   0.00   0.20   0.00 1975      6   3.10   1.90   3.40   5.60   4.00   0.00   0.00   0.00   0.00   0.00   0.00   0.00   0.10   0.00   0.40   0.00   0.01   1.10   1.50   1.40   0.00   0.00   0.00   0.01   0.00   0.00   0.00   0.00   0.00   0.00 -99.99 1975      7   0.00   0.00   0.01   0.01   0.00   0.00   0.01   0.10   7.20   7.90   0.01   5.50   5.90  18.10   0.01   0.00   7.00   0.01   4.10   2.20  15.60  32.80   2.50   7.20   2.50   0.01   0.00   0.01   0.01   0.01   0.00 1975      8   0.00   0.00   0.00   2.80   2.70   0.00   1.30   5.80   3.60   0.00   0.00   0.01   0.00  11.40  26.70   0.30   0.00   0.01   5.20   0.20   8.00   0.00   0.80   4.60   0.00   0.00   0.00   0.00   7.50   0.50   0.00 1975      9   0.00   0.40   0.01   5.40   2.00   0.90   1.30   9.70  13.70  23.50  18.90   0.20   0.00   0.00   0.00   0.00   6.90   0.30   3.80   1.80   0.00   7.40   0.60  32.00   5.60   3.40  13.50   0.00   4.60  19.90 -99.99 1975     10   8.30  21.10   0.20   5.00   0.20   0.00   0.00   0.01   1.80   0.00   0.00   0.00   0.01   0.10   1.20   1.20   0.00   0.00   0.00   0.00   0.00   0.01   6.00   0.00   0.01   0.00   0.00   0.00   0.01   0.40   3.20 1975     11   8.20   9.70   0.01   8.70   4.90   0.01   0.00   0.00   0.50   0.40   0.10   0.00   0.00   5.80  17.50   0.01   0.00   4.60   3.00   0.00   0.00   0.20   5.00   4.20  11.50   6.80   7.20   0.01   3.10   5.00 -99.99 1975     12  43.20   0.01   0.01   0.01   0.01   0.40   0.01   0.01   0.01   0.01   3.20   0.00   0.01   0.00   0.01   0.20   0.00   1.30   0.20   0.01   0.01   0.01   3.10   8.40   0.01   0.01   0.80   0.10   0.40   3.20  10.70 

i've realised each month separated line, use make sorting easier?

if code tries execute following loop second time, starting value of c 31.

            for(int = 0; < 31; i++){                 string day = rainfile.next();                 sorteddata[a][b][c] = day;                 c++;             { 

you set a, b, c @ beginning , increment them.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -