cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Re: PTC Mathcad Matrix to C++ Code

Werner_E
25-Diamond I

Re: PTC Mathcad Matrix to C++ Code

Documents created by PTC staff don't allow for comments - so this is an attempt to comment on a recent document posted.

The file recently posted by Brent Edmonds (http://communities.ptc.com/docs/DOC-4875) contains two routines, gen_cplusplus() and WRITEFILE().

The first one takes a matrix consisting of numbers (no error checking) and creates a vector of strings similar to what you would type if you define and initialize an array in C(++). And this routine has some flaws in my opinion.

The second routine is, as is also stated in the enclosed word doc, the real gem. Its courtesy by Magnus Eklund from PTC and writes a matrix with arbitrary elements to a file and if a matrix element is a string it is written without the double quotes. Its sure a valuable utility routine for the collection.

Nevertheless some comments to this second routine first:

  • Please change the name from WRITEFILE() to something else, as WRITEFILE() is the name of a built in routine. In the attached file I included it renamed to WRITEMATRIX().
  • In case the matrix element is a number, it is converted to a string with num2str(). Then the routine looks if there is a comma (,) in the resulting string and if one is found, it is replaced by a decimal point. This should never be necessary, as Mathcads num2str() never produces a decimal comma, whatever the decimal character in the Windows setting may be. I should know, as we use the decimal comma over here and I often had problems with scripted components for Mathcad because of this, as the used VBS routine would consider the decimal character in the Windows settings and gives a decimal comma which Mathcad sees as an error.
    Anybody knowing why this replacement is done inMagnus Eklund's user function? Am I missing something?

Concerning the gen_cplusplus() routine, its a fairly basic one and somewhat long with a lot of if's for its purpose

  • as an "official" utility routine it should be ORIGIN aware; as its written now, ORIGIN=0 is assumed
  • I think the output should also include the dimensioning of the array, which can easyly be done, and when we are at it, why not create a complete definition with "float data [..." in front as well. Its easier to edit than to add/complete
  • The routine makes use of a strange "feature" that allows the usage of an undefined variable in a program if its used in a loop. At best its bad programming style but I think I would call this "feature" a bug in Prime (haven't tried if it works in Mathcad, too) - see below.
    undefined.png
    In my opinion test1 should also throw the error because of the undefined variable!
    EDIT: Just tested it and this behaviour is already present in Mathcad 15, too!

Find attached as simpler and bit more complete replacement for gen_cplusplus(), I called it mat2CPP() (also without error checking).

But as the goal is just the creation of the file an all-in-one routine like the attached WriteCPP() should do the job pretty well.

writecpp.png

P.S.: @ptc: Does it really makes sense to make a single document with just one small, very special utility? Wouldn't it make more sense to create a collection of 20 or more of such small routines in one file. Looks to me like pretending the existence of lot of content and that shouldn't be necessary.

10 REPLIES 10
jsheehan
12-Amethyst
(To:Werner_E)

Werner,

I did not export the array declaration thinking this would make it easy to go to JAVA and not too big a stretch for FORTRAN. I need to use str2vec more, thanks for your example.

Regarding your comment "looks like pretending the exisitence of a lot of content". .. well we have come to expect these comments from you. We will continue to post utilities customers find useful and just expect to hear from you.

John

John T. Sheehan wrote:

. .. well we have come to expect these comments from you.

John

This attack is unprofessional and uncalled for.

It was not meant as an attack Fred. Simply a statement of our readiness and our plans to continue to post

Werner_E
25-Diamond I
(To:jsheehan)

John T. Sheehan wrote:

It was not meant as an attack

Glad to hear. But then, you could have commented on the question about the comma to point replacement or the bug(?) with the usage of an undefined variable. You decided to pick my concerns about the inflationary posting of single 10-liners in the same manner as multi-page complex utility calculation sheets (and I won't ramble about the sloppily converted old tutorial sheets again).

Let me say and be assured that at no time I seriously thought that PTC would alter its marketing strategy just because of my concerns.

This attack is unprofessional and uncalled for.

Well Fred, I live long enough to have made the experience that not all people are alike. Not all are well eductaed, well mannered and able to deal with criticism. But I agree that showing bad manners if one appears as representative of a company, thats not professional.

John had shown his rough manners already in the past - at least thats what I feel about, when a customers concerns are shirtsleeved dismissed as "rubbish" (http://communities.ptc.com/message/219983#219983)

But after all, as John wrote, it wasn't an attack at all.

RichardJ
19-Tanzanite
(To:Werner_E)

Easy, folks, easy. This is beginning to have a faint odor of escalation, and that never ends well for either party.

I don't think anyone (even PTC, with the exception of their marketing department) would dispute that there are many long term users of Mathcad that are very frustrated with the slow progression of Prime (which includes, but is not limited to, the inadequacies of Prime itself, destruction of much of the old forum content, the destruction of the Mathsoft library, and the rewriting of Mathcad's history on Wikipedia). I could claim that I'm not one of them, but then I would have a nose about 400ft long . But I suspect some old Mathsoft employees perhaps are also frustrated, and some comments on the forum just rub it in. I'm not saying I know that, just that I suspect it. Unlike us, any such employee is not in a position to vent publicly, unless they want to be "sent to greener pastures". As a number already have

Werner_E
25-Diamond I
(To:RichardJ)

Well spoken. I'm not interested in a flame war anyway 😉

The beauty of Wikipedia - it's all there, recorded in the history.

It's too bad when there is a fundamental conflict for direction in a company, especially when due to acquisition. Often the aquiring company has little clue or interest in what the core of the acquired company valued and made it worth buying in the first place.

Time Warner bought Atari because of the sharp increase in home video games, then ignored the core of the company who pointed out that the trend was not limitless. They left to develop the Amiga computer, a multitasking OS with an integrated GPU. Soon after, the video game market collapsed leaving TW with little. Commodore eventually bought Amiga to get an advantage and promptly did everything wrong that Amiga had done right. Dead Amiga. Dead Commodore.

Schlumberger bought Applicon (CAD) and MDSI (an NC company) and forced them to integrate. Both gone.

I recall a Schlumberger/Applicon tech rep becoming really unhappy at a meeting. He wanted to know what features I was interested in and I mentioned I liked the recently announced Pro/Engineer. He came unglued. The sales rep calmly held him back and mentioned that this was a common request.

Yup. It's a bad sign when the tech reps get angry with users. Too bad it's usually someone who really cares for the product and are prevented from making it better or are forced to make it worse.

lturek
12-Amethyst
(To:Werner_E)

Thanks for this routine! I wasn't aware we could use this combination of str2vec and WRITEBIN to get rid of the double quotes.

As an asisde, I also consider John's remark on a rather constructive posting as absolutely out of place, unnecessary and inapprehensible.

Werner_E
25-Diamond I
(To:lturek)

Leopold Turek wrote:

Thanks for this routine! I wasn't aware we could use this combination of str2vec and WRITEBIN to get rid of the double quotes.

Not my baby - the idea of doing it that way is from the WRITEFILE() routine in the referenced file posted by Brent Edmonds. The routine was said to be courtesy of PTC staff member Magnus Eklund.

Announcements

Top Tags