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

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

Initial import--MML version from SOLEIL@2013

File size: 3.3 KB
Line 
1function [UpdateFileFullName, BackupState]=idBackupFFWDTableFile(idName, CorrectorName, idMode)
2% Written by F. Briquez 30/03/2011
3% Saves a backup of a FFWD table used by the device server.
4% The backup is made in a directory called as idBackupDirectoryName in the
5% id directory (created if necessary).
6%
7% 1) Inputs : - idName : such as 'HU36_SIRIUS'
8%           : - CorrectorName : 'CHE', 'CHS', 'CVE' or 'CVS'
9%           : - idMode : 'ii' or 'x' for parallel or anti-parallel modes.
10%               (Not case-sensitive)
11% 2) Output : - UpdateFileFullName : String containing the full name where to copy the updated
12%               table, in the backup directory.
13%           : - BackupState : -1 : backup necessary (existing old table) but failed
14%                             1  : backup necessary and succeeded
15%                             0  : backup unnecessary (no existing old table)
16
17%% Initialisation
18idBackupDirectoryName='Backup_Of_FFWD_Tables';
19BackupFileSuffix='Backup';
20UpdateFileSuffix='Update';
21
22UpdateFileFullName='';
23BackupState=-1;
24%% Get name of the table used by the device
25FFWDTableFullFileName=idGetFFWDTableFullFileName(idName, CorrectorName, idMode);
26if (strcmp(FFWDTableFullFileName, ''))
27   fprintf('Error in ''idBackupFFWDTableFile'' : could not construct table file name\n');
28    return
29end
30
31%% Get name of the directory of the id
32idDirectoryName=getfamilydata('Directory',idName);
33if (exist(idDirectoryName, 'dir')~=7)
34   fprintf('Error in ''idBackupFFWDTableFile'' : could not find directory ''%s''\n', idDirectoryName);
35    return
36end
37
38%% Create the backup directory of the id if does not exist yet
39idBackupDirectoryFullName=fullfile(idDirectoryName, idBackupDirectoryName);
40if (exist(idBackupDirectoryFullName, 'dir')~=7)
41    Status=mkdir(idBackupDirectoryFullName);
42    if (Status==0)
43       fprintf('Error in ''idBackupFFWDTableFile'' : could not create backup directory ''%s''\n', idBackupDirectoryFullName);
44        return
45    end
46    if (exist(idBackupDirectoryFullName, 'dir')~=7)
47        fprintf('Error in ''idBackupFFWDTableFile'' : could not create backup directory ''%s''\n', idBackupDirectoryFullName);
48        return
49    end
50end
51
52[~, FFWDTableFileCoreName, ext, ~] = fileparts(FFWDTableFullFileName);
53
54%% If table exists, duplicates it to backup directory
55if (exist(FFWDTableFullFileName, 'file')==2) % Existing former table file => it is duplicated
56    BackupFileCoreName=[FFWDTableFileCoreName '_' BackupFileSuffix];
57    BackupFileName=appendtimestamp(BackupFileCoreName);
58    BackupFileName=[BackupFileName ext];
59    BackupFileFullName=fullfile(idBackupDirectoryFullName, BackupFileName);
60    Status=copyfile(FFWDTableFullFileName, BackupFileFullName);
61    if (Status==0)
62        fprintf('Error in ''idBackupFFWDTableFile'' : could not create backup file ''%s''\n', BackupFileFullName);
63        return
64    else
65        fprintf ('Old table copied in ''%s''\n', BackupFileFullName);
66        BackupState=1;
67    end
68else
69    fprintf('''idBackupFFWDTableFile'' : no existing previous table file ''%s'' to backup\n', FFWDTableFullFileName);
70    BackupState=0;
71end
72
73%% Construct and return full name of the new file
74UpdateFileCoreName=[FFWDTableFileCoreName '_' UpdateFileSuffix];
75UpdateFileName=appendtimestamp(UpdateFileCoreName);
76UpdateFileName=[UpdateFileName ext];
77UpdateFileFullName=fullfile(idBackupDirectoryFullName, UpdateFileName);
78
79   
80   
81   
Note: See TracBrowser for help on using the repository browser.