473,389 Members | 1,066 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 software developers and data experts.

File parsing of different file format

440 256MB
Hi,

The following if the file format,which need to read the data and store the data in a proper format.

Thanks
PSB
Expand|Select|Wrap|Line Numbers
  1. FileFormat
  2. $TITLE   = THIS IS A DEFAULT SUBCASE.                                          1
  3. $SUBTITLE=DEFAULT                                                              2
  4. $LABEL   =                                                                     3
  5. $                                                                       4
  6. $REAL OUTPUT                                                                   5
  7. $SUBCASE ID =           1                                                      6
  8.   26010701       G      0.000000E+00      0.000000E+00      0.000000E+00       7
  9. -CONT-                  0.000000E+00      0.000000E+00      0.000000E+00       8
  10.   26010705       G      0.000000E+00      3.749271E+01     -2.064228E+02       9
  11. -CONT-                  0.000000E+00      0.000000E+00      0.000000E+00      10
  12. $TITLE   = THIS IS A DEFAULT SUBCASE.                                       3621
  13. $SUBTITLE=DEFAULT                                                           3622
  14. $LABEL   =                                                                  3623
  15. $SPCF                                                                       3624
  16. $REAL OUTPUT                                                                3625
  17. $SUBCASE ID =           1                                                   3626
  18.   26010701       G      1.952712E+08     -4.666506E+08     -1.753539E+08    3627
  19. -CONT-                  0.000000E+00      0.000000E+00      0.000000E+00    3628
  20.   26010705       G      1.423922E+05      0.000000E+00      0.000000E+00    3629
  21. -CONT-                  0.000000E+00      0.000000E+00      0.000000E+00    3630
  22. $SUBCASE ID =           1                                                   7246
  23. $ELEMENT TYPE =         144  QUAD4C    VONM           BILIN                 7247
  24.    1101101        CEN/                       4             -2.761030E-01    7248
  25. -CONT-                 -8.196901E+07     -1.179783E+07      4.211394E+07    7249
  26. -CONT-                  6.489902E+01      7.930654E+06     -1.016975E+08    7250
  27. -CONT-                  1.058858E+08      2.761030E-01     -8.196901E+07    7251
  28. -CONT-                 -1.179783E+07      4.211394E+07      6.489902E+01    7252
  29. -CONT-                  7.930654E+06     -1.016975E+08      1.058858E+08    7253
  30. -CONT-              86020101             -2.761030E-01     -7.440834E+07    7254
  31. -CONT-                 -4.704828E+07      2.672956E+07      5.855155E+01    7255
  32. -CONT-                 -3.070145E+07     -9.075518E+07      7.995477E+07    7256
  33. -CONT-                  2.761030E-01     -7.440834E+07     -4.704828E+07    7257
  34. -CONT-                  2.672956E+07      5.855155E+01     -3.070145E+07    7258
  35. -CONT-                 -9.075518E+07      7.995477E+07  86020105            7259
  36. -CONT-                 -2.761030E-01     -6.063257E+07      2.346534E+07    7260
  37. -CONT-                  5.788607E+07      6.299749E+01      5.296295E+07    7261
  38. -CONT-                 -9.013018E+07      1.253080E+08      2.761030E-01    7262
  39. -CONT-                 -6.063257E+07      2.346534E+07      5.788607E+07    7263
  40. -CONT-                  6.299749E+01      5.296295E+07     -9.013018E+07    7264
  41. -CONT-                  1.253080E+08  86010105             -2.761030E-01    7265
  42. -CONT-                 -8.953238E+07      2.354783E+07      5.754012E+07    7266
  43. -CONT-                  6.724889E+01      4.767772E+07     -1.136623E+08    7267
  44. -CONT-                  1.435668E+08      2.761030E-01     -8.953238E+07    7268
  45. -CONT-                  2.354783E+07      5.754012E+07      6.724889E+01    7269
  46. -CONT-                  4.767772E+07     -1.136623E+08      1.435668E+08    7270
  47. -CONT-              86010101             -2.761030E-01     -1.033237E+08    7271
  48. -CONT-                 -4.714099E+07      2.630644E+07      6.843965E+01    7272
  49. -CONT-                 -3.674659E+07     -1.137181E+08      1.005155E+08    7273
  50. -CONT-                  2.761030E-01     -1.033237E+08     -4.714099E+07    7274
  51. -CONT-                  2.630644E+07      6.843965E+01     -3.674659E+07    7275
  52. -CONT-                 -1.137181E+08      1.005155E+08                      7276
  53. $SUBCASE ID =           1                                                  56379
  54. $ELEMENT TYPE =           1  ROD                                           56380
  55.    1503101             -5.977985E+07         1              0.000000E+00   56381
  56. -CONT-                     1                                               56382
  57.    1503105             -5.080535E+07         1              0.000000E+00   56383
  58. -CONT-                     1                                               56384
  59. $SUBCASE ID =           1                                                  59646
  60. $ELEMENT TYPE =          74  TRIA3     VONM                                59647
  61.    1102105             -1.972300E-01     -4.522417E+07      1.691269E+07   59648
  62. -CONT-                  6.367384E+07      5.800459E+01      5.669343E+07   59649
  63. -CONT-                 -8.500491E+07      1.235281E+08      1.972300E-01   59650
  64. -CONT-                 -4.522417E+07      1.691269E+07      6.367384E+07   59651
  65. -CONT-                  5.800459E+01      5.669343E+07     -8.500491E+07   59652
  66. -CONT-                  1.235281E+08                                       59653
  67.    1103108             -2.024500E-01     -1.456588E+07      1.263059E+07   59654
  68. -CONT-                  8.925811E+06      7.335966E+01      1.529834E+07   59655
  69. -CONT-                 -1.723362E+07      2.819011E+07      2.024500E-01   59656
  70. -CONT-                 -1.456588E+07      1.263059E+07      8.925811E+06   59657
  71. -CONT-                  7.335966E+01      1.529834E+07     -1.723362E+07   59658
  72. -CONT-                  2.819011E+07                                       59659
  73.  
  74.  
Jan 5 '08 #1
1 1050
psbasha
440 256MB
Expand|Select|Wrap|Line Numbers
  1. SampleData
  2. def read_file_data(self,strFile):
  3.         bQuadDataFlag = False
  4.         bTriaDataFlag = False
  5.         bRodDataFlag = False
  6.         bEleStressFlag = False
  7.         iCounter = 0
  8.         dataTempList = []
  9.         dataList = []
  10.         dataID = 0
  11.         dataIDDataDict = {}
  12.  
  13.         f = open(strFile,'r')
  14.  
  15.         strTemp = f.readlines()
  16.  
  17.         for line in strTemp:            
  18.             """if line.startswith('$ELEMENT STRESSES'):
  19.                 bEleStressFlag = False
  20.             else:
  21.                 pass"""
  22.             if line.startswith('$ELEMENT TYPE ='):
  23.                 if 'QUAD4C' in line.split():
  24.                     bQuadDataFlag = True
  25.                     bTriaDataFlag = False
  26.                     bRodDataFlag = False
  27.                 elif 'TRIA3' in line.split():
  28.                     bQuadDataFlag = False
  29.                     bTriaDataFlag = True
  30.                     bRodDataFlag = False
  31.                 elif 'ROD' in line.split():
  32.                     bRodDataFlag = True
  33.                     bQuadDataFlag = False
  34.                     bTriaDataFlag = False                        
  35.             elif bQuadDataFlag:
  36.                 if line.startswith('$TITLE'):
  37.                     bQuadDataFlag = False
  38.                 else:
  39.                     dataTempList = line.split()
  40.                     if 'CEN/' in line.split():                    
  41.                         dataID = int( dataTempList[0])
  42.                         dataList.append(float(dataTempList[3]))
  43.                         iCounter = iCounter +1
  44.                     elif '-CONT-' in line.split() and iCounter ==1:
  45.                         dataList.append(float(dataTempList[1]))
  46.                         dataList.append(float(dataTempList[2]))
  47.                         iCounter = iCounter +1
  48.                     elif '-CONT-' in line.split() and iCounter ==2:
  49.                         dataList.append(float(dataTempList[2]))
  50.                         iCounter = iCounter +1
  51.                     if iCounter == 3:
  52.                         dataIDDataDict[dataID] = dataList
  53.                         dataList = []
  54.                         iCounter = 0
  55.                     #bQuadDataFlag = False
  56.             elif  bTriaDataFlag:
  57.                 if line.startswith('$TITLE'):
  58.                     bTriaDataFlag = False
  59.                 else:
  60.                     dataTempList = line.split()
  61.                     if iCounter ==0 and ('-CONT-' not in line.split()):
  62.                         dataID = int( dataTempList[0])
  63.                         dataList.append(float(dataTempList[2]))
  64.                         dataList.append(float(dataTempList[3]))
  65.                         iCounter = iCounter +1
  66.                     elif '-CONT-' in line.split() and iCounter ==1:                    
  67.                         dataList.append(float(dataTempList[3]))
  68.                         iCounter = iCounter +1
  69.                     if iCounter == 2:
  70.                         dataIDDataDict[dataID] = dataList
  71.                         dataList = []
  72.                         iCounter = 0
  73.                         bQuadDataFlag = False                    
  74.                         bRodDataFlag = False
  75.             elif  bRodDataFlag:
  76.                 if line.startswith('$TITLE'):
  77.                     bRodDataFlag = False
  78.                 else:
  79.                     dataTempList = line.split()
  80.                     if iCounter ==0:
  81.                         dataID = int( dataTempList[0])
  82.                         dataList.append(float(dataTempList[1]))                    
  83.                         iCounter = iCounter +1
  84.                     elif '-CONT-' in line.split() and iCounter ==1:
  85.                         iCounter = iCounter +1
  86.                         pass
  87.                     if iCounter == 2:
  88.                         dataIDDataDict[dataID] = dataList
  89.                         dataList = []
  90.                         iCounter = 0
  91.                         bQuadDataFlag = False
  92.                         bTriaDataFlag = False
  93.         print dataIDDataDict
  94.  
Find the above code.Is this code can be made more modular or precise size to handle 1GB data.

Thanks
PSB
Jan 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Roberto A. F. De Almeida | last post by:
Hi, I'm interested in parsing a file containing this "structure": """dataset { int catalog_number; sequence { string experimenter; int32 time; structure {
7
by: Kylotan | last post by:
I have a text file where the fields are delimited in various different ways. For example, strings are terminated with a tilde, numbers are terminated with whitespace, and some identifiers are...
8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Subodh | last post by:
Hi, Currently we get data from more then 200 different sources and all of our vendors provide data in different file formats. The problem is we have more then 100 DTS packages now and the...
19
by: Johnny Google | last post by:
Here is an example of the type of data from a file I will have: Apple,4322,3435,4653,6543,4652 Banana,6934,5423,6753,6531 Carrot,3454,4534,3434,1111,9120,5453 Cheese,4411,5522,6622,6641 The...
7
by: M | last post by:
Hi, I need to parse text files to extract data records. The files will consist of a header, zero or more data records, and a trailer. I can discard the header and trailer but I must split the...
7
by: christian.eickhoff | last post by:
Hi Everyone, I am currently implementing an XercesDOMParser to parse an XML file and to validate this file against its XSD Schema file which are both located on my local HD drive. For this...
9
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
5
by: Luis Zarrabeitia | last post by:
I need to parse a file, text file. The format is something like that: TYPE1 metadata data line 1 data line 2 .... data line N TYPE2 metadata data line 1 ....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.