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

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



void roudfout(void) {

/*  変数定義  */
    char    filename[250]    ; 
    int     ii ;
    int     bunrui ; 
    double  nenrei_kei_ninzu[61][ENDY-STARTY+1][5]  ;
    double  nenrei_kei_ninzuX[61][ENDY-STARTY+1][5] ;
    double  nenrei_betu_ninzu[121] ;


/* 新分類番号ごとにループ */

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

      sprintf(filename, "/rev31/wakuc/rslt/ver_3/rslt%04d/wakuroud%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(KE,KF) ; nendo++ ) {

          nenrei_kei_ninzu[bunrui][nendo-STARTY][sei] = 0.0 ;
          nenrei_kei_ninzuX[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] = jinko_c[nendo-STARTY][sei][nenrei] ;
                break ;
              case 1: 
                nenrei_betu_ninzu[nenrei] = jinko_m[nendo-STARTY][sei][nenrei] ;
                break ;
              case 2: 
                nenrei_betu_ninzu[nenrei] = roudj_c[nendo-STARTY][sei][nenrei] ;
                break ;
              case 3: 
                nenrei_betu_ninzu[nenrei] = roudj_m[nendo-STARTY][sei][nenrei] ;
                break ;
              case 4: 
                nenrei_betu_ninzu[nenrei] = syugyoj_c[nendo-STARTY][sei][nenrei]  ;
                break ;
              case 5: 
                nenrei_betu_ninzu[nenrei] = syugyoj_m[nendo-STARTY][sei][nenrei] ;
                break ;
              case 6: 
                nenrei_betu_ninzu[nenrei] = koyouj_c[0][nendo-STARTY][sei][nenrei] ;
                break ;
              case 7: 
                nenrei_betu_ninzu[nenrei] = koyouj_m[0][nendo-STARTY][sei][nenrei] ;
                break ;
              case 8: 
                nenrei_betu_ninzu[nenrei] = koyouj_c[1][nendo-STARTY][sei][nenrei] ;
                break ;
              case 9: 
                nenrei_betu_ninzu[nenrei] = koyouj_m[1][nendo-STARTY][sei][nenrei] ;
                break ;
              case 10:
                nenrei_betu_ninzu[nenrei] = koyouj_c[2][nendo-STARTY][sei][nenrei] ;
                break ;
              case 11: 
                nenrei_betu_ninzu[nenrei] = koyouj_m[2][nendo-STARTY][sei][nenrei] ;
                break ;
              case 12: 
                nenrei_betu_ninzu[nenrei] = jieigyoj_c[nendo-STARTY][sei][nenrei] ;
                break ;
              case 13: 
                nenrei_betu_ninzu[nenrei] = jieigyoj_m[nendo-STARTY][sei][nenrei] ;
                break ;
              case 14: 
                nenrei_betu_ninzu[nenrei] = soroudh_c[0][nendo-STARTY][sei][nenrei] * 12 / 10000 ;
                break ;
              case 15: 
                nenrei_betu_ninzu[nenrei] = soroudh_m[0][nendo-STARTY][sei][nenrei] * 12 / 10000  ;
                break ;
              case 16: 
                nenrei_betu_ninzu[nenrei] = soroudh_c[1][nendo-STARTY][sei][nenrei] * 12 / 10000  ;
                break ;
              case 17: 
                nenrei_betu_ninzu[nenrei] = soroudh_m[1][nendo-STARTY][sei][nenrei] * 12 / 10000  ;
                break ;
              case 18: 
                nenrei_betu_ninzu[nenrei] = soroudh_c[2][nendo-STARTY][sei][nenrei] * 12 / 10000  ;
                break ;
              case 19: 
                nenrei_betu_ninzu[nenrei] = soroudh_m[2][nendo-STARTY][sei][nenrei] * 12 / 10000  ;
                break ;
              case 20: 
                nenrei_betu_ninzu[nenrei] = soroudh_c[3][nendo-STARTY][sei][nenrei] * 12 / 10000  ;
                break ;
              case 21: 
                nenrei_betu_ninzu[nenrei] = soroudh_m[3][nendo-STARTY][sei][nenrei] * 12 / 10000  ;
                break ;
              case 22:
                nenrei_betu_ninzu[nenrei] = koyouj_c[6][nendo-STARTY][sei][nenrei] ;
                break ;
              case 23: 
                nenrei_betu_ninzu[nenrei] = koyouj_m[6][nendo-STARTY][sei][nenrei] ;
                break ;
              case 24:
                nenrei_betu_ninzu[nenrei] = koyouj_c[4][nendo-STARTY][sei][nenrei]+koyouj_c[5][nendo-STARTY][sei][nenrei] ;
                break ;
              case 25: 
                nenrei_betu_ninzu[nenrei] = koyouj_m[4][nendo-STARTY][sei][nenrei]+koyouj_m[5][nendo-STARTY][sei][nenrei] ;
                break ;
              case 26:
                nenrei_betu_ninzu[nenrei] = koyouj_c[3][nendo-STARTY][sei][nenrei] ;
                break ;
              case 27: 
                nenrei_betu_ninzu[nenrei] = koyouj_m[3][nendo-STARTY][sei][nenrei] ;
                break ;
              case 28: 
                nenrei_betu_ninzu[nenrei] = koyouj_c[7][nendo-STARTY][sei][nenrei] ;
                break ;
              case 29: 
                nenrei_betu_ninzu[nenrei] = koyouj_m[7][nendo-STARTY][sei][nenrei] ;
                break ;
              case 30: 
                nenrei_betu_ninzu[nenrei] = koyouj_c[8][nendo-STARTY][sei][nenrei] ;
                break ;
              case 31: 
                nenrei_betu_ninzu[nenrei] = koyouj_m[8][nendo-STARTY][sei][nenrei] ;
                break ;
              case 32:
                nenrei_betu_ninzu[nenrei] = koyouj_c[9][nendo-STARTY][sei][nenrei] ;
                break ;
              case 33: 
                nenrei_betu_ninzu[nenrei] = koyouj_m[9][nendo-STARTY][sei][nenrei] ;
                break ;
              case 34: 
                nenrei_betu_ninzu[nenrei] = roudr_c[nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 35: 
                nenrei_betu_ninzu[nenrei] = roudr_m[nendo-STARTY][sei][nenrei] * 1000000  ;
                break ;
              case 36: 
                nenrei_betu_ninzu[nenrei] = syuwari_c[nendo-STARTY][sei][nenrei] * 1000000  ;
                break ;
              case 37:
                nenrei_betu_ninzu[nenrei] = syuwari_m[nendo-STARTY][sei][nenrei] * 1000000  ;
                break ;
              case 38: 
                nenrei_betu_ninzu[nenrei] = syugyor_c[nendo-STARTY][sei][nenrei] * 1000000  ;
                break ;
              case 39:
                nenrei_betu_ninzu[nenrei] = syugyor_m[nendo-STARTY][sei][nenrei] * 1000000  ;
                break ;
              case 40: 
                nenrei_betu_ninzu[nenrei] = koyour_c[nendo-STARTY][sei][nenrei] * 1000000  ;
                break ;
              case 41:
                nenrei_betu_ninzu[nenrei] = koyour_m[nendo-STARTY][sei][nenrei] * 1000000  ;
                break ;
              case 42: 
                nenrei_betu_ninzu[nenrei] = koyour_a_c[nendo-STARTY][sei][nenrei] * 1000000  ;
                break ;
              case 43:
                nenrei_betu_ninzu[nenrei] = koyour_a_m[nendo-STARTY][sei][nenrei] * 1000000  ;
                break ;
              case 44: 
                nenrei_betu_ninzu[nenrei] = seikir_c[nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 45: 
                nenrei_betu_ninzu[nenrei] = seikir_m[nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 46: 
                nenrei_betu_ninzu[nenrei] = hiseikihurur_c[0][nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 47: 
                nenrei_betu_ninzu[nenrei] = hiseikihurur_m[0][nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 48: 
                nenrei_betu_ninzu[nenrei] = hiseikihurur_c[1][nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 49: 
                nenrei_betu_ninzu[nenrei] = hiseikihurur_m[1][nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 50: 
                nenrei_betu_ninzu[nenrei] = hiseikitanr_c[0][nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 51: 
                nenrei_betu_ninzu[nenrei] = hiseikitanr_m[0][nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 52: 
                nenrei_betu_ninzu[nenrei] = hiseikitanr_c[1][nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 53: 
                nenrei_betu_ninzu[nenrei] = hiseikitanr_m[1][nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 54: 
                if ( nenrei == 15 ) {
                  nenrei_betu_ninzu[nenrei] = kounenteki_m[1][nendo-STARTY] * 1000000 ;
                }
                else if ( nenrei == 16 ) {
                  nenrei_betu_ninzu[nenrei] = kounenteki_m[2][nendo-STARTY] * 1000000 ;
                }
                else if ( nenrei == 17 ) {
                  nenrei_betu_ninzu[nenrei] = kounenteki_m[3][nendo-STARTY] * 1000000 ;
                }
                else if ( nenrei == 18 ) {
                  nenrei_betu_ninzu[nenrei] = kounenteki_m[4][nendo-STARTY] * 1000000 ;
                }
                else if ( nenrei == 19 ) {
                  nenrei_betu_ninzu[nenrei] = kounenteki_m[5][nendo-STARTY] * 1000000 ;
                }
                else if ( nenrei == 20 ) {
                  nenrei_betu_ninzu[nenrei] = kounenteki_m[6][nendo-STARTY] * 1000000 ;
                }
                break ;
              case 55: 
                nenrei_betu_ninzu[nenrei] = kounen_cho[nendo-STARTY][sei][nenrei] * 1000000 ;
                break ;
              case 56: 
                nenrei_betu_ninzu[nenrei] = soroudh_c[9][nendo-STARTY][sei][nenrei] * 12 / 10000  ;
                break ;
              case 57: 
                nenrei_betu_ninzu[nenrei] = soroudh_m[9][nendo-STARTY][sei][nenrei] * 12 / 10000  ;
                break ;
              case 58: 
                if ( nenrei == 15 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_c[1][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 16 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_c[2][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 17 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_c[3][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 18 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_c[4][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 19 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_c[5][nendo-STARTY] * 1000000;
                }                
                else if ( nenrei == 20 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_c[6][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 21 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_c[7][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 22 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_c[8][nendo-STARTY] * 1000000;
                }                                                
                else if ( nenrei == 23 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_c[9][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 24 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_c[10][nendo-STARTY] * 1000000;
                }                
                break ;
              case 59: 
                if ( nenrei == 15 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_m[1][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 16 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_m[2][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 17 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_m[3][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 18 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_m[4][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 19 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_m[5][nendo-STARTY] * 1000000;
                }                
                else if ( nenrei == 20 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_m[6][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 21 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_m[7][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 22 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_m[8][nendo-STARTY] * 1000000;
                }                                                
                else if ( nenrei == 23 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_m[9][nendo-STARTY] * 1000000;
                }
                else if ( nenrei == 24 ) {
                  nenrei_betu_ninzu[nenrei] = heikinh_m[10][nendo-STARTY] * 1000000;
                }                
                break ;
              case 60: 
                  nenrei_betu_ninzu[nenrei] = tankor_cho_c[nendo-STARTY][sei][nenrei] * 1000000;
              break ;
            }
            nenrei_kei_ninzu[bunrui][nendo-STARTY][sei] += nenrei_betu_ninzu[nenrei] ;
            if ( nenrei< 80 ) {
              nenrei_kei_ninzuX[bunrui][nendo-STARTY][sei] += nenrei_betu_ninzu[nenrei] ;
            }
            if ( nenrei>100 ) {
              nenrei_betu_ninzu[100] += nenrei_betu_ninzu[nenrei] ;
            }
            if ( ( bunrui>=34 ) && ( bunrui<=48 ) ) { 
              nenrei_kei_ninzu[bunrui][nendo-STARTY][sei] = 0.0 ;
              nenrei_kei_ninzuX[bunrui][nendo-STARTY][sei] = 0.0 ;
            }

          }

          /*  出力  */
          if ( nendo>=KS ) { 
              fprintf(fp_wakuout , "roud-%2d,%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-roudkei.csv", BANGO, BANGO ) ;
      if ((fp_wakuout = fopen(filename, "w")) == NULL) {
           fprintf(stderr, "出力wakuファイルを開けません!\n");
           exit (2); /* 終了 */
      }

    /*  表頭出力  */
      fprintf(fp_wakuout , "15歳以上全年齢,試算番号,BANGO=,%d,", BANGO );
      fprintf(fp_wakuout , "人口,JIN=,%d,", JIN );
      fprintf(fp_wakuout , "死亡率,QX=,%d,", QX );
      fprintf(fp_wakuout , "労働力率,ROUDR=,%d\n", ROUDR );

    /*  男女計の表頭  */
      fprintf(fp_wakuout , "男女計,,人口央,人口末,労人央,労人末,就業人央,就業人末,");
      fprintf(fp_wakuout , "総雇者央,総雇者末,正規雇央,正規雇末,非正規フル雇央,非正規フル雇末,ｩ営央,ｩ営末,");
      fprintf(fp_wakuout , "総時間央,総時間末,正規時間央,正規時間末,非正規フル時間央,非正規フル時間末,");
      fprintf(fp_wakuout , "非正規短時間央,非正規短時間末,短35央,短35末,短20-30央,短20-30末,短-20央,短-20末,");
      fprintf(fp_wakuout , "被用ﾒ央,被用ﾒ末,正規被用ﾒ央,正規被用ﾒ末,非正規フル被用ﾒ央,非正規フル被用ﾒ末,被平均時間央,短被平均時間末,正規央,正規末,短央,短末\n");

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

    /*  男性の表頭  */
      fprintf(fp_wakuout , "男,,人口央,人口末,労人央,労人末,就業人央,就業人末,");
      fprintf(fp_wakuout , "総雇者央,総雇者末,正規雇央,正規雇末,非正規フル雇央,非正規フル雇末,ｩ営央,ｩ営末,");
      fprintf(fp_wakuout , "総時間央,総時間末,正規時間央,正規時間末,非正規フル時間央,非正規フル時間末,");
      fprintf(fp_wakuout , "非正規短時間央,非正規短時間末,短35央,短35末,短20-30央,短20-30末,短-20央,短-20末,");
      fprintf(fp_wakuout , "被用ﾒ央,被用ﾒ末,正規被用ﾒ央,正規被用ﾒ末,非正規フル被用ﾒ央,非正規フル被用ﾒ末\n");

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

    /*  女性の表頭  */
      fprintf(fp_wakuout , "女,,人口央,人口末,労人央,労人末,就業人央,就業人末,");
      fprintf(fp_wakuout , "総雇者央,総雇者末,正規雇央,正規雇末,非正規フル雇央,非正規フル雇末,ｩ営央,ｩ営末,");
      fprintf(fp_wakuout , "総時間央,総時間末,正規時間央,正規時間末,非正規フル時間央,非正規フル時間末,");
      fprintf(fp_wakuout , "非正規短時間央,非正規短時間末,短35央,短35末,短20-30央,短20-30末,短-20央,短-20末,");
      fprintf(fp_wakuout , "被用ﾒ央,被用ﾒ末,正規被用ﾒ央,正規被用ﾒ末,非正規フル被用ﾒ央,非正規フル被用ﾒ末\n");

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

    /*  女性有配偶の表頭  */
      fprintf(fp_wakuout , "女有配偶,,人口央,人口末,労人央,労人末,就業人央,就業人末,");
      fprintf(fp_wakuout , "総雇者央,総雇者末,正規雇央,正規雇末,非正規フル雇央,非正規フル雇末,ｩ営央,ｩ営末,");
      fprintf(fp_wakuout , "総時間央,総時間末,正規時間央,正規時間末,非正規フル時間央,非正規フル時間末,");
      fprintf(fp_wakuout , "非正規短時間央,非正規短時間末,短35央,短35末,短20-30央,短20-30末,短-20央,短-20末,");
      fprintf(fp_wakuout , "被用ﾒ央,被用ﾒ末,正規被用ﾒ央,正規被用ﾒ末,非正規フル被用ﾒ央,非正規フル被用ﾒ末\n");

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

    /*  女性無配偶の表頭  */
      fprintf(fp_wakuout , "女無配偶,,人口央,人口末,労人央,労人末,就業人央,就業人末,");
      fprintf(fp_wakuout , "総雇者央,総雇者末,正規雇央,正規雇末,非正規フル雇央,非正規フル雇末,ｩ営央,ｩ営末,");
      fprintf(fp_wakuout , "総時間央,総時間末,正規時間央,正規時間末,非正規フル時間央,非正規フル時間末,");
      fprintf(fp_wakuout , "非正規短時間央,非正規短時間末,短35央,短35末,短20-30央,短20-30末,短-20央,短-20末,");
      fprintf(fp_wakuout , "被用ﾒ央,被用ﾒ末,正規被用ﾒ央,正規被用ﾒ末,非正規フル被用ﾒ央,非正規フル被用ﾒ末\n");

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



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





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

    /*  表頭出力  */
      fprintf(fp_wakuout , "15〜79歳限定,試算番号,BANGO=,%d,", BANGO );
      fprintf(fp_wakuout , "人口,JIN=,%d,", JIN );
      fprintf(fp_wakuout , "死亡率,QX=,%d,", QX );
      fprintf(fp_wakuout , "労働力率,ROUDR=,%d\n", ROUDR );

    /*  男女計の表頭  */
      fprintf(fp_wakuout , "男女計,,人口央,人口末,労人央,労人末,就業人央,就業人末,");
      fprintf(fp_wakuout , "総雇者央,総雇者末,正規雇央,正規雇末,非正規フル雇央,非正規フル雇末,ｩ営央,ｩ営末,");
      fprintf(fp_wakuout , "総時間央,総時間末,正規時間央,正規時間末,非正規フル時間央,非正規フル時間末,");
      fprintf(fp_wakuout , "非正規短時間央,非正規短時間末,短35央,短35末,短20-30央,短20-30末,短-20央,短-20末,");
      fprintf(fp_wakuout , "被用ﾒ央,被用ﾒ末,正規被用ﾒ央,正規被用ﾒ末,非正規フル被用ﾒ央,非正規フル被用ﾒ末,被平均時間央,短被平均時間末,正規央,正規末,短央,短末\n");

    /*  男女計出力  */
      for ( nendo=KS; nendo<=(int)min(KE,KF); nendo++ ) {
        fprintf(fp_wakuout , "%4d,0,", nendo );
        for ( bunrui=0; bunrui<=33; bunrui++ ) {
            fprintf(fp_wakuout , "%lf,", raund( nenrei_kei_ninzuX[bunrui][nendo-STARTY][0],0 ) );
        }
        fprintf(fp_wakuout , "%lf,", heikinh_c[10][nendo-STARTY] );
        fprintf(fp_wakuout , "%lf,", heikinh_m[10][nendo-STARTY] );
        fprintf(fp_wakuout , "%lf,", heikinh_c[1][nendo-STARTY] );
        fprintf(fp_wakuout , "%lf,", heikinh_m[1][nendo-STARTY] );
        fprintf(fp_wakuout , "%lf,", heikinh_c[8][nendo-STARTY] );
        fprintf(fp_wakuout , "%lf,\n", heikinh_m[8][nendo-STARTY] );
      }

    /*  男性の表頭  */
      fprintf(fp_wakuout , "男,,人口央,人口末,労人央,労人末,就業人央,就業人末,");
      fprintf(fp_wakuout , "総雇者央,総雇者末,正規雇央,正規雇末,非正規フル雇央,非正規フル雇末,ｩ営央,ｩ営末,");
      fprintf(fp_wakuout , "総時間央,総時間末,正規時間央,正規時間末,非正規フル時間央,非正規フル時間末,");
      fprintf(fp_wakuout , "非正規短時間央,非正規短時間末,短35央,短35末,短20-30央,短20-30末,短-20央,短-20末,");
      fprintf(fp_wakuout , "被用ﾒ央,被用ﾒ末,正規被用ﾒ央,正規被用ﾒ末,非正規フル被用ﾒ央,非正規フル被用ﾒ末,被平均時間央,短被平均時間末,正規央,正規末,短央,短末\n");

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

    /*  女性の表頭  */
      fprintf(fp_wakuout , "女,,人口央,人口末,労人央,労人末,就業人央,就業人末,");
      fprintf(fp_wakuout , "総雇者央,総雇者末,正規雇央,正規雇末,非正規フル雇央,非正規フル雇末,ｩ営央,ｩ営末,");
      fprintf(fp_wakuout , "総時間央,総時間末,正規時間央,正規時間末,非正規フル時間央,非正規フル時間末,");
      fprintf(fp_wakuout , "非正規短時間央,非正規短時間末,短35央,短35末,短20-30央,短20-30末,短-20央,短-20末,");
      fprintf(fp_wakuout , "被用ﾒ央,被用ﾒ末,正規被用ﾒ央,正規被用ﾒ末,非正規フル被用ﾒ央,非正規フル被用ﾒ末\n");

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

    /*  女性有配偶の表頭  */
      fprintf(fp_wakuout , "女有配偶,,人口央,人口末,労人央,労人末,就業人央,就業人末,");
      fprintf(fp_wakuout , "総雇者央,総雇者末,正規雇央,正規雇末,非正規フル雇央,非正規フル雇末,ｩ営央,ｩ営末,");
      fprintf(fp_wakuout , "総時間央,総時間末,正規時間央,正規時間末,非正規フル時間央,非正規フル時間末,");
      fprintf(fp_wakuout , "非正規短時間央,非正規短時間末,短35央,短35末,短20-30央,短20-30末,短-20央,短-20末,");
      fprintf(fp_wakuout , "被用ﾒ央,被用ﾒ末,正規被用ﾒ央,正規被用ﾒ末,非正規フル被用ﾒ央,非正規フル被用ﾒ末\n");

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

    /*  女性無配偶の表頭  */
      fprintf(fp_wakuout , "女無配偶,,人口央,人口末,労人央,労人末,就業人央,就業人末,");
      fprintf(fp_wakuout , "総雇者央,総雇者末,正規雇央,正規雇末,非正規フル雇央,非正規フル雇末,ｩ営央,ｩ営末,");
      fprintf(fp_wakuout , "総時間央,総時間末,正規時間央,正規時間末,非正規フル時間央,非正規フル時間末,");
      fprintf(fp_wakuout , "非正規短時間央,非正規短時間末,短35央,短35末,短20-30央,短20-30末,短-20央,短-20末,");
      fprintf(fp_wakuout , "被用ﾒ央,被用ﾒ末,正規被用ﾒ央,正規被用ﾒ末,非正規フル被用ﾒ央,非正規フル被用ﾒ末\n");

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



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







}


