/*************************************
*                                    *
*    外枠システム  setjinko.c        *
*  （人口設定）                      *
*                                    *
*************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "set.h"
#include "cntl.h"


void setjinko(void) {

/*  変数定義  */
int  TMP ;



/*  年央人口106歳以上を105歳に落とし込み */
  for ( nendo=STARTY+1; nendo<=KE+1; nendo++ ) {
    for ( sei=1; sei<=2; sei++ ) {
      for ( nenrei=106; nenrei<=120; nenrei++ ) {
        if ( jinko_c[nendo-STARTY][sei][nenrei] > 0.0 ) {
            jinko_c[nendo-STARTY][sei][105] += jinko_c[nendo-STARTY][sei][nenrei] ;
            jinko_c[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
        if ( stk_jinko_c[nendo-STARTY][sei][nenrei] > 0.0 ) {
            stk_jinko_c[nendo-STARTY][sei][105] += stk_jinko_c[nendo-STARTY][sei][nenrei] ;
            stk_jinko_c[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
        if ( str_jinko_c[nendo-STARTY][sei][nenrei] > 0.0 ) {
            str_jinko_c[nendo-STARTY][sei][105] += str_jinko_c[nendo-STARTY][sei][nenrei] ;
            str_jinko_c[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
        if ( sts_jinko_c[nendo-STARTY][sei][nenrei] > 0.0 ) {
            sts_jinko_c[nendo-STARTY][sei][105] += sts_jinko_c[nendo-STARTY][sei][nenrei] ;
            sts_jinko_c[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
      }
    }
  }



/*  年央人口→年度末人口の作成  */

  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    for ( nenrei=0; nenrei<=105; nenrei++) {
      for ( sei=1; sei<=2; sei++){
         if ( nenrei+SJINKOY-nendo > 0 ) {  /*  SJINKOY 年時点で既に生まれている世代なら */
             TMP = 0;
             TMP = nenrei + SJINKOY - nendo; /*  SJINKOY 年時点年齢  */
             if ( TMP < 106 ) {
               if (( nenrei > 0 ) && ( nenrei < 105 )) {
                   jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][TMP] ) / 2.0;
                   stk_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( stk_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + stk_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + stk_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + stk_jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][TMP] ) / 2.0;
                   str_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( str_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + str_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + str_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + str_jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][TMP] ) / 2.0;
                   sts_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( sts_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + sts_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + sts_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + sts_jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][TMP] ) / 2.0;
               }
               else if ( nenrei==0 ) {     
                   jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( jinko_c[nendo-STARTY][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP] )
                     + jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][TMP] ) / 2.0;
                   stk_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( stk_jinko_c[nendo-STARTY][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP] )
                     + stk_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + stk_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + stk_jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][TMP] ) / 2.0;
                   str_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( str_jinko_c[nendo-STARTY][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP] )
                     + str_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + str_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + str_jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][TMP] ) / 2.0;
                   sts_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( sts_jinko_c[nendo-STARTY][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP] )
                     + sts_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + sts_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + sts_jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][TMP] ) / 2.0;
               }
               else if ( nenrei==105 ) {     
                   jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + jinko_c[nendo-STARTY+1][sei][nenrei] * jinko_wari[sei][TMP-1] ) / 2.0;
                   stk_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( stk_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + stk_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + stk_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + stk_jinko_c[nendo-STARTY+1][sei][nenrei] * jinko_wari[sei][TMP-1] ) / 2.0;
                   str_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( str_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + str_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + str_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + str_jinko_c[nendo-STARTY+1][sei][nenrei] * jinko_wari[sei][TMP-1] ) / 2.0;
                   sts_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( sts_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + sts_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][TMP] 
                     + sts_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][TMP-1] )
                     + sts_jinko_c[nendo-STARTY+1][sei][nenrei] * jinko_wari[sei][TMP-1] ) / 2.0;
               }
             }
             else { /* TMP>105 のときの特別処理、TMP=105とみなす */
               if (( nenrei > 0 ) && ( nenrei < 105 )) {
                   jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][105] )
                     + jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][105] 
                     + jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][105] )
                     + jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][105] ) / 2.0;
                   stk_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( stk_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][105] )
                     + stk_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][105] 
                     + stk_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][105] )
                     + stk_jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][105] ) / 2.0;
                   str_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( str_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][105] )
                     + str_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][105] 
                     + str_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][105] )
                     + str_jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][105] ) / 2.0;
                   sts_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( sts_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][105] )
                     + sts_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][105] 
                     + sts_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][105] )
                     + sts_jinko_c[nendo-STARTY+1][sei][nenrei+1] * jinko_wari[sei][105] ) / 2.0;
               }
               else if ( nenrei==105 ) {     
                   jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][105] )
                     + jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][105] 
                     + jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][105] )
                     + jinko_c[nendo-STARTY+1][sei][nenrei] * jinko_wari[sei][105] ) / 2.0;
                   stk_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( stk_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][105] )
                     + stk_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][105] 
                     + stk_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][105] )
                     + stk_jinko_c[nendo-STARTY+1][sei][nenrei] * jinko_wari[sei][105] ) / 2.0;
                   str_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( str_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][105] )
                     + str_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][105] 
                     + str_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][105] )
                     + str_jinko_c[nendo-STARTY+1][sei][nenrei] * jinko_wari[sei][105] ) / 2.0;
                   sts_jinko_m[nendo-STARTY][sei][nenrei] = 
                     ( sts_jinko_c[nendo-STARTY][sei][nenrei-1] * ( 1.0 - jinko_wari[sei][105] )
                     + sts_jinko_c[nendo-STARTY][sei][nenrei] * jinko_wari[sei][105] 
                     + sts_jinko_c[nendo-STARTY+1][sei][nenrei] * ( 1.0 - jinko_wari[sei][105] )
                     + sts_jinko_c[nendo-STARTY+1][sei][nenrei] * jinko_wari[sei][105] ) / 2.0;
               }
             }

         }
         else { /*  SJINKOY 年時点でまだ生まれていない世代なら */
             if (( nenrei > 0 ) && ( nenrei < 105 )) {
                 jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( jinko_c[nendo-STARTY][sei][nenrei-1] 
                   + jinko_c[nendo-STARTY][sei][nenrei] 
                   + jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + jinko_c[nendo-STARTY+1][sei][nenrei+1] ) / 4.0;
                 stk_jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( stk_jinko_c[nendo-STARTY][sei][nenrei-1] 
                   + stk_jinko_c[nendo-STARTY][sei][nenrei] 
                   + stk_jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + stk_jinko_c[nendo-STARTY+1][sei][nenrei+1] ) / 4.0;
                 str_jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( str_jinko_c[nendo-STARTY][sei][nenrei-1] 
                   + str_jinko_c[nendo-STARTY][sei][nenrei] 
                   + str_jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + str_jinko_c[nendo-STARTY+1][sei][nenrei+1] ) / 4.0;
                 sts_jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( sts_jinko_c[nendo-STARTY][sei][nenrei-1] 
                   + sts_jinko_c[nendo-STARTY][sei][nenrei] 
                   + sts_jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + sts_jinko_c[nendo-STARTY+1][sei][nenrei+1] ) / 4.0;
             }
             else if ( nenrei==0 ) {     
                 jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( jinko_c[nendo-STARTY][sei][nenrei] 
                   + jinko_c[nendo-STARTY][sei][nenrei] 
                   + jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + jinko_c[nendo-STARTY+1][sei][nenrei+1] ) / 4.0;
                 stk_jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( stk_jinko_c[nendo-STARTY][sei][nenrei] 
                   + stk_jinko_c[nendo-STARTY][sei][nenrei] 
                   + stk_jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + stk_jinko_c[nendo-STARTY+1][sei][nenrei+1] ) / 4.0;
                 str_jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( str_jinko_c[nendo-STARTY][sei][nenrei] 
                   + str_jinko_c[nendo-STARTY][sei][nenrei] 
                   + str_jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + str_jinko_c[nendo-STARTY+1][sei][nenrei+1] ) / 4.0;
                 sts_jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( sts_jinko_c[nendo-STARTY][sei][nenrei] 
                   + sts_jinko_c[nendo-STARTY][sei][nenrei] 
                   + sts_jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + sts_jinko_c[nendo-STARTY+1][sei][nenrei+1] ) / 4.0;
             }
             else if ( nenrei==105 ) {     
                 jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( jinko_c[nendo-STARTY][sei][nenrei-1] 
                   + jinko_c[nendo-STARTY][sei][nenrei] 
                   + jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + jinko_c[nendo-STARTY+1][sei][nenrei] ) / 4.0;
                 stk_jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( stk_jinko_c[nendo-STARTY][sei][nenrei-1] 
                   + stk_jinko_c[nendo-STARTY][sei][nenrei] 
                   + stk_jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + stk_jinko_c[nendo-STARTY+1][sei][nenrei] ) / 4.0;
                 str_jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( str_jinko_c[nendo-STARTY][sei][nenrei-1] 
                   + str_jinko_c[nendo-STARTY][sei][nenrei] 
                   + str_jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + str_jinko_c[nendo-STARTY+1][sei][nenrei] ) / 4.0;
                 sts_jinko_m[nendo-STARTY][sei][nenrei] = 
                   ( sts_jinko_c[nendo-STARTY][sei][nenrei-1] 
                   + sts_jinko_c[nendo-STARTY][sei][nenrei] 
                   + sts_jinko_c[nendo-STARTY+1][sei][nenrei] 
                   + sts_jinko_c[nendo-STARTY+1][sei][nenrei] ) / 4.0;
             }
         }
         /* 男女計 */
         jinko_c[nendo-STARTY][0][nenrei]
           = jinko_c[nendo-STARTY][1][nenrei] + jinko_c[nendo-STARTY][2][nenrei] ; 
         jinko_m[nendo-STARTY][0][nenrei]
           = jinko_m[nendo-STARTY][1][nenrei] + jinko_m[nendo-STARTY][2][nenrei] ; 
         stk_jinko_c[nendo-STARTY][0][nenrei]
           = stk_jinko_c[nendo-STARTY][1][nenrei] + stk_jinko_c[nendo-STARTY][2][nenrei] ; 
         stk_jinko_m[nendo-STARTY][0][nenrei]
           = stk_jinko_m[nendo-STARTY][1][nenrei] + stk_jinko_m[nendo-STARTY][2][nenrei] ; 
         str_jinko_c[nendo-STARTY][0][nenrei]
           = str_jinko_c[nendo-STARTY][1][nenrei] + str_jinko_c[nendo-STARTY][2][nenrei] ; 
         str_jinko_m[nendo-STARTY][0][nenrei]
           = str_jinko_m[nendo-STARTY][1][nenrei] + str_jinko_m[nendo-STARTY][2][nenrei] ; 
         sts_jinko_c[nendo-STARTY][0][nenrei]
           = sts_jinko_c[nendo-STARTY][1][nenrei] + sts_jinko_c[nendo-STARTY][2][nenrei] ; 
         sts_jinko_m[nendo-STARTY][0][nenrei]
           = sts_jinko_m[nendo-STARTY][1][nenrei] + sts_jinko_m[nendo-STARTY][2][nenrei] ; 

      }
    }
  }


/*  人口100歳以上を100歳に落とし込み */
  for ( nendo=STARTY+1; nendo<=KE+1; nendo++ ) {
    for ( sei=1; sei<=2; sei++ ) {
      for ( nenrei=101; nenrei<=120; nenrei++ ) {
        if ( jinko_c[nendo-STARTY][sei][nenrei] > 0.0 ) {
            jinko_c[nendo-STARTY][sei][100] += jinko_c[nendo-STARTY][sei][nenrei] ;
            jinko_c[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
        if ( jinko_m[nendo-STARTY][sei][nenrei] > 0.0 ) {
            jinko_m[nendo-STARTY][sei][100] += jinko_m[nendo-STARTY][sei][nenrei] ;
            jinko_m[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
        if ( stk_jinko_c[nendo-STARTY][sei][nenrei] > 0.0 ) {
            stk_jinko_c[nendo-STARTY][sei][100] += stk_jinko_c[nendo-STARTY][sei][nenrei] ;
            stk_jinko_c[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
        if ( stk_jinko_m[nendo-STARTY][sei][nenrei] > 0.0 ) {
            stk_jinko_m[nendo-STARTY][sei][100] += stk_jinko_m[nendo-STARTY][sei][nenrei] ;
            stk_jinko_m[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
        if ( str_jinko_c[nendo-STARTY][sei][nenrei] > 0.0 ) {
            str_jinko_c[nendo-STARTY][sei][100] += str_jinko_c[nendo-STARTY][sei][nenrei] ;
            str_jinko_c[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
        if ( str_jinko_m[nendo-STARTY][sei][nenrei] > 0.0 ) {
            str_jinko_m[nendo-STARTY][sei][100] += str_jinko_m[nendo-STARTY][sei][nenrei] ;
            str_jinko_m[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
        if ( sts_jinko_c[nendo-STARTY][sei][nenrei] > 0.0 ) {
            sts_jinko_c[nendo-STARTY][sei][100] += sts_jinko_c[nendo-STARTY][sei][nenrei] ;
            sts_jinko_c[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
        if ( sts_jinko_m[nendo-STARTY][sei][nenrei] > 0.0 ) {
            sts_jinko_m[nendo-STARTY][sei][100] += sts_jinko_m[nendo-STARTY][sei][nenrei] ;
            sts_jinko_m[nendo-STARTY][sei][nenrei] = 0.0 ;
        }
      }
    }
  }



/*  女性有配偶、無配偶別人口  */

  /*  年度中有配偶率の延長  */
  for ( nendo=YUHAIGY+1; nendo<=KE+1; nendo++ ) {
    for ( nenrei=0; nenrei<=100; nenrei++) {
      yuhaigr_c[nendo-STARTY][nenrei] = yuhaigr_c[nendo-1-STARTY][nenrei] ;
    }
  }

  for ( nendo=STARTY+1; nendo<=KE+1; nendo++ ) {
    for ( nenrei=0; nenrei<=100; nenrei++) {
      /*  年度末有配偶率  */
        yuhaigr_m[nendo-STARTY][nenrei] =
          ( yuhaigr_c[nendo-STARTY][nenrei] + yuhaigr_c[nendo+1-STARTY][nenrei] ) / 2.0 ;
      /*  有配偶、無配偶別人口  */
        jinko_c[nendo-STARTY][3][nenrei] =
          jinko_c[nendo-STARTY][2][nenrei] * yuhaigr_c[nendo-STARTY][nenrei] ;
        jinko_c[nendo-STARTY][4][nenrei] =
          jinko_c[nendo-STARTY][2][nenrei] * (1.0 - yuhaigr_c[nendo-STARTY][nenrei] ) ;
        jinko_m[nendo-STARTY][3][nenrei] =
          jinko_m[nendo-STARTY][2][nenrei] * yuhaigr_m[nendo-STARTY][nenrei] ;
        jinko_m[nendo-STARTY][4][nenrei] =
          jinko_m[nendo-STARTY][2][nenrei] * (1.0 - yuhaigr_m[nendo-STARTY][nenrei] ) ;
        stk_jinko_c[nendo-STARTY][3][nenrei] =
          stk_jinko_c[nendo-STARTY][2][nenrei] * yuhaigr_c[nendo-STARTY][nenrei] ;
        stk_jinko_c[nendo-STARTY][4][nenrei] =
          stk_jinko_c[nendo-STARTY][2][nenrei] * (1.0 - yuhaigr_c[nendo-STARTY][nenrei] ) ;
        stk_jinko_m[nendo-STARTY][3][nenrei] =
          stk_jinko_m[nendo-STARTY][2][nenrei] * yuhaigr_m[nendo-STARTY][nenrei] ;
        stk_jinko_m[nendo-STARTY][4][nenrei] =
          stk_jinko_m[nendo-STARTY][2][nenrei] * (1.0 - yuhaigr_m[nendo-STARTY][nenrei] ) ;
        str_jinko_c[nendo-STARTY][3][nenrei] =
          str_jinko_c[nendo-STARTY][2][nenrei] * yuhaigr_c[nendo-STARTY][nenrei] ;
        str_jinko_c[nendo-STARTY][4][nenrei] =
          str_jinko_c[nendo-STARTY][2][nenrei] * (1.0 - yuhaigr_c[nendo-STARTY][nenrei] ) ;
        str_jinko_m[nendo-STARTY][3][nenrei] =
          str_jinko_m[nendo-STARTY][2][nenrei] * yuhaigr_m[nendo-STARTY][nenrei] ;
        str_jinko_m[nendo-STARTY][4][nenrei] =
          str_jinko_m[nendo-STARTY][2][nenrei] * (1.0 - yuhaigr_m[nendo-STARTY][nenrei] ) ;
        sts_jinko_c[nendo-STARTY][3][nenrei] =
          sts_jinko_c[nendo-STARTY][2][nenrei] * yuhaigr_c[nendo-STARTY][nenrei] ;
        sts_jinko_c[nendo-STARTY][4][nenrei] =
          sts_jinko_c[nendo-STARTY][2][nenrei] * (1.0 - yuhaigr_c[nendo-STARTY][nenrei] ) ;
        sts_jinko_m[nendo-STARTY][3][nenrei] =
          sts_jinko_m[nendo-STARTY][2][nenrei] * yuhaigr_m[nendo-STARTY][nenrei] ;
        sts_jinko_m[nendo-STARTY][4][nenrei] =
          sts_jinko_m[nendo-STARTY][2][nenrei] * (1.0 - yuhaigr_m[nendo-STARTY][nenrei] ) ;
    }
  }

/*  総人口、生産年齢人口  */

  for ( nendo=STARTY+1; nendo<=KE; nendo++ ) {
    sojinko_c[nendo-STARTY][0] = sojinko_c[nendo-STARTY][1] + sojinko_c[nendo-STARTY][2] ;
    stk_sojinko_c[nendo-STARTY][0] = stk_sojinko_c[nendo-STARTY][1] + stk_sojinko_c[nendo-STARTY][2] ;
    str_sojinko_c[nendo-STARTY][0] = str_sojinko_c[nendo-STARTY][1] + str_sojinko_c[nendo-STARTY][2] ;
    sts_sojinko_c[nendo-STARTY][0] = sts_sojinko_c[nendo-STARTY][1] + sts_sojinko_c[nendo-STARTY][2] ;
    for ( nenrei=0; nenrei<=100; nenrei++) {
      for ( sei=1; sei<=4; sei++){
        sojinko_m[nendo-STARTY][sei] += jinko_m[nendo-STARTY][sei][nenrei] ;
        stk_sojinko_m[nendo-STARTY][sei] += stk_jinko_m[nendo-STARTY][sei][nenrei] ;
        str_sojinko_m[nendo-STARTY][sei] += str_jinko_m[nendo-STARTY][sei][nenrei] ;
        sts_sojinko_m[nendo-STARTY][sei] += sts_jinko_m[nendo-STARTY][sei][nenrei] ;
        if ( sei<=2 ) {
          sojinko_m[nendo-STARTY][0] += jinko_m[nendo-STARTY][sei][nenrei] ;
          stk_sojinko_m[nendo-STARTY][0] += stk_jinko_m[nendo-STARTY][sei][nenrei] ;
          str_sojinko_m[nendo-STARTY][0] += str_jinko_m[nendo-STARTY][sei][nenrei] ;
          sts_sojinko_m[nendo-STARTY][0] += sts_jinko_m[nendo-STARTY][sei][nenrei] ;
        }
        if (( nenrei >= 15 ) && ( nenrei <= 64 )) {
          seisanj_c[nendo-STARTY][sei] += jinko_c[nendo-STARTY][sei][nenrei] ;
          seisanj_m[nendo-STARTY][sei] += jinko_m[nendo-STARTY][sei][nenrei] ;
          stk_seisanj_c[nendo-STARTY][sei] += stk_jinko_c[nendo-STARTY][sei][nenrei] ;
          stk_seisanj_m[nendo-STARTY][sei] += stk_jinko_m[nendo-STARTY][sei][nenrei] ;
          str_seisanj_c[nendo-STARTY][sei] += str_jinko_c[nendo-STARTY][sei][nenrei] ;
          str_seisanj_m[nendo-STARTY][sei] += str_jinko_m[nendo-STARTY][sei][nenrei] ;
          sts_seisanj_c[nendo-STARTY][sei] += sts_jinko_c[nendo-STARTY][sei][nenrei] ;
          sts_seisanj_m[nendo-STARTY][sei] += sts_jinko_m[nendo-STARTY][sei][nenrei] ;
          if ( sei<=2 ) {
            seisanj_c[nendo-STARTY][0] += jinko_c[nendo-STARTY][sei][nenrei] ;
            seisanj_m[nendo-STARTY][0] += jinko_m[nendo-STARTY][sei][nenrei] ;
            stk_seisanj_c[nendo-STARTY][0] += stk_jinko_c[nendo-STARTY][sei][nenrei] ;
            stk_seisanj_m[nendo-STARTY][0] += stk_jinko_m[nendo-STARTY][sei][nenrei] ;
            str_seisanj_c[nendo-STARTY][0] += str_jinko_c[nendo-STARTY][sei][nenrei] ;
            str_seisanj_m[nendo-STARTY][0] += str_jinko_m[nendo-STARTY][sei][nenrei] ;
            sts_seisanj_c[nendo-STARTY][0] += sts_jinko_c[nendo-STARTY][sei][nenrei] ;
            sts_seisanj_m[nendo-STARTY][0] += sts_jinko_m[nendo-STARTY][sei][nenrei] ;
          }
        }
      }
    }
  }


}

