1 | function [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 |
---|
18 | idBackupDirectoryName='Backup_Of_FFWD_Tables'; |
---|
19 | BackupFileSuffix='Backup'; |
---|
20 | UpdateFileSuffix='Update'; |
---|
21 | |
---|
22 | UpdateFileFullName=''; |
---|
23 | BackupState=-1; |
---|
24 | %% Get name of the table used by the device |
---|
25 | FFWDTableFullFileName=idGetFFWDTableFullFileName(idName, CorrectorName, idMode); |
---|
26 | if (strcmp(FFWDTableFullFileName, '')) |
---|
27 | fprintf('Error in ''idBackupFFWDTableFile'' : could not construct table file name\n'); |
---|
28 | return |
---|
29 | end |
---|
30 | |
---|
31 | %% Get name of the directory of the id |
---|
32 | idDirectoryName=getfamilydata('Directory',idName); |
---|
33 | if (exist(idDirectoryName, 'dir')~=7) |
---|
34 | fprintf('Error in ''idBackupFFWDTableFile'' : could not find directory ''%s''\n', idDirectoryName); |
---|
35 | return |
---|
36 | end |
---|
37 | |
---|
38 | %% Create the backup directory of the id if does not exist yet |
---|
39 | idBackupDirectoryFullName=fullfile(idDirectoryName, idBackupDirectoryName); |
---|
40 | if (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 |
---|
50 | end |
---|
51 | |
---|
52 | [~, FFWDTableFileCoreName, ext, ~] = fileparts(FFWDTableFullFileName); |
---|
53 | |
---|
54 | %% If table exists, duplicates it to backup directory |
---|
55 | if (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 |
---|
68 | else |
---|
69 | fprintf('''idBackupFFWDTableFile'' : no existing previous table file ''%s'' to backup\n', FFWDTableFullFileName); |
---|
70 | BackupState=0; |
---|
71 | end |
---|
72 | |
---|
73 | %% Construct and return full name of the new file |
---|
74 | UpdateFileCoreName=[FFWDTableFileCoreName '_' UpdateFileSuffix]; |
---|
75 | UpdateFileName=appendtimestamp(UpdateFileCoreName); |
---|
76 | UpdateFileName=[UpdateFileName ext]; |
---|
77 | UpdateFileFullName=fullfile(idBackupDirectoryFullName, UpdateFileName); |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | |
---|