Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to execute MathCAD from command line (e.g. *.bat)???

Status
Not open for further replies.

ChrMeissner

Mechanical
Jan 31, 2005
21
Hello,

I'm using MathCAD (among others) for manipulating pictures (RGBREAD, RGBWRITE, ...). I've to process more than 2000 bitmaps and I intented to do this over night in a loop. But because of the big image size (1680x1050) the memory limit is reached after 3 files !!! (task manager: RAM: 1,5GB avaible, 1,45GB used by MathCAD). MathCAD gives an error like "not enough memory". If I close MathCAD an restart it again, I can process annother 3 files.

1) Is there a possibility to FREE the MEMORY used by the variables (e.g. a big matrix; "M:=0" dos'nt work)?

2) If I write a batchfile (*.bat) with "mathcad.exe test.xmcd" MathCAD starts an executes the calculation. OK. Ist there a posibility to say that MathCAD should close itself after finishing the calculation ??? ("mathcad.exe test.xmcd /close" dose'nt work)

Thanks for hints.
Christian
 
Replies continue below

Recommended for you

Once a variable is defined in the worksheet ( := ) you can not clear the memory by clearing the variable later in the sheet.
However, I believe that local definitions within programs ( <- ) are not saved in memory when the calculation is done. You could try setting up a loop within one program where all the variables are local definitions. So the read file, processing and write file are all within one program, using only local definitions and nothing is saved at the worksheet level. This 'might' help your memory problem.

Peter
 
I thought A:=A undefines A. Hopefully this will free up memory too.
 
Nope. No such luck. The only place where Mathcad, particularly the newer versions, is reasonably efficient is in the middle of a program loop.

TTFN

FAQ731-376
 
Thank you for your replies.

Indeed it seems to be difficult to free the memory, which mathcad has allocated. To get a quick solution, I wrote a little C++ programm which
- starts mathcad with a certain *.xmcd-file
- reads a certain status file, where mathcad places an idication number after the calculation has finished
- kills the MathCAD-task
- restart MathCAD with the mext FRAME to process...

Christian
 
"I thought A:=A undefines A. Hopefully this will free up memory too."

Nope. That'll just keep A equal to whatever was in A.
 
Another option would be to use a Windows based mouse recorder. I used to have one that would open a given set of programs from one click. Sorry, I can't remember its name.

Cheers

Greg Locock

SIG:please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
2. taskkill /im mathcad.exe will kill it. Perhaps a timer could be implemented with a long enough delay to ensure calculations are complete before killing. Here is a batch file timer I've used:

echo Wscript.Sleep 4000> c:\batch\sleep.vbs
start /w wscript.exe c:\batch\sleep.vbs
del c:\batch\sleep.vbs

Increase or decrease the 4000 as needed.
 
The way to do it is using the Animation feature. This uses the built in variable FRAME and runs the same proramme as many times as you require and each time Frame is the new value. Anything that depends on FRAME is updated and a small selected area is captured to make an avi (which is what it was designed for).
I regularly use it to batch process hundreds of test results from cameras, each which takes in hundreds of image frames. When used in that mode it does overwrite the memory space.

search the collab for FRAME to see all the explanations.

Also look for 'components' which allow you to process directory lists etc.

Philip
 
Thanks @ philipoakley,

I'm using the Animation feature very often for periodic (recurrent) calculaions. Normally this works good. But in this special case, it only processes two or three images and then MathCAD gives the described memory error - the evidence that MathCAD does NOT free the allocated memory (MathCAD 13).

It seems to me that it depends what you do with the images. If I only concatenate two images, no error occurs. If I do many complex things like copy one image into another (frame in frame) and append status bars etc. this error occurs. You can also force this error with a little example sheet, see following link:

(In this synthetic case, the animation tool works good in many cases.)

Thanks @ stevenal,
I used this command (it works fine), a timer is also included and at the end of the MathCAD sheet, a "PRNWRITE" command writes a flag into a status file indicating that the calculation has finished. The C-software reads out this file and kills the MathCAD task if this flag is set.

Thanks @all for your replies. I think this problem is solved:
- MathCAD ist not as powerful as a "real" programming language (disadvantage)
- with MathCAD you can write a software and find mistakes very fast (big advantage)
-> Sometimes very special solutions are necessary (kill/restart, DLL, ...)

Thanks for all help,
Christian
 
in the test...
So you have 1050 x 1680 x 3 x 2 data values, times 15 repeats. This makes 158,760,000 data values, each is an object, so will have multi-byte representation. Even as a simple double it is 600+meg, then all the .net overhead...

V13 may have leak, but it appeared to work OK for me in V14 (with a lot of disc thrash).

Don't forget you have fifteen different 'variables' called k, and fifteen different 'variables' called K. In fact, mathcad has no variables at all. They are all just the names of the constants they represent, and their placement signifies the start of their scope, until another constant of the same name ends it...

One trick is to put all the looping (the 15 steps) into a programme and have each bit of processing as a simple function (which uses no memory at the point of definition). You can copy out any intermediate values to review as part of the return matrix (which can be nested)

If you need more have a look at
Philip
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor