source: MML/trunk/machine/SOLEIL/StorageRing/insertions/idSaveStruct.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 2.1 KB
Line 
1function 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
14res = '';
15DirStart = pwd;
16WrongDirectory=0;
17%% Check fileNameCore
18if strcmp(fileNameCore, '')
19        fprintf('idSaveStruct : fileNameCore ''%s'' is not correct\n', fileNameCore);
20end
21
22%% Get directory name and check idName
23DirectoryName = getfamilydata('Directory',idName);
24if isempty(DirectoryName)
25    WrongDirectory=1;
26else
27    [DirectoryName, WrongDirectory] = gotodirectory(DirectoryName);
28end
29if WrongDirectory
30    fprintf('idSaveStruct : idName ''%s'' is incorrect -> check idName or modify ''setoperationalmode.m''\n', idName)
31%       DirectoryName = '/home/operateur/GrpGMI/';
32    return
33end
34
35%% Add time if necessary
36if addTime
37    FileName=appendtimestamp(fileNameCore);
38else
39    FileName=fileNameCore;
40end
41
42%% Save structure
43save(FileName,'-struct', 'structToSave');
44
45%% Check the file is correctly created
46if (strcmp(FileName(length(FileName)-3:length(FileName)), '.mat')==0)
47    FileName=[FileName '.mat'];
48end
49fileID=fopen(FileName);
50if (fileID==-1)
51    fprintf ('idSaveStruct : file ''%s'' not created\n', FileName);
52    return
53else
54    Status=fclose(fileID);
55    if (Status==-1)
56        fprintf ('idSaveStruct : file ''%s'' could not be closed correctly\n', FileName);
57        return
58    end
59end
60% res = fullfile(DirectoryName, FileName);
61res = FileName;
62%% Go back to initial directory
63cd(DirStart);
64
65%% Display data if necessary
66if dispData ~= 0
67        fprintf('Sauvegarde:  %s\n', FileName);
68end
Note: See TracBrowser for help on using the repository browser.