% simply to check
clear all
clc
close all
for reg_no=19 %1:19
    reg_no
    for chain=2:81
        chain
        if chain<=17; gcm='ipsl_cm6a-lr';
elseif chain>=18 && chain<=33; gcm='gfdl-esm4';
elseif chain>=34 && chain<=49; gcm='mpi-esm1-2-hr';
elseif chain>=50 && chain<=65; gcm='mri-esm2-0';
elseif chain>=66 && chain<=81; gcm='ukesm1-0-ll'; end

%PERIOD (amd hist ssp)
if chain== 2 || chain== 18 || chain== 34 ||chain==  50 ||chain==  66; period='1851-1870'; ssp='hist';
elseif chain== 3 || chain== 19 || chain== 35 || chain== 51 || chain==  67; period='1901-1920'; ssp='hist';
elseif chain== 4 || chain== 20 || chain== 36 || chain== 52 || chain==  68; period='1951-1970'; ssp='hist';
elseif chain== 5 || chain== 21 || chain== 37 || chain== 53 || chain== 69; period='1995-2014'; ssp='hist';

elseif chain== 6 || chain==10 || chain==14 || chain==22 || chain==26 || chain==30 || chain==38 || chain==42 || chain==46 || chain==54 || chain==58 || chain==62 || chain==70 || chain==74 || chain==78; period='2021-2040';
elseif chain== 7 || chain==11 || chain==15 || chain==23 || chain==27 || chain==31 || chain==39 || chain==43 || chain==47 || chain==55 || chain==59 || chain==63 || chain==71 || chain==75 || chain==79; period='2041-2060';
elseif chain== 8 || chain==12 || chain==16 || chain==24 || chain==28 || chain==32 || chain==40 || chain==44 || chain==48 || chain==56 || chain==60 || chain==64 || chain==72 || chain==76 || chain==80; period='2061-2080';
elseif chain== 9 || chain==13 || chain==17 || chain==25 || chain==29 || chain==33 || chain==41 || chain==45 || chain==49 || chain==57 || chain==61 || chain==65 || chain==73 || chain==77 || chain==81; period='2081-2100'; end

%SSP
if chain== 6 ||  chain==22 || chain==38 || chain==54 || chain==70; ssp='ssp126';
elseif chain== 7 || chain==23 || chain==39 || chain==55 || chain==71; ssp='ssp126';
elseif chain== 8 || chain==24 || chain==40 || chain==56 || chain==72; ssp='ssp126';
elseif chain== 9 || chain==25 || chain==41 || chain==57 || chain==73; ssp='ssp126'; end

if chain== 6+4 ||  chain==22+4  || chain==38+4  || chain==54+4  || chain==70+4 ; ssp='ssp370';
elseif chain== 7+4  || chain==23+4  || chain==39+4  || chain==55+4  || chain==71+4 ; ssp='ssp370';
elseif chain== 8+4  || chain==24+4  || chain==40+4  ||chain== 56+4  || chain==72+4 ; ssp='ssp370';
elseif chain== 9+4  || chain==25+4  || chain==41+4  || chain==57+4  || chain==73+4 ; ssp='ssp370'; end

if chain== 6+8 ||  chain==22+8  || chain==38+8  ||chain== 54+8  || chain==70+8 ; ssp='ssp585';
elseif chain== 7+8  || chain==23+8  || chain==39+8  || chain==55+8  || chain==71+8 ; ssp='ssp585';
elseif chain== 8+8  || chain==24+8  || chain==40+8  || chain==56+8  || chain==72+8 ; ssp='ssp585';
elseif chain== 9+8  || chain==25+8  || chain==41+8  || chain==57+8  || chain==73+8 ; ssp='ssp585'; end
    
  %%
  contributor='Huss';
rgi_reg=['rgi',num2str(reg_no,'%02d')];
agg_level = 'sum';
agg_level_all = 'dyn';
  
  
  %file name
filename=['/scratch_net/vierzack06_fourth/cloris/GMIP/mhuss_sum/',contributor,'_',rgi_reg,'_',agg_level,'_',period,'_',gcm,'_',ssp,'.nc'];

  
  area = ncread(filename,'area_m2');
  volume = ncread(filename,'volume_m3');
  
  try
  area_all(1:5000,chain)=area;
  volume_all(1:5000,chain)=volume;
  catch
     area_all(1:2000,chain)=area;
  volume_all(1:2000,chain)=volume;   
  end
  
  %%
        
        
    end
    figure
    plot(area_all)
    ylabel('area')
    
    figure
    plot(volume_all)
    ylabel('volume')
    
    ciao=3
    close all
    clear area_all volume_all
    
end