function [gcm_temp_out,gcm_f_temp_out]=bias_correction_100percentiles...
  	(obsdata_temp,gcm_temp,gcm_f_temp,bc_mult_or_add,var,DRY_DAY_THRES,...
		calendarDays,BC_MAX_PR_RATIO);

        %temp for troubleshooting
        %obsdata_temp=obsdata(dayWindow,:);
	%gcm_temp=gcmdata(dayWindow,HISTORICAL_YEAR_INDICES);
        %gcm_f_temp=gcmdata(dayWindow,FUTURE_YEAR_INDICES);
	%DRY_DAY_THRES = DRY_DAY_THRES_FINE;
%======================================================================          
        %Preset output array
        temp_out = NaN(size(gcm_temp));
        temp_out_f = NaN(size(gcm_f_temp));
   	%==============================================
        % Strip out NaN data
        %==============================================
 	index_nnan_obs=find(~isnan(obsdata_temp));
        obs =double(obsdata_temp(index_nnan_obs));
        index_nnan_out=find(~isnan(gcm_temp));
        gcm=double(gcm_temp(index_nnan_out));
        index_nnan_out_f=find(~isnan(gcm_f_temp));
        gcm_f=double(gcm_f_temp(index_nnan_out_f));
   	%=========beginning 100 percentile method=====================================
bcMethodName='hundredscalingsBC2';
if(isempty(gcm_f)||isempty(gcm))
else
	 obs_h = obs;
	 f=find(obs_h<DRY_DAY_THRES);obs_h(f)=0.0;

	%these will be filled
	 bc_hist = gcm; 
	 bc_fut = gcm_f; 

	%these will be used to determine percentiles
	 gcm_hist = gcm;
	 gcm_fut = gcm_f;

	%find lowest quantile that's nonzero
	if(var==5);
		pindex_minObs=min(find(prctile(obs_h(:),1:100)>0));
		pmin_zero = prctile(gcm_hist(:),pindex_minObs);
                %if(pmin_zero==0); %everything below the pindex_minObs set to 0
		%	fhist = find(gcm_hist(:)<=DRY_DAY_THRES);bc_hist(fhist)=0.0;
		%	ffut = find(gcm_fut(:)<=DRY_DAY_THRES);bc_fut(ffut)=0.0;
		%else;
			fhist = find(gcm_hist(:)<=pmin_zero);bc_hist(fhist)=0.0;
			ffut = find(gcm_fut(:)<=pmin_zero);bc_fut(ffut)=0.0;
		%end;
	else;
		pindex_minObs=1;
	end;

	for i = pindex_minObs:100; %100 quantiles

		obs_imin=prctile(obs_h(:),i-1);
		obs_imax=prctile(obs_h(:),i);
		gcm_imin=prctile(gcm_hist(:),i-1);
		gcm_imax=prctile(gcm_hist(:),i);

		if(strcmp(bcMethodName,'hundredscalingsBC2'));
			%this is the part that makes it 100scalingsBC2
			%something to think about if this should be percentiles of gcm_fut... or of gcm_hist ? 9/13/17 GM.
			gcmf_imin=prctile(gcm_fut(:),i-1);
			gcmf_imax=prctile(gcm_fut(:),i);
		end;

		if(i==pindex_minObs); %first non-zero quantile for the obs
		    fobs=find(obs_h(:)<=obs_imax);
		    fhist= find(gcm_hist(:)<=gcm_imax);
		    if(strcmp(bcMethodName,'hundredscalingsBC2'));
			    ffut = find(gcm_fut(:)<=gcmf_imax);
		    else;
			    ffut = find(gcm_fut(:)<=gcm_imax); %BC1
		    end;
		elseif(i==100);
		    fobs = find(obs_h(:)>obs_imin);
		    fhist= find(gcm_hist(:)>gcm_imin);
		    if(strcmp(bcMethodName,'hundredscalingsBC2'));
			 ffut = find(gcm_fut(:)>gcmf_imin);
		    else;
			ffut = find(gcm_fut(:)>gcm_imin); %BC1
		    end;
		else;
		    fobs = find(obs_h(:)>obs_imin & obs_h(:)<=obs_imax);
		    fhist= find(gcm_hist(:)>gcm_imin & gcm_hist(:)<=gcm_imax);
		    if(strcmp(bcMethodName,'hundredscalingsBC2'));
			ffut = find(gcm_fut(:)>gcmf_imin & gcm_fut(:)<=gcmf_imax);
		    else;
			ffut = find(gcm_fut(:)>gcm_imin & gcm_fut(:)<=gcm_imax); %BC1
		    end;
		end;

		if(obs_imin==obs_imax);
			obs_avg=obs_imin;
		else;
			obs_avg=nanmean(obs_h(fobs));
		end;
		if(gcm_imin==gcm_imax);
			gcm_avg=gcm_imin;
		else;
			gcm_avg=nanmean(gcm_hist(fhist));
		end;
		if(var==5);
			if(gcm_avg==0 & obs_avg <=DRY_DAY_THRES);
				ratio_avg(i) = 1;
			elseif(gcm_avg==0);
				ratio_avg(i)=obs_avg/DRY_DAY_THRES; %always >=1.0
			else;
				ratio_avg(i)=obs_avg/gcm_avg;
			end;
			if(ratio_avg(i)>BC_MAX_PR_RATIO);
				%[i,ratio_avg(i)]
				ratio_avg(i) = BC_MAX_PR_RATIO;
			end;
			%if(ratio_avg(i)>2);
				%[i,ratio_avg(i)]
			%end;

			%adjust with ratio
			bc_hist(fhist) = bc_hist(fhist)* ratio_avg(i);
			bc_fut(ffut) = bc_fut(ffut)* ratio_avg(i);
		else;
			ratio_avg(i)=obs_avg-gcm_avg;
			bc_hist(fhist) = bc_hist(fhist)+ ratio_avg(i);
			bc_fut(ffut) = bc_fut(ffut)+ ratio_avg(i);
		end;
	end;
	gcm_obs = bc_hist;
	gcm_f_t = bc_fut;
        if(var==5);
                f=find(gcm_obs<DRY_DAY_THRES);gcm_obs(f) =0.0;
                f=find(gcm_f_t<DRY_DAY_THRES);gcm_f_t(f) =0.0;
        end;

%%%==============end 100 percentile method=========================================

 	%last check on data
        f=find(isnan(gcm_obs));
        f2=find(isinf(gcm_obs));
        if(~isempty(f))
                fprintf('Bad news; GCM_OBS has %d NaNs in it',length(f))
        end
        if(~isempty(f2))
                fprintf('Bad news; GCM_OBS has %d INFs in it',length(f))
        end
        f=find(isnan(gcm_f_t));
        f2=find(isinf(gcm_f_t));
        if(~isempty(f))
                fprintf('Bad news; GCM_F_T has %d NaNs in it',length(f))
		fprintf('ratio_avg: %f',ratio_avg);
		fprintf('obs_avg: %f',obs_avg);
		fprintf('gcm_avg: %f',gcm_avg);
		gcm_f(f)
		pindex_minObs
                pmin_zero
		pmin_zero==0
        end
        if(~isempty(f2))
                fprintf('Bad news; GCM_F_T has %d INFs in it',length(f))
        end


%max(factor_fut(:))
%%%=======================================================
%             SET OUTPUT 
%%%=======================================================
        temp_out(index_nnan_out)                = gcm_obs;
        temp_out_f(index_nnan_out_f)            = gcm_f_t;
end;
%%%=======================================================
%             TRUNCATE FOR OUTPUT 
%%%=======================================================
        s=length(calendarDays);
        gcm_temp_out         =temp_out(1:s,:);
        gcm_f_temp_out       =temp_out_f(1:s,:);
%%%=======================================================
end
