/*************************************
*                                    *
*    外枠システム  fout.c            *
*  （結果ファイル出力）              *
*                                    *
*************************************/

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



void fout(void) {

    char    filename[250]    ; 
    int     ii ;
    int     bunrui ; 
    double  nenrei_kei_ninzu[62][ENDY-STARTY+1][5] ; 
    double  nenrei_betu_ninzu[121] ; 
    int     XEND ;




  for ( bunrui=0; bunrui<=61; bunrui++ ) {

      sprintf(filename, "/rev31/wakuc/rslt/ver_3/rslt%04d/waku%04d-%02d.csv", BANGO, BANGO, bunrui ) ;
      if ((fp_wakuout = fopen(filename, "w")) == NULL) {
           fprintf(stderr, "出力wakuファイルを開けません!\n");
           exit (2); /* 終了 */
      }

      fprintf(fp_wakuout , "試算番号,BANGO=,%d\n", BANGO );
      fprintf(fp_wakuout , "分類,性,年度,計," );
      for ( ii=15; ii<=99; ii++ ) {
        fprintf(fp_wakuout , "%02d," , ii );
      }
      fprintf(fp_wakuout , "100\n" );

      for ( sei=0; sei<=4; sei++ ) {
        for ( nendo=STARTY+1 ; nendo<=(int)min(KF,ENDY) ; nendo++ ) {

          nenrei_kei_ninzu[bunrui][nendo-STARTY][sei] = 0.0 ;
          for ( nenrei=15; nenrei<=120; nenrei++ ) {
            nenrei_betu_ninzu[nenrei] = 0.0 ;
            switch ( bunrui ) {
              case 0: /* 公的年金被保険者合計 */
                nenrei_betu_ninzu[nenrei] = ichigou[nendo-STARTY][sei][nenrei]
                    + nigou[nendo-STARTY][sei][nenrei] + sangou[nendo-STARTY][sei][nenrei] ;
                if ( nendo >= 2016 ) {
                    nenrei_betu_ninzu[nenrei] += partnin[nendo-STARTY][sei][nenrei][0][0]  ;
                }
                else if ( nendo == PARTJJ ) {
                  nenrei_betu_ninzu[nenrei] = ichigou[PARTJJ-STARTY][sei][nenrei]
                      + nigou[PARTYR1-1-STARTY][sei][nenrei] + sangou[PARTJJ-STARTY][sei][nenrei]
                      + (partnin[PARTJJ-STARTY][sei][nenrei][0][1]+partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]) ;
                }
                else if ( nendo == PARTKK ) {
                  nenrei_betu_ninzu[nenrei] = ichigou[PARTKK-STARTY][sei][nenrei]
                      + nigou[PARTYR2-1-STARTY][sei][nenrei] + sangou[PARTKK-STARTY][sei][nenrei]
                      + (partnin[PARTKK-STARTY][sei][nenrei][0][2]+partnin[PARTYR2-1-STARTY][sei][nenrei][0][0]) ;
                }
                  XEND = xend[8][nendo-STARTY] ; 
                  if ( nendo == PARTJJ ) { XEND = xend[8][PARTYR1-1-STARTY] ; }
                  if ( XEND < 60 ) { XEND = 60; }
                  if ( ( MODE >= 4 ) && ( nenrei >= XEND ) ) {
					if( (nendo == PARTJJ) && ( PART ==1) ){
					  nenrei_betu_ninzu[nenrei] = ichigouni[PARTJJ-STARTY][sei][nenrei]
                                                  + nigou[PARTYR1-1-STARTY][sei][nenrei]+partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]+partnin[PARTJJ-STARTY][sei][nenrei][0][1] ;
					}
					else {
                      nenrei_betu_ninzu[nenrei] = ichigouni[nendo-STARTY][sei][nenrei]
                                                  + nigou[nendo-STARTY][sei][nenrei]+partnin[nendo-STARTY][sei][nenrei][0][0] ;
					}
                  }
                break ;
              case 1: 
                nenrei_betu_ninzu[nenrei] = kou12syu[nendo-STARTY][sei][nenrei] ;
                if ( nendo==PARTJJ ) { nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR1-1-STARTY][sei][nenrei] ; }
                if ( nendo==PARTKK ) { nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR2-1-STARTY][sei][nenrei] ; }
                break ;
              case 2: 
                nenrei_betu_ninzu[nenrei] = kou3syu[nendo-STARTY][sei][nenrei] ;
                if ( nendo==PARTJJ ) { nenrei_betu_ninzu[nenrei] = kou3syu[PARTYR1-1-STARTY][sei][nenrei] ; }
                if ( nendo==PARTKK ) { nenrei_betu_ninzu[nenrei] = kou3syu[PARTYR2-1-STARTY][sei][nenrei] ; }
                break ;
              case 3: 
                nenrei_betu_ninzu[nenrei] = kyosai[1][nendo-STARTY][sei][nenrei] ;
                if ( nendo==PARTJJ ) { nenrei_betu_ninzu[nenrei] = kyosai[1][PARTYR1-1-STARTY][sei][nenrei] ; }
                if ( nendo==PARTKK ) { nenrei_betu_ninzu[nenrei] = kyosai[1][PARTYR2-1-STARTY][sei][nenrei] ; }
                break ;
              case 4: 
                nenrei_betu_ninzu[nenrei] = kyosai[2][nendo-STARTY][sei][nenrei] ;
                if ( nendo==PARTJJ ) { nenrei_betu_ninzu[nenrei] = kyosai[2][PARTYR1-1-STARTY][sei][nenrei] ; }
                if ( nendo==PARTKK ) { nenrei_betu_ninzu[nenrei] = kyosai[2][PARTYR2-1-STARTY][sei][nenrei] ; }
                break ;
              case 5: 
                nenrei_betu_ninzu[nenrei] = kyosai[3][nendo-STARTY][sei][nenrei] ;
                if ( nendo==PARTJJ ) { nenrei_betu_ninzu[nenrei] = kyosai[3][PARTYR1-1-STARTY][sei][nenrei] ; }
                if ( nendo==PARTKK ) { nenrei_betu_ninzu[nenrei] = kyosai[3][PARTYR2-1-STARTY][sei][nenrei] ; }
                break ;
              case 6: 
                nenrei_betu_ninzu[nenrei] = kyosai[4][nendo-STARTY][sei][nenrei] ;
                if ( nendo==PARTJJ ) { nenrei_betu_ninzu[nenrei] = kyosai[4][PARTYR1-1-STARTY][sei][nenrei] ; }
                if ( nendo==PARTKK ) { nenrei_betu_ninzu[nenrei] = kyosai[4][PARTYR2-1-STARTY][sei][nenrei] ; }
                break ;
              case 7: 
                nenrei_betu_ninzu[nenrei] = kyosai[5][nendo-STARTY][sei][nenrei] ;
                if ( nendo==PARTJJ ) { nenrei_betu_ninzu[nenrei] = kyosai[5][PARTYR1-1-STARTY][sei][nenrei] ; }
                if ( nendo==PARTKK ) { nenrei_betu_ninzu[nenrei] = kyosai[5][PARTYR2-1-STARTY][sei][nenrei] ; }
                break ;
              case 8:
                nenrei_betu_ninzu[nenrei] = kyosai[7][nendo-STARTY][sei][nenrei] ;
                if ( nendo==PARTJJ ) { nenrei_betu_ninzu[nenrei] = kyosai[7][PARTYR1-1-STARTY][sei][nenrei] ; }
                if ( nendo==PARTKK ) { nenrei_betu_ninzu[nenrei] = kyosai[7][PARTYR2-1-STARTY][sei][nenrei] ; }
                break ;
              case 9:
                nenrei_betu_ninzu[nenrei] = kyosai[6][nendo-STARTY][sei][nenrei] ;
                if ( nendo==PARTJJ ) { nenrei_betu_ninzu[nenrei] = kyosai[6][PARTYR1-1-STARTY][sei][nenrei] ; }
                if ( nendo==PARTKK ) { nenrei_betu_ninzu[nenrei] = kyosai[6][PARTYR2-1-STARTY][sei][nenrei] ; }
                break ;
              case 10:
                nenrei_betu_ninzu[nenrei] = ichigou[nendo-STARTY][sei][nenrei] ;
                break ;
              case 11: 
                nenrei_betu_ninzu[nenrei] = kou12syu3[nendo-STARTY][sei][nenrei] ;
                break ;
              case 12: 
                nenrei_betu_ninzu[nenrei] = kou3syu3[nendo-STARTY][sei][nenrei] ;
                break ;
              case 13:
                nenrei_betu_ninzu[nenrei] = kyosai3[1][nendo-STARTY][sei][nenrei] ;
                break ;
              case 14: 
                nenrei_betu_ninzu[nenrei] = kyosai3[2][nendo-STARTY][sei][nenrei] ;
                break ;
              case 15: 
                nenrei_betu_ninzu[nenrei] = kyosai3[3][nendo-STARTY][sei][nenrei] ;
                break ;
              case 16: 
                nenrei_betu_ninzu[nenrei] = kyosai3[4][nendo-STARTY][sei][nenrei] ;
                break ;
              case 17: 
                nenrei_betu_ninzu[nenrei] = kyosai3[5][nendo-STARTY][sei][nenrei] ;
                break ;
              case 18: 
                nenrei_betu_ninzu[nenrei] = kyosai3[7][nendo-STARTY][sei][nenrei] ;
                break ;
              case 19: 
                nenrei_betu_ninzu[nenrei] = kyosai3[6][nendo-STARTY][sei][nenrei] ;
                break ;
              case 20: 
                nenrei_betu_ninzu[nenrei] = sangou[nendo-STARTY][sei][nenrei] ;
                break ;
              case 21: 
                if ( nenrei<70 ) {
                  nenrei_betu_ninzu[nenrei] = mika_soto1[nendo-STARTY][sei][nenrei] ;
                }
                else {
                  nenrei_betu_ninzu[nenrei] = 0.0 ;
                }
                break ;
              case 22: 
                nenrei_betu_ninzu[nenrei] = kounen[nendo-STARTY][sei][nenrei] ;
                for ( seido=1; seido<=3; seido++ ) { 
                  nenrei_betu_ninzu[nenrei] += kyosai[seido][nendo-STARTY][sei][nenrei] ;
                }
                if ( nendo <= 2001 ) { 
                  nenrei_betu_ninzu[nenrei] += kyosai[7][nendo-STARTY][sei][nenrei] ;
                }
                if ( nendo >= 2016 ) {
                  nenrei_betu_ninzu[nenrei] += partnin[nendo-STARTY][sei][nenrei][0][0] ;
                }
				if(HIHO74 ==70){
                	if ( nenrei >= 70 ) {
                 	nenrei_betu_ninzu[nenrei] -= qkounen[nendo-STARTY][sei][nenrei] ;
                	}
                	if ( nendo==PARTJJ ) {
                  		nenrei_betu_ninzu[nenrei] = kounen[PARTYR1-1-STARTY][sei][nenrei] 
                    	 + (partnin[PARTJJ-STARTY][sei][nenrei][0][1] +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]);
                  		for ( seido=1; seido<=3; seido++ ) { 
                   	 	nenrei_betu_ninzu[nenrei] += kyosai[seido][PARTYR1-1-STARTY][sei][nenrei] ;
                  		}
                  		if ( nenrei >= 70 ) {
                   	 	nenrei_betu_ninzu[nenrei] -= qkounen[PARTYR1-1-STARTY][sei][nenrei] ;
                  		}
                	}
                	if ( nendo==PARTKK ) {
                  		nenrei_betu_ninzu[nenrei] = kounen[PARTYR2-1-STARTY][sei][nenrei] 
                    	 + (partnin[PARTKK-STARTY][sei][nenrei][0][2] +partnin[PARTYR2-1-STARTY][sei][nenrei][0][0]) ;
                  		for ( seido=1; seido<=3; seido++ ) { 
                    		nenrei_betu_ninzu[nenrei] += kyosai[seido][PARTYR2-1-STARTY][sei][nenrei] ;
                  		}
                  		if ( nenrei >= 70 ) {
                    	nenrei_betu_ninzu[nenrei] -= qkounen[PARTYR2-1-STARTY][sei][nenrei] ;
                  		}
                	}
				}
				else{
				  if ( nendo < HIHO74YR){
					if ( nenrei >= 70 ) {
                 	nenrei_betu_ninzu[nenrei] -= qkounen[nendo-STARTY][sei][nenrei] ;
                	}
                	if ( nendo==PARTJJ ) {
                  		nenrei_betu_ninzu[nenrei] = kounen[PARTYR1-1-STARTY][sei][nenrei] 
                    	 + (partnin[PARTJJ-STARTY][sei][nenrei][0][1] +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]);
                  		for ( seido=1; seido<=3; seido++ ) { 
                   	 	nenrei_betu_ninzu[nenrei] += kyosai[seido][PARTYR1-1-STARTY][sei][nenrei] ;
                  		}
                  		if ( nenrei >= 70 ) {
                   	 	nenrei_betu_ninzu[nenrei] -= qkounen[PARTYR1-1-STARTY][sei][nenrei] ;
                  		}
                	}
                	if ( nendo==PARTKK ) {
                  		nenrei_betu_ninzu[nenrei] = kounen[PARTYR2-1-STARTY][sei][nenrei] 
                    	 + (partnin[PARTKK-STARTY][sei][nenrei][0][2] +partnin[PARTYR2-1-STARTY][sei][nenrei][0][0]) ;
                  		for ( seido=1; seido<=3; seido++ ) { 
                    		nenrei_betu_ninzu[nenrei] += kyosai[seido][PARTYR2-1-STARTY][sei][nenrei] ;
                  		}
                  		if ( nenrei >= 70 ) {
                    	nenrei_betu_ninzu[nenrei] -= qkounen[PARTYR2-1-STARTY][sei][nenrei] ;
                  		}
                	}
				 }
				 else {
					if ( nenrei >= HIHO74+1 ) {
                 	nenrei_betu_ninzu[nenrei] -= qkounen[nendo-STARTY][sei][nenrei] ;
                	}
                	if ( nendo==PARTJJ ) {
                  		nenrei_betu_ninzu[nenrei] = kounen[PARTYR1-1-STARTY][sei][nenrei] 
                    	 + (partnin[PARTJJ-STARTY][sei][nenrei][0][1] +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]);
                  		for ( seido=1; seido<=3; seido++ ) { 
                   	 	nenrei_betu_ninzu[nenrei] += kyosai[seido][PARTYR1-1-STARTY][sei][nenrei] ;
                  		}
                  		if ( nenrei >= HIHO74+1 ) {
                   	 	nenrei_betu_ninzu[nenrei] -= qkounen[PARTYR1-1-STARTY][sei][nenrei] ;
                  		}
                	}
                	if ( nendo==PARTKK ) {
                  		nenrei_betu_ninzu[nenrei] = kounen[PARTYR2-1-STARTY][sei][nenrei] 
                    	 + (partnin[PARTKK-STARTY][sei][nenrei][0][2] +partnin[PARTYR2-1-STARTY][sei][nenrei][0][0]) ;
                  		for ( seido=1; seido<=3; seido++ ) { 
                    		nenrei_betu_ninzu[nenrei] += kyosai[seido][PARTYR2-1-STARTY][sei][nenrei] ;
                  		}
                  		if ( nenrei >= HIHO74+1 ) {
                    	nenrei_betu_ninzu[nenrei] -= qkounen[PARTYR2-1-STARTY][sei][nenrei] ;
                  		}
                	}
				 }
				}
                break ;
              case 23: 
                if (( nenrei >= 15 ) && ( nenrei < 65 )) {
                  nenrei_betu_ninzu[nenrei] = qkounen[nendo-STARTY][sei][nenrei] ;
                  for ( seido=1; seido<=7; seido++ ) {
                    nenrei_betu_ninzu[nenrei] += kyosai[seido][nendo-STARTY][sei][nenrei] ;
                  }
                  nenrei_betu_ninzu[nenrei] += partnin[nendo-STARTY][sei][nenrei][0][0] ;
                  if ( nendo==PARTJJ ) {
                    nenrei_betu_ninzu[nenrei] = qkounen[PARTYR1-1-STARTY][sei][nenrei] ;
                    for ( seido=1; seido<=7; seido++ ) {
                      nenrei_betu_ninzu[nenrei] += kyosai[seido][PARTYR1-1-STARTY][sei][nenrei] ;
                    }
                    nenrei_betu_ninzu[nenrei] += (partnin[PARTJJ-STARTY][sei][nenrei][0][1] +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]) ;
                  }
                  if ( nendo==PARTKK ) {
                    nenrei_betu_ninzu[nenrei] = qkounen[PARTYR2-1-STARTY][sei][nenrei] ;
                    for ( seido=1; seido<=7; seido++ ) {
                      nenrei_betu_ninzu[nenrei] += kyosai[seido][PARTYR2-1-STARTY][sei][nenrei] ;
                    }
                    nenrei_betu_ninzu[nenrei] += (partnin[PARTKK-STARTY][sei][nenrei][0][2]  +partnin[PARTYR2-1-STARTY][sei][nenrei][0][0]);
                  }
                }
                else {
                  nenrei_betu_ninzu[nenrei] = 0.0 ;
                }
                break ;
              case 24: 
               if (HIHO74 == 70){
				if (( nenrei >= 70 ) && ( nendo>=2007 )) { 
                  nenrei_betu_ninzu[nenrei] = kou12syu[nendo-STARTY][sei][nenrei] + kou3syu[nendo-STARTY][sei][nenrei] ;
                }
                else if ( ( nenrei >= 70 ) && ( nendo==PARTJJ )) {
                  nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR1-1-STARTY][sei][nenrei]
                     + kou3syu[PARTYR1-1-STARTY][sei][nenrei] ;
                }
                else if ( ( nenrei >= 70 ) && ( nendo==PARTKK )) {
                  nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR2-1-STARTY][sei][nenrei]
                     + kou3syu[PARTYR2-1-STARTY][sei][nenrei] ;
                }
                else {
                  nenrei_betu_ninzu[nenrei] = 0.0 ;
                }
			   }
			   else {
				if ( nendo < HIHO74YR){
				 	if (( nenrei >= 70 ) && ( nendo>=2007 )) {
                	  nenrei_betu_ninzu[nenrei] = kou12syu[nendo-STARTY][sei][nenrei] + kou3syu[nendo-STARTY][sei][nenrei] ;
                	}
                	else if ( ( nenrei >= 70 ) && ( nendo==PARTJJ )) {
                 	 nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR1-1-STARTY][sei][nenrei]
                    	 + kou3syu[PARTYR1-1-STARTY][sei][nenrei] ;
                	}
                	else if ( ( nenrei >= 70 ) && ( nendo==PARTKK )) {
                 	 nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR2-1-STARTY][sei][nenrei]
                    	 + kou3syu[PARTYR2-1-STARTY][sei][nenrei] ;
                	}
                	else {
                  	nenrei_betu_ninzu[nenrei] = 0.0 ;
                	}
			    }
				else {
					if (( nenrei >= HIHO74+1 ) && ( nendo>=2007 )) { 
                	  nenrei_betu_ninzu[nenrei] = kou12syu[nendo-STARTY][sei][nenrei] + kou3syu[nendo-STARTY][sei][nenrei] ;
                	}
                	else if ( ( nenrei >= HIHO74+1 ) && ( nendo==PARTJJ )) {
                 	 nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR1-1-STARTY][sei][nenrei]
                    	 + kou3syu[PARTYR1-1-STARTY][sei][nenrei] ;
                	}
                	else if ( ( nenrei >= HIHO74+1 ) && ( nendo==PARTKK )) {
                 	 nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR2-1-STARTY][sei][nenrei]
                    	 + kou3syu[PARTYR2-1-STARTY][sei][nenrei] ;
                	}
                	else {
                  	nenrei_betu_ninzu[nenrei] = 0.0 ;
                	}
				}
			   }
                break ;
              case 25: 
			   if(HIHO74 == 70){
                if (( nenrei < 70 ) || ( nendo < 2007 )) { 
                  nenrei_betu_ninzu[nenrei] = kou12syu[nendo-STARTY][sei][nenrei] ;
                  if ( nendo >= 2016 ) {
                    nenrei_betu_ninzu[nenrei] += partnin[nendo-STARTY][sei][nenrei][0][0]  ;
                  }
                  if ( ( nendo==PARTJJ ) && ( nenrei < 70 ) ) {
                    nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR1-1-STARTY][sei][nenrei]
                       +( partnin[PARTJJ-STARTY][sei][nenrei][0][1] +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]) ;
                  }
                  if ( ( nendo==PARTKK ) && ( nenrei < 70 ) ) {
                    nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR2-1-STARTY][sei][nenrei]
                       + (partnin[PARTKK-STARTY][sei][nenrei][0][2] +partnin[PARTYR1-2-STARTY][sei][nenrei][0][0]) ;
                  }
                }
                else {
                  nenrei_betu_ninzu[nenrei] = 0.0 ;
                }
			   }
			   else {
			    if ( nendo < HIHO74YR){
				 if (( nenrei < 70 ) || ( nendo < 2007 )) { 
                  nenrei_betu_ninzu[nenrei] = kou12syu[nendo-STARTY][sei][nenrei] ;
                  if ( nendo >= 2016 ) {
                    nenrei_betu_ninzu[nenrei] += partnin[nendo-STARTY][sei][nenrei][0][0]  ;
                  }
                  if ( ( nendo==PARTJJ ) && ( nenrei < 70 ) ) {
                    nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR1-1-STARTY][sei][nenrei]
                       +( partnin[PARTJJ-STARTY][sei][nenrei][0][1] +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]) ;
                  }
                  if ( ( nendo==PARTKK ) && ( nenrei < 70 ) ) {
                    nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR2-1-STARTY][sei][nenrei]
                       + (partnin[PARTKK-STARTY][sei][nenrei][0][2] +partnin[PARTYR1-2-STARTY][sei][nenrei][0][0]) ;
                  }
                }
                else {
                  nenrei_betu_ninzu[nenrei] = 0.0 ;
                }
			   }
			   else {
				 if (( nenrei < HIHO74+1 ) || ( nendo < 2007 )) { 
                  nenrei_betu_ninzu[nenrei] = kou12syu[nendo-STARTY][sei][nenrei] ;
                  if ( nendo >= 2016 ) {
                    nenrei_betu_ninzu[nenrei] += partnin[nendo-STARTY][sei][nenrei][0][0]  ;
                  }
                  if ( ( nendo==PARTJJ ) && ( nenrei < HIHO74+1 ) ) {
                    nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR1-1-STARTY][sei][nenrei]
                       +( partnin[PARTJJ-STARTY][sei][nenrei][0][1] +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]) ;
                  }
                  if ( ( nendo==PARTKK ) && ( nenrei < HIHO74+1 ) ) {
                    nenrei_betu_ninzu[nenrei] = kou12syu[PARTYR2-1-STARTY][sei][nenrei]
                       + (partnin[PARTKK-STARTY][sei][nenrei][0][2] +partnin[PARTYR1-2-STARTY][sei][nenrei][0][0]) ;
                  }
                }
                else {
                  nenrei_betu_ninzu[nenrei] = 0.0 ;
                }
			   }
      		  }
                break ;
              case 26: 
                nenrei_betu_ninzu[nenrei] = jinko_c[nendo-STARTY][sei][nenrei] ;
                break ;
              case 27: 
                nenrei_betu_ninzu[nenrei] = jinko_m[nendo-STARTY][sei][nenrei] ;
                break ;
              case 28: 
                nenrei_betu_ninzu[nenrei] = jinko_c[nendo-STARTY][sei][nenrei-15] ;
                break ;
              case 29: 
                nenrei_betu_ninzu[nenrei] = jinko_m[nendo-STARTY][sei][nenrei-15] ;
                break ;
              case 30: 
                nenrei_betu_ninzu[nenrei] = kikin[nendo-STARTY][sei][nenrei] ;
                break ;
              case 31:
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][0][0] ;
                if ( nendo==PARTJJ ) { nenrei_betu_ninzu[nenrei] = (partnin[PARTJJ-STARTY][sei][nenrei][0][1] +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]) ; }
                if ( nendo==PARTKK ) { nenrei_betu_ninzu[nenrei] = (partnin[PARTKK-STARTY][sei][nenrei][0][2]  +partnin[PARTYR2-1-STARTY][sei][nenrei][0][0]); }
                break ;
              case 32: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][0][1] ;
                break ;
              case 33: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][1][1] ;
                break ;
              case 34: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][2][1] ;
                break ;
              case 35: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][3][1] ;
                break ;
              case 36: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][0][2] ;
                break ;
              case 37: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][1][2] ;
                break ;
              case 38: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][2][2] ;
                break ;
              case 39: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][3][2] ;
                break ;
              case 40: 
			   if (HIHO74 ==70){
                if ( nenrei < 70 ) {
                  nenrei_betu_ninzu[nenrei] = kounen[nendo-STARTY][sei][nenrei] ;
                  if ( nendo >= 2016 ) {
                    nenrei_betu_ninzu[nenrei] += partnin[nendo-STARTY][sei][nenrei][0][0]  ;
                  }
                  if ( nendo==PARTJJ ) {
                    nenrei_betu_ninzu[nenrei]
                      = kounen[PARTYR1-1-STARTY][sei][nenrei] + (partnin[PARTJJ-STARTY][sei][nenrei][0][1]  +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]);
                  }
                  if ( nendo==PARTKK ) {
                    nenrei_betu_ninzu[nenrei]
                      = kounen[PARTYR2-1-STARTY][sei][nenrei] + (partnin[PARTKK-STARTY][sei][nenrei][0][2]  +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]);
                  }
                }
                else {
                  nenrei_betu_ninzu[nenrei] = 0.0 ;
                }
			   }
			   else {
				if(nendo <HIHO74YR ){
                if ( nenrei < 70 ) {
                  nenrei_betu_ninzu[nenrei] = kounen[nendo-STARTY][sei][nenrei] ;
                  if ( nendo >= 2016 ) {
                    nenrei_betu_ninzu[nenrei] += partnin[nendo-STARTY][sei][nenrei][0][0]  ;
                  }
                  if ( nendo==PARTJJ ) {
                    nenrei_betu_ninzu[nenrei]
                      = kounen[PARTYR1-1-STARTY][sei][nenrei] + (partnin[PARTJJ-STARTY][sei][nenrei][0][1]  +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]);
                  }
                  if ( nendo==PARTKK ) {
                    nenrei_betu_ninzu[nenrei]
                      = kounen[PARTYR2-1-STARTY][sei][nenrei] + (partnin[PARTKK-STARTY][sei][nenrei][0][2]  +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]);
                  }
                }
                else {
                  nenrei_betu_ninzu[nenrei] = 0.0 ;
                }
			   }
			   else {
                if ( nenrei < HIHO74+1 ) {
                  nenrei_betu_ninzu[nenrei] = kounen[nendo-STARTY][sei][nenrei] ;
                  if ( nendo >= 2016 ) {
                    nenrei_betu_ninzu[nenrei] += partnin[nendo-STARTY][sei][nenrei][0][0]  ;
                  }
                  if ( nendo==PARTJJ ) {
                    nenrei_betu_ninzu[nenrei]
                      = kounen[PARTYR1-1-STARTY][sei][nenrei] + (partnin[PARTJJ-STARTY][sei][nenrei][0][1]  +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]);
                  }
                  if ( nendo==PARTKK ) {
                    nenrei_betu_ninzu[nenrei]
                      = kounen[PARTYR2-1-STARTY][sei][nenrei] + (partnin[PARTKK-STARTY][sei][nenrei][0][2]  +partnin[PARTYR1-1-STARTY][sei][nenrei][0][0]);
                  }
                }
                else {
                  nenrei_betu_ninzu[nenrei] = 0.0 ;
                }
			   }
			  }
                break ;
              case 41: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][8][1] ;
                break ;
              case 42: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][5][1] ;
                break ;
              case 43: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][6][1] ;
                break ;
              case 44: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][7][1] ;
                break ;
              case 45: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][8][2] ;
                break ;
              case 46: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][5][2] ;
                break ;
              case 47: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][6][2] ;
                break ;
              case 48: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][7][2] ;
                break ;
              case 49: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][11][2] ;
                break ;
              case 50: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][14][2]  ; 
                break ;
              case 51: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][17][2] ;
                break ;
              case 52: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][18][2] 
                                          + partnin[nendo-STARTY][sei][nenrei][20][2] ; 
                break ;
              case 53: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][11][2] ;
                break ;
              case 54: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][15][2] ;
                break ;
              case 55: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][14][2] ;
                break ;
              case 56: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][16][2] ;
                break ;
              case 57:
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][17][2] ;
                break ;
              case 58: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][19][2] ;
                break ;
              case 59: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][18][2] ;
                break ;
              case 60: 
                nenrei_betu_ninzu[nenrei] = partnin[nendo-STARTY][sei][nenrei][20][2] ;
                break ;
              case 61: 
                nenrei_betu_ninzu[nenrei] = ichigouip[nendo-STARTY][sei][nenrei] ;;
                break ;
            }
            nenrei_kei_ninzu[bunrui][nendo-STARTY][sei] += nenrei_betu_ninzu[nenrei] ;
            if ( nenrei>100 ) {
              nenrei_betu_ninzu[100] += nenrei_betu_ninzu[nenrei] ;
            }


          }

          /*  出力  */
          if ( nendo>=KS ) { 
              fprintf(fp_wakuout , "%4d,%1d,%4d,", bunrui , sei , nendo );
              fprintf(fp_wakuout , "%lf,", raund(nenrei_kei_ninzu[bunrui][nendo-STARTY][sei],0) );
              for ( nenrei=15; nenrei<=99; nenrei++ ){
                fprintf(fp_wakuout , "%lf,", raund(nenrei_betu_ninzu[nenrei],0) );
              }
              fprintf(fp_wakuout , "%lf\n", raund(nenrei_betu_ninzu[100],0) );
          }

        }
      }

      fclose( fp_wakuout ) ;

  }



      sprintf(filename, "/rev31/wakuc/rslt/ver_3/rslt%04d/waku%04d-nenreikei.csv",BANGO, BANGO ) ;
      if ((fp_wakuout = fopen(filename, "w")) == NULL) {
           fprintf(stderr, "出力wakuファイルを開けません!\n");
           exit (2); /* 終了 */
      }

    /*  表頭出力  */
      fprintf(fp_wakuout , "年度末,試算番号,BANGO=,%d\n", BANGO );

      fprintf(fp_wakuout , "男女計,公的計,厚12種,厚3種,国共2号,地共2号,私学2号,ＪＲ2号,ＪＴ2号,農林2号,");
      fprintf(fp_wakuout , "ＮＴＴ2号,国年1号,厚12種3号,厚3種3号,国共3号,地共3号,私学3号,ＪＲ3号,");
      fprintf(fp_wakuout , "ＪＴ3号,農林3号,ＮＴＴ３号,3号全,外枠未,２号計,国年２号,厚70以上,厚69以下,");
      fprintf(fp_wakuout , "人口央,人口末,人口央,人口末,厚基,パート計,パート１段計,パート１段１,");
      fprintf(fp_wakuout , "パート１段３,パート１段他,パート２段計,パート２段１,パート２段３,パート２段他,");
      fprintf(fp_wakuout , "厚年計,パート１段３厚,パート１段３国,パート１段３地,パート１段３私,");
      fprintf(fp_wakuout , "パート２段３厚,パート２段３国,パート２段３地,パート２段３私,");
      fprintf(fp_wakuout , "パート２段30-,パート２段-30,パート２段１30-,パート２段１-30,パート２段フル,");
      fprintf(fp_wakuout , "パート２段30-35,パート２段20-30,パート２段-20,パート２段１フル,パート２段１30-35,");
      fprintf(fp_wakuout , "パート２段１20-30,パート２段１-20\n");

    /*  男女計出力  */
      for ( nendo=KS; nendo<=(int)min(KE,KF); nendo++ ) {
        fprintf(fp_wakuout , "%4d,", nendo );
        for ( bunrui=0; bunrui<=59; bunrui++ ) {
            fprintf(fp_wakuout , "%lf,", raund( nenrei_kei_ninzu[bunrui][nendo-STARTY][0],0 ) );
        }
        fprintf(fp_wakuout , "%lf,\n", raund( nenrei_kei_ninzu[60][nendo-STARTY][0],0) );
      }

    /*  男性の表頭  */
      fprintf(fp_wakuout , "男,公的計,厚12種,厚3種,国共2号,地共2号,私学2号,ＪＲ2号,ＪＴ2号,農林2号,");
      fprintf(fp_wakuout , "ＮＴＴ2号,国年1号,厚12種3号,厚3種3号,国共3号,地共3号,私学3号,ＪＲ3号,");
      fprintf(fp_wakuout , "ＪＴ3号,農林3号,ＮＴＴ３号,3号全,外枠未,２号計,国年２号,厚70以上,厚69以下,");
      fprintf(fp_wakuout , "人口央,人口末,人口央,人口末,厚基,パート計,パート１段計,パート１段１,");
      fprintf(fp_wakuout , "パート１段３,パート１段他,パート２段計,パート２段１,パート２段３,パート２段他,");
      fprintf(fp_wakuout , "厚年計,パート１段３厚,パート１段３国,パート１段３地,パート１段３私,");
      fprintf(fp_wakuout , "パート２段３厚,パート２段３国,パート２段３地,パート２段３私,");
      fprintf(fp_wakuout , "パート２段30-,パート２段-30,パート２段１30-,パート２段１-30,パート２段フル,");
      fprintf(fp_wakuout , "パート２段30-35,パート２段20-30,パート２段-20,パート２段１フル,パート２段１30-35,");
      fprintf(fp_wakuout , "パート２段１20-30,パート２段１-20\n");

    /*  男性出力  */
      for ( nendo=KS; nendo<=(int)min(KE,KF); nendo++ ) {
        fprintf(fp_wakuout , "%4d,", nendo );
        for ( bunrui=0; bunrui<=59; bunrui++ ) {
            fprintf(fp_wakuout , "%lf,", raund( nenrei_kei_ninzu[bunrui][nendo-STARTY][1],0 ) );
        }
        fprintf(fp_wakuout , "%lf,\n", raund( nenrei_kei_ninzu[60][nendo-STARTY][1],0) );
      }

    /*  女性の表頭  */
      fprintf(fp_wakuout , "女,公的計,厚12種,厚3種,国共2号,地共2号,私学2号,ＪＲ2号,ＪＴ2号,農林2号,");
      fprintf(fp_wakuout , "ＮＴＴ2号,国年1号,厚12種3号,厚3種3号,国共3号,地共3号,私学3号,ＪＲ3号,");
      fprintf(fp_wakuout , "ＪＴ3号,農林3号,ＮＴＴ３号,3号全,外枠未,２号計,国年２号,厚70以上,厚69以下,");
      fprintf(fp_wakuout , "人口央,人口末,人口央,人口末,厚基,パート計,パート１段計,パート１段１,");
      fprintf(fp_wakuout , "パート１段３,パート１段他,パート２段計,パート２段１,パート２段３,パート２段他,");
      fprintf(fp_wakuout , "厚年計,パート１段３厚,パート１段３国,パート１段３地,パート１段３私,");
      fprintf(fp_wakuout , "パート２段３厚,パート２段３国,パート２段３地,パート２段３私,");
      fprintf(fp_wakuout , "パート２段30-,パート２段-30,パート２段１30-,パート２段１-30,パート２段フル,");
      fprintf(fp_wakuout , "パート２段30-35,パート２段20-30,パート２段-20,パート２段１フル,パート２段１30-35,");
      fprintf(fp_wakuout , "パート２段１20-30,パート２段１-20\n");

    /*  女性出力  */
      for ( nendo=KS; nendo<=(int)min(KE,KF); nendo++ ) {
        fprintf(fp_wakuout , "%4d,", nendo );
        for ( bunrui=0; bunrui<=59; bunrui++ ) {
            fprintf(fp_wakuout , "%lf,", raund( nenrei_kei_ninzu[bunrui][nendo-STARTY][2],0 ) );
        }
        fprintf(fp_wakuout , "%lf,\n", raund( nenrei_kei_ninzu[60][nendo-STARTY][2],0) );
      }

    /*  女性有配偶の表頭  */
      fprintf(fp_wakuout , "女有配偶,公的計,厚12種,厚3種,国共2号,地共2号,私学2号,ＪＲ2号,ＪＴ2号,農林2号,");
      fprintf(fp_wakuout , "ＮＴＴ2号,国年1号,厚12種3号,厚3種3号,国共3号,地共3号,私学3号,ＪＲ3号,");
      fprintf(fp_wakuout , "ＪＴ3号,農林3号,ＮＴＴ３号,3号全,外枠未,２号計,国年２号,厚70以上,厚69以下,");
      fprintf(fp_wakuout , "人口央,人口末,人口央,人口末,厚基,パート計,パート１段計,パート１段１,");
      fprintf(fp_wakuout , "パート１段３,パート１段他,パート２段計,パート２段１,パート２段３,パート２段他,");
      fprintf(fp_wakuout , "厚年計,パート１段３厚,パート１段３国,パート１段３地,パート１段３私,");
      fprintf(fp_wakuout , "パート２段３厚,パート２段３国,パート２段３地,パート２段３私,");
      fprintf(fp_wakuout , "パート２段30-,パート２段-30,パート２段１30-,パート２段１-30,パート２段フル,");
      fprintf(fp_wakuout , "パート２段30-35,パート２段20-30,パート２段-20,パート２段１フル,パート２段１30-35,");
      fprintf(fp_wakuout , "パート２段１20-30,パート２段１-20\n");

    /*  女性有配偶出力  */
      for ( nendo=KS; nendo<=(int)min(KE,KF); nendo++ ) {
        fprintf(fp_wakuout , "%4d,", nendo );
        for ( bunrui=0; bunrui<=59; bunrui++ ) {
            fprintf(fp_wakuout , "%lf,", raund( nenrei_kei_ninzu[bunrui][nendo-STARTY][3],0 ) );
        }
        fprintf(fp_wakuout , "%lf,\n", raund( nenrei_kei_ninzu[60][nendo-STARTY][3],0) );
      }

    /*  女性無配偶の表頭  */
      fprintf(fp_wakuout , "女無配偶,公的計,厚12種,厚3種,国共2号,地共2号,私学2号,ＪＲ2号,ＪＴ2号,農林2号,");
      fprintf(fp_wakuout , "ＮＴＴ2号,国年1号,厚12種3号,厚3種3号,国共3号,地共3号,私学3号,ＪＲ3号,");
      fprintf(fp_wakuout , "ＪＴ3号,農林3号,ＮＴＴ３号,3号全,外枠未,２号計,国年２号,厚70以上,厚69以下,");
      fprintf(fp_wakuout , "人口央,人口末,人口央,人口末,厚基,パート計,パート１段計,パート１段１,");
      fprintf(fp_wakuout , "パート１段３,パート１段他,パート２段計,パート２段１,パート２段３,パート２段他,");
      fprintf(fp_wakuout , "厚年計,パート１段３厚,パート１段３国,パート１段３地,パート１段３私,");
      fprintf(fp_wakuout , "パート２段３厚,パート２段３国,パート２段３地,パート２段３私,");
      fprintf(fp_wakuout , "パート２段30-,パート２段-30,パート２段１30-,パート２段１-30,パート２段フル,");
      fprintf(fp_wakuout , "パート２段30-35,パート２段20-30,パート２段-20,パート２段１フル,パート２段１30-35,");
      fprintf(fp_wakuout , "パート２段１20-30,パート２段１-20\n");

    /*  女性無配偶出力  */
      for ( nendo=KS; nendo<=(int)min(KE,KF); nendo++ ) {
        fprintf(fp_wakuout , "%4d,", nendo );
        for ( bunrui=0; bunrui<=59; bunrui++ ) {
            fprintf(fp_wakuout , "%lf,", raund( nenrei_kei_ninzu[bunrui][nendo-STARTY][4],0 ) );
        }
        fprintf(fp_wakuout , "%lf,\n", raund( nenrei_kei_ninzu[60][nendo-STARTY][4],0 ) );
      }

    /*  ファイルクローズ  */
      fclose( fp_wakuout ) ;




      sprintf(filename, "/rev31/wakuc/rslt/ver_3/rslt%04d/waku%04d-nenkeikan.csv",BANGO, BANGO ) ;
      if ((fp_wakuout = fopen(filename, "w")) == NULL) {
           fprintf(stderr, "出力wakuファイルを開けません!\n");
           exit (2); /* 終了 */
      }

    /*  表頭出力  */
      fprintf(fp_wakuout , "年度間,試算番号,BANGO=,%d\n", BANGO );

    /*  男女計の表頭  */
      fprintf(fp_wakuout , "男女計,公的計,厚12種,厚3種,国共2号,地共2号,私学2号,ＪＲ2号,ＪＴ2号,農林2号,");
      fprintf(fp_wakuout , "ＮＴＴ2号,国年1号,厚12種3号,厚3種3号,国共3号,地共3号,私学3号,ＪＲ3号,");
      fprintf(fp_wakuout , "ＪＴ3号,農林3号,ＮＴＴ３号,3号全,外枠未,２号計,国年２号,厚70以上,厚69以下,");
      fprintf(fp_wakuout , "人口央,人口末,人口央,人口末,厚基,パート計,パート１段計,パート１段１,");
      fprintf(fp_wakuout , "パート１段３,パート１段他,パート２段計,パート２段１,パート２段３,パート２段他,");
      fprintf(fp_wakuout , "厚年計,パート１段３厚,パート１段３国,パート１段３地,パート１段３私,");
      fprintf(fp_wakuout , "パート２段３厚,パート２段３国,パート２段３地,パート２段３私,");
      fprintf(fp_wakuout , "パート２段30-,パート２段-30,パート２段１30-,パート２段１-30,パート２段フル,");
      fprintf(fp_wakuout , "パート２段30-35,パート２段20-30,パート２段-20,パート２段１フル,パート２段１30-35,");
      fprintf(fp_wakuout , "パート２段１20-30,パート２段１-20\n");

    /*  男女計出力  */
      for ( nendo=KS; nendo<=(int)min(KE,KF); nendo++ ) {
        fprintf(fp_wakuout , "%4d,", nendo );
        for ( bunrui=0; bunrui<=59; bunrui++ ) {
            if ( ( ( PART == 2 ) && ( PARTJ2 == 1 ) ) && ( nendo == PARTYR2 ) ) {/*意味ないロジ*/
              if(bunrui<=20 || (22<=bunrui && bunrui<=25) || bunrui==31 || bunrui==40){
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][0]
                          + nenrei_kei_ninzu[bunrui][PARTKK-STARTY][0] ) / 2.0 ,0 ) );
              } else {
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][0]
                          + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][0] ) / 2.0 ,0 ) );
              }
            }
            else if ( nendo == PARTYR1 ){
            	if(bunrui<=20 || (22<=bunrui && bunrui<=25)  || bunrui==31 || bunrui==40){
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][0]
                          + nenrei_kei_ninzu[bunrui][PARTJJ-STARTY][0] ) / 2.0 ,0 ) );
              	} else {
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][0]
                          + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][0] ) / 2.0 ,0 ) );
              	}
            }
            else {
              fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][0]
                      + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][0] ) / 2.0 ,0 ) );
            }
        }
        fprintf(fp_wakuout , "%lf,\n", raund( ( nenrei_kei_ninzu[60][nendo-STARTY][0]
                    + nenrei_kei_ninzu[60][nendo-1-STARTY][0] ) / 2.0 ,0 ) );
      }

    /*  男性の表頭  */
      fprintf(fp_wakuout , "男,公的計,厚12種,厚3種,国共2号,地共2号,私学2号,ＪＲ2号,ＪＴ2号,農林2号,");
      fprintf(fp_wakuout , "ＮＴＴ2号,国年1号,厚12種3号,厚3種3号,国共3号,地共3号,私学3号,ＪＲ3号,");
      fprintf(fp_wakuout , "ＪＴ3号,農林3号,ＮＴＴ３号,3号全,外枠未,２号計,国年２号,厚70以上,厚69以下,");
      fprintf(fp_wakuout , "人口央,人口末,人口央,人口末,厚基,パート計,パート１段計,パート１段１,");
      fprintf(fp_wakuout , "パート１段３,パート１段他,パート２段計,パート２段１,パート２段３,パート２段他,");
      fprintf(fp_wakuout , "厚年計,パート１段３厚,パート１段３国,パート１段３地,パート１段３私,");
      fprintf(fp_wakuout , "パート２段３厚,パート２段３国,パート２段３地,パート２段３私,");
      fprintf(fp_wakuout , "パート２段30-,パート２段-30,パート２段１30-,パート２段１-30,パート２段フル,");
      fprintf(fp_wakuout , "パート２段30-35,パート２段20-30,パート２段-20,パート２段１フル,パート２段１30-35,");
      fprintf(fp_wakuout , "パート２段１20-30,パート２段１-20\n");

    /*  男性出力  */
      for ( nendo=KS; nendo<=(int)min(KE,KF); nendo++ ) {
        fprintf(fp_wakuout , "%4d,", nendo );
        for ( bunrui=0; bunrui<=59; bunrui++ ) {
            if ( ( ( PART == 2 ) && ( PARTJ2 == 1 ) ) && ( nendo == PARTYR2 ) ) {
              if(bunrui<=20 || (22<=bunrui && bunrui<=25) || bunrui==31 || bunrui==40){
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][1]
                          + nenrei_kei_ninzu[bunrui][PARTKK-STARTY][1] ) / 2.0 ,0 ) );
              } else {
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][1]
                          + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][1] ) / 2.0 ,0 ) );
              }
            }
            else if ( nendo == PARTYR1 ){
            	if(bunrui<=20 || (22<=bunrui && bunrui<=25) || bunrui==31 || bunrui==40){
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][1]
                          + nenrei_kei_ninzu[bunrui][PARTJJ-STARTY][1] ) / 2.0 ,0 ) );
              	} else {
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][1]
                          + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][1] ) / 2.0 ,0 ) );
              	}
            }
            else {
              fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][1]
                      + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][1] ) / 2.0 ,0 ) );
            }
        }
        fprintf(fp_wakuout , "%lf,\n", raund( ( nenrei_kei_ninzu[60][nendo-STARTY][1]
                    + nenrei_kei_ninzu[60][nendo-1-STARTY][1] ) / 2.0,0 ) );
      }

    /*  女性の表頭  */
      fprintf(fp_wakuout , "女,公的計,厚12種,厚3種,国共2号,地共2号,私学2号,ＪＲ2号,ＪＴ2号,農林2号,");
      fprintf(fp_wakuout , "ＮＴＴ2号,国年1号,厚12種3号,厚3種3号,国共3号,地共3号,私学3号,ＪＲ3号,");
      fprintf(fp_wakuout , "ＪＴ3号,農林3号,ＮＴＴ３号,3号全,外枠未,２号計,国年２号,厚70以上,厚69以下,");
      fprintf(fp_wakuout , "人口央,人口末,人口央,人口末,厚基,パート計,パート１段計,パート１段１,");
      fprintf(fp_wakuout , "パート１段３,パート１段他,パート２段計,パート２段１,パート２段３,パート２段他,");
      fprintf(fp_wakuout , "厚年計,パート１段３厚,パート１段３国,パート１段３地,パート１段３私,");
      fprintf(fp_wakuout , "パート２段３厚,パート２段３国,パート２段３地,パート２段３私,");
      fprintf(fp_wakuout , "パート２段30-,パート２段-30,パート２段１30-,パート２段１-30,パート２段フル,");
      fprintf(fp_wakuout , "パート２段30-35,パート２段20-30,パート２段-20,パート２段１フル,パート２段１30-35,");
      fprintf(fp_wakuout , "パート２段１20-30,パート２段１-20\n");

    /*  女性出力  */
      for ( nendo=KS; nendo<=(int)min(KE,KF); nendo++ ) {
        fprintf(fp_wakuout , "%4d,", nendo );
        for ( bunrui=0; bunrui<=59; bunrui++ ) {
            if ( ( ( PART == 2 ) && ( PARTJ2 == 1 ) ) && ( nendo == PARTYR2 ) ) {
              if(bunrui<=20 || (22<=bunrui && bunrui<=25) || bunrui==31 || bunrui==40){
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][2]
                          + nenrei_kei_ninzu[bunrui][PARTKK-STARTY][2] ) / 2.0 ,0 ) );
              } else {
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][2]
                          + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][2] ) / 2.0 ,0 ) );
              }
            }
            else if ( nendo == PARTYR1 ){
            	if(bunrui<=20 || (22<=bunrui && bunrui<=25) || bunrui==31 || bunrui==40){
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][2]
                          + nenrei_kei_ninzu[bunrui][PARTJJ-STARTY][2] ) / 2.0 ,0 ) );
              	} else {
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][2]
                          + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][2] ) / 2.0 ,0 ) );
              	}
            }
            else {
              fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][2]
                      + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][2] ) / 2.0 ,0 ) );
            }
        }
        fprintf(fp_wakuout , "%lf,\n", raund( (nenrei_kei_ninzu[60][nendo-STARTY][2]
                     + nenrei_kei_ninzu[60][nendo-1-STARTY][2] ) / 2.0 ,0 ) );
      }

    /*  女性有配偶の表頭  */
      fprintf(fp_wakuout , "女有配偶,公的計,厚12種,厚3種,国共2号,地共2号,私学2号,ＪＲ2号,ＪＴ2号,農林2号,");
      fprintf(fp_wakuout , "ＮＴＴ2号,国年1号,厚12種3号,厚3種3号,国共3号,地共3号,私学3号,ＪＲ3号,");
      fprintf(fp_wakuout , "ＪＴ3号,農林3号,ＮＴＴ３号,3号全,外枠未,２号計,国年２号,厚70以上,厚69以下,");
      fprintf(fp_wakuout , "人口央,人口末,人口央,人口末,厚基,パート計,パート１段計,パート１段１,");
      fprintf(fp_wakuout , "パート１段３,パート１段他,パート２段計,パート２段１,パート２段３,パート２段他,");
      fprintf(fp_wakuout , "厚年計,パート１段３厚,パート１段３国,パート１段３地,パート１段３私,");
      fprintf(fp_wakuout , "パート２段３厚,パート２段３国,パート２段３地,パート２段３私,");
      fprintf(fp_wakuout , "パート２段30-,パート２段-30,パート２段１30-,パート２段１-30,パート２段フル,");
      fprintf(fp_wakuout , "パート２段30-35,パート２段20-30,パート２段-20,パート２段１フル,パート２段１30-35,");
      fprintf(fp_wakuout , "パート２段１20-30,パート２段１-20\n");

    /*  女性有配偶出力  */
      for ( nendo=KS; nendo<=(int)min(KE,KF); nendo++ ) {
        fprintf(fp_wakuout , "%4d,", nendo );
        for ( bunrui=0; bunrui<=59; bunrui++ ) {
            if ( ( ( PART == 2 ) && ( PARTJ2 == 1 ) ) && ( nendo == PARTYR2 ) ) {
              if(bunrui<=20 || (22<=bunrui && bunrui<=25) || bunrui==31 || bunrui==40){
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][3]
                          + nenrei_kei_ninzu[bunrui][PARTKK-STARTY][3] ) / 2.0 ,0 ) );
              } else {
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][3]
                          + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][3] ) / 2.0 ,0 ) );
              }
            }
            else if ( nendo == PARTYR1 ){
            	if(bunrui<=20 || (22<=bunrui && bunrui<=25) || bunrui==31 || bunrui==40){
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][3]
                          + nenrei_kei_ninzu[bunrui][PARTJJ-STARTY][3] ) / 2.0 ,0 ) );
              	} else {
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][3]
                          + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][3] ) / 2.0 ,0 ) );
              	}
            }
            else {
              fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][3]
                      + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][3] ) / 2.0 ,0 ) );
            }
        }
        fprintf(fp_wakuout , "%lf,\n", raund( (nenrei_kei_ninzu[60][nendo-STARTY][3]
                     + nenrei_kei_ninzu[60][nendo-1-STARTY][3] ) / 2.0 ,0 ) );
      }

    /*  女性無配偶の表頭  */
      fprintf(fp_wakuout , "女無配偶,公的計,厚12種,厚3種,国共2号,地共2号,私学2号,ＪＲ2号,ＪＴ2号,農林2号,");
      fprintf(fp_wakuout , "ＮＴＴ2号,国年1号,厚12種3号,厚3種3号,国共3号,地共3号,私学3号,ＪＲ3号,");
      fprintf(fp_wakuout , "ＪＴ3号,農林3号,ＮＴＴ３号,3号全,外枠未,２号計,国年２号,厚70以上,厚69以下,");
      fprintf(fp_wakuout , "人口央,人口末,人口央,人口末,厚基,パート計,パート１段計,パート１段１,");
      fprintf(fp_wakuout , "パート１段３,パート１段他,パート２段計,パート２段１,パート２段３,パート２段他,");
      fprintf(fp_wakuout , "厚年計,パート１段３厚,パート１段３国,パート１段３地,パート１段３私,");
      fprintf(fp_wakuout , "パート２段３厚,パート２段３国,パート２段３地,パート２段３私,");
      fprintf(fp_wakuout , "パート２段30-,パート２段-30,パート２段１30-,パート２段１-30,パート２段フル,");
      fprintf(fp_wakuout , "パート２段30-35,パート２段20-30,パート２段-20,パート２段１フル,パート２段１30-35,");
      fprintf(fp_wakuout , "パート２段１20-30,パート２段１-20\n");

    /*  女性無配偶出力  */
      for ( nendo=KS; nendo<=(int)min(KE,KF); nendo++ ) {
        fprintf(fp_wakuout , "%4d,", nendo );
        for ( bunrui=0; bunrui<=59; bunrui++ ) {
            if ( ( ( PART == 2 ) && ( PARTJ2 == 1 ) ) && ( nendo == PARTYR2 ) ) {
              if(bunrui<=20 || (22<=bunrui && bunrui<=25) || bunrui==31 || bunrui==40){
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][4]
                          + nenrei_kei_ninzu[bunrui][PARTKK-STARTY][4] ) / 2.0 ,0 ) );
              } else {
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][4]
                          + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][4] ) / 2.0 ,0 ) );
              }
            }
            else if ( nendo == PARTYR1 ){
            	if(bunrui<=20 || (22<=bunrui && bunrui<=25) || bunrui==31 || bunrui==40){
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][4]
                          + nenrei_kei_ninzu[bunrui][PARTJJ-STARTY][4] ) / 2.0 ,0 ) );
              	} else {
                  fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][4]
                          + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][4] ) / 2.0 ,0 ) );
              	}
            }
            else {
              fprintf(fp_wakuout , "%lf,", raund( (nenrei_kei_ninzu[bunrui][nendo-STARTY][4]
                      + nenrei_kei_ninzu[bunrui][nendo-1-STARTY][4] ) / 2.0 ,0 ) );
            }
        }
        fprintf(fp_wakuout , "%lf,\n", raund( (nenrei_kei_ninzu[60][nendo-STARTY][4]
                     + nenrei_kei_ninzu[60][nendo-1-STARTY][4] ) / 2.0 ,0 ) );
      }



    /*  ファイルクローズ  */
      fclose( fp_wakuout ) ;




    /*  出力ファイル名セットと開く  */
      sprintf(filename, "/rev31/wakuc/rslt/ver_3/rslt%04d/waku%04d-settei.csv",BANGO, BANGO ) ;
      if ((fp_wakuout = fopen(filename, "w")) == NULL) {
           fprintf(stderr, "出力wakuファイルを開けません!\n");
           exit (2); /* 終了 */
      }

    /*  各種設定出力  */
      fprintf(fp_wakuout , "試算番号,BANGO=,%d\n", BANGO );
      fprintf(fp_wakuout , "開始年度,STARTY=,%d\n", STARTY );
      fprintf(fp_wakuout , "終了年度,ENDY=,%d\n", ENDY );
      fprintf(fp_wakuout , "計算モード,MODE=,%d\n", MODE );
      fprintf(fp_wakuout , "基準年度,KIJUN=,%d\n", KIJUN );
      fprintf(fp_wakuout , "出力開始年度,KS=,%d\n", KS );
      fprintf(fp_wakuout , "推計終了年度,KE=,%d\n", KE );
      fprintf(fp_wakuout , "出力終了年度,KF=,%d\n", KF );
      fprintf(fp_wakuout , "人口の設定,JIN=,%d\n", JIN );
      fprintf(fp_wakuout , "死亡率の設定,QX=,%d\n", QX );
      fprintf(fp_wakuout , "人口推計開始年度,SJINKOY=,%d\n", SJINKOY );
      fprintf(fp_wakuout , "有配偶者推計終了年度,YUHAIGY=,%d\n", YUHAIGY );
      fprintf(fp_wakuout , "有配偶者割合,YUHAIGX=,%d\n", YUHAIGX );
      fprintf(fp_wakuout , "労働力率,ROUDR=,%d\n", ROUDR );
      fprintf(fp_wakuout , "労働力率設定,ROUDYR=,%d\n", ROUDYR );
      fprintf(fp_wakuout , "国共済推計方法,KYOREQK=,%d\n",KYOREQK );
      fprintf(fp_wakuout , "地共済推計方法,KYOREQR=,%d\n",KYOREQR );
      fprintf(fp_wakuout , "私学共済推計方法,KYOREQS=,%d\n",KYOREQS );
      fprintf(fp_wakuout , "国共済データ投入番号,KYOREQBK=,%d\n",KYOREQBK );
      fprintf(fp_wakuout , "地共済データ投入番号,KYOREQBR=,%d\n",KYOREQBR );
      fprintf(fp_wakuout , "私学共済データ投入番号,KYOREQBS=,%d\n",KYOREQBS );
      fprintf(fp_wakuout , "女性３号の推計方法,MODESAN=,%d\n",MODESAN );
      fprintf(fp_wakuout , "パート適用導入の有無,PART=,%d\n",PART );
      fprintf(fp_wakuout , "パート適用導入年度1,PARTYR1=,%d\n",PARTYR1 );
      fprintf(fp_wakuout , "パート適用導入年度2,PARTYR2=,%d\n",PARTYR2 );
      fprintf(fp_wakuout , "パート適用導入時期,PARTJ2=,%d\n",PARTJ2 );
      fprintf(fp_wakuout , "パート基礎数値1,PARTK1=,%d\n",PARTK1 );
      fprintf(fp_wakuout , "パート基礎数値2,PARTK2=,%d\n",PARTK2 );
      fprintf(fp_wakuout , "パート基礎数値の年度,PARTKYR=,%d\n",PARTKYR );
      fprintf(fp_wakuout , "45年モデル調整率,MODE45=,%d\n",MODE45 );


    /*  ファイルクローズ  */
      fclose( fp_wakuout ) ;




}


