1 | function copymachineconfigfile(DataFileName, ToFileName) |
---|
2 | %COPYMACHINECONFIGFILE - Copies a lattice file to the golden file |
---|
3 | % copymachineconfigfile(DataFileName, ToFileName) |
---|
4 | % |
---|
5 | % Written by Greg Portmann |
---|
6 | |
---|
7 | if nargin < 1 |
---|
8 | DataFileName = ''; |
---|
9 | end |
---|
10 | |
---|
11 | if nargin < 2 |
---|
12 | ToFileName = 'Golden'; |
---|
13 | end |
---|
14 | |
---|
15 | |
---|
16 | % Get the file |
---|
17 | if isempty(DataFileName) |
---|
18 | DataDirectoryName = getfamilydata('Directory','ConfigData'); |
---|
19 | if isempty(DataDirectoryName) |
---|
20 | DataDirectoryName = getfamilydata('Directory','DataRoot'); |
---|
21 | end |
---|
22 | [DataFileName, DataDirectoryName, FilterIndex] = uigetfile('*.mat','Select the Machine Configuration File to Copy', DataDirectoryName); |
---|
23 | if FilterIndex == 0 |
---|
24 | fprintf(' File not copied (copymachineconfigfile)\n'); |
---|
25 | return; |
---|
26 | end |
---|
27 | else |
---|
28 | [DataDirectoryName, DataFileName, ExtName] = fileparts(DataFileName); |
---|
29 | DataDirectoryName = [DataDirectoryName, filesep]; |
---|
30 | DataFileName = [DataFileName, ExtName]; |
---|
31 | end |
---|
32 | |
---|
33 | |
---|
34 | % Where is it going |
---|
35 | if strcmpi(ToFileName, 'Golden') |
---|
36 | % Get the production file name (full path) |
---|
37 | % AD.OpsData.LatticeFile could have the full path else default to AD.Directory.OpsData |
---|
38 | FileName = getfamilydata('OpsData','LatticeFile'); |
---|
39 | [DirectoryName, FileName, Ext, VerNumber] = fileparts(FileName); |
---|
40 | if isempty(DirectoryName) |
---|
41 | DirectoryName = getfamilydata('Directory', 'OpsData'); |
---|
42 | end |
---|
43 | FileNameGolden = [FileName, '.mat']; |
---|
44 | FileName = fullfile(DirectoryName,[FileName, '.mat']); |
---|
45 | |
---|
46 | if exist(FileName, 'file') |
---|
47 | AnswerString = questdlg(strvcat(strvcat(strvcat('Are you sure you want to overwrite the default configuration file?',sprintf('%s',FileName)),'With file:'),[DataDirectoryName, DataFileName]),'Default Lattice','Yes','No','No'); |
---|
48 | else |
---|
49 | AnswerString = 'Yes'; |
---|
50 | end |
---|
51 | |
---|
52 | if strcmp(AnswerString,'Yes') |
---|
53 | DirStart = pwd; |
---|
54 | [DirectoryName, ErrorFlag] = gotodirectory(DirectoryName); |
---|
55 | cd(DirStart); |
---|
56 | else |
---|
57 | fprintf(' File not copied (copymachineconfigfile)\n'); |
---|
58 | return; |
---|
59 | end |
---|
60 | else |
---|
61 | FileName = ToFileName; |
---|
62 | end |
---|
63 | |
---|
64 | |
---|
65 | % Backup first |
---|
66 | if exist(FileName,'file') |
---|
67 | DirStart = pwd; |
---|
68 | %BackupDirectoryName = [getfamilydata('Directory','DataRoot') 'Backup' filesep]; |
---|
69 | %BackupDataFileName = prependtimestamp(FileNameGolden); |
---|
70 | BackupDirectoryName = [getfamilydata('Directory','ConfigData'), 'GoldenBackup', filesep]; |
---|
71 | |
---|
72 | try |
---|
73 | load(FileName,'ConfigSetpoint'); |
---|
74 | Fields = fieldnames(ConfigSetpoint); |
---|
75 | BackupDataFileName = prependtimestamp(FileNameGolden, ConfigSetpoint.(Fields{1}).Setpoint.TimeStamp); |
---|
76 | clear ConfigSetpoint |
---|
77 | catch |
---|
78 | fprintf(' Unknown time stamp on the old production lattice file, so backup file has the present time in the filename.\n'); |
---|
79 | BackupDataFileName = prependtimestamp(FileNameGolden); |
---|
80 | end |
---|
81 | |
---|
82 | [FinalDir, ErrorFlag] = gotodirectory(BackupDirectoryName); |
---|
83 | if ~ErrorFlag |
---|
84 | copyfile(FileName, [BackupDirectoryName, BackupDataFileName], 'f'); |
---|
85 | fprintf(' File %s backup to %s\n', FileName, [BackupDirectoryName, BackupDataFileName]); |
---|
86 | else |
---|
87 | fprintf(' Problem finding/creating backup directory, hence backup made to the present directory.\n'); |
---|
88 | copyfile(FileName, BackupDataFileName, 'f'); |
---|
89 | end |
---|
90 | cd(DirStart); |
---|
91 | |
---|
92 | % BackupDirectoryName = [getfamilydata('Directory','DataRoot') 'Backup' filesep]; |
---|
93 | % BackupDataFileName = prependtimestamp(FileName); |
---|
94 | % DirStart = pwd; |
---|
95 | % [FinalDir, ErrorFlag] = gotodirectory(BackupDirectoryName); |
---|
96 | % if ~ErrorFlag |
---|
97 | % copyfile([DirectoryName, FileName], [BackupDirectoryName, BackupDataFileName], 'f'); |
---|
98 | % fprintf(' File %s backup to %s\n', [DirectoryName, FileName], [BackupDirectoryName, BackupDataFileName]); |
---|
99 | % else |
---|
100 | % fprintf(' Problem finding/creating backup directory, hence backup made to ops directory.\n'); |
---|
101 | % copyfile([DirectoryName, FileName], [DirectoryName, BackupDataFileName], 'f'); |
---|
102 | % end |
---|
103 | end |
---|
104 | |
---|
105 | % Do the copy |
---|
106 | copyfile([DataDirectoryName, DataFileName], FileName, 'f'); |
---|
107 | fprintf(' File %s copied to %s\n', [DataDirectoryName, DataFileName], FileName); |
---|