Updates a variable in a GAUSS Data Archive, leaving no empty bytes if the updated variable is smaller or larger than the variable it is replacing.


retcode = gdaUpdateAndPack(filename, x, varname)
  • filename (string) – name of data file.
  • x (matrix) – array, string or string array, data.
  • varname (string) – variable name.

retcode (scalar) –

return code, 0 if successful, otherwise one of the following error codes:

1 Null file name.
2 File open error.
3 File write error.
4 File read error.
5 Invalid data file type.
8 Variable not found.
10 File contains no variables.
12 File truncate error.
14 File too large to be read on current platform.


// Generate random variable x
x = rndn(100, 50);

// Create GDA `myFile`
retcode1 = gdaCreate("myfile.gda", 1);

// Write `x`  to `myfile` as x1
retcode2 = gdaWrite("myfile.gda", x ,"x1");

// Generate random variable y
y = rndn(75, 5);

// Update x1 with y and pack
retcode3 = gdaUpdateAndPack("myfile.gda", y, "x1");


This command updates the variable varname in filename with the data contained in x. gdaUpdateAndPack() always writes the data in x over the specified variable in the file. If x is larger than the specified variable, then it first moves all subsequent data in the file to make room for the new data. If x is smaller, then gdaUpdateAndPack() writes the data, packs all of the subsequent data, leaving no empty bytes after the updated variable, and truncates the file.

This command uses disk space efficiently; however, it may be slow for large files (especially if the variable to be updated is one of the first variables in the file). If speed is a concern, you may want to use gdaUpdate() instead.

See also

Functions gdaUpdate(), gdaWrite()