loadstruct#
Purpose#
Loads a structure into memory from a file on the disk.
Format#
- { instance, retcode } = loadstruct(file_name, structure_type)#
- Parameters:
file_name (string) – name of file containing structure.
structure_type (string) – structure type.
- Returns:
instance (struct) – instance of the struct.
retcode (scalar) – 0 if successful, otherwise 1.
Examples#
Single Instance of Structure#
#include ds.sdf
struct DS p3;
{ p3, retc } = loadstruct("p2", "ds");
Array of structures#
First, define a new structure country, declare and instance countries, reshape it to an array, and save the structure to disk.
struct country
{
string name;
scalar population;
};
struct country countries;
countries = reshape(countries, 2, 1);
countries[1].name = "Canada";
countries[1].population = 37;
countries[2].name = "China";
countries[2].population = 1386;
retc = saveStruct(countries, "countries");
Now load the saved instance as a new instance countries_new
struct country countries_new;
countries_new = reshape(countries_new, 2, 1);
{ countries_new, retcode } = loadStruct("countries", "country");
Remarks#
instance can be an array of structures.