source: MML/trunk/machine/SOLEIL/common/cycling/magnetcycle.m @ 17

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

To have a stable version on the server.

  • Property svn:executable set to *
File size: 31.5 KB
Line 
1function magnetcycle(varargin)
2%MAGNETCYCLE - Standardize machine magnets
3%
4%  INPUTS
5%  1. LatticeFile -'Present' {Default} - cycle to present setpoints
6%                  'Golden'  - cycle to the golden lattice setpoints
7%                  'UserSelect' - cycle to a selected file (a pop up to choose will be displayed)
8%                   LatticeFilename - cycle to the ConfigSetpoint in that file
9%
10%  Optional input arguments
11%  2. Cells of Families - for instance {'CH','CV'} or {'QP'}
12%  3. 'Display' or 'NoDisplay' - to verify before standardizing and display results (or not)
13%  4. Machine type - 'LT1', 'LT2', 'StorageRing', 'Booster'
14%                     Default is given by mml via getfamilydata('SubMachine')
15%  5. 'NoApply' - just configure but does not start cycling
16%     'NoConfig'
17%
18%  EXAMPLES
19%  1. magnetcycle('Golden')
20%  2. magnetcycle('Golden',{'CH'}) % cycle only CH family to golden
21%  values
22%
23% See Also setcyclecurve, getcyclingcurve, plotcyclingcurve, LT1cycling, RINGcycling
24
25%
26%  Written by Laurent S. Nadolski
27
28% TODO: Display part, cycle single element, cycle set of families (not
29% all)
30
31DisplayFlag = 1;
32ApplyFlag = 1;
33
34LatticeFileDefault = 'Present';
35ConfigFlag = 0; % confirm before modifying cycling ramp
36
37%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38% Input parsing and checking %
39%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
41for i = length(varargin):-1:1
42    if strcmpi(varargin{i},'Present')
43        LatticeFile = 'Present';
44        varargin(i) = [];
45    elseif strcmpi(varargin{i},'Golden')
46        LatticeFile = 'Golden';
47        varargin(i) = [];
48    elseif strcmpi(varargin{i},'UserSelect')
49        LatticeFile = 'UserSelect';
50        varargin(i) = [];
51    elseif strcmpi(varargin{i},'Display')
52        DisplayFlag = 1;
53        varargin(i) = [];
54    elseif strcmpi(varargin{i},'NoDisplay')
55        DisplayFlag = 0;
56        varargin(i) = [];
57    elseif strcmpi(varargin{i},'LT1')
58        Machine = 'LT1';
59        varargin(i) = [];
60    elseif strcmpi(varargin{i},'Booster')
61        Machine = 'Booster';
62        varargin(i) = [];
63    elseif strcmpi(varargin{i},'LT2')
64        Machine = 'LT2';
65        varargin(i) = [];
66    elseif strcmpi(varargin{i},'StorageRing')
67        Machine = 'StorageRing';
68        varargin(i) = [];
69    elseif strcmpi(varargin{i},'NoConfig')
70        ConfigFlag = 0;
71    elseif strcmpi(varargin{i},'Config')
72        ConfigFlag = 1;
73    elseif strcmpi(varargin{i},'Apply')
74        ApplyFlag = 1;
75    elseif strcmpi(varargin{i},'NoApply')
76        ApplyFlag = 0;
77    elseif iscell(varargin{i})
78        Magnet = varargin{i};
79        varargin(i) = [];
80    end
81end
82
83if ~exist('LatticeFile','var')
84    LatticeFile = LatticeFileDefault;
85end
86
87if ~exist('Machine','var')
88    Machine = getfamilydata('SubMachine');
89end
90
91%%%%%%%%%%%%%%%%%%%%%%%%%%
92% Get the proper lattice %
93%%%%%%%%%%%%%%%%%%%%%%%%%%
94if strcmpi(LatticeFile, 'UserSelect')
95    [FileName, DirectoryName, FilterIndex] = uigetfile('*.mat', 'Select a Machine Configuration File for Standardization', getfamilydata('Directory', 'ConfigData'));
96    if FilterIndex == 0
97        if strcmpi(DisplayFlag, 'Display')
98            fprintf('   %s standardization cancelled\n', Machine);
99        end
100        return
101    end
102    try
103        load([DirectoryName FileName]);
104        Lattice = ConfigSetpoint;
105    catch
106        error('Problem getting data from machine configuration file\n%s',lasterr);
107    end
108    if strcmpi(DisplayFlag, 'Display')
109        fprintf('   Standardizing to the lattice file %s\n', [DirectoryName FileName]);
110    end
111elseif strcmpi(LatticeFile, 'Present')
112    % Present lattice
113    Lattice = getmachineconfig;
114    if strcmpi(DisplayFlag, 'Display')
115        fprintf('   Standardizing to the present lattice\n');
116    end
117elseif strcmpi(LatticeFile, 'Golden')
118    % Golden lattice
119    FileName = getfamilydata('OpsData', 'LatticeFile');
120    DirectoryName = getfamilydata('Directory', 'OpsData');
121    load([DirectoryName FileName]);
122
123    Lattice = ConfigSetpoint;
124    if strcmpi(DisplayFlag, 'Display')
125        fprintf('   Standardizing to the golden lattice %s\n', [DirectoryName FileName]);
126    end
127elseif ischar(LatticeFile)
128    load(LatticeFile);
129    Lattice = ConfigSetpoint;
130    if strcmpi(DisplayFlag, 'Display')
131        fprintf('   Standardizing to lattice file %s\n', LatticeFile);
132    end
133else
134    error('Not sure what lattice to cycle to!');
135end
136
137
138%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139% Query to begin measurement %
140%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141if strcmpi(DisplayFlag, 'Display')
142    tmp = questdlg(['Begin ' getfamilydata('Machine') ' standardization?'], ...
143        'MAGNETCYCLE','Yes','No','No');
144    if strcmpi(tmp,'No')
145        fprintf('   Lattice standardization cancelled\n');
146        return
147    end
148end
149
150%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151% Set cycling curves
152%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153Family = fieldnames(Lattice);
154
155% select only asked families
156if exist('Magnet','var') && ~isempty(Magnet)
157    if iscell(Magnet)
158        for k = 1:length(Magnet),
159            % For C13 Family special trick to reconstruct the family
160            if strcmpi(Magnet{k},'QC13')
161                LatticeN.QC13.Setpoint.Data = [
162                    Lattice.Q1.Setpoint.Data(7)
163                    Lattice.Q2.Setpoint.Data(7)
164                    Lattice.Q3.Setpoint.Data(7)
165                    Lattice.Q4.Setpoint.Data(13)
166                    Lattice.Q5.Setpoint.Data(13:14)
167                    Lattice.Q4.Setpoint.Data(14)
168                    Lattice.Q6.Setpoint.Data(19)
169                    Lattice.Q7.Setpoint.Data(19)
170                    Lattice.Q8.Setpoint.Data(19)
171                    ];
172                LatticeN.QC13.Setpoint.FamilyName = 'QC13';
173                FamilyN{k} = Magnet{k};
174            end
175            [temp flag] = findkeyword(Family,Magnet{k});
176            % Nanoscopium S1/S11
177            % if family not defined and S11 family
178            if (isempty(flag) && strcmp(Magnet{k}, 'S11'))
179                Lattice.S11 = Lattice.S1;
180                Lattice.S11.Setpoint.FamilyName = 'S11';
181                flag = 1;
182            end
183            if flag
184                LatticeN.(Magnet{k})  = Lattice.(Magnet{k});
185                FamilyN{k} = Magnet{k};
186            else
187                warning('Family %s not configured', Magnet{k});
188            end
189        end
190    end
191    Lattice = LatticeN;
192    Family  = FamilyN';
193    if ConfigFlag
194        cyclingconfiguration(Lattice, Family, varargin{:});
195    end
196else
197    disp('Select first a magnet!');
198    return;
199end
200
201%%%%%%%%%%%%%%%%%%%
202% Start the cycle %
203%%%%%%%%%%%%%%%%%%%
204if ApplyFlag
205
206    disp('  *****************************************************************');
207    disp('  **  Cycling will start!                                        **');
208    disp('  **  Are you sure to start cycling magnet                       **');
209    disp('  **                                                             **');
210    disp('  *****************************************************************');
211
212    tmp = questdlg('Start cycling magnet ?','MAGNETCYCLE','Yes','No','No');
213    if strcmpi(tmp,'No')
214        disp('Cycling cancelled')
215    else
216        disp('  ** Cycling starting                                     **');
217        Families = Family;
218        % Machine switchyard
219        switch Machine
220            case {'LT1','StorageRing','LT2'}
221                % start all selected families for cycling
222                h = waitbar(0,sprintf('Starting cycling on magnets: %2d %%',0));
223                for k1 = 1:length(Families),
224                    Family = Families{k1};
225                    % check if family is valid and return it in AO
226                    CycleFamily = ['Cycle' Family];
227                    cyclingcommand(CycleFamily,'Start');
228                    waitbar(k1/length(Families), h, sprintf('Cycling configuration progression: %2d %%', k1/length(Families)*100))
229                end
230                close(h);
231
232                CyclingEnd = 1;
233                % Cycling
234                while ~CyclingEnd
235                    fprintf('Cycling running, %s',datestr(now));
236                    pause(5); %seconds
237                    CyclingEnd = anacycling(Families);
238                end
239
240            case 'Booster'
241                disp('Not implemented yet');
242                return;
243
244            otherwise
245                error('Unknown machine %s',Machine);
246        end
247
248        if strcmpi(DisplayFlag, 'Display')
249            fprintf('   %s standardization complete\n', Machine);
250        end
251    end
252
253
254end
255
256%==========================================================================
257function curve = makecyclingcurve(Inom,Imax,MagnetType,varargin)
258% makecyclingcurve - Generates cycling curve used by Cycling Dserver
259%
260%  INPUTS
261%  1. Inom - Value at the end of cycling
262%  2. Imax - Maximum value
263%  3. MagnetType - Type of magnet ('BEND', 'Q1', 'CH', ...)
264%  Optionals parameters
265%  4. CyclingMode - Type of cycling process
266%                   'Simple' {default}
267%                   'Full'
268%                   'Startup' - after shutdown
269%  5. Machine type - 'LT1', 'LT2', 'StorageRing', 'Booster'
270%                     Default is given by mml via getfamilydata('Machine')
271%
272%
273%  OUTPUTS
274%  1. curve - 2D array discribing the cycling curve
275%             Structure of 2D array in multiple inputs
276%
277%  EXAMPLES
278%  1. makecurve(10,120,'CH')
279%  2. makecurve([10 12],[120 130],'CH')
280%
281%  NOTES
282%  1. MagnetType has to be the same for all vectorial inputs
283%
284%
285%  See Also plotcyclecurve
286
287%
288% Written by Laurent S. Nadolski
289
290% modification mars 2006 marie
291%CyclingMode = 'Simple';
292DisplayFlag = 0;
293
294%% INPUT PARSER
295for i = length(varargin):-1:1
296    if strcmpi(varargin{i},'Simple')
297        CyclingMode = 'Simple';
298        % modification mars 2006 marie
299        % se justifie par le fait que varargin n'a qu'un seul argument
300        %varargin(i) = [];
301    elseif strcmpi(varargin{i},'Full')
302        CyclingMode = 'Full';
303        % modification mars 2006 marie
304        %varargin(i) = [];
305    elseif strcmpi(varargin{i},'Startup')
306        CyclingMode = 'Startup';
307        % modification mars 2006 marie
308        %varargin(i) = [];
309    elseif strcmpi(varargin{i},'LT1')
310        Machine = 'LT1';
311        varargin(i) = [];
312    elseif strcmpi(varargin{i},'Booster')
313        Machine = 'Booster';
314        varargin(i) = [];
315    elseif strcmpi(varargin{i},'LT2')
316        Machine = 'LT2';
317        varargin(i) = [];
318    elseif strcmpi(varargin{i},'StorageRing')
319        Machine = 'StorageRing';
320        varargin(i) = [];
321    elseif strcmpi(varargin{i},'Display')
322        DisplayFlag = 1;
323        varargin(i) = [];
324    elseif strcmpi(varargin{i},'NoDisplay')
325        DisplayFlag = 0;
326        varargin(i) = [];
327    end
328end
329
330if ~ischar(MagnetType)
331    error('Magnet Type sould be a string')
332end
333
334if ~exist('Machine','var')
335    Machine = getfamilydata('SubMachine');
336end
337
338if isempty(Inom)
339    error('Empty nominal value for family %s, skip data');
340end
341
342% if not a single element
343if length(Inom) > 1
344    for k = 1:length(Inom)
345        curve{k} = makecyclingcurve(Inom(k),Imax(k),MagnetType,varargin{:});
346    end
347else
348
349    %% Main part
350    switch Machine
351        case 'LT1'
352            switch MagnetType
353                case {'BEND'}
354                    switch CyclingMode
355                        case 'Simple'
356                            curve = [[0 1] % current time
357                                [Imax 30]
358                                [Inom 1] ];
359                        case 'Full'
360                            %curve = [[0 10] % current time
361                            %[Imax 180]
362                            %[0.95*Inom 180]
363                            %[1.05*Inom 180]
364                            %[0.95*Inom 180]
365                            %[1.05*Inom 180]
366                            %[Inom 180] ];
367                            curve = [[0 10] % test !
368                                [Imax 10]
369                                [0.95*Inom 10]
370                                [1.05*Inom 10]
371                                [0.95*Inom 10]
372                                [1.05*Inom 10]
373                                [Inom 10] ];
374                        case 'Startup'
375                            curve = [[0 10] % current time
376                                [Imax 1800] % temps de chauffe 30 min
377                                [0.95*Inom 180]
378                                [1.05*Inom 180]
379                                [0.95*Inom 180]
380                                [1.05*Inom 180]
381                                [Inom 180] ];
382                        otherwise
383                            error('Unknown Mode: %s', CyclingMode);
384                    end
385                case {'QP'}
386                    switch CyclingMode
387                        case 'Simple'
388                            % test avec temps plus courts mars 2006
389                            curve = [[0 1] % current time
390                                [Imax 10]
391                                [Inom 1] ];
392                            %                             curve = [[0 1] % current time
393                            %                                 [Imax 30]
394                            %                                 [Inom 1] ];
395                        case 'Full'
396                            % on raccourcit les temps pour tests mars 2006
397                            curve = [[0 10] % current time
398                                [Imax 40]
399                                [0.95*Inom 10]
400                                [1.05*Inom 10]
401                                [0.95*Inom 10]
402                                [1.05*Inom 10]
403                                [Inom 10] ];
404                            %                             curve = [[0 10] % current time
405                            %                                 [Imax 180]
406                            %                                 [0.95*Inom 180]
407                            %                                 [1.05*Inom 180]
408                            %                                 [0.95*Inom 180]
409                            %                                 [1.05*Inom 180]
410                            %                                 [Inom 10] ];
411                        case 'Startup'
412                            % test avec temps courts mars 2006
413                            curve = [[0 10] % current time
414                                [Imax 20] % temps de chauffe 10 min
415                                [0.95*Inom 10]
416                                [1.05*Inom 10]
417                                [0.95*Inom 10]
418                                [1.05*Inom 10]
419                                [Inom 20] ];
420                            %                             curve = [[0 10] % current time
421                            %                                 [Imax 600] % temps de chauffe 10 min
422                            %                                 [0.95*Inom 180]
423                            %                                 [1.05*Inom 180]
424                            %                                 [0.95*Inom 180]
425                            %                                 [1.05*Inom 180]
426                            %                                 [Inom 180] ];
427                        otherwise
428                            error('Unknown Mode: %s', CyclingMode);
429                    end
430                case {'CH','CV'}
431                    switch CyclingMode
432                        case {'Simple', 'Full','Startup'}
433                            curve = [[0 1] % current time
434                                [Imax 30]
435                                [Inom 1] ];
436                        otherwise
437                            error('Unknown Mode: %s', CyclingMode);
438                    end
439
440                otherwise
441                    error('Unknown magnet type: %s', MagnetType)
442            end
443        case 'LT2'
444            switch MagnetType
445                case {'BEND'}
446                    switch CyclingMode
447                        case 'Simple'
448                            curve = [[0 10] % current time
449                                [Imax 30]
450                                [Inom 10] ];
451                        case 'Full'
452                            %curve = [[0 10] % current time
453                            %[Imax 180]
454                            %[0.95*Inom 180]
455                            %[1.05*Inom 180]
456                            %[0.95*Inom 180]
457                            %[1.05*Inom 180]
458                            %[Inom 180] ];
459
460                            curve = [[0 10] %
461                                [Imax 60]
462                                [0.95*Inom 60]
463                                [1.05*Inom 60]
464                                [Inom 10] ];
465
466                        case 'Startup'
467                            curve = [[0 10] % current time
468                                [Imax 1800] % temps de chauffe 30 min
469                                [0.95*Inom 180]
470                                [1.05*Inom 180]
471                                [0.95*Inom 180]
472                                [1.05*Inom 180]
473                                [Inom 180] ];
474                        otherwise
475                            error('Unknown Mode: %s', CyclingMode);
476                    end
477                case {'QP'}
478                    switch CyclingMode
479                        case 'Simple'
480                            % test avec temps plus courts mars 2006
481                            curve = [[0 1] % current time
482                                [Imax 10]
483                                [Inom 1] ];
484                            %                             curve = [[0 1] % current time
485                            %                                 [Imax 30]
486                            %                                 [Inom 1] ];
487                        case 'Full'
488                            % on raccourcit les temps pour tests mars 2006
489                            curve = [[0 10] % current time
490                                [Imax 40]
491                                [0.95*Inom 10]
492                                [1.05*Inom 10]
493                                [0.95*Inom 10]
494                                [1.05*Inom 10]
495                                [Inom 10] ];
496                            %                             curve = [[0 10] % current time
497                            %                                 [Imax 180]
498                            %                                 [0.95*Inom 180]
499                            %                                 [1.05*Inom 180]
500                            %                                 [0.95*Inom 180]
501                            %                                 [1.05*Inom 180]
502                            %                                 [Inom 10] ];
503                        case 'Startup'
504                            % test avec temps courts mars 2006
505                            curve = [[0 10] % current time
506                                [Imax 20] % temps de chauffe 10 min
507                                [0.95*Inom 10]
508                                [1.05*Inom 10]
509                                [0.95*Inom 10]
510                                [1.05*Inom 10]
511                                [Inom 20] ];
512                            %                             curve = [[0 10] % current time
513                            %                                 [Imax 600] % temps de chauffe 10 min
514                            %                                 [0.95*Inom 180]
515                            %                                 [1.05*Inom 180]
516                            %                                 [0.95*Inom 180]
517                            %                                 [1.05*Inom 180]
518                            %                                 [Inom 180] ];
519                        otherwise
520                            error('Unknown Mode: %s', CyclingMode);
521                    end
522                case {'CH','CV'}
523                    switch CyclingMode
524                        case {'Simple', 'Full','Startup'}
525                            curve = [[0 1] % current time
526                                [Imax 30]
527                                [Inom 1] ];
528                        otherwise
529                            error('Unknown Mode: %s', CyclingMode);
530                    end
531
532                otherwise
533                    error('Unknown magnet type: %s', MagnetType)
534            end
535
536        case 'Booster'
537            error('%s: Not implemented yet', Machine)
538        case 'StorageRing'
539
540            switch MagnetType
541                case {'BEND'}
542                    switch CyclingMode
543                        case 'Simple'
544                            %                             curve = [[0 1] % current time
545                            %                                 [Imax 30]
546                            %                                 [Inom 1] ];
547                        case 'Full'
548                            % valeur initiale differente de zero car zero
549                            % impossible
550                            curve = [[20 10] %
551                                [Imax 60]
552                                [0.95*Inom 60]
553                                [1.05*Inom 60]
554                                [Inom 10] ];
555                        case 'Startup'
556                            curve = [[20 10] % current time
557                                [Imax 1800] % temps de chauffe 30 min
558                                [0.95*Inom 180]
559                                [1.05*Inom 180]
560                                [0.95*Inom 180]
561                                [1.05*Inom 180]
562                                [Inom 180] ];
563                        otherwise
564                            error('Unknown Mode: %s', CyclingMode);
565                    end
566                case {'Q1','Q2','Q3','Q4','Q5','Q6','Q7','Q8','Q9','Q10', ...
567                        'Q11', 'Q12','QC13', 'S11', 'S12'}
568                    % S11 and S12 powersupplies are of quadrupole type
569                    switch CyclingMode
570                        case 'Simple'
571                            % test avec temps plus courts
572                            curve = [[sign(Imax)*20 5] % current time non zero consigne
573                                [Imax 30]
574                                [Inom 5] ];
575                        case 'Full'
576                            % Add one cycle 29 August 2009
577%                             curve = [[sign(Imax)*20 10] % current time non zero consigne
578%                                 [Imax 30]
579%                                 [0.90*Inom 30]
580%                                 [1.10*Inom 30]
581%                                 [0.90*Inom 30]
582%                                 [1.10*Inom 30]
583%                                 [Inom 10] ];
584
585                            % nanoscopium 1.10*Inom is more than Imax !!
586                            curve = [[sign(Imax)*20 10] % current time non zero setpoint value
587                                [Imax  30]
588                                [0.90*Inom 30]
589                                [sign(Imax)*min([abs(Imax), 1.10*abs(Inom)]) 30]
590                                [0.90*Inom 30]
591                                [sign(Imax)*min([abs(Imax), 1.10*abs(Inom)]) 30]
592                                [Inom-sign(Imax)*2 5]
593                                [sign(Imax)*min(abs(Inom+sign(Imax)*2), abs(Imax)) 1]
594                                [Inom-sign(Imax)*2 1]
595                                [sign(Imax)*min(abs(Inom+sign(Imax)*2), abs(Imax)) 1]
596                                [Inom-sign(Imax)*2 1]
597                                [sign(Imax)*min(abs(Inom+sign(Imax)*2), abs(Imax)) 1]
598                                [Inom 1] ];
599                        case 'Startup'
600                            % test
601                            curve = [[sign(Imax)*20 10] % current time non zero setpoint value
602                                [Imax 30]
603                                [0.90*Inom 30]
604                                [sign(Imax)*min([abs(Imax), 1.10*abs(Inom)]) 30]
605                                [0.90*Inom 30]
606                                [sign(Imax)*min([abs(Imax), 1.10*abs(Inom)]) 30]
607                                [0.90*Inom 30]
608                                [sign(Imax)*min([abs(Imax), 1.10*abs(Inom)]) 30]
609                                [Inom 10] ];
610                        otherwise
611                            error('Unknown Mode: %s', CyclingMode);
612                    end
613                case {'S1','S2','S3','S4','S5','S6','S7','S8','S9','S10'}
614                    switch CyclingMode
615                        case 'Simple'
616                            % test avec temps plus courts mars 2006
617                            curve = [[0 1] % current time
618                                [Imax 10]
619                                [Inom 1] ];
620                        case 'Full'
621                            % Add one cycle 29 August 2009
622                            curve = [[0 10] % current time
623                                [Imax 30]
624                                [0.90*Inom 30]
625                                [sign(Imax)*min([abs(Imax), 1.10*abs(Inom)]) 30]
626                                [0.90*Inom 30]
627                                [sign(Imax)*min([abs(Imax), 1.10*abs(Inom)]) 30]
628                                [Inom 10] ];
629                        case 'Startup'
630                            curve = [[0 10] % current time
631                                [Imax 20] % temps de chauffe 10 min
632                                [0.90*Inom 60]
633                                [sign(Imax)*min([abs(Imax), 1.10*abs(Inom)]) 60]
634                                [0.90*Inom 60]
635                                [sign(Imax)*min([abs(Imax), 1.10*abs(Inom)]) 60]
636                                [Inom 20] ];
637                        otherwise
638                            error('Unknown Mode: %s', CyclingMode);
639                    end
640                case {'HCOR'}
641                    switch CyclingMode
642                        case 'Simple'
643                            %                             curve = [[0 1] % current time
644                            %                                 [Imax 30]
645                            %                                 [Inom 1] ];
646                        case 'Full'
647                            % valeur initiale differente de zero car zero
648                            % impossible
649                            curve = [[0 1] %
650                                [Imax 1]
651                                [-Imax 1]
652                                [0 1]
653                                [Inom 1]];
654                        case 'Startup'
655                            %
656                            %
657                            %
658                        otherwise
659                            error('Unknown Mode: %s', CyclingMode);
660                    end
661                   
662                case {'VCOR'}
663                    switch CyclingMode
664                        case 'Simple'
665                            %                             curve = [[0 1] % current time
666                            %                                 [Imax 30]
667                            %                                 [Inom 1] ];
668                        case 'Full'
669                            % valeur initiale differente de zero car zero
670                            % impossible
671                            curve = [[0 1] %
672                                [Imax 1]
673                                [-Imax 1]
674                                [0 1]
675                                [Inom 1] ];
676                        case 'Startup'
677                            %
678                            %
679                            %
680                           
681                        otherwise
682                            error('Unknown Mode: %s', CyclingMode);
683                    end
684                case {'QT'}
685                    switch CyclingMode
686                        case 'Simple'
687                            %                             curve = [[0 1] % current time
688                            %                                 [Imax 30]
689                            %                                 [Inom 1] ];
690                        case 'Full'
691                            % valeur initiale differente de zero car zero
692                            % impossible
693                            curve = [[0 1] %
694                                [Imax 1]
695                                [-Imax 1]
696                                [0 1]
697                                [Inom 1] ];
698                        case 'Startup'
699                            %
700                            %
701                            %
702                           
703                        otherwise
704                            error('Unknown Mode: %s', CyclingMode);
705                    end
706                otherwise
707                    error('Unknown magnet type: %s', MagnetType)
708            end
709        otherwise
710            error('Unknown machine: %s', Machine);
711    end
712
713    if DisplayFlag
714        fprintf(1,'%s : Inom = %f Imax= %f \n', ...
715            CycleAO.DeviceName, CycleAO.Inom, CycleAO.Imax);
716        plotcyclingcurve(curve);
717    end
718end
719%==========================================================================
720function CyclingEnd = anacycling(Families)
721%
722%
723%
724
725%
726% Written by Laurent S. Nadolski
727
728for k1=1:length(Families),
729    CycleFamily = ['Cycle' Families{k1}];
730    [CycleIndex, CycleAO] = isfamily(CycleFamily);
731
732    rep = tango_group_command_inout2(CycleAO.GroupId,'State',1,0);
733    Status = rep.replies.obj_name;
734    rep = tango_group_read_attribute(CycleAO.GroupId,'totalProgression');
735    totalProgression = rep.replies.value;
736end
737
738% look whether all cycling precessus are done
739if min(totalProgression) ~= 100
740    CyclingEnd = 0;
741else
742    CylclingEnd = 1;
743end
744
745% look for States and error
746totalProgression;
747
748%==========================================================================
749function cyclingconfiguration(Lattice, Family, varargin)
750% cyclingconfiguration
751%
752%  INPUTS
753%  1. Lattice - Structure of setpoints
754%  2. Family - Families to cycle to
755%
756%  See Also magnetcycle, setcyclecurve
757
758%
759% Written by Laurent S. Nadolski
760
761%TODO if not a tango group --> treat single case
762
763DisplayFlag = 1;
764ConfigFlag  = 0;
765
766
767if iscell(Family)
768    % Build input line
769    h = waitbar(0,sprintf('Cycling configuration progression: %2.0f %%',0));
770    for k = 1:length(Family)
771        cyclingconfiguration(Lattice,Family{k},varargin{:})
772        waitbar(k/length(Family), h, sprintf('Cycling configuration progression: %2.0f %%',k/length(Family)*100))
773    end
774    close(h);
775else
776    %% INPUT PARSER
777    for i = length(varargin):-1:1
778        if strcmpi(varargin{i},'Display')
779            DisplayFlag = 1;
780            varargin(i) = [];
781        elseif strcmpi(varargin{i},'NoDisplay')
782            DisplayFlag = 0;
783            varargin(i) = [];
784        elseif strcmpi(varargin{i},'NoConfig')
785            ConfigFlag = 0;
786            varargin(i) = [];
787        end
788    end
789    % Build Cycling configuration name
790    CycleFamily = ['Cycle' Family];
791
792    % Check whether CyclingFamily exists
793    if ismemberof(CycleFamily,'Cyclage')
794        [CycleIndex, CycleAO] = isfamily(CycleFamily);
795        CycleAO.Inom = Lattice.(Family).Setpoint.Data;
796        %% create cycling curve for each element of the group
797        curve = makecyclingcurve(CycleAO.Inom,CycleAO.Imax,Family,varargin{:});
798
799        % upload cycling curve
800        if ConfigFlag
801            reply = input(['Apply to Dserver new cycling curve to ', Family, '? (y/n)'],'s');
802        else
803            reply = 'yes';
804        end
805
806        switch lower(reply)
807            case {'y','yes'}
808                dev_name = family2tangodev(CycleAO.FamilyName);
809                if size(dev_name,1) == 1 &&  iscell(dev_name)
810                    dev_name = char(dev_name);
811                end
812                %dev_name = CycleAO.DeviceName;
813                setcyclecurve(dev_name,curve);
814            otherwise
815                disp('Parameter not set to dserver')
816        end
817    else
818        warning('Family %s not cycled',Family)
819    end
820end
821
Note: See TracBrowser for help on using the repository browser.