mgeti function plugged. 46/12146/3
Cedric Delamarre [Fri, 26 Jul 2013 10:30:48 +0000 (12:30 +0200)]
test_run("fileio","mgeti",["no_check_error_output" ]);

Change-Id: If304e2b575414d70765c9aa88d429b5433e2507b

scilab/modules/fileio/tests/unit_tests/mgeti.dia.ref
scilab/modules/fileio/tests/unit_tests/mgeti.tst
scilab/modules/integer/macros/mgeti.sci [new file with mode: 0644]

index a840525..2778485 100644 (file)
@@ -19,13 +19,19 @@ endfunction
 //
 //prepare data
 //
-ul1     = uint32(123); //0x7B
-ul2     = uint32(45678);//0xB26E
-ul3     = uint32(123456);//0x0001E240
-l1      = int32(-123); //0x85
-l2      = int32(-23456);//0xA460
-l3      = int32(-123456);//0xFFFE1DC0
-l3t     = int32(7616);//0x1DC0
+ul1     = uint64(123); //0x7B
+ul2     = uint64(45678);//0xB26E
+ul3     = uint64(123456);//0x0001E240
+l1      = int64(-123); //0x7B
+l2      = int64(-23456);//0xB26E
+l3      = int64(-123456);//0x0001E240
+ui1     = uint32(123); //0x7B
+ui2     = uint32(45678);//0xB26E
+ui3     = uint32(123456);//0x0001E240
+i1      = int32(-123); //0x85
+i2      = int32(-23456);//0xA460
+i3      = int32(-123456);//0xFFFE1DC0
+i3t     = int32(7616);//0x1DC0
 us1     = uint16(123); //0x7B
 us2     = uint16(45678);//0xB26E
 us3     = uint16(123456);//0x0001E240
@@ -34,17 +40,25 @@ s2      = int16(-23456);//0xA460
 s3      = int16(-123456);//0xFFFE1DC0
 s3t     = int16(7616);//0x1DC0
 //unsigned long big endian
-writedata("ulb", ["00" "00" "00" "7B" "00" "00" "B2" "6E" "00" "01" "E2" "40"]);
+writedata("ulb", ["00" "00" "00" "00" "00" "00" "00" "7B" "00" "00" "00" "00" "00" "00" "B2" "6E" "00" "00" "00" "00" "00" "01" "E2" "40"]);
 //unsigned long little endian
-writedata("ull", ["7B" "00" "00" "00" "6E" "B2" "00" "00" "40" "E2" "01" "00"]);
+writedata("ull", ["7B" "00" "00" "00" "00" "00" "00" "00" "6E" "B2" "00" "00" "00" "00" "00" "00" "40" "E2" "01" "00" "00" "00" "00" "00"]);
+//unsigned int big endian
+writedata("uib", ["00" "00" "00" "7B" "00" "00" "B2" "6E" "00" "01" "E2" "40"]);
+//unsigned int little endian
+writedata("uil", ["7B" "00" "00" "00" "6E" "B2" "00" "00" "40" "E2" "01" "00"]);
 //unsigned short big endian
 writedata("usb", ["00" "7B" "B2" "6E" "E2" "40"]);
 //unsigned short little endian
 writedata("usl", ["7B" "00" "6E" "B2" "40" "E2"]);
 //long big endian
-writedata("lb", ["FF" "FF" "FF" "85" "FF" "FF" "A4" "60" "FF" "FE" "1D" "C0"]);
+writedata("lb", ["FF" "FF" "FF" "FF" "FF" "FF" "FF" "85" "FF" "FF" "FF" "FF" "FF" "FF" "A4" "60" "FF" "FF" "FF" "FF" "FF" "FE" "1D" "C0"]);
 //long little endian
-writedata("ll", ["85" "FF" "FF" "FF" "60" "A4" "FF" "FF" "C0" "1D" "FE" "FF"]);
+writedata("ll", ["85" "FF" "FF" "FF" "FF" "FF" "FF" "FF" "60" "A4" "FF" "FF" "FF" "FF" "FF" "FF" "C0" "1D" "FE" "FF" "FF" "FF" "FF" "FF"]);
+//int big endian
+writedata("ib", ["FF" "FF" "FF" "85" "FF" "FF" "A4" "60" "FF" "FE" "1D" "C0"]);
+//int little endian
+writedata("il", ["85" "FF" "FF" "FF" "60" "A4" "FF" "FF" "C0" "1D" "FE" "FF"]);
 //short big endian
 writedata("sb", ["FF" "85" "A4" "60" "1D" "C0"]);
 //short little endian
@@ -53,14 +67,22 @@ res = readdata("ulb");
 assert_checkequal(res, [ul1, ul2, ul3]);
 res = readdata("ull");
 assert_checkequal(res, [ul1, ul2, ul3]);
-res = readdata("usb");
-assert_checkequal(res, [us1, us2, us3]);
-res = readdata("usl");
-assert_checkequal(res, [us1, us2, us3]);
 res = readdata("lb");
 assert_checkequal(res, [l1, l2, l3]);
 res = readdata("ll");
 assert_checkequal(res, [l1, l2, l3]);
+res = readdata("uib");
+assert_checkequal(res, [ui1, ui2, ui3]);
+res = readdata("uil");
+assert_checkequal(res, [ui1, ui2, ui3]);
+res = readdata("usb");
+assert_checkequal(res, [us1, us2, us3]);
+res = readdata("usl");
+assert_checkequal(res, [us1, us2, us3]);
+res = readdata("ib");
+assert_checkequal(res, [i1, i2, i3]);
+res = readdata("il");
+assert_checkequal(res, [i1, i2, i3]);
 res = readdata("sb");
 assert_checkequal(res, [s1, s2, s3]);
 res = readdata("sl");
index f0e7079..fff13c0 100644 (file)
@@ -23,13 +23,20 @@ endfunction
 //prepare data
 //
 
-ul1     = uint32(123); //0x7B
-ul2     = uint32(45678);//0xB26E
-ul3     = uint32(123456);//0x0001E240
-l1      = int32(-123); //0x85
-l2      = int32(-23456);//0xA460
-l3      = int32(-123456);//0xFFFE1DC0
-l3t     = int32(7616);//0x1DC0
+ul1     = uint64(123); //0x7B
+ul2     = uint64(45678);//0xB26E
+ul3     = uint64(123456);//0x0001E240
+l1      = int64(-123); //0x7B
+l2      = int64(-23456);//0xB26E
+l3      = int64(-123456);//0x0001E240
+
+ui1     = uint32(123); //0x7B
+ui2     = uint32(45678);//0xB26E
+ui3     = uint32(123456);//0x0001E240
+i1      = int32(-123); //0x85
+i2      = int32(-23456);//0xA460
+i3      = int32(-123456);//0xFFFE1DC0
+i3t     = int32(7616);//0x1DC0
 
 us1     = uint16(123); //0x7B
 us2     = uint16(45678);//0xB26E
@@ -40,18 +47,26 @@ s3      = int16(-123456);//0xFFFE1DC0
 s3t     = int16(7616);//0x1DC0
 
 //unsigned long big endian
-writedata("ulb", ["00" "00" "00" "7B" "00" "00" "B2" "6E" "00" "01" "E2" "40"]);
+writedata("ulb", ["00" "00" "00" "00" "00" "00" "00" "7B" "00" "00" "00" "00" "00" "00" "B2" "6E" "00" "00" "00" "00" "00" "01" "E2" "40"]);
 //unsigned long little endian
-writedata("ull", ["7B" "00" "00" "00" "6E" "B2" "00" "00" "40" "E2" "01" "00"]);
+writedata("ull", ["7B" "00" "00" "00" "00" "00" "00" "00" "6E" "B2" "00" "00" "00" "00" "00" "00" "40" "E2" "01" "00" "00" "00" "00" "00"]);
+//unsigned int big endian
+writedata("uib", ["00" "00" "00" "7B" "00" "00" "B2" "6E" "00" "01" "E2" "40"]);
+//unsigned int little endian
+writedata("uil", ["7B" "00" "00" "00" "6E" "B2" "00" "00" "40" "E2" "01" "00"]);
 //unsigned short big endian
 writedata("usb", ["00" "7B" "B2" "6E" "E2" "40"]);
 //unsigned short little endian
 writedata("usl", ["7B" "00" "6E" "B2" "40" "E2"]);
 
 //long big endian
-writedata("lb", ["FF" "FF" "FF" "85" "FF" "FF" "A4" "60" "FF" "FE" "1D" "C0"]);
+writedata("lb", ["FF" "FF" "FF" "FF" "FF" "FF" "FF" "85" "FF" "FF" "FF" "FF" "FF" "FF" "A4" "60" "FF" "FF" "FF" "FF" "FF" "FE" "1D" "C0"]);
 //long little endian
-writedata("ll", ["85" "FF" "FF" "FF" "60" "A4" "FF" "FF" "C0" "1D" "FE" "FF"]);
+writedata("ll", ["85" "FF" "FF" "FF" "FF" "FF" "FF" "FF" "60" "A4" "FF" "FF" "FF" "FF" "FF" "FF" "C0" "1D" "FE" "FF" "FF" "FF" "FF" "FF"]);
+//int big endian
+writedata("ib", ["FF" "FF" "FF" "85" "FF" "FF" "A4" "60" "FF" "FE" "1D" "C0"]);
+//int little endian
+writedata("il", ["85" "FF" "FF" "FF" "60" "A4" "FF" "FF" "C0" "1D" "FE" "FF"]);
 //short big endian
 writedata("sb", ["FF" "85" "A4" "60" "1D" "C0"]);
 //short little endian
@@ -61,15 +76,24 @@ res = readdata("ulb");
 assert_checkequal(res, [ul1, ul2, ul3]);
 res = readdata("ull");
 assert_checkequal(res, [ul1, ul2, ul3]);
+res = readdata("lb");
+assert_checkequal(res, [l1, l2, l3]);
+res = readdata("ll");
+assert_checkequal(res, [l1, l2, l3]);
+
+res = readdata("uib");
+assert_checkequal(res, [ui1, ui2, ui3]);
+res = readdata("uil");
+assert_checkequal(res, [ui1, ui2, ui3]);
 res = readdata("usb");
 assert_checkequal(res, [us1, us2, us3]);
 res = readdata("usl");
 assert_checkequal(res, [us1, us2, us3]);
 
-res = readdata("lb");
-assert_checkequal(res, [l1, l2, l3]);
-res = readdata("ll");
-assert_checkequal(res, [l1, l2, l3]);
+res = readdata("ib");
+assert_checkequal(res, [i1, i2, i3]);
+res = readdata("il");
+assert_checkequal(res, [i1, i2, i3]);
 res = readdata("sb");
 assert_checkequal(res, [s1, s2, s3]);
 res = readdata("sl");
diff --git a/scilab/modules/integer/macros/mgeti.sci b/scilab/modules/integer/macros/mgeti.sci
new file mode 100644 (file)
index 0000000..1f58971
--- /dev/null
@@ -0,0 +1,54 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Cedric Delamarre
+//
+// 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-en.txt
+
+function x = mgeti(n, type, fd)
+
+    rhs=argn(2);
+    if rhs == 0 | rhs > 3 then
+        error(msprintf(_("%s: Wrong number of input argument(s): %d to %d expected.\n"), "mgeti", 1, 3));
+    end
+
+    if typeof(type) <> "string" then
+        error(msprintf(_("%s: Wrong type for argument #%d: A string expected.\n"), "mgeti", 2));
+    end
+
+    if size(type, '*') <> 1 then
+        error(msprintf(_("%s: Wrong size for argument #%d: A single string expected.\n"), "mgeti", 2));
+    end
+
+    typeToConvert = 0;
+    len = length(type);
+    partPos = 1;
+
+    if len == 0 | len > 3 then
+        error(msprintf(_("%s: Wrong size for argument #%d: A single string of size %d to %d expected.\n"), "mgeti", 2, 1, 3));
+    end
+
+    // unsigne
+    if part(type, partPos) == 'u'
+        typeToConvert = 10;
+        partPos = 2;
+    end
+
+    // type to convert
+    select part(type, partPos)
+    case 'l'
+        typeToConvert = typeToConvert + 8;
+    case 'i'
+        typeToConvert = typeToConvert + 4;
+    case 's'
+        typeToConvert = typeToConvert + 2;
+    case 'c'
+        typeToConvert = typeToConvert + 1;
+    else
+        error(msprintf(_("%s: Incorrect integer type: %s .\n"), "mgeti", part(type, partPos)));
+    end
+
+    x = iconvert(mget(n, type, fd), typeToConvert);
+endfunction