Skip to content

allow double quotes in mode name for atvariablethinmultipole - #1140

Merged
oscarxblanco merged 7 commits into
masterfrom
fix_matlab_mode_name
Sep 9, 2026
Merged

oscarxblanco merged 7 commits into
masterfrom
fix_matlab_mode_name

Conversation

@oscarxblanco

@oscarxblanco oscarxblanco commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

This PR solves issue #1139 , where a mode name double quoted created a .mat file incompatible with pyat.

The string is converted to characters to make it readable in pyat.

@oscarxblanco oscarxblanco added Matlab For Matlab/Octave AT code bug fix labels Aug 26, 2026
@oscarxblanco

Copy link
Copy Markdown
Contributor Author

Dear all, who could review this PR ?

@oscarxblanco

Copy link
Copy Markdown
Contributor Author

Hi all. I’m away for another 2 weeks and I cannot look at the code… Matlab « strings » create problems, did you look at what happens for element names in double quotes ? Are they converted to char arrays ?Le 26 août 2026 à 13:52, oscarxblanco @.> a écrit :oscarxblanco left a comment (atcollab/at#1142) Dear all, who could review this PR ? —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.>

Hi @lfarv !
I just checked and FamName has the same behaviour. If I double quote the FamName of an element I get an error in pyat.

For example, saving a ring with a drift as d = atdrift("d",0.1); where the name is double quoted makes pyat fail when loading the .mat file.

@oscarxblanco

Copy link
Copy Markdown
Contributor Author

@lfarv ,
the function convertStringsToChars could be used to convert the MATLAB strings to a char array which is compatible with the pyat read_mat method.

Comment thread atmat/lattice/element_creation/atvariablethinmultipole.m Outdated
Comment thread atmat/lattice/element_creation/atvariablethinmultipole.m Outdated
@lfarv

lfarv commented Sep 9, 2026

Copy link
Copy Markdown
Contributor
    function rsrc = setparams(rsrc,modename,ab)
        amplarg=strcat('Amplitude',ab);
        if isfield(rsrc,amplarg)
            switch modename
                case "SINE"
                    rsrc = setsine(rsrc,ab);
                case "ARBITRARY"
                    rsrc = setarb(rsrc,ab);
                case "WHITENOISE"
                    rsrc = setwhitenoise(rsrc,ab);
            end
        end
    end

Since ModeName has been converted to char, one should use single quotes here.

@lfarv

lfarv commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

To protect also FamName and Method in any element, you could change line 18 in atbaselem():

From

elem           = struct('FamName',famname,'PassMethod',method,'Length',lg,rsrc{:});

to

elem           = struct('FamName',char(famname),'PassMethod',char(method),'Length',lg,rsrc{:});

@oscarxblanco

Copy link
Copy Markdown
Contributor Author

@lfarv , all changes have been implemented.

@lfarv lfarv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you checked that everything is now working, that's ok for me.

@oscarxblanco
oscarxblanco merged commit badd775 into master Sep 9, 2026
22 checks passed
@oscarxblanco
oscarxblanco deleted the fix_matlab_mode_name branch September 9, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix Matlab For Matlab/Octave AT code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants