Warning, /verification/advect_xz/input.linFS/grph_StD_ws.m is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit 4013270f on 2026-11-20 17:40:17 UTC
4013270f16 Jean*0001 prefix='dynStD';
0002 flxPfx=''; wsCor=0;
0003 namA={'std'};
0004 %namA={'r02','t00'};
0005 Nexp=size(namA,2);
0006
0007 %- to read recond set of stats (time-mean):
0008 flxPfx='flxStD'; wsCor=1;
0009
0010 nItMx=1e10*ones(1,Nexp); %nItMx(3)=11;
0011 nItMx=2400*ones(1,Nexp);
0012 namLg=namA ; namLg=strrep(namLg,'_','\_');
0013 %-----------
0014 %- test if the variable krd is define :
0015 if size(who('krd'),1) > 0,
0016 fprintf('krd is defined and = %i \n',krd);
0017 else
0018 fprintf('krd undefined ; set to 1 \n'); krd=1 ;
0019 end
0020 if krd > 0,
0021 %- define list of fields to read in:
0022 clear listV ;
0023 %listV={'Eta','U','W','T','S','ADVx_TH','ADVr_TH','AB_gT','AB_gS'};
0024 %listV={'Eta','U','W','T','S','ADVx_TH','ADVr_TH','gSinAB'};
0025 %- or take all them:
0026 clear listV ; listV='all_flds';
0027 %-----------
0028
0029 %- start to read the longest record:
0030 n=1; rf=-1; if strcmp(char(listV),'all_flds'), rf=0; end
0031 [ntA(n),rList,tim,vv1,listV] = ...
0032 read_StD(prefix,namA(n),listV);
0033 nIt=ntA(n); nk=size(vv1,1); nRg=size(vv1,3);
0034 %- set global dims: & load vvA --> vvB
0035 nbV=size(listV,2);
0036 nrec=nIt; n3d=nk; nReg=nRg;
0037 vvA=zeros(n3d,nrec,nReg,5,nbV,Nexp); tiA=zeros(nrec,2,Nexp);
0038 vvA(1:nk,1:nIt,1:nRg,:,:,n)=vv1; tiA(1:nIt,:,n)=tim;
0039 %----
0040 for n=2:Nexp,
0041 [ntA(n),rList,tim,vv1,listV] = ...
0042 read_StD(prefix,namA(n),listV);
0043 nIt=ntA(n); nk=size(vv1,1); nRg=size(vv1,3);
0044 if (nrec < nIt),
0045 fprintf('\n');
0046 error([' Nb of records=',int2str(nIt),' exceeds nrec=',int2str(nrec)]);
0047 end
0048 if (n3d < nk),
0049 fprintf('\n');
0050 error([' Nb of Levels=',int2str(nk),' exceeds n3d=',int2str(n3d)]);
0051 end
0052 vvA(1:nk,1:nIt,1:nRg,:,:,n)=vv1; tiA(1:nIt,:,n)=tim;
0053 end;
0054 if krd == 2,
0055 fprintf('save to "sav_StD.mat" file ...');
0056 save('sav_StD.mat','vvA','tiA','ntA','rList','listV');
0057 fprintf(' done\n')
0058 end
0059 elseif krd < 0,
0060 fprintf('load from "sav_StD.mat" file ...');
0061 load sav_StD
0062 fprintf(' done\n'); nbV=size(listV,2);
0063 end
0064 if krd ~= 0,
0065 ttA=squeeze(tiA(:,2,:));
0066 ttA=ttA/3600; titT='hrs'; ttA=ttA/24; titT='days';
0067 %ttA=ttA/30 ; titT='month'; ttA=ttA/12 ; titT='year';
0068 end
0069 %---------------------------------------------------------
0070 if krd ~= 0,
0071 if length(flxPfx) > 0 ,
0072 n=1;
0073 [nIt2,rList2,tim2,vv2,listV2] = read_StD(flxPfx,namA(n),'all_flds');
0074 nk2=size(vv2,1); nbV2=size(listV2,2);
0075 vvB=zeros(nk2,nIt2,5,nbV2,Nexp); tiB=zeros(nIt2,2,Nexp);
0076 % save only 1 region (3rd index)
0077 vvB(:,:,:,:,n)=vv2(:,:,1,:,:); tiB(:,:,n)=tim2;
0078 for n=2:Nexp,
0079 [nt2,rListi2,tim2,vv2,listV2] = read_StD(flxPfx,namA(n),listV2);
0080 vvB(:,1:nt2,:,:,n)=vv2(:,:,1,:,:); tiB(1:nt2,:,n)=tim2;
0081 end
0082 else listV2=listV; nIt2=nrec-1; end
0083 end
0084 %=========================================================
0085
0086 ttax1=0 ; ttax2=0 ; ttay=zeros(nbV,2);
0087 %-- fixed time axis bound :
0088 % ttax1=15.; ttax2=20.;
0089 %-- fixed Y axis bound :
0090 % ttay(4,:)=[0 0.6];
0091 %-----------
0092 fprintf('Total length: ntA=');fprintf(' %i ,',ntA); fprintf(' \n');
0093 for n=1:Nexp,
0094 fprintf(' exp %i : time(d):%10.2f ->%10.2f \n', n,ttA(1,n),ttA(ntA(n),n) );
0095 end;
0096 %--
0097
0098 list_on=zeros(1,nbV);
0099 nbG=8;
0100 %nbG=min(nbG,nbV); list_on(1:nbG)=1 ;
0101 list_on(3:4)=1;
0102 %list_on(1:6)=[1 1 1 1 1 1];
0103
0104 isA=ones(1,Nexp); ieA=ntA;
0105 %- limit the length :
0106 %isA=isA*31 ; % drop the 1rst mnth (1 Monitor/d)
0107 %ieA(:)=240; %isA(:)=1;
0108
0109 lThick=0; %- default line thickness
0110 linA={'k-','b-','r-','g-','m-','c-'};
0111 % lThick=1.5;
0112 linA={'k-','b--','r-','g-','m-','c-'};
0113 lThick=1.5;
0114
0115 ieA=min(ieA,nItMx);
0116 %titall='AIM , Cubic-G (32x32) , cpl-FM Forcing' ;
0117 %titall='Global Ocean, Cubic-G (32x32) , CORE Forc (2)' ;
0118 titall='Advect\_xz (nlfs) test experiment' ;
0119
0120 %=========================================================
0121
0122 for ng=1:nbV,
0123 %-------------------
0124 flag=list_on(ng); kl=0;
0125 vv1=vvA(:,:,:,:,ng,:); namV=char(listV(ng));
0126 titv=strrep(namV,'_','\_');
0127 %if strcmp(namV,'Eta'), vv1=vv1/100; titv='Eta [mb]'; end
0128 %if strcmp(namV,'T'), kl=1; end % <-- to get surf.Temp
0129 %if ng == 1, flag=2*list_on(1) ; end
0130 if kl > 0, titv=[titv,'\_',int2str(kl)];
0131 fprintf([' var= ',namV,' at level k= %i \n'],kl);
0132 end
0133
0134 if flag == 1
0135 %--
0136 %figure(ng); set(ng,'position',[100+100*ng 60+40*ng 500 700]);clf;
0137 figure(ng); PP=get(ng,'position'); set(ng,'position',[PP(1:2) 500 700]);clf;
0138 var=squeeze(vv1(1+kl,:,1,:,:)); dd=zeros(5,Nexp); av=zeros(5,Nexp);
0139 for n=1:Nexp,
0140 dd(:,n)=max(var(isA(n):ieA(n),:,n))-min(var(isA(n):ieA(n),:,n));
0141 av(:,n)=mean(var(isA(n):ieA(n),:,n));
0142 end
0143 for nv=1:4,
0144 subplot(410+nv); ttmn=' Mx-mn:'; ttav=' Av:';
0145 for n=1:Nexp,
0146 LL(n)=plot(ttA(isA(n):ieA(n),n),var(isA(n):ieA(n),nv,n),char(linA(n)));
0147 if n == 1, hold on ; end ;
0148 ttmn=sprintf([ttmn,' %2.1e ;'],dd(nv,n));
0149 ttav=sprintf([ttav,' %3.2e ;'],av(nv,n));
0150 end ; hold off ;
0151 if lThick > 0, set(LL,'LineWidth',lThick); end
0152 AA=axis ; dAA=AA(4)-AA(3);
0153 if AA(3)*AA(4) <= 0, AA(3)=min(AA(3),-dAA/10); AA(4)=max(AA(4),dAA/10); end
0154 if ttax1 < ttax2, AA(1)=ttax1; AA(2)=ttax2; end;
0155 axis(AA); grid ;
0156 if nv == 1, title(['Avr ',titv,' ',ttmn]); end
0157 if nv == 2, title(['Std-Dev ',titv,' ',ttav]); end
0158 if nv == 3, title(['min ',titv,' ',ttav]);
0159 legend(namLg,'Location','best'); end
0160 if nv == 4, title(['Max ',titv,' ',ttav]); end
0161 end ; xlabel(titT);
0162 %--
0163 axes('position',[.01,.01,.99,.99],'Visible','off');
0164 T=text(0.5,0.97,titall);
0165 set(T,'HorizontalAlignment','center','FontSize',12);
0166 Td=text(0.99,0.01,date);
0167 set(Td,'HorizontalAlignment','right','FontSize',6);
0168 %---
0169 end
0170
0171 %-------------------
0172 end
0173
0174 %=========================================================
0175 %-- get mean-depth + surface-level index from a pair of 3d,2d vars:
0176 nm3d='T'; j3d=0; [I]=strcmp(listV,nm3d); if sum(I) == 1, j3d=find(I==1); end
0177 nm2d='Eta'; j2d=0; [I]=strcmp(listV,nm2d); if sum(I) == 1, j2d=find(I==1); end
0178 if j2d*j3d > 0,
0179 vol=squeeze(vvA(:,1,1,5,j3d,:)); area=squeeze(vvA(1,1,1,5,j2d,:));
0180 hAvr=vol(1,:)'./area;
0181 for n=1:Nexp, [I]=find(vol(2:end,n) > 0.); kSrf(n)=I(1); end
0182 fprintf(' from j3d,j2d= %i,%i volume ratio, get:\n',j3d,j2d);
0183 for n=1:Nexp, fprintf(' - kSrf= %i , mean-Depth=%7.1f\n',kSrf(n),hAvr(n)); end
0184 else
0185 fprintf(' missing vars "%s" or "%s" --> use default kSrf,hAvr\n',nm3d,nm2d);
0186 kSrf=ones(Nexp,1); hAvr=kSrf;
0187 end
0188 %---------
0189 trF={'TH','SLT'}; nbTr=length(trF);
0190 nSav=4; titV={'Total','Wsrf','gAB','Resid'}; ndt=nrec-1;
0191 ndt=nrec-1; savVar=zeros(ndt,nSav*nbTr,Nexp);
0192 ttD=(ttA(1:nrec-1,:)+ttA(2:nrec,:))*0.5;
0193 for j=1:nbTr,
0194 sNam=char(trF(j)); namD=['W',sNam,'MASS']; namAB=['AB_g',sNam(1)];
0195 jTr=0; [I]=strcmp(listV,sNam(1));
0196 if sum(I) == 1, jTr=find(I==1); end
0197 jWs=0; [I]=strcmp(listV2,namD);
0198 if sum(I) == 1, jWs=find(I==1); end
0199 jAB=0; [I]=strcmp(listV2,namAB);
0200 if sum(I) == 1, jAB=find(I==1); end
0201 fprintf(' %3s : jTr,jWs,jAB= %i , %i , %i \n',sNam,jTr,jWs,jAB);
0202 j1= 1 + (j-1)*nSav; j3=j1+3;
0203 if jTr > 0,
0204 %-- save time series:
0205 locVar=reshape(vvA(1,:,1,1,jTr,:),[nrec Nexp]);
0206 %- rate of change: do finite difference from difference between record:
0207 locVar(1:nrec-1,:)=locVar(2:nrec,:)-locVar(1:nrec-1,:);
0208 locVar=reshape(locVar(1:ndt,:),[ndt Nexp]);
0209 % divided by time-interval between record:
0210 delTA=reshape(tiA(2:nrec,2,:)-tiA(1:nrec-1,2,:),[ndt Nexp]);
0211 recDTA=delTA; recDTA(find(delTA==0))=-1; recDTA=1./recDTA; recDTA=max(recDTA,0);
0212 %-- save time series:
0213 savVar(1:ndt,j1,:)=locVar.*recDTA;
0214 savVar(1:ndt,j3,:)=savVar(1:ndt,j1,:);
0215 end
0216 if jAB > 0, jj=j1+2;
0217 tmpVar=reshape(vvB(1,:,1,jAB,:),[nIt2 Nexp]);
0218 savVar(1:ndt,jj,:)=tmpVar(1:ndt,:);
0219 end
0220 if jTr*jWs > 0, jj=j1+1;
0221 tmpVar=zeros(nIt2,Nexp);
0222 for n=1:Nexp, tmpVar(:,n)=squeeze(vvB(1+kSrf(n),:,1,jWs,n)); end
0223 tmpVar=tmpVar./repmat(hAvr',[nIt2 1]); %- divide by mean depth
0224 savVar(1:ndt,jj,:)=tmpVar(1:ndt,:);
0225 end
0226 if jTr*jWs*wsCor > 0, jj=j1+1;
0227 savVar(:,j3,:)=savVar(:,j3,:)+savVar(:,jj,:);
0228 end
0229 if jAB > 0, jj=j1+2;
0230 savVar(:,j3,:)=savVar(:,j3,:)-savVar(:,jj,:);
0231 end
0232 end
0233 %-------------------
0234 ieB=max(isA,ieA-1);
0235 for j2=1:nbTr,
0236 ng=8+j2;
0237 figure(ng); PP=get(ng,'position'); set(ng,'position',[PP(1:2) 500 700]);clf;
0238 for j1=1:nSav,
0239 nv=j1+(j2-1)*nSav;
0240 tit_fg=[char(trF(j2)),' tendency : ',char(titV(j1))];
0241 nsp=nSav*100+10+j1; subplot(nsp)
0242 for n=1:Nexp,
0243 LL(n)=plot(ttD(isA(n):ieB(n),n),savVar(isA(n):ieB(n),nv,n),char(linA(n)));
0244 if n == 1, hold on ; end ;
0245 end ; hold off ;
0246 if lThick > 0, set(LL,'LineWidth',lThick); end
0247 AA=axis ; dAA=AA(4)-AA(3);
0248 if AA(3)*AA(4) <= 0, AA(3)=min(AA(3),-dAA/10); AA(4)=max(AA(4),dAA/10); end
0249 if ttax1 < ttax2, AA(1)=ttax1; AA(2)=ttax2; end;
0250 axis(AA); grid ;
0251 title(tit_fg);
0252 end
0253 xlabel(titT);
0254 end
0255