[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
wgould@stata.com (William Gould, StataCorp LP) |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: FORTRAN 77's GO TO <label> CONTINUE into Mata |

Date |
Wed, 17 Oct 2007 09:31:07 -0500 |

Joseph Coveney <jcoveney@bigplanet.com> asks a question about FORTRAN and than a claim about Mata. I'm in denial about the claim about Mata, as I will explain. First, the question: > A question about translating the following snippet of FORTRAN 77 into Mata: > > DO 120 J=1,NCV > . . . > IF (SM) 100,120,100 > 100 SM=SM*B > . . . > 120 CONTINUE > > I currently have the following (perhaps-too-literal) translation: > > for (j=1; j<=ncv; j++) { > . . . > if (!sm) goto L120 > sm = sm * b > . . . > L120: } Joseph asks whether if the translation right. It is. The Fortran line IF (SM) 100,120,100 says to goto 100 if SM!=0 and goto line 120 if SM==0. Joseph then says, > But in an aside exploration of Mata's behavior with an analogous probe > function, it seems that when a -goto- sends control to the continuation > line as above, it behaves like a -break- and not a -continue-. That's where I go into denial because I ran an experiment: . mata: --------------------------------------- mata (type end to exit) ----- : : function bill() > { > sm = 0 > > for (j=1; j<=4; j++) { > printf("j = %g\n", j) > if (!sm) goto L120 > printf("doit\n") > L120: } > "DONE" > } : : bill() j = 1 j = 2 j = 3 j = 4 DONE : end --------------------------------------------------------------------- Am I misunderstanding? I think the experiment I did is identical to Joseph's code, and Mata repeated the loop 4 times, amounting to a continue, just as Joseph expected. It is always dangerous to assert a lack of a bug in software as complicated as Stata and Mata, but the presence of this bug would surprise me. We translated most of EISPACK in the mechanical way Joseph translated his problem -- 3,660 lines -- and in the certification scripts for Mata, we compile that translated code and certify it. The construct of going to a close brace is not uncommon in the translated code. I wonder if the Fortran variable SM was declared to be an integer. If so, there might be a formula for the calcuation of SM in the original code that reads SM = ... which Joseph translated as sm = ... when what is necessary is sm = floor(...) In such a case, sm might be .001 when it ought to be 0. -- Bill wgould@stata.com * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

- Prev by Date:
**st: Positive log likelihoods in xtmixed models** - Next by Date:
**Re: st: Positive log likelihoods in xtmixed models** - Previous by thread:
**st: Importing Selected Variables** - Next by thread:
**Re: st: FORTRAN 77's GO TO <label> CONTINUE into Mata** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |