----Messaggio originale---- Da: [EMAIL PROTECTED] Data: 3-mag-2007 10.02 A: <python-list@python.org> Ogg: problem with meteo datas
Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by word and number arguments like this: GRILLE EURAT5 Coin Nord-Ouest : 46.50/ 0.50 Coin Sud-Est : 44.50/ 2.50 MODELE PA PARAMETRE P NIVEAU MER 0 ECHEANCE 0.0 DATE 20020304000000 NB_POINTS 25 1020.91 1020.87 1020.91 1021.05 1021.13 1020.07 1020.27 1020.49 1020.91 1021.15 1019.37 1019.65 1019.79 1020.53 1020.77 1018.73 1018.89 1019.19 1019.83 1020.81 1018.05 1018.19 1018.75 1019.55 1020.27 NIVEAU MER 0 ECHEANCE 3.0 DATE 20020304000000 NB_POINTS 25 1019.80 1019.78 1019.92 1020.18 1020.34 1018.94 1019.24 1019.54 1020.08 1020.32 1018.24 1018.64 1018.94 1019.84 1019.98 1017.48 1017.88 1018.28 1018.98 1019.98 1016.62 1017.08 1017.66 1018.26 1018.34 NIVEAU MER 0 ECHEANCE 6.0 DATE 20020304000000 NB_POINTS 25 1019.37 1019.39 1019.57 ........ ........ ....... ......... ....... ....... ....... ....... ......... NIVEAU MER 0 ECHEANCE 48.0 DATE 20020304000000 NB_POINTS 25 1017.84 1017.46 1017.14 1016.86 1016.58 1017.28 1016.90 1016.46 1016.48 1016.34 1016.50 1016.06 1015.62 1015.90 1015.72 1015.94 1015.30 1014.78 1014.68 1014.86 1015.86 1015.10 1014.36 1014.00 1013.90 ............................. MODELE PA PARAMETRE T NIVEAU HAUTEUR 2 ECHEANCE 0.0 DATE 20020304000000 NB_POINTS 25 1.34 1.51 1.40 0.56 -0.36 1.73 1.43 0.89 -0.16 -0.99 2.06 1.39 1.14 -0.53 -0.99 2.12 2.22 2.15 0.76 -1.16 1.67 1.45 1.40 1.26 0.28 NIVEAU HAUTEUR 2 ECHEANCE 3.0 DATE 20020304000000 NB_POINTS 25 0.94 1.16 1.03 0.44 -0.41 0.95 0.61 0.22 ............................................. I'am at the begginning of computation and for the moment I write this code to extract only number data in form of a string: from pyparsing import * dec = Combine (Optional( "-" ) + delimitedList( Word( nums ), ".", combine=True )) datas = ZeroOrMore( dec ) f=file("arqal-Arpege.00", "r") g=file("out3", "w") for line in f: try: result = datas. parseString (line) add = result add1 = ";".join (add) print >> g,"(",add1,")" except ParseException, pe: print pe This is the output result in file g=file("out3", "w") ( ) ( ) ( ) ( 1020.91;1020.87;1020.91;1021.05;1021.13 ) ( 1020.07;1020.27; 1020.49;1020.91;1021.15 ) ( 1019.37;1019.65;1019.79; 1020.53;1020.77 ) ( 1018.73;1018.89;1019.19;1019.83;1020.81 ) ( 1018.05;1018.19;1018.75; 1019.55;1020.27 ) ( ) ( 1019.80;1019.78; 1019.92;1020.18;1020.34 ) ( 1018.94;1019.24;1019.54;1020.08;1020.32 ) ( 1018.24;1018.64;1018.94; 1019.84;1019.98 ) ( 1017.48;1017.88;1018.28; 1018.98;1019.98 ) ( 1016.62; 1017.08;1017.66;1018.26;1018.34 ) ( ) ( 1019.37;1019.39;1019.57; 1019.9;......; ........ .........; 1016.87) ( ) ( 1017.84; 1017.46;1017.14;1016.86;1016.58 ) ( 1017.28; 1016.90;1016.46;1016.48; 1016.34 ) ( 1016.50;1016.06;1015.62;1015.90; 1015.72 ) ( 1015.94;1015.30; 1014.78;1014.68;1014.86 ) ( 1015.86; 1015.10;1014.36;1014.00;1013.90 ) So I don't have any word but the problem is that Now I have to put in order this numerical datas in a type of NESTED matrix emulated by python like a nested dictionary : { 'P ' : { MER 0 : [ (1020.91; 1020.87;........;1020.27 ) ; (.........) ; ( 1019.80;1019.78;........; 1018.26;1018.34 ) ]; ......; SOL 0 : [ ( .......);.....;(........ ) ] } ; 'T' : { SOL 0 : [(.....;......) ; (ECHEANCE 3.0) ; (ECHEANCE 6.0) ; (.......;........) ]; HAUTEUR 2 : [(.......;......;......) ] } } ======>>>>>> { 'Parameter X' : { Level X : [ (predict step 3 hours from +0 to +48 hours ) ;]} } >>>>>> the bigger shell is fixed by Dictionary PARAMETER in the example is P= 'Pressure' but thre are many of this Temperature = T , Wind = U and V ecc... the second nested shell is setted by another Dictionary NIVEAU MER 0 in the example is MER 0 = sea level or SOL 0, but can be HAUTER 2,10 (HEIGHT 2,10 METERS) ecc..... (soil level , 1;0 meter from soil) ecc (from French language) and after every Level is associated with a LIST OF TUPLE: [(....); (....);(....)] to rappresented every step hours of prediction or expiration hours in French language: ECHEANCE XX.X = predicted hour +3. 0 +6.0 until 48H is setted of a list of tuple [(ECHEANCE 3.0); (ECHEANCE 6.0); (ECHEANCE XX.0);.........;(ECHEANCE 48.0)] like so: [1019.37; 1019.39;........;1020.27 );(.........);(1019.80; 1019.78;........; 1018.26;1018.34 )] where every list is at the end the is the datas grill: (5 x 5 points)= 25 datas 1020.91 1020.87 1020.91 1021.05 1021.13 1020.07 1020.27 1020.49 1020.91 1021.15 1019.37 1019.65 1019.79 1020.53 1020.77 1018.73 1018.89 1019.19 1019.83 1020.81 1018.05 1018.19 1018.75 1019.55 1020.27 So I ask you wich is the best way to begin to code the grammar parsying to make recognize him the 'word' inside of the data file and put the data in the form of nested dictionary and list of tuple illustrated before. In attached file there is one meteo arpege datas file and text of the message in open office file Thanks a lot for everyone can said me anything to solve this, big problem (for me)!!!! -- http://mail.python.org/mailman/listinfo/python-list