text:
function [nameu,fu,tidecon,xout]=t_tide(xin,varargin);
% T_TIDE Harmonic analysis of a time series
% [NAME,FREQ,TIDECON,XOUT]=T_TIDE(XIN) computes the tidal analysis
% of the (possibly complex) time series XIN.
%
% [TIDESTRUC,XOUT]=T_TIDE(XIN) returns the analysis information in
% a structure formed of NAME, FREQ, and TIDECON.
%
% XIN can be scalar (e.g. for elevations), or complex ( =U+sqrt(-1)*V
% for eastward velocity U and northward velocity V.
%
% Further inputs are optional, and are specified as property/value pairs
% [...]=T_TIDE(XIN,property,value,property,value,...,etc.)
%
% These properties are:
%
%       'interval'       Sampling interval (hours), default = 1.
%
%   The next two are required if nodal corrections are to be computed,
%   otherwise not necessary. If they are not included then the reported
%   phases are raw constituent phases at the central time.
%
%   If your time series is longer than 18.6 years then nodal corrections
%   are not made -instead we fit directly to all satellites (start time
%   is then just used to generate Greenwich phases).
%
%       'start time'     [year,month,day,hour,min,sec]
%                        - min,sec are optional OR
%                        decimal day (matlab DATENUM scalar)
%       'latitude'       decimal degrees (+north) (default: none).
%
%   Where to send the output.
%       'output'         where to send printed output:
%                        'none'    (no printed output)
%                        'screen'  (to screen) - default
%                        FILENAME   (to a file)
%
%   Correction factor for prefiltering.
%       'prefilt'        FS,CORR
%                        If the time series has been passed through
%                        a pre-filter of some kind (say, to reduce the
%                        low-frequency variability), then the analyzed
%                        constituents will have to be corrected for
%                        this. The correction transfer function
%                        (1/filter transfer function) has (possibly
%                        complex) magnitude CORR at frequency FS (cph).
%                        Corrections of more than a factor of 100 are
%                        not applied; it is assumed these refer to tidal
%                        constituents that were intentionally filtered
%                        out, e.g., the fortnightly components.
%
%   Adjustment for long-term behavior ("secular" behavior).
%       'secular'        'mean'   - assume constant offset (default).
%                        'linear' - get linear trend.
%
%   Inference of constituents.
%       'inference'      NAME,REFERENCE,AMPRAT,PHASE_OFFSET
%                        where NAME is an array of the names of
%                        constituents to be inferred, REFERENCE is an
%                        array of the names of references, and AMPRAT
%                        and PHASE_OFFSET are the amplitude factor and
%                        phase offset (in degrees)from the references.
%                        NAME and REFERENCE are Nx4 (max 4 characters
%                        in name), and AMPRAT and PHASE_OFFSET are Nx1
%                        (for scalar time series) and Nx2 for vector
%                        time series (column 1 is for + frequencies and
%                        column 2 for - frequencies).
%                        NB - you can only infer ONE unknown constituent
%                        per known constituent (i.e. REFERENCE must not
%                        contain multiple instances of the same name).
%
%   Shallow water constituents
%       'shallow'        NAME
%                        A matrix whose rows contain the names of
%                        shallow-water constituents to analyze.
%
%   Resolution criterions for least-squares fit.
%       'rayleigh'       scalar - Rayleigh criteria, default = 1.
%                        Matrix of strings - names of constituents to
%                                   use (useful for testing purposes).
%
%   Calculation of confidence limits.
%       'error'          'wboot'  - Boostrapped confidence intervals
%                                   based on a correlated bivariate
%                                   white-noise model.
%                        'cboot'  - Boostrapped confidence intervals
%                                   based on an uncorrelated bivariate
%                                   coloured-noise model (default).
%                        'linear' - Linearized error analysis that
%                                   assumes an uncorrelated bivariate
%                                   coloured noise model.
%
%   Computation of "predicted" tide (passed to t_predic, but note that
%                                    the default value is different).
%       'synthesis'      0 - use all selected constituents
%                        scalar>0 - use only those constituents with a
%                                   SNR greater than that given (1 or 2
%                                   are good choices, 2 is the default).
%                              <0 - return result of least-squares fit
%                                   (should be the same as using '0',
%                                   except that NaN-holes in original
%                                   time series will remain and mean/trend
%                                   are included).
%
%   Least squares soln computational efficiency parameter
%	'lsq'		'direct'  - use A\x fit
%			'normal'  - use (A'A)\(A'x) (may be necessary
%				    for very large input vectors since
%                                   A'A is much smaller than A)
%			'best'	  - automatically choose based on
%				    length of series (default).
%
%       It is possible to call t_tide without using property names,
%       in which case the assumed calling sequence is
%
%          T_TIDE(XIN,INTERVAL,START_TIME,LATITUDE,RAYLEIGH)
%
%
%  OUTPUT:
%
%    nameu=list of constituents used
%    fu=frequency of tidal constituents (cycles/hr)
%    tidecon=[fmaj,emaj,fmin,emin,finc,einc,pha,epha] for vector xin
%           =[fmaj,emaj,pha,epha] for scalar (real) xin
%       fmaj,fmin - constituent major and minor axes (same units as xin)
%       emaj,emin - 95% confidence intervals for fmaj,fmin
%       finc - ellipse orientations (degrees)
%       einc - 95% confidence intervals for finc
%       pha - constituent phases (degrees relative to Greenwich)
%       epha - 95% confidence intervals for pha
%    xout=tidal prediction
%
% Note: Although missing data can be handled with NaN, it is wise not
%       to have too many of them. If your time series has a lot of
%       missing data at the beginning and/or end, then truncate the
%       input time series.  The Rayleigh criterion is applied to
%       frequency intervals calculated as the inverse of the input
%       series length.
%
% A description of the theoretical basis of the analysis and some
% implementation details can be found in:
%
% Pawlowicz, R., B. Beardsley, and S. Lentz, "Classical Tidal
%   "Harmonic Analysis Including Error Estimates in MATLAB
%    using T_TIDE", Computers and Geosciences, 28, 929-937 (2002).
%
% (citation of this article would be appreciated if you find the
%  toolbox useful).

% R. Pawlowicz 11/8/99 - Completely rewritten from the transliterated-
%                        to-matlab IOS/Foreman fortran code by S. Lentz
%                        and B. Beardsley.
%              3/3/00  - Redid errors to take into account covariances
%                        between u and v errors.
%              7/21/00 - Found that annoying bug in error calc!
%              11/1/00 - Added linear error analysis.
%              8/29/01 - Made synth=1 default, also changed behavior
%                        when no lat/time given so that phases are raw
%                        at central time.
%              9/1/01  - Moved some SNR code to t_predic.
%              9/28/01 - made sure you can't choose Z0 as constituent.
%              6/12/01 - better explanation for variance calcs, fixed
%                        bug in typed output (thanks Mike Cook).
%              8/2/03 - Added block processing for long time series (thanks
%                       to Derek Goring).
%              9/2/03 - Beta version of 18.6 year series handling
%              12/2/03 - Bug (x should be xin) fixed thanks to Mike Cook (again!)
%              4/3/11 - Changed (old) psd to (new) pwelch calls, also
%                       isfinite for finite.
%              23/3/11 - Corrected my conversion from psd to pwelch, thanks
%                       to Dan Codiga and (especially) Evan Haug!

%
% Version 1.3

% ----------------------Parse inputs-----------------------------------

ray=1;
dt=1;
fid=1;
stime=[];
lat=[];
corr_fs=[0 1e6];
corr_fac=[1  1];
secular='mean';
inf.iname=[];
inf.irefname=[];
shallownames=[];
constitnames=[];
errcalc='cboot';
synth=2;
lsq='best';

k=1;
while length(varargin)>0,
  if ischar(varargin{1}),
    switch lower(varargin{1}(1:3)),
      case 'int',
        dt=varargin{2};
      case 'sta',
        stime=varargin{2};
	if length(stime)>1,
	  stime=[stime(:)' zeros(1,6-length(stime))];
	  stime=datenum(stime(1),stime(2),stime(3),stime(4),stime(5),stime(6));
	end;
      case 'lat',
         lat=varargin{2};
      case 'out',
         filen=varargin{2};
	 switch filen,
	   case 'none',
	     fid=-1;
	   case 'screen',
	     fid=1;
	   otherwise
	     [fid,mesg]=fopen(filen,'w');
	     if fid==-1, error(msg); end;
	  end;
      case 'ray',
         if isnumeric(varargin{2}),
           ray=varargin{2};
	 else
	   constitnames=varargin{2};
	   if iscellstr(constitnames), constitnames=char(constitnames); end;
	 end;
       case 'pre',
         corr_fs=varargin{2};
	 corr_fac=varargin{3};
         varargin(1)=[];
      case 'sec',
         secular=varargin{2};
      case 'inf',
         inf.iname=varargin{2};
	 inf.irefname=varargin{3};
	 inf.amprat=varargin{4};
	 inf.ph=varargin{5};
	 varargin(1:3)=[];
      case 'sha',
         shallownames=varargin{2};
      case 'err',
         errcalc=varargin{2};
      case 'syn',
         synth=varargin{2};
      case 'lsq',
         lsq=varargin{2};
      otherwise,
         error(['Can''t understand property:' varargin{1}]);
    end;
    varargin([1 2])=[];
  else
    switch k,
      case 1,
        dt=varargin{1};
      case 2,
        stime=varargin{1};
      case 3,
        lat=varargin{1};
      case 4,
        ray=varargin{1};
      otherwise
        error('Too many input parameters');
     end;
     varargin(1)=[];
  end;
  k=k+1;
end;

[inn,inm]=size(xin);
if ~(inn==1 | inm==1), error('Input time series is not a vector'); end;

xin=xin(:); % makes xin a column vector
nobs=length(xin);

if strcmp(lsq(1:3),'bes'),  % Set matrix method if auto-choice.
 if nobs>10000,
    lsq='normal';
 else
    lsq='direct';
 end;
end;

if nobs*dt> 18.6*365.25*24,  % Long time series
  longseries=1; ltype='full';
else
  longseries=0; ltype='nodal';
end;

nobsu=nobs-rem(nobs-1,2);% makes series odd to give a center point

t=dt*([1:nobs]'-ceil(nobsu/2));  % Time vector for entire time series,
                                 % centered at series midpoint.

if ~isempty(stime),
  centraltime=stime+floor(nobsu./2)./24.0*dt;
else
  centraltime=[];
end;

% -------Get the frequencies to use in the harmonic analysis-----------

[nameu,fu,ju,namei,fi,jinf,jref]=constituents(ray/(dt*nobsu),constitnames,...
                                           shallownames,inf.iname,inf.irefname,centraltime);

mu=length(fu); % # base frequencies
mi=length(fi); % # inferred

% Find the good data points (here I assume that in a complex time
% series, if u is bad, so is v).

gd=find(isfinite(xin(1:nobsu)));
ngood=length(gd);
fprintf('   Points used: %d of %d\n',ngood,nobs)

%----------------------------------------------------------------------
% Now solve for the secular trend plus the analysis. Instead of solving
% for + and - frequencies using exp(i*f*t), I use sines and cosines to
% keep tc real.  If the input series is real, than this will
% automatically use real-only computation (faster). However, for the analysis,
% it's handy to get the + and - frequencies ('ap' and 'am'), and so
% that's what we do afterwards.

% The basic code solves the matrix problem Ac=x+errors where the functions to
% use in the fit fill up the A matrix, which is of size (number points)x(number
% constituents). This can get very, very large for long time series, and
% for this the more complex block processing algorithm was added. It should
% give identical results (up to roundoff error)

if strcmp(lsq(1:3),'dir'),

  if secular(1:3)=='lin',
    tc=[ones(length(t),1) cos((2*pi)*t*fu') sin((2*pi)*t*fu') t*(2/dt/nobsu)];
  else
    tc=[ones(length(t),1) cos((2*pi)*t*fu') sin((2*pi)*t*fu') ];
  end;

  coef=tc(gd,:)\xin(gd);

  z0=coef(1);
  ap=(coef(2:(1+mu))-i*coef((2+mu):(1+2*mu)))/2;  % a+ amplitudes
  am=(coef(2:(1+mu))+i*coef((2+mu):(1+2*mu)))/2;  % a- amplitudes
  if secular(1:3)=='lin',
    dz0=coef(end);
  else
    dz0=0;
  end;
  xout=tc*coef;  % This is the time series synthesized from the analysis

else  % More complicated code required for long time series when memory may be
      % a problem. Modified from code submitted by Derek Goring (NIWA Chrischurch)

      % Basically the normal equations are formed (rather than using Matlab's \
      % algorithm for least squares); this can be done by adding up subblocks
      % of data. Notice how the code is messier, and we have to recalculate everything
      % to get the original fit.

  nsub=5000;  % Block length - doesn't matter really but should be small enough to
              % get allocated quickly
  if secular(1:3)=='lin',
    lhs=zeros(mu*2+2,mu*2+2); rhs=zeros(mu*2+2,1);
    for j1=1:nsub:ngood
      j2=min(j1 + nsub - 1,ngood);
      E=[ones(j2-j1+1,1) cos((2*pi)*t(gd(j1:j2))*fu') sin((2*pi)*t(gd(j1:j2))*fu') t(gd(j1:j2))*(2/dt/nobsu)];
      rhs=rhs + E'*xin(gd(j1:j2));
      lhs=lhs + E'*E;
    end;
  else
    lhs=zeros(mu*2+1,mu*2+1); rhs=zeros(mu*2+1,1);
    for j1=1:nsub:ngood
      j2=min(j1 + nsub - 1,ngood);
      E=[ones(j2-j1+1,1) cos((2*pi)*t(gd(j1:j2))*fu') sin((2*pi)*t(gd(j1:j2))*fu')];
      rhs=rhs + E'*xin(gd(j1:j2));
      lhs=lhs + E'*E;
    end;
  end;

  coef=lhs\rhs;

  z0=coef(1);
  ap=(coef(2:(1+mu))-i*coef((2+mu):(1+2*mu)))/2;  % a+ amplitudes
  am=(coef(2:(1+mu))+i*coef((2+mu):(1+2*mu)))/2;  % a- amplitudes
  if secular(1:3)=='lin',
    dz0=coef(end);
  else
    dz0=0;
  end;

  xout=xin; % Copies over NaN
  if secular(1:3)=='lin',
    for j1=1:nsub:nobs
      j2=min(j1 + nsub - 1,nobs);
      E=[ones(j2-j1+1,1) cos((2*pi)*t(j1:j2)*fu') sin((2*pi)*t(j1:j2)*fu') t(j1:j2)*(2/dt/nobsu)];
      xout(j1:j2)=E*coef;
    end;
  else
    for j1=1:nsub:nobs
      j2=min(j1 + nsub - 1,nobs);
      E=[ones(j2-j1+1,1) cos((2*pi)*t(j1:j2)*fu') sin((2*pi)*t(j1:j2)*fu')];
      xout(j1:j2)=E*coef;
    end;
  end;

end;

%----------------------------------------------------------------------
% Check variance explained (but do this with the original fit).

xres=xin-xout; % and the residuals!

if isreal(xin),    % Real time series
  varx=cov(xin(gd));varxp=cov(xout(gd));varxr=cov(xres(gd));
  fprintf('   percent of var residual after lsqfit/var original: %5.2f %%\n',100*(varxr/varx));
else               % Complex time series
  varx=cov(real(xin(gd)));varxp=cov(real(xout(gd)));varxr=cov(real(xres(gd)));
  fprintf('   percent of X var residual after lsqfit/var original: %5.2f %%\n',100*(varxr/varx));

  vary=cov(imag(xin(gd)));varyp=cov(imag(xout(gd)));varyr=cov(imag(xres(gd)));
  fprintf('   percent of Y var residual after lsqfit/var original: %5.2f %%\n',100*(varyr/vary));
end;

%---------- Correct for prefiltering-----------------------------------

corrfac=interp1(corr_fs,corr_fac,fu);
% To stop things blowing up!
corrfac(corrfac>100 | corrfac <.01 | isnan(corrfac))=1;

ap=ap.*corrfac;
am=am.*conj(corrfac);

%---------------Nodal Corrections--------------------------------------
% Generate nodal corrections and calculate phase relative to Greenwich.
% Note that this is a slightly weird way to do the nodal corrections,
% but is 'traditional'.  The "right" way would be to change the basis
% functions used in the least-squares fit above.

if ~isempty(lat) & ~isempty(stime),   % Time and latitude

  % Get nodal corrections at midpoint time.
  [v,u,f]=t_vuf(ltype,centraltime,[ju;jinf],lat);

  vu=(v+u)*360; % total phase correction (degrees)
  nodcor=['Greenwich phase computed with nodal corrections applied to amplitude \n and phase relative to center time'];
elseif ~isempty(stime),    % Time only
  % Get nodal corrections at midpoint time
  [v,u,f]=t_vuf(ltype,centraltime,[ju;jinf]);
  vu=(v+u)*360; % total phase correction (degrees)
  nodcor=['Greenwich phase computed, no nodal corrections'];
else   % No time, no latitude
  vu=zeros(length(ju)+length(jinf),1);
  f=ones(length(ju)+length(jinf),1);
   nodcor=['Phases at central time'];
end
fprintf(['   ',nodcor,'\n']);

%---------------Inference Corrections----------------------------------
% Once again, the "right" way to do this would be to change the basis
% functions.
ii=find(isfinite(jref));
if ii,
  fprintf('   Do inference corrections\n');
  snarg=nobsu*pi*(fi(ii)   -fu(jref(ii)) )*dt;
  scarg=sin(snarg)./snarg;

  if size(inf.amprat,2)==1,    % For real time series
    pearg=     2*pi*(vu(mu+ii)-vu(jref(ii))+inf.ph(ii))/360;
    pcfac=inf.amprat(ii).*f(mu+ii)./f(jref(ii)).*exp(i*pearg);
    pcorr=1+pcfac.*scarg;
    mcfac=conj(pcfac);
    mcorr=conj(pcorr);
  else                          % For complex time series
    pearg=     2*pi*(vu(mu+ii)-vu(jref(ii))+inf.ph(ii,1))/360;
    pcfac=inf.amprat(ii,1).*f(mu+ii)./f(jref(ii)).*exp(i*pearg);
    pcorr=1+pcfac.*scarg;
    mearg=    -2*pi*(vu(mu+ii)-vu(jref(ii))+inf.ph(ii,2))/360;
    mcfac=inf.amprat(ii,2).*f(mu+ii)./f(jref(ii)).*exp(i*mearg);
    mcorr=1+mcfac.*scarg;
  end;

  ap(jref(ii))=ap(jref(ii))./pcorr;   % Changes to existing constituents
  ap=[ap;ap(jref(ii)).*pcfac];        % Inferred constituents

  am(jref(ii))=am(jref(ii))./mcorr;
  am=[am;am(jref(ii)).*mcfac];

  fu=[fu;fi(ii)];
  nameu=[nameu;namei(ii,:)];
end;

% --------------Error Bar Calculations---------------------------------
%
% Error bar calcs involve two steps:
%      1) Estimate the uncertainties in the analyzed amplitude
%         for both + and - frequencies (i.e., in 'ap' and 'am').
%         A simple way of doing this is to take the variance of the
%         original time series and divide it into the amount appearing
%         in the bandwidth of the analysis (approximately 1/length).
%         A more sophisticated way is to assume "locally white"
%         noise in the vicinity of, e.g., the diurnal consistuents.
%         This takes into account slopes in the continuum spectrum.
%
%      2) Transform those uncertainties into ones suitable for ellipse
%         parameters (axis lengths, angles). This can be done
%         analytically for large signal-to-noise ratios. However, the
%         transformation is non-linear at lows SNR, say, less than 10
%         or so.
%

xr=fixgaps(xres); % Fill in "internal" NaNs with linearly interpolated
                  % values so we can fft things.
nreal=1;

if strmatch(errcalc(2:end),'boot'),
  fprintf('   Using nonlinear bootstrapped error estimates\n');

  % "noise" matrices are created with the right covariance structure
  % to add to the analyzed components to create 'nreal' REPLICATES.
  %

  nreal=300;             % Create noise matrices
  [NP,NM]=noise_realizations(xr(isfinite(xr)),fu,dt,nreal,errcalc);

  % All replicates are then transformed (nonlinearly) into ellipse
  % parameters.  The computed error bars are then based on the std
  % dev of the replicates.

  AP=ap(:,ones(1,nreal))+NP;        % Add to analysis (first column
  AM=am(:,ones(1,nreal))+NM;        % of NM,NP=0 so first column of
                                    % AP/M holds ap/m).
  epsp=angle(AP)*180/pi;            % Angle/magnitude form:
  epsm=angle(AM)*180/pi;
  ap=abs(AP);
  am=abs(AM);
elseif strmatch(errcalc,'linear'),
  fprintf('   Using linearized error estimates\n');
  %
  % Uncertainties in analyzed amplitudes are computed in different
  % spectral bands. Real and imaginary parts of the residual time series
  % are treated separately (no cross-covariance is assumed).
  %
  % Noise estimates are then determined from a linear analysis of errors,
  % assuming that everything is uncorrelated. This is OK for scalar time
  % series but can fail for vector time series if the noise is not
  % isotropic.

  [ercx,eicx]=noise_stats(xr(isfinite(xr)),fu,dt);
  % Note - here we assume that the error in the cos and sin terms is
  % equal, and equal to total power in the encompassing frequency bin.
  % It seems like there should be a factor of 2 here somewhere but it
  % only works this way! <shrug>
  [emaj,emin,einc,epha]=errell(ap+am,i*(ap-am),ercx,ercx,eicx,eicx);

  epsp=angle(ap)*180/pi;
  epsm=angle(am)*180/pi;
  ap=abs(ap);
  am=abs(am);
else
  error(['Unrecognized type of error analysis: ''' errcalc ''' specified!']);
end;

%-----Convert complex amplitudes to standard ellipse parameters--------

aap=ap./f(:,ones(1,nreal));	% Apply nodal corrections and
aam=am./f(:,ones(1,nreal));	% compute ellipse parameters.

fmaj=aap+aam;                   % major axis
fmin=aap-aam;                   % minor axis

gp=mod( vu(:,ones(1,nreal))-epsp ,360); % pos. Greenwich phase in deg.
gm=mod( vu(:,ones(1,nreal))+epsm ,360); % neg. Greenwich phase in deg.

finc= (epsp+epsm)/2;
finc(:,1)=mod( finc(:,1),180 ); % Ellipse inclination in degrees
				% (mod 180 to prevent ambiguity, i.e.,
				% we always ref. against northern
				% semi-major axis.

finc=cluster(finc,180); 	% Cluster angles around the 'true'
                                % angle to avoid 360 degree wraps.

pha=mod( gp+finc ,360); 	% Greenwich phase in degrees.

pha=cluster(pha,360);		% Cluster angles around the 'true' angle
				% to avoid 360 degree wraps.

%----------------Generate 95% CI---------------------------------------
%% For bootstrapped errors, we now compute limits of the distribution.
if strmatch(errcalc(2:end),'boot'),
     %% std dev-based estimates.
     % The 95% CI are computed from the sigmas
     % by a 1.96 fudge factor (infinite degrees of freedom).
     % emaj=1.96*std(fmaj,0,2);
     % emin=1.96*std(fmin,0,2);
     % einc=1.96*std(finc,0,2);
     % epha=1.96*std(pha ,0,2);
     %% Median-absolute-deviation (MAD) based estimates.
     % (possibly more stable?)
      emaj=median(abs(fmaj-median(fmaj,2)*ones(1,nreal)),2)/.6375*1.96;
      emin=median(abs(fmin-median(fmin,2)*ones(1,nreal)),2)/.6375*1.96;
      einc=median(abs(finc-median(finc,2)*ones(1,nreal)),2)/.6375*1.96;
      epha=median(abs( pha-median( pha,2)*ones(1,nreal)),2)/.6375*1.96;
else
   % In the linear analysis, the 95% CI are computed from the sigmas
   % by this fudge factor (infinite degrees of freedom).
   emaj=1.96*emaj;
   emin=1.96*emin;
   einc=1.96*einc;
   epha=1.96*epha;
end;

if isreal(xin),
    tidecon=[fmaj(:,1),emaj,pha(:,1),epha];
else
    tidecon=[fmaj(:,1),emaj,fmin(:,1),emin, finc(:,1),einc,pha(:,1),epha];
end;

% Sort results by frequency (needed if anything has been inferred since
% these are stuck at the end of the list by code above).
if any(isfinite(jref)),
 [fu,I]=sort(fu);
 nameu=nameu(I,:);
 tidecon=tidecon(I,:);
end;

snr=(tidecon(:,1)./tidecon(:,2)).^2;  % signal to noise ratio

%--------Generate a 'prediction' using significant constituents----------
xoutOLD=xout;
if synth>=0,
 if ~isempty(lat) & ~isempty(stime),
   fprintf('   Generating prediction with nodal corrections, SNR is %f\n',synth);
   xout=t_predic(stime+[0:nobs-1]*dt/24.0,nameu,fu,tidecon,'lat',lat,'synth',synth,'anal',ltype);
 elseif ~isempty(stime),
   fprintf('   Generating prediction without nodal corrections, SNR is %f\n',synth);
   xout=t_predic(stime+[0:nobs-1]*dt/24.0,nameu,fu,tidecon,'synth',synth,'anal',ltype);
 else
   fprintf('   Generating prediction without nodal corrections, SNR is %f\n',synth);
   xout=t_predic(t/24.0,nameu,fu,tidecon,'synth',synth,'anal',ltype);
 end;
else
 fprintf('   Returning fitted prediction\n');
end;

%----------------------------------------------------------------------
% Check variance explained (but now do this with the synthesized fit).
xres=xin(:)-xout(:); % and the residuals!

%error;

if isreal(xin),    % Real time series
  varx=cov(xin(gd));varxp=cov(xout(gd));varxr=cov(xres(gd));
  fprintf('   percent of var residual after synthesis/var original: %5.2f %%\n',100*(varxr/varx));
else               % Complex time series
  varx=cov(real(xin(gd)));varxp=cov(real(xout(gd)));varxr=cov(real(xres(gd)));
  fprintf('   percent of X var residual after synthesis/var original: %5.2f %%\n',100*(varxr/varx));

  vary=cov(imag(xin(gd)));varyp=cov(imag(xout(gd)));varyr=cov(imag(xres(gd)));
  fprintf('   percent of Y var residual after synthesis/var original: %5.2f %%\n',100*(varyr/vary));
end;

%-----------------Output results---------------------------------------

if fid>1,
 fprintf(fid,'\n%s\n',['file name: ',filen]);
elseif fid==1,
 fprintf(fid,'-----------------------------------\n');
end

if fid>0,
  fprintf(fid,'date: %s\n',date);
  fprintf(fid,'nobs = %d,  ngood = %d,  record length (days) = %.2f\n',nobs,ngood,length(xin)*dt/24);
  if ~isempty(stime); fprintf(fid,'%s\n',['start time: ',datestr(stime)]); end
  fprintf(fid,'rayleigh criterion = %.1f\n',ray);
  fprintf(fid,'%s\n',nodcor);
%  fprintf(fid,'\n     coefficients from least squares fit of x\n');
%  fprintf(fid,'\n tide    freq        |a+|       err_a+      |a-|       err_a-\n');
%  for k=1:length(fu);
%    if ap(k)>eap(k) | am(k)>eam(k), fprintf('*'); else fprintf(' '); end;
%    fprintf(fid,'%s  %8.5f  %9.4f  %9.4f  %9.4f  %9.4f\n',nameu(k,:),fu(k),ap(k),eap(k),am(k),eam(k));
%  end
  fprintf(fid,'\nx0= %.3g, x trend= %.3g\n',real(z0),real(dz0));
  fprintf(fid,['\nvar(x)= ',num2str(varx),'   var(xp)= ',num2str(varxp),'   var(xres)= ',num2str(varxr) '\n']);
  fprintf(fid,'percent var predicted/var original= %.1f %%\n',100*varxp/varx);

  if isreal(xin)
    fprintf(fid,'\n     tidal amplitude and phase with 95%% CI estimates\n');
    fprintf(fid,'\ntide   freq       amp     amp_err    pha    pha_err     snr\n');
    for k=1:length(fu);
      if snr(k)>synth, fprintf(fid,'*'); else fprintf(fid,' '); end;
      fprintf(fid,'%s %9.7f %9.4f %8.3f %8.2f %8.2f %8.2g\n',nameu(k,:),fu(k),tidecon(k,:),snr(k));
    end
  else
    fprintf(fid,'\ny0= %.3g, x trend= %.3g\n',imag(z0),imag(dz0));
    fprintf(fid,['\nvar(y)= ',num2str(vary),'    var(yp)= ',num2str(varyp),'  var(yres)= ',num2str(varyr) '\n']);
    fprintf(fid,'percent var predicted/var original= %.1f %%\n',100*varyp/vary);
    fprintf(fid,'\n%s\n',['ellipse parameters with 95%% CI estimates']);
    fprintf(fid,'\n%s\n',['tide   freq      major  emaj    minor   emin     inc    einc     pha    epha      snr']);
    for k=1:length(fu);
      if snr(k)>synth, fprintf(fid,'*'); else fprintf(fid,' '); end;
      fprintf(fid,'%s %9.7f %6.3f %7.3f %7.3f %6.2f %8.2f %6.2f %8.2f %6.2f %6.2g\n',...
	nameu(k,:),fu(k),tidecon(k,:),snr(k));
    end
    fprintf(fid,['\ntotal var= ',num2str(varx+vary),'   pred var= ',num2str(varxp+varyp) '\n']);
    fprintf(fid,'percent total var predicted/var original= %.1f %%\n\n',100*(varxp+varyp)/(varx+vary));
  end

  if fid~=1, st=fclose(fid); end
end;

xout=reshape(xout,inn,inm);
switch nargout,
  case {0,3,4}
  case {1}
   nameu = struct('name',nameu,'freq',fu,'tidecon',tidecon,'type',ltype);
  case {2}
   nameu = struct('name',nameu,'freq',fu,'tidecon',tidecon,'type',ltype);
   fu=xout;
end;

%----------------------------------------------------------------------
function [nameu,fu,ju,namei,fi,jinf,jref]=constituents(minres,constit,...
                                     shallow,infname,infref,centraltime);
% [name,freq,kmpr]=constituents(minres,infname) loads tidal constituent
% table (containing 146 constituents), then picks out only the '
% resolvable' frequencies (i.e. those that are MINRES apart), base on
% the comparisons in the third column of constituents.dat. Only
% frequencies in the 'standard' set of 69 frequencies are actually used.
% Also return the indices of constituents to be inferred.

% If we have the mat-file, read it in, otherwise create it and read
% it in!

% R Pawlowicz 9/1/01
% Version 1.0
%
%    19/1/02 - typo fixed (thanks to  Zhigang Xu)

% Compute frequencies from astronomical considerations.

if minres>1/(18.6*365.25*24),                       % Choose only resolveable pairs for short
  [const,sat,cshallow]=t_getconsts(centraltime);    % Time series
  ju=find(const.df>=minres);
else                                                % Choose them all if > 18.6 years.
  [const,sat,cshallow]=t_get18consts(centraltime);
  ju=[2:length(const.freq)]';  % Skip Z0
  for ff=1:2,                  % loop twice to make sure of neightbouring pairs
    jck=find(diff(const.freq(ju))<minres);
    if (length(jck)>0)
       jrm=jck;
       jrm=jrm+(abs(const.doodsonamp(ju(jck+1)))<abs(const.doodsonamp(ju(jck))));
       disp(['  Warning! Following constituent pairs violate Rayleigh criterion']);
       for ick=1:length(jck);
	 disp(['     ',const.name(ju(jck(ick)),:),' vs ',const.name(ju(jck(ick)+1),:) ' - not using ',const.name(ju(jrm(ick)),:)]);
       end;
       ju(jrm)=[];
    end
  end;
end;

if ~isempty(constit),     % Selected if constituents are specified in input.
  ju=[];
  for k=1:size(constit,1),
   j1=strmatch(constit(k,:),const.name);
   if isempty(j1),
     disp(['Can''t recognize name ' constit(k,:) ' for forced search']);
   elseif j1==1,
     disp(['*************************************************************************']);
     disp(['Z0 specification ignored - for non-tidal offsets see ''secular'' property']);
     disp(['*************************************************************************']);
   else
     ju=[ju;j1];
   end;
  end;
  [dum,II]=sort(const.freq(ju)); % sort in ascending order of frequency.
  ju=ju(II);
end;

disp(['   number of standard constituents used: ',int2str(length(ju))])

if ~isempty(shallow),          % Add explictly selected shallow water constituents.
 for k=1:size(shallow,1),
   j1=strmatch(shallow(k,:),const.name);
   if isempty(j1),
     disp(['Can''t recognize name ' shallow(k,:) ' for forced search']);
   else
     if isnan(const.ishallow(j1)),
       disp([shallow(k,:) ' Not a shallow-water constituent']);
     end;
     disp(['   Forced fit to ' shallow(k,:)]);
     ju=[ju;j1];
   end;
 end;

end;

nameu=const.name(ju,:);
fu=const.freq(ju);

% Check if neighboring chosen constituents violate Rayleigh criteria.
jck=find(diff(fu)<minres);
if (length(jck)>0)
   disp(['  Warning! Following constituent pairs violate Rayleigh criterion']);
   for ick=1:length(jck);
   disp(['     ',nameu(jck(ick),:),'  ',nameu(jck(ick)+1,:)]);
   end;
end

% For inference, add in list of components to be inferred.

fi=[];namei=[];jinf=[];jref=[];
if ~isempty(infname),
  fi=zeros(size(infname,1),1);
  namei=zeros(size(infname,1),4);
  jinf=zeros(size(infname,1),1)+NaN;
  jref=zeros(size(infname,1),1)+NaN;

  for k=1:size(infname,1),
   j1=strmatch(infname(k,:),const.name);
   if isempty(j1),
     disp(['Can''t recognize name' infname(k,:) ' for inference']);
   else
    jinf(k)=j1;
    fi(k)=const.freq(j1);
    namei(k,:)=const.name(j1,:);
    j1=strmatch(infref(k,:),nameu);
    if isempty(j1),
      disp(['Can''t recognize name ' infref(k,:) ' for as a reference for inference']);
    else
      jref(k)=j1;
      fprintf(['   Inference of ' namei(k,:) ' using ' nameu(j1,:) '\n']);
    end;
   end;
  end;
  jinf(isnan(jref))=NaN;
end;

%----------------------------------------------------------------------
function y=fixgaps(x);
% FIXGAPS: Linearly interpolates gaps in a time series
% YOUT=FIXGAPS(YIN) linearly interpolates over NaN in the input time
% series (may be complex), but ignores trailing and leading NaNs.

% R. Pawlowicz 11/6/99
% Version 1.0

y=x;

bd=isnan(x);
gd=find(~bd);

bd([1:(min(gd)-1) (max(gd)+1):end])=0;

y(bd)=interp1(gd,x(gd),find(bd));

%----------------------------------------------------------------------
function ain=cluster(ain,clusang);
% CLUSTER: Clusters angles in rows around the angles in the first
% column. CLUSANG is the allowable ambiguity (usually 360 degrees but
% sometimes 180).

ii=(ain-ain(:,ones(1,size(ain,2))))>clusang/2;
ain(ii)=ain(ii)-clusang;
ii=(ain-ain(:,ones(1,size(ain,2))))<-clusang/2;
ain(ii)=ain(ii)+clusang;

%----------------------------------------------------------------------
function [NP,NM]=noise_realizations(xres,fu,dt,nreal,errcalc);
% NOISE_REALIZATIONS: Generates matrices of noise (with correct
% cross-correlation structure) for bootstrap analysis.
%

% R. Pawlowicz 11/10/00
% Version 1.0

if strmatch(errcalc,'cboot'),
  [fband,Pxrave,Pxiave,Pxcave]=residual_spectrum(xres,fu,dt);

  Pxcave=zeros(size(Pxcave));  %% For comparison with other technique!
  %fprintf('**** Assuming no covariance between u and v errors!*******\n');

elseif strmatch(errcalc,'wboot'),
  fband=[0 .5];
  nx=length(xres);
  A=cov(real(xres),imag(xres))/nx;
  Pxrave=A(1,1);Pxiave=A(2,2);Pxcave=A(1,2);
else
  error(['Unrecognized type of bootstap analysis specified: ''' errcalc '''']);
end;

nfband=size(fband,1);

Mat=zeros(4,4,nfband);
for k=1:nfband,

  % The B matrix represents the covariance matrix for the vector
  % [Re{ap} Im{ap} Re{am} Im{am}]' where Re{} and Im{} are real and
  % imaginary parts, and ap/m represent the complex constituent
  % amplitudes for positive and negative frequencies when the input
  % is bivariate white noise. For a flat residual spectrum this works
  % fine.

  % This is adapted here for "locally white" conditions, but I'm still
  % not sure how to handle a complex sxy, so this is set to zero
  % right now.

  p=(Pxrave(k)+Pxiave(k))/2;
  d=(Pxrave(k)-Pxiave(k))/2;
  sxy=Pxcave(k);

  B=[p    0   d   sxy;
     0    p  sxy  -d;
     d   sxy  p    0
     sxy -d   0    p];

  % Compute the transformation matrix that takes uncorrelated white
  % noise and makes noise with the same statistical structure as the
  % Fourier transformed noise.
  [V,D]=eig(B);
  Mat(:,:,k)=V*diag(sqrt(diag(D)));
end;

% Generate realizations for the different analyzed constituents.

N=zeros(4,nreal);
NM=zeros(length(fu),nreal);
NP=NM;
for k=1:length(fu);
  l=find(fu(k)>fband(:,1) & fu(k)<fband(:,2));
  N=[zeros(4,1),Mat(:,:,l)*randn(4,nreal-1)];
  NP(k,:)=N(1,:)+i*N(2,:);
  NM(k,:)=N(3,:)+i*N(4,:);
end;

%----------------------------------------------------------------------
function [ercx,eicx]=noise_stats(xres,fu,dt);
% NOISE_STATS: Computes statistics of residual energy for all
% constituents (ignoring any cross-correlations between real and
% imaginary parts).

% S. Lentz  10/28/99
% R. Pawlowicz 11/1/00
% Version 1.0

[fband,Pxrave,Pxiave,Pxcave]=residual_spectrum(xres,fu,dt);
nfband=size(fband,1);
mu=length(fu);

% Get the statistics for each component.
ercx=zeros(mu,1);
eicx=zeros(mu,1);
for k1=1:nfband;
   k=find(fu>=fband(k1,1) & fu<=fband(k1,2));
   ercx(k)=sqrt(Pxrave(k1));
   eicx(k)=sqrt(Pxiave(k1));
end

%----------------------------------------------------------------------
function [fband,Pxrave,Pxiave,Pxcave]=residual_spectrum(xres,fu,dt)
% RESIDUAL_SPECTRUM: Computes statistics from an input spectrum over
% a number of bands, returning the band limits and the estimates for
% power spectra for real and imaginary parts and the cross-spectrum.
%
% Mean values of the noise spectrum are computed for the following
% 8 frequency bands defined by their center frequency and band width:
% M0 +.1 cpd; M1 +-.2 cpd; M2 +-.2 cpd; M3 +-.2 cpd; M4 +-.2 cpd;
% M5 +-.2 cpd; M6 +-.21 cpd; M7 (.26-.29 cpd); and M8 (.30-.50 cpd).

% S. Lentz  10/28/99
% R. Pawlowicz 11/1/00
% Version 1.0

% Define frequency bands for spectral averaging.
fband =[.00010 .00417;
        .03192 .04859;
        .07218 .08884;
        .11243 .12910;
        .15269 .16936;
        .19295 .20961;
        .23320 .25100;
        .26000 .29000;
        .30000 .50000];

% If we have a sampling interval> 1 hour, we might have to get
% rid of some bins.
%fband(fband(:,1)>1/(2*dt),:)=[];

nfband=size(fband,1);
nx=length(xres);

% Spectral estimate (takes real time series only).

% Matlab has changed their spectral estimator functions
% To match the old code, I have to divide by 2*dt. This is because
%
%  PSD*dt  is two-sided spectrum in units of power per hertz.
%
%  PWELCH is the one-sided spectrum in power per hertz
%
%  So PWELCH/2 = PSD*dt

%[Pxr,fx]=psd(real(xres),nx,1/dt); % Call to SIGNAL PROCESSING TOOLBOX - see note in t_readme. If you have an error here you are probably missing this toolbox
%[Pxi,fx]=psd(imag(xres),nx,1/dt); % Call to SIGNAL PROCESSING TOOLBOX - see note in t_readme.
%[Pxc,fx]=csd(real(xres),imag(xres),nx,1/dt); % Call to SIGNAL PROCESSING TOOLBOX - see note in t_readme.

[Pxr,fx]=pwelch(real(xres),hanning(nx),ceil(nx/2),nx,1/dt); % Call to SIGNAL PROCESSING TOOLBOX - see note in t_readme. If you have an error here you are probably missing this toolbox
Pxr=Pxr/2/dt;
[Pxi,fx]=pwelch(imag(xres),hanning(nx),ceil(nx/2),nx,1/dt); % Call to SIGNAL PROCESSING TOOLBOX - see note in t_readme.
Pxi=Pxi/2/dt;
[Pxc,fx]=cpsd(real(xres),imag(xres),[],[],nx,1/dt); % Call to SIGNAL PROCESSING TOOLBOX - see note in t_readme.
Pxc=Pxc/2/dt;

df=fx(3)-fx(2);
Pxr(round(fu./df)+1)=NaN ; % Sets Px=NaN in bins close to analyzed frequencies
Pxi(round(fu./df)+1)=NaN ; % (to prevent leakage problems?).
Pxc(round(fu./df)+1)=NaN ;

Pxrave=zeros(nfband,1);
Pxiave=zeros(nfband,1);
Pxcave=zeros(nfband,1);
% Loop downwards in frequency through bands (cures short time series
% problem with no data in lowest band).
%
% Divide by nx to get power per frequency bin, and multiply by 2
% to account for positive and negative frequencies.
%
for k=nfband:-1:1,
   jband=find(fx>=fband(k,1) & fx<=fband(k,2) & isfinite(Pxr));
   if any(jband),
     Pxrave(k)=mean(Pxr(jband))*2/nx;
     Pxiave(k)=mean(Pxi(jband))*2/nx;
     Pxcave(k)=mean(Pxc(jband))*2/nx;
   elseif k<nfband,
     Pxrave(k)=Pxrave(k+1);   % Low frequency bin might not have any points...
     Pxiave(k)=Pxiave(k+1);
     Pxcave(k)=Pxcave(k+1);
   end;
end

%----------------------------------------------------------------------
function [emaj,emin,einc,epha]=errell(cxi,sxi,ercx,ersx,ercy,ersy)
% [emaj,emin,einc,epha]=errell(cx,sx,cy,sy,ercx,ersx,ercy,ersy) computes
% the uncertainities in the ellipse parameters based on the
% uncertainities in the least square fit cos,sin coefficients.
%
%  INPUT:  cx,sx=cos,sin coefficients for x
%          cy,sy=cos,sin coefficients for y
%          ercx,ersx=errors in x cos,sin coefficients
%          ercy,ersy=errors in y cos,sin coefficients
%
%  OUTPUT: emaj=major axis error
%          emin=minor axis error
%          einc=inclination error (deg)
%          epha=pha error (deg)

% based on linear error propagation, with errors in the coefficients
% cx,sx,cy,sy uncorrelated.

% B. Beardsley  1/15/99; 1/20/99
% Version 1.0

r2d=180./pi;
cx=real(cxi(:));sx=real(sxi(:));cy=imag(cxi(:));sy=imag(sxi(:));
ercx=ercx(:);ersx=ersx(:);ercy=ercy(:);ersy=ersy(:);

rp=.5.*sqrt((cx+sy).^2+(cy-sx).^2);
rm=.5.*sqrt((cx-sy).^2+(cy+sx).^2);
ercx2=ercx.^2;ersx2=ersx.^2;
ercy2=ercy.^2;ersy2=ersy.^2;

% major axis error
ex=(cx+sy)./rp;
fx=(cx-sy)./rm;
gx=(sx-cy)./rp;
hx=(sx+cy)./rm;
dcx2=(.25.*(ex+fx)).^2;
dsx2=(.25.*(gx+hx)).^2;
dcy2=(.25.*(hx-gx)).^2;
dsy2=(.25.*(ex-fx)).^2;
emaj=sqrt(dcx2.*ercx2+dsx2.*ersx2+dcy2.*ercy2+dsy2.*ersy2);

% minor axis error
dcx2=(.25.*(ex-fx)).^2;
dsx2=(.25.*(gx-hx)).^2;
dcy2=(.25.*(hx+gx)).^2;
dsy2=(.25.*(ex+fx)).^2;
emin=sqrt(dcx2.*ercx2+dsx2.*ersx2+dcy2.*ercy2+dsy2.*ersy2);

% inclination error
rn=2.*(cx.*cy+sx.*sy);
rd=cx.^2+sx.^2-(cy.^2+sy.^2);
den=rn.^2+rd.^2;
dcx2=((rd.*cy-rn.*cx)./den).^2;
dsx2=((rd.*sy-rn.*sx)./den).^2;
dcy2=((rd.*cx+rn.*cy)./den).^2;
dsy2=((rd.*sx+rn.*sy)./den).^2;
einc=r2d.*sqrt(dcx2.*ercx2+dsx2.*ersx2+dcy2.*ercy2+dsy2.*ersy2);

% phase error
rn=2.*(cx.*sx+cy.*sy);
rd=cx.^2-sx.^2+cy.^2-sy.^2;
den=rn.^2+rd.^2;
dcx2=((rd.*sx-rn.*cx)./den).^2;
dsx2=((rd.*cx+rn.*sx)./den).^2;
dcy2=((rd.*sy-rn.*cy)./den).^2;
dsy2=((rd.*cy+rn.*sy)./den).^2;
epha=r2d.*sqrt(dcx2.*ercx2+dsx2.*ersx2+dcy2.*ercy2+dsy2.*ersy2);


text:
<?php
/**
 * DO NOT EDIT THIS FILE!
 *
 * This file was automatically generated from external sources.
 *
 * Any manual change here will be lost the next time the SDK
 * is updated. You've been warned!
 */

namespace DTS\eBaySDK\FileTransfer\Enums;

class ErrorCategory
{
    const C_APPLICATION = 'Application';
    const C_REQUEST = 'Request';
    const C_SYSTEM = 'System';
}

redpajama_set_name: RedPajamaGithub


text:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class FitbitRestClient : ManagerBehaviour<FitbitRestClient>
{

	public string DEBUG_USERID = "";
	public string DEBUG_TOKEN = "";

	private const string CLIENT_ID = "227FWT";
	private const string EXPIRED_TIME = "2592000";
	private const string LOGIN_API = "https://www.fitbit.com/oauth2/authorize";

	private const string TokenKey = "Token";
	private const string UserIDKey = "UserID";

	private const string ANDROID_URL = LOGIN_API + "?response_type=token&client_id="+ CLIENT_ID+ "&redirect_uri=fitachi%3A%2F%2Fcb&scope=activity%20nutrition%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight&expires_in=" + EXPIRED_TIME;
	private const string WIN_URL = LOGIN_API + "?response_type=token&client_id=" + CLIENT_ID + "&redirect_uri=http%3A%2F%2Fwww.fiea.ucf.edu&scope=activity%20nutrition%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight&expires_in=" + EXPIRED_TIME;

	private string mAccessToke = "";
	private string mUserId = "";

	private bool mIsLogin = false;
	public Fitbit.User.Profile Profile = new Fitbit.User.Profile();
	public Fitbit.Activity.Activities Activities = new Fitbit.Activity.Activities();
	public Fitbit.ActivitiesDaily.ActivitiesDaily ActivitiesDaily = new Fitbit.ActivitiesDaily.ActivitiesDaily();

	public bool IsLogin()
	{
		return mIsLogin;
	}

	public string GetUserId()
	{
		return mUserId;
	}

	public void SaveData(string token, string userID)
	{
		Debug.Log("Save.. " + token + " " + userID);
		PlayerPrefs.SetString(TokenKey, token);
		PlayerPrefs.SetString(UserIDKey, userID);
		PlayerPrefs.Save();
    }

	public IEnumerator LoadData()
	{
		try
		{
			AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
			AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
		} catch
		{
			mUserId = "";
			mAccessToke = "";
			mIsLogin = false;
			yield break;
		}

		mAccessToke = PlayerPrefs.GetString(TokenKey);
		mUserId = PlayerPrefs.GetString(UserIDKey);

		if (mAccessToke == "" || mUserId == "")
		{
			Debug.Log("Need to login");
			mIsLogin = false;
		}
		else
		{
			Debug.Log("Got catched id and token" + mUserId + " " + mAccessToke);

			// Validate the token, a very naive way...
			var headers = new Dictionary<string, string>();
			headers.Add("Authorization", "Bearer " + mAccessToke);
			var www = new WWW("https://api.fitbit.com/1/user/" + mUserId + "/profile.json", null, headers);

			yield return www;
			if (www.text.Contains("errors"))
			{
				Debug.Log(www.text);
				Debug.Log("Error token: " + mUserId + " " + mAccessToke);
				mIsLogin = false;
            } else
			{
				Profile = JsonUtility.FromJson<Fitbit.User.Profile>(www.text);
				mIsLogin = true;
				GetAll();
			}
		}
	}

	// Use this for initialization
	IEnumerator Start () {
        //PlayerPrefs.DeleteAll();
        // try get access toke from preference
        yield return LoadData();

		Debug.Log("ID: "+ GetHashCode());

		if (!mIsLogin) {

			string url = ANDROID_URL;
			try
			{
				AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
				AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
				Debug.Log("Login...");
				Application.OpenURL(url);
			}
			catch
			{
				url = WIN_URL;
				if (DEBUG_USERID != string.Empty && DEBUG_TOKEN != string.Empty) {
					mAccessToke = DEBUG_TOKEN;
					mUserId = DEBUG_USERID;

					SaveData(mAccessToke, mUserId);

					mIsLogin = true;
					GetAll();
				} else
				{
					Application.OpenURL(url);
				}
			}
		}
    }

	public Coroutine GetProfile()
	{
		return StartCoroutine(Instance.GetProfileInternal());
	}

	IEnumerator GetProfileInternal()
	{
        var headers = new Dictionary<string, string>();
		headers.Add("Authorization", "Bearer " + mAccessToke);
		var www = new WWW("https://api.fitbit.com/1/user/" + mUserId + "/profile.json", null, headers);

		yield return new WaitUntil(() => www.isDone);

		if (!www.text.Contains("errors"))
		{
			Debug.Log("DEBUG: " + www.text);
			Profile = JsonUtility.FromJson<Fitbit.User.Profile>(www.text);
			Debug.Log("DEBUG: " + JsonUtility.ToJson(Profile));
		}
    }

	public Coroutine GetActiviesLifeTimeState()
	{
		return StartCoroutine(Instance.GetActiviesLifeTimeStateInternal());
	}

	IEnumerator GetActiviesLifeTimeStateInternal()
	{
		var headers = new Dictionary<string, string>();
		headers.Add("Authorization", "Bearer " + mAccessToke);
		var www = new WWW("https://api.fitbit.com/1/user/" + mUserId + "/activities.json", null, headers);

		yield return new WaitUntil(() => www.isDone);

		if (!www.text.Contains("errors"))
		{
			Debug.Log("DEBUG: " + www.text);
			Activities = JsonUtility.FromJson<Fitbit.Activity.Activities>(www.text);
		}
	}

	public Coroutine GetActiviesDailyState(System.DateTime date)
	{
		return StartCoroutine(Instance.GetActiviesDailyStateInternal(date));
	}

	IEnumerator GetActiviesDailyStateInternal(System.DateTime date)
	{
		var headers = new Dictionary<string, string>();
		headers.Add("Authorization", "Bearer " + mAccessToke);
		var www = new WWW("https://api.fitbit.com/1/user/" + mUserId + "/activities/date/" + date.ToString("yyyy-MM-dd")+ ".json", null, headers);

		yield return new WaitUntil(() => www.isDone);

		if (!www.text.Contains("errors"))
		{
			Debug.Log("DEBUG: " + www.text);
			ActivitiesDaily = JsonUtility.FromJson<Fitbit.ActivitiesDaily.ActivitiesDaily>(www.text);
		}
	}

	// Update is called once per frame
	void Update () {

		if (!mIsLogin)
		{
			try
			{
				AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
				AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
                if (activity.Call<bool>("IsLogin"))
				{
					mAccessToke = activity.Call<string>("GetToken");
					mUserId = activity.Call<string>("GetUserId");
					// TODO Debug.Log(activity.Call<string>("GetExpires"));

					SaveData(mAccessToke, mUserId);

					mIsLogin = true;
					GetAll();
                }
			}
			catch
			{

			}
		}
	}

	private void GetAll()
	{
		GetProfile();
		GetActiviesLifeTimeState();
		GetActiviesDailyState(System.DateTime.Now);
	}
}


text:
package net.sf.mmm.client.ui.api.attribute;

/**
 * This interface gives read access to the {@link #isResizable() resizable} attribute of an object.
 *
 * @see AttributeWriteResizable
 *
 * @author Joerg Hohwiller (hohwille at users.sourceforge.net)
 * @since 1.0.0
 */
public abstract interface AttributeReadResizable {

  /**
   * This method determines if this object is resizable.
   *
   * @return true if the object can be
   *         {@link AttributeWriteSizeAdvanced#setSize(net.sf.mmm.client.ui.api.common.Length, net.sf.mmm.client.ui.api.common.Length)
   *         resized} (by the end-user), false otherwise.
   */
  boolean isResizable();

}


text:
/* You can add global styles to this file, and also import other style files */

body {
    height: 100vh;
}


text:
 'use strict';

function cdAcceptDojoUserInvitationCtrl($scope, $window, $state, $stateParams, $location, auth, cdDojoService, usSpinnerService, alertService, $translate) {
  var dojoId = $stateParams.dojoId;
  var inviteToken = $stateParams.userInviteToken;
  var currentPath = $location.path();

  auth.get_loggedin_user(function(user) {
    if($state.current.url === '/accept_dojo_user_invitation/:dojoId/:userInviteToken') {
      $window.location.href = '/dashboard' + currentPath;
    } else {

      usSpinnerService.spin('user-invitation-spinner');
      $scope.user = user;
      var tokenData = {dojoId:dojoId,
        inviteToken:inviteToken,
        currentUserEmail: $scope.user.email,
        currentUserId: $scope.user.id
      };

      cdDojoService.acceptUserInvite(tokenData, function (response) {
        usSpinnerService.stop('user-invitation-spinner');
        if(!response.error) {
          alertService.showAlert($translate.instant('Invitation Accepted'), function () {
            $state.go('my-dojos');
          });
        } else {
          alertService.showError($translate.instant('Invalid Invitation'), function () {
            $state.go('my-dojos');
          });
        }
      }, function (err) {
        usSpinnerService.stop('mentor-invitation-spinner');
        alertService.showError($translate.instant('Error accepting invitation'));
      });
    }

  }, function () {
    //Not logged in
    $state.go('register-account', {referer:$location.url()});
  });
}

angular.module('cpZenPlatform')
    .controller('accept-dojo-user-invitation-controller', ['$scope', '$window', '$state',
      '$stateParams', '$location', 'auth', 'cdDojoService',
      'usSpinnerService', 'alertService', '$translate', cdAcceptDojoUserInvitationCtrl]);


text:
package session

import (
	"errors"
	"net/http"

	"github.com/skygeario/skygear-server/pkg/auth/dependency/auth"
	"github.com/skygeario/skygear-server/pkg/core/time"
)

type ResolverProvider interface {
	GetByToken(token string) (*IDPSession, error)
	Update(session *IDPSession) error
}

type Resolver struct {
	CookieConfiguration CookieConfiguration
	Provider            ResolverProvider
	Time                time.Provider
}

func (re *Resolver) Resolve(rw http.ResponseWriter, r *http.Request) (auth.AuthSession, error) {
	cookie, err := r.Cookie(CookieName)
	if err != nil {
		// No cookie. Simply proceed.
		return nil, nil
	}

	session, err := re.Provider.GetByToken(cookie.Value)
	if err != nil {
		if errors.Is(err, ErrSessionNotFound) {
			err = auth.ErrInvalidSession
			re.CookieConfiguration.Clear(rw)
		}
		return nil, err
	}

	session.AccessInfo.LastAccess = auth.NewAccessEvent(re.Time.NowUTC(), r)
	if err = re.Provider.Update(session); err != nil {
		return nil, err
	}

	return session, nil
}


text:
package software.amazon.awssdk.buildtools.checkstyle;

import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.ScopeUtil;

/**
 * A rule that disallows unnecessary 'final' on local variables
 */
public class UnnecessaryFinalOnLocalVariableCheck extends AbstractCheck {

    @Override
    public int[] getDefaultTokens() {
        return getRequiredTokens();
    }

    @Override
    public int[] getAcceptableTokens() {
        return getRequiredTokens();
    }

    @Override
    public int[] getRequiredTokens() {
        return new int[] { TokenTypes.VARIABLE_DEF };
    }

    @Override
    public void visitToken(DetailAST ast) {
        if (ScopeUtil.isLocalVariableDef(ast) && ast.findFirstToken(TokenTypes.MODIFIERS)
                                                    .findFirstToken(TokenTypes.FINAL) != null) {
            log(ast, "final should be removed from local variable");
        }
    }
}


text:
package org.jboss.resteasy.annotations.providers.multipart;

import javax.ws.rs.core.MediaType;
import javax.xml.bind.annotation.XmlMimeType;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * This annotation can be used to process/produce incoming/outgoing XOP messages
 * (packaged as multipart/related) to/from JAXB annotated objects.
 *
 *

 * XOP packaging can be suitable if you have to work with binary content and you
 * don't want to encode it (for example in base64 or hex inside an xml). XOP
 * makes it possible to pass binary through the network without any encoding on
 * it (binary contents will travel in separate parts of the multipart/related
 * message).
 *

 *
 *

 * Example. A bean annotated with JAXB. {@link XmlMimeType} tells JAXB the mime
 * type of the binary content (its not required to do XOP packaging but it is
 * recommended to be set if you know the exact type):
 *
 *

 * @XmlRootElement
 * @XmlAccessorType(XmlAccessType.FIELD)
 * public static class Xop {
 *   private Customer bill;
 *
 *   private Customer monica;
 *
 *   @XmlMimeType(MediaType.APPLICATION_OCTET_STREAM)
 *   private byte[] myBinary;
 *
 *   @XmlMimeType(MediaType.APPLICATION_OCTET_STREAM)
 *   private DataHandler myDataHandler;
 *
 *   // methods, other fields ...
 * }
 *

 *
 * A REST Service method parameters/return value annotated with
 * {@link XopWithMultipartRelated} and consuming/producing
 * {@link MediaType#MULTIPART_RELATED}:
 *
 *

 * @PUT
 * @Path("xop")
 * @Consumes(MediaType.MULTIPART_RELATED)
 * public void putXopWithMultipartRelated(@XopWithMultipartRelated Xop xop) {}
 *

 *
 *

 *
 *

 * More about XOP can be read here: http://www.w3.org/TR/xop10
 *

 *
 * @author Attila Kiraly
 * @version $Revision: 1 $
 */
@Target( { ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface XopWithMultipartRelated {

}


text:
Registrar Producto

		<form class="form-horizontal" ng-submit="producto.registrar()" novalidate>

				ID del Producto

			      <input type="text" class="form-control" id="idproducto" name="idproducto" placeholder="Id de Producto" ng-model="producto.idProducto">

				Nombre

			      <input type="text" class="form-control" id="name" name="name" placeholder="Nombre" ng-model="producto.name">

				Categoria

			      	<select class="form-control" ng-options="data.idCategoria as data.nombreCategoria for (key , data) in producto.dataCategoria" ng-model="producto.categoria">
					</select>

				Compañia

			      	<select class="form-control" ng-options="data.idCompania as data.nombreCompania for (key , data) in producto.dataCompania" ng-model="producto.compania">
					</select>

			      <button type="submit" class="btn btn-success">Registrar</button>

		</form>

 0" ng-bind="producto.errorRegistrar">


text:
	// $Id: gzfilebuf.h 236 2009-02-03 13:25:19Z nicolabertoldi $

#ifndef _GZFILEBUF_H_
#define _GZFILEBUF_H_

#include <streambuf>
#include <cstring>
#include <zlib.h>
#include <iostream>

class gzfilebuf : public std::streambuf {
public:
  gzfilebuf(const char *filename)
  { _gzf = gzopen(filename, "rb");
    setg (_buff+sizeof(int),     // beginning of putback area
          _buff+sizeof(int),     // read position
          _buff+sizeof(int));    // end position
  }
  ~gzfilebuf() { gzclose(_gzf); }
protected:
  virtual int_type overflow (int_type /* unused parameter: c */) {
    std::cerr << "gzfilebuf::overflow is not implemented" << std::endl;;
      throw;
  }

  // write multiple characters
  virtual std::streamsize xsputn (const char* /* unused parameter: s */, std::streamsize /* unused parameter: num */) {
    std::cerr << "gzfilebuf::xsputn is not implemented" << std::endl;;
      throw;
  }

  virtual std::streampos seekpos ( std::streampos /* unused parameter: sp */, std::ios_base::openmode /* unused parameter: which */= std::ios_base::in | std::ios_base::out ){
    std::cerr << "gzfilebuf::seekpos is not implemented" << std::endl;;
	throw;
  }

  //read one character
  virtual int_type underflow () {
    // is read position before end of _buff?
        if (gptr() < egptr()) {
            return traits_type::to_int_type(*gptr());
        }

        /* process size of putback area
         * - use number of characters read
         * - but at most four
         */
        unsigned int numPutback = gptr() - eback();
        if (numPutback > sizeof(int)) {
            numPutback = sizeof(int);
        }

        /* copy up to four characters previously read into
         * the putback _buff (area of first four characters)
         */
        std::memmove (_buff+(sizeof(int)-numPutback), gptr()-numPutback,
                      numPutback);

        // read new characters
        int num = gzread(_gzf, _buff+sizeof(int), _buffsize-sizeof(int));
        if (num <= 0) {
            // ERROR or EOF
            return EOF;
        }

        // reset _buff pointers
        setg (_buff+(sizeof(int)-numPutback),   // beginning of putback area
              _buff+sizeof(int),                // read position
              _buff+sizeof(int)+num);           // end of buffer

        // return next character
        return traits_type::to_int_type(*gptr());
  }

  std::streamsize xsgetn (char* s,
                          std::streamsize num) {
    return gzread(_gzf,s,num);
  }

private:
  gzFile _gzf;
  static const unsigned int _buffsize = 1024;
  char _buff[_buffsize];
};

#endif


text:
namespace luabind
{
namespace detail
{
  namespace mpl = boost::mpl;

  template<class T, class ConverterGenerator>
  void push_aux(lua_State* L, T& value, ConverterGenerator*)
  {
      typedef typename boost::mpl::if_<
          boost::is_reference_wrapper<T>
        , BOOST_DEDUCED_TYPENAME boost::unwrap_reference<T>::type&
        , T
      >::type unwrapped_type;

      typename mpl::apply_wrap2<
          ConverterGenerator,unwrapped_type,cpp_to_lua
      >::type cv;

      cv.apply(
          L
        , boost::implicit_cast<
              BOOST_DEDUCED_TYPENAME boost::unwrap_reference<T>::type&
          >(value)
      );
  }

} // namespace detail

template<class T, class Policies>
void push(lua_State* L, T& value, Policies const&)
{
    typedef typename detail::find_conversion_policy<
        0
      , Policies
    >::type converter_policy;

    push_aux(L, value, static_cast<converter_policy*>(0));
}

template<class T>
void push(lua_State* L, T& value)
{
    push(L, value, detail::null_type());
}

namespace detail
{

  template<
      class T
    , class Policies
    , class ErrorPolicy
    , class ReturnType
  >
  ReturnType from_lua_aux(
      lua_State* L
    , int idx
    , T*
    , Policies*
    , ErrorPolicy*
    , ReturnType*
  )
  {
#ifndef LUABIND_NO_ERROR_CHECKING
      if (!L)
          return ErrorPolicy::handle_error(L, typeid(void));
#endif
      typedef typename detail::find_conversion_policy<
          0
        , Policies
      >::type converter_generator;

      typename mpl::apply_wrap2<converter_generator, T, lua_to_cpp>::type cv;

      if (cv.match(L, LUABIND_DECORATE_TYPE(T), idx) < 0)
      {
          return ErrorPolicy::handle_error(L, typeid(T));
      }

      return cv.apply(L, LUABIND_DECORATE_TYPE(T), idx);
  }

# ifdef BOOST_MSVC
#  pragma warning(push)
#  pragma warning(disable:4702) // unreachable code
# endif

  template<class T>
  struct throw_error_policy
  {
      static T handle_error(lua_State* L, type_id const& type_info)
      {
#ifndef LUABIND_NO_EXCEPTIONS
          throw cast_failed(L, type_info);
#else
          cast_failed_callback_fun e = get_cast_failed_callback();
          if (e) e(L, type_info);

          assert(0 && "object_cast failed. If you want to handle this error use "
              "luabind::set_error_callback()");
          std::terminate();
          return *(typename boost::remove_reference<T>::type*)0;
#endif
      }
  };

# ifdef BOOST_MSVC
#  pragma warning(pop)
# endif

  template<class T>
  struct nothrow_error_policy
  {
      static boost::optional<T> handle_error(lua_State*, type_id const&)
      {
          return boost::optional<T>();
      }
  };

} // namespace detail

template<class T, class Policies>
T from_lua(lua_State* L, int idx, Policies const&)
{
    return detail::from_lua_aux(
        L
      , idx
      , static_cast<T*>(0)
      , static_cast<Policies*>(0)
      , static_cast<detail::throw_error_policy<T>*>(0)
      , static_cast<T*>(0)
    );
}

template<class T>
T from_lua(lua_State* L, int idx)
{
    return from_lua<T>(L, idx, detail::null_type());
}

template<class T, class Policies>
boost::optional<T> from_lua_nothrow(lua_State* L, int idx, Policies const&)
{
    return detail::from_lua_aux(
        L
      , idx
      , static_cast<T*>(0)
      , static_cast<Policies*>(0)
      , static_cast<detail::nothrow_error_policy<T>*>(0)
      , static_cast<boost::optional<T>*>(0)
    );
}

template<class T>
boost::optional<T> from_lua_nothrow(lua_State* L, int idx)
{
    return from_lua_nothrow<T>(L, idx, detail::null_type());
}

} // namespace luabind

#endif // LUABIND_STACK_HPP_INCLUDED


text:
Collectif
Danse
  Rennes
 Métropole

	<button class="menu-button" id="open-button">
menu</button>


text:
package galvin.swing;

import galvin.dc.LanguageCode;
import java.awt.BorderLayout;
import javax.swing.JComboBox;

public class LanguageSelector
extends JComboBox
{
    private static LanguageCode[] codes;
    static
    {
        try
        {
            codes = LanguageCode.loadLanguageCodeArray();
        }
        catch( Throwable t )
        {
            codes = new LanguageCode[]
            {
                LanguageCode.ENGLISH,
                LanguageCode.ENGLISH_US,
                LanguageCode.ENGLISH_UK,
                LanguageCode.FRENCH,
                LanguageCode.SPANISH,
            };
            t.printStackTrace();
        }
    }

    public LanguageSelector()
    {
        super( codes );
        setSelectedItem( LanguageCode.ENGLISH_US );
    }

    @Override
    public LanguageCode getSelectedItem()
    {
        return (LanguageCode)super.getSelectedItem();
    }

    public void setSelectedItem( LanguageCode code )
    {
        if( code != null )
        {
            super.setSelectedItem( code );
        }
        else
        {
            super.setSelectedItem( LanguageCode.ENGLISH_US );
        }
    }

    public static void main( String[] args )
    {
        try
        {
            LanguageSelector selector = new LanguageSelector();
            ApplicationWindow window = new ApplicationWindow( "Languages" );
            window.getContentPane().setLayout( new BorderLayout() );
            window.getContentPane().add( selector, BorderLayout.CENTER );
            window.pack();
            window.center();
            window.setVisible( true );
        }
        catch( Throwable t )
        {
            t.printStackTrace();
        }
    }
}


text:
  && !defined(BOOST_ASIO_NO_EXCEPTIONS)
# include <exception>
# include <boost/asio/multiple_exceptions.hpp>
#endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
       // && !defined(BOOST_ASIO_NO_EXCEPTIONS)

#include <boost/asio/detail/push_options.hpp>

namespace boost {
namespace asio {
namespace detail {

class thread_info_base
  : private noncopyable
{
public:
  struct default_tag
  {
    enum { mem_index = 0 };
  };

  struct awaitable_frame_tag
  {
    enum { mem_index = 1 };
  };

  struct executor_function_tag
  {
    enum { mem_index = 2 };
  };

  thread_info_base()
#if defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR) \
  && !defined(BOOST_ASIO_NO_EXCEPTIONS)
    : has_pending_exception_(0)
#endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
       // && !defined(BOOST_ASIO_NO_EXCEPTIONS)
  {
    for (int i = 0; i < max_mem_index; ++i)
      reusable_memory_[i] = 0;
  }

  ~thread_info_base()
  {
    for (int i = 0; i < max_mem_index; ++i)
    {
      // The following test for non-null pointers is technically redundant, but
      // it is significantly faster when using a tight io_context::poll() loop
      // in latency sensitive applications.
      if (reusable_memory_[i])
        ::operator delete(reusable_memory_[i]);
    }
  }

  static void* allocate(thread_info_base* this_thread, std::size_t size)
  {
    return allocate(default_tag(), this_thread, size);
  }

  static void deallocate(thread_info_base* this_thread,
      void* pointer, std::size_t size)
  {
    deallocate(default_tag(), this_thread, pointer, size);
  }

  template <typename Purpose>
  static void* allocate(Purpose, thread_info_base* this_thread,
      std::size_t size)
  {
    std::size_t chunks = (size + chunk_size - 1) / chunk_size;

    if (this_thread && this_thread->reusable_memory_[Purpose::mem_index])
    {
      void* const pointer = this_thread->reusable_memory_[Purpose::mem_index];
      this_thread->reusable_memory_[Purpose::mem_index] = 0;

      unsigned char* const mem = static_cast<unsigned char*>(pointer);
      if (static_cast<std::size_t>(mem[0]) >= chunks)
      {
        mem[size] = mem[0];
        return pointer;
      }

      ::operator delete(pointer);
    }

    void* const pointer = ::operator new(chunks * chunk_size + 1);
    unsigned char* const mem = static_cast<unsigned char*>(pointer);
    mem[size] = (chunks <= UCHAR_MAX) ? static_cast<unsigned char>(chunks) : 0;
    return pointer;
  }

  template <typename Purpose>
  static void deallocate(Purpose, thread_info_base* this_thread,
      void* pointer, std::size_t size)
  {
    if (size <= chunk_size * UCHAR_MAX)
    {
      if (this_thread && this_thread->reusable_memory_[Purpose::mem_index] == 0)
      {
        unsigned char* const mem = static_cast<unsigned char*>(pointer);
        mem[0] = mem[size];
        this_thread->reusable_memory_[Purpose::mem_index] = pointer;
        return;
      }
    }

    ::operator delete(pointer);
  }

  void capture_current_exception()
  {
#if defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR) \
  && !defined(BOOST_ASIO_NO_EXCEPTIONS)
    switch (has_pending_exception_)
    {
    case 0:
      has_pending_exception_ = 1;
      pending_exception_ = std::current_exception();
      break;
    case 1:
      has_pending_exception_ = 2;
      pending_exception_ =
        std::make_exception_ptr<multiple_exceptions>(
            multiple_exceptions(pending_exception_));
      break;
    default:
      break;
    }
#endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
       // && !defined(BOOST_ASIO_NO_EXCEPTIONS)
  }

  void rethrow_pending_exception()
  {
#if defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR) \
  && !defined(BOOST_ASIO_NO_EXCEPTIONS)
    if (has_pending_exception_ > 0)
    {
      has_pending_exception_ = 0;
      std::exception_ptr ex(
          BOOST_ASIO_MOVE_CAST(std::exception_ptr)(
            pending_exception_));
      std::rethrow_exception(ex);
    }
#endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
       // && !defined(BOOST_ASIO_NO_EXCEPTIONS)
  }

private:
  enum { chunk_size = 4 };
  enum { max_mem_index = 3 };
  void* reusable_memory_[max_mem_index];

#if defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR) \
  && !defined(BOOST_ASIO_NO_EXCEPTIONS)
  int has_pending_exception_;
  std::exception_ptr pending_exception_;
#endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
       // && !defined(BOOST_ASIO_NO_EXCEPTIONS)
};

} // namespace detail
} // namespace asio
} // namespace boost

#include <boost/asio/detail/pop_options.hpp>

#endif // BOOST_ASIO_DETAIL_THREAD_INFO_BASE_HPP


text:
package org.apache.geode.internal.monitoring;

import static org.junit.Assert.assertTrue;

import org.apache.logging.log4j.Logger;
import org.junit.Test;

import org.apache.geode.logging.internal.log4j.api.LogService;

/**
 * Contains simple tests for the {@link org.apache.geode.internal.monitoring.ThreadsMonitoring}.
 *
 * @since Geode 1.5
 */
public class ThreadsMonitoringJUnitTest {

  public enum ModeExpected {
    FunctionExecutor,
    PooledExecutor,
    SerialQueuedExecutor,
    OneTaskOnlyExecutor,
    ScheduledThreadExecutor,
    AGSExecutor,
    P2PReaderExecutor,
    ServerConnectionExecutor,

    AsyncWriterExecutor
  }

  public final int numberOfElements = 9;
  private static final Logger logger = LogService.getLogger();

  /**
   * Tests that number of elements in ThreadMonitoring.Mode is correct
   */
  @Test
  public void testVerifyNumberOfElements() {
    assertTrue(ThreadsMonitoring.Mode.values().length == numberOfElements);
  }

  /**
   * Tests that type of elements in ThreadMonitoring.Mode is correct
   */
  @Test
  public void testVerifyTypeOfElements() {
    try {
      for (int i = 0; i < ThreadsMonitoring.Mode.values().length; i++) {
        assertTrue(
            ThreadsMonitoring.Mode.values()[i].name().equals(ModeExpected.values()[i].name()));
      }
    } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
      logger.error(
          "Please verify to update the test in case of changes in ThreadMonitoring.Mode enum\n",
          arrayIndexOutOfBoundsException);
      assertTrue(false);
    }
  }
}


text:
//
//  FBSession.h
//  feedback
//
//  Created by 宁金鹏 on 2017/2/20.
//  Copyright © 2017年 宁金鹏. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "FBMacros.h"

@interface FBSession : NSObject

/**
 *  会话ID,如果当前session为team,则sessionId为teamId,如果是P2P则为对方帐号
 */
@property (nonatomic,copy,readonly)         NSString *sessionId;

/**
 *  会话类型,当前仅支持P2P,Team和Chatroom
 */
@property (nonatomic,assign,readonly)       FBSessionType sessionType;

/**
 *  通过id和type构造会话对象
 *
 *  @param sessionId   会话ID
 *  @param sessionType 会话类型
 *
 *  @return 会话对象实例
 */
+ (instancetype)session:(NSString *)sessionId type:(FBSessionType)sessionType;

@end


text:
package com.kohoh.account_aid_demo;

import android.os.AsyncTask;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.kohoh.account_aid.base.AccountAidFactory;
import com.kohoh.account_aid.base.AccountAidFuture;
import com.kohoh.account_aid.base.IAccountAid;

public class ChangePasswordDemo extends ActionBarActivity {

    static public final String TAG = ChangePasswordDemo.class.getSimpleName();

    private IAccountAid accountAid;
    private TextView tv_auth_token;
    private ProgressBar pb_auth_token;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_password_demo);
        accountAid = AccountAidFactory.build(this);
        tv_auth_token = (TextView) findViewById(R.id.tv_auth_token);
        pb_auth_token = (ProgressBar) findViewById(R.id.pb_auth_token);
    }

    @Override
    protected void onResume() {
        nullPointVerify();

        super.onResume();
        if (!accountAid.isValidated()) {
            accountAid.verifing();
        } else {
            new AsyncTask(){
                @Override
                protected void onPreExecute() {
                    nullPointVerify();
                    toggleProgressBar();
                }

                @Override
                protected Object doInBackground(Object[] params) {
                    nullPointVerify();
                    AccountAidFuture<String> future = accountAid.getAuthToken("", ChangePasswordDemo.this, null);
                    String auth_token = future.getResult();
                    Log.v(TAG, "auth_token=" + auth_token);
                    return auth_token;
                }

                @Override
                protected void onPostExecute(Object o) {
                    String auth_token = (String) o;

                    nullPointVerify();
                    tv_auth_token.setText(auth_token);
                    toggleProgressBar();
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    public void bn_onClick_change_password(View view) {
        accountAid.changePassword();
    }

    private void nullPointVerify() {
        if (accountAid == null ) {
            Log.e(TAG, "空指针错误 accountAid=" + accountAid );
        }

        if ( tv_auth_token == null) {
            Log.e(TAG, "空指针错误 tv_auth_token=" + tv_auth_token);
        }

        if (pb_auth_token==null) {
            Log.e(TAG, "空指针错误 pb_auth_token=" + pb_auth_token);
        }
    }

    private void toggleProgressBar() {
        nullPointVerify();

        if (pb_auth_token.getVisibility() == View.GONE) {
            pb_auth_token.setVisibility(View.VISIBLE);
        } else {
            pb_auth_token.setVisibility(View.GONE);
        }

        if (tv_auth_token.getVisibility() == View.GONE) {
            tv_auth_token.setVisibility(View.VISIBLE);
        } else {
            tv_auth_token.setVisibility(View.GONE);
        }
    }

}


text:
import os
from PyQt5.QtWidgets import (QVBoxLayout, QHBoxLayout, QPushButton,
                             QRadioButton, QButtonGroup)
from .content import Content

class TypeOfTask(Content):

    def __init__(self, parent=None, button_func=None, params=None):
        super().__init__(parent, 'Task', params)

        self.button_func = button_func

        path = os.path.abspath(os.path.dirname(__file__)) + '/static/'

        # Text for machine learning tasks
        path1 = path + 'task'
        text = self.get_text(path1)
        if self.params.lang == 'en':
            self.set_paragraph('Type of task', text=text, img=path1)
        else:
            self.set_paragraph('分析タスク', text=text, img=path1)

        # Text for supervised learning
        path2 = path + 'supervised_learning'
        text = self.get_text(path2)
        if self.params.lang == 'en':
            self.set_paragraph('Supervised learning', text=text, img=path2)
        else:
            self.set_paragraph('教師あり学習', text=text, img=path2)

        if params.lang == 'jp':
            self.set_paragraph(
                'タスクの選択',
                text='あなたの機械学習のタスクを選択してください。')
        else:
            self.set_paragraph(
                'Task selection',
                text='Choose your machine learning task.')

        vbox1 = QVBoxLayout()
        vbox1.setContentsMargins(10, 10, 10, 10)
        vbox1.setSpacing(10)

        rbtn_cls = QRadioButton('Classification', self.inner)
        rbtn_cls.setStyleSheet('QRadioButton{font: 15pt;};')
        rbtn_cls.clicked.connect(self.rbtn_clicked)
        rbtn_reg = QRadioButton('Regression', self.inner)
        rbtn_reg.setStyleSheet('QRadioButton{font: 15pt;};')
        rbtn_reg.clicked.connect(self.rbtn_clicked)
        if params.task == 'Classification':
            rbtn_cls.setChecked(True)
        elif params.task == 'Regression':
            rbtn_reg.setChecked(True)

        self.btn_group = QButtonGroup()
        self.btn_group.addButton(rbtn_cls, 1)
        self.btn_group.addButton(rbtn_reg, 1)

        vbox1.addWidget(rbtn_cls)
        vbox1.addWidget(rbtn_reg)
        vbox1.addStretch(1)

        self.vbox.addLayout(vbox1)

        self.vbox.addStretch(1)

        self.btn = QPushButton('Next', self.inner)
        self.btn.setStyleSheet('QPushButton{font: bold; font-size: 15pt; background-color: white;};')
        if self.params.lang == 'en':
            self.btn.clicked.connect(lambda: self.button_func('Input data'))
        else:
            self.btn.clicked.connect(lambda: self.button_func('入力データ'))
        if params.task is None:
            self.btn.setEnabled(False)

        self.vbox.addWidget(self.btn)

    def rbtn_clicked(self):
        self.params.task = self.btn_group.checkedButton().text()
        self.btn.setEnabled(True)


text:
# Webinar: How the HPC Environment is Different from the Desktop (and Why)

- Date: 2016-07-14
- Location: Online
- Event Website: https://ideas-productivity.org/events/hpc-best-practices-webinars/#webinar005
- Organizers: The IDEAS Productivity Project

This event is a part of the "Best Practices for HPC Software
Developers" webinar series, produced by the IDEAS Productivity
Project. The HPC Best Practices webinars address issues faced by
developers of computational science and engineering (CSE) software on
high-performance computers (HPC) and occur approximately monthly.

Resource Information | Details
:--- | :---
Webinar Title | How the HPC Environment is Different from the Desktop (and Why)
Date and Time | 2016-07-14 02:00 pm EDT
Presenter | Katherine Riley (Argonne Leadership Comptuting Facility)
Registration, Information, and Archives | 	<https://ideas-productivity.org/events/hpc-best-practices-webinars/#webinar005>

**Webinars are free and open to the public, but advance registration is required through the Event website. Archives (recording, slides, Q&A) will be posted at the same link soon after the event.**

### Abstract

High performance computing has transformed how science and engineering
research is conducted.  Answering a question in 30 minutes that used
to take 6 months can quickly change the way one asks questions.  Large
computing facilities provide access to some of the world's largest
computing, data, and network resources in the world.  Indeed, the DOE
complex has the highest concentration of supercomputing capability in
the world.  However, by nature of their existence, making use of the
largest computers in the world can be a challenging and unique
task. This talk will discuss how supercomputers are unique and explain
how that impacts their use.

#### Contributed by Katherine Riley

#### Publication date: July 14, 2016


text:
<?php

namespace Ivory\Tests\Serializer\Fixture;

/**
 * @author GeLo <geloen.eric@gmail.com>
 */
class ExtendedScalarFixture extends ScalarFixture
{
}


text:
package com.faforever.client.util;

import com.faforever.client.domain.RatingHistoryDataPoint;
import com.faforever.client.player.Player;

public final class RatingUtil {

  private RatingUtil() {
    // Utility class
  }

  public static int roundRatingToNextLowest100(double rating) {
    double ratingToBeRounded = rating < 0 ? rating - 100 : rating;
    return (int) (ratingToBeRounded / 100) * 100;
  }

  public static int getRoundedGlobalRating(Player player) {
    return getRoundedRating(getGlobalRating(player));
  }

  public static int getRoundedRating(int rating) {
    return (rating + 50) / 100 * 100;
  }

  public static int getGlobalRating(Player playerInfo) {
    return getRating(playerInfo.getGlobalRatingMean(), playerInfo.getGlobalRatingDeviation());
  }

  public static int getRating(double ratingMean, double ratingDeviation) {
    return (int) (ratingMean - 3f * ratingDeviation);
  }

  public static int getLeaderboardRating(Player player) {
    return getRating(player.getLeaderboardRatingMean(), player.getLeaderboardRatingDeviation());
  }

  public static int getGlobalRating(com.faforever.client.remote.domain.Player player) {
    return getRating(player.getGlobalRating()[0], player.getGlobalRating()[1]);
  }

  public static int getLeaderboardRating(com.faforever.client.remote.domain.Player player) {
    return getRating(player.getLadderRating()[0], player.getLadderRating()[1]);
  }

  public static int getRating(RatingHistoryDataPoint datapoint) {
    return getRating(datapoint.getMean(), datapoint.getDeviation());
  }

  public static int getRating(Rating rating) {
    return getRating(rating.getMean(), rating.getDeviation());
  }
}