- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I needed a program to draw bridge profiles so I grabbed a program from 1991 to draw rising mains from a text file.
!
! NATURAL SURFACE
!
!
! LAST PLOT POINTS FIX FOR WMS/SWP
!
! >>>>>>>>>>>>>>>>>>>>>>>>THIS COULD BE FLAWED<<<<<<<<<<<<<<<<<<<<<
IH1=I-1
DO 600 J11=1,7
NH1=NCHAIN(IH1)
IF (NH1 .EQ. 22) THEN
IH1=IH1-1
ELSEIF( NH1 .EQ. 28) THEN
IH1=IH1-1
ELSEIF(NH1 .EQ. 38) THEN
IH1=IH1-1
ELSEIF(NH1 .EQ. 77) THEN
IH1=IH1-1
ELSEIF(NH1 .EQ. 78) THEN
IH1=IH1-1
ENDIF
600 CONTINUE
I had to laugh, when I wrote this code with this comment in 1991.
IF(NYNEXT .NE. 22 .AND. NYNEXT .NE. 28 .AND. NYNEXT .NE. 38 .AND. NYNEXT .NE. 77 .AND. NYNEXT .NE. 78 .OR. NY .EQ. 31) THEN
Jim: Is there a better way to do the if statement? This is from 1991.
Me to student : What are you studying?
Student : FEM
Me What language?
Student: Python
Me: Ah.. you want a fast language
Student: It is better then MATLAB.
Me: Ah.....................
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Any is not in my MS Fortran 5.1 manual written in 1991.
Pity I like that manual.
Thanks - learnt something new. I will not comment about it potentially being syntactic sugar, although it is simpler.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well you could have constructed an integer array and made a do loop with an if statement in it. That would be much shorter code also. I remember using that old ms Fortran and had no opinion good or bad at the time. If I had to use it now I would consider it a restrictive buggy bag of ****.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. Old MS Fortran manuals are good as they provide simple examples and clear explanations for a lot of Fortran stuff.
Old Fortran cannot do what a modern compiler can do I accept that, but the manuals were better then, as you could read them in bed. Now they are html and example poor.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Presumably @andrew_4619 's solution is inside the DO 600 loop and thus will execute 7 times regardless of the length of the chain.
As to if which method is faster, will depend on the length of the chain.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I agree about old manuals. When I was using Algol many of us used one vendor's inexpensive readable manual even though our one compiler was a different vendor's. There are books e.g. Modern Fortran Explained by Metcalf et al. that could be read in bed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do, but you cannot read the Intel Fortran 2025 manual in bed unless you take a computer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortunately, it was not arithmetic if. Imagine
if (nhi-22) 10,90,10
10 if (nhi-28) 11,90,11
11 ...
goto 99
90 ih1=ih1-1
99 continue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IN order to do some of the plastic analysis I am using programs from late 1960's and early 1970's and they use arithmetic if, slowly fixing them, but if it is not broken why fix it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In your first source:
IH1=I-1
DO J11=1,7
NH1=NCHAIN(IH1)
SELECT CASE(NH1)
CASE(22,28,38,77,78)
IH1=IH1-1
DEFAULT
EXIT ! Note, if none of the above, exit loop as NH1 is unchanging
END SELECT
END DO
Jim
Edit
@andrew_4619 's solution is much better
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Should have thought of case been using it a lot.
I like Andrew's solution, but which one takes up the least assembler code and which one is fastest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The speed difference of any of them is probably irrelevant, easiest to read, understand and maintain would get my vote.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
= If (any(nh1==[22,28,38,77,78])) ih= ih1-1
If you like Lisp and I love Lisp then this would be your first choice.
!
! NATURAL SURFACE
!
!
! LAST PLOT POINTS FIX FOR WMS/SWP
!
! >>>>>>>>>>>>>>>>>>>>>>>>THIS COULD BE FLAWED<<<<<<<<<<<<<<<<<<<<<
IH1=I-1
DO 600 J11=1,7
NH1=NCHAIN(IH1)
IF (NH1 .EQ. 22) THEN
IH1=IH1-1
ELSEIF( NH1 .EQ. 28) THEN
IH1=IH1-1
ELSEIF(NH1 .EQ. 38) THEN
IH1=IH1-1
ELSEIF(NH1 .EQ. 77) THEN
IH1=IH1-1
ELSEIF(NH1 .EQ. 78) THEN
IH1=IH1-1
ENDIF
600 CONTINUE
If you are rapidly developing Fortran code this is easy to understand although Verbose, its only problem is say 100 items, but
it is easy to forget( in Version 1 top of page) in counting or adding numbers correctly, try MySQL commands with more than 4 parameters.
IH1=I-1
DO J11=1,7
NH1=NCHAIN(IH1)
SELECT CASE(NH1)
CASE(22,28,38,77,78)
IH1=IH1-1
DEFAULT
EXIT ! Note, if none of the above, exit loop as NH1 is unchanging
END SELECT
END DO
This is Zen like, obviously the person who wrote this read Zen and the Art of Motorcycle maintenance in their misspent youth.
As an early Fortran programmer I read the book and summarized it for an English student who had more homework than I did.
For Zen read C.
Al of them meet Andrew's criteria for different reasons. It is the old argument, how does one do hill climbing, slow and steady or fast and parched.
Although technically 1 is syntactic sugar on old English Fortran, beloved of no-one.
of course @mecej4 would tell me to knock of the games and just concentrate on the Fortran. Although yesterday I was asked by a student, who is the Mother of Zeus, she was doing a crossword, I said Raia but it is Rhea.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Some of the older coder's style may have written the loop as follows:
IH1=I-1
DO 600 J11=1,7
NH1=NCHAIN(IH1)
IF(NH1 .EQ. 22) IH1=IH1-1
IF(NH1 .EQ. 28) IH1=IH1-1
IF(NH1 .EQ. 38) IH1=IH1-1
IF(NH1 .EQ. 77) IH1=IH1-1
IF(NH1 .EQ. 78) IH1=IH1-1
600 CONTINUE
Fewer punched cards.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Although technically 1 is syntactic sugar on old English Fortran, beloved of no-one.
I don't actually agree, there are several things happening in that one line statement all of which have many different potential usage cases.
1] constructing a list of integers in an array
2] constructing a temporary logical array comparing a scaler to an array.
3] Using the ANY function to see if any logical in the array is true and if so......
4] executing the IF construct.
The use of whole array operations is fundamental to the Fortran language from Fortran 90 onwards. Personally I find that the one liner much quicker to understand than the list of ELSEIFs which I need to read all of to see what each case does. OK they all do the same thing but you do not know that without checking each line. Why write and maintain 14 lines of code when one will do? Why write code that creates unnecessary scrolling up and down the page because it is verbose? And as a final point if one wanted to change the IH1 = IH1-1 in some way you would need to change it in 5 places instead of one, whoops I missed one and made a bug....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Should @JohnNichols choose the ANY method, then after the 600 CONTINUE, he will need to insert NH1=NCHAIN(IH1) should the value of NH1 be required later in the code.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(map ’string #’(lambda (x y)
(char "01234567890ABCDEF" (mod (+ x y) 16)))
’(1 2 3 4)
’(10 9 8 7)) → "AAAA"
(setq seq ’("lower" "UPPER" "" "123")) → ("lower" "UPPER" "" "123")
(map nil #’nstring-upcase seq) → NIL
seq → ("LOWER" "UPPER" "" "123")
(map ’list #’- ’(1 2 3 4)) → (-1 -2 -3 -4)
(map ’string
#’(lambda (x) (if (oddp x) #\1 #\0))
’(1 2 3 4)) → "1010"
(map ’(vector \* 4) #’cons "abc" "de") should signal an error
This is the problem with Fortran's development over the last 50 years. The developers borrow from other languages, such as ANY being similar to map from Lisp. Why not use a word that other program use and not reinvent the wheel.
I have no problem with ANY per se, just make the language closer to common things in other languages.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A piece of code slightly modernized but in which I never succeeded to replace the arithmetic if. The code do what it is supposed to do but I never understood neither how neither why.
intli=0
9 if (lign-ptal_g)999,15,10
10 if (lign-ptal_d)11,20,999
11 if (xa-xb)20,999,15
15 isens=1
lim=ptal_d
goto 30
20 isens=-1
lim=ptal_g
30 do l=lign+isens,lim,isens
do n=npro,npro,-1
call inseg_old(xa,ya,xb,yb,p(n ).x(l),p(n ).y(l)
s ,p(n-1).x(l),p(n-1).y(l)
s ,x,y)
if ((x-xa)*(x-xb))34,34,40
34 if ((x-p(n).x(l))*(x-p(n-1).x(l)))35,35,40
35 if (p(n).v(l))36,36,100
36 if (p(n-1).v(l))40,40,100
40 if (p(n-1).y(l)-ymin)41,45,45
41 if (p(n-1).y(l)-p(n).y(l))50,50,45
45 continue
enddo
50 continue
enddo
return
100 intli=1
xint=x
yint=y
999 return
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do not know lisp but ANY does not seem analogous to MAP and there is already a MAP in a widely supported Fortran extension. ANY is just an .OR. applied to an array of type logical and returns TRUE if ANY are true. ALL is the equivalent for .AND. and returns TRUE if ALL are true. Those names seem quite LOGICAL to me. ANY/ALL/COUNT (from F2003 or 2008 from memory) allow you to work with arrays rather than scalars and can make code much less verbose and can eliminate loops. I would also think it gives a compiler more chance to vectorise/optimise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Perfectly explained, thank you. I accept your point of view.
The real challenge is time, one has code that is from the 1970's, one has used the code since the early 1980's and it works. It is old Fortran in the truest sense, but the time to rewrite the Fortran in modern Fortran is much longer than the time one spends using the code, it is not worth it. So one lives with many ifs, just no buts.
The real beauty of Fortran is that it will pretty much run old Fortran, from 1968, with minor modifications. Sometimes you use the code, as you fix the code.
Work expands to fill the available time. Is true of computer languages, the number of computer languages expands to fill the available computers or Professorial chairs, based on the observation that Professors have to produce papers and you can get many papers out of a new compiler. You get paid for paper production.
NB: If you want to see the scientific method run wild, look at the country of origin of an author list on any engineering journal.
i.e. Scheme is a classic example from a pair of fine programmers. TI tried it for a while, it is a nice little language, if Fortran had some of Scheme's syntax it would be nice.
But why invent Scheme when you have Lisp, and I have programmed a lot in Lisp inside AUTOCAD. It makes for a highly productive environment. I need to change 100000 things on an drawing, I need someone with a lot of time, or 20 lines of LISP code and a few minutes.
NB: Programming in C is just staring at people who stole from Lisp, without them understanding the beauty of Lisp and the ugliness of C. But I can do many things in C that I cannot do in Lisp.
I spent many happy hours with draughtsmen and draughtswomen saying can you do this?
But places like this forum are rare and the rest of the world probably thinks we are slightly strange people. And we are, but we are our strange.
My mother once said to someone, it is a waste of time arguing with him, he will just take the opposite side to annoy you and he never stops. I miss my mum, although my 17 yr old daughter is annoyingly like her and my grandmother, it does not repeat but it rhymes.
Happy Chinese New Year.
PS: Re the Chinese AI machine, a bright academic in South Australia did not have the budget for a super computer, so he linked a whole series of PC's (I think) together and with LINUX got his supercomputer and like most supercomputers uses Intel Fortran, probably an old version.
You can have money with some brains and you can have brains with limited funds, the second will be more inventive, particularly if you tell them you cannot do it with those funds. Or one has Alang Ship Breaking Yard as an economic model.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page