Problems running scripts with octave 6.1.0

Hi, I’m Leonardo.

I have a problem with GNU octave 6.1.0.

When I write a script in the editor and save it so that I can execute it in the command window, the octave simply saves my program with strange characters and when executing my program in the command window, the program is not recognized.

For exemple
Running this simple script

c = cos(7*pi*32)*pi

Octave returns a syntax error

error: parse error near line 1 of file C:\Users\leona\Desktop\teste.m

  syntax error

>>>
    ^

which doesn’t make sense since it’s a simple calculation line.

When trying to save a simple program like this next example

t = [0:0.1:2*pi];
a = length(t);
for i = 1:a
s(i) = cos(t(i))+cos(3*t(i))+cos(8*t(i));
end
s
plot(t,s)

Octave saves the .m file with strange characters, as below:

Ä  «€Š€~Š‚zÀ¹­‹
±  ¼µ¾·Ä¸xÄy‹
¶¿Â ¹  Š±
Ãx¹y  ³¿ÃxÄx¹yy{³¿ÃxƒzÄx¹yy{³¿ÃxˆzÄx¹yy‹
µ¾´
Ã
À¼¿ÄxÄ|Ãy

Using the notepad ++ software to save the same .m file, the file is saved correctly without strange characters and still runs normally in Octave, as shown below:

>> teste_leo
s =

 Columns 1 through 8:

   3.000000   2.647047   1.776203   0.839553   0.285124   0.294676   0.685633   1.035562

 Columns 9 through 16:

   0.952498   0.325889  -0.595190  -1.344977  -1.519089  -1.019418  -0.117289   0.703795

 Columns 17 through 24:

   1.031132   0.760837   0.147673  -0.362314  -0.413636   0.034334   0.677475   1.050089

 Columns 25 through 32:

   0.810178  -0.046426  -1.173527  -2.072088  -2.379089  -2.073699  -1.476944  -1.046210

 Columns 33 through 40:

  -1.090176  -1.577773  -2.157382  -2.374599  -1.956078  -0.986547   0.129356   0.898442

 Columns 41 through 48:

   1.024434   0.575548  -0.066377  -0.443559  -0.302061   0.256161   0.840968   1.019862

 Columns 49 through 56:

   0.591951  -0.277221  -1.142964  -1.539125  -1.250982  -0.438744   0.462617   1.006116

 Columns 57 through 63:

   0.998786   0.610014   0.257228   0.339266   0.980343   1.941144   2.752183

I would like to know how to solve this problem.

Thanks

Leonardo Milfont

What happens when you load the file, that you have saved with notepad++, with octave?

Which OS do you use? Which locale and version?

What does the following command return for you in Octave?

__mfile_encoding__

The octave stops responding and immediately closes the program on its own.

My operating system is windows 10, version 1909, installed on 3/15/2020.
Using the __mfile_encoding__ command, my octave returns:

>> __mfile_encoding__
ans = system

Which language version is the OS?
What does the following command return in Octave?

 __locale_charset__

I didn’t quite understand what you meant by the first question. My Windows 10 is in Portuguese.
When I use the locale_charset command, the octave returns the following to me:

>>  __locale_charset__
ans = CP1252

Hm. I’m using the same codepage for encoding on my Windows 10 with German locale without issues. So, there might be a different reason than encoding that is causing the issue for you.

As a last test in that direction, could you please switch the encoding to UTF-8, open a new file in Octave’s editor, type some text and save that file? Does that file still contain similar gibberish?

You can change the encoding in the preferences on the “Editor” tab in the dropdown list “Text encoding used for loading and saving” or with the following command:

__mfile_encoding__ ("utf-8")

I managed to solve the problem, thank you very much, that was the solution, it worked well here.

@ttl: Do you have an idea what could cause the editor to save gibberish when the encoding is set to “system” (which seems to resolve to “CP1252” for this user)?

Friend, I don’t know, I never came across this type of problem, I just used the solution you proposed and it worked well, thanks.

@Leonardo: That was what I already gathered from your previous answer. I was asking Torsten what he makes out of that.
As probably the last test: Could you please revert to the previous setting and check if the files are saved as gibberish again? You could select “SYSTEM” from the drop-down list in the preferences dialog. Or run the following command:

__mfile_encoding__ ("system")

After that, open a new file in Octave’s editor, type some text and save that file.

Yes, I ran this mfile_encoding (“system”) command and made a script and tested it. He was saved correctly.

@Markus: I don’t know what might have been going wrong on Leonardo’s system.

Might have been that a weird coded that encodes Latin characters differently than ASCII was picked up for saving the file. Maybe something similar to EBCDIC:
Character Encodings - Legacy Encodings - CP037 (EBCDIC US/Canada) (kreativekorp.com)

AFAICT, Notepad++ doesn’t display files correctly that are encoded in EBCDIC (and probably also other “weird” encodings).

But Octave should be using the same encodings for saving files in the editor and for loading files in the parser.
Maybe setting and resetting the encoding in Octave initialized something that wasn’t initialized correctly before. :thinking:
But that is hard to tell without steps to reproduce. Let’s just wait if this comes up again in the future…