/*------------------------------------------------------------------------------ NDVIの各種パラメータを求める [GIMMSバージョン] 0:年最大値 1:積算(0.1以上) ------------------------------------------------------------------------------*/ /* 格納されているデータの値域(要確認) NDVI 0-1 : 0-1000(ただし、負の値もあり) Water -0.1 : -10000 Null -0.05 : (未確認) */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define NUMBER_OF_LINES 2091 #define NUMBER_OF_PIXELS 4950 #define NUMBER_OF_CHANNELS 24 #define NUMBER_OF_PRM 2 signed short ndvi[NUMBER_OF_CHANNELS][NUMBER_OF_PIXELS]; signed short nprm[NUMBER_OF_PRM][NUMBER_OF_PIXELS]; unsigned char buffer[NUMBER_OF_PIXELS*2]; void main(argc,argv) int argc; char *argv[]; { int fi,fo; int i,j,ch; int isw; /* 0:最大値、1:積算 */ signed short max,count; int sum; if(argc!=4){ printf("Extraction of NDVI Parameter - GIMMS version\n"); printf("USAGE: getviprm [input] [output] [switch]\n"); printf("(1) input : GIMM NDVI - annual 24 bi-monthly data. BIL format.\n"); printf("(2) output : 0:max, 1:sum(>0.1)\n"); printf("note) output values are NDVI*1000\n"); exit(-1); } if( (fi=open(argv[1],O_RDONLY | O_BINARY))==-1){ printf("Can't open %s.\n",argv[1]); exit(-1); } if( (fo=open(argv[2],O_RDWR | O_TRUNC | O_CREAT | O_BINARY, S_IREAD | S_IWRITE))==-1){ printf("Can't open %s.\n",argv[2]); exit(-1); } isw=atoi(argv[3]); if(isw<0 || isw>1){ printf("Switch error %d\n",isw); exit(-1); } /* 計算 */ for(i=0;i0.1) */ for(j=0;jmax){ max=ndvi[ch][j]; } if(ndvi[ch][j]>100 ){ /* NDVI 0.1=100 植生域のみ積算 */ sum += ndvi[ch][j]; /* 1000倍の値をそのまま積算 */ count++; } }/* next ch */ /* 最大値格納 isw=0 */ if(isw==0){ nprm[0][j]=max; } /* 積算値格納 isw=1*/ if(isw==1){ nprm[1][j]=sum; } }/* next j */ /* 出力 NDVI*1000 */ write(fo,nprm[isw],NUMBER_OF_PIXELS*sizeof(short)); }/* next line */ printf("\n"); }/* end of main */