diff options
author | Shashank | 2017-05-29 12:40:26 +0530 |
---|---|---|
committer | Shashank | 2017-05-29 12:40:26 +0530 |
commit | 0345245e860375a32c9a437c4a9d9cae807134e9 (patch) | |
tree | ad51ecbfa7bcd3cc5f09834f1bb8c08feaa526a4 /modules/time/macros | |
download | scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.gz scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.bz2 scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.zip |
CMSCOPE changed
Diffstat (limited to 'modules/time/macros')
29 files changed, 762 insertions, 0 deletions
diff --git a/modules/time/macros/buildmacros.bat b/modules/time/macros/buildmacros.bat new file mode 100755 index 000000000..c4e35ec40 --- /dev/null +++ b/modules/time/macros/buildmacros.bat @@ -0,0 +1 @@ +@..\..\..\bin\scilex -nwni -ns -e exec('buildmacros.sce');quit;
\ No newline at end of file diff --git a/modules/time/macros/buildmacros.sce b/modules/time/macros/buildmacros.sce new file mode 100755 index 000000000..06666846d --- /dev/null +++ b/modules/time/macros/buildmacros.sce @@ -0,0 +1,12 @@ +//------------------------------------ +// Pierre MARECHAL +// Scilab team +// Copyright INRIA +// Date : décembre 2005 +//------------------------------------ +if (isdef("genlib") == %f) then + exec(SCI+"/modules/functions/scripts/buildmacros/loadgenlib.sce"); +end +//------------------------------------ +genlib("timelib","SCI/modules/time/macros",%f,%t); +//------------------------------------ diff --git a/modules/time/macros/calendar.bin b/modules/time/macros/calendar.bin Binary files differnew file mode 100755 index 000000000..72a400d49 --- /dev/null +++ b/modules/time/macros/calendar.bin diff --git a/modules/time/macros/calendar.sci b/modules/time/macros/calendar.sci new file mode 100755 index 000000000..0536a9302 --- /dev/null +++ b/modules/time/macros/calendar.sci @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - Allan CORNET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt +//------------------------------------------------------------------------ +function listcal = calendar(varargin) + lhs=argn(1); + rhs=argn(2); + + c=[0,0,0]; + + select rhs + case 0 + ct=getdate(); + c=[ct(1),ct(2),1] + break + case 2 + Y=varargin(1); + M=varargin(2); + if (size(Y) == [1,1]) & (size(M) == [1,1]) then + else + error(msprintf(gettext("%s: Wrong type for input arguments: Must be scalars.\n"),"calendar")); + end + if (M < 1) | (M > 12) then error(msprintf(gettext("%s: Wrong value for input argument: Must be between %d and %d.\n"),"calendar",1,12));,end + c=[Y,M,1]; + break + else + error(msprintf(gettext("%s: Wrong number of input arguments.\n"),"calendar")); + end + + + mths = [gettext("Jan"); .. + gettext("Feb"); .. + gettext("Mar"); .. + gettext("Apr"); .. + gettext("May"); .. + gettext("Jun"); .. + gettext("Jul"); .. + gettext("Aug"); .. + gettext("Sep"); .. + gettext("Oct"); .. + gettext("Nov"); .. + gettext("Dec")]; + + mth = mths(c(:,2),:); + cal=Calendar(c(1),c(2)); + listcal=list(sprintf("%s %d",mth,c(1)),gettext(" M Tu W Th F Sat Sun"),cal); +endfunction +//------------------------------------------------------------------------ diff --git a/modules/time/macros/cleanmacros.bat b/modules/time/macros/cleanmacros.bat new file mode 100755 index 000000000..5079dfd71 --- /dev/null +++ b/modules/time/macros/cleanmacros.bat @@ -0,0 +1,3 @@ +@del *.bin 2>NUL +@del lib 2>NUL +@del names 2>NUL
\ No newline at end of file diff --git a/modules/time/macros/clock.bin b/modules/time/macros/clock.bin Binary files differnew file mode 100755 index 000000000..13f6c29df --- /dev/null +++ b/modules/time/macros/clock.bin diff --git a/modules/time/macros/clock.sci b/modules/time/macros/clock.sci new file mode 100755 index 000000000..7e21bdfa4 --- /dev/null +++ b/modules/time/macros/clock.sci @@ -0,0 +1,16 @@ +//------------------------------------------------------------------------ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - Pierre MARECHAL +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +// Return the current date and time as serial number +//------------------------------------------------------------------------ + +function t=clock() + t=datevec(datenum()); +endfunction diff --git a/modules/time/macros/date.bin b/modules/time/macros/date.bin Binary files differnew file mode 100755 index 000000000..e509d1192 --- /dev/null +++ b/modules/time/macros/date.bin diff --git a/modules/time/macros/date.sci b/modules/time/macros/date.sci new file mode 100755 index 000000000..69adfe646 --- /dev/null +++ b/modules/time/macros/date.sci @@ -0,0 +1,25 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - Pierre MARECHAL +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +function s=date() + w=getdate(); + month=[gettext("Jan"), .. + gettext("Feb"), .. + gettext("Mar"), .. + gettext("Apr"), .. + gettext("May"), .. + gettext("Jun"), .. + gettext("Jul"), .. + gettext("Aug"), .. + gettext("Sep"), .. + gettext("Oct"), .. + gettext("Nov"), .. + gettext("Dec")]; + s = msprintf("%02d-%s-%04d",w(6),month(w(2)),w(1)); +endfunction diff --git a/modules/time/macros/datenum.bin b/modules/time/macros/datenum.bin Binary files differnew file mode 100755 index 000000000..4fbfe8dfa --- /dev/null +++ b/modules/time/macros/datenum.bin diff --git a/modules/time/macros/datenum.sci b/modules/time/macros/datenum.sci new file mode 100755 index 000000000..8aaa7b3b5 --- /dev/null +++ b/modules/time/macros/datenum.sci @@ -0,0 +1,192 @@ +//------------------------------------------------------------------------ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - Pierre MARECHAL +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +// +// Convert to serial date number +//------------------------------------------------------------------------ + +function n=datenum(varargin) + + lhs=argn(1); + rhs=argn(2); + + select rhs + case 0 + Date = getdate(); + + n = ymdhmns_to_scalar(Date(1),.. + Date(2),.. + Date(6),.. + Date(7),.. + Date(8),.. + Date(9)); + + break + + case 1 + + DateIn = varargin(1); + + // Checks + + if type(DateIn)<> 1 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: Real matrix expected.\n"),"datenum",1)); + end + + [nr,nc] = size(DateIn); + + if (nc <> 3) & (nc <> 6) then + error(msprintf(gettext("%s: Wrong size for input argument #%d: m*3 matrix or a m*6 matrix expected.\n"),"datenum",1)); + end + + if min(DateIn(:,2))<1 | max(DateIn(:,2))>12 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: %s must be between %d and %d.\n"),"datenum",1,gettext("Month"),1,12)); + end + + if min(DateIn(:,3))<1 | max(DateIn(:,3))>31 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: %s must be between %d and %d.\n"),"datenum",1,gettext("Day"),1,31)); + end + + if nc == 6 then + + if min(DateIn(:,4))<0 | max(DateIn(:,4))>23 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: %s must be between %d and %d.\n"),"datenum",1,gettext("Hour"),0,23)); + end + + if min(DateIn(:,5))<0 | max(DateIn(:,5))>59 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: %s must be between %d and %d.\n"),"datenum",1,gettext("Minute"),0,59)); + end + + if min(DateIn(:,6))<0 | max(DateIn(:,6))>=60 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: %s must be between %d and %d.\n"),"datenum",1,gettext("Second"),0,59)); + end + + end + + if nc == 3 then + n = ymdhmns_to_scalar(DateIn(:,1),DateIn(:,2),DateIn(:,3),zeros(nr),zeros(nr),zeros(nr)); + else + n = ymdhmns_to_scalar(DateIn(:,1),DateIn(:,2),DateIn(:,3),DateIn(:,4),DateIn(:,5),DateIn(:,6)); + end + break + + case 3 + + YearIn = varargin(1); + MonthIn = varargin(2); + DayIn = varargin(3); + + // checks + + if (type(YearIn)<> 1) | (type(MonthIn)<> 1) | (type(DayIn)<> 1) then + error(msprintf(gettext("%s: Wrong type for input arguments.\n"),"datenum")); + end + + if (size(YearIn) <> size(MonthIn)) | (size(YearIn) <> size(DayIn)) then + error(msprintf(gettext("%s: Wrong size for input arguments: Same size expected.\n"),"datenum")); + end + + if min(MonthIn)<1 | max(MonthIn)>12 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"),"datenum",2,1,12)); + end + + if min(DayIn)<1 | max(DayIn)>31 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"),"datenum",3,1,31)); + end + + [nr,nc] = size(YearIn); + n = ymdhmns_to_scalar(YearIn,MonthIn,DayIn,zeros(nr,nc),zeros(nr,nc),zeros(nr,nc)); + + break + + case 6 + + YearIn = varargin(1); + MonthIn = varargin(2); + DayIn = varargin(3); + HourIn = varargin(4); + MinIn = varargin(5); + SecIn = varargin(6); + + // checks + + if (type(YearIn) <> 1) | .. + (type(MonthIn)<> 1) | .. + (type(DayIn) <> 1) | .. + (type(HourIn) <> 1) | .. + (type(MinIn) <> 1) | .. + (type(SecIn) <> 1) then + error(msprintf(gettext("%s: Wrong type for input arguments.\n"),"datenum")); + end + + if (size(YearIn) <> size(MonthIn)) | .. + (size(YearIn) <> size(DayIn)) | .. + (size(YearIn) <> size(HourIn)) | .. + (size(YearIn) <> size(MinIn)) | .. + (size(YearIn) <> size(SecIn)) then + error(msprintf(gettext("%s: Wrong size for input arguments: Same size expected.\n"),"datenum")); + end + + if min(MonthIn)<1 | max(MonthIn)>12 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"),"datenum",2,1,12)); + end + + if min(DayIn)<1 | max(DayIn)>31 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"),"datenum",3,1,31)); + end + + if min(HourIn)<0 | max(HourIn)>23 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"),"datenum",4,0,23)); + end + + if min(MinIn)<0 | max(MinIn)>59 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"),"datenum",5,0,59)); + end + + if min(SecIn)<0 | max(SecIn)>=60 then + error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"),"datenum",6,0,59)); + end + + n = ymdhmns_to_scalar(YearIn,MonthIn,DayIn,HourIn,MinIn,SecIn); + + break + else + error(msprintf(gettext("%s: Wrong number of input argument.\n"),"datenum")); + end + + +endfunction + + +function scalaire=ymdhmns_to_scalar (annee,mois,jour,heure,mn,seconde) + + decimal_part = (seconde*(1/(24*3600)))+(mn*(1/(24*60)))+(heure*(1/24)); + + // convert of month and day + integer_part = jour + floor((mois * 3057 - 3007) / 100); + + // On retranche 1 si le mois est au dela de février + integer_part = integer_part + ((mois < 3) - 1); + + // On retranche encore 1 si le mois est au dela de février et année non bissextile + integer_part = integer_part + (((mois < 3)|(isLeapYear(annee))) -1); + + // Convertion des année + leap_year_case = annee * 365 + (annee / 4) - floor(annee / 100) + floor(annee / 400); + not_leap_year_case = annee * 365 + floor(annee/4) + 1 - floor(annee / 100) + floor(annee / 400); + + leap_year_case(~isLeapYear(annee)) = 0; + not_leap_year_case(isLeapYear(annee)) = 0; + + integer_part = integer_part + leap_year_case + not_leap_year_case; + + scalaire = integer_part+decimal_part; + +endfunction diff --git a/modules/time/macros/datevec.bin b/modules/time/macros/datevec.bin Binary files differnew file mode 100755 index 000000000..e99aabad2 --- /dev/null +++ b/modules/time/macros/datevec.bin diff --git a/modules/time/macros/datevec.sci b/modules/time/macros/datevec.sci new file mode 100755 index 000000000..a847ff2c0 --- /dev/null +++ b/modules/time/macros/datevec.sci @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - Pierre MARECHAL +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +// Copyright INRIA +// Date : 28 Dec 2005 +//------------------------------------------------------------------------ + +function [Y,M,D,h,m,s] = datevec(N) + + lhs=argn(1); + rhs=argn(2); + + common_year = [0,31,59,90,120,151,181,212,243,273,304,334,365]; + leap_year = [0,31,60,91,121,152,182,213,244,274,305,335,366]; + + if rhs<>1 then + error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"datevec",1)); + end + + if type(N) <> 1 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: Real matrix expected.\n"),"datevec",1)); + end + + [nr,nc] = size(N); + + if nc == 1 then + common_year = common_year'; + leap_year = leap_year'; + end + + // for the moment : hour, minute, second + // ========================================================================= + + second = 86400*(N-floor(N)); + hour = floor(second/3600); + second = second - 3600*hour; + minute = floor(second/60); + second = second - 60*minute; + + // Now, the year + // ========================================================================= + + N = floor(N); + Year = floor(N/365.2425); + + temp = N - (365.0*Year + ceil(0.25*Year)- ceil(0.01*Year) + ceil(0.0025*Year)); + + // On retranche 1 si la valeur est inferieur à 0 + + mask = (temp <= 0); + Year(mask) = Year(mask)-1; + + N(mask) = N(mask) - (365.0*Year(mask) + ceil(0.25*Year(mask)) - ceil(0.01*Year(mask)) + ceil(0.0025*Year(mask))); + N(~mask) = temp(~mask); + + // ... and the month + // ========================================================================= + + Month = int (N/29); + + // construction de la matrice + + month_day_mat = ones(nr,nc); + + month_day_mat(isLeapYear(Year)) = leap_year(Month(isLeapYear(Year))+1); + month_day_mat(~isLeapYear(Year)) = common_year(Month(~isLeapYear(Year))+1); + + Month( N>month_day_mat ) = Month( N>month_day_mat )+1; + + Day = ones(nr,nc); + + month_day_mat(isLeapYear(Year)) = leap_year(Month(isLeapYear(Year))); + month_day_mat(~isLeapYear(Year)) = common_year(Month(~isLeapYear(Year))); + + Day = N - month_day_mat; + + if (lhs==1) then + Y(:,1) = matrix(Year ,nr*nc , 1); + Y(:,2) = matrix(Month ,nr*nc , 1); + Y(:,3) = matrix(Day ,nr*nc , 1); + Y(:,4) = matrix(hour ,nr*nc , 1); + Y(:,5) = matrix(minute,nr*nc , 1); + Y(:,6) = matrix(second,nr*nc , 1); + else + Y = Year; + M = Month; + D = Day; + h = hour; + m = minute; + s = second; + end + +endfunction diff --git a/modules/time/macros/eomday.bin b/modules/time/macros/eomday.bin Binary files differnew file mode 100755 index 000000000..d5c31583c --- /dev/null +++ b/modules/time/macros/eomday.bin diff --git a/modules/time/macros/eomday.sci b/modules/time/macros/eomday.sci new file mode 100755 index 000000000..9429159b2 --- /dev/null +++ b/modules/time/macros/eomday.sci @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------------------------------------ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - Pierre MARECHAL +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +// +// Returns the last day of the year and month by corresponding element of Matrix Y and M +//------------------------------------------------------------------------------------------------------------ + +function E=eomday(Y,M) + + rhs=argn(2); + + if rhs <> 2 then + error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"eomday", 2)); + end + + common_year = [31,28,31,30,31,30,31,31,30,31,30,31]; + leap_year = [31,29,31,30,31,30,31,31,30,31,30,31]; + + if type(Y) <> 1 | ~isreal(Y) | int(Y) <> Y then + error(msprintf(gettext("%s: Wrong value for input argument #%d: An integer value expected.\n"), "eomday", 1)); + end + + if type(M) <> 1 | ~isreal(M) | int(M) <> M then + error(msprintf(gettext("%s: Wrong value for input argument #%d: An integer value expected.\n"), "eomday", 2)) + end + + if or(size(Y) <> size(M)) then + error(msprintf(gettext("%s: Wrong size for input arguments #%d and #%d: Same sizes expected.\n"),"eomday", 1, 2)); + end + + if (min(M) < 1) | (max(M) > 12) then + error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"),"eomday",2,1,12)); + end + + [nr,nc] = size(M); + E = zeros(1, nr*nc); + isleapyear = isLeapYear(Y); + E(isleapyear) = leap_year(M(isleapyear)); + E(~isleapyear) = common_year(M(~isleapyear)); + E = matrix(E,nr,nc); + +endfunction diff --git a/modules/time/macros/etime.bin b/modules/time/macros/etime.bin Binary files differnew file mode 100755 index 000000000..b0b677484 --- /dev/null +++ b/modules/time/macros/etime.bin diff --git a/modules/time/macros/etime.sci b/modules/time/macros/etime.sci new file mode 100755 index 000000000..f2493f4f3 --- /dev/null +++ b/modules/time/macros/etime.sci @@ -0,0 +1,91 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - Vincent Couvert +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +function t=etime(t1,t0) + + // returns the time in seconds that has elapsed between vectors t1 and t0 + // t1 and t0 must be six elements long, in the format: + // t = [Year Month Day Hour Minute Second.Milliseconds] + // or, 10 elements long, in the format returned by getdate() + // t = [Year Month ISO_8601_week_number Julian_day Week_Day Day Hour Minute Second Millisecond] + // in this case ISO_8601_week_number Julian_day Week_Day are ignored + // t1 and t0 can also be matrices having each line equal to a vector described above + + + if type(t1)<>1 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: Real vector expected.\n"),"etime",1)); + end + if type(t0)<>1 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: Real vector expected.\n"),"etime",2)); + end + if and(size(t1,2)<>[6,10]) then + error(msprintf(gettext("%s: Wrong size for input argument #%d: Must be between %d and %d.\n"),"etime",1,6,10)); + end + if and(size(t0,2)<>[6,10]) then + error(msprintf(gettext("%s: Wrong size for input argument #%d: Must be between %d and %d.\n"),"etime",2,6,10)); + end + + if size(t1,"*")<>size(t0,"*") then + error(msprintf(gettext("%s: Wrong size for input arguments #%d and #%d: Same size expected.\n"),"etime"), 1, 2); + end + + if size(t1,2)==10 then + t1(:,3:5)=[] + end + if size(t0,2)==10 then + t0(:,3:5)=[] + end + + // Cumulative days per month in a nonleap year + cdm = [0,31,59,90,120,151,181,212,243,273,304,334] + + t=0 + + for k=1:2 + if k==1 then + tcur=t1 + else + tcur=t0 + end + + Year=tcur(:,1) + Month=tcur(:,2) + Day=tcur(:,3) + + // Make sure month is in the range 1 to 12 + Month(Month<1)=1 + for kM=1:size(Month,"*") + if Month(kM) > 12 then + Year(kM) = Year(kM) + (Month(kM)-1)/12; + Month(kM) = fix((Month(kM)-1) / 12) + 1; + end + CDM=cdm(Month(kM)) + end + + tsec = 365.*Year + ceil(Year/4) - ceil(Year/100) + ceil(Year/400) + CDM + Day; + + for kM=1:size(Month,"*") + if Month > 2 then + iy=fix(Year) + if fix(iy/4).*4 == iy & fix(iy/100).*100 <> iy | fix(iy/400).*400 == iy then + tsec = tsec+1; + end + end + end + if k==1 then + t=tsec + else + t=t-tsec + end + end + t=86400*t+t1(:,4)*3600-t0(:,4)*3600+t1(:,5)*60-t0(:,5)*60+t1(:,6)-t0(:,6) + if size(t1,2)==7 then + t=t+(t1(:,7)-t0(:,7))*1e-3 + end +endfunction diff --git a/modules/time/macros/isLeapYear.bin b/modules/time/macros/isLeapYear.bin Binary files differnew file mode 100755 index 000000000..a5d13697c --- /dev/null +++ b/modules/time/macros/isLeapYear.bin diff --git a/modules/time/macros/isLeapYear.sci b/modules/time/macros/isLeapYear.sci new file mode 100755 index 000000000..947c12677 --- /dev/null +++ b/modules/time/macros/isLeapYear.sci @@ -0,0 +1,28 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - Pierre MARECHAL +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +// Return True if year is a leap year, otherwise False + +// Si l'année est divisible par 4 et non par 100 => Année bissextile +// Si l'année est divisible par 400 => Année bissextile +// ============================================================================= + +function Rep=isLeapYear(year) + + lhs=argn(1); + rhs=argn(2); + + if rhs==1 & type(year)==1 then + Rep = ((modulo(year,100)<>0) & (modulo(year,4)==0)) | (modulo(year,400)== 0); + else + error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"isLeapYear",1)); + end + +endfunction diff --git a/modules/time/macros/lib b/modules/time/macros/lib Binary files differnew file mode 100755 index 000000000..68d0fc616 --- /dev/null +++ b/modules/time/macros/lib diff --git a/modules/time/macros/names b/modules/time/macros/names new file mode 100755 index 000000000..2e56d6fcc --- /dev/null +++ b/modules/time/macros/names @@ -0,0 +1,12 @@ +calendar +clock +date +datenum +datevec +eomday +etime +isLeapYear +now +tic +toc +weekday diff --git a/modules/time/macros/now.bin b/modules/time/macros/now.bin Binary files differnew file mode 100755 index 000000000..eb02c1994 --- /dev/null +++ b/modules/time/macros/now.bin diff --git a/modules/time/macros/now.sci b/modules/time/macros/now.sci new file mode 100755 index 000000000..eb94fc9cc --- /dev/null +++ b/modules/time/macros/now.sci @@ -0,0 +1,17 @@ +//------------------------------------------------------------------------ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - Pierre MARECHAL +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +// +// Return the current date and time as serial number +//------------------------------------------------------------------------ + +function t=now() + t=datenum(); +endfunction diff --git a/modules/time/macros/tic.bin b/modules/time/macros/tic.bin Binary files differnew file mode 100755 index 000000000..ce75882fb --- /dev/null +++ b/modules/time/macros/tic.bin diff --git a/modules/time/macros/tic.sci b/modules/time/macros/tic.sci new file mode 100755 index 000000000..ca4c81c95 --- /dev/null +++ b/modules/time/macros/tic.sci @@ -0,0 +1,20 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - V.C & A.C +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +function tic() + // tic() start a stopwatch timer. + // The sequence of commands tic(), operation, toc() + // prints the number of milliseconds required for the operation. + + + global TICTOC; + + TICTOC=getdate(); + +endfunction diff --git a/modules/time/macros/toc.bin b/modules/time/macros/toc.bin Binary files differnew file mode 100755 index 000000000..72bfd4d8d --- /dev/null +++ b/modules/time/macros/toc.bin diff --git a/modules/time/macros/toc.sci b/modules/time/macros/toc.sci new file mode 100755 index 000000000..1ebbb61b6 --- /dev/null +++ b/modules/time/macros/toc.sci @@ -0,0 +1,24 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - V.C , A.C +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +function tictoctime=toc() + + // toc() read the stopwatch timer. + // toc(), by itself, prints the elapsed time (in milliseconds) since tic() was used. + + + global TICTOC; + + if isempty(TICTOC) then + error(msprintf(gettext("%s: You must call tic() before calling toc().\n"),"toc")); + end + + tictoctime=etime(getdate(),TICTOC); + +endfunction diff --git a/modules/time/macros/weekday.bin b/modules/time/macros/weekday.bin Binary files differnew file mode 100755 index 000000000..8e02771c0 --- /dev/null +++ b/modules/time/macros/weekday.bin diff --git a/modules/time/macros/weekday.sci b/modules/time/macros/weekday.sci new file mode 100755 index 000000000..1855c1f7a --- /dev/null +++ b/modules/time/macros/weekday.sci @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2005 - INRIA - Pierre MARECHAL +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +// +// Return day of week +// Maurice Kraitchik Algorithm +//------------------------------------------------------------------------ + +function [N,S] = weekday(D,form) + + lhs=argn(1); + rhs=argn(2); + + // checkings + + if rhs < 1 | rhs > 2 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"),"weekday",1,2)); + end + + if type(D) <> 1 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: Real constant matrix expected.\n"),"weekday",1)); + end + + if (rhs==2) & (form <> "long") & (form <> "short") then + error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"),"weekday",2,"long","short")); + end + + // some definitions + + common_year = [0,31,59,90,120,151,181,212,243,273,304,334,365]; + leap_year = [0,31,60,91,121,152,182,213,244,274,305,335,366]; + week_numbers = [7,1,2,3,4,5,6]; + + week_strings_short = [gettext("Sat"), .. + gettext("Sun"), .. + gettext("Mon"), .. + gettext("Tue"), .. + gettext("Wed"), .. + gettext("Thu"), .. + gettext("Fri")]; + + week_strings_long = [gettext("Saturday"), .. + gettext("Sunday") , .. + gettext("Monday") , .. + gettext("Tuesday") , .. + gettext("Wednesday") , .. + gettext("Thursday") , .. + gettext("Friday") , .. + gettext("Jan")]; + + + if rhs==2 then + if form == "long" then + week_strings = week_strings_long; + else + week_strings = week_strings_short; + end + else + week_strings = week_strings_short; + end + + + // Algorithm + + [nr,nc] = size(D); + + if nc == 1 then + common_year = common_year'; + leap_year = leap_year'; + end + + month_day_mat = ones(nr,nc); + + m = ones(nr,nc); + y = ones(nr,nc); + d = ones(nr,nc); + + Y = floor(D/365.2425); + temp = D - (365.0*Y + ceil(0.25*Y)- ceil(0.01*Y) + ceil(0.0025*Y)); + + mask = (temp <= 0); + Y(mask) = Y(mask) - 1; + D(mask) = D(mask) - (365.0*Y(mask) + ceil(0.25*Y(mask)) - ceil(0.01*Y(mask)) + ceil(0.0025*Y(mask))); + D(~mask) = temp(~mask) + + M = int(D/29); + + month_day_mat(isLeapYear(Y)) = leap_year(M(isLeapYear(Y))+1); + month_day_mat(~isLeapYear(Y)) = common_year(M(~isLeapYear(Y))+1); + + M( D>month_day_mat ) = M( D>month_day_mat )+1; + + month_day_mat(isLeapYear(Y)) = leap_year(M(isLeapYear(Y))); + month_day_mat(~isLeapYear(Y)) = common_year(M(~isLeapYear(Y))); + + d = D - month_day_mat; + + m(M==1) = 13; + m(M==2) = 14; + + y( M==1 | M==2 ) = Y( M==1 | M==2 ) - 1; + + m( M<>1 & M<>2 ) = M( M<>1 & M<>2 ); + y( M<>1 & M<>2 ) = Y( M<>1 & M<>2 ); + + n = modulo( (d + floor(2*m) + floor(3*(m+1)/5) + y + floor(y/4) - floor(y/100) + floor(y/400) + 2) , 7 ); + + N = matrix( week_numbers(n+1) , nr, nc ); + S = matrix( week_strings(n+1) , nr, nc ); + +endfunction |