mod_wave_power_jd

PURPOSE ^

SYNOPSIS ^

function wave = mod_wave_power_jd(wave,P0,flag_lin,locwave_id,opt_save)

DESCRIPTION ^

 INPUTS : 
   - wave      : original wave structure
   - P0        : new wave power (in W). If NaN, the power is not changed
   - flag_lin  : (true) : add "_lin" to linear ray power fields to comply with new formalism
   - locwaveid : add extra string at the end of wave.id. Otherwise, leave empty
   - opt_save  : save wave locally if opt_save == 1 or if opt_save is a non-empty string (which provides the file name [opt_save,'.mat'])

 OUTPUTS :
   - wave      : modified wave structure

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function wave = mod_wave_power_jd(wave,P0,flag_lin,locwave_id,opt_save)
0002     %
0003     % INPUTS :
0004     %   - wave      : original wave structure
0005     %   - P0        : new wave power (in W). If NaN, the power is not changed
0006     %   - flag_lin  : (true) : add "_lin" to linear ray power fields to comply with new formalism
0007     %   - locwaveid : add extra string at the end of wave.id. Otherwise, leave empty
0008     %   - opt_save  : save wave locally if opt_save == 1 or if opt_save is a non-empty string (which provides the file name [opt_save,'.mat'])
0009     %
0010     % OUTPUTS :
0011     %   - wave      : modified wave structure
0012     %
0013     if nargin < 5,
0014         opt_save = 0;
0015     end
0016     if nargin < 4,
0017         locwave_id = '';
0018     end
0019     if nargin < 3,
0020         flag_lin = false;
0021     end
0022     if nargin < 2,
0023         P0 = NaN;
0024     end
0025     %
0026     if isfield(wave,'rayinit') && isfield(wave.rayinit,'launch') && isfield(wave.rayinit.launch,'type') && strcmp(wave.rayinit.launch.type,'LH'),
0027         %
0028         % LH RT representation
0029         %
0030         P0_in = sum(wave.rayinit.launch.bPlhtot);
0031         %
0032         if ~isnan(P0),
0033             %
0034             Pfac = P0/P0_in;
0035             Pstr = ['_P0_',num2str(P0)];
0036             %
0037             % rayinit
0038             %
0039             wave.rayinit = mod_rayinit_power_jd(wave.rayinit,Pfac,Pstr);
0040             %
0041             % wave
0042             %
0043             if isfield(wave,'id'),
0044                 wave.id = [wave.id,Pstr];
0045             else
0046                 wave.id = wave.rayinit.id;
0047             end
0048             %
0049         end
0050         %
0051         if ~isempty(locwave_id),
0052             wave.id = [wave.id,locwave_id];
0053         end
0054         %
0055         % rays
0056         %
0057         for iray = 1:length(wave.rays),
0058             %
0059             ray = wave.rays{iray};
0060             %
0061             if flag_lin == 1,
0062                 %
0063                 if isfield(ray,'stau') && ~isfield(ray,'stau_lin'),
0064                     ray.stau_lin = ray.stau;
0065                     ray = rmfield(ray,'stau');
0066                 end
0067                 %
0068                 if isfield(ray,'sP_2piRp') && ~isfield(ray,'sP_2piRp_lin'),
0069                     ray.sP_2piRp_lin = ray.sP_2piRp;
0070                     ray = rmfield(ray,'sP_2piRp');
0071                 end
0072                 %
0073                 if isfield(ray,'sdP_2piRp_ds') && ~isfield(ray,'sdP_2piRp_ds_lin'),
0074                     ray.sdP_2piRp_ds_lin = ray.sdP_2piRp_ds;
0075                     ray = rmfield(ray,'sdP_2piRp_ds');
0076                 end
0077             end
0078             %
0079             if ~isnan(P0),
0080                 %
0081                 ray.P0_2piRp = ray.P0_2piRp*Pfac; 
0082                 %
0083                 if isfield(ray,'sP_2piRp_lin'),
0084                     ray.sP_2piRp_lin = ray.sP_2piRp_lin*Pfac; 
0085                 end
0086                 %
0087                 if isfield(ray,'sdP_2piRp_ds_lin'),
0088                     ray.sdP_2piRp_ds_lin = ray.sdP_2piRp_ds_lin*Pfac; 
0089                 end
0090                 %
0091                 if isfield(ray,'sP_2piRp'),
0092                     ray.sP_2piRp = ray.sP_2piRp*Pfac; 
0093                 end
0094                 %
0095                 if isfield(ray,'sdP_2piRp_ds'),
0096                     ray.sdP_2piRp_ds = ray.sdP_2piRp_ds*Pfac; 
0097                 end
0098                 %
0099                 if isfield(ray,'rayinits'),
0100                     %
0101                     for irayinit = 1:length(ray.rayinits),
0102                         %
0103                         ray.rayinits{irayinit} = mod_rayinit_power_jd(ray.rayinits{irayinit},Pfac,Pstr);
0104                         %
0105                     end
0106                     %
0107                 end
0108                 %
0109             end
0110             %
0111             wave.rays{iray} = ray;
0112             %
0113         end
0114         %
0115     else
0116         error('wave structure not compatible with mod_wave_power_jd')
0117     end
0118     %
0119     if ischar(opt_save) && ~isempty(opt_save),
0120         save([opt_save,'.mat'],'wave');
0121     elseif opt_save == 1,
0122         save(['WAVE_',wave.id,'.mat'],'wave');
0123     end
0124     %
0125 end
0126 %
0127 function rayinit = mod_rayinit_power_jd(rayinit,Pfac,Pstr)
0128     %
0129     % spectrum
0130     %
0131     if isfield(rayinit.launch,'spectrum'),
0132         if isfield(rayinit.launch.spectrum,'orig'),
0133             rayinit.launch.spectrum = rmfield(rayinit.launch.spectrum,{'orig'});
0134         end
0135         if isfield(rayinit.launch.spectrum,'Plhtot'),
0136             rayinit.launch.spectrum.Plhtot = rayinit.launch.spectrum.Plhtot*Pfac;
0137         end
0138     end
0139     %
0140     % launch
0141     %
0142     if isfield(rayinit.launch,'orig'),
0143         rayinit.launch = rmfield(rayinit.launch,{'orig'});
0144     end
0145     %
0146     if isfield(rayinit.launch,'id'),
0147         rayinit.launch.id = [rayinit.launch.id,Pstr];
0148     else
0149         rayinit.launch.id = [rayinit.launch.type,Pstr];
0150     end
0151     %
0152     rayinit.launch.bPlhtot = rayinit.launch.bPlhtot*Pfac;
0153     %
0154     % rayinit
0155     %
0156     if isfield(rayinit,'id'),
0157         rayinit.id = [rayinit.id,Pstr];
0158     else
0159         rayinit.id = ['C3PO_',rayinit.launch.id];
0160     end
0161     %
0162     rayinit.yP0_2piRp = rayinit.yP0_2piRp*Pfac;                                               
0163     %
0164 end
0165 %

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.