471,337 Members | 1,117 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 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 993
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

Post your reply

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

Similar topics

2 posts views Thread by Roberto A. F. De Almeida | last post: by
7 posts views Thread by Kylotan | last post: by
8 posts views Thread by Gerrit Holl | last post: by
19 posts views Thread by Johnny Google | last post: by
7 posts views Thread by M | last post: by
AdrianH
1 post views Thread by AdrianH | last post: by
5 posts views Thread by Luis Zarrabeitia | last post: by
reply views Thread by rosydwin | last post: by

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.