---input---
// Scilab ( http://www.scilab.org/ )
// Copyright (C) INRIA - Serge STEER
// 

function I=sub2ind(dims,varargin)
//sub2ind is used to determine the equivalent single index
//corresponding to a given set of subscript values.
 
//I = sub2ind(dims,i1,i2,..) returns the linear index equivalent to the
//row,  column, ... subscripts in the arrays i1,i2,..  for an matrix of
//size dims.
 
//I = sub2ind(dims,Mi) returns the linear index
//equivalent to the n subscripts in the columns of the matrix Mi for a matrix
//of size dims.
 
  d=[1;cumprod(matrix(dims(1:$-1),-1,1))]
  for i=1:size(varargin)
    if varargin(i)==[] then I=[],return,end
  end

  if size(varargin)==1 then //subindices are the columns of the argument
    I=(varargin(1)-1)*d+1
  else //subindices are given as separated arguments
    I=1
    for i=1:size(varargin)
      I=I+(varargin(i)-1)*d(i)
    end
  end
endfunction

---tokens---
'// Scilab ( http://www.scilab.org/ )' Comment.Single
'\n'          Text

'// Copyright (C) INRIA - Serge STEER' Comment.Single
'\n'          Text

'// '         Comment.Single
'\n'          Text

'\nfunction'  Keyword
' '           Text.Whitespace
'I'           Text
'='           Punctuation
'sub2ind'     Name.Function
'('           Punctuation
'dims,varargin' Text
')'           Punctuation
'\n'          Text.Whitespace

'//sub2ind is used to determine the equivalent single index' Comment.Single
'\n'          Text

'//corresponding to a given set of subscript values.' Comment.Single
'\n'          Text

' '           Text
'\n'          Text

'//I = sub2ind(dims,i1,i2,..) returns the linear index equivalent to the' Comment.Single
'\n'          Text

'//row,  column, ... subscripts in the arrays i1,i2,..  for an matrix of' Comment.Single
'\n'          Text

'//size dims.' Comment.Single
'\n'          Text

' '           Text
'\n'          Text

'//I = sub2ind(dims,Mi) returns the linear index' Comment.Single
'\n'          Text

'//equivalent to the n subscripts in the columns of the matrix Mi for a matrix' Comment.Single
'\n'          Text

'//of size dims.' Comment.Single
'\n'          Text

' '           Text
'\n'          Text

' '           Text
' '           Text
'd'           Name
'='           Punctuation
'['           Punctuation
'1'           Literal.Number.Integer
';'           Punctuation
'cumprod'     Name.Builtin
'('           Punctuation
'matrix'      Name.Builtin
'('           Punctuation
'dims'        Name
'('           Punctuation
'1'           Literal.Number.Integer
':'           Punctuation
'$'           Text
'-'           Operator
'1'           Literal.Number.Integer
')'           Punctuation
','           Punctuation
'-'           Operator
'1'           Literal.Number.Integer
','           Punctuation
'1'           Literal.Number.Integer
')'           Punctuation
')'           Punctuation
']'           Punctuation
'\n'          Text

' '           Text
' '           Text
'for'         Keyword
' '           Text
'i'           Name
'='           Punctuation
'1'           Literal.Number.Integer
':'           Punctuation
'size'        Name.Builtin
'('           Punctuation
'varargin'    Name
')'           Punctuation
'\n'          Text

' '           Text
' '           Text
' '           Text
' '           Text
'if'          Keyword
' '           Text
'varargin'    Name
'('           Punctuation
'i'           Name
')'           Punctuation
'=='          Operator
'['           Punctuation
']'           Punctuation
' '           Text
'then'        Name.Builtin
' '           Text
'I'           Name
'='           Punctuation
'['           Punctuation
']'           Punctuation
','           Punctuation
'return'      Keyword
','           Punctuation
'end'         Keyword
'\n'          Text

' '           Text
' '           Text
'end'         Keyword
'\n'          Text

'\n'          Text

' '           Text
' '           Text
'if'          Keyword
' '           Text
'size'        Name.Builtin
'('           Punctuation
'varargin'    Name
')'           Punctuation
'=='          Operator
'1'           Literal.Number.Integer
' '           Text
'then'        Name.Builtin
' '           Text
'//subindices are the columns of the argument' Comment.Single
'\n'          Text

' '           Text
' '           Text
' '           Text
' '           Text
'I'           Name
'='           Punctuation
'('           Punctuation
'varargin'    Name
'('           Punctuation
'1'           Literal.Number.Integer
')'           Punctuation
'-'           Operator
'1'           Literal.Number.Integer
')'           Punctuation
'*'           Operator
'd'           Name
'+'           Operator
'1'           Literal.Number.Integer
'\n'          Text

' '           Text
' '           Text
'else'        Keyword
' '           Text
'//subindices are given as separated arguments' Comment.Single
'\n'          Text

' '           Text
' '           Text
' '           Text
' '           Text
'I'           Name
'='           Punctuation
'1'           Literal.Number.Integer
'\n'          Text

' '           Text
' '           Text
' '           Text
' '           Text
'for'         Keyword
' '           Text
'i'           Name
'='           Punctuation
'1'           Literal.Number.Integer
':'           Punctuation
'size'        Name.Builtin
'('           Punctuation
'varargin'    Name
')'           Punctuation
'\n'          Text

' '           Text
' '           Text
' '           Text
' '           Text
' '           Text
' '           Text
'I'           Name
'='           Punctuation
'I'           Name
'+'           Operator
'('           Punctuation
'varargin'    Name
'('           Punctuation
'i'           Name
')'           Punctuation
'-'           Operator
'1'           Literal.Number.Integer
')'           Punctuation
'*'           Operator
'd'           Name
'('           Punctuation
'i'           Name
')'           Punctuation
'\n'          Text

' '           Text
' '           Text
' '           Text
' '           Text
'end'         Keyword
'\n'          Text

' '           Text
' '           Text
'end'         Keyword
'\n'          Text

'endfunction' Keyword
'\n'          Text
