RSZeta[t_] := RiemannSiegelZ[t]

mgetem[n_, m_] := Module[ {start,k,x,y,t,tt,h1,h2,z1,z2,t1,t2,rere,
                invave,center,scale1,scale2,scale3,max,tinc,kcheck,incr,
                diff1,diff2,diff3,diff4,diff5,diff6,diff7,diff8,
                diff9,diff10,diff11,
			    difn1,difn2,difn3,difn4,difn5,difn6,difn7,difn8,
			    difn9,difn10,difn11,
			    n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,
			    crap,rere2,lowzero,highzero},
             
	     max = 4000;
	     center = 2000;
         scale1  =  200;
		 scale2  =  100;
         scale3  =  1;
	     crap = Table[0, {m+1}];
         incr = Table[0, {7}];
         n0 = m+1;
         n1  = m;   n2 = m - 1; n3 = m - 2; n4 = m - 3; n5  = m - 4;
         n6  = m-5; n7 = m - 6; n8 = m - 7; n9 = m - 8; n10 = m - 9;
         n11 = m-10;

	     diff1 = diff2 = diff3 = diff4 = diff5 = 
         diff6 = diff7 = diff8 = diff9 = diff10= 
         diff11 = Table[0, {max}];
 		 difn1 = difn2 = difn3 = difn4 = difn5 = difn6 = difn7 =
         difn8 = difn9 = difn10= difn11 = Table[0, {max}];
         rere = ReadList["zs1000b"];
		 Do[ crap[[x]] = rere[[1]][[x]], {x,1,m+1}];
         t = Table[0, {m+2}];			
         Do[ t[[x]] = crap[[x]], {x,1,m}];    
		 Do[ Print[ t[[x]], {x,1,m} ] ];
         lowzero = t[[1]]; 
	    


  	     h1 = h2 = Table[0, {12}];

	     start = Round[ Abs[ crap[[m+1]] ] ];

	     Do[Print[ t[[x]], " "], {x,1,m}];	
         Print["here"];

	     kcheck = Table[0, {6}]; incr = Table[0, {6}];
	     kcheck[[1]] =   2000;   incr[[1]] = .1;
         kcheck[[2]] = 399999;   incr[[2]] = .015;
         kcheck[[3]] =1209999;   incr[[3]] = .001;
         kcheck[[4]] =1509999;   incr[[4]] = .0001;
         kcheck[[5]] =2599999;   incr[[5]] = .00001;
         kcheck[[6]] =2999999;   incr[[6]] = .00001;

	     Do[
            (
	         t1 = t[[m]] + .001;
	         z1 = RSZeta[t1];
             t2 = t1;
             z2 = z1;
       
             Do[
	          If[k < kcheck[[x]],
	           (
                tinc = incr[[x]];
                While[ z1 * z2 > 0,
	             (
		 	      t2 = t2 + tinc;
		 	      z2 = RSZeta[t2];
	             )   ];
	            t1 = t2 - tinc; t2 = t1;
                z1 = RSZeta[t1];
                z2 = z1;
               ), x = x], 
             {x,3,5} ];

	      t2 = t2 - .00005;
          t[[m+1]] = t2;
	      t1     = t2;
	      invave =  Log[t2/(2*3.141593)] / (2*3.141593) ; 


		h1[[1]] = t[[n0]] -   t[[n1]];
		h1[[2]] = t[[n0]] - 2*t[[n1]] +   t[[n2]];
		h1[[3]] = t[[n0]] - 3*t[[n1]] + 3*t[[n2]] -   t[[n3]];
		h1[[4]] = t[[n0]] - 4*t[[n1]] + 6*t[[n2]] - 4*t[[n3]] +  t[[n4]];
		h1[[5]] = t[[n0]] - 5*t[[n1]] +10*t[[n2]] -10*t[[n3]] +5*t[[n4]] - t[[n5]];

		h1[[6]] = t[[n0]] - 6*t[[n1]] + 15*t[[n2]] - 20*t[[n3]] + 15*t[[n4]]
                         - 6*t[[n5]] +    t[[n6]];
		
		h1[[7]] = t[[n0]] - 7*t[[n1]] + 21*t[[n2]] - 35*t[[n3]] + 35*t[[n4]]
						 -21*t[[n5]] +  7*t[[n6]] -    t[[n7]];

		h1[[8]] = t[[n0]] - 8*t[[n1]] + 28*t[[n2]] - 56*t[[n3]] + 70*t[[n4]]
						 -56*t[[n5]] + 28*t[[n6]] -  8*t[[n7]] +    t[[n8]];

		h1[[9]] = t[[n0]] - 9*t[[n1]] + 36*t[[n2]] - 84*t[[n3]] +126*t[[n4]]
						-126*t[[n5]] + 84*t[[n6]] - 36*t[[n7]] +  9*t[[n8]]
                         -   t[[n9]];

		h1[[10]]= t[[n0]] - 10*t[[n1]] + 45*t[[n2]] - 120*t[[n3]] + 210*t[[n4]]
                         -252*t[[n5]] +210*t[[n6]] - 120*t[[n7]] +  45*t[[n8]]
                         - 10*t[[n9]] +    t[[n10]];

		h1[[11]]= t[[n0]] - 11*t[[n1]] + 55*t[[n2]] - 165*t[[n3]] + 330*t[[n4]]
						 -462*t[[n5]] +462*t[[n6]] - 330*t[[n7]] + 165*t[[n8]]
                         - 55*t[[n9]] + 11*t[[n10]] -    t[[n11]];

	    Do[ h1[[x]] = h1[[x]]*scale1, {x,1,5} ];
		Do[ h1[[x]] = h1[[x]]*scale2, {x,6,11}];

		Do[ h2[[x]] = h1[[x]]*invave, {x,1,11}];
	 	
 		Do[ h1[[x]] = h1[[x]]*scale3, {x,1,11}];

		


		Do[ h1[[x]] = Round[ h1[[x]] + center], {x,2,11}];
		Do[ h2[[x]] = Round[ h2[[x]] + center], {x,2,11}];
	    h1[[1]] = Round[ h1[[1]] ];
	    h2[[1]] = Round[ h2[[1]] ];


	    Do[(
		    If[ h1[[x]] < 1,     h1[[x]] = 1,     x=x];
		    If[ h1[[x]] > max-1, h1[[x]] = max-1, x=x];
            If[ h2[[x]] < 1,     h2[[x]] = 1,     x=x];
		    If[ h2[[x]] > max-1, h2[[x]] = max-1, x=x];
           ), {x,1,11}];
		
		++diff1[[ h1[[1]] ]];
        ++diff2[[ h1[[2]] ]];
        ++diff3[[ h1[[3]] ]];
        ++diff4[[ h1[[4]] ]];
        ++diff5[[ h1[[5]] ]];
  		++diff6[[ h1[[6]] ]];
        ++diff7[[ h1[[7]] ]];
        ++diff8[[ h1[[8]] ]];
        ++diff9[[ h1[[9]] ]];
        ++diff10[[ h1[[10]] ]];
	    ++diff11[[ h1[[11]] ]];


  		++difn1[[ h2[[1]] ]];
        ++difn2[[ h2[[2]] ]];
        ++difn3[[ h2[[3]] ]];
        ++difn4[[ h2[[4]] ]];
        ++difn5[[ h2[[5]] ]];
  		++difn6[[ h2[[6]] ]];
        ++difn7[[ h2[[7]] ]];
        ++difn8[[ h2[[8]] ]];
        ++difn9[[ h2[[9]] ]];
        ++difn10[[ h2[[10]] ]];
	    ++difn11[[ h2[[11]] ]];
           
		Do[ t[[x]] = t[[x+1]], {x,1,12}];


       If[ Mod[k,1000] == 0,
		(

	  	 Print[k," ",t[[m+1]]," ",t[[m]], " ",t[[m-1]]," ", t[[m-2]]    ];
		 t[[6]] = k + 1;
         highzero = t[[m+1]];
         Put[diff1, diff2, diff3, diff4, diff5, diff6, diff7, diff8,
 			 diff9, diff10, diff11, k, lowzero, highzero, "zo1unnm"];	         
         Put[difn1, difn2, difn3, difn4, difn5, difn6, difn7, difn8, 
			 difn9, difn10, difn11, k, lowzero, highzero,t, "zo2norm"];	         

		If[ Mod[k,10000] == 0,
         (
	         Put[diff1, diff2, diff3, diff4, diff5, diff6, diff7, diff8,
 			     diff9, diff10, diff11, k, "zoz1orig"];	         
         	 Put[difn1, difn2, difn3, difn4, difn5, difn6, difn7, difn8, 
		 	     difn9, difn10, difn11, k,t, "zoz2norm"];	         
	     ), x = x];
		
        Print["   =>    SAVED <==> ", k];

       ), x = x];

     ), {k,start,start + n}];	


   ]

de = Table[0, {1000}];

mfirstfew[beginn_,lasthighzero_, m_] := Module[ {start,k,x,y,t,
				z1,z2,t1,t2,
                invave,center,scale,max,tinc,kcheck,incr,
				firstzeros,
			    crap,rere2},
             
	     max = 4000;
	     center = 2000;
         scale  =  200;
	     t = crap = Table[0, {12}];
         incr = Table[0, {7}];
 		 start = Round[beginn];

		 firstzeros = Table[0, {m+1}];
	     firstzeros[[1]] = lasthighzero;
             Print["here"];

	     kcheck = Table[0, {6}]; incr = Table[0, {6}];
	     kcheck[[1]] =   2000;   incr[[1]] = .1;
         kcheck[[2]] = 199999;   incr[[2]] = .025;
         kcheck[[3]] = 599999;   incr[[3]] = .01;
         kcheck[[4]] =1509999;   incr[[4]] = .001;
         kcheck[[5]] =2999999;   incr[[5]] = .0005;
         kcheck[[6]] =2999999;   incr[[6]] = .0001;
 
		 t1 = firstzeros[[1]];
      Do[
       (  

	   	       z1 = RSZeta[t1];
               t2 = t1+.001;
               z2 = RSZeta[t2];
               
               Do[
	            If[k < kcheck[[x]],
	            (
                 tinc = incr[[x]];
                 While[ z1 * z2 > 0,
 	              (
		 	       t2 = t2 + tinc;
		 	       z2 = RSZeta[t2];
	              )   ];
	             t1 = t2 - tinc; t2 = t1;
                 z1 = RSZeta[t1];
                 z2 = z1;
                ), x = x], 
             {x,1,6} ];

	      t2 = t2 - .00005;
               firstzeros[[k - start + 1]] = t2;
	      t1 = t2;
		  t1 = firstzeros[[k - start + 1]] + .0001;       
    ), {k,start,start + m - 1}];

		firstzeros[[m+1]] = start + m; 




         Do[ Print[firstzeros[[y]], " "], {y,1,m + 1}];	  	
		 Put[firstzeros, "zs1000b"];      
		 Print["   =>    S-A=V=E-D"];
      ]

Put[de,de,de,de,de, "ze2"];

Save["svz1000", RSZeta, mgetem, mfirstfew]