[Scilab-users] mprintf("%d *\n", nHiters, M) horizontal format iterator ?

Samuel Gougeon sgougeon at free.fr
Wed Feb 24 18:06:22 CET 2016


Le 24/02/2016 17:10, Clément David a écrit :
> Hi Samuel,
>
> Le mercredi 24 février 2016 à 15:27 +0100, Samuel Gougeon a écrit :
>> I am pretty sure that an horizontal iterator was recently implemented for the format
>> used within mprintf(), but i am failing to find any information about how to use it.
> What do you mean by "horizontal iterator" ? Is it like the "argument_index$" for Java [1] ?

I don't know much java, but as Fortran format allows it with "#(...)", 
this one replicates at most #times the content of ()
(that may have other (...) patterns (recursive 
replication/substitution))... Then, for all provided data, the format is 
feed with
row-wise input data and builds the output with replicating the format as 
many times as some input data remain
(for the current row), and then stop without error (even before the end 
of the format).

Unfortunately, write() that could manage such a handy fortran format is 
not well implemented:

  * the write() format cannot mix input data types (bug 3798)
    <http://bugzilla.scilab.org/3798>
  * when the write() format meets a string (a), its parsing stops (bug
    12476) <http://bugzilla.scilab.org/12476>

Being so handicaped, write() has not much interest wrt mprintf(), and 
AFAIK, there is presently
no native Scilab function handling input data in this way. We are 
compelled to use things
like this msprintf():

--> NL=4; NC=6; Nchar=5;

--> data = 
matrix(strsplit(ascii(grand(NL*NC*Nchar,1,"uin",32,126)),(1:NL*NC-1)*Nchar),NL,NC)
  data  =

!/6QV0  L)3zw  I<wxX  l/u02  f(kAd  #P8oI  !
!                                          !
!+`kUF  !'{*`  BE$d%  q3WnC  Ch:iP  3|fj^  !
!                                          !
!FdBRS  !Gsp"  VkE<-  ySYC<  UNX-.  Gbfb#  !
!                                          !
!xJZH3  W!(g"  ~p9 at z   3Df9  6CjU7  MDWnB  !

--> mprintf(strcat(emptystr(1,size(data,2))+"%10s ")+"\n", data)
      /6QV0      L)3zw      I<wxX      l/u02 f(kAd      #P8oI
      +`kUF      !'{*`      BE$d%      q3WnC Ch:iP      3|fj^
      FdBRS      !Gsp"      VkE<-      ySYC< UNX-.      Gbfb#
      xJZH3      W!(g"      ~p9 at z       3Df9 6CjU7      MDWnB

since write() misworks:

--> write(%io(2), data, "((2x a))")
   /6QV0
   +`kUF
   FdBRS
   xJZH3
   L)3zw
   !'{*`
   !Gsp"
   W!(g"
   I<wxX
   BE$d%
   VkE<-
   ~p9 at z
   l/u02
   q3WnC
   ySYC<
    3Df9
   f(kAd
   Ch:iP
   UNX-.
   6CjU7
   #P8oI
   3|fj^
   Gbfb#
   MDWnB

Samuel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160224/4c56fbfd/attachment.htm>


More information about the users mailing list