source: issm/trunk/src/m/solutions/dakota/dakota_resp_uconv.m@ 3185

Last change on this file since 3185 was 3185, checked in by jschierm, 15 years ago

Add dakota_resp_uconv to convert units of Dakota responses.

File size: 3.4 KB
Line 
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%
33function [dresp]=dakota_resp_uconv(dresp)
34
35if ~nargin
36 help dakota_resp_uconv
37 return
38end
39
40if ~isstruct(dresp)
41 error('''%s'' is not a structure array.',inputname(1));
42end
43if ~isfield(dresp,'descriptor')
44 error('''%s'' does not have a descriptor field.',inputname(1));
45end
46
47%% define the conversion factors
48
49sec_per_yr=365.2425*24*60*60; % mean gregorian year
50m_per_km=1000;
51kg_per_gton=10^12;
52
53%% loop through the response array
54
55for 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
66end
67
68end
69
70%% function to convert the units of a dakota response
71
72function [dresp]=drespi_conv(dresp,umfac,ulab)
73
74disp(['Converting response ''' dresp.descriptor ''' to ' ulab '.']);
75
76% loop over the fields, converting only the appropriate ones
77
78fnames=fieldnames(dresp);
79for 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
106end
107
108if isfield(dresp,'unit')
109 dresp.unit=ulab;
110end
111
112end
Note: See TracBrowser for help on using the repository browser.