1 |
gforget |
1.1 |
function [MITprof]=MITprof_stats_load(dirData,listData,varCur,varargin); |
2 |
|
|
%[MITprof]=MITprof_stats_load(dirData,listData,varCur,varargin); |
3 |
gforget |
1.4 |
%object: loads a series of MITprof files, and computes |
4 |
|
|
% normalized misfits for one variable |
5 |
|
|
%input: dirData is the data directory name |
6 |
|
|
% listData is the data file list (e.g. {'argo_in*'} or {'argo_in*','argo_at*'} ) |
7 |
|
|
% varCur is 'T' or 'S' |
8 |
gforget |
1.7 |
%optional : |
9 |
|
|
% EITHER normFactor (optional; double) is the normalization factor (1./prof_?weight by default) |
10 |
|
|
% OR varSpec (optional; char) is e.g. 'prof_T' or 'prof_Testim' |
11 |
gforget |
1.4 |
%output: MITprof.prof is the normalized misfit |
12 |
|
|
%note: by assumption, all of the files in listData must share the same vertical grid |
13 |
gforget |
1.1 |
|
14 |
gforget |
1.6 |
normFactor=[]; varSpec=''; |
15 |
|
|
if nargin>3; |
16 |
|
|
if isnumeric(varargin{1}); normFactor=varargin{1}; end; |
17 |
|
|
if ischar(varargin{1}); varSpec=varargin{1}; end; |
18 |
|
|
end; |
19 |
gforget |
1.1 |
|
20 |
gforget |
1.2 |
useExtendedProfDepth=1; |
21 |
|
|
|
22 |
gforget |
1.5 |
%develop listData (that may include wildcards) |
23 |
|
|
listData_bak=listData; |
24 |
|
|
listData={}; |
25 |
|
|
for ii=1:length(listData_bak); |
26 |
|
|
tmp1=dir([dirData listData_bak{ii}]); |
27 |
|
|
for jj=1:length(tmp1); |
28 |
|
|
ii2=length(listData)+1; |
29 |
|
|
listData{ii2}=tmp1(jj).name; |
30 |
|
|
end; |
31 |
|
|
end; |
32 |
|
|
%avoid duplicates |
33 |
|
|
listData=unique(listData); |
34 |
|
|
|
35 |
|
|
%loop over files |
36 |
gforget |
1.1 |
for iFile=1:length(listData); |
37 |
|
|
fileData=dir([dirData listData{iFile}]); |
38 |
gforget |
1.5 |
fileData=fileData.name; |
39 |
|
|
fprintf(['loading ' varCur ' from ' fileData '\n']); |
40 |
gforget |
1.1 |
MITprofCur=MITprof_load([dirData fileData]); |
41 |
|
|
|
42 |
|
|
% fixes: |
43 |
|
|
if ~isfield(MITprofCur,'prof_S'); |
44 |
|
|
tmp1=NaN*MITprofCur.prof_T; |
45 |
|
|
MITprofCur.prof_S=tmp1; MITprofCur.prof_Sestim=tmp1; |
46 |
|
|
MITprofCur.prof_Sweight=tmp1; MITprofCur.prof_Sflag=[]; |
47 |
|
|
end; |
48 |
|
|
% fixes |
49 |
gforget |
1.7 |
if ~isfield(MITprofCur,['prof_' varCur 'weight']); |
50 |
|
|
eval(['MITprofCur.prof_' varCur 'weight=1+0*MITprofCur.prof_' varCur ';']); |
51 |
|
|
end; |
52 |
gforget |
1.1 |
|
53 |
|
|
if ~isempty(normFactor);%replace weights with normFactor |
54 |
|
|
eval(['tmp1=MITprofCur.prof_' varCur 'weight;']); |
55 |
|
|
tmp1(tmp1>0)=normFactor; |
56 |
|
|
eval(['MITprofCur.prof_' varCur 'weight=tmp1;']); |
57 |
|
|
end; |
58 |
|
|
|
59 |
|
|
if varCur=='T'; |
60 |
|
|
tmp1=(MITprofCur.prof_Testim-MITprofCur.prof_T).*sqrt(MITprofCur.prof_Tweight); |
61 |
|
|
else; |
62 |
|
|
tmp1=(MITprofCur.prof_Sestim-MITprofCur.prof_S).*sqrt(MITprofCur.prof_Sweight); |
63 |
gforget |
1.2 |
end; |
64 |
gforget |
1.6 |
%nan-mask |
65 |
|
|
tmp1(tmp1==0)=NaN; |
66 |
|
|
%replace non-masked values with varSpec? |
67 |
|
|
if ~isempty(varSpec); |
68 |
|
|
eval(['tmp2=MITprofCur.' varSpec ';']); tmp2(isnan(tmp1))=NaN; tmp1=tmp2; |
69 |
|
|
end; |
70 |
|
|
MITprofCur.prof=tmp1; |
71 |
gforget |
1.3 |
|
72 |
gforget |
1.4 |
listRm={'prof_T','prof_Testim','prof_Tweight','prof_Tflag','prof_Terr',... |
73 |
|
|
'prof_S','prof_Sestim','prof_Sweight','prof_Sflag','prof_Serr',... |
74 |
gforget |
1.7 |
'prof_D','prof_Destim',... |
75 |
|
|
'prof_T_SOSE59','prof_S_SOSE59','prof_madt_aviso',... |
76 |
|
|
'prof_DRHODR','prof_DRHODRestim','prof_DRHODRweight',... |
77 |
|
|
'prof_RHOP','prof_RHOPestim','prof_RHOPweight'}; |
78 |
gforget |
1.2 |
for iRm=1:length(listRm); |
79 |
gforget |
1.3 |
if isfield(MITprofCur,listRm{iRm}); MITprofCur=rmfield(MITprofCur,listRm{iRm}); end; |
80 |
gforget |
1.1 |
end; |
81 |
|
|
|
82 |
|
|
MITprofCur.prof_date=datenum(num2str(MITprofCur.prof_YYYYMMDD*1e6+MITprofCur.prof_HHMMSS),'yyyymmddHHMMSS'); |
83 |
gforget |
1.3 |
%old: ii=find(MITprofCur.prof_date<datenum(1992,1,1)|MITprofCur.prof_date>datenum(2008,12,27)); MITprofCur.prof(ii,:)=NaN; |
84 |
gforget |
1.1 |
|
85 |
gforget |
1.2 |
if useExtendedProfDepth; |
86 |
gforget |
1.3 |
%use extended standard depth vector |
87 |
gforget |
1.2 |
all_depth=[ 0 5 10 15 20 25 30 35 45 50 55 65 75 85 95 100 ... |
88 |
gforget |
1.3 |
105 115 125 135 145 150 155 165 175 185 200 220 240 250 260 280 ... |
89 |
|
|
300 320 340 360 380 400 420 440 460 480 500 550 600 650 700 750 ... |
90 |
|
|
800 850 900 950 1000 1100 1200 1300 1400 1500 1600 1700 1750 1800 1900 2000 2100 ... |
91 |
|
|
2200 2300 2400 2500 2600 2700 2800 2900 3000 3100 3200 3300 3400 3500 3600 3700 ... |
92 |
|
|
3800 3900 4000 4100 4200 4300 4400 4500 4600 4700 4800 4900 5000 5100 5200 5300 ... |
93 |
|
|
5400 5500 5600 5700 5800 5900 6000 6500 7000 7500 8000 8500 9000]; |
94 |
gforget |
1.2 |
k_depth=NaN*zeros(1,MITprofCur.nr); |
95 |
|
|
for kk=1:MITprofCur.nr; k_depth(kk)=find(MITprofCur.prof_depth(kk)==all_depth); end; |
96 |
|
|
all_prof=NaN*ones(MITprofCur.np,length(all_depth)); |
97 |
gforget |
1.3 |
all_prof(:,k_depth)=MITprofCur.prof; |
98 |
|
|
MITprofCur.prof=all_prof; |
99 |
gforget |
1.2 |
MITprofCur.nr=length(all_depth); |
100 |
|
|
MITprofCur.prof_depth=all_depth; |
101 |
gforget |
1.1 |
end; |
102 |
|
|
|
103 |
|
|
if iFile==1; |
104 |
|
|
MITprof=MITprofCur; |
105 |
|
|
else; |
106 |
|
|
MITprof=MITprof_concat(MITprof,MITprofCur); |
107 |
|
|
end; |
108 |
|
|
clear MITprofCur; |
109 |
|
|
end; |
110 |
|
|
|
111 |
|
|
|