From 2f5bea934d59f7d754ca3cfcae96cb5dceb30b37 Mon Sep 17 00:00:00 2001 From: Lan Dam <ldam@passcal.nmt.edu> Date: Thu, 24 Jan 2019 14:50:26 -0700 Subject: [PATCH] error writing fixed header --- fixhdr/LibTrace.py | 99 +++++++++++++++++++++++++--------------------- fixhdr/fixhdr.py | 4 +- 2 files changed, 55 insertions(+), 48 deletions(-) diff --git a/fixhdr/LibTrace.py b/fixhdr/LibTrace.py index 68dabb4..39e6b30 100755 --- a/fixhdr/LibTrace.py +++ b/fixhdr/LibTrace.py @@ -503,52 +503,59 @@ class Mseed(futils): Requires four tuples (see self.fixedhdr) """ - try: - self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) - #station info - #left justify values - #fmtstr0 = fmtorderstr + "6scc5s2s3s2s" - - SeqNum=self.Pad(hdrlist[0][0], 6) #SeqNum - DQual=hdrlist[0][1] #DataQual - Res=hdrlist[0][2] #Reserved - Stat=self.Pad(hdrlist[0][3], 5) #Stat - Loc=self.Pad(hdrlist[0][4], 2) #Loc - Chan=self.Pad(hdrlist[0][5], 3) #Chan - Net=self.Pad(hdrlist[0][6], 2) #Net - - #time info - #fmtstr1 = fmtorderstr + "HHBBBBH" - (Year, Day, Hour, Min, Sec, junk, Micro)=hdrlist[1] - Micro=int(Micro) - - #sample info - #fmtstr2 = fmtorderstr + "Hhh" - (NumSamp, SampFact, SampMult)=hdrlist[2] - - #misc info - #fmtstr3 = fmtorderstr + "BBBBlHH" - (actFlags, ioFlags, dqFlags, numblk, timecor, offsetData, offsetBlktt)=hdrlist[3] - #convert flag string to integer - actFlags = self.FlagStrtoInt(actFlags) - ioFlags = self.FlagStrtoInt(ioFlags) - dqFlags = self.FlagStrtoInt(dqFlags) - - #pack fields - fmtstr= fmtorderstr + "6scc5s2s3s2sHHBBBBHHhhBBBBlHH" - pack_hdr=self.spack(fmtstr,SeqNum, DQual, Res, Stat, Loc, Chan, Net,\ - Year, Day, Hour, Min, Sec, junk, Micro,\ - NumSamp, SampFact, SampMult,\ - actFlags, ioFlags, dqFlags, numblk, timecor, offsetData, offsetBlktt) - - #write header - self.infilewrite(pack_hdr) - - return 48 - except Exception as e: - print("error writing fixed header") - return 0 + #try: + self.infileseek(seekval) + fmtorderstr=self.setEndian(endianess) + #station info + #left justify values + #fmtstr0 = fmtorderstr + "6scc5s2s3s2s" + + SeqNum = self.Pad(hdrlist[0][0], 6) #SeqNum + DQual = hdrlist[0][1] #DataQual + Res = hdrlist[0][2] #Reserved + Stat = self.Pad(hdrlist[0][3], 5).encode() #Stat + Loc = self.Pad(hdrlist[0][4], 2).encode() #Loc + Chan = self.Pad(hdrlist[0][5], 3).encode() #Chan + Net = self.Pad(hdrlist[0][6], 2).encode() #Net + + #time info + #fmtstr1 = fmtorderstr + "HHBBBBH" + (Year, Day, Hour, Min, Sec, junk, Micro)=hdrlist[1] + Micro=int(Micro) + + #sample info + #fmtstr2 = fmtorderstr + "Hhh" + (NumSamp, SampFact, SampMult) = hdrlist[2] + + #misc info + #fmtstr3 = fmtorderstr + "BBBBlHH" + (actFlags, ioFlags, dqFlags, numblk, timecor, offsetData, + offsetBlktt)=hdrlist[3] + #convert flag string to integer + actFlags = self.FlagStrtoInt(actFlags) + ioFlags = self.FlagStrtoInt(ioFlags) + dqFlags = self.FlagStrtoInt(dqFlags) + print("SeqNum, DQual, Res, Stat, Loc, Chan, Net,Year, Day, Hour, Min, Sec, junk, Micro,NumSamp, SampFact, SampMult,actFlags, ioFlags, dqFlags,numblk, timecor, offsetData, offsetBlktt:", + SeqNum, DQual, Res, Stat, Loc, Chan, Net, + Year, Day, Hour, Min, Sec, junk, Micro, + NumSamp, SampFact, SampMult,actFlags, ioFlags, dqFlags, + numblk, timecor, offsetData, offsetBlktt) + #pack fields + fmtstr = fmtorderstr + "6scc5s2s3s2sHHBBBBHHhhBBBBlHH" + print("fmtstr") + pack_hdr = self.spack( + fmtstr,SeqNum, DQual, Res, Stat, Loc, Chan, Net, + Year, Day, Hour, Min, Sec, junk, Micro, + NumSamp, SampFact, SampMult,actFlags, ioFlags, dqFlags, + numblk, timecor, offsetData, offsetBlktt) + + #write header + self.infilewrite(pack_hdr) + + return 48 + #except Exception as e: + #print("error writing fixed header") + #return 0 ######################################################### def GetBlk(self, blknum, seekval=0): diff --git a/fixhdr/fixhdr.py b/fixhdr/fixhdr.py index 737743c..157ddc2 100755 --- a/fixhdr/fixhdr.py +++ b/fixhdr/fixhdr.py @@ -2281,8 +2281,8 @@ class MainWindow: Net = Net.strip().decode() key = Stat + ":" + Loc + ":" + Net if key != self.TimeShiftName.get(): - blk_err+=1 - n+=1 + blk_err += 1 + n += 1 continue # determine time of blockette and process if between startEpoch -- GitLab