/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_calc/layers_remap.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/matlab_class/gcmfaces_calc/layers_remap.m

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


Revision 1.1 - (show annotations) (download)
Mon Sep 24 23:05:20 2012 UTC (12 years, 10 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65r, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
- calc_barostream.m : add list_factors argument to accomodate e.g. tracer class transports.
- calc_overturn.m : add doFlip,list_factors args to accomodate e.g. tracer class transports.
- calc_barostream.m : introduce list_factors to allow use for e.g. tracer class transports.
- layers_remap.m (new) : remap variables (e.g. transports) from depth to tracer classes.
                       Uses regrid_dblres.m and regrid_sum.m and mimics pkg/layers.
- regrid_dblres.m (new) : double the resolution (only along 3rd dimension for now)
                       for a variable P (extensive or intensive) a number of times.
- regrid_sum.m (new) : add 3rd dimension elements of extensive variable P,
                       according to values of a tracer field collocated with P,
                       to the tracer grid defined by trGrid (1D vector)

1 function [varargout]=layers_remap(P,pType,tracer,trGrid,nDblRes);
2 %object : remap variables (e.g. transports) from depth to tracer classes.
3 %input : P is the variable of interest
4 % pType is 'extensive' or 'intensive'
5 % tracer is the tracer field (3D; at cell center in depth space).
6 % trGrid is the tracer space grid (1D; centers of tracer bins).
7 % nDblRes is the number of resolution doublings (in depth, not tracer space)
8 %output : P is the remapped variable
9 %notes : this was not fully tested for intensive quantities
10
11 gcmfaces_global;
12
13 doUV=iscell(P);%should depend on argument list
14 if isempty(whos('nDblRes')); nDblRes=0; end;%default is no grid refinement
15 tracer=tracer.*mygrid.mskC;%needed for trW/S, and regrid_dblres/intensive
16
17 if ~doUV;
18 listVar={'P'}; listTr={'tracer'}; listPos={'C'};
19 else;
20 listVar={'U','V'}; listTr={'trW','trS'}; listPos={'W','S'};
21 %
22 U=P{1}; V=P{2};
23 %
24 FLD=exch_T_N(tracer);
25 trW=NaN*tracer; trS=NaN*tracer;
26 for iF=1:FLD.nFaces;
27 tmpA=FLD{iF}(2:end-1,2:end-1,:);
28 tmpB=FLD{iF}(1:end-2,2:end-1,:);
29 trW{iF}=(tmpA+tmpB)/2;
30 tmpA=FLD{iF}(2:end-1,2:end-1,:);
31 tmpB=FLD{iF}(2:end-1,1:end-2,:);
32 trS{iF}=(tmpA+tmpB)/2;
33 end;
34 end;
35
36 for ii=1:length(listVar);
37 %rename
38 eval(['P=' listVar{ii} '; tracer=' listTr{ii} ';']);
39
40 %set to extensive
41 if strcmp(pType,'intensive');
42 if listPos{ii}=='C'; dxy=mk3D(mygrid.RAC,P).*mygrid.hFacC;
43 elseif listPos{ii}=='W'; dxy=mk3D(mygrid.DYG,P);
44 elseif listPos{ii}=='S'; dxy=mk3D(mygrid.DXG,P);
45 else; error('unknown position');
46 %document the different weights about C vs U/V
47 end;
48 S=dxy.*mk3D(mygrid.DRF,P);
49 P=P.*S;
50 end;
51
52 %apply mask
53 eval(['P=P.*mygrid.msk' listPos{ii} ';']);
54
55 %grid refinement (if nDblRes>0)
56 tracer=regrid_dblres(tracer,'intensive',nDblRes);
57 P=regrid_dblres(P,'extensive',nDblRes);
58
59 %the very remaping
60 P=regrid_sum(P,tracer,trGrid);
61
62 %reset to intensive
63 if strcmp(pType,'intensive');
64 eval(['S=S.*mygrid.msk' listPos{ii} ';']);
65 S=regrid_dblres(S,'extensive',nDblRes);
66 S=regrid_sum(S,tracer,trGrid);
67 P=P./S;
68 end;
69
70 %rename
71 eval([listVar{ii} '=P;']);
72 end;
73
74 %output result
75 if ~doUV; varargout={P}; else; varargout={U,V}; end;
76
77
78

  ViewVC Help
Powered by ViewVC 1.1.22