+diff -ruN -x '*~' -x -q cml-orig/CmlStartup.m cml/CmlStartup.m
--- cml-orig/CmlStartup.m 2007-09-08 23:12:26.000000000 +0930
-+++ cml/CmlStartup.m 2016-09-19 10:30:08.673767127 +0930
++++ cml/CmlStartup.m 2018-04-12 16:38:31.966825321 +0930
@@ -20,7 +20,7 @@
addpath( strcat( cml_home, '\mex'), ...\r
strcat( cml_home, '\mat'), ...\r
-save( save_directory, save_flag, 'cml_home' );
\ No newline at end of file
+save( save_directory, save_flag, 'cml_home' );\r
+diff -ruN -x '*~' -x -q cml-orig/mat/CreateConstellation.m cml/mat/CreateConstellation.m
+--- cml-orig/mat/CreateConstellation.m 2007-12-27 21:36:24.000000000 +1030
++++ cml/mat/CreateConstellation.m 2018-04-15 10:21:35.325168186 +0930
+@@ -58,7 +58,7 @@
+ % Optional argument: Label Type
+ if (length(varargin)>=2)
+ label_type = varargin{2};
+- if ~isstr( label_type )
++ if ~ischar( label_type )
+ if (length( label_type ) ~= M )
+ error( 'Length of label_type must be M' );
+ elseif (sum( sort( label_type ) ~= [0:M-1] ) > 0)
+diff -ruN -x '*~' -x -q cml-orig/mat/InitializeWiMaxLDPC.m cml/mat/InitializeWiMaxLDPC.m
+--- cml-orig/mat/InitializeWiMaxLDPC.m 2007-07-21 08:18:04.000000000 +0930
++++ cml/mat/InitializeWiMaxLDPC.m 2018-04-15 10:19:59.487185664 +0930
+@@ -134,7 +134,7 @@
+ H(cnt1:cnt1+z-1, cnt2:cnt2+z-1)= eye(z); \r
+ end\r
+ if (Hbm(i, j) >0)\r
+- if ((rate ==2/3)&(ind ==0))\r
++ if ((rate ==2/3)&&(ind ==0))\r
+ H(cnt1:cnt1+z-1, cnt2:cnt2+z-1)=circshift( eye(z),[0,mod(Hbm(i,j),z)]);\r
+ else\r
+ H(cnt1:cnt1+z-1, cnt2:cnt2+z-1)= circshift( eye(z),[0,floor(Hbm(i,j)*z/z0)]);\r
+@@ -146,7 +146,7 @@
+ end\r
+ \r
+ P =eye(z);\r
+-if ((rate ==3/4) & (ind ==1))\r
++if ((rate ==3/4) && (ind ==1))\r
+ P=inv(circshift( eye(z),[0,floor(80*z/z0)]));\r
+ end\r
+ \r
+diff -ruN -x '*~' -x -q cml-orig/source/matrix.h cml/source/matrix.h
--- cml-orig/source/matrix.h 1970-01-01 09:30:00.000000000 +0930
-+++ cml/source/matrix.h 2016-09-19 10:25:58.009761169 +0930
-@@ -0,0 +1 @@
++++ cml/source/matrix.h 2018-04-12 16:38:31.966825321 +0930
+@@ -0,0 +1,1 @@
+#include <mex.h>
+diff -ruN -x '*~' -x -q cml-orig/source/MpDecode.c cml/source/MpDecode.c
+--- cml-orig/source/MpDecode.c 2007-08-06 14:44:24.000000000 +0930
++++ cml/source/MpDecode.c 2018-04-15 07:28:51.092724038 +0930
+@@ -53,6 +53,7 @@
+ #include <mex.h>\r
+ #include <matrix.h>\r
+ #include <stdlib.h>\r
++#include <stdio.h>\r
+ \r
+ /* Input Arguments */\r
+ #define INPUT prhs[0]\r
+@@ -332,8 +333,10 @@
+ int sign;\r
+ float temp_sum;\r
+ float Qi;\r
+-\r
++ int ssum;\r
++ \r
+ for (iter=0;iter<max_iter;iter++) {\r
++ ssum = 0;\r
+ /* update r */\r
+ for (j=0;j<NumberParityBits;j++) { \r
+ sign = v_nodes[ c_nodes[j].index[0] ].sign[ c_nodes[j].socket[0] ];\r
+@@ -344,6 +347,8 @@
+ sign ^= v_nodes[ c_nodes[j].index[i] ].sign[ c_nodes[j].socket[i] ];\r
+ }\r
+ \r
++ if (sign==0) ssum++;\r
++ \r
+ for (i=0;i<c_nodes[j].degree;i++) {\r
+ if ( sign^v_nodes[ c_nodes[j].index[i] ].sign[ c_nodes[j].socket[i] ] ) {\r
+ c_nodes[j].message[i] = -phi0( phi_sum - v_nodes[ c_nodes[j].index[i] ].message[ c_nodes[j].socket[i] ] )*r_scale_factor;\r
+@@ -382,12 +387,18 @@
+ for (i=0;i<CodeLength-NumberParityBits;i++)\r
+ if ( DecodedBits[iter+max_iter*i] != data[i] )\r
+ BitErrors[iter]++;\r
+-\r
++ \r
+ /* Halt if zero errors */\r
+ if (BitErrors[iter] == 0)\r
+- break; \r
++ break;\r
++ \r
++ // added by Bill -- reuse the BitErrors array to count PCs\r
++ // count the number of PC satisfied and exit if all OK\r
++ BitErrors[iter] = ssum;\r
++ if (ssum==NumberParityBits) break;\r
+ \r
+ }\r
++ //fprintf(stderr, " iter: %d ssum is %d \n", iter, ssum);\r
+ }\r
+ \r
+ /* main function that interfaces with MATLAB */\r
+@@ -765,4 +776,4 @@
+ free( v_nodes );\r
+ \r
+ return;\r
+-}
+\ No newline at end of file
++}\r