3

I am using Matlab to print a small text file (temp_script.exec) that will be used to run GrADS commands. The script looks like the following:

'reinit'
'open temp_ctl.ctl'
'set lon -100 -80'
'set lat 20 30'
'define prc = var'
'set sdfwrite data_out.nc'
'sdfwrite prc'

The script is called via cshell:

#!/bin/csh -f
grads -lbc << EOF
temp_script.exec
EOF
exit

The script seems to execute properly, but the output (data_out.nc) is not generated. Strangely, if I edit it using VI and replace the first character -- the single quotation before the command "reinit" -- by typing another single quotation, then re-run the script, data is generated properly.

My question is, what could be different? The scripts look identical in several different text editors, but the "modified" script (by typing) is 1 byte larger. I am using the "fprintf" function to generate the single quotes in Matlab. Could it be some problem with that function?

Thanks for reading.

FoxRyerson
  • 151
  • 1
  • 2
  • 5

1 Answers1

0

To see if the files are really the same (the generated one and the one edited with vi):

od -c -t x1 temp_script.exec > temp_script.lis
od -c -t x1 vi_script.exec > vi_script.lis
diff exec_script.lis vi_script.lis

There could be a UNICODE BOM at the beginning of the file, or a missing newline at the end of file that is causing your issue.

fork2execve
  • 1,561
  • 11
  • 16