#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "set.h"
#include "glva.h"


void shus_econ_out(void){
	/**************************************************************************
                       	宱嵪慜採摍偺弌椡
	 **************************************************************************/
	int k;
	int ii;
	FILE *ofp;
	
	
	for(ii=0; ii<=4; ii++){
		ofp = ofp01_shushi[ii];
		
		fprintf(ofp, "宱嵪慜採摍\n");
		fprintf(ofp, "擭搙,暔壙,捓嬥,塣梡棙夞傝,斾椺夵掕棪,斾椺婛嵸68嵨,婎慴夵掕棪,婎慴婛嵸68嵨,\n");
		for(k=5; k<=Ke; k++){
			fprintf(ofp, "%3d, %5.2f, %5.2f, %5.2f, ", k, Ci[k-ECSTY]*100.0, H[k-ECSTY]*100.0, Ri[k-ECSTY]*100.0);
			fprintf(ofp, "%5.2f, %5.2f, %5.2f, %5.2f,\n",
			    (Krb[k-ECSTY][67-ECXA]-1.0)*100.0,(Krb[k-ECSTY][68-ECXA]-1.0)*100.0,
			    (Kra[k-ECSTY][67-ECXA]-1.0)*100.0,(Kra[k-ECSTY][68-ECXA]-1.0)*100.0);
		}
		fprintf(ofp, "\n");
	}
}



void shus_nin_out(void){
	/**************************************************************************
                       	旐曐尟幰悢丄庴媼尃幰悢摍偺弌椡
	 **************************************************************************/
	/* 庴媼幰悢:T4xtp[ii:0-4][S:0-3][I:0-6][K][X] */
	int s, i, k, x;
	int ii;
	int s2;
	double t4sx[5][4][7][ENDY-STTY+1];
	FILE *ofp;
	
	/* 曄悢弶婜壔 */
	for(ii=0; ii<5; ii++){
		for(s=0; s<4; s++){
			for(i=0; i<7; i++){
				for(k=0; k<ENDY-STTY+1; k++){
					t4sx[ii][s][i][k] = 0.;
				}
			}
		}
	}
	
	/*** 弌椡梡僨乕僞偺僙僢僩 ***/
	
	for(ii=1; ii<=4; ii++){
		if(ii==1) s2 = 3;
		else      s2 = 2;
		
		for(s=0; s<=s2; s++){
			for(i=0; i<7; i++){
				for(k=Ks+1; k<=Ke; k++){
					for(x=XA-1; x<=XB; x++){
						t4sx[ii][s][i][k-STTY] += T4xtp[ii][s][i][k-STTY][x];
						if(ii==1 || (ii>1 && k>Kyoskijun)){
							t4sx[0][s][i][k-STTY] += T4xtp[ii][s][i][k-STTY][x];
						} else if(k==Kyoskijun){
							t4sx[0][s][i][k-STTY] += T4xtp[ii][s][i][k-STTY][x]/2.;
						}
					}
				}
			}
		}
		
		/*** 堦尦壔帪偺崌寁偺嶌惉摍 ***/
		for(s=0; s<=s2; s++){
			for(k=Ks+1; k<=Ke; k++){
				if(ii==1 || (ii>1 && k>Kyoskijun)){
					Ap[0][s][k-STTY]   += Ap[ii][s][k-STTY];
					Ap65[0][s][k-STTY] += Ap65[ii][s][k-STTY];
				} else if(k==Kyoskijun){
					Ap[0][s][k-STTY]   += Ap[ii][s][k-STTY]   / 2.;
					Ap65[0][s][k-STTY] += Ap65[ii][s][k-STTY] / 2.;
				}
			}
		}
	}
	
	/*** 弌椡梡僨乕僞偺僼傽僀儖弌椡 ***/
	for(ii=0; ii<=4; ii++){
		ofp = ofp01_shushi[ii];
		
		if(ii<=1) s2 = 3;
		else      s2 = 2;
		
		fprintf(ofp, "擭搙,旐曐尟幰,榁楊,榁嵼,捠榁,捠嵼,忈奞,堚懓,");
		fprintf(ofp, "旐曐尟幰丒抝,旐曐尟幰丒彈,");
		fprintf(ofp, "65嵨埲忋旐曐尟幰丒抝,65嵨埲忋旐曐尟幰丒彈,");
		fprintf(ofp, "榁楊嘆,榁嵼嘆,捠榁嘆,捠嵼嘆,忈奞嘆,堚懓嘆,");
		fprintf(ofp, "榁楊嘇,榁嵼嘇,捠榁嘇,捠嵼嘇,忈奞嘇,堚懓嘇,");
		if(s2==3){
			fprintf(ofp, "榁楊嘊,榁嵼嘊,捠榁嘊,捠嵼嘊,忈奞嘊,堚懓嘊");
		}
		fprintf(ofp, "\n");
		
		for(k=FLKS_SHU; k<=FLKE_SHU; k++){
			fprintf(ofp, "%3d,", k);
			fprintf(ofp, "%14.8e,", Ap[ii][0][k-STTY]);
			for(i=1; i<=6; i++) fprintf(ofp, "%14.8e,", t4sx[ii][0][i][k-STTY]);
			fprintf(ofp, "%14.8e,%14.8e,", Ap[ii][1][k-STTY]  +Ap[ii][3][k-STTY],   Ap[ii][2][k-STTY]);
			fprintf(ofp, "%14.8e,%14.8e,", Ap65[ii][1][k-STTY]+Ap65[ii][3][k-STTY], Ap65[ii][2][k-STTY]);
			for(s=1; s<=s2; s++){
				for(i=1; i<=6; i++){
					fprintf(ofp, "%14.8e,", t4sx[ii][s][i][k-STTY]);
				}
			}
			fprintf(ofp, "\n");
		}
	}
	
	
	for(ii=1; ii<=4 ; ii++){
		for(i=1; i<=6 ; i++){
			if(i==1 || i==2){
				s=0;
			} else if (i<=4){
				s=1;
			} else {
				s=i-3;
			}
			for(k=FLKS; k<=FLKE; k++){
				Ukyu[0][ii][s][k-STTY] += t4sx[ii][0][i][k-STTY];
				Ukyu[0][0][s][k-STTY]  += t4sx[ii][0][i][k-STTY];
			}
		}
	}
}



void shus_shushiout(int mode){  /***** 廂巟弌椡 *****/
	int k, i;
	int kend_t, kend_h;
	double dtemp;
	FILE *ofp;
	int ii, psd;
	double tanni[31];
	
	for(i=0; i<31; i++){
		if(i<=25 || i==30){
			tanni[i] = 1.0E-8;
		}else if(i==27 || i==28){
			tanni[i] = 1.0E+2;
		}else{
			tanni[i] = 1.0;
		}
	}
	
	
	if(mode==1){  /*** 嵟廔擭搙偺寁嶼 ***/
		/* 岤擭偺嵟廔擭搙 */
		kend_h = 0;
		dtemp = Escutrrh[Ke-1-ECSTY][67-ECXA];
		for(k=Ke-1; k>=Ks+1; k--){
			if(Escutrrh[k-1-ECSTY][67-ECXA]-dtemp>1.0E-13){
				kend_h = k;
				break;
			} else {
				dtemp = Escutrrh[k-1-ECSTY][67-ECXA];
			}
		}
		/* 崙擭偺嵟廔擭搙 */
		kend_t = 0;
		dtemp = Escutrrt[Ke-1-ECSTY][67-ECXA];
		for(k=Ke-1; k>=Ks+1; k--){
			if(Escutrrt[k-1-ECSTY][67-ECXA]-dtemp>1.0E-13){
				kend_t = k;
				break;
			} else {
				dtemp = Escutrrt[k-1-ECSTY][67-ECXA];
			}
		}
	}
	
	for(ii=0; ii<=4; ii++){
		ofp = ofp01_shushi[ii];
		
		/**************************************************************************
		                    嵟廔挷惍擭搙傪弌椡
		 **************************************************************************/
		if(mode==1){
			if(ii==1) printf(" 挷惍嵟廔擭搙 ");
			fprintf(ofp, "\n挷惍嵟廔擭搙, ");
			if(kend_h!=0 && kend_h!=Ke-1){
				if(ii==1)
				  printf(" 岤擭丗%3d (%.1f) ", kend_h, Escutrrh[MAX(0,kend_h-ECSTY)][67-ECXA]*100.);
				fprintf(ofp, " 岤擭, %3d, %20.14e, ", kend_h, Escutrrh[MAX(0,kend_h-ECSTY)][67-ECXA]);
			} else {
				if(ii==1) printf(" 岤擭丗 -  (%20.14e)", Escutrrh[Ke-1-ECSTY][67-ECXA]);
				fprintf(ofp, " 岤擭, - , - , ");
			}
			if(kend_t!=0 && kend_t!=Ke-1){
				if(ii==1)
				  printf(" 崙擭丗%3d (%.1f)\n", kend_t, Escutrrt[MAX(0,kend_t-ECSTY)][67-ECXA]*100.);
				fprintf(ofp, " 崙擭, %3d, %20.14e\n", kend_t, Escutrrt[MAX(0,kend_t-ECSTY)][67-ECXA]);
			} else {
				if(ii==1) printf(" 崙擭丗 -  (%20.14e)\n", Escutrrt[Ke-1-ECSTY][67-ECXA]);
				fprintf(ofp, " 崙擭, - , - \n");
			}
		}
		
		fprintf(ofp, "\n");
		
		/**************************************************************************
		                    廂巟尒捠偟偺弌椡
		 **************************************************************************/
		
		if(mode==0){
			fprintf(ofp, "\n廂巟尒捠偟亂僗儔僀僪挷惍慜亃\n");
		} else {
			fprintf(ofp, "\n廂巟尒捠偟亂僗儔僀僪挷惍屻亃\n");
		}
		
		fprintf(ofp,"擭搙,廂擖寁,曐尟椏廂擖,(嵞)忋忔偣暘,塣梡廂擖,崙屔晧扴,");
		fprintf(ofp, "(嵞)崙屔婎慴,(嵞)崙屔宱夁斾椺,(嵞)崙屔宱夁掕妟,");
		fprintf(ofp, "(嵞)崙屔偐偝忋偘,巟墖妟廂擖,擺晅嬥,");
		fprintf(ofp, "巟弌寁,撈帺媼晅,(嵞)撈帺斾椺,(嵞)撈帺掕妟宯,");
		fprintf(ofp, "(嵞)撈帺壛媼,婎慴擭嬥嫆弌嬥,帠柋旓,巟墖妟巟弌,");
		fprintf(ofp, "廂巟嵎,擭搙枛愊棫嬥,愊棫嬥(尰嵼壙奿),");
		fprintf(ofp, "(嵞)僷乕僩曐尟椏,憤曬廣憤妟,憤曬廣妟,堢帣曬廣妟,愊棫搙崌,曐尟椏棪,晩壽曐尟椏棪,,");
		fprintf(ofp, "嵢愊傒暘攝摍,\n");
		
		
		/** 僼傽僀儖偺弌椡 **/
		for(k=FLKS_SHU; k<=FLKE_SHU; k++){
			
			/** 廂巟寁嶼屻偺彅曄悢偺愝掕 **/
			/* 愊棫嬥尰嵼壙奿 */
			if(k>=ECSTY && k<=ECEDY){
				Cc[ii][21][k-STTY] = Cc[ii][20][k-STTY] / Id_Hhd[k-ECSTY];
			} else {
				Cc[ii][21][k-STTY] = 0.;
			}
			/* 愊棫搙崌 */
			if(Cc[ii][11][k-STTY]>0.){
				Cc[ii][26][k-STTY] = Cc[ii][20][k-1-STTY] / Cc[ii][11][k-STTY];
			} else {
				Cc[ii][26][k-STTY] = 0.;
			}
			/* 曐尟椏棪丒晩壽曐尟椏棪 */
			if(ii==0) psd=1;
			else      psd=ii2psd(ii);
			
			if(k>=ECSTY && k<=ECEDY){
					Cc[ii][27][k-STTY] = Prema[psd][k-STTY];
			}
			
			if(Cc[ii][23][k-STTY]>0.){
				Cc[ii][28][k-STTY] = ( Cc[ii][11][k-STTY] - Cc[ii][2][k-STTY] - Cc[ii][4][k-STTY]
				                      -Cc[ii][9][k-STTY] - Cc[ii][10][k-STTY])
			        	            / Cc[ii][24][k-STTY];
			} else {
				Cc[ii][28][k-STTY] = 0.;
			}
			
			/* 弌椡 */
			fprintf(ofp, "%3d,", k);
			for(i=0; i<31; i++){
				if(ii==1 || k!=Kyoskijun-1 || i!=30){
					fprintf(ofp, "%20.13e,", Cc[ii][i][k-STTY] * tanni[i]);
				} else {
					fprintf(ofp, "%20.13e,", Siwake[ii] * tanni[i]);
				}
			}
			if(ii==0 && k==Kyoskijun){
				for(i=1; i<=17; i++){
					if((i>=2&&i<=4) || (i>=9&&i<=12)) continue;
					dtemp=0.;
					for(psd=2; psd<=4; psd++){
						dtemp += Dc[psd][i];
					}
					fprintf(ofp, "%20.13e,", dtemp/1.0E+8);
				}
			}
			fprintf(ofp, "\n");
		}
	}
	
	/*************************************************************************/
	/***                        巇暘偗忣曬偺弌椡                           ***/
	/*************************************************************************/
	ofp = ofp_siwake;
	
	if(mode==0){
		fprintf(ofp,"%s-%s-%s-%s-%s, [%s%s%s], 嵢%s,Part=%d, Dmakuro=%d, Jimu=1\n",
		  Nfile, Nkfile, Wcfile, Ecfile, Cutrfile4, Cutrfile1, Cutrfile2, Cutrfile3,
		  Tumafile,Flg_Part, Flg_Dmakuro);
		
		fprintf(ofp, "\n嵢愊傒巇暘偗忣曬亂僗儔僀僪挷惍慜亃\n\n");
	} else {
		fprintf(ofp, "\n嵢愊傒巇暘偗忣曬亂僗儔僀僪挷惍屻亃\n\n");
	}
	
	dtemp = Cc[1][20][Kyoskijun-1-STTY] + Jyutaku[Kyoskijun-1-STTY];
	
	fprintf(ofp, "堦尦壔巤峴擔: ,暯惉%d(%d)擭10寧1寧\n", Kyoskijun+12, Kyoskijun+2000);
	fprintf(ofp, "媽岤擭愊棫嬥(壄墌): ,%20.13e ,偆偪廧戭梈帒, %20.13e,(暯惉%d擭搙枛),\n",
	             dtemp/1.0E+8, Jyutaku[Kyoskijun-1-STTY]/1.0E+8, Kyoskijun-1+12);
	fprintf(ofp, "媽岤擭幚幙巟弌(壄墌):, %20.13e,(暯惉%d擭搙)\n", Jisout[1]/1.0E+8, Kyoskijun+12);
	if(Jisout[1]>0.){
		fprintf(ofp, "暯惉%d擭搙, 媽岤擭愊棫斾棪:, %20.13e\n\n",
		             Kyoskijun+12, (Cc[1][20][Kyoskijun-1-STTY]+Jyutaku[Kyoskijun-1-STTY])/Jisout[1]);
		
		fprintf(ofp, "惂搙, 巇暘偗妟乮壄墌乯,摉擭壖憐幚幙巟弌乮壄墌乯,愊棫斾棪乮壖憐乯,,");
		fprintf(ofp, "摉擭崙屔乮婎慴嫆弌嬥乯,摉擭崙屔乮宱夁斾乯,摉擭崙屔乮宱夁掕乯,摉擭崙屔乮悡忋偘乯,");
		fprintf(ofp, "摉擭撈帺乮斾椺乯,摉擭撈帺乮掕妟乯,摉擭撈帺乮壛媼乯,摉擭撈帺乮婎慴嫆弌嬥乯,摉擭帠柋,,");
		fprintf(ofp, "慜壖崙屔乮婎慴嫆弌嬥乯,慜壖崙屔乮宱夁斾乯,慜壖崙屔乮宱夁掕乯,慜壖崙屔乮悡忋偘乯,");
		fprintf(ofp, "慜壖撈帺乮斾椺乯,慜壖撈帺乮掕妟乯,慜壖撈帺乮壛媼乯,慜壖撈帺乮婎慴嫆弌嬥乯,慜壖帠柋\n");
		
		fprintf(ofp, "(嶲)媽岤擭,");
		fprintf(ofp, "%20.13e, %20.13e, %20.13e,,",
		             dtemp/1.0E+8, Jisout[1]/1.0E+8, dtemp/Jisout[1]);
		for(i=5;  i<=8;  i++) fprintf(ofp, "%20.13e,", Dc[1][i]/1.0E+8);
		for(i=13; i<=17; i++) fprintf(ofp, "%20.13e,", Dc[1][i]/1.0E+8);
		fprintf(ofp, ",");
		for(i=5;  i<=8;  i++) fprintf(ofp, "%20.13e,", (Cc[1][i][Kyoskijun-STTY]-Dc[1][i])/1.0E+8);
		for(i=13; i<=17; i++) fprintf(ofp, "%20.13e,", (Cc[1][i][Kyoskijun-STTY]-Dc[1][i])/1.0E+8);
		fprintf(ofp, "\n");
		
		for(ii=2; ii<=4; ii++){
			if(ii==2) fprintf(ofp, "崙嫟嵪,");
			if(ii==3) fprintf(ofp, "抧嫟嵪,");
			if(ii==4) fprintf(ofp, "巹妛嫟嵪,");
			
			if(Jisout[ii]>0.){
				fprintf(ofp, "%20.13e, %20.13e, %20.13e,,",
				             Siwake[ii]/1.0E+8, Jisout[ii]/1.0E+8, Siwake[ii]/Jisout[ii]);
			} else {
				fprintf(ofp, "%20.13e, %20.13e,-,,",
				             Siwake[ii]/1.0E+8, Jisout[ii]/1.0E+8);
			}
			for(i=5; i<=8 ; i++)   fprintf(ofp, "%20.13e,", Dc[ii][i]/1.0E+8);
			for(i=13; i<=17 ; i++) fprintf(ofp, "%20.13e,", Dc[ii][i]/1.0E+8);
			fprintf(ofp, ",");
			for(i=5; i<=8 ; i++)   fprintf(ofp, "%20.13e,", (Cc[ii][i][Kyoskijun-STTY]-Dc[ii][i])/1.0E+8);
			for(i=13; i<=17 ; i++) fprintf(ofp, "%20.13e,", (Cc[ii][i][Kyoskijun-STTY]-Dc[ii][i])/1.0E+8);
			
			fprintf(ofp, "\n");
		}
	} else {
		fprintf(ofp, "巇暘偗擭搙偺媽岤擭偺幚幙巟弌偑儅僀僫僗側偨傔丄愊棫嬥巇暘偗偑偱偒傑偣傫偱偟偨丅\n");
		exit(1);
	}
	fprintf(ofp, "\n");
}



void shus_cutout(void){
	
	int k, i;
	FILE *ofp;
	
	/* 婎慴掕妟偺僇僢僩棪 */
	ofp = ofp_cuta;
	
	for(k=5; k<=8; k++){
		fprintf(ofp, "%4d,", k);
		for(i=63; i<=115; i++) fprintf(ofp, "%20.14e,", 1.);
		fprintf(ofp, "\n");
	}
	for(k=9; k<=FLKE; k++){
		fprintf(ofp, "%4d,", k);
		for(i=63; i<=115; i++) fprintf(ofp, "%20.14e,", Escutrrt[k-ECSTY][i-ECXA]);
		fprintf(ofp, "\n");
	}
	
	/* 斾椺偺僇僢僩棪 */
	ofp = ofp_cutb;
	
	for(k=5; k<=8; k++){
		fprintf(ofp, "%4d,", k);
		for(i=63; i<=115; i++) fprintf(ofp, "%20.14e,", 1.);
		fprintf(ofp, "\n");
	}
	for(k=9; k<=FLKE; k++){
		fprintf(ofp, "%4d,", k);
		for(i=63; i<=115; i++) fprintf(ofp, "%20.14e,", Escutrrh[k-ECSTY][i-ECXA]);
		fprintf(ofp, "\n");
	}
}



void shus_summary(void){
	FILE *ofp;
	int k, ii, i;
	int kend_t, kend_h;
	double r1, r1h, r1k, r2, r2h ,r2k;
	double dtemp;
	
	ofp=ofp03_summary;
	
	/** 帋嶼斣崋摍偺彂偒崬傒 **/
	fprintf(ofp, "%s, %s, %s\n", Nfile, Nfile2, Nfile3);
	fprintf(ofp, "%s, %s\n", Ecfile, Wcfile);
	fprintf(ofp, "%s\n", Nkfile);
	fprintf(ofp, "%s, 梊旛:, %s, Cntlset:, %d, Seidn:, %d\n",
	                          Sifile, Cutrfile4, Cntlset, Seidn);
	fprintf(ofp, "\n");
	fprintf(ofp, "Flg_Part,%d,, Flg_Dmakuro,%d\n\n", Flg_Part, Flg_Dmakuro);
	
	/* 岤擭偺嵟廔擭搙 */
	kend_h = 0;
	dtemp = Escutrrh[Ke-1-ECSTY][67-ECXA];
	for(k=Ke-1; k>=Ks+1; k--){
		if(Escutrrh[k-1-ECSTY][67-ECXA]-dtemp>1.0E-13){
			kend_h = k;
			break;
		} else {
			dtemp = Escutrrh[k-1-ECSTY][67-ECXA];
		}
	}
	/* 崙擭偺嵟廔擭搙 */
	kend_t = 0;
	dtemp = Escutrrt[Ke-1-ECSTY][67-ECXA];
	for(k=Ke-1; k>=Ks+1; k--){
		if(Escutrrt[k-1-ECSTY][67-ECXA]-dtemp>1.0E-13){
			kend_t = k;
			break;
		} else {
			dtemp = Escutrrt[k-1-ECSTY][67-ECXA];
		}
	}
	fprintf(ofp, "廔椆擭搙丗,岤擭,%d,%20.14e,崙擭,%d, %20.14e\n\n",
	         kend_h, 1.0-Escutrrh[Ke-ECSTY][67-ECXA], kend_t, 1.0-Escutrrt[Ke-ECSTY][67-ECXA]);
	
	/** 宱嵪慜採 **/
	fprintf(ofp, "宱嵪慜採摍\n");
	fprintf(ofp, "擭搙,暔壙,捓嬥,塣梡棙夞傝,斾椺夵掕棪,斾椺婛嵸68嵨,婎慴夵掕棪,婎慴婛嵸68嵨,");
	fprintf(ofp, "擭嬥妟,偆偪斾椺,偆偪婎慴,壜張暘強摼,");
	fprintf(ofp, "戙懼棪(堦尦壔),偆偪斾椺,偆偪婎慴,戙懼棪(廬棃),");
	fprintf(ofp, "斾椺僇僢僩67,斾椺僇僢僩68,婎慴僇僢僩67,婎慴僇僢僩68,m僼傽僀儖,");
	fprintf(ofp, "幚幙擭嬥妟,幚幙斾椺,幚幙婎慴,幚幙壜張暘\n");
	
	r1 = r1h = r1k = r2 = r2h = r2k =0.;
	for(k=5; k<=Ke; k++){
		fprintf(ofp, "%3d, %5.2f, %5.2f, %5.2f, ", k, Ci[k-ECSTY]*100.0, H[k-ECSTY]*100.0, Ri[k-ECSTY]*100.0);
		fprintf(ofp, "%20.14e, %20.14e, %20.14e, %20.14e, ",
		    (Krb[k-ECSTY][67-ECXA]-1.0)*100.0,(Krb[k-ECSTY][68-ECXA]-1.0)*100.0,
		    (Kra[k-ECSTY][67-ECXA]-1.0)*100.0,(Kra[k-ECSTY][68-ECXA]-1.0)*100.0);
		if(k>=14){
			r1h = Mhirei[k-STTY][0]*Escutrrh[k-ECSTY][67-ECXA];
			r1k = Mkiso[k-STTY]    *Escutrrt[k-ECSTY][67-ECXA];
			r2h = Mhirei[k-STTY][1]*Escutrrh[k-ECSTY][67-ECXA];
			r2k = Mkiso[k-STTY]    *Escutrrt[k-ECSTY][67-ECXA];
		}
		if(k==14){
			r1h = nround(r1h, 0);
			r2h = nround(r2h, 0);
		}
		r1 = r1h + r1k;
		r2 = r2h + r2k;
		if(k>=14){
			fprintf(ofp, "%20.14e, %20.14e, %20.14e, %20.14e, ", r1, r1h, r1k, Kw[k-STTY][0]);
			fprintf(ofp, "%20.14e, %20.14e, %20.14e, %20.14e, ",
			  r1/Kw[k-STTY][0]*100., r1h/Kw[k-STTY][0]*100., r1k/Kw[k-STTY][0]*100., r2/Kw[k-STTY][1]*100.);
		}else {
			fprintf(ofp, "%20.14e, %20.14e, %20.14e, %20.14e, ", 0., 0., 0., 0.);
			fprintf(ofp, "%20.14e, %20.14e, %20.14e, %20.14e, ", 0., 0., 0., 0.);
		}
		fprintf(ofp, "%20.14e, %20.14e, %20.14e, %20.14e, %20.14e,",
		    Escutrrh[k-ECSTY][67-ECXA], Escutrrh[k-ECSTY][68-ECXA],
		    Escutrrt[k-ECSTY][67-ECXA], Escutrrt[k-ECSTY][68-ECXA],
		    Scutrk1[k-ECSTY]);
		if(k>=14){
			fprintf(ofp, "%20.14e, %20.14e, %20.14e, %20.14e,\n",
			  r1/Id_Cid[k-ECSTY], r1h/Id_Cid[k-ECSTY], r1k/Id_Cid[k-ECSTY], Kw[k-STTY][0]/Id_Cid[k-ECSTY]);
		} else {
			fprintf(ofp, "%20.14e, %20.14e, %20.14e, %20.14e,\n", 0., 0., 0., 0.);
		}
	}
	fprintf(ofp, "\n");
	
	/* 恖悢 */
	fprintf(ofp, "\n,慡岤擭,,,,,媽岤擭,,,,,崙嫟,,,,,抧嫟,,,,,巹妛,,,,,\n");
	fprintf(ofp, "擭搙,");
	for(ii=0; ii<=4; ii++) fprintf(ofp, "旐曐尟幰,榁楊憡摉,捠榁憡摉,忈奞,堚懓,");
	fprintf(ofp, "\n");
	for(k=FLKS; k<=FLKE; k++){
		fprintf(ofp, "%3d,", k);
		Ap[0][0][k-STTY] = Ap[1][0][k-STTY];
		for(ii=2; ii<=4; ii++) Ap[0][0][k-STTY] += Ap[ii][0][k-STTY]; 
		for(ii=0; ii<=4; ii++){
			fprintf(ofp, "%20.14e, %20.14e, %20.14e, %20.14e, %20.14e,", Ap[ii][0][k-STTY],
			  Ukyu[0][ii][0][k-STTY],Ukyu[0][ii][1][k-STTY],
			  Ukyu[0][ii][2][k-STTY],Ukyu[0][ii][3][k-STTY]);
		}
		fprintf(ofp, "\n");
	}
	fprintf(ofp, "\n");
	
	/* 巇暘偗僒儅儕 */
	Siwake[1] = Cc[1][20][Kyoskijun-1-STTY] + Jyutaku[Kyoskijun-1-STTY];
	Siwake[0] = 0.;
	for(ii=2; ii<=4; ii++) Siwake[0] += Siwake[ii];
	fprintf(ofp, "巇暘偗僒儅儕\n");
	fprintf(ofp, "媽岤慜擭搙枛愊棫嬥,%20.14e,偆偪廧戭梈帒暘,%20.14e,幚幙巟弌,%20.14e,愊棫斾棪,%20.14e\n",
	              Siwake[1]/1.0E+8, Jyutaku[Kyoskijun-1-STTY]/1.0E+8, Jisout[1]/1.0E+8, Siwake[1]/Jisout[1]);
	fprintf(ofp, "嫟嵪巇暘偗寁,%20.14e,偆偪崙嫟嵪, %20.14e,偆偪抧嫟嵪, %20.14e,偆偪巹妛嫟嵪, %20.14e\n\n",
	              Siwake[0]/1.0E+8, Siwake[2]/1.0E+8, Siwake[3]/1.0E+8, Siwake[4]/1.0E+8);
	
	
	/* 廂巟慡岤擭侾 */
	fprintf(ofp, "廂巟[慡岤擭侾:tou]\n\n");
	fprintf(ofp, "擭搙,");
	fprintf(ofp, "廂擖寁, 曐尟椏, 塣梡廂擖, 崙屔晧扴, 偆偪婎慴, 偆偪宱夁揑崙屔, 巟墖擖, 擺晅嬥,");
	fprintf(ofp, "巟弌寁,撈帺媼晅,婎慴擭嬥嫆弌嬥,暉巸,巟墖弌,廂巟嵎,");
	fprintf(ofp, "愊棫嬥, 尰嵼壙抣, 憤曬廣, 憤曬廣(堢帣摍彍偔), 曐尟椏棪,嵢愊傒,廧戭梈帒乮暿宖乯,,");
	fprintf(ofp, "榁楊憡摉,捠榁憡摉,忈奞,堚懓\n");
	for(k=FLKS; k<=FLKE; k++){
		fprintf(ofp, "%3d,", k);
		for(i=0; i<=30; i++){
			if(i==2 || i==7 || i==8 || (i>=13 && i<=15) || i==22 || (i>=25 && i!=27 && i!=30)){
				continue;
			}
			if(i==6){
				dtemp = Cc[0][6][k-STTY] + Cc[0][7][k-STTY] + Cc[0][8][k-STTY];
			} else {
				dtemp = Cc[0][i][k-STTY];
			}
			if(i!=27) dtemp /= 1.0E+8;
			else      dtemp *= 100.;
			fprintf(ofp, "%20.14e,", dtemp);
		}
		fprintf(ofp, "%20.14e,,", Jyutaku[k-STTY]/1.0E+8);
		for(i=0; i<=3; i++){
			fprintf(ofp, "%20.14e,", 0.);
		}
		fprintf(ofp, "\n");
	}
	fprintf(ofp, "\n\n");
	
	/* 廂巟慡岤擭俀,屄暿惂搙 */
	for(k=FLKS; k<=Kyoskijun; k++){
		for(i=0; i<=30; i++){
			if(k!=Kyoskijun || (i!=20 && i!=21)){
				Cc[0][i][k-STTY] = 0.;
			}
			if(k==Kyoskijun) Dc[0][i]  =0.;
			if(i!=0 && i!=3 && i!=19 && i!=20 && i!=21 && (i<=25 || i==30)){
				for(ii=1; ii<=4; ii++){
					Cc[0][i][k-STTY] += Cc[ii][i][k-STTY];
					if(k==Kyoskijun) Dc[0][i] += Dc[ii][i];
				}
			}
		}
	}
	Jisout[0] = 0.;
	for(ii=2; ii<=4; ii++) Jisout[0] += Jisout[ii];
	
	for(ii=0; ii<=4; ii++){
		fprintf(ofp, "\n");
		if(ii==0) fprintf(ofp, "廂巟[慡岤擭俀:廂巟梡]\n\n");
		if(ii==1) fprintf(ofp, "廂巟[媽岤擭]\n\n");
		if(ii==2) fprintf(ofp, "廂巟[崙嫟嵪]\n\n");
		if(ii==3) fprintf(ofp, "廂巟[抧嫟嵪]\n\n");
		if(ii==4) fprintf(ofp, "廂巟[巹妛嫟嵪]\n\n");
		if(ii!=1){
			fprintf(ofp, "嫟嵪巇暘妟,%20.14e,嫟嵪幚巟弌,%20.14e\n\n", Siwake[ii]/1.0E+8, Jisout[ii]/1.0E+8);
		} else {
			fprintf(ofp, "媽岤愊棫嬥,%20.14e,媽岤幚巟弌,%20.14e\n\n", Siwake[ii]/1.0E+8, Jisout[ii]/1.0E+8);
		}
		fprintf(ofp, "擭搙,");
		fprintf(ofp, "廂擖寁, 曐尟椏, 塣梡廂擖, 崙屔晧扴, 偆偪婎慴, 偆偪宱夁揑崙屔, 巟墖擖, 擺晅嬥,");
		fprintf(ofp, "巟弌寁,撈帺媼晅,婎慴擭嬥嫆弌嬥,暉巸,巟墖弌,廂巟嵎,");
		fprintf(ofp, "愊棫嬥, 尰嵼壙抣, 憤曬廣, 憤曬廣(堢帣摍彍偔), 曐尟椏棪,嵢愊傒,廧戭梈帒乮暿宖乯,,");
		fprintf(ofp, "榁楊憡摉,捠榁憡摉,忈奞,堚懓\n");
		/* 摑崌擭搙(屻敿) */
		fprintf(ofp, "(嵞)15屻敿,");
		for(i=0; i<=30; i++){
			if(i==2 || i==7 || i==8 || (i>=13 && i<=15) || i==22 || (i>=25 && i!=27 && i!=30)){
				continue;
			}
			if(i==6){
				dtemp = Dc[ii][6] + Dc[ii][7] + Dc[ii][8];
			} else {
				dtemp = Dc[ii][i];
			}
			if(i!=27) dtemp /= 1.0E+8;
			else      dtemp *= 100.;
			fprintf(ofp, "%20.14e,", dtemp);
		}
		fprintf(ofp, "\n\n");
		for(k=FLKS; k<=FLKE; k++){
			fprintf(ofp, "%3d,", k);
			for(i=0; i<=30; i++){
				if(i==2 || i==7 || i==8 || (i>=13 && i<=15) || i==22 || (i>=25 && i!=27 && i!=30)){
					continue;
				}
				if(i==6){
					dtemp = Cc[ii][6][k-STTY] + Cc[ii][7][k-STTY] + Cc[ii][8][k-STTY];
				} else {
					dtemp = Cc[ii][i][k-STTY];
				}
				if(i!=27) dtemp /= 1.0E+8;
				else      dtemp *= 100.;
				fprintf(ofp, "%20.14e,", dtemp);
			}
			if(ii<=1){
				fprintf(ofp, "%20.14e,,", Jyutaku[k-STTY]/1.0E+8);
			} else {
				fprintf(ofp, "%20.14e,,", 0.);
			}
			for(i=0; i<=3; i++){
				fprintf(ofp, "%20.14e,", Ukyu[1][ii][i][k-STTY]);
			}
			fprintf(ofp, "\n");
		}
		fprintf(ofp, "\n\n");
	}
}


