source: MML/trunk/machine/SOLEIL/StorageRing/insertions/idAuxNum2FileNameStr.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: 781 bytes
Line 
1function resStr = idAuxNum2FileNameStr(num)
2%Encodes decimal number in string, which can then be used as a part of file name
3
4strParamValue = sprintf('%f', num);
5strParamValue = strrep(strParamValue, '.', '_');
6lenOrigStrParamValue = length(strParamValue);
7numTrailZeros = 0; %removing trailing zeros
8for k = 1:lenOrigStrParamValue
9        if(strcmp(strParamValue(lenOrigStrParamValue - k + 1), '0'))
10        numTrailZeros = numTrailZeros + 1;
11    else
12        if(numTrailZeros > 0) && strcmp(strParamValue(lenOrigStrParamValue - k + 1), '_')
13                numTrailZeros = numTrailZeros + 1;
14        end
15        break;
16        end
17end
18if(numTrailZeros > 0)
19        resStr = '';
20        for k = 1:lenOrigStrParamValue - numTrailZeros
21        resStr = strcat(resStr, strParamValue(k));
22        end
23else
24    resStr = strParamValue;
25end
Note: See TracBrowser for help on using the repository browser.