/[MITgcm]/MITgcm_contrib/gael/matlab_class/ecco_v4/extend_xx.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/matlab_class/ecco_v4/extend_xx.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download)
Thu Jan 28 01:38:48 2016 UTC (9 years, 6 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Changes since 1.2: +5 -6 lines
- minor changes.

1 function []=extend_xx(dirIn,dirOut,ndayIn,nyearOut);
2 %object: extend atmospheric controls to additional years
3 %inputs: dirIn is the input directory
4 % dirOut is the output directory
5 % ndayIn is the control vector frecuency, in days
6 % nyearOut is the extended number of years
7 %
8 %note: we will take the time mean seasonal cycle, and transition
9 % to it linearly over the last year that was already covered
10
11 gcmfaces_global;
12
13 %first copy time independent controls
14 listCp={'diffkr','kapgm','kapredi','salt','theta'};
15 for ii=1:length(listCp);
16 fileIn=dir([dirIn 'ADXXfiles/xx_' listCp{ii} '.00*data']);
17 copyfile([dirIn 'ADXXfiles/' fileIn.name] , [dirOut fileIn.name]);
18 end;
19
20 %then extend the time dependent ones
21 for ii=1:7;
22 switch ii;
23 case 1; xxName='atemp';
24 case 2; xxName='aqh';
25 case 3; xxName='tauu';
26 case 4; xxName='tauv';
27 case 5; xxName='lwdown';
28 case 6; xxName='swdown';
29 case 7; xxName='precip';
30 end;
31
32 %read model cost output
33 fld_xx=rdmds2gcmfaces([dirIn 'ADXXfiles/xx_' xxName '.00*']);
34
35 %determine already covered time period
36 nrec=size(fld_xx{1},3);
37 nyearIn=nrec*ndayIn/365;
38 nrecInOneYear=round(365/ndayIn);
39 nrecOut=nrecInOneYear*nyearOut+1;
40
41 %determine seasonal cycle
42 season_xx=0*fld_xx(:,:,1:nrecInOneYear);
43 for tt=1:nrecInOneYear;
44 season_xx(:,:,tt)=mean(fld_xx(:,:,tt:nrecInOneYear:nrec),3);
45 end;
46
47 if nyearOut==0;
48 more_xx=convert2gcmfaces(season_xx);
49 else;
50 %determine transition factor (fld_xx -> season_xx)
51 nrec0=nrecInOneYear*(floor(nyearIn)-1);
52 fac=([1:nrecOut]-nrec0)/(nrec-nrec0);
53 fac=max(min(fac,1),0);
54
55 %build extended time series
56 more_xx=zeros(fld_xx(:,:,1),nrecOut);
57 more_xx(:,:,1:nrec0)=fld_xx(:,:,1:nrec0);
58 for tt=nrec0+1:nrecOut;
59 ttt=mod(tt,nrecInOneYear);
60 if ttt==0; ttt=nrecInOneYear; end;
61 if tt<nrec;
62 more_xx(:,:,tt)=fac(tt)*season_xx(:,:,ttt)+(1-fac(tt))*fld_xx(:,:,tt);
63 else;
64 more_xx(:,:,tt)=season_xx(:,:,ttt);
65 end;
66 end;
67
68 %to check the transition:
69 tmp1=convert2array(fld_xx); tmp11=squeeze(mean(tmp1,1));
70 tmp2=convert2array(more_xx); tmp22=squeeze(mean(tmp2,1));
71 more_xx=convert2gcmfaces(more_xx);
72 end;
73
74 %save to file
75 fileIn=dir([dirIn 'ADXXfiles/xx_' xxName '.00*data']);
76 write2file([dirOut fileIn.name],more_xx);
77
78 end;%for ii=1:6;
79

  ViewVC Help
Powered by ViewVC 1.1.22