1 | function UploadState=idUploadFFWDTableToDevice(FFWDTableWithArgs, idName, CorrectorName, idMode) |
---|
2 | %% Written by F.Briquez 25/04/2011 |
---|
3 | % Creates the FFWD table text file (used by the Device Server) containing the matrix 'FFWDTableWithArgs' |
---|
4 | % - Backup the old file in /home/operateur/GrpGMI/.../Backup_Of_FFWD_Tables |
---|
5 | % - Backup the new file in /home/operateur/GrpGMI/.../Backup_Of_FFWD_Tables |
---|
6 | % - Deletes the old file in /usr/Local/configFiles/InsertionFFTables/... |
---|
7 | % - Creates the new file in /usr/Local/configFiles/InsertionFFTables/... |
---|
8 | % 1) Inputs : FFWDTableWithArgs : matrix containing the FFWD correction currents with headers (phase and gap values as first column and first row) |
---|
9 | % : idName : such as 'HU36_SIRIUS' |
---|
10 | % : CorrectorName : 'CHE', 'CHS', 'CVE' or 'CVS' |
---|
11 | % : idMode : 'ii' or 'x' for parallel or anti-parallel modes. |
---|
12 | % (Not case-sensitive) |
---|
13 | % 2) Output : -1 if failed. 1 if succeeded |
---|
14 | |
---|
15 | %% |
---|
16 | UploadState=-1; |
---|
17 | |
---|
18 | %% If existing, backup of old FFWD table used by the Device Server |
---|
19 | [UpdateFileFullName, BackupState]=idBackupFFWDTableFile(idName, CorrectorName, idMode); |
---|
20 | if (BackupState==-1) |
---|
21 | fprintf('Error in ''idUploadFFWDTableToDevice'' : Backup of old FFWD table failed => New table was not uploaded\n'); |
---|
22 | return |
---|
23 | end |
---|
24 | TemporaryFFWDTableToCopyForBackupAndDeviceServer=FFWDTableWithArgs; |
---|
25 | |
---|
26 | %% Create backup of new FFWD table |
---|
27 | save (UpdateFileFullName, 'TemporaryFFWDTableToCopyForBackupAndDeviceServer', '-ascii'); |
---|
28 | if (exist(UpdateFileFullName, 'file')~=2) |
---|
29 | fprintf('Error in ''idUploadFFWDTableToDevice'' : could not create backup of new FFWD table file ''%s'' => New table was not uploaded\n', UpdateFileFullName); |
---|
30 | return |
---|
31 | end |
---|
32 | |
---|
33 | %% If existing, delete old FFWD table used by the Device Server |
---|
34 | FFWDTableFileName=idGetFFWDTableFullFileName(idName, CorrectorName, idMode); |
---|
35 | if (exist(FFWDTableFileName, 'file')==2) |
---|
36 | delete(FFWDTableFileName); |
---|
37 | if (exist(FFWDTableFileName, 'file')==2) |
---|
38 | fprintf ('Error in ''idUploadFFWDTableToDevice'' : could not delete old FFWD table used by the Device Server => New table was not uploaded\n'); |
---|
39 | return |
---|
40 | end |
---|
41 | end |
---|
42 | |
---|
43 | %% Create new FFWD table for Device Server |
---|
44 | |
---|
45 | save (FFWDTableFileName, 'TemporaryFFWDTableToCopyForBackupAndDeviceServer', '-ascii'); |
---|
46 | if (exist(FFWDTableFileName, 'file')~=2) |
---|
47 | fprintf('Error in ''idUploadFFWDTableToDevice'' : could not create new FFWD table file ''%s''\n', FFWDTableFileName); |
---|
48 | return |
---|
49 | end |
---|
50 | clear('TemporaryFFWDTableToCopyForBackupAndDeviceServer'); |
---|
51 | UploadState=1; |
---|
52 | end |
---|