source: MML/trunk/machine/SOLEIL/StorageRing/insertions/idAuxFormatElecBeamMeasDataAfterEfficiency.m @ 17

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

To have a stable version on the server.

  • Property svn:executable set to *
File size: 3.5 KB
Line 
1function res=idAuxFormatElecBeamMeasDataAfterEfficiency(EfficiencyResutlStructure, displayOnScreen)
2% F. Briquez 05/03/2011
3    res=-1;
4               
5    %% LOADING INPUT EFFICIENCY RESULT STRUCTURE
6    idName=EfficiencyResutlStructure.idName;
7    cellGaps=EfficiencyResutlStructure.gaps;
8    cellAllFileNames=EfficiencyResutlStructure.fileNames;
9    vectorCorCurrents=EfficiencyResutlStructure.corCurrents;
10    numberOfCorCurrents=length(vectorCorCurrents);
11    OutputString='';
12   
13    %% WRITING PREFIX PART
14    CorCurrentsString='[';
15    for i=1:numberOfCorCurrents
16        tempCorCurrent=vectorCorCurrents(i);
17        tempString=num2str(tempCorCurrent);
18        if (i~=numberOfCorCurrents)
19            tempString=[tempString, ', '];
20        end
21        CorCurrentsString=[CorCurrentsString, tempString];
22    end
23    CorCurrentsString=[CorCurrentsString, ']'];
24    OutputStringPrefix=sprintf('\n\n%%%%%%%% %s\n\tif strcmp(idName, ''%s'')\n\t\tvCurVals = %s;\n\n', idName, idName, CorCurrentsString);
25   
26    %% WRITING MAIN PART
27    numberOfGaps=length(cellGaps);
28    if (numberOfGaps~=length(cellAllFileNames))
29        fprintf ('Bad input!\n');
30        return
31    end
32    OutputStringMainPart='';
33    for gapIndex=1:numberOfGaps
34        gapValue=cellGaps{gapIndex};
35        if (gapIndex~=numberOfGaps)
36            nextGapValue=cellGaps{gapIndex+1};
37        end
38        stringOfFileNames=cellAllFileNames{gapIndex};
39        sRes = idAuxFormatPartCorElecBeamMeasData(stringOfFileNames);
40        if (gapIndex==1)
41            if (gapIndex==numberOfGaps)
42                tempMainString=sprintf('if(gap == %g)', gapValue);
43            else
44                tempMainString=sprintf('if(gap < 0.5*(%g+ %g))', gapValue, nextGapValue);
45            end
46        elseif (gapIndex~=numberOfGaps)
47            tempMainString=sprintf('elseif(gap < 0.5*(%g+ %g))', gapValue, nextGapValue);
48        else
49            tempMainString=sprintf('else\t%%%% Gap > %g',cellGaps{numberOfGaps});
50        end
51        tempMainString=['\t\t', tempMainString, '\n\n', sRes];
52        OutputStringMainPart=[OutputStringMainPart, tempMainString];
53    end
54       
55    %% WRITING SUFFIX PART
56    OutputStringSuffix=sprintf('\tend\t%%%% End of %s', idName);
57   
58    %% WRITING AND WHOLE TEXT PRINTING IT ON SCREEN
59    OutputString=[OutputStringPrefix, OutputStringMainPart, '\n', OutputStringSuffix, '\n\n'];   
60    stringToCopy=sprintf(OutputString);
61    clipboard('copy',stringToCopy);
62    if (displayOnScreen)
63        fprintf (OutputString);
64    else
65        fprintf('Text is copied in the clipboard => just past it in the ''idReadCorElecBeamMeasData'' file\n');
66    end
67   
68    res=0;
69    return
70   
71
72   
73end   
74   
75   
76function outputString=idAuxAddTabulationsInString(inputString, numberOfTabsToAdd, endingLineString)
77    outputString='';
78    % endingLineString=char(10) or '\n'
79    % tabulationCharacter=char(9) (corresponds to '\t')
80    n=length(inputString);
81    nEndingLineString=length(endingLineString);
82    outputString=inputString;
83    tabulationString=zeros(1, numberOfTabsToAdd);
84    tabulationString(:)=9;
85    tabulationString=char(tabulationString);
86
87    i=1;
88    while(i<n)
89        if (i~=1)
90            lastLineLastCharacters=outputString(i-nEndingLineString:i-1);
91            conditionOnBeginOfLine=strcmp(lastLineLastCharacters, endingLineString);
92        else
93            conditionOnBeginOfLine=1;
94        end
95        if (conditionOnBeginOfLine==1)
96            outputString=[outputString(1:i-1), tabulationString, outputString(i:n)];
97            n=length(outputString);
98        end
99        i=i+1;
100    end
101    return
102end
Note: See TracBrowser for help on using the repository browser.