From 42659d6cdbe63972aea27baf0289db8fcc1310fa Mon Sep 17 00:00:00 2001 From: pmarecha Date: Thu, 5 Jun 2008 08:49:05 +0000 Subject: SVN is not FTP ! --- .../GeneralFunctions/FunName2SciFileName.sci | 45 +++++++++++++++++ src/Scilab2C/GeneralFunctions/PrintStringInfo.sci | 56 ++++++++++++++++++++++ src/Scilab2C/GeneralFunctions/ReadStringCard.sci | 51 ++++++++++++++++++++ src/Scilab2C/GeneralFunctions/SCI2CCreateDir.sci | 21 ++++++++ src/Scilab2C/GeneralFunctions/SCI2Cerror.sci | 11 +++++ src/Scilab2C/GeneralFunctions/SCI2Cfileexist.sci | 28 +++++++++++ src/Scilab2C/GeneralFunctions/SCI2Cmdelete.sci | 21 ++++++++ src/Scilab2C/GeneralFunctions/SCI2Cstrncmp.sci | 19 ++++++++ .../GeneralFunctions/SCI2Cstrncmps1size.sci | 21 ++++++++ src/Scilab2C/GeneralFunctions/SciFile2ASTFile.sci | 29 +++++++++++ src/Scilab2C/GeneralFunctions/SizeInByte.sci | 31 ++++++++++++ src/Scilab2C/GeneralFunctions/dispina.sci | 23 +++++++++ src/Scilab2C/GeneralFunctions/filenamefprintf.sci | 39 +++++++++++++++ src/Scilab2C/GeneralFunctions/squeezestrings.sci | 21 ++++++++ 14 files changed, 416 insertions(+) create mode 100644 src/Scilab2C/GeneralFunctions/FunName2SciFileName.sci create mode 100644 src/Scilab2C/GeneralFunctions/PrintStringInfo.sci create mode 100644 src/Scilab2C/GeneralFunctions/ReadStringCard.sci create mode 100644 src/Scilab2C/GeneralFunctions/SCI2CCreateDir.sci create mode 100644 src/Scilab2C/GeneralFunctions/SCI2Cerror.sci create mode 100644 src/Scilab2C/GeneralFunctions/SCI2Cfileexist.sci create mode 100644 src/Scilab2C/GeneralFunctions/SCI2Cmdelete.sci create mode 100644 src/Scilab2C/GeneralFunctions/SCI2Cstrncmp.sci create mode 100644 src/Scilab2C/GeneralFunctions/SCI2Cstrncmps1size.sci create mode 100644 src/Scilab2C/GeneralFunctions/SciFile2ASTFile.sci create mode 100644 src/Scilab2C/GeneralFunctions/SizeInByte.sci create mode 100644 src/Scilab2C/GeneralFunctions/dispina.sci create mode 100644 src/Scilab2C/GeneralFunctions/filenamefprintf.sci create mode 100644 src/Scilab2C/GeneralFunctions/squeezestrings.sci (limited to 'src/Scilab2C/GeneralFunctions') diff --git a/src/Scilab2C/GeneralFunctions/FunName2SciFileName.sci b/src/Scilab2C/GeneralFunctions/FunName2SciFileName.sci new file mode 100644 index 00000000..c2f6db34 --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/FunName2SciFileName.sci @@ -0,0 +1,45 @@ +function ScilabFileName = FunName2SciFileName(DirList,InFunName); +// function ScilabFileName = FunName2SciFileName(DirList,InFunName); +// ----------------------------------------------------------------- +// This function generates the full path of the scilab file +// related to the function name (InFunName) specified. +// In more detail the file "eval(InFunName).sci" file is searched +// in the directories specified in DirList. +// +// Input data: +// +// +// Output data: +// +// Status: +// 16-Apr-2007 -- Nutricato Raffaele: Author. +// ----------------------------------------------------------------- + +if (prod(size(DirList)) == 0) + SCI2Cerror('Incorrect DirList parameter.'); +end + +if (prod(size(InFunName)) == 0) + SCI2Cerror('Incorrect InFunName parameter.'); +end + +// --- Generate the PathList. --- +for tmpcounter = 1:max(size(DirList)) + PathList(tmpcounter) = fullfile(DirList(tmpcounter),(InFunName+'.sci')); +end + +// --- Search the .sci file. --- +ScilabFileName = listfiles(PathList); + +// --- Check on the number of .sci files found. --- +if ((prod(size(ScilabFileName))) > 1) + disp(ScilabFileName); + SCI2Cerror('Found more than one scilab file.'); +end + +if ((prod(size(ScilabFileName))) < 1) + disp(ScilabFileName); + SCI2Cerror('Scilab file ""'+InFunName+'.sci"", not found'); +end + +endfunction diff --git a/src/Scilab2C/GeneralFunctions/PrintStringInfo.sci b/src/Scilab2C/GeneralFunctions/PrintStringInfo.sci new file mode 100644 index 00000000..36377bdc --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/PrintStringInfo.sci @@ -0,0 +1,56 @@ +function PrintStringInfo(str, filename, outputtype, ennewline); +// function PrintStringInfo(str,filename,outputtype,ennewline); +// ----------------------------------------------------------------- +// Prints a string into a file or on the stdout or on both. +// +// Input data: +// filename: optional parameter, that specifies the output file. +// If filename is '' or it is not provided to the function, +// the string will be printed on the stdout. +// outputtype: 'file' -> prints only on file. +// 'stdout' -> prints only on the stdout. +// 'both' -> prints on both file and stdout. +// Default is 'stdout'. +// ennewline: optional (default = 'y'); If y adds a newline character +// at the end of the input string. +// Output data: +// +// Status: +// 02-Jan-2006 -- Nutricato Raffaele: Author. +// 02-Jan-2006 -- Nutricato Raffaele: TEST OK. +// 02-May-2006 -- Nutricato Raffaele: Added ennewline. +// ----------------------------------------------------------------- + + if argn(2) < 4 + ennewline = 'y'; + if argn(2) < 3 + outputtype = 'stdout'; + if argn(2) < 2 + filename = ''; + if argn(2) < 1 + str = ''; + end + end + end + else if argn(2) > 4 + SCI2CSCI2Cerror('Incorrect number of input arguments.'); + end + end + + if (length(filename) == 0) then + outputtype = 'stdout'; // Prints only on the stdout. + end + + if (outputtype=='both') | (outputtype=='stdout') + disp(str) + end + + if (outputtype=='both') | (outputtype=='file') + if (ennewline=='y') + filenamefprintf(filename,'y',str); + else + filenamefprintf(filename,'n',str); + end + end + +endfunction diff --git a/src/Scilab2C/GeneralFunctions/ReadStringCard.sci b/src/Scilab2C/GeneralFunctions/ReadStringCard.sci new file mode 100644 index 00000000..a6abfcb7 --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/ReadStringCard.sci @@ -0,0 +1,51 @@ +function cardvalue = ReadStringCard(filename,cardname,commentdelim,enableerror); +// function cardvalue = ReadStringCard(filename,cardname,commentdelim,enableerror); +// ----------------------------------------------------------------- +// Reads the string associated to the card cardname placed +// in filename. +// The value of cardname is assumed to be a string. +// If the card is not found an error will occur. +// +// Input data: +// filename: full path + name of the file where the card +// is being searched. +// cardname: string with the name of the card. +// commentdelim: specifies a character for an eventual comment +// (to be discarded) after the card value. +// enableerror: 'y' enable error message. +// 'n' enable warning message. +// +// Output data: +// cardvalue: string associated to the card. Blanks characters +// are discarded. +// +// Status: +// 06-Feb-2004 -- Nutricato Raffaele: Author. +// 06-Feb-2004 -- Nutricato Raffaele: TEST OK. +// 25-Jun-2004 -- Nutricato Raffaele: Added Comment delimiter +// and enableerror as input parameter. +// 13-Apr-2007 -- Intelligente Fabio: Rewritten from Matlab to Scilab. +// ----------------------------------------------------------------- + +if argn(2) == 2 then + commentdelim = ' '; + enableerror = 'y'; + +elseif argn(2) == 3 then + enableerror = 'y'; +end + +[flag_found,requested_line,dummy2] = ... + KeyString2FileStringPos(filename,cardname,'cut'); +cardvalue = stripblanks(strtok(requested_line,commentdelim)); +clear requested_line dummy2 + +if (flag_found == 0) then + if (enableerror == 'y') then + SCI2Cerror([cardname,' not found']); + else + warning([cardname,' not found']); + end +end + +endfunction diff --git a/src/Scilab2C/GeneralFunctions/SCI2CCreateDir.sci b/src/Scilab2C/GeneralFunctions/SCI2CCreateDir.sci new file mode 100644 index 00000000..606c662a --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/SCI2CCreateDir.sci @@ -0,0 +1,21 @@ +function SCI2CCreateDir(OutDir); +// function SCI2CCreateDir(OutDir); +// ----------------------------------------------------------------- +// Create the dir OutDir. +// +// Input data: +// OutDir: +// +// Output data: +// --- +// +// Status: +// 25-Jun-2007 -- Nutricato Raffaele: Author. +// ----------------------------------------------------------------- + +status_dir = mkdir(OutDir) ; +if (status_dir == 0) + SCI2Cerror('Cannot create: '+OutDir); +end + +endfunction diff --git a/src/Scilab2C/GeneralFunctions/SCI2Cerror.sci b/src/Scilab2C/GeneralFunctions/SCI2Cerror.sci new file mode 100644 index 00000000..444dcff5 --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/SCI2Cerror.sci @@ -0,0 +1,11 @@ +function SCI2Cerror(errorstring); +// function SCI2Cerror(errorstring); +// ----------------------------------------------------------------- +// It is the error function but before issuing the error, perorms +// the mclose('all'); +// 02-May-2006 -- Nutricato Raffaele: Author. +// ----------------------------------------------------------------- + +mclose('all') +error('###########SCI2C_ERROR: '+errorstring); +endfunction diff --git a/src/Scilab2C/GeneralFunctions/SCI2Cfileexist.sci b/src/Scilab2C/GeneralFunctions/SCI2Cfileexist.sci new file mode 100644 index 00000000..87cc1777 --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/SCI2Cfileexist.sci @@ -0,0 +1,28 @@ +function ExistTest = SCI2Cfileexist(InDir,FileName) +// function ExistTest = SCI2Cfileexist(InDir,FileName) +// ----------------------------------------------------------------- +// Searches for the file FileName in the directory InDir. +// Return %F if it doesn't exist. +// +// Input data: +// +// Output data: +// +// Status: +// 12-Jun-2007 -- Nutricato Raffaele: Author. +// ----------------------------------------------------------------- + +tmppwd = pwd(); +cd(InDir); +allfiles = ls(FileName); +cd(tmppwd); + +if (size(allfiles,1) == 0) + ExistTest = %F; +elseif (size(allfiles,1) == 1) + ExistTest = %T; +else + SCI2Cerror('Very Strange! Found more than one file with the same name.'); +end + +endfunction diff --git a/src/Scilab2C/GeneralFunctions/SCI2Cmdelete.sci b/src/Scilab2C/GeneralFunctions/SCI2Cmdelete.sci new file mode 100644 index 00000000..772cff98 --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/SCI2Cmdelete.sci @@ -0,0 +1,21 @@ +function SCI2Cmdelete(InFile); +// function SCI2Cmdelete(InFile); +// ----------------------------------------------------------------- +// Deletes the input files only if the file really exists. +// This avoids the issuing of the error generated by mdelete. +// +// Input data: +// InFile: full path of the file to be deleted. +// +// Output data: +// +// Status: +// 12-Apr-2007 -- Nutricato Raffaele: Author. +// ----------------------------------------------------------------- + +[Inx,Inierr]=fileinfo(InFile) +if Inierr == 0 + mdelete(InFile); +end + +endfunction diff --git a/src/Scilab2C/GeneralFunctions/SCI2Cstrncmp.sci b/src/Scilab2C/GeneralFunctions/SCI2Cstrncmp.sci new file mode 100644 index 00000000..81bc2f5b --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/SCI2Cstrncmp.sci @@ -0,0 +1,19 @@ +function res = SCI2Cstrncmp(s1,s2,n); +// function res = SCI2Cstrncmp(s1,s2,n); +// ----------------------------------------------------------------- +// This function compares first n characters of strings s1 and s2. +// SCI2Cstrncmp(s1,s2,n) returns logical T (true) if the first n characters of +// the strings s1 and s2 are the same and logical 0 (false) otherwise. +// +// Input data: +// +// +// Output data: +// +// Status: +// 16-Apr-2007 -- Nutricato Raffaele: Author. +// ----------------------------------------------------------------- + +res = (part(s1,1:n) == part(s2,1:n)); + +endfunction diff --git a/src/Scilab2C/GeneralFunctions/SCI2Cstrncmps1size.sci b/src/Scilab2C/GeneralFunctions/SCI2Cstrncmps1size.sci new file mode 100644 index 00000000..d560b850 --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/SCI2Cstrncmps1size.sci @@ -0,0 +1,21 @@ +function res = SCI2Cstrncmps1size(s1,s2); +// function res = SCI2Cstrncmps1size(s1,s2); +// ----------------------------------------------------------------- +// This function compares first n characters of strings s1 and s2. +// n is the size of the string s1. +// SCI2Cstrncmps1size returns logical T (true) if the first n characters of +// the strings s1 and s2 are the same and logical 0 (false) otherwise. +// +// Input data: +// +// +// Output data: +// +// Status: +// 16-Apr-2007 -- Nutricato Raffaele: Author. +// ----------------------------------------------------------------- + +n = length(s1); +res = (part(s1,1:n) == part(s2,1:n)); + +endfunction diff --git a/src/Scilab2C/GeneralFunctions/SciFile2ASTFile.sci b/src/Scilab2C/GeneralFunctions/SciFile2ASTFile.sci new file mode 100644 index 00000000..8930564d --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/SciFile2ASTFile.sci @@ -0,0 +1,29 @@ +function SciFile2ASTFile(SciFile,ASTFile); +// function SciFile2ASTFile(SciFile,ASTFile); +// ----------------------------------------------------------------- +// This function makes use of the macr2tree function to generate +// the ASTFile containing the AST (Abstract Syntactic Tree) of the +// input Scilab function (SciFile). +// +// Input data: +// SciFile: full path of the input function. +// ASTFile: full path of the file that will store the AST. +// +// Output data: +// +// Status: +// 12-Apr-2007 -- Nutricato Raffaele: Author. +// ----------------------------------------------------------------- + +getf(SciFile); +[tmppath,ScilabFunName,tmpext] = fileparts(SciFile); +AST=eval('macr2tree('+ScilabFunName+')'); + + +[ASTx,ASTierr]=fileinfo(ASTFile) +if ASTierr == 0 + mdelete(ASTFile); +end +write(ASTFile,string(AST)); + +endfunction diff --git a/src/Scilab2C/GeneralFunctions/SizeInByte.sci b/src/Scilab2C/GeneralFunctions/SizeInByte.sci new file mode 100644 index 00000000..5fcf4e08 --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/SizeInByte.sci @@ -0,0 +1,31 @@ +function SizeIn = SizeInByte(InDataType); +// function SizeIn = SizeInByte(InDataType); +// ----------------------------------------------------------------- +// Returns the size in bytes of the input data type. +// +// Input data: +// InDataType: input data type. It can be: +// 'float' +// 'double' +// 'floatComplex*' +// 'doubleComplex*' +// +// Output data: +// SizeIn: size in bytes of the input data type. +// +// Status: +// 12-May-2007 -- Nutricato Raffaele: Author. +// ----------------------------------------------------------------- + +if (InDataType == 'float') + SizeIn = 4; +elseif (InDataType == 'double') + SizeIn = 8; +elseif (InDataType == 'floatComplex*') + SizeIn = 8; +elseif (InDataType == 'doubleComplex*') + SizeIn = 16; +else + error('Unknown data type: '+InDataType); +end +endfunction diff --git a/src/Scilab2C/GeneralFunctions/dispina.sci b/src/Scilab2C/GeneralFunctions/dispina.sci new file mode 100644 index 00000000..a1d85a68 --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/dispina.sci @@ -0,0 +1,23 @@ +function dispina(instring); +// function dispina(instring); +// ----------------------------------------------------------------- +// Quista sacciu sulu iou comu funziona e a ce me server. +// +// Input data: +// +// Output data: +// +// Status: +// 12-Apr-2007 -- Nutricato Raffaele: Author. +// ----------------------------------------------------------------- + +disp('++++++++++++++++++++++++++++++++++++++++++++++++++') +disp('++++++++++++++++++++++++++++++++++++++++++++++++++') +disp('++++++++++++++++++++++++++++++++++++++++++++++++++') +disp('++++++++++++++++++++++++++++++++++++++++++++++++++') +disp(instring); +disp('++++++++++++++++++++++++++++++++++++++++++++++++++') +disp('++++++++++++++++++++++++++++++++++++++++++++++++++') +disp('++++++++++++++++++++++++++++++++++++++++++++++++++') +disp('++++++++++++++++++++++++++++++++++++++++++++++++++') +endfunction diff --git a/src/Scilab2C/GeneralFunctions/filenamefprintf.sci b/src/Scilab2C/GeneralFunctions/filenamefprintf.sci new file mode 100644 index 00000000..98a0cba2 --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/filenamefprintf.sci @@ -0,0 +1,39 @@ +function filenamefprintf(filename,ennewline,str) +// function filenamefprintf(filename,ennewline,str) +// -------------------------------------------------------------------------------- +// Uses the printf to print the string specified by varargin. filenamefprintf +// uses the filename instead of the fid parameter used by fprintf. +// Everytime filenamefprintf is called it +// opens the file, prints the string in it and then closes it. +// Opening is performed in read/append mode (at+). +// +// Input data: +// filename: string that specifies the name of the file. +// varargin are the input arguments for the printf. +// +// Output data: +// +// Status: +// 31-Jan-2006 -- Nutricato Raffaele: Author. +// 31-Jan-2006 -- Nutricato Raffaele: TEST OK. +// -------------------------------------------------------------------------------- + + + if argn(2) < 3 then + SCI2Cerror('Incorrect number of input arguments.'); + end + +// [FidReportFile, mess] = mopen(deblank(filename),'at+'); + [FidReportFile, mess] = mopen(filename,'a+'); + if (FidReportFile == -1) then + SCI2Cerror(mess); + end + + if ennewline=='y' then + mfprintf(FidReportFile,'%s\n',str); + else + mfprintf(FidReportFile,'%s',str); + end + mclose(FidReportFile); + +endfunction diff --git a/src/Scilab2C/GeneralFunctions/squeezestrings.sci b/src/Scilab2C/GeneralFunctions/squeezestrings.sci new file mode 100644 index 00000000..97e8f9a1 --- /dev/null +++ b/src/Scilab2C/GeneralFunctions/squeezestrings.sci @@ -0,0 +1,21 @@ +function OutString = squeezestrings(InStringArray); +// function OutString = squeezestrings(InStringArray); +// ----------------------------------------------------------------- +// Converts an array of strings into a single string. +// +// Input data: +// InStringArray: Array of strings. +// +// Output data: +// OutString: Output string. +// +// Status: +// 12-Apr-2007 -- Nutricato Raffaele: Author. +// ----------------------------------------------------------------- + +OutString = []; +for counterstrings = 1:max(size(InStringArray)) + OutString = OutString+InStringArray(counterstrings); +end + +endfunction -- cgit