I have created my first mathematica 'program' as I think of it, to do some image processing. After reading in an image, it does a lot of stuff (including smoothing, fourier transform, functional representation, searching for critical points, outputing various files).
Now, I have hundreds of images that I want to process: obviously a job for a script. But I am somehow not understanding the whole mess of CommandLine, ScriptCommandline, or even how to properly edit script files (am I supposed to do it in the notebook? Because I'm using a lot of mathematica symbols, so I'm not sure how I could edit otherwise) or how to get scripts to run! It seems part of the problem is that scripting has changed in Mathematica 9 and a lot of previous Q&A entries focus on solutions for prior versions.
I have tried to get a basic script working on my system and I get really odd errors. E.g.,
#!/Applications/Mathematica.app/Contents/MacOS/MathematicaScript - script
(*generate "num" samples of a mixed distribution*)
num = ToExpression[$ScriptCommandLine[[2]]];
Print /@ RandomVariate[
MixtureDistribution[{1, 2}, {NormalDistribution[1, 0.2],
NormalDistribution[3, 0.1]}], num, WorkingPrecision -> 50]
I get:
$ ./test.m 10
./test.m: line 1: F814W_knotD_ACSHRC_2.91772_J8L001031_50_.fits: command not found
./test.m: line 3: F814W_knotD_ACSHRC_2.91772_J8L001031_50_.fits: command not found
./test.m: line 4: *#!/Applications/Mathematica.app/Contents/MacOS/MathematicaScript: No such file or directory
./test.m: line 5: F814W_knotD_ACSHRC_2.91772_J8L001031_50_.fits: command not found
./test.m: line 6: syntax error near unexpected token `*generate'
./test.m: line 6: `(*(generate "num" samples of a mixed distribution)*)'
(those fits files are in the same directory, and I have NO IDEA why it is talking about them)
Apologies for the newbie questions... hopefully this will be the last one for a while!!
FileNames
to get a list of your image files and map your processing function on the list of files. Ditch the command line stuff for now (unless you have something on the order of thousands/millions of files and want to run it as a batch job in the background) $\endgroup$$HistoryLength=0
is your friend in any case... $\endgroup$