Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.5.0 - English

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Scilab Help >> Files : Input/Output functions > mseek

mseek

sets current position in a binary file

Calling Sequence

mseek(n [,fd, flag])

Arguments

n

a scalar: the offset in a number of bytes.

fd

a scalar: a file descriptor returned by the function mopen. -1 stands for last opened file. Default value is -1.

flag

a string: specifies the origin. Default value 'set'.

Description

The function mseek sets the position of the next input or output operation on the stream fd. The new position is at the signed distance given by n bytes from the beginning, from the current position, or from the end of the file, according to the flag value which can be 'set', 'cur' or 'end'. This is the reason why n must be positive when flag is equal to 'set'.

mseek allows the file position indicator to be set beyond the end of the existing data in the file. If data is later written at this point, subsequent reads of data in the gap will return zero until data is actually written into the gap. mseek, by itself, does not extend the size of the file.

Examples

file3=fullfile(TMPDIR,'test3.bin');
fd1= mopen(file3,'wb');
for i=1:10
  mput(i,'d');
end 
mseek(0);
mput(678,'d');
mseek(0,fd1,'end');
mput(932,'d');
mclose(fd1)

fd1= mopen(file3,'rb');
res=mget(11,'d')
res1=[1:11]; res1(1)=678;res1($)=932;
if res1<>res then
  write(%io(2),'Bug');
end
mseek(0,fd1,'set');

// trying to read more than stored data 
res1=mget(100,'d',fd1);
if res1<>res then
  write(%io(2),'Bug');
end
meof(fd1)
mclearerr(fd1)
mclose(fd1);

See Also

  • mclose — closes an opened file
  • meof — checks if end of file has been reached
  • mfprintf — converts, formats, and writes data to a file
  • fprintfMat — writes a matrix in a file
  • mfscanf — reads input from the stream pointer stream (interface to the C fscanf function)
  • fscanfMat — reads a matrix from a text file
  • mget — reads byte or word in a given binary format and converts to a double type
  • mgetstr — reads a character string from a file
  • mopen — opens a file in Scilab
  • mprintf — converts, formats, and writes data to the main scilab window
  • mput — writes byte or word in a given binary format
  • mputstr — writes a character string in a file
  • mtell — Returns the offset of the current byte relative to the beginning of a file
  • mdelete — deletes file(s)
Report an issue
<< mputstr Files : Input/Output functions mtell >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Fri Apr 11 14:06:54 CEST 2014