File: mputl.sci

package info (click to toggle)
scilab 2.6-4
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 54,632 kB
  • ctags: 40,267
  • sloc: ansic: 267,851; fortran: 166,549; sh: 10,005; makefile: 4,119; tcl: 1,070; cpp: 233; csh: 143; asm: 135; perl: 130; java: 39
file content (37 lines) | stat: -rw-r--r-- 769 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function mputl(str,fd)
[lhs,rhs]=argn()
np=5000 //pack size
LF=ascii(10);CR=ascii(13)
if MSDOS then
  newline=CR+LF
else
  newline=LF
end
str=strcat(str,newline)+newline
n=length(str)
mp=floor(n/np)

if rhs==1 then //write to last opened file
  k1=1
  for i=1:mp
    mput(ascii(part(str,k1:k1+np)),'uc')
    k1=k1+np+1
  end  
  mput(ascii(part(str,k1:n)),'uc')
else
  if type(fd)==10 then // file given by its path
    opened=%t
    fil=fd
    [fd,ierr]=mopen(fil,'wb')
    if ierr~=0 then error('File '+fil+' cannot be opened for writing'),end
  else // file given by its logical unit
    opened=%f
  end
  k1=1
  for i=1:mp
    mput(ascii(part(str,k1:k1+np)),'uc',fd)
    k1=k1+np+1
  end  
  mput(ascii(part(str,k1:n)),'uc',fd);
  if opened then mclose(fd),end
end