A very nice introduction to Fortran 90. It was well explained at the right pace and covered exactly what I need to know to get some Fortran utilities working. You covered the part that others leave out. One point I would like to make is about "Best Practice". I'm an old school programmer and we knew what we were doing with the "sloppy code" because we were careful with our code. A few years ago there was a problem at a major footwear company when the overnight processing extended to mid morning and lost them a lot of sales. I was asked to check the code to see if I could speed it up. The bad code was written in SQL and was to generally accepted "Best Practice" standards. I restructured the code using basic Data Processing principles (1970s) and SQL code written in original IBM SQL syntax. (Optimal machine code for that machine). This made it run 9 times faster, saved 7 hours processing and meant the tills worked when the shops opened. The "expert" SQL coders who maintained the original SQL code said that what I had done was not "Best Practice" and that it was "wrong" but the management were delighted with the increase sales.
Excited to watch this; I never knew that learning about astrophysics was going to be why I needed to learn Fortran, but I knew I would have to someday. Supposedly knowing some LOGO is helpful, so that's a plus for me.
thank you for this, my uni lecturer is pretty useless at teaching how to code, he basically gave us his pi calculator as the first bit of code weve ever seen and told us to try out a bunch of functions, which i didnt even know how to do that, but now i do!
The problem is that old fortran ignores spaces. Thus “do 30 i =1.20” is interpreted as setting a variable as in “do30i = 1.20” where “do30i” is a legal floating point variable. FORTRAN is a two pass compiler which is why you do not have to give the code a function prototype.
yes just click on "settings"->"install" and install the "language-fortran" package. You might also find the "linter-gfortran" package useful, which shows you code problems on-the-fly.
Why does GCC's Fortran compiler give a different answer for 4*atan(1) than Wolfram Alpha? How would one know which one is correct? This man's example program overestimates the value of pi. Why?
on the atom text editor at the bottom right-hand side, what do you change it to because I can't find FORTRAN there, mine is still showing Plain text. Thanks for your prompt response
Even when I do gfortran -o maths geometry.f90 maths.f90 I get same the same error that " cannot open file geometry.mod for reading at (1): no such file or directory exists"
first install "homebrew" (brew.sh) then open a terminal and type "brew install gcc" and you should have gfortran working from a terminal. If you are not used to working from the terminal I would recommend taking a basic unix tutorial first.
Amazing set of videos! Now I know what the Makefile is doing! Also, my ~1,200 line Fortran code is now 80 lines with the use of modules :) Thanks! Out of curiosity, is there a way to organize all of the modules and use them from a different directory? My working directory is getting a little cluttered with all of the *.o and *.mod files along with the data? Appreciate any help :) and looking forward to your other videos which look interesting!
yes, just add the line VPATH=dir1 dir2 to the top of the Makefile, where dir1 and dir2 are the name of the subdirectories where your source code files are located
program loop implicit none real :: i do i = 1, 25 print*, i end do end program loop in this code i have instigated i as a real value and it still ouputs a real value
install homebrew (google for it)->type "brew install gfortran" into the terminal->download VSCode or Cursor AI or other text editor with IDE-like capabilities
Hello, I want to make a guess about the bug in this do loop. Maybe because 1.20 is a real and not an integer it can not be assigned to the implicit i. So I would guess i was implicit initialized with a value of 0. As 1.20 can not be assigned it will stay 0 and is printed like that. As the loop has no further steps to do, it will finish. Thanks for the tutorial! And greetings from Darmstadt (Germany)! PS: Is the tutorials PDF public or is there away to receive it for strictly private use?
you're half way there. The key is that FORTRAN allowed spaces in variable names, whereas these are not allowed in modern Fortran. So the =1.20 is treated as an assignment to a variable (hint: starting with d makes it a real if implicit types are allowed). For the pdf, it is available from my web page: users.monash.edu.au/~dprice/teaching/fortran/lab-Fortran.pdf
@@DanielPriceAstro so 1.20 is assigned to the variable 'do 30 i' . 'i' as a counter variable holds 0 by default and the leading 30 in front of 'continue' is ommit due to its position?
But why??? Why does the error statement complain about a named 'constant,' but the type declaration uses the keyword 'parameter?' It is not consistent. Why isn't the declaration using the keyword, 'constnt' if that's what the compiler believes it is and calls it such? Else, why isn't then the error statement informing about a parameter instead of a constant? Come on! It's 2023 and how long have these boffins been writing errors statements and revising Fortran? More than 50 years?
Hi Professor, I am a beginner in Fortran and learning it by myself. The below code gives me error and Stackoverlfow has not been able to give me any meaningful help. Can you help me with this? Filename: Univariate_search.f90 ---------------------------------------------------------- Compiling with gfortran 12 | f(x,y) = 2.0*x**2 + 2.0*y**2 | 1 Error: Unclassifiable statement at (1) Compiling with ifort error #6410: This name has not been declared as an array or a function. [F] f(x,y) = 2.0*x**2 + 2.0*y**2 ^ compilation aborted for new.f90 (code 1) ------------------------------------------------------------------------------------------------------ program Univariate_search implicit none real :: a,x,y,x0,y0,f !initialise the variables x0=0.0 y0=0.0 !define the functions f(x,y) = 2.0*x**2 + 2.0*y**2 a=f(x0,y0) print*, a end program
you did not define a function correctly. try this: program Univariate_search implicit none real :: a,x,y,x0,y0,f !initialise the variables x0 = 0.0 y0 = 0.0 !error: define the functions ! error: f(x,y) = 2.0*x**2 + 2.0*y**2 a = f(x0,y0) print*, a end program Univariate_search real function f(x,y) real x,y,z z = 2.0 * x**2 + 2.0 * y**2 f = z return end function f
A very nice introduction to Fortran 90. It was well explained at the right pace and covered exactly what I need to know to get some Fortran utilities working. You covered the part that others leave out. One point I would like to make is about "Best Practice". I'm an old school programmer and we knew what we were doing with the "sloppy code" because we were careful with our code. A few years ago there was a problem at a major footwear company when the overnight processing extended to mid morning and lost them a lot of sales. I was asked to check the code to see if I could speed it up. The bad code was written in SQL and was to generally accepted "Best Practice" standards. I restructured the code using basic Data Processing principles (1970s) and SQL code written in original IBM SQL syntax. (Optimal machine code for that machine). This made it run 9 times faster, saved 7 hours processing and meant the tills worked when the shops opened. The "expert" SQL coders who maintained the original SQL code said that what I had done was not "Best Practice" and that it was "wrong" but the management were delighted with the increase sales.
Thanks for the video, from a "Fortran For Humans" grognard. I was looking for a quick refresher on Fortran and this seems to be it.
Hi Prof. Very nice presentation. Clear and useful. Thank you. I will watch all four. Cheers!
Very nice presentation. I am completely new to Fortran and I found this tutorial very helpful, thank you! Moving on to part II now. :)
Excited to watch this; I never knew that learning about astrophysics was going to be why I needed to learn Fortran, but I knew I would have to someday. Supposedly knowing some LOGO is helpful, so that's a plus for me.
You are doing great work, I love your fortran video
thank you for this, my uni lecturer is pretty useless at teaching how to code, he basically gave us his pi calculator as the first bit of code weve ever seen and told us to try out a bunch of functions, which i didnt even know how to do that, but now i do!
The problem is that old fortran ignores spaces. Thus “do 30 i =1.20” is interpreted as setting a variable as in “do30i = 1.20” where “do30i” is a legal floating point variable. FORTRAN is a two pass compiler which is why you do not have to give the code a function prototype.
correct!
i was wondering if oyu have to know fortran before hand
Great video! Can you explain how to get that fortran syntax highlighting with atom
yes just click on "settings"->"install" and install the "language-fortran" package. You might also find the "linter-gfortran" package useful, which shows you code problems on-the-fly.
Thank u sir, I have a problem during opening a file inside the program of a simple x.f90 file in my mac, how to solve this problem?please help me
Why does GCC's Fortran compiler give a different answer for 4*atan(1) than Wolfram Alpha?
How would one know which one is correct? This man's example program overestimates the value of pi. Why?
on the atom text editor at the bottom right-hand side, what do you change it to because I can't find FORTRAN there, mine is still showing Plain text. Thanks for your prompt response
PLS HELP!
what should I do when it says "nothing is register" in the Terminal ?
Even when I do gfortran -o maths geometry.f90 maths.f90 I get same the same error that " cannot open file geometry.mod for reading at (1): no such file or directory exists"
Hello professor I really need advice on how I can download FORTRAN on my MacBook .How can I download it ?
first install "homebrew" (brew.sh) then open a terminal and type "brew install gcc" and you should have gfortran working from a terminal. If you are not used to working from the terminal I would recommend taking a basic unix tutorial first.
Amazing set of videos! Now I know what the Makefile is doing! Also, my ~1,200 line Fortran code is now 80 lines with the use of modules :) Thanks! Out of curiosity, is there a way to organize all of the modules and use them from a different directory? My working directory is getting a little cluttered with all of the *.o and *.mod files along with the data? Appreciate any help :) and looking forward to your other videos which look interesting!
yes, just add the line VPATH=dir1 dir2 to the top of the Makefile, where dir1 and dir2 are the name of the subdirectories where your source code files are located
@@DanielPriceAstro Thank you Thank you! You are the Best!
Thank you so much!
Good evening my teacher
can you help me
program loop
implicit none
real :: i
do i = 1, 25
print*, i
end do
end program loop in this code i have instigated i as a real value and it still ouputs a real value
Could you make a video explaining how to install a compiler and IDE for Fortran on a Mac M1? 😌😌😌😌
install homebrew (google for it)->type "brew install gfortran" into the terminal->download VSCode or Cursor AI or other text editor with IDE-like capabilities
Hello,
I want to make a guess about the bug in this do loop. Maybe because 1.20 is a real and not an integer it can not be assigned to the implicit i. So I would guess i was implicit initialized with a value of 0. As 1.20 can not be assigned it will stay 0 and is printed like that. As the loop has no further steps to do, it will finish.
Thanks for the tutorial! And greetings from Darmstadt (Germany)!
PS: Is the tutorials PDF public or is there away to receive it for strictly private use?
Just found the link to the PDF in the comments of the second video. Thanks!
you're half way there. The key is that FORTRAN allowed spaces in variable names, whereas these are not allowed in modern Fortran. So the =1.20 is treated as an assignment to a variable (hint: starting with d makes it a real if implicit types are allowed). For the pdf, it is available from my web page: users.monash.edu.au/~dprice/teaching/fortran/lab-Fortran.pdf
@@DanielPriceAstro so 1.20 is assigned to the variable 'do 30 i' . 'i' as a counter variable holds 0 by default and the leading 30 in front of 'continue' is ommit due to its position?
@@Swamtrooper8 correct !
@@DanielPriceAstro Thanks a lot! It is always nice to learn something new!
But why???
Why does the error statement complain about a named 'constant,' but the type declaration uses the keyword 'parameter?'
It is not consistent. Why isn't the declaration using the keyword, 'constnt' if that's what the compiler believes it is and calls it such?
Else, why isn't then the error statement informing about a parameter instead of a constant?
Come on! It's 2023 and how long have these boffins been writing errors statements and revising Fortran? More than 50 years?
"If you haven't done any programming before", you shouldn't be taking a Fortran 90 course to start with it.
Hi Professor, I am a beginner in Fortran and learning it by myself. The below code gives me error and
Stackoverlfow has not been able to give me any meaningful help. Can you help me with this?
Filename: Univariate_search.f90
----------------------------------------------------------
Compiling with gfortran
12 | f(x,y) = 2.0*x**2 + 2.0*y**2
| 1
Error: Unclassifiable statement at (1)
Compiling with ifort
error #6410: This name has not been declared as an array or a function. [F]
f(x,y) = 2.0*x**2 + 2.0*y**2
^
compilation aborted for new.f90 (code 1)
------------------------------------------------------------------------------------------------------
program Univariate_search
implicit none
real :: a,x,y,x0,y0,f
!initialise the variables
x0=0.0
y0=0.0
!define the functions
f(x,y) = 2.0*x**2 + 2.0*y**2
a=f(x0,y0)
print*, a
end program
you did not define a function correctly.
try this:
program Univariate_search
implicit none
real :: a,x,y,x0,y0,f
!initialise the variables
x0 = 0.0
y0 = 0.0
!error: define the functions
! error: f(x,y) = 2.0*x**2 + 2.0*y**2
a = f(x0,y0)
print*, a
end program Univariate_search
real function f(x,y)
real x,y,z
z = 2.0 * x**2 + 2.0 * y**2
f = z
return
end function f