diff --git a/scripts/ibsimu2tw b/scripts/ibsimu2tw
old mode 100644
new mode 100755
index 4c628b8106f910576707e101334a9e9160813b57..16349f5dbb80d7d9b11128d0e28894614e916dd3
--- a/scripts/ibsimu2tw
+++ b/scripts/ibsimu2tw
@@ -81,14 +81,14 @@ def save_dst(file_name, x6, Ibeam, mc2=938.272, freq=352.21):
 
     x6 = numpy.reshape(x6, (numpy.size(x6)))    
     with open(file_name, 'wb') as file:
-        out  = struct.pack('b'             , 125        )
-        out += struct.pack('b'             , 100        )
-        out += struct.pack('i'             , len(x6) )
-        out += struct.pack('d'             , Ibeam      )
-        out += struct.pack('d'             , freq       )
-        out += struct.pack('b'             , 125        )  # Typo in the manual !!!!
-        out += struct.pack('%s'%len(x6)+'d', *x6        )
-        out += struct.pack('d'             , mc2        )
+        out  = struct.pack('b'                  , 125        )
+        out += struct.pack('b'                  , 100        )
+        out += struct.pack('i'                  , len(x6)//6 )
+        out += struct.pack('d'                  , Ibeam      )
+        out += struct.pack('d'                  , freq       )
+        out += struct.pack('b'                  , 125        )  # Typo in the manual !!!!
+        out += struct.pack('{}d'.format(len(x6)), *x6        )
+        out += struct.pack('d'                  , mc2        )
         file.write(out)
 
 #-- Parameters from the header