1 | %
|
---|
2 | % convert the units for dakota responses.
|
---|
3 | %
|
---|
4 | % [dresp]=dakota_resp_uconv(dresp)
|
---|
5 | %
|
---|
6 | % where the required input is:
|
---|
7 | % dresp (structure array, responses)
|
---|
8 | %
|
---|
9 | % the required output is:
|
---|
10 | % dresp (structure array, responses)
|
---|
11 | %
|
---|
12 | % this function reads through a dakota response structure, and
|
---|
13 | % for those quantities whose descriptors are recognized, converts
|
---|
14 | % the units of all the applicable fields. a "unit" field is added
|
---|
15 | % to the response structure.
|
---|
16 | %
|
---|
17 | % this data would typically be read by dakota_out_parse and be used
|
---|
18 | % for plotting and other post-processing within matlab or excel.
|
---|
19 | %
|
---|
20 | % "Copyright 2010, by the California Institute of Technology.
|
---|
21 | % ALL RIGHTS RESERVED. United States Government Sponsorship
|
---|
22 | % acknowledged. Any commercial use must be negotiated with
|
---|
23 | % the Office of Technology Transfer at the California Institute
|
---|
24 | % of Technology. (NTR 47078)
|
---|
25 | %
|
---|
26 | % This software may be subject to U.S. export control laws.
|
---|
27 | % By accepting this software, the user agrees to comply with
|
---|
28 | % all applicable U.S. export laws and regulations. User has the
|
---|
29 | % responsibility to obtain export licenses, or other export
|
---|
30 | % authority as may be required before exporting such information
|
---|
31 | % to foreign countries or providing access to foreign persons."
|
---|
32 | %
|
---|
33 | function [dresp]=dakota_resp_uconv(dresp)
|
---|
34 |
|
---|
35 | if ~nargin
|
---|
36 | help dakota_resp_uconv
|
---|
37 | return
|
---|
38 | end
|
---|
39 |
|
---|
40 | if ~isstruct(dresp)
|
---|
41 | error('''%s'' is not a structure array.',inputname(1));
|
---|
42 | end
|
---|
43 | if ~isfield(dresp,'descriptor')
|
---|
44 | error('''%s'' does not have a descriptor field.',inputname(1));
|
---|
45 | end
|
---|
46 |
|
---|
47 | %% define the conversion factors
|
---|
48 |
|
---|
49 | sec_per_yr=365.2425*24*60*60; % mean gregorian year
|
---|
50 | m_per_km=1000;
|
---|
51 | kg_per_gton=10^12;
|
---|
52 |
|
---|
53 | %% loop through the response array
|
---|
54 |
|
---|
55 | for i=1:numel(dresp)
|
---|
56 | dresp(i).unit='';
|
---|
57 | if ~isempty(strfind(dresp(i).descriptor,'vel')) % in m/sec
|
---|
58 | dresp(i)=drespi_conv(dresp(i),sec_per_yr,'m/yr');
|
---|
59 | elseif ~isempty(strfind(dresp(i).descriptor,'misfit')) % in m^2*(m/sec)^2
|
---|
60 | dresp(i)=drespi_conv(dresp(i),1/m_per_km^2*sec_per_yr^2,'km^2*(m/yr)^2');
|
---|
61 | elseif ~isempty(strfind(dresp(i).descriptor,'mass_flux')) % in kg/sec
|
---|
62 | dresp(i)=drespi_conv(dresp(i),1/kg_per_gton*sec_per_yr,'Gton/yr');
|
---|
63 | else
|
---|
64 | disp(['Skipping response ''' dresp(i).descriptor '''.']);
|
---|
65 | end
|
---|
66 | end
|
---|
67 |
|
---|
68 | end
|
---|
69 |
|
---|
70 | %% function to convert the units of a dakota response
|
---|
71 |
|
---|
72 | function [dresp]=drespi_conv(dresp,umfac,ulab)
|
---|
73 |
|
---|
74 | disp(['Converting response ''' dresp.descriptor ''' to ' ulab '.']);
|
---|
75 |
|
---|
76 | % loop over the fields, converting only the appropriate ones
|
---|
77 |
|
---|
78 | fnames=fieldnames(dresp);
|
---|
79 | for i=1:length(fnames)
|
---|
80 | switch fnames{i}
|
---|
81 | case {'sample',...
|
---|
82 | 'mean',...
|
---|
83 | 'stddev',...
|
---|
84 | 'meanci',...
|
---|
85 | 'stddevci',...
|
---|
86 | 'min',...
|
---|
87 | 'quart1',...
|
---|
88 | 'median',...
|
---|
89 | 'quart3',...
|
---|
90 | 'max'} % appropriate to convert
|
---|
91 | dresp.(fnames{i})=dresp.(fnames{i})*umfac;
|
---|
92 | case {'cdf'} % only responses, not probs or reliabilities
|
---|
93 | dresp.cdf(:,1)=dresp.cdf(:,1)*umfac;
|
---|
94 | case {'descriptor',...
|
---|
95 | 'coefvar',...
|
---|
96 | 'var',...
|
---|
97 | 'impfac'} % unitless (or non-numeric)
|
---|
98 | continue;
|
---|
99 | case {'best',...
|
---|
100 | 'vum',...
|
---|
101 | 'unit'} % other
|
---|
102 | continue;
|
---|
103 | otherwise
|
---|
104 | disp(['Unrecognized field ''' fnames{i} '''.']);
|
---|
105 | end
|
---|
106 | end
|
---|
107 |
|
---|
108 | if isfield(dresp,'unit')
|
---|
109 | dresp.unit=ulab;
|
---|
110 | end
|
---|
111 |
|
---|
112 | end
|
---|