function result_status = monitored_fields_data(JSONString)

pkg load image
JSONSentinel = JSONString
%B4URL = JSONSentinel.Band4URI
try
TileCloudCover = str2double(JSONSentinel.cloud_cover)
catch
TileCloudCover = 0.0;
end
FieldArea = JSONSentinel.FieldArea
StartPixelLat = JSONSentinel.StartPixelLat
EndPixelLat = JSONSentinel.EndPixelLat
StartPixelLong = JSONSentinel.StartPixelLong
EndPixelLong = JSONSentinel.EndPixelLong
FieldArea = JSONSentinel.FieldArea
FieldID = JSONSentinel.FieldID
PlantDistance = JSONSentinel.PlantDistance
if EndPixelLong > 10980
	EndPixelLong = 10979;
end
UID = JSONSentinel.UID

PreviousDay = str2num(JSONSentinel.PreviousDay)
ImageDate = str2num(JSONSentinel.LatestDay)
MGRS = JSONSentinel.MGRS
B4FileName = 'Tile_B4.jp2';

B8FileName = 'Tile_B8.jp2';
TCIFileName = 'Tile_TCI.jp2';

B12FileName = 'Tile_B12.jp2';
B11FileName = 'Tile_B11.jp2';
B5FileName = 'TIle_B5.jp2';

B2FileName = 'Tile_B2.jp2';

B3FileName = 'Tile_B3.jp2';

ImageDate = JSONSentinel.LatestDay

newDate = strcat(ImageDate(1:4),'-')
newDate = strcat(newDate,ImageDate(5:6))
newDate = strcat(newDate,'-')
newDate= strcat(newDate,ImageDate(7:8))
filepath = strcat('AwsData/',MGRS);
filepath = strcat(filepath,',');
filepath = strcat(filepath,newDate);
filepath = strcat(filepath,',0/');
ImageDate = str2num(JSONSentinel.LatestDay)
B4FileName = strcat(filepath,'B04.jp2');

B8FileName = strcat(filepath,'B08.jp2');

TCIFileName = strcat(filepath,'TCI.jp2');

B12FileName = strcat(filepath,'B12.jp2');

B11FileName = strcat(filepath,'B11.jp2');

B5FileName = strcat(filepath,'B05.jp2');

B2FileName = strcat(filepath,'B02.jp2');

B3FileName = strcat(filepath,'B03.jp2');

sizeB4 = [10980 10980];
format long;

try
	B4 = imread(B4FileName);


	B5 = imread(B5FileName);

	B2 = imread(B2FileName);

	B3 = imread(B3FileName);

	B8 = imread(B8FileName);

	TCI = imread(TCIFileName);
	B12 = imread(B12FileName);
	B11 = imread(B11FileName);
catch
	try
		ImageDate = JSONSentinel.LatestDay

newDate = strcat(ImageDate(1:4),'-')
newDate = strcat(newDate,ImageDate(5:6))
newDate = strcat(newDate,'-')
newDate= strcat(newDate,ImageDate(7:8))
filepath = strcat('AwsData/',MGRS);
filepath = strcat(filepath,',');
filepath = strcat(filepath,newDate);
filepath = strcat(filepath,',1/');
ImageDate = str2num(JSONSentinel.LatestDay)
B4FileName = strcat(filepath,'B04.jp2');

B8FileName = strcat(filepath,'B08.jp2');

TCIFileName = strcat(filepath,'TCI.jp2');

B12FileName = strcat(filepath,'B12.jp2');

B5FileName = strcat(filepath,'B05.jp2');

B2FileName = strcat(filepath,'B02.jp2');

B3FileName = strcat(filepath,'B03.jp2');
B4 = imread(B4FileName);


        B5 = imread(B5FileName);

        B2 = imread(B2FileName);

        B3 = imread(B3FileName);

        B8 = imread(B8FileName);

        TCI = imread(TCIFileName);
        B12 = imread(B12FileName);
		B11 = imread(B11FileName);
	catch
	result_status = strcat(UID,"failed2")
	return
	end
end


sizeB4 = [10980 10980];
wq = 1
%cmap2 for vari
	
%result_status = strcat(UID,"failed4")
%return
try
	clip = [StartPixelLat EndPixelLat StartPixelLong EndPixelLong];
	clip_tci = clip;
	
	TCI = TCI(clip(1):clip(2),clip(3):clip(4),:);
	
	
	B4 = B4(clip(1):clip(2),clip(3):clip(4));
	B8 = B8(clip(1):clip(2),clip(3):clip(4));

	B2 = B2(clip(1):clip(2),clip(3):clip(4));
	B3 = B3(clip(1):clip(2),clip(3):clip(4));

catch
result_status = strcat(UID,"failed2")
	return
end
%find field coordinates for smaller resolution images
sizeB4 = [5490 5490];
rr = 11
StartPixelLat = round(StartPixelLat/2);
EndPixelLat = round(EndPixelLat/2);
%clip smaller images
%clip = [StartPixelLat EndPixelLat StartPixelLong EndPixelLong];
	clip = round(clip/2);
	%B8A = B8A(clip(1):clip(2),clip(3):clip(4),:);
	B12 = B12(clip(1):clip(2),clip(3):clip(4),:);
	B11 = B11(clip(1):clip(2),clip(3):clip(4),:);
	B5 = B5(clip(1):clip(2),clip(3):clip(4),:);
	rr = 12
	B8NDRE = B8;
	B4F_name = strcat(UID,"_B4.png");
	%imwrite(B4,B4F_name);
	B4BSI = B4;
	B12BSI = B12;	
	B8NDRE = imresize(B8NDRE,[abs(clip(2)-clip(1)+1) abs(clip(4)-clip(3)+1)]);
	B8NDRE = single(B8NDRE);

	B4BSI = imresize(B4BSI,[abs(clip(2)-clip(1)+1) abs(clip(4)-clip(3)+1)]);
        B4BSI = single(B4BSI);

	B12BSI = imresize(B12BSI,[abs(clip(2)-clip(1)+1) abs(clip(4)-clip(3)+1)]);
        B12BSI = single(B12BSI);
	B4 = single(B4);
	B8 = single(B8);
	
	B12 = single(B12);
	B5 = single(B5);
	B2 = single(B2);
	B3 = single(B3);
	B11 = single(B11);

	
	%calculate NDVI, NDRE, NDWI
	NDVI = (B8 - B4)./(B8 + B4);
	minN = min(min(NDVI));
	maxN = max(max(NDVI))
	AVI = (B8.*(4096-B4).*(B8-B4)).^(1/3);
	AVI = AVI/4096;
	%BSI = ((B8+B3+B4)./(B8+B3-B4));
	BSI = (B8 +B3 +B4)./(B8+B3-B4);
	sizeBSI = size(BSI);
	for ii =1:sizeBSI(1)
		for jj=1:sizeBSI(2)
			if BSI(ii,jj) > 2.5
			BSI(ii,jj) = 2.5;
			end
		end
	end
	BSI = BSI/2.5;
%	BSI = 2*(BSI-minBSI)./(maxBSI - minBSI)-1;
	SI = ((4096-B2).*(4096-B3).*(4096-B4)).^(1/3);
	SI = SI/4096;
	
	%BNDVI = mat2gray(NDVI);
	%imwrite(BNDVI,'BNDVI_clipped.png');
	NDRE = (B8NDRE-B5)./(B8NDRE+B5);
	NDWI = (B8NDRE - B12)./(B8NDRE + B12);
	%NDWI = (B3-B8)./(B3+B8);
	NDMI = (B8NDRE - B11)./(B8NDRE + B11);
weas = 'ndmi minmax'
	min(min(NDMI))
	max(max(NDMI))
	NumVARI = B3-B4;
	DenVARI = (B3+B4-B2);
	VARI = NumVARI./DenVARI;
	EVI = (2.5*(B8-B4))./((B8+2.4*B4)+4096);
	sizeVARI = size(VARI);
	sizeNDRE = size(NDRE);
	minNDVI = -1;
	maxNDVI = 1;
	SAVI = (B8-B4)./(B8+B4+0.428*4096)*(1+0.428);
	SAVI = 1.5*(B8-B4)./(B8+B4+0.5);
	LAI = zeros(sizeVARI(1), sizeVARI(2));
	SOC = zeros(sizeVARI(1), sizeVARI(2));
	VSSI = 2*B3 - 5*(B4+B8);
	for ii = 1:sizeVARI(1)
		for jj = 1:sizeVARI(2)
			NDVIij = NDVI(ii,jj);
			Fc = 1- (maxNDVI - NDVIij)/(maxNDVI - minNDVI);
			LAI = -2*log(1 - Fc);
			SOC_pc_ij = 100*(LAI - 0.0411)/0.0087;
			SOCij= SOC_pc_ij*0.004536*100/(350*9*20);
			SOC(ii,jj) = SOCij;
		end
	end
	SOC = single(SOC);
	for ii = 1:sizeNDRE(1)
		for jj = 1:sizeNDRE(2)			
			if NDRE(ii,jj)>=1
				NDRE(ii,jj)=1;
			elseif NDRE(ii,jj)<-1
				NDRE(ii,jj)=-1;
			end
			if NDWI(ii,jj)>=1
				NDWI(ii,jj)=1;
			elseif NDWI(ii,jj)<-1
				NDWI(ii,jj)=-1;
			end
			if NDMI(ii,jj)>=0.8
				NDMI(ii,jj)=0.8;
			elseif NDMI(ii,jj)<-0.8
				NDMI(ii,jj)=-0.8;
			end
		end
	end
	for ii = 1:sizeVARI(1)
		for jj = 1:sizeVARI(2)
			a_mat = max([-1 VARI(ii,jj)]);
			VARI(ii,jj) = min([1 a_mat]);
			
		end
	end
	sB12 = size(B12)
	mainPath = strcat(UID, "/");
mainPath = strcat(mainPath,FieldID);
	filename= strcat(mainPath,"/IndexValues_ndvi.csv")
	csvwrite(filename, NDVI);
	%csvwrite("IndexValues_evi", EVI);
	%csvwrite("IndexValues_ndre", NDRE);
	%csvwrite("IndexValues_vari",VARI);
	%csvwrite("IndexValues_ndwi", NDWI);	
	%check if there is too much cloud
	sN = size(NDVI);	
	
	SizeNewB4 = size(B4);
	IsNaNMat = isnan(NDVI);

TCIFilename2 = strcat(mainPath,"/TCI.png");

imwrite(TCI,TCIFilename2);	%sar image
try
filename = strcat(mainPath,"/evapo.png");
EVAPO = imread(filename);
EVAPO_new = imresize(EVAPO,[sizeVARI(1),sizeVARI(2)]);
imwrite(EVAPO_new,filename);
catch
        akkk = 1;
end

try
filename = strcat(mainPath,"/lulc.png");
LULC = imread(filename);
LULC_new = imresize(LULC,[sizeVARI(1),sizeVARI(2)]);
imwrite(LULC_new,filename);
catch
        akkk = 1;
end


try
filename = strcat(mainPath,"/rvi.png");
RVI = imread(filename);
RVI_new = imresize(RVI,[sizeVARI(1),sizeVARI(2)]);
imwrite(RVI_new,filename);
%csvwrite("IndexValues_rvi.csv", get_rvi_value(UID));
catch
	akkk = 1;
end



try
filename = strcat(mainPath,"/dem.png");
DEM = imread(filename);
DEM_new = imresize(DEM,[sizeVARI(1),sizeVARI(2)]);
imwrite(DEM_new,filename);
catch
	akkk = 1;
end
	IsNaNCount =sum(sum(IsNaNMat))
	if(IsNaNCount > SizeNewB4(1)*SizeNewB4(2)*0.8)
		result_status = strcat(UID,"failed1")
		result_status2 = 'Too much black in image'
		return
	else	

	%create ETCI image
		my_limit=0.5;
low_limit=0.008;
up_limit=0.992;
%----------------------------------------------------------------------
img=TCI;
[m1 n1 r1]=size(img);
%----------------------------------------------------------------------
if r1==3
    my_limit2=0.04;my_limit3=-0.04;
a = img;
try
    a=rgb2ntsc(img);
catch
	img = im2double(img);
	a=rgb2ntsc(img);
end
    mean_adjustment=my_limit2-mean(mean(a(:,:,2)));
    a(:,:,2)=a(:,:,2)+mean_adjustment*(0.596-a(:,:,2));
    mean_adjustment=my_limit3-mean(mean(a(:,:,3)));
    a(:,:,3)=a(:,:,3)+mean_adjustment*(0.523-a(:,:,3));
else
    a=double(img)./255;
end
%----------------------------------------------------------------------
mean_adjustment=my_limit-mean(mean(a(:,:,1)));
a(:,:,1)=a(:,:,1)+mean_adjustment*(1-a(:,:,1));
if r1==3
    a=ntsc2rgb(a);
end
%----------------------------------------------------------------------
img=a.*255;
%--------------------calculation of vmin and vmax----------------------
for k=1:r1
    arr=sort(reshape(img(:,:,k),m1*n1,1));
    v_min(k)=arr(ceil(low_limit*m1*n1));
    v_max(k)=arr(ceil(up_limit*m1*n1));
end
%----------------------------------------------------------------------
if r1==3

trans = [ 0.299,  0.596,  0.211; 0.587, -0.274, -0.523; 0.114, -0.322,  0.312 ];

  v_min = v_min*trans;
	v_max = v_max*trans;
end
%----------------------------------------------------------------------
%if abs(v_max(1)-v_min(1))<1e-3
%	result_status = strcat(UID,"failed1")
%                result_status2 = 'Too much black in image vmin vmax'
%	return
%end
%v_min
img=(img-v_min(1))/(v_max(1)-v_min(1));

startx=25;
endx = 900-25;
starty=181;
endy=1200-188;
TCIFilename = strcat(mainPath,"/ETCI.png");
%save ETCI image
imwrite(uint8(img.*255),TCIFilename);
TCIFilenameL = strcat(mainPath,"/ETCI_large.png");
%save ETCI image
imwrite(uint8(img.*255),TCIFilenameL);
%save TCI image
TCIFilename2 = strcat(mainPath,"/TCI.png");

imwrite(TCI,TCIFilename2);
TCIFilename2L = strcat(mainPath,"/TCI_large.png");
imwrite(TCI,TCIFilename2L);
%create color map NDVI image
filenametci = strcat(mainPath,"/ETCI.png");
tci = imread(filenametci);
try
TCIgray = rgb2gray(tci);
catch
        result_status = strcat(UID,"failed1")
        return
        end
badveg = [247 136 90];
vbadveg = [229 25 26];
badwater = [180 145 200];
vbadwater = [60 19 97];
badcloud = [255 255 255];
bothbad = [145 16 44];
otherregions = [17 167 95];
sizeNDVI = size(NDVI);


BI = B8NDRE./B5 - 1;
BI_expanded = zeros(sizeNDVI(1), sizeNDVI(2));
NDRE_expanded= zeros(sizeNDVI(1), sizeNDVI(2));
NDWI_expanded = zeros(sizeNDVI(1), sizeNDVI(2));
NDMI_expanded = zeros(sizeNDVI(1),sizeNDVI(2));
%NDRE
%NDWI



delta = 0;
if PlantDistance > 1
	if PlantDistance < 3
		delta = 0.1;
	end
end

if PlantDistance > 3
	if PlantDistance < 6
		delta = 0.2;
	end
end

if PlantDistance > 6
	delta = 0.3;
end


for ii = 1:sizeNDRE(1)
	for jj = 1:sizeNDRE(2)
		if 2*ii < sizeNDVI(1) 
			if 2*jj < sizeNDVI(2)
		NDRE_expanded(2*ii-1,2*jj-1) = NDRE(ii,jj);
		NDRE_expanded(2*ii-1,2*jj) = NDRE(ii,jj);
		NDRE_expanded(2*ii,2*jj-1) = NDRE(ii,jj);
		NDRE_expanded(2*ii,2*jj) = NDRE(ii,jj);
		NDWI_expanded(2*ii-1,2*jj-1) = NDWI(ii,jj);
		NDWI_expanded(2*ii-1,2*jj) = NDWI(ii,jj);
		NDWI_expanded(2*ii,2*jj-1) = NDWI(ii,jj);
		NDWI_expanded(2*ii,2*jj) = NDWI(ii,jj);
		BI_expanded(2*ii,2*jj) = BI(ii,jj);
		BI_expanded(2*ii-1,2*jj-1) = BI(ii,jj);
		BI_expanded(2*ii-1,2*jj) = BI(ii,jj);
		BI_expanded(2*ii,2*jj-1) = BI(ii,jj);
		NDMI_expanded(2*ii-1,2*jj-1) = NDMI(ii,jj);
		NDMI_expanded(2*ii-1,2*jj) = NDMI(ii,jj);
		NDMI_expanded(2*ii,2*jj-1) = NDMI(ii,jj);
		NDMI_expanded(2*ii,2*jj) = NDMI(ii,jj);
		NDRE(ii,jj) = NDRE(ii,jj) + delta;
		NDWI(ii,jj) = NDWI(ii,jj) + delta;
		BI(ii,jj) = BI(ii,jj) + delta;
		NDMI(ii,jj) = NDMI(ii,jj) + delta;
		if NDRE(ii,jj) > 0.9
				NDRE(ii,jj) = 0.9;
			end

		if NDWI(ii,jj) > 0.9
				NDWI(ii,jj) = 0.9;
			end

		if BI(ii,jj) > 0.9
				BI(ii,jj) = 0.9;
			end

		if NDMI(ii,jj) > 0.9
				NDMI(ii,jj) = 0.9;
			end
		
		end
		end
	end
end


hybridImage = zeros(sizeVARI(1), sizeVARI(2), 3);
hybridBlindImage = hybridImage;
for ii = 1:sizeVARI(1)
                for jj = 1:sizeVARI(2)
                        NDVIij = NDVI(ii,jj);
                        EVIij = EVI(ii,jj);
			NDREij = NDRE_expanded(ii,jj);
			NDWIij = NDWI_expanded(ii,jj);
			NDVIij = NDVIij + delta;
			EVIij = EVIij + delta;
			NDREij = NDREij + delta;
			NDWIij = NDWIij + delta;
			if NDVIij > 0.9
				NDVIij = NDVIij;
			end
			if EVIij > 0.9
				EVIij = EVIij;
			end
			if NDREij > 0.9
				NDREij = NDREij;
			end
			if NDWIij > 0.9
				NDWIij = NDWIij;
			end
			NDVI(ii,jj) = NDVIij;
			EVI(ii,jj) = EVIij;
			if TCIgray(ii,jj) >170
				CloudFlag = 1;
			else
				CloudFlag = 0;
			end
			hybridImage(ii,jj,:) = otherregions;
			hybridBlindImage(ii,jj,:) = [111,111,111];
			if CloudFlag ==1
				hybridImage(ii,jj,:) = badcloud;
				hybridBlindImage(ii,jj,:) = [0,0,0];
			else
				if NDVIij< 0.45 
					if NDVIij > 0.3
					hybridImage(ii,jj,:) = badveg;
					hybridBlindImage(ii,jj,:) = [0,0,0];
				end
				end
				if NDVIij < 0.3
					hybridImage(ii,jj,:) = vbadveg;
					hybridBlindImage(ii,jj,:) = [0,0,0];
				end
				if NDWIij< 0.4
					if NDVIij > 0.3
                                        hybridImage(ii,jj,:) = badwater;
										hybridBlindImage(ii,jj,:) = [255,255,255];
                                end
				end
                                if NDWIij < 0.3
                                        hybridImage(ii,jj,:) = vbadwater;
										hybridBlindImage(ii,jj,:) = [255,255,255];
                                end
				if NDVIij < 0.45
					if NDWIij < 0.4
					hybridImage(ii,jj,:) = bothbad;
					hybridBlindImage(ii,jj,:) = [0,0,0];
				end
				end
			end
                end
        end


filename = strcat(mainPath,"/hybrid");
filename=strcat(filename,".png");
imwrite(uint8(hybridImage),filename);

filename = strcat(mainPath,"/hybrid_blind");
filename=strcat(filename,".png");
imwrite(uint8(hybridBlindImage),filename);

index_new = NDVI;
imgCMP = gen_map1_img(index_new);
filename = strcat(mainPath,"/ndvi")
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map2_img(index_new);
filename = strcat(mainPath,"/ndvi_cmap2")
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);



index_new = VSSI;
filename= strcat(mainPath,"/IndexValues_vssi.csv")
csvwrite(filename, VSSI);
imgCMP = gen_map1_img(index_new);
filename = strcat(mainPath,"/vssi")
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map2_img(index_new);
filename = strcat(mainPath,"/vssi_cmap2")
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);

index_new = SOC;
filename= strcat(mainPath,"/IndexValues_soc.csv")
csvwrite(filename, SOC);
imgCMP = gen_map1_soc(index_new);
filename = strcat(mainPath,"/soc")
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map2_soc(index_new);
filename = strcat(mainPath,"/soc_cmap2")
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);



%create color map EVI image
filename= strcat(mainPath,"/IndexValues_evi.csv")
csvwrite(filename, EVI);

index_new = EVI;
imgCMP = gen_map1_img(index_new);
filename = strcat(mainPath,"/evi")
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map2_img(index_new);
filename = strcat(mainPath,"/evi_cmap2");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);

filename= strcat(mainPath,"/IndexValues_vari.csv")
       csvwrite(filename,VARI);
index_new = VARI;
imgCMP = gen_map3_img(index_new);
filename = strcat(mainPath,"/vari")
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map4_img(index_new);
filename = strcat(mainPath,"/vari_cmap2");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);


%create colormap NDRE image
%NDRE_new = (1/(max(max(NDRE))))*NDRE;
%csvwrite("IndexValues_evi", EVI);
filename= strcat(mainPath,"/IndexValues_ndre.csv")
        csvwrite(filename, NDRE);
        %csvwrite("IndexValues_vari",VARI);
        %csvwrite("IndexValues_ndwi", NDWI);
		filename= strcat(mainPath,"/IndexValues_avi.csv")
 csvwrite(filename, AVI);
index_new = AVI;
imgCMP = gen_map1_img(index_new);
filename = strcat(mainPath,"/avi")
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map2_img(index_new);
filename = strcat(mainPath,"/avi_cmap2");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);

filename= strcat(mainPath,"/IndexValues_bsi.csv")
 csvwrite(filename, BSI);
index_new = BSI;
imgCMP = gen_map1_img(index_new);
filename = strcat(mainPath,"/bsi");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map2_img(index_new);
filename = strcat(mainPath,"/bsi_cmap2");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);

filename= strcat(mainPath,"/IndexValues_si.csv")
 csvwrite(filename, SI);
index_new = SI;
imgCMP = gen_map1_img(index_new);
filename = strcat(mainPath,"/si");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map2_img(index_new);
filename = strcat(mainPath,"/si_cmap2");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);

filename= strcat(mainPath,"/IndexValues_savi.csv")
 csvwrite(filename,SAVI);
index_new = SAVI;
imgCMP = gen_map1_img(index_new);
imgCMP = resize_index_image(imgCMP, size(NDVI));
filename = strcat(mainPath,"/savi");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map2_img(index_new);
filename = strcat(mainPath,"/savi_cmap2");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);


index_new = NDRE;
imgCMP = gen_map1_img(index_new);
imgCMP = resize_index_image(imgCMP, size(NDVI));
filename = strcat(mainPath,"/ndre");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map2_img(index_new);
imgCMP = resize_index_image(imgCMP, size(NDVI));
filename = strcat(mainPath,"/ndre_cmap2");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);

try
filename= strcat(mainPath,"/IndexValues_ndmi.csv")
	csvwrite(filename, NDMI);
catch
	asdfd = 1;
end

index_new = NDMI;
imgCMP = gen_map1_img(index_new);
imgCMP = resize_index_image(imgCMP, size(NDVI));
filename = strcat(mainPath,"/ndmi");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map2_img(index_new);
imgCMP = resize_index_image(imgCMP, size(NDVI));
filename = strcat(mainPath,"/ndmi_cmap2");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);



NDWI_new = NDWI;
%csvwrite("IndexValues_evi", EVI);
        %csvwrite("IndexValues_ndre", NDRE);
        %csvwrite("IndexValues_vari",VARI);
		filename= strcat(mainPath,"/IndexValues_ndwi.csv")
        csvwrite(filename, NDWI);
index_new = NDWI;
imgCMP = gen_map1_img(index_new);
imgCMP = resize_index_image(imgCMP, size(NDVI));
filename = strcat(mainPath,"/ndwi");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);
imgCMP = gen_map2_img(index_new);
imgCMP = resize_index_image(imgCMP, size(NDVI));
filename = strcat(mainPath,"/ndwi_cmap2");
filename=strcat(filename,".png");
imwrite(uint8(imgCMP),filename);

result_status = strcat(UID,"successful")
end
