function fieldnames added, bug 4586 fix
Serge Steer [Fri, 19 Jun 2009 12:24:09 +0000 (14:24 +0200)]
SEP/SEP_24_fieldnames.odt [new file with mode: 0644]
scilab/modules/data_structures/help/en_US/fieldnames.xml [new file with mode: 0644]
scilab/modules/data_structures/help/fr_FR/fieldnames.xml [new file with mode: 0644]
scilab/modules/data_structures/macros/fieldnames.sci [new file with mode: 0644]
scilab/modules/data_structures/tests/unit_tests/fieldnames.dia.ref [new file with mode: 0644]
scilab/modules/data_structures/tests/unit_tests/fieldnames.tst [new file with mode: 0644]

diff --git a/SEP/SEP_24_fieldnames.odt b/SEP/SEP_24_fieldnames.odt
new file mode 100644 (file)
index 0000000..3f4f46f
Binary files /dev/null and b/SEP/SEP_24_fieldnames.odt differ
diff --git a/scilab/modules/data_structures/help/en_US/fieldnames.xml b/scilab/modules/data_structures/help/en_US/fieldnames.xml
new file mode 100644 (file)
index 0000000..b15ddd6
--- /dev/null
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2006-2008 - INRIA
+ *
+ * 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
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="en" xml:id="fieldnames">
+  <info>
+    <pubdate>$LastChangedDate$</pubdate>
+  </info>
+  <refnamediv>
+    <refname>fieldnames</refname>
+    <refpurpose>  returns the tlist, mlist or struct field names</refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+    <synopsis>f=fieldnames(x)</synopsis>
+  </refsynopsisdiv>
+  <refsection>
+    <title>Parameters</title>
+    <variablelist>
+      <varlistentry>
+        <term>x</term>
+        <listitem>
+          <para>a tlist or an mlist or a struct. </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>f</term>
+        <listitem>
+          <para>column vector of strings</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  <refsection>
+    <title>Description</title>
+    <para>
+    This function  returns the tlist, mlist, cell or struct field names.</para>
+  </refsection>
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[
+clear t;
+t.a=1;
+t.b=2;
+fieldnames(t)
+fieldnames(1/%s)
+fieldnames(tf2ss(1/%s))
+  ]]></programlisting>
+  </refsection>
+  <refsection>
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="extraction">extraction</link>
+      </member>  
+      <member>
+        <link linkend="getfield">getfield</link>
+      </member>
+      <member>
+        <link linkend="tlist">tlist</link>
+      </member>
+      <member>
+        <link linkend="mlist">mlist</link>
+      </member>
+      <member>
+        <link linkend="mlist">struct</link>
+      </member>
+    </simplelist>
+  </refsection>
+</refentry>
diff --git a/scilab/modules/data_structures/help/fr_FR/fieldnames.xml b/scilab/modules/data_structures/help/fr_FR/fieldnames.xml
new file mode 100644 (file)
index 0000000..26ae434
--- /dev/null
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="fr" xml:id="fieldnames">
+  <info>
+    <pubdate>$LastChangedDate$</pubdate>
+  </info>
+  <refnamediv>
+    <refname>fieldnames</refname>
+    <refpurpose>returne les noms de champs d'une tlist, d'une mlist ou d'une struct</refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <title>Séquence d'appel</title>
+    <synopsis>f=fieldnames(x)</synopsis>
+  </refsynopsisdiv>
+  <refsection>
+    <title>Paramètres</title>
+    <variablelist>
+      <varlistentry>
+        <term>x  </term>
+        <listitem>
+          <para>une tlist,  une mlist ou une struct.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>f</term>
+        <listitem>
+          <para>Un vecteur colonne de chaînes de caractères</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  <refsection>
+    <title>Description</title>
+    <para>
+    returne les noms de champs d'une tlist, d'une mlist ou d'une struct.</para>
+  </refsection>
+  <refsection>
+    <title>Exemples</title>
+    <programlisting role="example"><![CDATA[
+clear t;
+t.a=1;
+t.b=2;
+fieldnames(t)
+fieldnames(1/%s)
+fieldnames(tf2ss(1/%s))
+ ]]></programlisting>
+  </refsection>
+  <refsection>
+    <title>Voir Aussi</title>
+    <simplelist type="inline">
+     <member>
+        <link linkend="extraction">extraction</link>
+      </member>  
+      <member>
+        <link linkend="getfield">getfield</link>
+      </member>
+      <member>
+        <link linkend="tlist">tlist</link>
+      </member>
+      <member>
+        <link linkend="mlist">mlist</link>
+      </member>
+      <member>
+        <link linkend="mlist">struct</link>
+      </member>
+    </simplelist>
+  </refsection>
+</refentry>
diff --git a/scilab/modules/data_structures/macros/fieldnames.sci b/scilab/modules/data_structures/macros/fieldnames.sci
new file mode 100644 (file)
index 0000000..f699783
--- /dev/null
@@ -0,0 +1,21 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) ????-2009 - Serge Steer, INRIA
+//
+// 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 f=fieldnames(t)
+  if or(type(t)==[16,17]) then
+    f=matrix(getfield(1,t),-1,1)
+    if f(1)<>'st' then //ignore type
+      f=f(2:$)
+    else //ignore type and dims
+      f=f(3:$)
+    end
+  else
+    f=[]
+  end
+endfunction
diff --git a/scilab/modules/data_structures/tests/unit_tests/fieldnames.dia.ref b/scilab/modules/data_structures/tests/unit_tests/fieldnames.dia.ref
new file mode 100644 (file)
index 0000000..f48e16a
--- /dev/null
@@ -0,0 +1,38 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - INRIA - Serge.Steer@inria.fr
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- ENGLISH IMPOSED -->
+// <-- JVM NOT MANDATORY -->
+// unit tests for fieldnames function
+// =============================================================================
+if fieldnames(1)<>[] then bugmes();quit;end
+my_struct = struct("field_1",123,"field_2",456);
+if or(fieldnames(my_struct)<>["field_1";"field_2"]) then bugmes();quit;end
+clear T;
+T.a=rand(2,2);
+T.b='s';
+if or(fieldnames(T)<>["a";"b"]) then bugmes();quit;end
+if or(fieldnames(1/%s)<>["num";"den";"dt"]) then bugmes();quit;end
+M=mlist(['foo','A','B','C'],[],[],[])
+ M  =
+       M(1)
+!foo  A  B  C  !
+       M(2)
+     []
+       M(3)
+     []
+       M(4)
+     []
+if or(fieldnames(M)<>['A';'B';'C']) then bugmes();quit;end
diff --git a/scilab/modules/data_structures/tests/unit_tests/fieldnames.tst b/scilab/modules/data_structures/tests/unit_tests/fieldnames.tst
new file mode 100644 (file)
index 0000000..547a357
--- /dev/null
@@ -0,0 +1,28 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - INRIA - Serge.Steer@inria.fr
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- ENGLISH IMPOSED -->
+// <-- JVM NOT MANDATORY -->
+
+// unit tests for fieldnames function
+// =============================================================================
+
+if fieldnames(1)<>[] then pause,end
+
+my_struct = struct("field_1",123,"field_2",456);
+if or(fieldnames(my_struct)<>["field_1";"field_2"]) then pause,end
+
+clear T;
+T.a=rand(2,2);
+T.b='s';
+if or(fieldnames(T)<>["a";"b"]) then pause,end
+
+
+if or(fieldnames(1/%s)<>["num";"den";"dt"]) then pause,end
+
+M=mlist(['foo','A','B','C'],[],[],[])
+if or(fieldnames(M)<>['A';'B';'C']) then pause,end