/*************************************
*                                    *
*    外枠システム  simlpart.c        *
*  （適用拡大者数の推計）            *
*                                    *
*************************************/

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

void simlpart(void) 
{


    char    filename[250]    ; 
    int     pkubun  ;  
    int     ykubun  ;  
    int     ii      ;
    int     TMR     ;
    int     XEND ;



    switch ( PARTK1 ) { 
        case 1: 
            sprintf(filename, "/rev26/wakuc/data/part/partnin26-1.csv");
            break ;
    }

    if ((fp_part = fopen(filename, "r")) == NULL) {
        fprintf(stderr, "適用拡大入力ファイル（１）を開けません!\n");
        exit (2); 
    }

    karayomi( fp_part );  

    for ( kubun=1; kubun<=11; kubun++ ) {
        read_csv( buffer, fp_part, &data_number );
        ii = (int) buffer[0] ; 
        kbetu_partkiso[1][ii][1][1] = (double) buffer[1] ; 
        kbetu_partkiso[1][ii][2][1] = (double) buffer[2] ; 
        kbetu_partkiso[1][ii][3][1] = (double) buffer[3] ; 
        kbetu_partkiso[2][ii][1][1] = (double) buffer[4] ; 
        kbetu_partkiso[2][ii][2][1] = (double) buffer[5] ; 
        kbetu_partkiso[2][ii][3][1] = (double) buffer[6] ; 
    }

        fclose(fp_part);


    switch ( PARTK2 ) { 
        case 0: 
            sprintf(filename, "/rev26/wakuc/data/part/partnin26-0.csv");
            break ;
        case 1: 
            sprintf(filename, "/rev26/wakuc/data/part/partnin26-1.csv");
            break ;
        case 2: 
            sprintf(filename, "/rev26/wakuc/data/part/partnin26-2.csv");
            break ;
        case 8:
        case 9: 
            sprintf(filename, "/rev26/wakuc/data/part/partnin26-1.csv");
            break ;
    }

    if ((fp_part = fopen(filename, "r")) == NULL) {
        fprintf(stderr, "適用拡大ファイル（２）を開けません!\n");
        exit (2); 
    }

    karayomi( fp_part );  

    for ( kubun=1; kubun<=11; kubun++ ) {
        read_csv( buffer, fp_part, &data_number );
        ii = (int) buffer[0] ; 
        kbetu_partkiso[1][ii][1][2] = (double) buffer[1] ; 
        kbetu_partkiso[1][ii][2][2] = (double) buffer[2] ; 
        kbetu_partkiso[1][ii][3][2] = (double) buffer[3] ; 
        kbetu_partkiso[2][ii][1][2] = (double) buffer[4] ; 
        kbetu_partkiso[2][ii][2][2] = (double) buffer[5] ; 
        kbetu_partkiso[2][ii][3][2] = (double) buffer[6] ; 
    }

      fclose(fp_part);

      PARTJJ = 1995 ; 

    for ( nendo=KS; nendo<=KE+1; nendo++ ) {
      for ( sei=0; sei<=4; sei++ ) {
        for ( nenrei=15; nenrei<=120; nenrei++ ) {
            tmae[1][nendo-STARTY][sei][nenrei] = kou12syu[nendo-STARTY][sei][nenrei] ;
            tmae[2][nendo-STARTY][sei][nenrei] = kou3syu[nendo-STARTY][sei][nenrei] ;
            tmae[3][nendo-STARTY][sei][nenrei] = kyosai[1][nendo-STARTY][sei][nenrei] ;
            tmae[4][nendo-STARTY][sei][nenrei] = kyosai[2][nendo-STARTY][sei][nenrei] ;
            tmae[5][nendo-STARTY][sei][nenrei] = kyosai[3][nendo-STARTY][sei][nenrei] ;
            tmae[6][nendo-STARTY][sei][nenrei] = kounen[nendo-STARTY][sei][nenrei] ; 
            tmae[9][nendo-STARTY][sei][nenrei] = ichigouip[nendo-STARTY][sei][nenrei] ; 
            tmae[10][nendo-STARTY][sei][nenrei] = ichigou[nendo-STARTY][sei][nenrei] ;
            tmae[11][nendo-STARTY][sei][nenrei] = kou12syu3[nendo-STARTY][sei][nenrei] ;
            tmae[12][nendo-STARTY][sei][nenrei] = kou3syu3[nendo-STARTY][sei][nenrei] ;
            tmae[13][nendo-STARTY][sei][nenrei] = kyosai3[1][nendo-STARTY][sei][nenrei] ;
            tmae[14][nendo-STARTY][sei][nenrei] = kyosai3[2][nendo-STARTY][sei][nenrei] ;
            tmae[15][nendo-STARTY][sei][nenrei] = kyosai3[3][nendo-STARTY][sei][nenrei] ;
            tmae[16][nendo-STARTY][sei][nenrei] = kyosai3[4][nendo-STARTY][sei][nenrei] ;
            tmae[17][nendo-STARTY][sei][nenrei] = kyosai3[5][nendo-STARTY][sei][nenrei] ;
            tmae[18][nendo-STARTY][sei][nenrei] = kyosai3[7][nendo-STARTY][sei][nenrei] ;
            tmae[19][nendo-STARTY][sei][nenrei] = kyosai3[6][nendo-STARTY][sei][nenrei] ;
            tmae[20][nendo-STARTY][sei][nenrei] = sangou[nendo-STARTY][sei][nenrei] ;
            tmae[21][nendo-STARTY][sei][nenrei] = kounen3[nendo-STARTY][sei][nenrei] ; 
        }
      }
    }


    for ( nendo=PARTKYR-1; nendo<=KE; nendo++ ) {
        for ( sei=1; sei<=2; sei++ ) {
            for ( kubun=1; kubun<=15; kubun++ ) {
                TMR = kubun * 5 + 12 ; 
                kbetu_tankoj[nendo-STARTY][sei][kubun] = 0.0 ;
                for ( nenrei=TMR-2; nenrei<=TMR+2; nenrei++ ) {
                    kbetu_tankoj[nendo-STARTY][sei][kubun] += koyouj_m[4][nendo-STARTY][sei][nenrei] ;
                }
            }
        }
    }



  for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {
    for ( sei=1; sei<=2; sei++ ) {
      for ( kubun=1; kubun<=15; kubun++ ) {
        for ( pkubun=1; pkubun<=3; pkubun++ ) { 
          for ( ykubun=1; ykubun<=2; ykubun++ ) {

            if ( kbetu_tankoj[PARTKYR-STARTY][sei][kubun] > 0.0 ) {
                kbetu_partnin[nendo-STARTY][sei][kubun][pkubun][ykubun]
                 = kbetu_partkiso[sei][kubun][pkubun][ykubun]
                   * kbetu_tankoj[nendo-STARTY][sei][kubun] / kbetu_tankoj[PARTKYR-STARTY][sei][kubun] ;
            }
            else {  
              fprintf(stderr, "適用拡大推計エラー\n" );
              printf("適用拡大推計エラー\n" );
              kbetu_partnin[nendo-STARTY][sei][kubun][pkubun][ykubun] = 0.0 ;
            }

          }
        }

        for ( ykubun=0; ykubun<=2; ykubun++ ) {
          if (( kubun >= 2 ) && ( kubun <= 9 )) { 
              kbetu_partnin[nendo-STARTY][sei][kubun][1][ykubun]
                += kbetu_partnin[nendo-STARTY][sei][kubun][3][ykubun] ;
              kbetu_partnin[nendo-STARTY][sei][kubun][3][ykubun] = 0.0 ;
          }
          kbetu_partnin[nendo-STARTY][sei][kubun][0][ykubun]
            = kbetu_partnin[nendo-STARTY][sei][kubun][1][ykubun] 
            + kbetu_partnin[nendo-STARTY][sei][kubun][2][ykubun] 
            + kbetu_partnin[nendo-STARTY][sei][kubun][3][ykubun] ;
        }
      }
    }
  }


  for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {
    for ( sei=1; sei<=2; sei++ ) {
      for ( kubun=2; kubun<=9; kubun++ ) {
          TMR = kubun * 5 + 12 ; 
          for ( nenrei=TMR-2; nenrei<=TMR+2; nenrei++ ) {
              kbetu_partgen[nendo-STARTY][sei][kubun][1] += ichigouip[nendo-STARTY][sei][nenrei] ;
              kbetu_partgen[nendo-STARTY][sei][kubun][2] += sangou[nendo-STARTY][sei][nenrei] ;
          }
      }
      for ( kubun=10; kubun<=11; kubun++ ) {
          TMR = kubun * 5 + 12 ; 
          for ( nenrei=TMR-2; nenrei<=TMR+2; nenrei++ ) {
              kbetu_partgen[nendo-STARTY][sei][kubun][1] += ichigouni[nendo-STARTY][sei][nenrei] ;
          }
      }
    }
  }


  for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {
    for ( sei=1; sei<=2; sei++ ) {
      for ( kubun=2; kubun<=9; kubun++ ) {
        for ( pkubun=1; pkubun<=3; pkubun++ ) {
          for ( ykubun=1; ykubun<=2; ykubun++ ) {
            if ( kbetu_partgen[nendo-STARTY][sei][kubun][pkubun] <= 0.0 ) { 
              kbetu_partnin[nendo-STARTY][sei][kubun][pkubun][ykubun] = 0.0 ;
              TMR = kubun * 5 + 12 ; 
              for ( nenrei=TMR-2; nenrei<=TMR+2; nenrei++ ) {
                partgenwari[nendo-STARTY][sei][nenrei][pkubun][ykubun] = 1.0 ;
              }
            }
            else if ( kbetu_partnin[nendo-STARTY][sei][kubun][pkubun][ykubun]
                       <= kbetu_partgen[nendo-STARTY][sei][kubun][pkubun] ) { 
              TMR = kubun * 5 + 12 ; 
              for ( nenrei=TMR-2; nenrei<=TMR+2; nenrei++ ) {
                partgenwari[nendo-STARTY][sei][nenrei][pkubun][ykubun] = 
                 ( kbetu_partgen[nendo-STARTY][sei][kubun][pkubun]
                    - kbetu_partnin[nendo-STARTY][sei][kubun][pkubun][ykubun] ) 
                 / kbetu_partgen[nendo-STARTY][sei][kubun][pkubun] ;
              }
            }
            else if ( nendo < KE ) { 
              printf("適用拡大減算エラー\n" ) ;
              fprintf(fp_err, "適用拡大減算エラー\n" ) ;
              kbetu_partnin[nendo-STARTY][sei][kubun][pkubun][ykubun] =
                kbetu_partgen[nendo-STARTY][sei][kubun][pkubun] ;
              TMR = kubun * 5 + 12 ; 
              for ( nenrei=TMR-2; nenrei<=TMR+2; nenrei++ ) {
                partgenwari[nendo-STARTY][sei][nenrei][pkubun][ykubun] = 0.0 ;
              }
            }
          }
        }
      }

      for ( kubun=10; kubun<=11; kubun++ ) {
        for ( ykubun=1; ykubun<=2; ykubun++ ) {  
            if ( kbetu_partgen[nendo-STARTY][sei][kubun][1] <= 0.0 ) { 
              kbetu_partnin[nendo-STARTY][sei][kubun][1][ykubun] = 0.0 ;
              TMR = kubun * 5 + 12 ; 
              for ( nenrei=TMR-2; nenrei<=TMR+2; nenrei++ ) {
                partgenwari[nendo-STARTY][sei][nenrei][1][ykubun] = 1.0 ;
              }
            }
            else if ( kbetu_partnin[nendo-STARTY][sei][kubun][1][ykubun]
                       <= kbetu_partgen[nendo-STARTY][sei][kubun][1] ) {
              TMR = kubun * 5 + 12 ; 
              for ( nenrei=TMR-2; nenrei<=TMR+2; nenrei++ ) {
                partgenwari[nendo-STARTY][sei][nenrei][1][ykubun] = 
                 ( kbetu_partgen[nendo-STARTY][sei][kubun][1]
                    - kbetu_partnin[nendo-STARTY][sei][kubun][1][ykubun] ) 
                 / kbetu_partgen[nendo-STARTY][sei][kubun][1] ;
              }
            }
            else if ( nendo < KE ) { 
              printf("適用拡大減算エラー\n" ) ;
              fprintf(fp_err, "適用拡大減算エラー\n" ) ;
              kbetu_partnin[nendo-STARTY][sei][kubun][1][ykubun]
               = kbetu_partgen[nendo-STARTY][sei][kubun][1] ;
              TMR = kubun * 5 + 12 ; 
              for ( nenrei=TMR-2; nenrei<=TMR+2; nenrei++ ) {
                partgenwari[nendo-STARTY][sei][nenrei][1][ykubun] = 0.0 ;
              }
            }
        }
      }

    }
  }



  for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {

      for ( nenrei=15; nenrei<=19; nenrei++ ) {
        for ( ykubun=1; ykubun<=2; ykubun++ ) {
          for ( sei=1; sei<=2; sei++ ) {
            partnin[nendo-STARTY][sei][nenrei][3][ykubun]
              = kbetu_partnin[nendo-STARTY][sei][1][3][ykubun]
              * koyouj_m[4][nendo-STARTY][sei][nenrei] / kbetu_tankoj[nendo-STARTY][sei][1] ;
          }
          partnin[nendo-STARTY][3][nenrei][3][ykubun]
            = partnin[nendo-STARTY][2][nenrei][3][ykubun] 
                * koyouj_m[4][nendo-STARTY][3][nenrei] / koyouj_m[4][nendo-STARTY][2][nenrei] ;
          partnin[nendo-STARTY][4][nenrei][3][ykubun]
            = partnin[nendo-STARTY][2][nenrei][3][ykubun] 
                * koyouj_m[4][nendo-STARTY][4][nenrei] / koyouj_m[4][nendo-STARTY][2][nenrei] ;
          partnin[nendo-STARTY][0][nenrei][3][ykubun]
            = partnin[nendo-STARTY][1][nenrei][3][ykubun] + partnin[nendo-STARTY][2][nenrei][3][ykubun] ;
        }
      }

      for ( kubun=2; kubun<=9; kubun++ ) {
        TMR = kubun * 5 + 12 ; 
        for ( nenrei=TMR-2; nenrei<=TMR+2; nenrei++ ) {

            for ( ykubun=1; ykubun<=2; ykubun++ ) {
              for ( sei=1; sei<=2; sei++ ) {
                partnin[nendo-STARTY][sei][nenrei][1][ykubun] =
                   ichigouip[nendo-STARTY][sei][nenrei] 
                     * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][1][ykubun] ) ;
              }
              for ( sei=3; sei<=4; sei++ ) {
                partnin[nendo-STARTY][sei][nenrei][1][ykubun] =
                   ichigouip[nendo-STARTY][sei][nenrei] 
                     * ( 1.0 - partgenwari[nendo-STARTY][2][nenrei][1][ykubun] ) ;
              }
              partnin[nendo-STARTY][0][nenrei][1][ykubun]
                = partnin[nendo-STARTY][1][nenrei][1][ykubun] + partnin[nendo-STARTY][2][nenrei][1][ykubun] ; 
            }
            if ( nendo >= PARTYR1 ) { 
                if ( nendo < PARTYR2 ) {
                  if ( nendo == PARTYR2-1 ) {
                    for ( sei=1; sei<=2; sei++ ) {
                      ichigouip[PARTJJ-STARTY][sei][nenrei]
                        = ichigouip[nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][sei][nenrei][1][2] ;
                      ichigouni[PARTJJ-STARTY][sei][nenrei] = ichigouni[nendo-STARTY][sei][nenrei] ;
                      ichigou[PARTJJ-STARTY][sei][nenrei]
                        = ichigouip[PARTJJ-STARTY][sei][nenrei] + ichigouni[PARTJJ-STARTY][sei][nenrei] ;
                    }
                    for ( sei=3; sei<=4; sei++ ) {
                      ichigouip[PARTJJ-STARTY][sei][nenrei] 
                        = ichigouip[nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][2][nenrei][1][2] ;
                      ichigouni[PARTJJ-STARTY][sei][nenrei] = ichigouni[nendo-STARTY][sei][nenrei] ;
                      ichigou[PARTJJ-STARTY][sei][nenrei]
                        = ichigouip[PARTJJ-STARTY][sei][nenrei] + ichigouni[PARTJJ-STARTY][sei][nenrei] ;
                    }
                  }
                  for ( sei=1; sei<=2; sei++ ) {
                    ichigouip[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][1][1] ;
                  }
                  for ( sei=3; sei<=4; sei++ ) {
                    ichigouip[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][2][nenrei][1][1] ;
                  }
                }
                else if ( nendo >= PARTYR2 ) {
                  for ( sei=1; sei<=2; sei++ ) {
                    ichigouip[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][1][2] ;
                  }
                  for ( sei=3; sei<=4; sei++ ) {
                    ichigouip[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][2][nenrei][1][2] ;
                  }
                }
                ichigouip[nendo-STARTY][0][nenrei]
                  = ichigouip[nendo-STARTY][1][nenrei] + ichigouip[nendo-STARTY][2][nenrei] ;
                if ( nendo == PARTYR2-1 ) {
                  ichigouip[PARTJJ-STARTY][0][nenrei]
                    = ichigouip[PARTJJ-STARTY][1][nenrei] + ichigouip[PARTJJ-STARTY][2][nenrei] ;
                  ichigouni[PARTJJ-STARTY][0][nenrei]
                    = ichigouni[PARTJJ-STARTY][1][nenrei] + ichigouni[PARTJJ-STARTY][2][nenrei] ;
                  ichigou[PARTJJ-STARTY][0][nenrei]
                    = ichigou[PARTJJ-STARTY][1][nenrei] + ichigou[PARTJJ-STARTY][2][nenrei] ;
                }
            }
         
            for ( ykubun=1; ykubun<=2; ykubun++ ) {
              for ( sei=1; sei<=2; sei++ ) {
                partnin[nendo-STARTY][sei][nenrei][2][ykubun]
                  = ( qkou12syu3[nendo-STARTY][sei][nenrei] + kou3syu3[nendo-STARTY][sei][nenrei]
                      + kyosai3[4][nendo-STARTY][sei][nenrei] + kyosai3[5][nendo-STARTY][sei][nenrei]
                      + kyosai3[6][nendo-STARTY][sei][nenrei] + kyosai3[7][nendo-STARTY][sei][nenrei] )
                  * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][2][ykubun] )  ;
                partnin[nendo-STARTY][sei][nenrei][8][ykubun] = partnin[nendo-STARTY][sei][nenrei][2][ykubun] ;
              }
              partnin[nendo-STARTY][3][nenrei][2][ykubun] = partnin[nendo-STARTY][2][nenrei][2][ykubun] ;
              partnin[nendo-STARTY][3][nenrei][8][ykubun] = partnin[nendo-STARTY][2][nenrei][8][ykubun] ;
              partnin[nendo-STARTY][4][nenrei][2][ykubun] = 0.0 ;
              partnin[nendo-STARTY][4][nenrei][8][ykubun] = 0.0 ;
              partnin[nendo-STARTY][0][nenrei][2][ykubun]
                = partnin[nendo-STARTY][1][nenrei][2][ykubun] + partnin[nendo-STARTY][2][nenrei][2][ykubun] ;
              partnin[nendo-STARTY][0][nenrei][8][ykubun]
                = partnin[nendo-STARTY][1][nenrei][8][ykubun] + partnin[nendo-STARTY][2][nenrei][8][ykubun] ;
            }

            if ( nendo >= PARTYR1 ) { 
                if ( nendo < PARTYR2 ) {
                  if ( nendo == PARTYR2-1 ) {
                    for ( sei=1; sei<=2; sei++ ) {
                      qkou12syu3[PARTJJ-STARTY][sei][nenrei]
                        = qkou12syu3[nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][sei][nenrei][2][2] ;
                      kou3syu3[PARTJJ-STARTY][sei][nenrei]
                        = kou3syu3[nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][sei][nenrei][2][2] ;
                      for ( seido=4; seido<=7; seido++ ) {
                        kyosai3[seido][PARTJJ-STARTY][sei][nenrei]
                          = kyosai3[seido][nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][sei][nenrei][2][2] ;
                      }
                    }
                  }
                  for ( sei=1; sei<=2; sei++ ) {
                    qkou12syu3[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][2][1] ;
                    kou3syu3[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][2][1] ;
                    for ( seido=4; seido<=7; seido++ ) {
                      kyosai3[seido][nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][2][1] ;
                    }
                  }
                }
                else if ( nendo >= PARTYR2 ) {
                  for ( sei=1; sei<=2; sei++ ) {
                    qkou12syu3[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][2][2] ;
                    kou3syu3[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][2][2] ;
                    for ( seido=4; seido<=7; seido++ ) {
                      kyosai3[seido][nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][2][2] ;
                    }
                  }
                }
                qkou12syu3[nendo-STARTY][3][nenrei] = qkou12syu3[nendo-STARTY][2][nenrei] ;
                kou3syu3[nendo-STARTY][3][nenrei] = kou3syu3[nendo-STARTY][2][nenrei] ;
                for ( seido=4; seido<=7; seido++ ) {
                  kyosai3[seido][nendo-STARTY][3][nenrei] = kyosai3[seido][nendo-STARTY][2][nenrei] ;
                }
                if ( nendo == PARTYR2-1 ) {
                  qkou12syu3[PARTJJ-STARTY][3][nenrei] = qkou12syu3[PARTJJ-STARTY][2][nenrei] ;
                  kou3syu3[PARTJJ-STARTY][3][nenrei] = kou3syu3[PARTJJ-STARTY][2][nenrei] ;
                  for ( seido=4; seido<=7; seido++ ) {
                    kyosai3[seido][PARTJJ-STARTY][3][nenrei] = kyosai3[seido][PARTJJ-STARTY][2][nenrei] ;
                  }
                }
                qkou12syu3[nendo-STARTY][0][nenrei]
                  = qkou12syu3[nendo-STARTY][1][nenrei] + qkou12syu3[nendo-STARTY][2][nenrei] ;
                kou3syu3[nendo-STARTY][0][nenrei]
                  = kou3syu3[nendo-STARTY][1][nenrei] + kou3syu3[nendo-STARTY][2][nenrei] ;
                for ( seido=4; seido<=7; seido++ ) {
                  kyosai3[seido][nendo-STARTY][0][nenrei]
                    = kyosai3[seido][nendo-STARTY][1][nenrei] + kyosai3[seido][nendo-STARTY][2][nenrei] ;
                }
                if ( nendo == PARTYR2-1 ) {
                  qkou12syu3[PARTJJ-STARTY][0][nenrei]
                    = qkou12syu3[PARTJJ-STARTY][1][nenrei] + qkou12syu3[PARTJJ-STARTY][2][nenrei] ;
                  kou3syu3[PARTJJ-STARTY][0][nenrei]
                    = kou3syu3[PARTJJ-STARTY][1][nenrei] + kou3syu3[PARTJJ-STARTY][2][nenrei] ;
                  for ( seido=4; seido<=7; seido++ ) {
                    kyosai3[seido][PARTJJ-STARTY][0][nenrei]
                      = kyosai3[seido][PARTJJ-STARTY][1][nenrei] + kyosai3[seido][PARTJJ-STARTY][2][nenrei] ;
                  }
                }
            }

            for ( ykubun=0; ykubun<=2; ykubun++ ) {
              for ( sei=1; sei<=2; sei++ ) {
                partnin[nendo-STARTY][sei][nenrei][2][ykubun]
                  += ( kyosai3[1][nendo-STARTY][sei][nenrei] + kyosai3[2][nendo-STARTY][sei][nenrei]
                       + kyosai3[3][nendo-STARTY][sei][nenrei] )
                     * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][2][ykubun] )  ; 
                partnin[nendo-STARTY][sei][nenrei][5][ykubun] = kyosai3[1][nendo-STARTY][sei][nenrei]
                  * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][2][ykubun] )  ; 
                partnin[nendo-STARTY][sei][nenrei][6][ykubun] = kyosai3[2][nendo-STARTY][sei][nenrei]
                  * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][2][ykubun] )  ; 
                partnin[nendo-STARTY][sei][nenrei][7][ykubun] = kyosai3[3][nendo-STARTY][sei][nenrei]
                  * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][2][ykubun] )  ; 
              }
              partnin[nendo-STARTY][3][nenrei][2][ykubun] = partnin[nendo-STARTY][2][nenrei][2][ykubun] ;
              partnin[nendo-STARTY][4][nenrei][2][ykubun] = 0.0 ;
              for ( pkubun=5; pkubun<=7; pkubun++ ) {
                partnin[nendo-STARTY][3][nenrei][pkubun][ykubun]
                  = partnin[nendo-STARTY][2][nenrei][pkubun][ykubun] ;
                partnin[nendo-STARTY][4][nenrei][pkubun][ykubun] = 0.0 ;
              }
              partnin[nendo-STARTY][0][nenrei][2][ykubun]
                = partnin[nendo-STARTY][1][nenrei][2][ykubun] + partnin[nendo-STARTY][2][nenrei][2][ykubun] ;
              for ( pkubun=5; pkubun<=7; pkubun++ ) {
                partnin[nendo-STARTY][0][nenrei][pkubun][ykubun]
                  = partnin[nendo-STARTY][1][nenrei][pkubun][ykubun] + partnin[nendo-STARTY][2][nenrei][pkubun][ykubun] ;
              }
            }
            if ( nendo >= PARTYR1 ) {
                if ( nendo < PARTYR2 ) {
                  if ( nendo == PARTYR2-1 ) {
                    for ( sei=1; sei<=2; sei++ ) {
                      for ( seido=1; seido<=3; seido++ ) {
                        kyosai3[seido][PARTJJ-STARTY][sei][nenrei] 
                          = kyosai3[seido][nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][sei][nenrei][2][2] ;
                      }
                    }
                  }
                  for ( sei=1; sei<=2; sei++ ) {
                    for ( seido=1; seido<=3; seido++ ) {
                      kyosai3[seido][nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][2][1] ;
                    }
                  }
                }
                else if ( nendo >= PARTYR2 ) {
                  for ( sei=1; sei<=2; sei++ ) {
                    for ( seido=1; seido<=3; seido++ ) {
                      kyosai3[seido][nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][2][2] ;
                    }
                  }
                }
                for ( seido=1; seido<=3; seido++ ) {
                  kyosai3[seido][nendo-STARTY][3][nenrei] = kyosai3[seido][nendo-STARTY][2][nenrei] ;
                }
                if ( nendo == PARTYR2-1 ) {
                  for ( seido=1; seido<=3; seido++ ) {
                    kyosai3[seido][PARTJJ-STARTY][3][nenrei] = kyosai3[seido][PARTJJ-STARTY][2][nenrei] ;
                  }
                }
                for ( seido=1; seido<=3; seido++ ) {
                  kyosai3[seido][nendo-STARTY][0][nenrei]
                    = kyosai3[seido][nendo-STARTY][1][nenrei] + kyosai3[seido][nendo-STARTY][2][nenrei] ;
                }
                if ( nendo == PARTYR2-1 ) {
                  for ( seido=1; seido<=3; seido++ ) {
                    kyosai3[seido][PARTJJ-STARTY][0][nenrei]
                      = kyosai3[seido][PARTJJ-STARTY][1][nenrei] + kyosai3[seido][PARTJJ-STARTY][2][nenrei] ;
                  }
                }

            }

        }
      }

      for ( kubun=10; kubun<=11; kubun++ ) {
        TMR = kubun * 5 + 12 ; 
        for ( nenrei=TMR-2; nenrei<=TMR+2; nenrei++ ) {

          for ( ykubun=1; ykubun<=2; ykubun++ ) {
            for ( sei=1; sei<=2; sei++ ) {
              partnin[nendo-STARTY][sei][nenrei][1][ykubun] = ichigouni[nendo-STARTY][sei][nenrei] 
                * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][1][ykubun] ) ;
            }
            for ( sei=3; sei<=4; sei++ ) {
              partnin[nendo-STARTY][sei][nenrei][1][ykubun] = ichigouni[nendo-STARTY][sei][nenrei] 
                * ( 1.0 - partgenwari[nendo-STARTY][2][nenrei][1][ykubun] ) ;
            }
            partnin[nendo-STARTY][0][nenrei][1][ykubun]
              = partnin[nendo-STARTY][1][nenrei][1][ykubun] + partnin[nendo-STARTY][2][nenrei][1][ykubun] ; 
          }
          if ( nendo >= PARTYR1 ) {
            if ( nendo < PARTYR2 ) {
                if ( nendo == PARTYR2-1 ) {
                  for ( sei=1; sei<=2; sei++ ) {
                    ichigouni[PARTJJ-STARTY][sei][nenrei]
                      = ichigouni[nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][sei][nenrei][1][2] ;
                  }
                  for ( sei=3; sei<=4; sei++ ) {
                    ichigouni[PARTJJ-STARTY][sei][nenrei] 
                      = ichigouni[nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][2][nenrei][1][2] ;
                  }
                }
                for ( sei=1; sei<=2; sei++ ) {
                  ichigouni[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][1][1] ;
                }
                for ( sei=3; sei<=4; sei++ ) {
                  ichigouni[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][2][nenrei][1][1] ;
                }
            }
            else if ( nendo >= PARTYR2 ) {
                for ( sei=1; sei<=2; sei++ ) {
                  ichigouni[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][1][2] ;
                }
                for ( sei=3; sei<=4; sei++ ) {
                  ichigouni[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][2][nenrei][1][2] ;
                }
            }
            ichigouni[nendo-STARTY][0][nenrei]
              = ichigouni[nendo-STARTY][1][nenrei] + ichigouni[nendo-STARTY][2][nenrei] ;
            if ( nendo == PARTYR2-1 ) {
              ichigouni[PARTJJ-STARTY][0][nenrei]
                = ichigouni[PARTJJ-STARTY][1][nenrei] + ichigouni[PARTJJ-STARTY][2][nenrei] ;
            }
          }

          for ( ykubun=0; ykubun<=2; ykubun++ ) {
            for ( sei=1; sei<=2; sei++ ) {
              partnin[nendo-STARTY][sei][nenrei][3][ykubun]
                = kbetu_partnin[nendo-STARTY][sei][kubun][3][ykubun]
                * koyouj_m[4][nendo-STARTY][sei][nenrei] / kbetu_tankoj[nendo-STARTY][sei][kubun] ;
            }
            partnin[nendo-STARTY][3][nenrei][3][ykubun]
              = partnin[nendo-STARTY][2][nenrei][3][ykubun] 
                  * koyouj_m[4][nendo-STARTY][3][nenrei] / koyouj_m[4][nendo-STARTY][2][nenrei] ;
            partnin[nendo-STARTY][4][nenrei][3][ykubun]
              = partnin[nendo-STARTY][2][nenrei][3][ykubun] 
                  * koyouj_m[4][nendo-STARTY][4][nenrei] / koyouj_m[4][nendo-STARTY][2][nenrei] ;
            partnin[nendo-STARTY][0][nenrei][3][ykubun]
              = partnin[nendo-STARTY][1][nenrei][3][ykubun] + partnin[nendo-STARTY][2][nenrei][3][ykubun] ;
          }

          if ( ( MODE == 4 ) && ( nendo >= PARTYR1 ) ) {
            XEND = xend[8][nendo-STARTY] ;
            if ( XEND < 60 ) { XEND = 60 ; }

            if ( nenrei < XEND ) {
                for ( sei=1; sei<=4; sei++ ) {
                  if ( ichigouip[nendo-STARTY][sei][nenrei] + sangou[nendo-STARTY][sei][nenrei] > 0.0 ) {
                    partgenwari[nendo-STARTY][sei][nenrei][3][1]
                      = 1.0 - partnin[nendo-STARTY][sei][nenrei][3][1]
                         / ( ichigouip[nendo-STARTY][sei][nenrei] + sangou[nendo-STARTY][sei][nenrei] ) ;
                    partgenwari[nendo-STARTY][sei][nenrei][3][2]
                      = 1.0 - partnin[nendo-STARTY][sei][nenrei][3][2]
                         / ( ichigouip[nendo-STARTY][sei][nenrei] + sangou[nendo-STARTY][sei][nenrei] ) ;
                  }
                  else {
                    partgenwari[nendo-STARTY][sei][nenrei][3][1] = 1.0 ;
                    partgenwari[nendo-STARTY][sei][nenrei][3][2] = 1.0 ;
                  }
                  if ( ( partgenwari[nendo-STARTY][sei][nenrei][3][1] > 0 )
                         && ( partgenwari[nendo-STARTY][sei][nenrei][3][1] < 1.0 ) ) { 
                      partnin[nendo-STARTY][sei][nenrei][1][1]
                        += ichigouip[nendo-STARTY][sei][nenrei] * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][1] ) ;
                      partnin[nendo-STARTY][sei][nenrei][2][1]
                        = sangou[nendo-STARTY][sei][nenrei] * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][1] ) ;
                      partnin[nendo-STARTY][sei][nenrei][5][1]
                        = kyosai3[1][nendo-STARTY][sei][nenrei] * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][1] ) ;
                      partnin[nendo-STARTY][sei][nenrei][6][1]
                        = kyosai3[2][nendo-STARTY][sei][nenrei] * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][1] ) ;
                      partnin[nendo-STARTY][sei][nenrei][7][1]
                        = kyosai3[3][nendo-STARTY][sei][nenrei] * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][1] ) ;
                      partnin[nendo-STARTY][sei][nenrei][8][1]
                        = ( qkou12syu3[nendo-STARTY][sei][nenrei] + kou3syu3[nendo-STARTY][sei][nenrei] )
                            * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][1] ) ;
                      partnin[nendo-STARTY][sei][nenrei][3][1] = 0.0 ;

                  }
                  else if ( partgenwari[nendo-STARTY][sei][nenrei][3][1] < 0 ) { 
                      partgenwari[nendo-STARTY][sei][nenrei][3][1] = 0.0 ;
                      partnin[nendo-STARTY][sei][nenrei][1][1] = ichigouip[nendo-STARTY][sei][nenrei] ;
                      partnin[nendo-STARTY][sei][nenrei][2][1] = sangou[nendo-STARTY][sei][nenrei] ;
                      partnin[nendo-STARTY][sei][nenrei][5][1] = kyosai3[1][nendo-STARTY][sei][nenrei] ;
                      partnin[nendo-STARTY][sei][nenrei][6][1] = kyosai3[2][nendo-STARTY][sei][nenrei] ;
                      partnin[nendo-STARTY][sei][nenrei][7][1] = kyosai3[3][nendo-STARTY][sei][nenrei] ;
                      partnin[nendo-STARTY][sei][nenrei][8][1]
                        = qkou12syu3[nendo-STARTY][sei][nenrei] + kou3syu3[nendo-STARTY][sei][nenrei] ;
                      partnin[nendo-STARTY][sei][nenrei][1][0] = partnin[nendo-STARTY][sei][nenrei][1][1] ;
                      partnin[nendo-STARTY][sei][nenrei][2][0] = partnin[nendo-STARTY][sei][nenrei][2][1] ;
                      partnin[nendo-STARTY][sei][nenrei][5][0] = partnin[nendo-STARTY][sei][nenrei][5][1] ;
                      partnin[nendo-STARTY][sei][nenrei][6][0] = partnin[nendo-STARTY][sei][nenrei][6][1] ;
                      partnin[nendo-STARTY][sei][nenrei][7][0] = partnin[nendo-STARTY][sei][nenrei][7][1] ;
                      partnin[nendo-STARTY][sei][nenrei][8][0] = partnin[nendo-STARTY][sei][nenrei][8][1] ;
                  }
                  if ( ( partgenwari[nendo-STARTY][sei][nenrei][3][2] > 0 )
                         && ( partgenwari[nendo-STARTY][sei][nenrei][3][2] < 1.0 ) ) { 
                      partnin[nendo-STARTY][sei][nenrei][1][2]
                        += ichigouip[nendo-STARTY][sei][nenrei] * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][2] ) ;
                      partnin[nendo-STARTY][sei][nenrei][2][2]
                         = sangou[nendo-STARTY][sei][nenrei] * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][2] ) ;
                      partnin[nendo-STARTY][sei][nenrei][5][2]
                        = kyosai3[1][nendo-STARTY][sei][nenrei] * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][2] ) ;
                      partnin[nendo-STARTY][sei][nenrei][6][2]
                        = kyosai3[2][nendo-STARTY][sei][nenrei] * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][2] ) ;
                      partnin[nendo-STARTY][sei][nenrei][7][2]
                        = kyosai3[3][nendo-STARTY][sei][nenrei] * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][2] ) ;
                      partnin[nendo-STARTY][sei][nenrei][8][2]
                        = ( qkou12syu3[nendo-STARTY][sei][nenrei] + kou3syu3[nendo-STARTY][sei][nenrei] )
                            * ( 1.0 - partgenwari[nendo-STARTY][sei][nenrei][3][2] ) ;
                      partnin[nendo-STARTY][sei][nenrei][3][2] = 0.0 ;
                  }
                  else if ( partgenwari[nendo-STARTY][sei][nenrei][3][2] < 0 ) { 
                      partgenwari[nendo-STARTY][sei][nenrei][3][2] = 0.0 ;
                      partnin[nendo-STARTY][sei][nenrei][1][2] = ichigouip[nendo-STARTY][sei][nenrei] ;
                      partnin[nendo-STARTY][sei][nenrei][2][2] = sangou[nendo-STARTY][sei][nenrei] ;
                      partnin[nendo-STARTY][sei][nenrei][5][2] = kyosai3[1][nendo-STARTY][sei][nenrei] ;
                      partnin[nendo-STARTY][sei][nenrei][6][2] = kyosai3[2][nendo-STARTY][sei][nenrei] ;
                      partnin[nendo-STARTY][sei][nenrei][7][2] = kyosai3[3][nendo-STARTY][sei][nenrei] ;
                      partnin[nendo-STARTY][sei][nenrei][8][2]
                        = qkou12syu3[nendo-STARTY][sei][nenrei] + kou3syu3[nendo-STARTY][sei][nenrei] ;
                  }

                  if ( nendo == PARTYR2-1 ) {
                    ichigouip[PARTJJ-STARTY][sei][nenrei]
                      = ichigouip[nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][sei][nenrei][3][2] ;
                    ichigouni[PARTJJ-STARTY][sei][nenrei] = ichigouni[nendo-STARTY][sei][nenrei] ; 
                    ichigou[PARTJJ-STARTY][sei][nenrei]
                      = ichigouip[PARTJJ-STARTY][sei][nenrei] + ichigouni[PARTJJ-STARTY][sei][nenrei] ;
                    qkou12syu3[PARTJJ-STARTY][sei][nenrei]
                      = qkou12syu3[nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][sei][nenrei][3][2] ;
                    kou3syu3[PARTJJ-STARTY][sei][nenrei] 
                      = kou3syu3[nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][sei][nenrei][3][2] ;
                    for ( seido=1; seido<=7; seido++ ) {
                      kyosai3[seido][PARTJJ-STARTY][sei][nenrei]
                        = kyosai3[seido][nendo-STARTY][sei][nenrei] * partgenwari[nendo-STARTY][sei][nenrei][3][2] ;
                    }
                  }

                  if ( nendo < PARTYR2 ) { 
                    partnin[nendo-STARTY][sei][nenrei][1][0] = partnin[nendo-STARTY][sei][nenrei][1][1] ;
                    partnin[nendo-STARTY][sei][nenrei][2][0] = partnin[nendo-STARTY][sei][nenrei][2][1] ;
                    partnin[nendo-STARTY][sei][nenrei][5][0] = partnin[nendo-STARTY][sei][nenrei][5][1] ;
                    partnin[nendo-STARTY][sei][nenrei][6][0] = partnin[nendo-STARTY][sei][nenrei][6][1] ;
                    partnin[nendo-STARTY][sei][nenrei][7][0] = partnin[nendo-STARTY][sei][nenrei][7][1] ;
                    partnin[nendo-STARTY][sei][nenrei][8][0] = partnin[nendo-STARTY][sei][nenrei][8][1] ;
                    ichigouip[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][3][1] ;
                    qkou12syu3[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][3][1] ;
                    kou3syu3[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][3][1] ;
                    for ( seido=1; seido<=7; seido++ ) {
                      kyosai3[seido][nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][3][1] ;
                    }
                  }
                  else if ( nendo >= PARTYR2 ) { 
                    partnin[nendo-STARTY][sei][nenrei][1][0] = partnin[nendo-STARTY][sei][nenrei][1][2] ;
                    partnin[nendo-STARTY][sei][nenrei][2][0] = partnin[nendo-STARTY][sei][nenrei][2][2] ;
                    partnin[nendo-STARTY][sei][nenrei][5][0] = partnin[nendo-STARTY][sei][nenrei][5][2] ;
                    partnin[nendo-STARTY][sei][nenrei][6][0] = partnin[nendo-STARTY][sei][nenrei][6][2] ;
                    partnin[nendo-STARTY][sei][nenrei][7][0] = partnin[nendo-STARTY][sei][nenrei][7][2] ;
                    partnin[nendo-STARTY][sei][nenrei][8][0] = partnin[nendo-STARTY][sei][nenrei][8][2] ;
                    ichigouip[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][3][2] ;
                    qkou12syu3[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][3][2] ;
                    kou3syu3[nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][3][2] ;
                    for ( seido=1; seido<=7; seido++ ) {
                      kyosai3[seido][nendo-STARTY][sei][nenrei] *= partgenwari[nendo-STARTY][sei][nenrei][3][2] ;
                    }
                  }


                }
            }

            ichigouip[nendo-STARTY][2][nenrei]
              = ichigouip[nendo-STARTY][3][nenrei] + ichigouip[nendo-STARTY][4][nenrei] ;
            qkou12syu3[nendo-STARTY][2][nenrei] = qkou12syu3[nendo-STARTY][3][nenrei] ;
            kou3syu3[nendo-STARTY][2][nenrei] = kou3syu3[nendo-STARTY][3][nenrei] ;
            for ( seido=1; seido<=7; seido++ ) {
              kyosai3[seido][nendo-STARTY][2][nenrei] = kyosai3[seido][nendo-STARTY][3][nenrei] ; 
            }
            for ( ii=1; ii<=8; ii++ ) {
              partnin[nendo-STARTY][2][nenrei][ii][0]
                = partnin[nendo-STARTY][3][nenrei][ii][0] + partnin[nendo-STARTY][4][nenrei][ii][0] ;
              partnin[nendo-STARTY][2][nenrei][ii][1]
                = partnin[nendo-STARTY][3][nenrei][ii][1] + partnin[nendo-STARTY][4][nenrei][ii][1] ;
              partnin[nendo-STARTY][2][nenrei][ii][2]
                = partnin[nendo-STARTY][3][nenrei][ii][2] + partnin[nendo-STARTY][4][nenrei][ii][2] ;
            }
            if ( nendo == PARTYR2-1 ) {
              ichigouip[PARTJJ-STARTY][2][nenrei]
                = ichigouip[PARTJJ-STARTY][3][nenrei] + ichigouip[PARTJJ-STARTY][4][nenrei] ;
              ichigouni[PARTJJ-STARTY][2][nenrei]
                = ichigouni[PARTJJ-STARTY][3][nenrei] + ichigouni[PARTJJ-STARTY][4][nenrei] ;
              ichigou[PARTJJ-STARTY][2][nenrei]
                = ichigou[PARTJJ-STARTY][3][nenrei] + ichigou[PARTJJ-STARTY][4][nenrei] ;
              qkou12syu3[PARTJJ-STARTY][2][nenrei] = qkou12syu3[PARTJJ-STARTY][3][nenrei] ;
              kou3syu3[PARTJJ-STARTY][2][nenrei] = kou3syu3[PARTJJ-STARTY][3][nenrei] ;
              for ( seido=1; seido<=7; seido++ ) {
                kyosai3[seido][PARTJJ-STARTY][2][nenrei] = kyosai3[seido][PARTJJ-STARTY][3][nenrei] ; 
              }
            }
            ichigouip[nendo-STARTY][0][nenrei]
              = ichigouip[nendo-STARTY][1][nenrei] + ichigouip[nendo-STARTY][2][nenrei] ;
            qkou12syu3[nendo-STARTY][0][nenrei]
              = qkou12syu3[nendo-STARTY][1][nenrei] + qkou12syu3[nendo-STARTY][2][nenrei] ;
            kou3syu3[nendo-STARTY][0][nenrei]
              = kou3syu3[nendo-STARTY][1][nenrei] + kou3syu3[nendo-STARTY][2][nenrei] ;
            for ( seido=1; seido<=7; seido++ ) {
              kyosai3[seido][nendo-STARTY][0][nenrei]
                = kyosai3[seido][nendo-STARTY][1][nenrei] + kyosai3[seido][nendo-STARTY][2][nenrei] ;
            }
            for ( ii=1; ii<=8; ii++ ) {
              partnin[nendo-STARTY][0][nenrei][ii][0]
                = partnin[nendo-STARTY][1][nenrei][ii][0] + partnin[nendo-STARTY][2][nenrei][ii][0] ;
              partnin[nendo-STARTY][0][nenrei][ii][1]
                = partnin[nendo-STARTY][1][nenrei][ii][1] + partnin[nendo-STARTY][2][nenrei][ii][1] ;
              partnin[nendo-STARTY][0][nenrei][ii][2]
                = partnin[nendo-STARTY][1][nenrei][ii][2] + partnin[nendo-STARTY][2][nenrei][ii][2] ;
            }
            if ( nendo == PARTYR2-1 ) {
              ichigouip[PARTJJ-STARTY][0][nenrei]
                = ichigouip[PARTJJ-STARTY][1][nenrei] + ichigouip[PARTJJ-STARTY][2][nenrei] ;
              ichigouni[PARTJJ-STARTY][0][nenrei]
                = ichigouni[PARTJJ-STARTY][1][nenrei] + ichigouni[PARTJJ-STARTY][2][nenrei] ;
              ichigou[PARTJJ-STARTY][0][nenrei]
                = ichigou[PARTJJ-STARTY][1][nenrei] + ichigou[PARTJJ-STARTY][2][nenrei] ;
              qkou12syu3[PARTJJ-STARTY][0][nenrei]
                = qkou12syu3[PARTJJ-STARTY][1][nenrei] + qkou12syu3[PARTJJ-STARTY][2][nenrei] ;
              kou3syu3[PARTJJ-STARTY][0][nenrei]
                = kou3syu3[PARTJJ-STARTY][1][nenrei] + kou3syu3[PARTJJ-STARTY][2][nenrei] ;
              for ( seido=1; seido<=7; seido++ ) {
                kyosai3[seido][PARTJJ-STARTY][0][nenrei]
                  = kyosai3[seido][PARTJJ-STARTY][1][nenrei] + kyosai3[seido][PARTJJ-STARTY][2][nenrei] ; 
              }
            }
          }

        }
      }

  }



  for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {
    for ( sei=0; sei<=4; sei++ ) {
      for ( nenrei=15; nenrei<=79; nenrei++ ) {
        for ( ykubun=1; ykubun<=2; ykubun++ ) {
          partnin[nendo-STARTY][sei][nenrei][0][ykubun] = 0.0 ;
          for ( pkubun=1; pkubun<=3; pkubun++ ) {
            partnin[nendo-STARTY][sei][nenrei][0][ykubun]
              += partnin[nendo-STARTY][sei][nenrei][pkubun][ykubun] ;
          }
        }
      }
    }
  }

  for ( nendo=PARTYR1; nendo<=KE; nendo++ ) {
    for ( sei=0; sei<=4; sei++ ) {
      for ( nenrei=15; nenrei<=79; nenrei++ ) {
        for ( pkubun=0; pkubun<=3; pkubun++ ) {
          if ( nendo < PARTYR2 ) {
            partnin[nendo-STARTY][sei][nenrei][pkubun][0] = partnin[nendo-STARTY][sei][nenrei][pkubun][1] ;
          }
          else if ( nendo >= PARTYR2 ) {
            partnin[nendo-STARTY][sei][nenrei][pkubun][0] = partnin[nendo-STARTY][sei][nenrei][pkubun][2] ;
          }
        }
      }
    }
  }


  for ( nendo=PARTYR1; nendo<=KE; nendo++ ) {
    for ( sei=0; sei<=4; sei++ ) {
      for ( nenrei=15; nenrei<=79; nenrei++ ) {

          if ( nendo < PARTYR2 ) {
            koyouj_m[8][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][1] ;
            koyouj_m[9][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][1] ;
            koyouj_c[8][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][1] + partnin[nendo-STARTY][sei][nenrei][0][1] ) / 2.0 ;
            koyouj_c[9][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][1] + partnin[nendo-STARTY][sei][nenrei][0][1] ) / 2.0 ;
            soroudh_m[8][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][1] * 100.0 ;
            soroudh_m[9][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][1] * 100.0 ;
            soroudh_c[8][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][1] + partnin[nendo-STARTY][sei][nenrei][0][1] ) * 50.0 ;
            soroudh_c[9][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][1] + partnin[nendo-STARTY][sei][nenrei][0][1] ) * 50.0 ;
          }
          else if ( nendo == PARTYR2 ) {
            koyouj_m[8][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][2] ;
            koyouj_m[9][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][2] ;
            koyouj_c[8][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][1] + partnin[nendo-STARTY][sei][nenrei][0][2] ) / 2.0 ;
            koyouj_c[9][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][1] + partnin[nendo-STARTY][sei][nenrei][0][2] ) / 2.0 ;
            soroudh_m[8][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][2] * 100.0 ;
            soroudh_m[9][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][2] * 100.0 ;
            soroudh_c[8][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][1] + partnin[nendo-STARTY][sei][nenrei][0][2] ) * 50.0 ;
            soroudh_c[9][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][1] + partnin[nendo-STARTY][sei][nenrei][0][2] ) * 50.0 ;
          }
          else if ( nendo > PARTYR2 ) {
            koyouj_m[8][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][2] ;
            koyouj_m[9][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][2] ;
            koyouj_c[8][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][2] + partnin[nendo-STARTY][sei][nenrei][0][2] ) / 2.0 ;
            koyouj_c[9][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][2] + partnin[nendo-STARTY][sei][nenrei][0][2] ) / 2.0 ;
            soroudh_m[8][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][2] * 100.0 ;
            soroudh_m[9][nendo-STARTY][sei][nenrei] += partnin[nendo-STARTY][sei][nenrei][0][2] * 100.0 ;
            soroudh_c[8][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][2] + partnin[nendo-STARTY][sei][nenrei][0][2] ) * 50.0 ;
            soroudh_c[9][nendo-STARTY][sei][nenrei]
              += ( partnin[nendo-1-STARTY][sei][nenrei][0][2] + partnin[nendo-STARTY][sei][nenrei][0][2] ) * 50.0 ;
          }

      }
    }
  }


  for ( nendo=PARTJJ; nendo<=KE; nendo++ ) {
    if ( ( nendo<= PARTJJ ) || ( nendo>=PARTYR1 ) ) {
      XEND = xend[8][nendo-STARTY] ;
      if ( XEND < 60 ) { XEND = 60 ; }
      for ( sei=0; sei<=4; sei++ ) {
        for ( nenrei=15; nenrei<=100; nenrei++ ) {
          ichigou[nendo-STARTY][sei][nenrei] =
            ichigouip[nendo-STARTY][sei][nenrei] + ichigouni[nendo-STARTY][sei][nenrei] ;
        }
        for ( nenrei=20; nenrei<=XEND-1; nenrei++ ) {
          qkounen3[nendo-STARTY][sei][nenrei]
            = qkou12syu3[nendo-STARTY][sei][nenrei] + kou3syu3[nendo-STARTY][sei][nenrei] ;
          kou12syu3[nendo-STARTY][sei][nenrei] = qkou12syu3[nendo-STARTY][sei][nenrei] ;
          kounen3[nendo-STARTY][sei][nenrei] = qkounen3[nendo-STARTY][sei][nenrei] ;
          for ( seido=4; seido<=7; seido++ ) {
            kou12syu3[nendo-STARTY][sei][nenrei] += kyosai3[seido][nendo-STARTY][sei][nenrei] ;
            kounen3[nendo-STARTY][sei][nenrei] += kyosai3[seido][nendo-STARTY][sei][nenrei] ;
          }
          sangou[nendo-STARTY][sei][nenrei] = kounen3[nendo-STARTY][sei][nenrei] ;
          for ( seido=1; seido<=3; seido++ ) { 
            sangou[nendo-STARTY][sei][nenrei] += kyosai3[seido][nendo-STARTY][sei][nenrei] ;
          }
        }
      }
    }
  }


  if ( PARTK2 >= 8 ) {
      simlpart_4(); 
  }



}



void simlpart_4(void) 
{


/*  変数定義  */
    int     ii      ;
    double  TMP     ;
    double  TMQ     ;
    int     XEND ;
    char    filename[250]    ; 


        sprintf(filename, "/rev26/wakuc/data/part/tyouken.csv");
        if ((fp_part = fopen(filename, "r")) == NULL) {
            fprintf(stderr, "パート賃金要件ファイルを開けません!\n");
            exit (2);
        }

          karayomi( fp_part );
          for ( ii=1; ii<=6; ii++) {
              read_csv( buffer, fp_part, &data_number );
              if ( PARTK2 == 8 ) {
                  tyouken[ii][KIJUN-STARTY] = buffer[1];
              }
              else if ( PARTK2 == 9 ) {
                  tyouken[ii][KIJUN-STARTY] = buffer[2];
              }
              else {
                  tyouken[ii][KIJUN-STARTY] = 1.0 ; 
              }
          }

          karayomi( fp_part );
          for ( ii=1; ii<=6; ii++) {
              read_csv( buffer, fp_part, &data_number );
              if ( PARTK2 == 8 ) {
                  syouken[ii][KIJUN-STARTY] = buffer[1];
              }
              else if ( PARTK2 == 9 ) {
                  syouken[ii][KIJUN-STARTY] = buffer[2];
              }
              else {
                  syouken[ii][KIJUN-STARTY] = 0.0 ; 
              }
          }

          fclose( fp_part );


    for ( nendo=KIJUN+1; nendo<=KE+1; nendo++ ) {
      for ( ii=1; ii<=6; ii++ ) {
        tyouken[ii][nendo-STARTY] = tyouken[ii][nendo-1-STARTY] ;
      }
      tyouken[2][nendo-STARTY] = tyouken[4][nendo-STARTY] * tankor_all_m[4][nendo-STARTY]
                               + tyouken[5][nendo-STARTY] * tankor_all_m[5][nendo-STARTY]
                               + tyouken[6][nendo-STARTY] * tankor_all_m[6][nendo-STARTY] ; 
    }


    for ( nendo=KS; nendo<=KE+1; nendo++ ) {
      for ( sei=0; sei<=4; sei++ ) {
        for ( nenrei=15; nenrei<=120; nenrei++ ) {
            tmae[31][nendo-STARTY][sei][nenrei] = partnin[nendo-STARTY][sei][nenrei][0][0] ;
            tmae[32][nendo-STARTY][sei][nenrei] = partnin[nendo-STARTY][sei][nenrei][0][1] ;
            tmae[33][nendo-STARTY][sei][nenrei] = partnin[nendo-STARTY][sei][nenrei][1][1] ;
            tmae[34][nendo-STARTY][sei][nenrei] = partnin[nendo-STARTY][sei][nenrei][2][1] ;
            tmae[35][nendo-STARTY][sei][nenrei] = partnin[nendo-STARTY][sei][nenrei][3][1] ;
            tmae[41][nendo-STARTY][sei][nenrei] = partnin[nendo-STARTY][sei][nenrei][8][1] ;
            tmae[42][nendo-STARTY][sei][nenrei] = partnin[nendo-STARTY][sei][nenrei][5][1] ;
            tmae[43][nendo-STARTY][sei][nenrei] = partnin[nendo-STARTY][sei][nenrei][6][1] ;
            tmae[44][nendo-STARTY][sei][nenrei] = partnin[nendo-STARTY][sei][nenrei][7][1] ;
        }
      }
    }

    for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {
      for ( nenrei=15; nenrei<=69; nenrei++ ) {
        for ( sei=1; sei<=4; sei++ ) {
            tmae[51][nendo-STARTY][sei][nenrei] = koyouj_m[3][nendo-STARTY][sei][nenrei]
                * kounenteki_m[1][nendo-STARTY] * kounen_cho[nendo-STARTY][sei][nenrei] 
                  + kyosai[1][nendo-STARTY][sei][nenrei] + kyosai[2][nendo-STARTY][sei][nenrei]
                  + kyosai[3][nendo-STARTY][sei][nenrei] ;
            tmae[52][nendo-STARTY][sei][nenrei] = koyouj_m[2][nendo-STARTY][sei][nenrei]
                * kounenteki_m[2][nendo-STARTY] * kounen_cho[nendo-STARTY][sei][nenrei] ; 
            tjwari[4] = koyouj_m[4][nendo-STARTY][sei][nenrei] * kounenteki_m[4][nendo-STARTY] ;
            tjwari[5] = koyouj_m[5][nendo-STARTY][sei][nenrei] * kounenteki_m[5][nendo-STARTY] ;
            tjwari[6] = koyouj_m[6][nendo-STARTY][sei][nenrei] * kounenteki_m[6][nendo-STARTY] ;
            tjwari[0] = tjwari[4] + tjwari[5] + tjwari[6] ; 
            if ( tjwari[0] > 0.0 ) {
              tmae[54][nendo-STARTY][sei][nenrei] = tmae[52][nendo-STARTY][sei][nenrei] 
                                                    * tjwari[4] / tjwari[0] ; 
              tmae[55][nendo-STARTY][sei][nenrei] = tmae[52][nendo-STARTY][sei][nenrei] 
                                                    * tjwari[5] / tjwari[0] ; 
              tmae[56][nendo-STARTY][sei][nenrei] = tmae[52][nendo-STARTY][sei][nenrei] 
                                                    * tjwari[6] / tjwari[0] ; 
            }
            else {
              tmae[54][nendo-STARTY][sei][nenrei] = 0.0 ;
              tmae[55][nendo-STARTY][sei][nenrei] = 0.0 ;
              tmae[56][nendo-STARTY][sei][nenrei] = 0.0 ;
            }
        }
        for ( ii=51; ii<=56; ii++ ) {
          tmae[ii][nendo-STARTY][2][nenrei]
            = tmae[ii][nendo-STARTY][3][nenrei] + tmae[ii][nendo-STARTY][4][nenrei] ;
          tmae[ii][nendo-STARTY][0][nenrei]
            = tmae[ii][nendo-STARTY][1][nenrei] + tmae[ii][nendo-STARTY][2][nenrei] ;
        }
      }
    }

    for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {
      for ( nenrei=15; nenrei<=69; nenrei++ ) {
        for ( sei=1; sei<=4; sei++ ) {
            tato[51][nendo-STARTY][sei][nenrei] 
              = koyouj_m[3][nendo-STARTY][sei][nenrei] * tyouken[1][nendo-STARTY] 
                  + kyosai[1][nendo-STARTY][sei][nenrei] + kyosai[2][nendo-STARTY][sei][nenrei]
                  + kyosai[3][nendo-STARTY][sei][nenrei] ; 
            TMQ = koyouj_m[3][nendo-STARTY][sei][nenrei]
                  * ( tyouken[1][nendo-STARTY] - kounenteki_m[1][nendo-STARTY+1] ) ; 
            if ( tato[51][nendo-STARTY][sei][nenrei] < tmae[51][nendo-STARTY][sei][nenrei] + TMQ ) {
               tato[51][nendo-STARTY][sei][nenrei] = tmae[51][nendo-STARTY][sei][nenrei] + TMQ ;
            }
            if ( tato[51][nendo-STARTY][sei][nenrei] < tmae[51][nendo-STARTY][sei][nenrei] ) { 
               fprintf(fp_err, "適用拡大エラー%d、%d、%d\n", nendo, sei, nenrei );
            }
            TMQ = 0.0 ;
            tato[54][nendo-STARTY][sei][nenrei] 
              = koyouj_m[4][nendo-STARTY][sei][nenrei] * tyouken[4][nendo-STARTY] ;
            tato[55][nendo-STARTY][sei][nenrei] 
              = koyouj_m[5][nendo-STARTY][sei][nenrei] * tyouken[5][nendo-STARTY] ;
            tato[56][nendo-STARTY][sei][nenrei] 
              = koyouj_m[6][nendo-STARTY][sei][nenrei] * tyouken[6][nendo-STARTY] ;
            tato[52][nendo-STARTY][sei][nenrei] = tato[54][nendo-STARTY][sei][nenrei] 
              + tato[55][nendo-STARTY][sei][nenrei] + tato[56][nendo-STARTY][sei][nenrei] ;
            tato[36][nendo-STARTY][sei][nenrei] = 
              ( tato[51][nendo-STARTY][sei][nenrei] - tmae[51][nendo-STARTY][sei][nenrei] ) 
              + ( tato[52][nendo-STARTY][sei][nenrei] - tmae[52][nendo-STARTY][sei][nenrei] ) ;
            if ( tato[36][nendo-STARTY][sei][nenrei] < 0.0 ) { 
               fprintf(fp_err, "適用拡大エラー%d、%d、%d\n", nendo, sei, nenrei );
               tato[36][nendo-STARTY][sei][nenrei] = 0.0 ; 
            }
            if ( tato[36][nendo-STARTY][sei][nenrei] > 0.0 ) {
              if ( tato[36][nendo-STARTY][sei][nenrei] < tmae[32][nendo-STARTY][sei][nenrei] ) { 
                 fprintf(fp_err, "適用拡大エラー１%d、%d、%d\n", nendo, sei, nenrei );
                 tato[37][nendo-STARTY][sei][nenrei]
                   = tmae[32][nendo-STARTY][sei][nenrei] / tato[36][nendo-STARTY][sei][nenrei] ; 
                 tato[36][nendo-STARTY][sei][nenrei] = tmae[32][nendo-STARTY][sei][nenrei] ; 
              }
            }
        }
        for ( ii=51; ii<=56; ii++ ) {
          tato[ii][nendo-STARTY][2][nenrei]
            = tato[ii][nendo-STARTY][3][nenrei] + tato[ii][nendo-STARTY][4][nenrei] ;
          tato[ii][nendo-STARTY][0][nenrei]
            = tato[ii][nendo-STARTY][1][nenrei] + tato[ii][nendo-STARTY][2][nenrei] ;
        }
        tato[36][nendo-STARTY][2][nenrei]
          = tato[36][nendo-STARTY][3][nenrei] + tato[36][nendo-STARTY][4][nenrei] ;
        tato[36][nendo-STARTY][0][nenrei]
          = tato[36][nendo-STARTY][1][nenrei] + tato[36][nendo-STARTY][2][nenrei] ;
      }
    }



  for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {
    XEND = xend[8][nendo-STARTY] ; 
    if ( XEND < 60 ) { XEND = 60; }
    for ( nenrei=20; nenrei<=XEND-1; nenrei++ ) {

      if ( tmae[33][nendo-STARTY][1][nenrei] + tmae[34][nendo-STARTY][1][nenrei] > 0 ) {
        tato[38][nendo-STARTY][1][nenrei]
          = tato[36][nendo-STARTY][1][nenrei] * tmae[34][nendo-STARTY][1][nenrei]
            / ( tmae[33][nendo-STARTY][1][nenrei] + tmae[34][nendo-STARTY][1][nenrei] ) ;
      }
      else {
        tato[38][nendo-STARTY][1][nenrei]
          = tato[36][nendo-STARTY][1][nenrei] * tmae[20][nendo-STARTY][1][nenrei]
            / ( tmae[10][nendo-STARTY][1][nenrei] + tmae[20][nendo-STARTY][1][nenrei] ) ;
      }

      if ( tmae[20][nendo-STARTY][1][nenrei] > 0.0 ) {
        partgenwari[nendo-STARTY][1][nenrei][2][2]
          = ( tmae[20][nendo-STARTY][1][nenrei] - tato[38][nendo-STARTY][1][nenrei] )
            / tmae[20][nendo-STARTY][1][nenrei] ; 
      }
      else { 
        partgenwari[nendo-STARTY][1][nenrei][2][2] = 0.0 ;
      }

            if ( ( partgenwari[nendo-STARTY][1][nenrei][2][2] < 0 ) && ( nendo < KE ) ) { 
              printf("適用拡大減算エラー\n" ) ;
              fprintf(fp_err, "適用拡大減算エラー\n" ) ;
              tato[38][nendo-STARTY][1][nenrei] = tmae[20][nendo-STARTY][1][nenrei] ;
            }

      for ( ii=11; ii<=21; ii++ ) {
        tato[ii][nendo-STARTY][1][nenrei]
          = tmae[ii][nendo-STARTY][1][nenrei] * partgenwari[nendo-STARTY][1][nenrei][2][2] ;
      }

    }
  }


  for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {
    XEND = xend[8][nendo-STARTY] ; 
    if ( XEND < 60 ) { XEND = 60; }
    for ( nenrei=20; nenrei<=XEND-1; nenrei++ ) {

      if ( nenrei < 25 ) {
        if ( tmae[32][nendo-STARTY][3][nenrei] > 0.0 ) {
          tato[20][nendo-STARTY][3][nenrei] = tmae[20][nendo-STARTY][3][nenrei] 
              - ( tmae[34][nendo-STARTY][3][nenrei]
                  * tato[36][nendo-STARTY][3][nenrei] / tmae[32][nendo-STARTY][3][nenrei] ) ; 
        }
        else { 
          tato[20][nendo-STARTY][3][nenrei] = 0.0 ;
        }
      }
      else { 
        TMP = jinko_m[KIJUN-STARTY][3][nenrei] - nigou[KIJUN-STARTY][3][nenrei] ;
        TMQ = jinko_m[nendo-STARTY][3][nenrei] - nigou[nendo-STARTY][3][nenrei] 
              - tato[36][nendo-STARTY][3][nenrei] ; 
        if (( TMP > 0.0 ) && ( TMQ > 0.0 )) {
          if ( MODESAN == 1 ) { 
            tato[20][nendo-STARTY][3][nenrei] = TMQ * sangou[KIJUN-STARTY][3][nenrei] / TMP 
              * ( ( nigou[nendo-STARTY][1][nenrei]
                      + tato[51][nendo-STARTY][1][nenrei] - tmae[51][nendo-STARTY][1][nenrei] 
                      + tato[55][nendo-STARTY][1][nenrei] - tmae[55][nendo-STARTY][1][nenrei] )
                   / jinko_m[nendo-STARTY][1][nenrei] )
              / ( nigou[KIJUN-STARTY][1][nenrei] / jinko_m[KIJUN-STARTY][1][nenrei] ) ;
            if ( tato[20][nendo-STARTY][3][nenrei] > TMQ - ichigouni[nendo-STARTY][3][nenrei] ) {
              tato[20][nendo-STARTY][3][nenrei] = TMQ - ichigouni[nendo-STARTY][3][nenrei] ;
            }
          }
        }
        else { 
          tato[20][nendo-STARTY][3][nenrei] = 0.0 ;
        }
      }
      tato[20][nendo-STARTY][4][nenrei] = 0.0 ; 
      tato[20][nendo-STARTY][2][nenrei] = tato[20][nendo-STARTY][3][nenrei] ;

      tato[21][nendo-STARTY][3][nenrei] = tato[20][nendo-STARTY][3][nenrei]
        * ( kounen[nendo-STARTY][1][nenrei] + tato[36][nendo-STARTY][1][nenrei] ) 
        / ( nigou[nendo-STARTY][1][nenrei] + tato[36][nendo-STARTY][1][nenrei] ) ; 
      tato[21][nendo-STARTY][4][nenrei] = 0.0 ;
      tato[21][nendo-STARTY][2][nenrei] = tato[21][nendo-STARTY][3][nenrei] ;
      tato[12][nendo-STARTY][3][nenrei] = tato[20][nendo-STARTY][3][nenrei]
        * kou3syu[nendo-STARTY][1][nenrei]
        / ( nigou[nendo-STARTY][1][nenrei] + tato[36][nendo-STARTY][1][nenrei] ) ; 
      tato[12][nendo-STARTY][4][nenrei] = 0.0 ;
      tato[12][nendo-STARTY][2][nenrei] = tato[12][nendo-STARTY][3][nenrei] ;
      for ( sei=2; sei<=4; sei++ ) { 
        tato[11][nendo-STARTY][sei][nenrei]
          = tato[21][nendo-STARTY][sei][nenrei] - tato[12][nendo-STARTY][sei][nenrei] ;
      }

      for ( seido=1; seido<=3; seido++ ) {
        tato[seido+12][nendo-STARTY][3][nenrei] = tato[20][nendo-STARTY][3][nenrei]
          * kyosai[seido][nendo-STARTY][1][nenrei]
          / ( nigou[nendo-STARTY][1][nenrei] + tato[36][nendo-STARTY][1][nenrei] ) ;
        tato[seido+12][nendo-STARTY][4][nenrei] = 0.0 ;
        tato[seido+12][nendo-STARTY][2][nenrei] = tato[seido+12][nendo-STARTY][3][nenrei] ;
      }

      for ( ii=16; ii<=19; ii++ ) {
        if ( tmae[21][nendo-STARTY][3][nenrei] > 0.0 ) {
          tato[ii][nendo-STARTY][3][nenrei] = tmae[ii][nendo-STARTY][3][nenrei] 
            * tato[21][nendo-STARTY][3][nenrei] / tmae[21][nendo-STARTY][3][nenrei] ;
        }
        else { 
          tato[ii][nendo-STARTY][3][nenrei] = 0.0 ;
        }
        tato[ii][nendo-STARTY][4][nenrei] = 0.0 ;
        tato[ii][nendo-STARTY][2][nenrei] = tato[ii][nendo-STARTY][3][nenrei] ;
      }

      for ( ii=11; ii<=21; ii++ ) {
        tato[ii][nendo-STARTY][0][nenrei]
          = tato[ii][nendo-STARTY][1][nenrei] + tato[ii][nendo-STARTY][2][nenrei] ;
      }

    }
  }


  for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {
    XEND = xend[8][nendo-STARTY] ; 
    if ( XEND < 60 ) { XEND = 60; }

    for ( nenrei=20; nenrei<=XEND-1; nenrei++ ) {
      for ( sei=1; sei<=4; sei++ ) {
        TMP = jinko_m[nendo-STARTY][sei][nenrei] - mika_soto1[nendo-STARTY][sei][nenrei] 
                - nigou[nendo-STARTY][sei][nenrei] - tato[36][nendo-STARTY][sei][nenrei] 
                - tato[20][nendo-STARTY][sei][nenrei] - ichigouni[nendo-STARTY][sei][nenrei] ;
          if ( tato[8][nendo-STARTY][sei][nenrei] < 0.0 ) { 
            TMP += tato[8][nendo-STARTY][sei][nenrei] ;
          }
        if ( TMP < 0.0 ) { 
            if ( sei == 3 ) { 
              tato[8][nendo-STARTY][4][nenrei] = TMP ; 
              tato[9][nendo-STARTY][3][nenrei] = 0.0 ;
            }
            else if ( nendo < KE ) {
              fprintf(fp_err, "適用拡大一般エラー%d、%d、%d\n", nendo, sei, nenrei );
              printf("適用拡大一般エラー%d、%d、%d\n", nendo, sei, nenrei );
              tato[9][nendo-STARTY][sei][nenrei] = 0.0 ;
            }
        }
        else {
          tato[9][nendo-STARTY][sei][nenrei] = TMP ;
        }
      }
      tato[9][nendo-STARTY][2][nenrei]
        = tato[9][nendo-STARTY][3][nenrei] + tato[9][nendo-STARTY][4][nenrei] ;
      tato[9][nendo-STARTY][0][nenrei]
        = tato[9][nendo-STARTY][1][nenrei] + tato[9][nendo-STARTY][2][nenrei] ;
    }

    for ( sei=0; sei<=4; sei++ ) {
      for ( nenrei=20; nenrei<=69; nenrei++ ) {
        tato[10][nendo-STARTY][sei][nenrei]
          = tato[9][nendo-STARTY][sei][nenrei] + ichigouni[nendo-STARTY][sei][nenrei] ;
      }
    }

  }


  for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {
    XEND = xend[8][nendo-STARTY] ; 
    if ( XEND < 60 ) { XEND = 60; }

    for ( sei=0; sei<=4; sei++ ) {

      for ( nenrei=15; nenrei<=19; nenrei++ ) {

        partnin[nendo-STARTY][sei][nenrei][0][2] = tato[36][nendo-STARTY][sei][nenrei] ;
        partnin[nendo-STARTY][sei][nenrei][11][2]
          = tato[51][nendo-STARTY][sei][nenrei] - tmae[51][nendo-STARTY][sei][nenrei] ;
        partnin[nendo-STARTY][sei][nenrei][14][2]
          = tato[54][nendo-STARTY][sei][nenrei] - tmae[54][nendo-STARTY][sei][nenrei] ;
        partnin[nendo-STARTY][sei][nenrei][15][2]
          = tato[55][nendo-STARTY][sei][nenrei] - tmae[55][nendo-STARTY][sei][nenrei] ;
        partnin[nendo-STARTY][sei][nenrei][16][2]
          = tato[56][nendo-STARTY][sei][nenrei] - tmae[56][nendo-STARTY][sei][nenrei] ;
        if ( tato[37][nendo-STARTY][sei][nenrei] > 1.0 ) { 
          partnin[nendo-STARTY][sei][nenrei][11][2] *= tato[37][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][14][2] *= tato[37][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][15][2] *= tato[37][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][16][2] *= tato[37][nendo-STARTY][sei][nenrei] ;
        }

        partnin[nendo-STARTY][sei][nenrei][3][2] = tato[36][nendo-STARTY][sei][nenrei] ;

        if ( nendo >= PARTYR2 ) {
          partnin[nendo-STARTY][sei][nenrei][0][0] = tato[36][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][11][0]
            = tato[51][nendo-STARTY][sei][nenrei] - tmae[51][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][14][0]
            = tato[54][nendo-STARTY][sei][nenrei] - tmae[54][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][15][0]
            = tato[55][nendo-STARTY][sei][nenrei] - tmae[55][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][16][0]
            = tato[56][nendo-STARTY][sei][nenrei] - tmae[56][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][3][0] = tato[36][nendo-STARTY][sei][nenrei] ;
          if ( tato[37][nendo-STARTY][sei][nenrei] > 1.0 ) { 
            partnin[nendo-STARTY][sei][nenrei][11][0] *= tato[37][nendo-STARTY][sei][nenrei] ;
            partnin[nendo-STARTY][sei][nenrei][14][0] *= tato[37][nendo-STARTY][sei][nenrei] ;
            partnin[nendo-STARTY][sei][nenrei][15][0] *= tato[37][nendo-STARTY][sei][nenrei] ;
            partnin[nendo-STARTY][sei][nenrei][16][0] *= tato[37][nendo-STARTY][sei][nenrei] ;
          }
        }


      }

      for ( nenrei=20; nenrei<=69; nenrei++ ) {

        partnin[nendo-STARTY][sei][nenrei][0][2] = tato[36][nendo-STARTY][sei][nenrei] ;
        partnin[nendo-STARTY][sei][nenrei][11][2]
          = tato[51][nendo-STARTY][sei][nenrei] - tmae[51][nendo-STARTY][sei][nenrei] ;
        partnin[nendo-STARTY][sei][nenrei][14][2]
          = tato[54][nendo-STARTY][sei][nenrei] - tmae[54][nendo-STARTY][sei][nenrei] ;
        partnin[nendo-STARTY][sei][nenrei][15][2]
          = tato[55][nendo-STARTY][sei][nenrei] - tmae[55][nendo-STARTY][sei][nenrei] ;
        partnin[nendo-STARTY][sei][nenrei][16][2]
          = tato[56][nendo-STARTY][sei][nenrei] - tmae[56][nendo-STARTY][sei][nenrei] ;
        if ( tato[37][nendo-STARTY][sei][nenrei] > 1.0 ) {
          partnin[nendo-STARTY][sei][nenrei][11][2] *= tato[37][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][14][2] *= tato[37][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][15][2] *= tato[37][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][16][2] *= tato[37][nendo-STARTY][sei][nenrei] ;
        }

        partnin[nendo-STARTY][sei][nenrei][1][2] 
          = tmae[10][nendo-STARTY][sei][nenrei] - tato[10][nendo-STARTY][sei][nenrei] ; 

        partnin[nendo-STARTY][sei][nenrei][2][2] 
          = tmae[20][nendo-STARTY][sei][nenrei] - tato[20][nendo-STARTY][sei][nenrei] ; 
        partnin[nendo-STARTY][sei][nenrei][8][2] 
          = tmae[21][nendo-STARTY][sei][nenrei] - tato[21][nendo-STARTY][sei][nenrei] ; 
        partnin[nendo-STARTY][sei][nenrei][5][2] 
          = tmae[13][nendo-STARTY][sei][nenrei] - tato[13][nendo-STARTY][sei][nenrei] ; 
        partnin[nendo-STARTY][sei][nenrei][6][2] 
          = tmae[14][nendo-STARTY][sei][nenrei] - tato[14][nendo-STARTY][sei][nenrei] ; 
        partnin[nendo-STARTY][sei][nenrei][7][2] 
          = tmae[15][nendo-STARTY][sei][nenrei] - tato[15][nendo-STARTY][sei][nenrei] ; 

        if ( nenrei >= XEND ) {
          partnin[nendo-STARTY][sei][nenrei][3][2] = tato[36][nendo-STARTY][sei][nenrei] ;
        }

        if ( nendo >= PARTYR2 ) {

          partnin[nendo-STARTY][sei][nenrei][0][0] = tato[36][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][11][0]
            = tato[51][nendo-STARTY][sei][nenrei] - tmae[51][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][14][0]
            = tato[54][nendo-STARTY][sei][nenrei] - tmae[54][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][15][0]
            = tato[55][nendo-STARTY][sei][nenrei] - tmae[55][nendo-STARTY][sei][nenrei] ;
          partnin[nendo-STARTY][sei][nenrei][16][0]
            = tato[56][nendo-STARTY][sei][nenrei] - tmae[56][nendo-STARTY][sei][nenrei] ;
          if ( tato[37][nendo-STARTY][sei][nenrei] > 1.0 ) { 
            partnin[nendo-STARTY][sei][nenrei][11][0] *= tato[37][nendo-STARTY][sei][nenrei] ;
            partnin[nendo-STARTY][sei][nenrei][14][0] *= tato[37][nendo-STARTY][sei][nenrei] ;
            partnin[nendo-STARTY][sei][nenrei][15][0] *= tato[37][nendo-STARTY][sei][nenrei] ;
            partnin[nendo-STARTY][sei][nenrei][16][0] *= tato[37][nendo-STARTY][sei][nenrei] ;
          }

          partnin[nendo-STARTY][sei][nenrei][1][0] 
            = tmae[10][nendo-STARTY][sei][nenrei] - tato[10][nendo-STARTY][sei][nenrei] ; 
          partnin[nendo-STARTY][sei][nenrei][2][0] 
            = tmae[20][nendo-STARTY][sei][nenrei] - tato[20][nendo-STARTY][sei][nenrei] ; 
          partnin[nendo-STARTY][sei][nenrei][8][0] 
            = tmae[21][nendo-STARTY][sei][nenrei] - tato[21][nendo-STARTY][sei][nenrei] ; 
          partnin[nendo-STARTY][sei][nenrei][5][0] 
            = tmae[13][nendo-STARTY][sei][nenrei] - tato[13][nendo-STARTY][sei][nenrei] ; 
          partnin[nendo-STARTY][sei][nenrei][6][0] 
            = tmae[14][nendo-STARTY][sei][nenrei] - tato[14][nendo-STARTY][sei][nenrei] ; 
          partnin[nendo-STARTY][sei][nenrei][7][0] 
            = tmae[15][nendo-STARTY][sei][nenrei] - tato[15][nendo-STARTY][sei][nenrei] ; 
          if ( nenrei >= XEND ) {
            partnin[nendo-STARTY][sei][nenrei][3][0] = tato[36][nendo-STARTY][sei][nenrei] ;
          }

          ichigou[nendo-STARTY][sei][nenrei]    = tato[10][nendo-STARTY][sei][nenrei] ;
          ichigouip[nendo-STARTY][sei][nenrei]  = tato[9][nendo-STARTY][sei][nenrei] ; 

          kou12syu3[nendo-STARTY][sei][nenrei]  = tato[11][nendo-STARTY][sei][nenrei] ;
          kou3syu3[nendo-STARTY][sei][nenrei]   = tato[12][nendo-STARTY][sei][nenrei] ;
          kyosai3[1][nendo-STARTY][sei][nenrei] = tato[13][nendo-STARTY][sei][nenrei] ;
          kyosai3[2][nendo-STARTY][sei][nenrei] = tato[14][nendo-STARTY][sei][nenrei] ;
          kyosai3[3][nendo-STARTY][sei][nenrei] = tato[15][nendo-STARTY][sei][nenrei] ;
          kyosai3[4][nendo-STARTY][sei][nenrei] = tato[16][nendo-STARTY][sei][nenrei] ;
          kyosai3[5][nendo-STARTY][sei][nenrei] = tato[17][nendo-STARTY][sei][nenrei] ;
          kyosai3[7][nendo-STARTY][sei][nenrei] = tato[18][nendo-STARTY][sei][nenrei] ;
          kyosai3[6][nendo-STARTY][sei][nenrei] = tato[19][nendo-STARTY][sei][nenrei] ;
          sangou[nendo-STARTY][sei][nenrei]     = tato[20][nendo-STARTY][sei][nenrei] ;
          kounen3[nendo-STARTY][sei][nenrei]    = tato[21][nendo-STARTY][sei][nenrei] ;
          qkou12syu3[nendo-STARTY][sei][nenrei] = kou12syu3[nendo-STARTY][sei][nenrei];
          qkounen3[nendo-STARTY][sei][nenrei]   = kounen3[nendo-STARTY][sei][nenrei]  ;
          for ( seido=4; seido<=7; seido++ ) {
            qkou12syu3[nendo-STARTY][sei][nenrei] -= kyosai3[seido][nendo-STARTY][sei][nenrei] ;
            qkounen3[nendo-STARTY][sei][nenrei] -= kyosai3[seido][nendo-STARTY][sei][nenrei] ;
          }
        }

        else if ( nendo == PARTYR2-1 ) {

          ichigou[PARTJJ-STARTY][sei][nenrei]    = tato[10][nendo-STARTY][sei][nenrei] ;
          ichigouip[PARTJJ-STARTY][sei][nenrei]  = tato[9][nendo-STARTY][sei][nenrei] ; 

          kou12syu3[PARTJJ-STARTY][sei][nenrei]  = tato[11][nendo-STARTY][sei][nenrei] ;
          kou3syu3[PARTJJ-STARTY][sei][nenrei]   = tato[12][nendo-STARTY][sei][nenrei] ;
          kyosai3[1][PARTJJ-STARTY][sei][nenrei] = tato[13][nendo-STARTY][sei][nenrei] ;
          kyosai3[2][PARTJJ-STARTY][sei][nenrei] = tato[14][nendo-STARTY][sei][nenrei] ;
          kyosai3[3][PARTJJ-STARTY][sei][nenrei] = tato[15][nendo-STARTY][sei][nenrei] ;
          kyosai3[4][PARTJJ-STARTY][sei][nenrei] = tato[16][nendo-STARTY][sei][nenrei] ;
          kyosai3[5][PARTJJ-STARTY][sei][nenrei] = tato[17][nendo-STARTY][sei][nenrei] ;
          kyosai3[7][PARTJJ-STARTY][sei][nenrei] = tato[18][nendo-STARTY][sei][nenrei] ;
          kyosai3[6][PARTJJ-STARTY][sei][nenrei] = tato[19][nendo-STARTY][sei][nenrei] ;
          sangou[PARTJJ-STARTY][sei][nenrei]     = tato[20][nendo-STARTY][sei][nenrei] ;
          kounen3[PARTJJ-STARTY][sei][nenrei]    = tato[21][nendo-STARTY][sei][nenrei] ;
          qkou12syu3[PARTJJ-STARTY][sei][nenrei] = kou12syu3[PARTJJ-STARTY][sei][nenrei];
          qkounen3[PARTJJ-STARTY][sei][nenrei]   = kounen3[PARTJJ-STARTY][sei][nenrei]  ;
          for ( seido=4; seido<=7; seido++ ) {
            qkou12syu3[PARTJJ-STARTY][sei][nenrei] -= kyosai3[seido][PARTJJ-STARTY][sei][nenrei] ;
            qkounen3[PARTJJ-STARTY][sei][nenrei] -= kyosai3[seido][PARTJJ-STARTY][sei][nenrei] ;
          }
        }




      }
    }

  }

  for ( nendo=PARTYR1-1; nendo<=KE; nendo++ ) {
    XEND = xend[8][nendo-STARTY] ; 
    if ( XEND < 60 ) { XEND = 60; }
    for ( sei=1; sei<=4; sei++ ) {
      for ( nenrei=20; nenrei<=XEND-1; nenrei++ ) {
          tiwari[1] = syouken[1][KIJUN-STARTY]
                       * ( koyouj_m[1][nendo-STARTY][sei][nenrei] / koyouj_m[0][nendo-STARTY][sei][nenrei] )
                       / ( koyouj_m[1][KIJUN-STARTY][sei][nenrei] / koyouj_m[0][KIJUN-STARTY][sei][nenrei] ) ;
          tiwari[4] = syouken[4][KIJUN-STARTY] 
                       * ( koyouj_m[4][nendo-STARTY][sei][nenrei] / koyouj_m[0][nendo-STARTY][sei][nenrei] )
                       / ( koyouj_m[4][KIJUN-STARTY][sei][nenrei] / koyouj_m[0][KIJUN-STARTY][sei][nenrei] ) ;
          tiwari[5] = syouken[5][KIJUN-STARTY] 
                       * ( koyouj_m[5][nendo-STARTY][sei][nenrei] / koyouj_m[0][nendo-STARTY][sei][nenrei] )
                       / ( koyouj_m[5][KIJUN-STARTY][sei][nenrei] / koyouj_m[0][KIJUN-STARTY][sei][nenrei] ) ;
          tiwari[6] = syouken[6][KIJUN-STARTY] 
                       * ( koyouj_m[6][nendo-STARTY][sei][nenrei] / koyouj_m[0][nendo-STARTY][sei][nenrei] )
                       / ( koyouj_m[6][KIJUN-STARTY][sei][nenrei] / koyouj_m[0][KIJUN-STARTY][sei][nenrei] ) ;
          tiwari[0] = tiwari[1] + tiwari[4] + tiwari[5] + tiwari[6] ;
          if ( tiwari[0] > 0.0 ) {
            partnin[nendo-STARTY][sei][nenrei][17][2]
              = partnin[nendo-STARTY][sei][nenrei][11][2] 
                 - ( partnin[nendo-STARTY][sei][nenrei][2][2] * tiwari[1] / tiwari[0] ) ;
            partnin[nendo-STARTY][sei][nenrei][18][2]
              = partnin[nendo-STARTY][sei][nenrei][14][2] 
                 - ( partnin[nendo-STARTY][sei][nenrei][2][2] * tiwari[4] / tiwari[0] ) ;
            partnin[nendo-STARTY][sei][nenrei][19][2]
              = partnin[nendo-STARTY][sei][nenrei][15][2] 
                 - ( partnin[nendo-STARTY][sei][nenrei][2][2] * tiwari[5] / tiwari[0] ) ;
            partnin[nendo-STARTY][sei][nenrei][20][2]
              = partnin[nendo-STARTY][sei][nenrei][16][2] 
                 - ( partnin[nendo-STARTY][sei][nenrei][2][2] * tiwari[6] / tiwari[0] ) ;
          }
          else {
            partnin[nendo-STARTY][sei][nenrei][17][2] = 0.0 ;
            partnin[nendo-STARTY][sei][nenrei][18][2] = 0.0 ;
            partnin[nendo-STARTY][sei][nenrei][19][2] = 0.0 ;
            partnin[nendo-STARTY][sei][nenrei][20][2] = 0.0 ;
          }
      }
    }
    for ( ii=17; ii<=20; ii++ ) {
      for ( nenrei=15; nenrei<=69; nenrei++ ) {
        partnin[nendo-STARTY][2][nenrei][ii][2]
          = partnin[nendo-STARTY][3][nenrei][ii][2] + partnin[nendo-STARTY][4][nenrei][ii][2] ;
        partnin[nendo-STARTY][0][nenrei][ii][2]
          = partnin[nendo-STARTY][1][nenrei][ii][2] + partnin[nendo-STARTY][2][nenrei][ii][2] ;
      }
    }

  }

  for ( nendo=PARTJJ; nendo<=KE; nendo++ ) {
    if ( ( nendo<= PARTJJ ) || ( nendo>=PARTYR1 ) ) {
      for ( sei=0; sei<=4; sei++ ) {
        for ( nenrei=15; nenrei<=100; nenrei++ ) {
          ichigou[nendo-STARTY][sei][nenrei] =
            ichigouip[nendo-STARTY][sei][nenrei] + ichigouni[nendo-STARTY][sei][nenrei] ;
        }
        for ( nenrei=20; nenrei<=59; nenrei++ ) {
          qkounen3[nendo-STARTY][sei][nenrei]
            = qkou12syu3[nendo-STARTY][sei][nenrei] + kou3syu3[nendo-STARTY][sei][nenrei] ;
          kou12syu3[nendo-STARTY][sei][nenrei] = qkou12syu3[nendo-STARTY][sei][nenrei] ;
          kounen3[nendo-STARTY][sei][nenrei] = qkounen3[nendo-STARTY][sei][nenrei] ;
          for ( seido=4; seido<=7; seido++ ) {
            kou12syu3[nendo-STARTY][sei][nenrei] += kyosai3[seido][nendo-STARTY][sei][nenrei] ;
            kounen3[nendo-STARTY][sei][nenrei] += kyosai3[seido][nendo-STARTY][sei][nenrei] ;
          }
          sangou[nendo-STARTY][sei][nenrei] = kounen3[nendo-STARTY][sei][nenrei] ;
          for ( seido=1; seido<=3; seido++ ) { 
            sangou[nendo-STARTY][sei][nenrei] += kyosai3[seido][nendo-STARTY][sei][nenrei] ;
          }
        }
      }
    }

  }



}

