WIP : porting of read/write fortran interface 86/15786/15
Antoine ELIAS [Mon, 12 Jan 2015 09:17:17 +0000 (10:17 +0100)]
Change-Id: I31a2c7bc01d1f325d111762d8fdcd82f4900a571

20 files changed:
scilab/CHANGES_6.0.X
scilab/modules/core/Makefile.am
scilab/modules/core/Makefile.in
scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/core/src/fortran/core_f.vfproj
scilab/modules/core/src/fortran/read_inter.f [new file with mode: 0644]
scilab/modules/core/src/fortran/write_inter.f [new file with mode: 0644]
scilab/modules/io/Makefile.am
scilab/modules/io/Makefile.in
scilab/modules/io/includes/gw_io.h
scilab/modules/io/includes/io_gw.hxx
scilab/modules/io/sci_gateway/c/sci_read.c [deleted file]
scilab/modules/io/sci_gateway/c/sci_write.c [deleted file]
scilab/modules/io/sci_gateway/cpp/sci_read.cpp [new file with mode: 0644]
scilab/modules/io/sci_gateway/cpp/sci_write.cpp [new file with mode: 0644]
scilab/modules/io/src/cpp/core_f_Import.def
scilab/modules/io/src/cpp/io_gw.cpp
scilab/modules/io/src/cpp/io_gw.vcxproj
scilab/modules/io/src/cpp/io_gw.vcxproj.filters
scilab/modules/output_stream/src/cpp/basout.cpp

index d20f94a..24c67a5 100644 (file)
@@ -40,6 +40,10 @@ Deprecated behavior
  1..
  2
 
+* write string or string matrix in file does not add black space before each value
+    write("TMPDIR/test", ["test", "sample"; "sample", "test"])
+    "-" + mgetl("TMPDIR/test") + "-"
+
 Removed functions
 ==================
 
index 7e400b4..c9a1a9a 100644 (file)
@@ -124,7 +124,9 @@ CORE_FORTRAN_SOURCES = \
     src/fortran/readinter.f \
     src/fortran/rewindinter.f \
     src/fortran/backspaceinter.f \
-    src/fortran/relocstack.f
+    src/fortran/relocstack.f \
+       src/fortran/write_inter.f \
+       src/fortran/read_inter.f
 
 GATEWAY_C_SOURCES = \
        sci_gateway/c/gw_core.c \
index 94b913c..eedd031 100644 (file)
@@ -263,7 +263,8 @@ am__objects_3 = src/fortran/clunit.lo src/fortran/getlin.lo \
        src/fortran/stacki2d.lo src/fortran/stackc2i.lo \
        src/fortran/isinstring.lo src/fortran/readinter.lo \
        src/fortran/rewindinter.lo src/fortran/backspaceinter.lo \
-       src/fortran/relocstack.lo
+       src/fortran/relocstack.lo src/fortran/write_inter.lo \
+       src/fortran/read_inter.lo
 am_libscicore_algo_la_OBJECTS = $(am__objects_1) $(am__objects_2) \
        $(am__objects_3)
 libscicore_algo_la_OBJECTS = $(am_libscicore_algo_la_OBJECTS)
@@ -822,7 +823,9 @@ CORE_FORTRAN_SOURCES = \
     src/fortran/readinter.f \
     src/fortran/rewindinter.f \
     src/fortran/backspaceinter.f \
-    src/fortran/relocstack.f
+    src/fortran/relocstack.f \
+       src/fortran/write_inter.f \
+       src/fortran/read_inter.f
 
 GATEWAY_C_SOURCES = \
        sci_gateway/c/gw_core.c \
@@ -1380,6 +1383,10 @@ src/fortran/backspaceinter.lo: src/fortran/$(am__dirstamp) \
        src/fortran/$(DEPDIR)/$(am__dirstamp)
 src/fortran/relocstack.lo: src/fortran/$(am__dirstamp) \
        src/fortran/$(DEPDIR)/$(am__dirstamp)
+src/fortran/write_inter.lo: src/fortran/$(am__dirstamp) \
+       src/fortran/$(DEPDIR)/$(am__dirstamp)
+src/fortran/read_inter.lo: src/fortran/$(am__dirstamp) \
+       src/fortran/$(DEPDIR)/$(am__dirstamp)
 
 libscicore-algo.la: $(libscicore_algo_la_OBJECTS) $(libscicore_algo_la_DEPENDENCIES) $(EXTRA_libscicore_algo_la_DEPENDENCIES) 
        $(AM_V_CXXLD)$(CXXLINK) $(am_libscicore_algo_la_rpath) $(libscicore_algo_la_OBJECTS) $(libscicore_algo_la_LIBADD) $(LIBS)
index 9a4f5db..116f6ed 100644 (file)
@@ -90,6 +90,7 @@ static void Add_gui(void);
 static void Add_fftw(void);
 static void Add_Nan(void);
 static void Add_Inf(void);
+static void Add_io(void);
 static void Add_All_Variables(void);
 static void Add_Double_Constant(std::wstring _szName, double _dblReal, double _dblImg, bool _bComplex);
 static void Add_Poly_Constant(std::wstring _szName, std::wstring _szPolyVar, int _iRank, types::Double * _pdblReal);
@@ -749,6 +750,7 @@ static void Add_All_Variables(void)
     Add_fftw();
     Add_Nan();
     Add_Inf();
+    Add_io();
 }
 
 static void Add_Nan(void)
@@ -817,6 +819,14 @@ static void Add_z(void)
     Add_Poly_Constant(L"%z", L"z", 1, &dblCoef);
 }
 
+static void Add_io(void)
+{
+    types::Double * pVal = new types::Double(1, 2);
+    pVal->set(0, 5);
+    pVal->set(1, 6);
+    symbol::Context::getInstance()->put(symbol::Symbol(L"%io"), pVal);
+}
+
 static void Add_Poly_Constant(wstring _szName, wstring _szPolyVar, int _iRank, Double * _pdbl)
 {
     types::Polynom * pVar = new types::Polynom(_szPolyVar, 1, 1, &_iRank);
index b21425e..2da1a41 100644 (file)
                <File RelativePath="prompt.f"/>
                <File RelativePath="ptrback.f"/>
                <File RelativePath="putid.f"/>
+               <File RelativePath=".\read_inter.f"/>
                <File RelativePath=".\readinter.f"/>
                <File RelativePath="ref2val.f"/>
                <File RelativePath=".\rewindinter.f"/>
                <File RelativePath=".\stackr2d.f"/>
                <File RelativePath="whatln.f"/>
                <File RelativePath=".\withf2c.f"/>
+               <File RelativePath=".\write_inter.f"/>
                <File RelativePath="xerbla.f"/></Filter>
                <File RelativePath="..\..\sci_gateway\core_gateway.xml"/>
                <File RelativePath="..\..\Makefile.am"/></Files>
diff --git a/scilab/modules/core/src/fortran/read_inter.f b/scilab/modules/core/src/fortran/read_inter.f
new file mode 100644 (file)
index 0000000..6ae1ad2
--- /dev/null
@@ -0,0 +1,176 @@
+c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+c Copyright (C) INRIA
+c Copyright (C) ENPC
+c 
+c This file must be used under the terms of the CeCILL.
+c This source file is licensed as described in the file COPYING, which
+c you should have received as part of this distribution.  The terms
+c are also available at    
+c http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+
+      subroutine read_double_file(ID, dat, m, n, ierr)
+
+      double precision dat(*)
+      integer m,n
+      integer ierr
+      
+      do 70 i=1,m
+          read(ID,*,end=10,err=20) (dat(j*m+i),j=0, n-1)
+      
+ 70   continue 
+      return
+
+10      ierr = 1
+      return        
+20      ierr = 2
+      return 
+      
+      end
+
+      subroutine read_double_file_form(ID, form, dat,  m, n, ierr)
+
+      double precision dat(*)
+      integer m,n
+      character form*(*)
+      integer ierr
+      
+      do 71 i=1,m
+          read(ID,form,end=10,err=20) (dat(j*m+i),j=0, n-1)
+      
+ 71   continue    
+      return
+      
+10      ierr = 1
+      return        
+20      ierr = 2
+      return 
+      
+      end
+
+      subroutine read_double_line_file(ID, dat, n, ierr)
+
+      double precision dat(*)
+      integer n
+      integer m
+      integer ierr
+
+      read(ID,*,end=10,err=20) dat(1:n)
+      
+      return
+
+10      ierr = 1
+      return        
+20      ierr = 2
+      return 
+      
+      end
+      
+      subroutine read_double_line_file_form(ID, form, dat, n, ierr)
+
+      double precision dat(*)
+      integer n
+      character form*(*)
+      integer ierr
+
+      read(ID,form,end=10,err=20) dat(1:n)
+      
+      return
+
+10      ierr = 1
+      return        
+20      ierr = 2
+      return 
+      
+      end
+      
+       subroutine read_string_file(ID, form, dat, siz, ierr)
+
+      parameter (lch=4096)
+      character dat*(lch)
+      character form*(*)
+      integer siz,ierr
+                     
+      read(ID,form,end=10,err=20) dat
+      mn = lch;
+127   mn=mn-1
+      if(dat(mn:mn).eq.' ') goto 127
+            siz=max(1,mn)
+      return
+
+10      ierr = 1
+      return        
+20      ierr = 2
+      return  
+            
+         
+      end
+
+      subroutine read_string(form, dat, siz, ierr)
+
+      parameter (lch=4096)
+      character string*(lch)
+      character dat*(lch)
+      
+      character form*(*)
+      integer siz,ierr
+             
+      string=' '
+      call eventloopprompt(string,len(string),lline,status,0,iflag)
+      if(status.ne.0) goto 10
+      if (lline.eq.0) then
+        string(1:1)=' '
+        lline=1
+      endif
+      
+      read(string,form,end=10,err=20) dat
+      mn = lch;
+128   mn=mn-1
+      if(dat(mn:mn).eq.' ') goto 128
+            siz=max(1,mn)
+      return
+
+10      ierr = 1
+      return        
+20      ierr = 2
+      return  
+               
+      end  
+      
+      
+      subroutine read_int_file_form(ID, form, dat,  m, n, ierr)
+
+      integer dat(*)
+      integer m,n
+      character form*(*)
+      integer ierr
+      
+      do 72 i=1,m
+          read(ID,form,end=10,err=20) (dat(j*m+i),j=0, n-1)
+      
+ 72   continue
+      return
+      
+10      ierr = 1
+      return        
+20      ierr = 2
+      return 
+      
+      end
+      
+      subroutine read_int_line_file_form(ID, form, dat, n, ierr)
+
+      integer dat(*)
+      integer n
+      character form*(*)
+      integer ierr
+
+      read(ID,form,end=10,err=20) dat(1:n)
+      
+      return
+
+10      ierr = 1
+      return        
+20      ierr = 2
+      return 
+      
+      end
\ No newline at end of file
diff --git a/scilab/modules/core/src/fortran/write_inter.f b/scilab/modules/core/src/fortran/write_inter.f
new file mode 100644 (file)
index 0000000..a4e4bb5
--- /dev/null
@@ -0,0 +1,263 @@
+c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+c Copyright (C) INRIA
+c Copyright (C) ENPC
+c 
+c This file must be used under the terms of the CeCILL.
+c This source file is licensed as described in the file COPYING, which
+c you should have received as part of this distribution.  The terms
+c are also available at    
+c http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+
+      subroutine write_double(form, dat, m, n, ierr)
+c         write(buf(ib:),buf(1:nc),err=139)
+c     &       (stk(li+j*m),j=0,n-1)
+      parameter (lch=4096)
+      character buf*(lch)
+      double precision dat(*)
+      integer m,n,ierr
+      character form*(*)
+      
+      !write (*, '(f)') dat(1)
+      !write (*, '(f)') dat(2)
+      do 65 i=1,m
+          write(buf,form,err=20) (dat(j*m+i),j=0, n-1)
+          lb1=lch
+ 66       lb1=lb1-1
+          if(buf(lb1:lb1).eq.' ') goto 66
+      
+          io = 0
+          call basout(io, 6, buf(1:lb1))
+ 65   continue      
+      return
+      
+20    ierr = 2
+      return
+      
+      end
+
+      subroutine write_int(form, dat, m, n, ierr)
+c         write(buf(ib:),buf(1:nc),err=139)
+c     &       (stk(li+j*m),j=0,n-1)
+      parameter (lch=4096)
+      character buf*(lch)
+      integer dat(*)
+      integer m,n,ierr
+      character form*(*)
+      
+      !write (*, '(f)') dat(1)
+      !write (*, '(f)') dat(2)
+      do 67 i=1,m
+          write(buf,form,err=20) (dat(j*m+i),j=0, n-1)
+          lb1=lch
+ 68       lb1=lb1-1
+          if(buf(lb1:lb1).eq.' ') goto 68
+      
+          io = 0
+          call basout(io, 6, buf(1:lb1))
+ 67   continue      
+      return
+      
+20    ierr = 2
+      return
+      
+      end      
+
+
+      subroutine write_string(form, dat, ierr)
+
+      parameter (lch=4096)
+      character buf*(lch)
+      character form*(*)
+      character dat*(*)
+      integer ierr
+
+      
+      write(buf,form,err=20) dat
+      lb1=lch
+ 69   lb1=lb1-1
+      if(buf(lb1:lb1).eq.' ') goto 69
+      
+      call basout(io, 6, buf)
+      return
+      
+20    ierr = 2
+      return
+      
+      end
+
+      subroutine write_string_file(ID, form, dat, ierr)
+      
+      parameter (lch=4096)
+      character buf*(lch)
+      integer ID,ierr
+      character form*(*)
+      character dat*(*)
+      
+      do 99 i=1,len(dat),lch
+          if(len(dat) < (i+lch-1)) then
+              write(ID,form,err=20) dat(i:len(dat))
+          else          
+              write(ID,form,err=20) dat(i:(i+lch-1))
+          end if
+          
+99    continue
+      return
+      
+20    ierr = 2
+      return
+      
+      end  
+      
+      subroutine write_double_file(ID, form, dat,  m, n, ierr)
+
+      parameter (lch=4096)
+      character buf*(lch)
+      double precision dat(*)
+      integer m,n,ierr
+      character form*(*)
+      
+      
+      do 71 i=1,m
+          write(ID,form,err=20) (dat(j*m+i),j=0, n-1)
+      
+ 71   continue      
+      return
+      
+20    ierr = 2
+      return
+      
+      end
+
+      subroutine write_int_file(ID, form, dat, m, n, ierr)
+
+      parameter (lch=4096)
+      integer dat(*)
+      integer m,n,ierr
+      character form*(*)
+
+      do 72 i=1,m
+          write(ID,form,err=20) (dat(j*m+i),j=0, n-1)
+      
+ 72   continue      
+      return
+      
+20    ierr = 2
+      return
+      
+      end 
+
+      subroutine write_double_szsc(form, dat, szsc, m, n, ierr)
+
+      parameter (lch=4096)
+      character buf*(lch)
+      character buf2*(lch)
+      double precision dat(*)
+      integer m,n,szsc,ierr
+      character form*(*)
+      
+      do 73 i=1,m
+          write(buf,form,err=20) (dat(j*m+i),j=0, n-1)
+          lb1=lch
+ 74       lb1=lb1-1
+          if(buf(lb1:lb1).eq.' ') goto 74
+      
+      do 75 j=1,lb1,szsc
+          if(lb1 < (j+szsr-1)) then
+              write(buf2,*) buf(j:lb1)
+              
+          else          
+              write(buf2,*) buf(j:(j+szsc-1))
+          end if
+          
+        io = 0
+        call basout(io, 6, buf2)
+ 75   continue   
+ 73   continue      
+      return
+      
+20    ierr = 2
+      return
+      
+      end
+
+      subroutine write_double_szsc_file(ID, dat, szsc,  m, n,ierr)
+
+      parameter (lch=4096)
+      character buf*(lch)
+      double precision dat(*)
+      integer m,n,szsc,ierr
+      
+      do 76 i=1,m
+          write(ID,*,err=20) (dat(j*m+i),j=0, n-1)
+ 76   continue  
+      return
+      
+20    ierr = 2
+      return
+      
+      end
+
+      subroutine write_int_szsc(form, dat, szsc, m, n, ierr)
+
+      parameter (lch=4096)
+      character buf*(lch)
+      character buf2*(lch)
+      integer*4 dat(*)
+      integer*4 m,n,szsc,ierr
+      character form*(*)
+      
+      do 79 i=1,m
+          write(buf,form,err=20) (dat(j*m+i),j=0, n-1)
+          lb1=lch
+ 80       lb1=lb1-1
+          if(buf(lb1:lb1).eq.' ') goto 80
+      
+      do 81 j=1,lb1,szsc
+          if(lb1 < (j+szsr-1)) then
+              write(buf2,*) buf(j:lb1)
+              
+          else          
+              write(buf2,*) buf(j:(j+szsc-1))
+          end if
+          
+        io = 0
+        call basout(io, 6, buf2)
+ 81   continue   
+ 79   continue      
+      return
+      
+20    ierr = 2
+      return
+      
+      end
+
+      subroutine write_int_szsc_file(ID, form, dat, szsc,  m, n, ierr)
+
+      parameter (lch=4096)
+      character buf*(lch)
+      integer dat(*)
+      integer m,n,szsc,ierr
+      character form*(*)
+      
+      do 82 i=1,m
+          write(buf,form,err=20) (dat(j*m+i),j=0, n-1)
+          lb1=lch
+ 83       lb1=lb1-1
+          if(buf(lb1:lb1).eq.' ') goto 83
+      
+      do 84 j=1,lb1,szsc
+          if(lb1 < (j+szsc-1)) then
+              write(ID,*) buf(j:lb1)
+              
+          else          
+              write(ID,*) buf(j:(j+szsc-1))
+          end if
+
+ 84   continue   
+ 82   continue  
+      return
+      
+20    ierr = 2
+      return
+      
+      end
\ No newline at end of file
index 0ca8fe8..40036b9 100644 (file)
@@ -15,17 +15,14 @@ IO_CPP_SOURCES = \
     src/cpp/io_gw.cpp \
     src/cpp/loadlib.cpp
 
-
 GATEWAY_C_SOURCES = \
     sci_gateway/c/sci_read4b.c \
     sci_gateway/c/sci_getio.c \
     sci_gateway/c/sci_readb.c \
     sci_gateway/c/sci_getenv.c \
-    sci_gateway/c/sci_write.c \
     sci_gateway/c/sci_writeb.c \
     sci_gateway/c/sci_setenv.c \
     sci_gateway/c/gw_io.c \
-    sci_gateway/c/sci_read.c \
     sci_gateway/c/sci_getpid.c \
     sci_gateway/c/sci_write4b.c \
     sci_gateway/c/sci_save.c
@@ -36,6 +33,8 @@ GATEWAY_CPP_SOURCES = \
     sci_gateway/cpp/sci_file.cpp \
     sci_gateway/cpp/sci_host.cpp \
     sci_gateway/cpp/sci_unix.cpp \
+    sci_gateway/cpp/sci_read.cpp \
+    sci_gateway/cpp/sci_write.cpp \
     sci_gateway/cpp/sci_lib.cpp
 
 
index 091691f..35738ad 100644 (file)
@@ -184,11 +184,9 @@ am__objects_3 = sci_gateway/c/libsciio_la-sci_read4b.lo \
        sci_gateway/c/libsciio_la-sci_getio.lo \
        sci_gateway/c/libsciio_la-sci_readb.lo \
        sci_gateway/c/libsciio_la-sci_getenv.lo \
-       sci_gateway/c/libsciio_la-sci_write.lo \
        sci_gateway/c/libsciio_la-sci_writeb.lo \
        sci_gateway/c/libsciio_la-sci_setenv.lo \
        sci_gateway/c/libsciio_la-gw_io.lo \
-       sci_gateway/c/libsciio_la-sci_read.lo \
        sci_gateway/c/libsciio_la-sci_getpid.lo \
        sci_gateway/c/libsciio_la-sci_write4b.lo \
        sci_gateway/c/libsciio_la-sci_save.lo
@@ -197,6 +195,8 @@ am__objects_4 = sci_gateway/cpp/libsciio_la-sci_genlib.lo \
        sci_gateway/cpp/libsciio_la-sci_file.lo \
        sci_gateway/cpp/libsciio_la-sci_host.lo \
        sci_gateway/cpp/libsciio_la-sci_unix.lo \
+       sci_gateway/cpp/libsciio_la-sci_read.lo \
+       sci_gateway/cpp/libsciio_la-sci_write.lo \
        sci_gateway/cpp/libsciio_la-sci_lib.lo
 am_libsciio_la_OBJECTS = $(am__objects_3) $(am__objects_4)
 libsciio_la_OBJECTS = $(am_libsciio_la_OBJECTS)
@@ -583,11 +583,9 @@ GATEWAY_C_SOURCES = \
     sci_gateway/c/sci_getio.c \
     sci_gateway/c/sci_readb.c \
     sci_gateway/c/sci_getenv.c \
-    sci_gateway/c/sci_write.c \
     sci_gateway/c/sci_writeb.c \
     sci_gateway/c/sci_setenv.c \
     sci_gateway/c/gw_io.c \
-    sci_gateway/c/sci_read.c \
     sci_gateway/c/sci_getpid.c \
     sci_gateway/c/sci_write4b.c \
     sci_gateway/c/sci_save.c
@@ -598,6 +596,8 @@ GATEWAY_CPP_SOURCES = \
     sci_gateway/cpp/sci_file.cpp \
     sci_gateway/cpp/sci_host.cpp \
     sci_gateway/cpp/sci_unix.cpp \
+    sci_gateway/cpp/sci_read.cpp \
+    sci_gateway/cpp/sci_write.cpp \
     sci_gateway/cpp/sci_lib.cpp
 
 libsciio_la_CPPFLAGS = \
@@ -856,8 +856,6 @@ sci_gateway/c/libsciio_la-sci_readb.lo: sci_gateway/c/$(am__dirstamp) \
 sci_gateway/c/libsciio_la-sci_getenv.lo:  \
        sci_gateway/c/$(am__dirstamp) \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
-sci_gateway/c/libsciio_la-sci_write.lo: sci_gateway/c/$(am__dirstamp) \
-       sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/c/libsciio_la-sci_writeb.lo:  \
        sci_gateway/c/$(am__dirstamp) \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
@@ -866,8 +864,6 @@ sci_gateway/c/libsciio_la-sci_setenv.lo:  \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/c/libsciio_la-gw_io.lo: sci_gateway/c/$(am__dirstamp) \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
-sci_gateway/c/libsciio_la-sci_read.lo: sci_gateway/c/$(am__dirstamp) \
-       sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/c/libsciio_la-sci_getpid.lo:  \
        sci_gateway/c/$(am__dirstamp) \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
@@ -897,6 +893,12 @@ sci_gateway/cpp/libsciio_la-sci_host.lo:  \
 sci_gateway/cpp/libsciio_la-sci_unix.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libsciio_la-sci_read.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libsciio_la-sci_write.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/cpp/libsciio_la-sci_lib.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
@@ -922,12 +924,10 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libsciio_la-sci_getenv.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libsciio_la-sci_getio.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libsciio_la-sci_getpid.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libsciio_la-sci_read.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libsciio_la-sci_read4b.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libsciio_la-sci_readb.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libsciio_la-sci_save.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libsciio_la-sci_setenv.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libsciio_la-sci_write.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libsciio_la-sci_write4b.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libsciio_la-sci_writeb.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_file.Plo@am__quote@
@@ -935,7 +935,9 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_host.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_lib.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_load.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_read.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_unix.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_write.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciio_algo_la-getenvc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciio_algo_la-getpidc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciio_algo_la-setenvc.Plo@am__quote@
@@ -1031,13 +1033,6 @@ sci_gateway/c/libsciio_la-sci_getenv.lo: sci_gateway/c/sci_getenv.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libsciio_la-sci_getenv.lo `test -f 'sci_gateway/c/sci_getenv.c' || echo '$(srcdir)/'`sci_gateway/c/sci_getenv.c
 
-sci_gateway/c/libsciio_la-sci_write.lo: sci_gateway/c/sci_write.c
-@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libsciio_la-sci_write.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libsciio_la-sci_write.Tpo -c -o sci_gateway/c/libsciio_la-sci_write.lo `test -f 'sci_gateway/c/sci_write.c' || echo '$(srcdir)/'`sci_gateway/c/sci_write.c
-@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libsciio_la-sci_write.Tpo sci_gateway/c/$(DEPDIR)/libsciio_la-sci_write.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='sci_gateway/c/sci_write.c' object='sci_gateway/c/libsciio_la-sci_write.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libsciio_la-sci_write.lo `test -f 'sci_gateway/c/sci_write.c' || echo '$(srcdir)/'`sci_gateway/c/sci_write.c
-
 sci_gateway/c/libsciio_la-sci_writeb.lo: sci_gateway/c/sci_writeb.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libsciio_la-sci_writeb.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libsciio_la-sci_writeb.Tpo -c -o sci_gateway/c/libsciio_la-sci_writeb.lo `test -f 'sci_gateway/c/sci_writeb.c' || echo '$(srcdir)/'`sci_gateway/c/sci_writeb.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libsciio_la-sci_writeb.Tpo sci_gateway/c/$(DEPDIR)/libsciio_la-sci_writeb.Plo
@@ -1059,13 +1054,6 @@ sci_gateway/c/libsciio_la-gw_io.lo: sci_gateway/c/gw_io.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libsciio_la-gw_io.lo `test -f 'sci_gateway/c/gw_io.c' || echo '$(srcdir)/'`sci_gateway/c/gw_io.c
 
-sci_gateway/c/libsciio_la-sci_read.lo: sci_gateway/c/sci_read.c
-@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libsciio_la-sci_read.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libsciio_la-sci_read.Tpo -c -o sci_gateway/c/libsciio_la-sci_read.lo `test -f 'sci_gateway/c/sci_read.c' || echo '$(srcdir)/'`sci_gateway/c/sci_read.c
-@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libsciio_la-sci_read.Tpo sci_gateway/c/$(DEPDIR)/libsciio_la-sci_read.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='sci_gateway/c/sci_read.c' object='sci_gateway/c/libsciio_la-sci_read.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libsciio_la-sci_read.lo `test -f 'sci_gateway/c/sci_read.c' || echo '$(srcdir)/'`sci_gateway/c/sci_read.c
-
 sci_gateway/c/libsciio_la-sci_getpid.lo: sci_gateway/c/sci_getpid.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libsciio_la-sci_getpid.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libsciio_la-sci_getpid.Tpo -c -o sci_gateway/c/libsciio_la-sci_getpid.lo `test -f 'sci_gateway/c/sci_getpid.c' || echo '$(srcdir)/'`sci_gateway/c/sci_getpid.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libsciio_la-sci_getpid.Tpo sci_gateway/c/$(DEPDIR)/libsciio_la-sci_getpid.Plo
@@ -1160,6 +1148,20 @@ sci_gateway/cpp/libsciio_la-sci_unix.lo: sci_gateway/cpp/sci_unix.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libsciio_la-sci_unix.lo `test -f 'sci_gateway/cpp/sci_unix.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_unix.cpp
 
+sci_gateway/cpp/libsciio_la-sci_read.lo: sci_gateway/cpp/sci_read.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libsciio_la-sci_read.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_read.Tpo -c -o sci_gateway/cpp/libsciio_la-sci_read.lo `test -f 'sci_gateway/cpp/sci_read.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_read.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_read.Tpo sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_read.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_read.cpp' object='sci_gateway/cpp/libsciio_la-sci_read.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libsciio_la-sci_read.lo `test -f 'sci_gateway/cpp/sci_read.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_read.cpp
+
+sci_gateway/cpp/libsciio_la-sci_write.lo: sci_gateway/cpp/sci_write.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libsciio_la-sci_write.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_write.Tpo -c -o sci_gateway/cpp/libsciio_la-sci_write.lo `test -f 'sci_gateway/cpp/sci_write.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_write.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_write.Tpo sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_write.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_write.cpp' object='sci_gateway/cpp/libsciio_la-sci_write.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libsciio_la-sci_write.lo `test -f 'sci_gateway/cpp/sci_write.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_write.cpp
+
 sci_gateway/cpp/libsciio_la-sci_lib.lo: sci_gateway/cpp/sci_lib.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libsciio_la-sci_lib.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_lib.Tpo -c -o sci_gateway/cpp/libsciio_la-sci_lib.lo `test -f 'sci_gateway/cpp/sci_lib.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_lib.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_lib.Tpo sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_lib.Plo
index ab7d0db..6452a61 100644 (file)
@@ -24,9 +24,9 @@ int sci_getenv(char *fname, void* pvApiCtx);
 int sci_setenv(char *fname, void* pvApiCtx);
 //IO_IMPEXP int sci_load(char *fname, void* pvApiCtx); Now in C++ in io_gw/sci_gateway/cpp/sci_load.cpp
 
-int sci_read(char *fname, unsigned long fname_len);
+//int sci_read(char *fname, unsigned long fname_len);
 int sci_oldsave(char *fname, unsigned long fname_len);
-int sci_write(char *fname, unsigned long fname_len);
+//int sci_write(char *fname, unsigned long fname_len);
 int sci_readb(char *fname, unsigned long fname_len);
 int sci_writb(char *fname, unsigned long fname_len);
 int sci_getpid(char *fname, unsigned long fname_len);
index 7e5060f..92f7079 100644 (file)
@@ -41,3 +41,5 @@ CPP_GATEWAY_PROTOTYPE(sci_file);
 CPP_GATEWAY_PROTOTYPE(sci_host);
 CPP_GATEWAY_PROTOTYPE(sci_unix);
 CPP_GATEWAY_PROTOTYPE(sci_lib);
+CPP_GATEWAY_PROTOTYPE(sci_write);
+CPP_GATEWAY_PROTOTYPE(sci_read);
diff --git a/scilab/modules/io/sci_gateway/c/sci_read.c b/scilab/modules/io/sci_gateway/c/sci_read.c
deleted file mode 100644 (file)
index fb92738..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2006 - INRIA - Allan CORNET
- *
- * 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.1-en.txt
- *
- */
-
-#include "gw_io.h"
-/*--------------------------------------------------------------------------*/
-extern int C2F(intread)(); /* fortran subroutine */
-/*--------------------------------------------------------------------------*/
-int sci_read(char *fname, unsigned long fname_len)
-{
-    //C2F(intread)();
-    return 0;
-}
-/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/io/sci_gateway/c/sci_write.c b/scilab/modules/io/sci_gateway/c/sci_write.c
deleted file mode 100644 (file)
index c13ed11..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2006 - INRIA - Allan CORNET
- *
- * 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.1-en.txt
- *
- */
-
-#include "gw_io.h"
-/*--------------------------------------------------------------------------*/
-extern int C2F(intwrite)(); /* fortran subroutine */
-/*--------------------------------------------------------------------------*/
-int sci_write(char *fname, unsigned long fname_len)
-{
-    //C2F(intwrite)();
-    return 0;
-}
-/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/io/sci_gateway/cpp/sci_read.cpp b/scilab/modules/io/sci_gateway/cpp/sci_read.cpp
new file mode 100644 (file)
index 0000000..8d2cc49
--- /dev/null
@@ -0,0 +1,774 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+* Copyright (C) 2015 - Scilab Enterprises - Sylvain GENIN
+*
+* 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
+*
+*/
+
+#include <string.h>
+#include "function.hxx"
+#include "io_gw.hxx"
+#include "string.hxx"
+#include "double.hxx"
+#include "int.hxx"
+#include "filemanager.hxx"
+
+
+extern "C"
+{
+#include "sci_malloc.h"
+#include "Scierror.h"
+#include "expandPathVariable.h"
+
+    extern int C2F(clunit)(int*, char const*, int*, int);
+
+    extern int C2F(read_double_file)(int* ID, double* dat, int* m, int* n, int* err);
+    extern int C2F(read_double_file_form)(int* ID, char* form, double* dat, int* m, int* n, int* err, int);
+    extern int C2F(read_double_line_file)(int* ID, double* dat, int* n, int* err);
+    extern int C2F(read_double_line_file_form)(int* ID, char* form, double* dat, int* n, int* err);
+
+    extern int C2F(read_int_file_form)(int* ID, char* form, int* dat, int* m, int* n, int* err, int);
+    extern int C2F(read_int_line_file_form)(int* ID, char* form, int* dat, int* n, int* err);
+
+    extern int C2F(read_string_file)(int* ID, char* form, char* dat, int* siz, int* err, int);
+    extern int C2F(read_string)(char* form, char* dat, int* siz, int* err, int);
+
+}
+
+using namespace types;
+
+int checkformatread(char* format);
+template<typename T>
+bool is_of_type(const std::string & Str);
+
+
+/*--------------------------------------------------------------------------*/
+Function::ReturnValue sci_read(typed_list &in, int _iRetCount, typed_list &out)
+{
+    int iID = 0;
+    int iAcces = 0;
+    int iRhs = (int)in.size();
+    char* pstFormat = NULL;
+
+    types::InternalType::ScilabType itTypeOfData = types::InternalType::ScilabDouble;
+
+    if (iRhs < 3 || iRhs > 5)
+    {
+        Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "write", 2, 4);
+        return Function::Error;
+    }
+
+    //file
+    if (in[0]->isString())
+    {
+        String* pSPath = in[0]->getAs<String>();
+
+        if (pSPath->isScalar() == false)
+        {
+            Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "write", 1);
+            return Function::Error;
+        }
+
+        int piMode[2] = { -1, 0};
+        char* pstFilename = wide_string_to_UTF8(pSPath->get(0));
+        int iErr = C2F(clunit)(&iID, pstFilename, piMode, (int)strlen(pstFilename));
+
+        if (iErr == 240)
+        {
+            Scierror(999, _("File \"%s\" already exists or directory write access denied.\n"), pstFilename);
+            FREE(pstFilename);
+            return Function::Error;
+        }
+
+        if (iErr == 241)
+        {
+            Scierror(999, _("File \"%s\" does not exist or read access denied.\n"), pstFilename);
+            FREE(pstFilename);
+            return Function::Error;
+        }
+
+        FREE(pstFilename);
+    }
+    else if (in[0]->isDouble())
+    {
+        Double* pDId = in[0]->getAs<Double>();
+        if (pDId->isScalar() == false)
+        {
+            Scierror(999, _("%s: Wrong type for input argument #%d : A real scalar expected.\n"), "write", 1);
+            return Function::Error;
+        }
+
+        iID = (int)pDId->get(0);
+        if (iID == -1)
+        {
+            iID = FileManager::getCurrentFile();
+        }
+    }
+    else
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d : A real scalar or file descriptor expected.\n"), "write", 1);
+        return Function::Error;
+    }
+
+    if (iRhs > 3)
+    {
+        int iPos = iRhs - 1;
+        if (in[iPos]->isString() == false)
+        {
+            Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "write", iRhs);
+            return Function::Error;
+        }
+
+        String* pSFormat = in[iPos]->getAs<String>();
+        if (pSFormat->isScalar() == false)
+        {
+            Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "write", iRhs);
+            return Function::Error;
+        }
+
+        //checkformat
+        pstFormat = wide_string_to_UTF8(pSFormat->get(0));
+
+        char cTypeData = checkformatread(pstFormat);
+        if (cTypeData == 0)
+        {
+            Scierror(999, _("Incorrect file or format.\n"));
+            return Function::Error;
+        }
+        switch (cTypeData)
+        {
+            case '1':
+                itTypeOfData = types::InternalType::ScilabDouble;
+                break;
+            case '2':
+                itTypeOfData = types::InternalType::ScilabInt32;
+                break;
+            case '3':
+                itTypeOfData = types::InternalType::ScilabBool;
+                break;
+            case '4':
+                itTypeOfData = types::InternalType::ScilabString;
+                break;
+            default:
+                break;
+        }
+
+    }
+
+    int error = 0;
+    int iRows = (int) in[1]->getAs<Double>()->get(0);
+    int iCols = (int) in[2]->getAs<Double>()->get(0);
+
+    //test dims
+    if ( (iCols <= 0) || (iRows == 0))
+    {
+        if (pstFormat != NULL)
+        {
+            FREE(pstFormat);
+        }
+        out.push_back(types::Double::Empty());
+        return Function::OK;
+    }
+    if (iRows < 0)
+    {
+        if (iID != 5 /*stdout*/)
+        {
+
+            switch (itTypeOfData)
+            {
+                case types::InternalType::ScilabDouble:
+                {
+                    iRows = 1;
+                    Double* pD = new types::Double(iRows, iCols, false);
+
+                    if (pstFormat == NULL)
+                    {
+                        while (error == 0)
+                        {
+                            double* pdData = new double[iCols];
+                            C2F(read_double_line_file)(&iID, pdData, &iCols, &error);
+                            if (error == 0)
+                            {
+                                pD->resize(iRows, iCols);
+                                for (int i = 0; i < iCols; i++)
+                                {
+                                    pD->set((iRows - 1), i, pdData[i]);
+                                }
+                                iRows++;
+                            }
+                            delete[] pdData;
+
+                        }
+
+                    }
+                    else
+                    {
+                        while (error == 0)
+                        {
+                            double* pdData = new double[iCols];
+                            C2F(read_double_line_file_form)(&iID, pstFormat, pdData, &iCols, &error);
+                            if (error == 0)
+                            {
+                                pD->resize(iRows, iCols);
+                                for (int i = 0; i < iCols; i++)
+                                {
+                                    pD->set((iRows - 1), i, pdData[i]);
+                                }
+                                iRows++;
+                            }
+                            delete[] pdData;
+                        }
+
+                    }
+
+                    if (error != 2)
+                    {
+                        out.push_back(pD);
+                    }
+                    else
+                    {
+                        delete pD;
+                    }
+
+                }
+                break;
+                case types::InternalType::ScilabInt32:
+                {
+
+                    iRows = 1;
+                    types::Int32* pI = new types::Int32(iRows, iCols);
+
+                    while (error == 0)
+                    {
+                        int* piData = new int[iCols];
+                        C2F(read_int_line_file_form)(&iID, pstFormat, piData, &iCols, &error);
+                        if (error == 0)
+                        {
+                            pI->resize(iRows, iCols);
+                            for (int i = 0; i < iCols; i++)
+                            {
+                                pI->set((iRows - 1), i, piData[i]);
+                            }
+                            iRows++;
+                        }
+                        delete[] piData;
+
+                    }
+
+                    if (error != 2)
+                    {
+                        out.push_back(pI);
+                    }
+                    else
+                    {
+                        delete pI;
+                    }
+                }
+                break;
+                case types::InternalType::ScilabString:
+                {
+
+                    if (iCols != 1)
+                    {
+                        Scierror(999, _("%s: Wrong input argument %d.\n"), "read", 3);
+                        return Function::Error;
+                    }
+                    else
+                    {
+                        bool bEndWrite = false;
+                        iRows = 1;
+                        String* pS = new types::String(iRows, iCols);
+
+                        for (; bEndWrite == false; iRows++)
+                        {
+                            char* pCt = (char *)MALLOC(sizeof(char) * 4096);
+                            int siz = 0;
+                            C2F(read_string_file)(&iID, pstFormat, pCt, &siz, &error, (int)strlen(pstFormat));
+
+                            if (error == 1)
+                            {
+                                bEndWrite = true;
+                            }
+                            else
+                            {
+                                char* pC = new char[(siz + 1)];
+                                pC[0] = '\0';
+                                strncat(pC, pCt, siz);
+                                pS->resize(iRows, iCols);
+                                pS->set((iRows - 1), (iCols - 1), pC);
+                                delete[] pC;
+
+                            }
+                            FREE(pCt);
+
+                        }
+
+                        if (error != 2)
+                        {
+                            out.push_back(pS);
+                        }
+                        else
+                        {
+                            delete pS;
+                        }
+                    }
+
+                }
+                break;
+                default:
+                    Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "write", 2);
+
+                    //close file
+                    if (in[0]->isString())
+                    {
+                        int piMode[2] = { 0, 0 };
+                        String* pSPath = in[0]->getAs<String>();
+                        char* pstFilename = wide_string_to_UTF8(pSPath->get(0));
+                        int  close = -iID;
+                        int iErr = C2F(clunit)(&close, pstFilename, piMode, (int)strlen(pstFilename));
+                        FREE(pstFilename);
+                    }
+                    return Function::Error;
+                    break;
+            }
+
+            //close file
+            if (in[0]->isString())
+            {
+                int piMode[2] = { 0, 0 };
+                String* pSPath = in[0]->getAs<String>();
+                char* pstFilename = wide_string_to_UTF8(pSPath->get(0));
+                int  close = -iID;
+                int iErr = C2F(clunit)(&close, pstFilename, piMode, (int)strlen(pstFilename));
+                FREE(pstFilename);
+            }
+        }
+        else//read from the console
+        {
+
+            switch (itTypeOfData)
+            {
+                case types::InternalType::ScilabDouble:
+                {
+                    iRows = 1;
+                    Double* pD = new types::Double(iRows, iCols, false);
+
+                    pstFormat = (char*)MALLOC(sizeof(char) * (strlen("(a)\0") + 1));
+                    pstFormat[0] = '(';
+                    pstFormat[1] = 'a';
+                    pstFormat[2] = ')';
+                    pstFormat[3] = '\0';
+
+                    bool bEndWrite = false;
+
+                    for (; (bEndWrite == false) && (error == 0); iRows++)
+                    {
+                        char* pCt = (char *)MALLOC(sizeof(char) * 4096);
+                        int siz = 0;
+                        C2F(read_string)(pstFormat, pCt, &siz, &error, (int)strlen(pstFormat));
+
+                        if ((siz == 1) && (pCt[0] == ' '))
+                        {
+                            bEndWrite = true;
+                        }
+                        else
+                        {
+                            char* pC = (char *)MALLOC(sizeof(char) * (siz + 1));
+                            pC[0] = '\0';
+                            strncat(pC, pCt, siz);
+                            FREE(pCt);
+
+                            char* pch;
+                            int iColsTempo = 0;
+                            pch = strtok(pC, " ");
+                            double* pdData = new double[iCols];
+                            while ((pch != NULL) && (error == 0) && (iColsTempo < iCols))
+                            {
+                                if (is_of_type<double>(pch))
+                                {
+
+                                    pdData[iColsTempo] = atof(pch);
+                                    iColsTempo++;
+                                }
+                                else
+                                {
+                                    error = 2;
+                                }
+                                pch = strtok(NULL, " ");
+                            }
+
+                            FREE(pC);
+
+                            if (iColsTempo != iCols)
+                            {
+                                FREE(pstFormat);
+
+                                delete[] pdData;
+                                delete pD;
+
+                                Scierror(999, _("End of file at line %d.\n"));
+                                return Function::Error;
+                            }
+                            else
+                            {
+                                pD->resize(iRows, iCols);
+                                for (int i = 0; i < iCols; i++)
+                                {
+                                    pD->set((iRows - 1), i, pdData[i]);
+                                }
+                            }
+                        }
+
+                    }
+
+                    if (error == 0)
+                    {
+                        out.push_back(pD);
+                    }
+                }
+                break;
+                case types::InternalType::ScilabInt32:
+                    Scierror(999, _("Incorrect file or format.\n"));
+                    return Function::Error;
+                case types::InternalType::ScilabString:
+                {
+                    if (iCols != 1)
+                    {
+                        Scierror(999, _("%s: Wrong input argument %d.\n"), "read", 3);
+                        return Function::Error;
+                    }
+                    else
+                    {
+                        bool bEndWrite = false;
+                        iRows = 1;
+                        String* pS = new types::String(iRows, iCols);
+
+                        for (; bEndWrite == false; iRows++)
+                        {
+                            char* pCt = (char *)MALLOC(sizeof(char) * 4096);
+                            int siz = 0;
+                            C2F(read_string)(pstFormat, pCt, &siz, &error, (int)strlen(pstFormat));
+                            if ((siz == 1) && (pCt[0] == ' '))
+                            {
+                                bEndWrite = true;
+                            }
+                            else
+                            {
+                                char* pC = new char[(siz + 1)];
+                                pC[0] = '\0';
+                                strncat(pC, pCt, siz);
+                                pS->resize(iRows, iCols);
+                                pS->set((iRows - 1), (iCols - 1), pC);
+                                delete[] pC;
+                            }
+                            FREE(pCt);
+
+                        }
+
+                        if (error == 0)
+                        {
+                            out.push_back(pS);
+                        }
+                        else
+                        {
+                            delete pS;
+                        }
+                    }
+                }
+                break;
+                default:
+                    break;
+            }
+        }
+    }
+    else
+    {
+        if (iID != 5 /*stdout*/)
+        {
+
+            switch (itTypeOfData)
+            {
+                case types::InternalType::ScilabDouble:
+                {
+                    Double* pD = new types::Double(iRows, iCols, false);
+                    double* pd = pD->get();
+
+                    if (pstFormat == NULL)
+                    {
+                        C2F(read_double_file)(&iID, pd, &iRows, &iCols, &error);
+                    }
+                    else
+                    {
+                        C2F(read_double_file_form)(&iID, pstFormat, pd, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                    }
+
+                    if (error == 0)
+                    {
+                        out.push_back(pD);
+                    }
+                    else
+                    {
+                        delete pD;
+                    }
+                }
+                break;
+                case types::InternalType::ScilabInt32:
+                {
+                    types::Int32* pI = new types::Int32(iRows, iCols);
+                    int* pi = pI->get();
+
+                    C2F(read_int_file_form)(&iID, pstFormat, pi, &iRows, &iCols, &error, (int)strlen(pstFormat));
+
+                    if (error == 0)
+                    {
+                        out.push_back(pI);
+                    }
+                    else
+                    {
+                        delete pI;
+                    }
+                }
+                break;
+                case types::InternalType::ScilabString:
+                {
+                    String* pS = new types::String(iRows, iCols);
+                    for (int i = 0; i < (iCols * iRows); i++)
+                    {
+                        char* pCt = (char *)MALLOC(sizeof(char) * 4096);
+                        int siz = 0;
+                        C2F(read_string_file)(&iID, pstFormat, pCt, &siz, &error, (int)strlen(pstFormat));
+                        char* pC = (char *)MALLOC(sizeof(char) * (siz + 1));
+                        strncat(pC, pCt, siz);
+                        pS->set(i, pC);
+                        FREE(pCt);
+                        FREE(pC);
+                    }
+
+                    if (error == 0)
+                    {
+                        out.push_back(pS);
+                    }
+                    else
+                    {
+                        delete pS;
+                    }
+                }
+                break;
+                default:
+                    Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "write", 2);
+
+                    //close file
+                    if (in[0]->isString())
+                    {
+                        int piMode[2] = { 0, 0 };
+                        String* pSPath = in[0]->getAs<String>();
+                        char* pstFilename = wide_string_to_UTF8(pSPath->get(0));
+                        int  close = -iID;
+                        int iErr = C2F(clunit)(&close, pstFilename, piMode, (int)strlen(pstFilename));
+                        FREE(pstFilename);
+                    }
+                    return Function::Error;
+                    break;
+            }
+
+            //close file
+            if (in[0]->isString())
+            {
+                int piMode[2] = { 0, 0 };
+                String* pSPath = in[0]->getAs<String>();
+                char* pstFilename = wide_string_to_UTF8(pSPath->get(0));
+                int  close = -iID;
+                int iErr = C2F(clunit)(&close, pstFilename, piMode, (int)strlen(pstFilename));
+                FREE(pstFilename);
+            }
+
+            if (error == 2)
+            {
+                Scierror(999, _("Incorrect file or format.\n"));
+                return Function::Error;
+            }
+
+        }
+        else//read from the console
+        {
+
+            switch (itTypeOfData)
+            {
+                case types::InternalType::ScilabDouble:
+                {
+                    Double* pD = new types::Double(iRows, iCols, false);
+
+                    pstFormat = (char*)MALLOC(sizeof(char) * (strlen("(a)\0") + 1));
+                    pstFormat[0] = '(';
+                    pstFormat[1] = 'a';
+                    pstFormat[2] = ')';
+                    pstFormat[3] = '\0';
+
+                    for (int i = 0; i < (iRows) && (error == 0); i++)
+                    {
+                        char* pCt = (char *)MALLOC(sizeof(char) * 4096);
+                        int siz = 0;
+                        C2F(read_string)(pstFormat, pCt, &siz, &error, (int)strlen(pstFormat));
+                        char* pC = (char *)MALLOC(sizeof(char) * (siz + 1));
+                        strncat(pC, pCt, siz);
+                        FREE(pCt);
+
+                        char* pch;
+                        int iColsTempo = 0;
+                        pch = strtok(pC, " ");
+                        while ((pch != NULL) && (error == 0))
+                        {
+                            if (is_of_type<double>(pch))
+                            {
+                                pD->set(i, iColsTempo, atof(pch));
+                                iColsTempo++;
+                            }
+                            else
+                            {
+                                error = 2;
+                            }
+                            pch = strtok(NULL, " ");
+                        }
+
+                        FREE(pC);
+
+                        if (iColsTempo != iCols)
+                        {
+                            delete pD;
+                            FREE(pstFormat);
+
+                            Scierror(999, _("End of file at line %d.\n"));
+                            return Function::Error;
+                        }
+                    }
+
+                    FREE(pstFormat);
+
+                    if (error == 0)
+                    {
+                        out.push_back(pD);
+                    }
+                    else
+                    {
+                        delete pD;
+                    }
+                }
+                break;
+                case types::InternalType::ScilabInt32:
+                    Scierror(999, _("Incorrect file or format.\n"));
+                    return Function::Error;
+                case types::InternalType::ScilabString:
+                {
+                    if (iCols != 1)
+                    {
+                        Scierror(999, _("%s: Wrong input argument %d.\n"), "read", 3);
+                        return Function::Error;
+                    }
+                    else
+                    {
+                        String* pS = new types::String(iRows, iCols);
+
+                        for (int i = 0; i < (iRows); i++)
+                        {
+                            char* pCt = (char *)MALLOC(sizeof(char) * 4096);
+                            int siz = 0;
+                            C2F(read_string)(pstFormat, pCt, &siz, &error, (int)strlen(pstFormat));
+                            char* pC = (char *)MALLOC(sizeof(char) * (siz + 1));
+                            strncat(pC, pCt, siz);
+                            pS->set(i, pC);
+                            FREE(pCt);
+                            FREE(pC);
+                        }
+
+
+                        if (error == 0)
+                        {
+                            out.push_back(pS);
+                        }
+                        else
+                        {
+                            delete pS;
+                        }
+                    }
+                }
+                break;
+                default:
+                    break;
+            }
+        }
+
+        if (error != 0)
+        {
+            Scierror(999, _("Incorrect file or format.\n"));
+            return Function::Error;
+        }
+
+    }
+
+    return Function::OK;
+}
+
+int checkformatread(char* format)
+{
+    char type1[] = { 'i', 'f', 'e', 'd', 'g', 'l', 'a', 'I', 'F', 'E', 'D', 'G', 'L', 'A' };
+    char type2[] = { '2', '1', '1', '1', '1', '3', '4', '2', '1', '1', '1', '1', '3', '4' };
+    int ret = 0;
+    int size = (int)strlen(format);
+    int count = 0;
+    if (size < 2 || format[0] != '(' || format[size - 1] != ')')
+    {
+        return 0;
+    }
+
+    for (int i = 1; i < size - 1; i++)
+    {
+        char c = format[i];
+        if (c == '\'')
+        {
+            if (count == 0)
+            {
+                count++;
+            }
+            else
+            {
+                count--;
+            }
+            continue;
+        }
+
+        for (int j = 0; j < sizeof(type1); j++)
+        {
+            if (c == type1[j])
+            {
+                if (ret == 0)
+                {
+                    ret = type2[j];
+                }
+
+                if (type2[j] != ret)
+                {
+                    return 0;
+                }
+
+                break;
+            }
+        }
+    }
+
+    return ret;
+}
+
+template<typename T>
+bool is_of_type(const std::string & Str)
+{
+    std::istringstream iss(Str);
+
+    T tmp;
+    return (iss >> tmp) && (iss.eof());
+}
\ No newline at end of file
diff --git a/scilab/modules/io/sci_gateway/cpp/sci_write.cpp b/scilab/modules/io/sci_gateway/cpp/sci_write.cpp
new file mode 100644 (file)
index 0000000..2fd2a56
--- /dev/null
@@ -0,0 +1,535 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+* Copyright (C) 2015 - Scilab Enterprises - Sylvain GENIN
+*
+* 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
+*
+*/
+
+#include <string.h>
+#include "function.hxx"
+#include "io_gw.hxx"
+#include "string.hxx"
+#include "double.hxx"
+#include "int.hxx"
+#include "filemanager.hxx"
+
+
+extern "C"
+{
+#include "sci_malloc.h"
+#include "Scierror.h"
+#include "expandPathVariable.h"
+
+    extern int C2F(clunit)(int*, char const*, int*, int);
+
+    extern int C2F(write_double)(char* form, double* dat, int* m, int* n, int* ierro, int);
+    extern int C2F(write_double_file)(int* ID, char* form, double* dat, int* m, int* n, int* ierro, int);
+    extern int C2F(write_double_szsc)(char* form, double* dat, int* szsr, int* m, int* n, int* ierro, int);
+    extern int C2F(write_double_szsc_file)(int* ID, double* dat, int* szsr, int* m, int* n, int* ierro, int);
+
+    extern int C2F(write_int)(char* form, int* dat, int* m, int* n, int* ierro, int);
+    extern int C2F(write_int_file)(int* ID, char* form, int* dat, int* m, int* n, int* ierro, int);
+    extern int C2F(write_int_szsc)(char* form, int* dat, int* szsr, int* m, int* n, int* ierro, int);
+    extern int C2F(write_int_szsc_file)(int* ID, char* form, int* dat, int* szsr, int* m, int* n, int* ierro, int);
+
+    extern int C2F(write_string)(char* form, char* dat, int* ierro, int, int);
+    extern int C2F(write_string_file)(int* ID, char* form, char* dat, int* ierro, int, int);
+
+}
+
+int checkformat(char* format);
+
+
+using namespace types;
+
+/*--------------------------------------------------------------------------*/
+Function::ReturnValue sci_write(typed_list &in, int _iRetCount, typed_list &out)
+{
+    int iID = 0;
+    int iAcces = 0;
+    int iRhs = (int)in.size();
+    char* pstFormat = NULL;
+
+    types::InternalType::ScilabType itTypeOfData = types::InternalType::ScilabDouble;
+
+    if (iRhs < 2 || iRhs > 4)
+    {
+        Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "write", 2, 4);
+        return Function::Error;
+    }
+
+    //file
+    if (in[0]->isString())
+    {
+        String* pSPath = in[0]->getAs<String>();
+
+        if (pSPath->isScalar() == false)
+        {
+            Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "write", 1);
+            return Function::Error;
+        }
+
+        int piMode[2] = {0, 0};
+        char* pstFilename = wide_string_to_UTF8(pSPath->get(0));
+        int iErr = C2F(clunit)(&iID, pstFilename, piMode, (int)strlen(pstFilename));
+
+        if (iErr == 240)
+        {
+            Scierror(999, _("File \"%s\" already exists or directory write access denied.\n"), pstFilename);
+            FREE(pstFilename);
+            return Function::Error;
+        }
+        FREE(pstFilename);
+    }
+    else if (in[0]->isDouble())
+    {
+        Double* pDId = in[0]->getAs<Double>();
+        if (pDId->isScalar() == false)
+        {
+            Scierror(999, _("%s: Wrong type for input argument #%d : A real scalar expected.\n"), "write", 1);
+            return Function::Error;
+        }
+
+        iID = (int)pDId->get(0);
+        if (iID == -1)
+        {
+            iID = FileManager::getCurrentFile();
+        }
+    }
+    else
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d : A real scalar or file descriptor expected.\n"), "write", 1);
+        return Function::Error;
+    }
+
+    if (iRhs == 4)
+    {
+        //iAccess is thrid parameter
+    }
+
+    int iRows = in[1]->getAs<types::GenericType>()->getRows();
+    int iCols;
+    if (in[1]->isString())
+    {
+        iCols = in[1]->getAs<types::GenericType>()->getSize();
+    }
+    else
+    {
+        iCols = in[1]->getAs<types::GenericType>()->getCols();
+    }
+
+    if (iRhs > 2)
+    {
+        int iPos = iRhs - 1;
+        if (in[iPos]->isString() == false)
+        {
+            Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "write", iRhs);
+            return Function::Error;
+        }
+
+        String* pSFormat = in[iPos]->getAs<String>();
+        if (pSFormat->isScalar() == false)
+        {
+            Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "write", iRhs);
+            return Function::Error;
+        }
+
+        //checkformat
+        pstFormat = wide_string_to_UTF8(pSFormat->get(0));
+
+        char cTypeData = checkformat(pstFormat);
+        if (cTypeData == 0)
+        {
+            Scierror(999, _("Incorrect file or format.\n"));
+            return Function::Error;
+        }
+        switch (cTypeData)
+        {
+            case '1':
+                itTypeOfData = types::InternalType::ScilabDouble;
+                break;
+            case '2':
+                itTypeOfData = types::InternalType::ScilabInt32;
+                break;
+            case '3':
+                itTypeOfData = types::InternalType::ScilabBool;
+                break;
+            case '4':
+                itTypeOfData = types::InternalType::ScilabString;
+                break;
+            default:
+                break;
+        }
+
+    }
+    else
+    {
+        switch (in[1]->getType())
+        {
+            case types::InternalType::ScilabInt32:
+            {
+                itTypeOfData = types::InternalType::ScilabInt32;
+                pstFormat = (char*)MALLOC(sizeof(char) * (strlen("(%d(1x,I4))\0") + (int)log10(iCols) + 2));
+                sprintf(pstFormat, "(%d(1x,I4))\0", iCols);
+                break;
+            }
+            case types::InternalType::ScilabDouble:
+            {
+                if (iID == 6)
+                {
+                    pstFormat = (char*)MALLOC(sizeof(char) * (strlen("((1x,1pd17.10))\0") + (int)log10(iCols) + 2));
+                    sprintf(pstFormat, "(%d(1x,1pd17.10))\0", iCols);
+                }
+                else
+                {
+                    pstFormat = (char*)MALLOC(sizeof(char) * (strlen("((1x,1pd17.10))\0") + (int)log10(iCols) + 2));
+                    sprintf(pstFormat, "(%d(1x,1pd17.10))\0", iCols);
+                }
+                break;
+            }
+            case types::InternalType::ScilabString:
+            {
+                itTypeOfData = types::InternalType::ScilabString;
+                pstFormat = (char*)MALLOC(sizeof(char) * (strlen("(a)\0") + 1));
+                sprintf(pstFormat, "(a)\0");
+                break;
+            }
+            default:
+            {
+                Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "write", 2);
+                return Function::Error;
+                break;
+            }
+        }
+    }
+
+    int error = 0;
+    if (iAcces == 0)
+    {
+        if (iID != 6 /*stdout*/)
+        {
+            //sequential
+            switch (in[1]->getType())
+            {
+                case types::InternalType::ScilabString:
+                {
+                    char* pd = NULL;
+                    types::String* pD = in[1]->getAs<String>();
+
+                    for (int i = 0; i < iCols; i++)
+                    {
+                        pd = wide_string_to_UTF8(pD->get(i));
+                        C2F(write_string_file)(&iID, pstFormat, pd, &error, (int)strlen(pstFormat), (int)strlen(pd));
+                        FREE(pd);
+                    }
+
+
+                }
+                break;
+                case types::InternalType::ScilabInt32:
+                {
+                    types::Int32* pI = in[1]->getAs<Int32>();
+                    int* pi = pI->get();
+
+                    if (itTypeOfData == in[1]->getType())
+                    {
+                        if (iRhs > 2)
+                        {
+                            C2F(write_int_file)(&iID, pstFormat, pi, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                        else
+                        {
+                            //we calculate the size for a set of data on a line
+                            int iConsoleWidth = ConfigVariable::getConsoleWidth();
+                            iConsoleWidth = ((int)(iConsoleWidth / 18)) * 18;
+                            C2F(write_int_szsc_file)(&iID, pstFormat, pi, &iConsoleWidth, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                    }
+                    else if (itTypeOfData == types::InternalType::ScilabDouble)
+                    {
+                        double* pd = new double [pI->getSize()];
+                        for (int i = 0; i < pI->getSize(); i++)
+                        {
+                            pd[i] = (double)pi[i];
+                        }
+
+                        if (iRhs > 2)
+                        {
+                            C2F(write_double_file)(&iID, pstFormat, pd, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                        else
+                        {
+                            //we calculate the size for a set of data on a line
+                            int iConsoleWidth = ConfigVariable::getConsoleWidth();
+                            iConsoleWidth = ((int)(iConsoleWidth / 18)) * 18;
+                            C2F(write_double_szsc_file)(&iID, pd, &iConsoleWidth, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+
+                        delete[] pd;
+
+                    }
+
+                }
+                break;
+                case types::InternalType::ScilabDouble:
+                {
+                    Double* pD = in[1]->getAs<Double>();
+                    double* pd = pD->get();
+
+                    if (itTypeOfData == in[1]->getType())
+                    {
+                        if (iRhs > 2)
+                        {
+                            C2F(write_double_file)(&iID, pstFormat, pd, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                        else
+                        {
+                            //we calculate the size for a set of data on a line
+                            int iConsoleWidth = ConfigVariable::getConsoleWidth();
+                            iConsoleWidth = ((int)(iConsoleWidth / 18)) * 18;
+                            C2F(write_double_szsc_file)(&iID, pd, &iConsoleWidth, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                    }
+                    else if (itTypeOfData == types::InternalType::ScilabInt32)
+                    {
+                        int* pi = new int [pD->getSize()];
+                        for (int i = 0; i < pD->getSize(); i++)
+                        {
+                            pi[i] = (int)pd[i];
+                        }
+
+                        if (iRhs > 2)
+                        {
+                            C2F(write_int_file)(&iID, pstFormat, pi, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                        else
+                        {
+                            //we calculate the size for a set of data on a line
+                            int iConsoleWidth = ConfigVariable::getConsoleWidth();
+                            iConsoleWidth = ((int)(iConsoleWidth / 18)) * 18;
+                            C2F(write_int_szsc_file)(&iID, pstFormat, pi, &iConsoleWidth, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+
+                        delete[] pi;
+                    }
+                }
+                break;
+                default:
+                    Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "write", 2);
+
+                    //close file
+                    if (in[0]->isString())
+                    {
+                        int piMode[2] = { 0, 0 };
+                        String* pSPath = in[0]->getAs<String>();
+                        char* pstFilename = wide_string_to_UTF8(pSPath->get(0));
+                        int  close = -iID;
+                        int iErr = C2F(clunit)(&close, pstFilename, piMode, (int)strlen(pstFilename));
+                        FREE(pstFilename);
+                    }
+
+                    return Function::Error;
+                    break;
+            }
+
+            //close file
+            if (in[0]->isString())
+            {
+                int piMode[2] = { 0, 0 };
+                String* pSPath = in[0]->getAs<String>();
+                char* pstFilename = wide_string_to_UTF8(pSPath->get(0));
+                int  close = -iID;
+                int iErr = C2F(clunit)(&close, pstFilename, piMode, (int)strlen(pstFilename));
+                FREE(pstFilename);
+            }
+
+        }
+        else
+        {
+            //direct
+
+            int iConsoleWidth = ConfigVariable::getConsoleWidth();
+            switch (in[1]->getType())
+            {
+                case types::InternalType::ScilabString:
+                {
+                    char* pd = NULL;
+                    types::String* pD = in[1]->getAs<String>();
+                    for (int i = 0; i < iCols; i++)
+                    {
+                        pd = wide_string_to_UTF8(pD->get(i));
+                        C2F(write_string)(pstFormat, pd, &error, (int)strlen(pstFormat), (int)strlen(pd));
+                        FREE(pd);
+                    }
+
+
+                }
+                break;
+                case types::InternalType::ScilabInt32 :
+                {
+                    types::Int32* pI = in[1]->getAs<Int32>();
+                    int* pi = pI->get();
+
+                    if (itTypeOfData == in[1]->getType())
+                    {
+                        if (iRhs > 2)
+                        {
+                            C2F(write_int)(pstFormat, pi, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                        else
+                        {
+                            //we calculate the size for a set of data on a line
+                            int iConsoleWidth = ConfigVariable::getConsoleWidth();
+                            iConsoleWidth = ((int)(iConsoleWidth / 18)) * 18;
+                            C2F(write_int_szsc)(pstFormat, pi, &iConsoleWidth, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                    }
+                    else if (itTypeOfData == types::GenericType::ScilabDouble)
+                    {
+                        double* pd = new double[pI->getSize()];
+                        for (int i = 0; i < pI->getSize(); i++)
+                        {
+                            pd[i] = (double)pi[i];
+                        }
+
+                        if (iRhs > 2)
+                        {
+                            C2F(write_double)(pstFormat, pd, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                        else
+                        {
+                            //we calculate the size for a set of data on a line
+                            int iConsoleWidth = ConfigVariable::getConsoleWidth();
+                            iConsoleWidth = ((int)(iConsoleWidth / 18)) * 18;
+                            C2F(write_double_szsc)(pstFormat, pd, &iConsoleWidth, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+
+                        delete[] pd;
+                    }
+                }
+                break;
+                case types::InternalType::ScilabDouble:
+                {
+                    Double* pD = in[1]->getAs<Double>();
+                    double* pd = pD->get();
+
+                    if (itTypeOfData == in[1]->getType())
+                    {
+                        if (iRhs > 2)
+                        {
+                            C2F(write_double)(pstFormat, pd, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                        else
+                        {
+                            //we calculate the size for a set of data on a line
+                            int iConsoleWidth = ConfigVariable::getConsoleWidth();
+                            iConsoleWidth = ((int)(iConsoleWidth / 18)) * 18;
+                            C2F(write_double_szsc)(pstFormat, pd, &iConsoleWidth, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                    }
+                    else if (itTypeOfData == types::GenericType::ScilabInt32)
+                    {
+                        int* pi = new int[pD->getSize()];
+                        for (int i = 0; i < pD->getSize(); i++)
+                        {
+                            pi[i] = (int)pd[i];
+                        }
+
+                        if (iRhs > 2)
+                        {
+                            C2F(write_int)(pstFormat, pi, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+                        else
+                        {
+                            //we calculate the size for a set of data on a line
+                            int iConsoleWidth = ConfigVariable::getConsoleWidth();
+                            iConsoleWidth = ((int)(iConsoleWidth / 18)) * 18;
+                            C2F(write_int_szsc)(pstFormat, pi, &iConsoleWidth, &iRows, &iCols, &error, (int)strlen(pstFormat));
+                        }
+
+                        delete[] pi;
+                    }
+                }
+                break;
+                default:
+                    Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "write", 2);
+                    return Function::Error;
+                    break;
+            }
+
+        }
+    }
+    else
+    {
+
+    }
+
+    if (pstFormat)
+    {
+        FREE(pstFormat);
+    }
+
+    if (error != 0)
+    {
+        Scierror(999, _("Incorrect file or format.\n"));
+        return Function::Error;
+    }
+
+    return Function::OK;
+}
+
+int checkformat(char* format)
+{
+    char type1[] = { 'i', 'f', 'e', 'd', 'g', 'l', 'a', 'I', 'F', 'E', 'D', 'G', 'L', 'A' };
+    char type2[] = { '2', '1', '1', '1', '1', '3', '4', '2', '1', '1', '1', '1', '3', '4' };
+    int ret = 0;
+    int size = (int)strlen(format);
+    int count = 0;
+    if (size < 2 || format[0] != '(' || format[size - 1] != ')')
+    {
+        return 0;
+    }
+
+    for (int i = 1; i < size - 1; i++)
+    {
+        char c = format[i];
+        if (c == '\'')
+        {
+            if (count == 0)
+            {
+                count++;
+            }
+            else
+            {
+                count--;
+            }
+            continue;
+        }
+
+        for (int j = 0; j < sizeof(type1); j++)
+        {
+            if (c == type1[j])
+            {
+                if (ret == 0)
+                {
+                    ret = type2[j];
+                }
+
+                if (type2[j] != ret)
+                {
+                    return 0;
+                }
+
+                break;
+            }
+        }
+    }
+
+    return ret;
+}
\ No newline at end of file
index 00ccd66..ce4dd3f 100644 (file)
@@ -9,3 +9,21 @@ clunit_
 readinter_
 rewindinter_
 backspaceinter_
+write_double_
+write_double_szsc_
+write_double_file_
+write_double_szsc_file_
+write_int_
+write_int_file_
+write_int_szsc_
+write_int_szsc_file_
+write_string_
+write_string_file_
+read_double_file_
+read_double_file_form_
+read_double_line_file_
+read_double_line_file_form_
+read_int_file_form_
+read_int_line_file_form_
+read_string_file_
+read_string_
\ No newline at end of file
index ffb28f8..df639f9 100644 (file)
@@ -32,5 +32,7 @@ int IoModule::Load()
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"getenv", &sci_getenv, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"setenv", &sci_setenv, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"lib", &sci_lib, MODULE_NAME));
+    symbol::Context::getInstance()->addFunction(Function::createFunction(L"write", &sci_write, MODULE_NAME));
+    symbol::Context::getInstance()->addFunction(Function::createFunction(L"read", &sci_read, MODULE_NAME));
     return 1;
 }
index f7258ab..b1f90c8 100644 (file)
@@ -99,7 +99,8 @@
       <AdditionalDependencies>core_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <PreLinkEvent>
-      <Command>lib /DEF:"$(ProjectDir)core_f_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core_f.lib" 1&gt;NUL 2&gt;NUL</Command>
+      <Command>lib /DEF:"$(ProjectDir)core_f_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core_f.lib" 1&gt;NUL 2&gt;NUL
+</Command>
     </PreLinkEvent>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
       <AdditionalDependencies>core_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <PreLinkEvent>
-      <Command>lib /DEF:"$(ProjectDir)core_f_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core_f.lib" 1&gt;NUL 2&gt;NUL</Command>
+      <Command>lib /DEF:"$(ProjectDir)core_f_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core_f.lib" 1&gt;NUL 2&gt;NUL
+</Command>
     </PreLinkEvent>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
       <AdditionalDependencies>core_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <PreLinkEvent>
-      <Command>lib /DEF:"$(ProjectDir)core_f_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core_f.lib" 1&gt;NUL 2&gt;NUL</Command>
+      <Command>lib /DEF:"$(ProjectDir)core_f_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core_f.lib" 1&gt;NUL 2&gt;NUL
+</Command>
     </PreLinkEvent>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
       <AdditionalDependencies>core_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <PreLinkEvent>
-      <Command>lib /DEF:"$(ProjectDir)core_f_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core_f.lib" 1&gt;NUL 2&gt;NUL</Command>
+      <Command>lib /DEF:"$(ProjectDir)core_f_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core_f.lib" 1&gt;NUL 2&gt;NUL
+</Command>
     </PreLinkEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="..\..\sci_gateway\cpp\sci_lib.cpp" />
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_read.cpp" />
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_write.cpp" />
     <ClCompile Include="..\..\sci_gateway\c\sci_getenv.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_getio.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_getpid.c" />
-    <ClCompile Include="..\..\sci_gateway\c\sci_read.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_read4b.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_readb.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_save.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_setenv.c" />
-    <ClCompile Include="..\..\sci_gateway\c\sci_write.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_write4b.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_writeb.c" />
     <ClCompile Include="io_gw.cpp" />
index c5c627d..563b7c7 100644 (file)
@@ -48,9 +48,6 @@
     <ClCompile Include="..\..\sci_gateway\c\sci_getpid.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\sci_gateway\c\sci_read.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\sci_gateway\c\sci_read4b.c">
       <Filter>Source Files</Filter>
     </ClCompile>
@@ -63,9 +60,6 @@
     <ClCompile Include="..\..\sci_gateway\c\sci_setenv.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\sci_gateway\c\sci_write.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\sci_gateway\c\sci_write4b.c">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="loadlib.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_write.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_read.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\dynlib_io_gw.h">
index e94fc1f..adfc27a 100644 (file)
 extern "C"
 {
 #include "basout.h"
+}
+
 int C2F(basout)(int *io, int *lunit, char *string, long int nbcharacters)
 {
-    char* strMsg = new char[nbcharacters+1];
+    char* strMsg = new char[nbcharacters + 1];
     *io = 0;
     memcpy(strMsg, string, nbcharacters);
     strMsg[nbcharacters] = '\0';
@@ -27,5 +29,4 @@ int C2F(basout)(int *io, int *lunit, char *string, long int nbcharacters)
     delete strMsg;
     return 0;
 }
-}