reading a complex text file

Hi, I want to read a text file exactly as below, the file consists of 3 sections, that I copied the first lines from each section below. as you can see the 3rd section starts with a text line and this one line is the only string type of data in the text file. I cannot just delete it since this file is going to be read and written (after some change) in an iterative manner. I appreciate it if someone can help me with this.
1
0.00
1 5 4 180
2 5 4 180
3 5 3 180
1 1 32 5 4 1 4 0 0 0
4 1 1 3 7062 6493 16015
1 2 32 5 4 1 6493 0 0 0
6493 1 2 3 16015 4 7062
=======Two Way Stop Signs/Yield Signs Below =======
75 2 2
750 75 6186 75
76 75 6182 75
381 2 1

 Respuesta aceptada

Walter Roberson
Walter Roberson el 19 de Jun. de 2011

0 votos

Looks like at least 5 sections to me.
Please indicate which parts are a fixed number of lines, and which parts can be repeated indefinitely.
The lines that end with 0 -- are those always exactly 10 fields, and will those lines always start with 1 ? Will the lines with 7 fields strictly alternate with the lines with 10 fields? Is 7 a fixed number of fields or does it vary with the data?
In the third section, is every line always 3 or 4 fields?
How do you want the data broken up for further use?
For the third section, should some particular "filler" value be used to indicate that the 4th value is not present?
Is that 0.00 certain to be the only floating point number?
Portions of the file appear to be fixed width fields. Are those portions defined to be fixed width fields? If so, then can an empty field appear in the middle of the line or only at the end of the line?

3 comentarios

Arash
Arash el 20 de Jun. de 2011
that's correct (5 sections), sorry for not being clear. or we can say 6 sections: the 1st section is just one line showing 1, the 2nd section is again one line showing 0.00. these two sections are always the same. the 3rd section always contains 5388 lines with 4 fields (always 4 fields). number of lines in the 4th section is not fixed but can be found: the number of lines in the 4th section can be found from the elements with values of 4 or 5 in the 2nd field of the 3rd section PLUS some additional lines for each, in other words, each 4 or 5 (from section 3-field 2) forms a couple of 10-field line in section 4 (always 10)the number of generated 10-field lines equals the value of the 3rd filed of the corresponding 4-field line in the 3rd section, and about additional lines, the 6th filed of the 10-filed lines shows the number of additional lanes that are added right after the 10-field lines, these additional lanes can have different numbers of fields from min:5 to max:8 (the exact number of fields can be found from the 4th field of the additional lines), the 5th section is just one line of string data, the 6th section is somehow similar to section 4: the number of lines in this section equals the total number of elements with values of 6 in the 2nd field of the 3rd section PLUS some additional lines for each, in other words, each 6 (from section 3-field 2) forms a 3-field line in section 6 (always 3 fields), and about additional lines, for each 3-field line, 2 lines are added (always 2), the number of fields of the first added line equals 2*(the value of the 2nd field in the corresponding 3-field line), and the number of fields of the second added line equals 2*(the value of the 3rd field in the corresponding 3-field line), here is a better sample: (the 1st field of the 3rd section(1,6,75,5075,5214) shows IDs so they can be traced in the sections 4 and 6)
1
0.00
1 5 4 180
6 1 0 0
75 6 0 0
5075 4 4 105
5214 6 0 0
1 1 32 5 4 1 4 0 0 0
4 1 1 3 7062 6493 16015
1 2 32 5 4 1 6493 0 0 0
6493 1 2 3 16015 4 7062
1 3 32 5 4 1 7062 0 0 0
7062 1 3 3 6493 16015 4
1 4 64 5 4 1 16015 0 0 0
5075 1 76 10 7 2 5077 6060 0 0
5077 5075 1 2 6059 5074
6060 5075 1 2 5074 6059
5075 2 76 32 7 2 5077 6060 0 0
5077 5075 2 2 6060 5074
6060 5075 2 2 5077 6059
5075 3 76 25 7 1 5074 0 0 0
5074 5075 3 3 5077 6059 6060
5075 4 76 10 7 1 6059 0 0 0
6059 5075 4 3 6060 5074 5077
=======Two Way Stop Signs/Yield Signs Below =======
75 2 2
750 75 6186 75
76 75 6182 75
5214 2 3
5237 5214 5255 5214
440 5214 5224 5214 5258 5214
your questions: they don't always start with 1-about my further use, I want to change some values in the 3rd section that consequently will change some parts of the data in the 4th and 6th sections, and finally I want to write this file in the same format and so on (iteratively)- I think I have answered your questions, if you think I need to describe more please let me know, thanks so much for your help!!!! I really appreciate it!!!
Walter Roberson
Walter Roberson el 20 de Jun. de 2011
Ouch, my eyes hurt reading that description of the sections!
Arash
Arash el 20 de Jun. de 2011
I don't know why the format was changed in my comment, I tried one more time, but the format changed again. I will ask in a new question thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 19 de Jun. de 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by