1 | function res = idSaveStruct(structToSave, fileNameCore, idName, addTime, dispData) |
---|
2 | %% Description |
---|
3 | %Saves the structure "structToSave" into a .mat file. |
---|
4 | % 1)The name of the file is : - fileNameCore if addTime=0 |
---|
5 | % - fileNameCore with time information if addTime=1 |
---|
6 | % 2) The directory where the file is stored is defined by idName and setoperationalmode.m |
---|
7 | % (usually /home/Grp/GMI/HU36_SIRIUS, for instance) |
---|
8 | % 3) if dispData=1, displays the name of the file |
---|
9 | % 4) Returns full name of created file if succeeded, or '' if failed |
---|
10 | |
---|
11 | % Modified by F. Briquez 20/06/2011 : new input arg "addTime" in order to merge former scripts : idSaveStruct, idSaveStructNoTime and idSaveStruct_NoTime |
---|
12 | |
---|
13 | %% Init |
---|
14 | res = ''; |
---|
15 | DirStart = pwd; |
---|
16 | WrongDirectory=0; |
---|
17 | %% Check fileNameCore |
---|
18 | if strcmp(fileNameCore, '') |
---|
19 | fprintf('idSaveStruct : fileNameCore ''%s'' is not correct\n', fileNameCore); |
---|
20 | end |
---|
21 | |
---|
22 | %% Get directory name and check idName |
---|
23 | DirectoryName = getfamilydata('Directory',idName); |
---|
24 | if isempty(DirectoryName) |
---|
25 | WrongDirectory=1; |
---|
26 | else |
---|
27 | [DirectoryName, WrongDirectory] = gotodirectory(DirectoryName); |
---|
28 | end |
---|
29 | if WrongDirectory |
---|
30 | fprintf('idSaveStruct : idName ''%s'' is incorrect -> check idName or modify ''setoperationalmode.m''\n', idName) |
---|
31 | % DirectoryName = '/home/operateur/GrpGMI/'; |
---|
32 | return |
---|
33 | end |
---|
34 | |
---|
35 | %% Add time if necessary |
---|
36 | if addTime |
---|
37 | FileName=appendtimestamp(fileNameCore); |
---|
38 | else |
---|
39 | FileName=fileNameCore; |
---|
40 | end |
---|
41 | |
---|
42 | %% Save structure |
---|
43 | save(FileName,'-struct', 'structToSave'); |
---|
44 | |
---|
45 | %% Check the file is correctly created |
---|
46 | if (strcmp(FileName(length(FileName)-3:length(FileName)), '.mat')==0) |
---|
47 | FileName=[FileName '.mat']; |
---|
48 | end |
---|
49 | fileID=fopen(FileName); |
---|
50 | if (fileID==-1) |
---|
51 | fprintf ('idSaveStruct : file ''%s'' not created\n', FileName); |
---|
52 | return |
---|
53 | else |
---|
54 | Status=fclose(fileID); |
---|
55 | if (Status==-1) |
---|
56 | fprintf ('idSaveStruct : file ''%s'' could not be closed correctly\n', FileName); |
---|
57 | return |
---|
58 | end |
---|
59 | end |
---|
60 | % res = fullfile(DirectoryName, FileName); |
---|
61 | res = FileName; |
---|
62 | %% Go back to initial directory |
---|
63 | cd(DirStart); |
---|
64 | |
---|
65 | %% Display data if necessary |
---|
66 | if dispData ~= 0 |
---|
67 | fprintf('Sauvegarde: %s\n', FileName); |
---|
68 | end |
---|