function [ R1,R2,R3,R4 ] = IONCO2( hei,xhi,it,F )
%IONCO2 ion concentration
%
%      Subroutine ionco2(hei,xhi,it,F,R1,R2,R3,R4)
%----------------------------------------------------------------
%     INPUT DATA :
%      hei  -  altitude in km
%      xhi  -  solar zenith angle in degree
%      it   -  seasonal month (Northern Hemisphere January 
%              is ismo=1 and so is Southern Hemisohere July)
%      F    -  10.7cm solar radio flux (12-month running mean)
%     OUTPUT DATA :
%     R1 -  NO+ concentration (in percent)
%     R2 -  O2+ concentration (in percent) 
%     R3 -  Cb+ concentration (in percent) 
%     R4 -  O+  concentration (in percent) 
%
%  A.D. Danilov and N.V. Smirnova, Improving the 75 to 300 km ion 
%  composition model of the IRI, Adv. Space Res. 15, #2, 171-177, 1995.
%
%-----------------------------------------------------------------

%      dimension j1ms70(7),j2ms70(7),h1s70(13,7),h2s70(13,7),
%     *       R1ms70(13,7),R2ms70(13,7),rk1ms70(13,7),rk2ms70(13,7),
%     *       j1ms140(7),j2ms140(7),h1s140(13,7),h2s140(13,7), 
%     *       R1ms140(13,7),R2ms140(13,7),rk1ms140(13,7),rk2ms140(13,7),
%     *       j1mw70(7),j2mw70(7),h1w70(13,7),h2w70(13,7),
%     *       R1mw70(13,7),R2mw70(13,7),rk1mw70(13,7),rk2mw70(13,7),
%     *       j1mw140(7),j2mw140(7),h1w140(13,7),h2w140(13,7), 
%     *       R1mw140(13,7),R2mw140(13,7),rk1mw140(13,7),rk2mw140(13,7),
%     *       j1mr70(7),j2mr70(7),h1r70(13,7),h2r70(13,7),
%     *       R1mr70(13,7),R2mr70(13,7),rk1mr70(13,7),rk2mr70(13,7),
%     *       j1mr140(7),j2mr140(7),h1r140(13,7),h2r140(13,7), 
%     *       R1mr140(13,7),R2mr140(13,7),rk1mr140(13,7),rk2mr140(13,7)
  persistent j1ms70 j2ms70 h1s70 h2s70 R1ms70 R2ms70 rk1ms70 rk2ms70 j1ms140 ...
    j2ms140 h1s140 h2s140 R1ms140 R2ms140 rk1ms140 rk2ms140 j1mr70 j2mr70 ...
    h1r70 h2r70 R1mr70 R2mr70 rk1mr70 rk2mr70 j1mr140 j2mr140 h1r140 h2r140 ...
    R1mr140 R2mr140 rk1mr140 rk2mr140 j1mw70 j2mw70 h1w70 h2w70 R1mw70 R2mw70 ...
    rk1mw70 rk2mw70 j1mw140 j2mw140 h1w140 h2w140 R1mw140 R2mw140 rk1mw140 ...
    rk2mw140;
  if isempty(j1ms70)
    j1ms70 = [11,11,10,10,11,9,11];
    j2ms70 = [13,11,10,11,11,9,11];
    h1s70 = transpose([75,85,90,95,100,120,130,200,220,250,270,0,0; ...
             75,85,90,95,100,120,130,200,220,250,270,0,0;  ...
             75,85,90,95,100,115,200,220,250,270,0,0,0; ...
             75,80,95,100,120,140,200,220,250,270,0,0,0; ...
             75,80,95,100,120,150,170,200,220,250,270,0,0; ...
             75,80,95,100,140,200,220,250,270,0,0,0,0; ...
             75,80,85,95,100,110,145,200,220,250,270,0,0]);
    h2s70 = transpose([75,80,90,95,100,120,130,140,150,200,220,250,270; ...
             75,80,90,95,100,120,130,200,220,250,270,0,0;  ...
             75,80,90,95,100,115,200,220,250,270,0,0,0; ...
             75,80,95,100,120,140,150,200,220,250,270,0,0; ...
             75,80,95,100,120,150,170,200,220,250,270,0,0; ...
             75,80,95,100,140,200,220,250,270,0,0,0,0; ...
             75,80,90,95,100,110,145,200,220,250,270,0,0]);
    R1ms70 = transpose([6,30,60,63,59,59,66,52,20,4,2,0,0; ...
              6,30,60,63,69,62,66,52,20,4,2,0,0;  ...
              6,30,60,63,80,68,53,20,4,2,0,0,0; ...
              4,10,60,85,65,65,52,25,12,4,0,0,0;  ...
              4,10,60,89,72,60,60,52,30,20,10,0,0;  ...
              4,10,60,92,68,54,40,25,13,0,0,0,0;  ...
              1,8,20,60,95,93,69,65,45,30,20,0,0]); 
    R2ms70 = transpose([4,10,30,32,41,41,32,29,34,28,15,3,1; ...
              4,10,30,32,31,38,32,28,15,3,1,0,0; ...
              4,10,30,32,20,32,28,15,3,1,0,0,0; ...
              2,6,30,15,35,30,34,26,19,8,3,0,0; ...
              2,6,30,11,28,38,29,29,25,12,5,0,0; ...
              2,6,30,8,32,30,20,14,8,0,0,0,0; ...
              1,2,10,20,5,7,31,23,18,15,10,0,0]); 
    rk1ms70 = transpose([2.4,6.,.6,-.8,0,.7,-.2,-1.6,-.533,-.1,-.067,0,0; ...
              2.4,6.,.6,1.2,-.35,.4,-.2,-1.6,-.533,-.1,-.067,0,0; ...
              2.4,6.,.6,3.4,-.8,-.176,-1.65,-.533,-.1,-.067,0,0,0; ...
              1.2,3.333,5.,-1.,0,-.216,-1.35,-.433,-.4,-.1,0,0,0; ...
              1.2,3.333,5.8,-.85,-.4,0,-.267,-1.1,-.333,-.4,-.2,0,0; ...
              1.2,3.333,6.4,-.6,-.233,-.7,-.5,-.6,-.267,0,0,0,0; ...
              1.4,2.4,4.,7.,-.2,-.686,-.072,-1.,-.5,-.5,-.5,0,0]);
    rk2ms70 = transpose([1.2,2.,.4,1.8,0,-.9,-.3,.5,-.12,-.65,-.4,-.1,-.033; ...
              1.2,2.,.4,-.2,.35,-.6,-.057,-.65,-.4,-.1,-.033,0,0; ...
              1.2,2.,.4,-2.4,.8,-.047,-.65,-.4,-.1,-.033,0,0,0; ...
              .8,1.6,-3.,1.,-.25,.4,-.16,-.35,-.367,-.25,-.1,0,0; ...
              .8,1.6,-3.8,.85,.333,-.45,0,-.2,-.433,-.35,-.1,0,0; ...
              .8,1.6,-4.4,.6,-.033,-.5,-.2,-.3,-.2,0,0,0,0; ...
              .2,.8,2.,-3.,.2,.686,-.145,-.25,-.1,-.25,-.2,0,0]);
    j1ms140 = [11,11,10,10,9,9,12]; 
    j2ms140 = [11,11,10,9,10,10,12];
    h1s140 = transpose([75,85,90,95,100,120,130,140,200,220,250,0,0; ...
             75,85,90,95,100,120,130,140,200,220,250,0,0; ...
             75,85,90,95,100,120,140,200,220,250,0,0,0; ...
             75,80,95,100,120,140,200,220,250,270,0,0,0; ...
             75,80,95,100,120,200,220,250,270,0,0,0,0; ...
             75,80,95,100,130,200,220,250,270,0,0,0,0; ...
             75,80,85,95,100,110,140,180,200,220,250,270,0]);
    h2s140 = transpose([75,80,90,95,100,120,130,155,200,220,250,0,0; ...
             75,80,90,95,100,120,130,160,200,220,250,0,0; ...
             75,80,90,95,100,120,165,200,220,250,0,0,0; ...
             75,80,95,100,120,180,200,250,270,0,0,0,0; ...
             75,80,95,100,120,160,200,220,250,270,0,0,0; ...
             75,80,95,100,130,160,200,220,250,270,0,0,0; ...
             75,80,90,95,100,110,140,180,200,220,250,270,0]);
    R1ms140 = transpose([6,30,60,63,59,59,66,66,38,14,1,0,0; ...
              6,30,60,63,69,62,66,66,38,14,1,0,0; ...
              6,30,60,63,80,65,65,38,14,1,0,0,0; ...
              4,10,60,85,66,66,38,22,9,1,0,0,0; ...
              4,10,60,89,71,42,26,17,10,0,0,0,0; ...
              4,10,60,93,71,48,35,22,10,0,0,0,0; ...
              1,8,20,60,95,93,72,60,58,40,26,13,0]); 
    R2ms140 = transpose([4,10,30,32,41,41,30,30,10,6,1,0,0; ...
              4,10,30,32,31,38,31,29,9,6,1,0,0; ...
              4,10,30,32,20,35,26,9,6,1,0,0,0; ...
              2,6,30,15,34,24,10,5,1,0,0,0,0; ...
              2,6,30,11,28,37,21,14,8,5,0,0,0; ...
              2,6,30,7,29,36,29,20,13,5,0,0,0; ...
              1,2,10,20,5,7,28,32,28,20,14,7,0]); 
    rk1ms140 = transpose([2.4,6.,.6,-.8,0,.7,0,-.467,-1.2,-.433,0,0,0; ...
              2.4,6.,.6,1.2,-.35,.4,0,-.467,-1.2,-.433,0,0,0; ... 
              2.4,6.,.6,3.4,-.75,0,-.45,-1.2,-.433,0,0,0,0; ...
              1.2,3.333,5.,-.95,0,-.467,-.8,-.433,-.4,0,0,0,0; ...
              1.2,3.333,5.8,-.9,-.363,-.8,-.3,-.35,-.3,0,0,0,0; ...
              1.2,3.333,6.6,-.733,-.329,-.65,-.433,-.6,-.267,0,0,0,0; ...
              1.4,2.4,4.,7.,-.2,-.7,-.3,-.1,-.9,-.467,-.65,-.333,0]);
    rk2ms140 = transpose([1.2,2.,.4,1.8,0,-1.1,0,-.444,-.2,-.166,0,0,0; ...
              1.2,2.,.4,-.2,.35,-.7,-.067,-.5,-.15,-.166,0,0,0; ...
              1.2,2.,.4,-2.4,.75,-.2,-.486,-.15,-.166,0,0,0,0; ...
              .8,1.6,-3.,.95,-.167,-.7,-.1,-.2,0,0,0,0,0; ...
              .8,1.6,-3.8,.85,.225,-.4,-.35,-.2,-.15,-.133,0,0,0; ...
              .8,1.6,-4.6,.733,.233,-.175,-.45,-.233,-.4,-.1,0,0,0; ...
              .2,.8,2.,-3.,.2,.7,.1,-.2,-.4,-.2,-.35,-.167,0]);
    j1mr70 = [12,12,12,9,10,11,13]; 
    j2mr70 = [9,9,10,13,12,11,11];
    h1r70 = transpose([75,80,90,95,100,120,140,180,200,220,250,270,0; ...
             75,80,90,95,100,120,145,180,200,220,250,270,0; ...
             75,80,90,95,100,120,145,180,200,220,250,270,0; ...
             75,95,100,110,140,180,200,250,270,0,0,0,0; ...
             75,95,125,150,185,195,200,220,250,270,0,0,0; ...
             75,95,100,150,160,170,190,200,220,250,270,0,0; ...
             75,80,85,95,100,140,160,170,190,200,220,250,270]);
    h2r70 = transpose([75,95,100,120,180,200,220,250,270,0,0,0,0; ...
             75,95,100,120,180,200,220,250,270,0,0,0,0; ...
             75,95,100,120,130,190,200,220,250,270,0,0,0; ...
             75,80,85,95,100,110,130,180,190,200,220,250,270; ...
             75,80,85,95,100,125,150,190,200,220,250,270,0; ...
             75,80,85,95,100,150,190,200,220,250,270,0,0; ...
             75,85,95,100,140,180,190,200,220,250,270,0,0]);
    R1mr70 = transpose([13,17,57,57,30,53,58,38,33,14,6,2,0; ...
              13,17,57,57,37,56,56,38,33,14,6,2,0; ...
              13,17,57,57,47,58,55,37,33,14,6,2,0; ...
              5,65,54,58,58,38,33,9,1,0,0,0,0; ...
              5,65,65,54,40,40,45,26,17,10,0,0,0; ...  
              5,65,76,56,57,48,44,51,35,22,10,0,0; ...
              3,11,35,75,90,65,63,54,54,50,40,26,13]); 
    R2mr70 = transpose([7,43,70,47,15,17,10,4,0,0,0,0,0; ...
              7,43,63,44,17,17,10,4,0,0,0,0,0; ...
              7,43,53,42,42,13,17,10,4,0,0,0,0; ...
              3,5,26,34,46,42,41,23,16,16,10,1,0; ...
              3,5,26,34,35,35,42,25,22,14,8,5,0; ...
              3,5,26,34,24,41,31,26,20,13,5,0,0; ...
              3,15,15,10,35,35,30,34,20,14,7,0,0]); 
    rk1mr70 = transpose([.8,4.,0,-5.4,1.15,.25,-.5,-.25,-.95,-.267,-.2, ...
                  -.067,0; ...
              .8,4.,0,-4.,.95,0,-.514,-.25,-.95,-.267,-.2,-.067,0; ...
              .8,4.,0,-2.,.55,-.12,-.514,-.2,-.95,-.267,-.2,-.067,0; ...
              3.,-2.2,.4,0,-.5,-.25,-.48,-.4,-.033,0,0,0,0; ...
              3.,0,-.44,-.466,0,1.0,-.95,-.3,-.35,-.3,0,0,0; ...
              3.,2.2,-.4,0.1,-.9,-.2,.7,-.8,-.433,-.6,-.267,0,0; ...
              1.6,4.8,4.,3.,-.625,-.1,-.9,0,-.4,-.5,-.467,-.65,-.3]);
    rk2mr70 = transpose([1.8,5.4,-1.15,-.533,.1,-.35,-.2,-.2,0,0,0,0,0; ...
              1.8,4.,-.95,-.45,0,-.35,-.2,-.2,0,0,0,0,0; ...
              1.8,2.,-.55,0,-.483,.4,-.35,-.2,-.2,0,0,0,0; ...  
              .4,4.2,.8,2.4,-.4,-.05,-.36,-.7,0,-.3,-.3,-.05,0; ...
              .4,4.2,.8,.2,0,.28,-.425,-.3,-.4,-.2,-.15,-.133,0; ...
              .4,4.2,.8,-2.,.34,-.25,-.5,-.3,-.233,-.4,-.1,0,0; ...
              1.2,0,-1.,.625,0,-.5,.4,-.7,-.2,-.35,-.167,0,0]);
    j1mr140 = [12,12,11,12,9,9,13]; 
    j2mr140 = [10,9,10,12,13,13,12];
    h1r140 = transpose([75,80,90,95,100,115,130,145,200,220,250,270,0; ...
             75,80,90,95,100,110,120,145,200,220,250,270,0; ...
             75,80,90,95,100,115,150,200,220,250,270,0,0; ...
             75,95,100,120,130,140,150,190,200,220,250,270,0; ...
             75,95,120,150,190,200,220,250,270,0,0,0,0; ...
             75,95,100,145,190,200,220,250,270,0,0,0,0; ...
             75,80,85,95,100,120,160,170,190,200,220,250,270]);
    h2r140 = transpose([75,95,100,115,130,175,200,220,250,270,0,0,0; ...
             75,95,100,110,175,200,220,250,270,0,0,0,0; ...
             75,95,100,115,130,180,200,220,250,270,0,0,0; ...
             75,80,85,95,100,120,130,190,200,220,250,270,0; ...
             75,80,85,95,100,120,140,160,190,200,220,250,270; ...
             75,80,85,95,100,145,165,180,190,200,220,250,270; ...
             75,85,95,100,120,145,170,190,200,220,250,270,0]);
    R1mr140 = transpose([13,17,57,57,28,51,56,56,12,8,1,0,0; ...
              13,17,57,57,36,46,55,56,10,8,1,0,0; ...
              13,17,57,57,46,56,55,12,8,1,0,0,0; ...
              5,65,54,59,56,56,53,23,16,13,3,1,0; ...
              5,65,65,54,29,16,16,10,2,0,0,0,0; ...
              5,65,76,58,36,25,20,12,7,0,0,0,0; ...
              3,11,35,75,91,76,58,49,45,32,28,20,12]); 
    R2mr140 = transpose([7,43,72,49,44,14,7,4,1,0,0,0,0; ...
              7,43,64,51,14,7,4,1,0,0,0,0,0; ...
              7,43,54,44,44,13,7,4,1,0,0,0,0; ...
              3,5,26,34,46,41,44,9,11,7,2,1,0; ...
              3,5,26,34,35,35,40,40,16,14,9,5,2; ...
              3,5,26,34,24,40,40,32,19,20,10,7,3; ...
              3,15,15,9,24,35,40,28,28,20,10,8,0]); 
    rk1mr140 = transpose([.8,4.,0,-5.8,1.533,.333,0,-.8,-.2,-.233,-.05,0,0; ...
              .8,4.,0,-4.2,1.3,.6,.04,-.836,-.1,-.233,-.05,0,0; ...
              .8,4.,0,-2.2,.667,-.029,-.86,-.2,-.233,-.05,0,0,0; ...      
              3.,-2.2,.25,-.3,0,-.3,-.75,-.7,-.15,-.333,-.1,-.033,0; ...
              3.,0,-.367,-.625,-1.3,0,-.2,-.4,-.067,0,0,0,0; ...
              3.,2.2,-.4,-.489,-1.1,-.25,-.267,-.25,-.2,0,0,0,0; ...
              1.6,4.8,4.,3.2,-.75,-.45,-.9,-.2,-1.3,-.2,-.267,-.4,-.3]);
    rk2mr140 = transpose([1.8,5.8,-1.533,-.333,-.667,-.28,-.15,-.1,-.05, ...
                   0,0,0,0; ...
              1.8,4.2,-1.3,-.569,-.28,-.15,-.1,-.05,0,0,0,0,0; ...
              1.8,2.2,-.667,0,-.62,-.3,-.15,-.1,-.05,0,0,0,0; ...
              .4,4.2,.8,2.4,-.25,.3,-.583,.2,-.2,-.167,-.05,-.033,0; ...
              .4,4.2,.8,.02,0,.25,0,-.6,-.2,-.25,-.133,-.15,-.067; ...
              .4,4.2,.8,-2.,.356,0,-.533,-1.3,.1,-.5,-.1,-.2,-.1; ...
              1.2,0,-1.2,.75,.44,.2,-.6,0,-.4,-.333,-.1,-.2,0]);
    j1mw70 = [13,13,13,13,9,8,9];
    j2mw70 = [10,10,11,11,9,8,11];
    h1w70 = transpose([75,80,85,95,100,110,125,145,180,200,220,250,270; ...
             75,80,85,95,100,110,120,150,180,200,220,250,270; ...
             75,80,85,95,100,110,120,155,180,200,220,250,270; ...
             75,80,90,100,110,120,140,160,190,200,220,250,270; ...
             75,80,90,110,150,200,220,250,270,0,0,0,0; ...
             75,80,90,100,150,200,250,270,0,0,0,0,0; ...
             75,80,90,100,120,130,140,200,270,0,0,0,0]);
    h2w70 = transpose([75,90,95,100,110,125,190,200,250,270,0,0,0; ...
             75,90,95,100,110,125,190,200,250,270,0,0,0; ...
             75,90,95,100,110,120,145,190,200,250,270,0,0; ...
             75,80,95,100,110,120,150,200,220,250,270,0,0; ...
             75,80,90,95,110,145,200,250,270,0,0,0,0; ...
             75,80,90,100,140,150,200,250,0,0,0,0,0; ...
             75,80,85,90,100,120,130,140,160,200,270,0,0]); 
    R1mw70 = transpose([28,35,65,65,28,44,46,50,25,25,10,5,0; ...
              28,35,65,65,36,49,47,47,25,25,10,5,0; ...
              28,35,65,65,48,54,51,43,25,25,10,5,0; ...
              16,24,66,54,58,50,50,38,25,25,10,5,0; ...
              16,24,66,66,46,30,20,6,3,0,0,0,0; ...
              16,24,66,76,49,32,12,7,0,0,0,0,0; ...
              6,19,67,91,64,68,60,40,12,0,0,0,0]); 
    R2mw70 = transpose([5,35,35,72,56,54,12,12,2,0,0,0,0; ...
              5,35,35,64,51,53,12,12,2,0,0,0,0; ...
              5,35,35,52,46,49,41,12,12,2,0,0,0; ...
              4,10,40,46,42,50,41,12,7,2,0,0,0; ...
              4,10,30,34,34,51,14,4,2,0,0,0,0; ...
              4,10,30,24,45,48,20,5,0,0,0,0,0; ...
              2,6,17,23,9,36,32,40,40,20,6,0,0]); 
    rk1mw70 = transpose([1.4,6.,0,-7.4,1.6,.133,.2,-.714,0,-.75,-.167,-.25,0; ...
              1.4,6.,0,-5.8,1.3,-.2,0,-.733,0,-.75,-.167,-.25,0; ...
              1.4,6.,0,-3.4,.6,-.3,-.229,-.72,0,-.75,-.167,-.25,0; ...
              1.6,4.2,-1.2,.4,-.8,0,-.6,-.433,0,-.75,-.167,-.25,0; ...
              1.6,4.2,0,-.5,-.32,-.5,-.467,-.15,-.1,0,0,0,0; ...
              1.6,4.2,1.,-.54,-.34,-.4,-.25,-.2,0,0,0,0,0; ...
              2.6,4.8,2.4,-1.35,.4,-.8,-.333,-.4,-.3,0,0,0,0]);
    rk2mw70 = transpose([2.,0,7.4,-1.6,-.133,-.646,0,-.2,-.1,0,0,0,0; ...
              2.,0,5.8,-1.3,.133,-.631,0,-.2,-.1,0,0,0,0; ...
              2.,0,3.4,-.6,.3,-.32,-.644,0,-.2,-.1,0,0,0; ...
              1.2,2.,1.2,-.4,.8,-.3,-.58,-.25,-.167,-.1,0,0,0; ...
              1.2,2.,.8,0,.486,-.673,-.2,-.1,-.066,0,0,0,0; ...
              1.2,2.,-.6,.525,.3,-.56,-.3,-.1,0,0,0,0,0; ...
              .8,2.2,1.2,-1.4,1.35,-.4,.8,0,-.5,-.2,-.167,0,0]);
    j1mw140 = [12,11,11,11,11,10,12];
    j2mw140 = [10,11,11,11,11,10,12];
    h1w140 = transpose([75,80,85,95,100,110,125,145,190,200,220,250,0; ...
             75,80,85,95,100,110,120,150,190,220,250,0,0; ...
             75,80,85,95,100,110,120,155,190,220,250,0,0; ...
             75,80,90,100,110,120,140,160,190,220,250,0,0; ...
             75,80,90,110,150,160,190,200,220,250,270,0,0; ...
             75,80,90,100,150,160,190,200,250,270,0,0,0; ...
             75,80,90,100,120,130,140,160,190,200,250,270,0]);
    h2w140 = transpose([75,90,95,100,110,125,190,200,220,250,0,0,0; ...
             75,90,95,100,110,120,125,190,200,220,250,0,0; ...
             75,90,95,100,110,120,145,190,200,220,250,0,0; ...
             75,80,95,100,110,120,150,190,200,220,250,0,0; ...
             75,80,90,95,110,145,190,200,220,250,270,0,0; ...
             75,80,90,100,140,150,200,220,250,270,0,0,0; ...
             75,80,85,90,100,120,130,140,160,180,200,220,0]); 
    R1mw140 = transpose([28,35,65,65,28,44,46,50,9,6,2,0,0; ...
              28,35,65,65,36,49,47,47,8,2,0,0,0; ...
              28,35,65,65,48,54,51,43,8,2,0,0,0; ...
              16,24,66,54,58,50,50,42,8,2,0,0,0; ...
              16,24,66,66,46,49,9,10,7,2,0,0,0; ...
              16,24,66,76,49,54,10,14,4,1,0,0,0; ...
              6,19,67,91,64,68,60,58,11,20,5,2,0]); 
    R2mw140 = transpose([5,35,35,72,56,54,5,5,1,0,0,0,0; ...
              5,35,35,64,51,53,53,5,5,1,0,0,0; ...
              5,35,35,52,46,49,41,5,5,1,0,0,0; ...
              4,10,40,46,42,50,41,5,5,1,0,0,0; ...
              4,10,30,34,34,51,10,5,3,1,0,0,0; ...
              4,10,30,24,45,48,4,2,1,0,0,0,0; ...
              2,6,17,23,9,36,32,40,39,29,1,0,0]); 
    rk1mw140 = transpose([1.4,6.,0,-7.4,1.6,.133,.2,-.911,-.3,-.2,-.066,0,0; ...
              1.4,6.,0,-5.8,1.3,-.2,0,-.975,-.2,-.066,0,0,0; ...
              1.4,6.,0,-3.4,.6,-.3,-.229,-1.,-.2,-.066,0,0,0; ...
              1.6,4.2,-1.2,.4,-.8,0,-.4,-1.133,-.2,-.066,0,0,0; ...
              1.6,4.2,0,-.5,.3,-1.133,.1,-.15,-.166,-.1,0,0,0; ...
              1.6,4.2,1.,-.54,.5,-1.466,.4,-.2,-.15,-.0333,0,0,0; ...
              2.6,4.8,2.4,-1.35,.4,-.8,-.1,-1.566,.9,-.3,-.15,-.05,0]);
    rk2mw140 = transpose([2.,0,7.4,-1.6,-.133,-.754,0,-.2,-.033,0,0,0,0; ...
              2.,0,5.8,-1.3,.2,0,-.738,0,-.2,-.033,0,0,0; ...
              2.,0,3.4,-.6,.3,-.32,-.8,0,-.2,-.033,0,0,0; ...
              1.2,2.,1.2,-.4,.8,-.3,-.9,0,-.2,-.033,0,0,0; ...
              1.2,2.,.8,0,.486,-.911,-.5,-.1,-.066,-.05,0,0,0; ...
              1.2,2.,-.6,.525,.3,-.88,-.1,-.033,-.05,0,0,0,0; ...
              .8,2.2,1.2,-1.4,1.35,-.4,.8,-.05,-.5,-1.4,-.05,0,0]);
  end
  h = hei;
  z = xhi;
  F0 = 70.0;
  F1 = 140.0;

  if z < 20
    z=20;
  elseif z > 90
    z=90;
  end
  it = floor(it);
  if (it == 1) || (it == 2) || (it == 11) || (it == 12)
    if F < F1
      [R1,R2] = IRI2012.APROK(j1mw70,j2mw70,h1w70,h2w70,R1mw70,R2mw70, ...
                rk1mw70,rk2mw70,h,z);
      R170=R1;
      R270=R2;
    end
    if F > F0
      [R1,R2] = IRI2012.APROK(j1mw140,j2mw140,h1w140,h2w140,R1mw140,R2mw140, ...
                rk1mw140,rk2mw140,h,z);
      R1140=R1;
      R2140=R2;
    end
    if (F > F0) && (F < F1)
      R1=R170+(R1140-R170)*(F-F0)/F0;
      R2=R270+(R2140-R270)*(F-F0)/F0;
    end
  elseif (it == 5) || (it == 6) || (it == 7) || (it == 8)
    if F < F1
      [R1,R2] = IRI2012.APROK(j1ms70,j2ms70,h1s70,h2s70,R1ms70,R2ms70, ...
                rk1ms70,rk2ms70,h,z);
      R170=R1;
      R270=R2;
    end
    if F > F0
      [R1,R2] = IRI2012.APROK(j1ms140,j2ms140,h1s140,h2s140,R1ms140,R2ms140, ...
                rk1ms140,rk2ms140,h,z);
      R1140=R1;
      R2140=R2;
    end
    if (F > F0) && (F < F1)
      R1=R170+(R1140-R170)*(F-F0)/F0;
      R2=R270+(R2140-R270)*(F-F0)/F0;
    end
  else %if (it == 3) || (it == 4) || (it == 9) || (it == 10)
    if F < F1
      [R1,R2] = IRI2012.APROK(j1mr70,j2mr70,h1r70,h2r70,R1mr70,R2mr70, ...
                rk1mr70,rk2mr70,h,z);
      R170=R1;
      R270=R2;
    end
    if F > F0
      [R1,R2] = IRI2012.APROK(j1mr140,j2mr140,h1r140,h2r140,R1mr140,R2mr140, ...
                rk1mr140,rk2mr140,h,z);
      R1140=R1;
      R2140=R2;
    end
    if (F > F0) && (F < F1)
      R1=R170+(R1140-R170)*(F-F0)/F0;
      R2=R270+(R2140-R270)*(F-F0)/F0;
    end
  end
  if h < 100
    R3=100-(R1+R2);
  else
    R3=0;
  end
  if h >= 100
    R4=100-(R1+R2);
  else
    R4=0;
  end
  if R3 < 0
    R3=0;
  end
  if R4 < 0
    R4=0;
  end
  R1=floor(R1+0.5);
  R2=floor(R2+0.5);
  R3=floor(R3+0.5);
  R4=floor(R4+0.5);

end

