miguelmoreto / pycomtrade

pyComtrade is a python module that provides you a transparent way for reading and writing oscillographic files in Comtrade format
http://pypi.python.org/pypi/pyComtrade
GNU General Public License v3.0
31 stars 30 forks source link

Different *.cfg breaks the library #8

Closed ldemattos closed 7 years ago

ldemattos commented 7 years ago

The oscillographic record that I'm trying to read doesn't have some data fields that are currently taken for granted by pycomtrade, hence I get IndexError exception. Those fields are:

on method ReadCFG() self.rev_year = int(templist[2])

self.primary.append(float(templist[10]))
self.secondary.append(float(templist[11]))
self.PS.append(templist[12])
self.Dccbm.append(templist[3])
self.y.append(int(templist[4]))

and

self.timemul = float(self.filehandler.readline())

I'm proposing a solution through PR. It's based on a simple check of the templist vector length.

miguelmoreto commented 7 years ago

Hello @ldemattos !

thanks for your help. If I understood correctly your comtrade record is broken, right? I agree with you that pyContrade should not crash in this case, but return to the user an indication of that. In you solution is this your idea or are you trying to read de broken comtrade? If think that a broken cfg should not be readed.

Best regards,

ldemattos commented 7 years ago

Hi @miguelmoreto !

My pleasure to help!

I don't know if it is broken or those are optional fields, since the record that I'm analyzing opens correctly on other oscillographic readers. I'm not used IEEE Comtrade standard details. Sorry.

The solution that I have proposed simply check if the missing fields exists, and if TRUE, reads it, or else skip it. It's a very simple solution that do not hinder by no means the reading of files that contains all fields. Nevertheless, it make the program more reliable.

I do agree that a broken cfg should not be opened, however this one is a keeper.

Best regards,

miguelmoreto commented 7 years ago

Ok. Can you include some comments in the code about these modifications? After that I will merge your PR. Best regards.

miguelmoreto commented 7 years ago

Done! PR merged!