CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

fortran 77 - questions about code and math operations

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By FMDenaro
  • 1 Post By agd

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 9, 2016, 12:44
Default fortran 77 - questions about code and math operations
  #1
Senior Member
 
mohammad
Join Date: Sep 2015
Posts: 279
Rep Power: 12
mostanad is on a distinguished road
hello everybody
what is the meaning of below command in fortran 77? "1.-parameter"
Code:
XC2(I,J)=1.-XC(II,J)
mostanad is offline   Reply With Quote

Old   September 9, 2016, 12:47
Default
  #2
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,849
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
I think "1." is nothing else that a real instead of an integer
sbaffini likes this.
FMDenaro is offline   Reply With Quote

Old   September 9, 2016, 13:32
Default
  #3
Senior Member
 
mohammad
Join Date: Sep 2015
Posts: 279
Rep Power: 12
mostanad is on a distinguished road
Quote:
Originally Posted by FMDenaro View Post
I think "1." is nothing else that a real instead of an integer
and what does it do? i think it is useless.
mostanad is offline   Reply With Quote

Old   September 9, 2016, 13:54
Default
  #4
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,849
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
the array XC is defined as real so that does not generate mismatch (warning) during compilation.
FMDenaro is offline   Reply With Quote

Old   September 9, 2016, 15:11
Default
  #5
agd
Senior Member
 
Join Date: Jul 2009
Posts: 357
Rep Power: 19
agd is on a distinguished road
It's not useless. The value of XC(II,J) is being subtracted from 1.0, and the result is put into XC2(I,J), as in

xc2(i,j) = 1 - xc(ii,j)
lcarasik likes this.
agd is offline   Reply With Quote

Old   September 9, 2016, 15:21
Default
  #6
Senior Member
 
mohammad
Join Date: Sep 2015
Posts: 279
Rep Power: 12
mostanad is on a distinguished road
Quote:
Originally Posted by agd View Post
It's not useless. The value of XC(II,J) is being subtracted from 1.0, and the result is put into XC2(I,J), as in

xc2(i,j) = 1 - xc(ii,j)
thanks agd
but what is advantages of this kind of writing?
mostanad is offline   Reply With Quote

Old   September 9, 2016, 15:46
Default
  #7
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,849
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
1 is an integer while 1. is a REAL*4 type (1d0 would be a REAL*8, that is a double precision) ... doing a mixed types operation like (integer) - (real), the compiler have to do the conversion in the same type of the variable in which you store the result of the difference.

If you use aggressive debugging option, the operation would result in a warning
FMDenaro is offline   Reply With Quote

Old   September 9, 2016, 16:15
Default
  #8
agd
Senior Member
 
Join Date: Jul 2009
Posts: 357
Rep Power: 19
agd is on a distinguished road
What FMDenaro said. It forces an explicit type conversion, since XC is a real variable (assuming the standard FORTRAN variable naming conventions) so that you add a real to a real.
agd is offline   Reply With Quote

Old   September 9, 2016, 16:23
Default
  #9
Senior Member
 
mohammad
Join Date: Sep 2015
Posts: 279
Rep Power: 12
mostanad is on a distinguished road
Quote:
Originally Posted by agd View Post
What FMDenaro said. It forces an explicit type conversion, since XC is a real variable (assuming the standard FORTRAN variable naming conventions) so that you add a real to a real.
so "dot" between two numbers converts type of one of them to another one, then add numbers.That's ok?
mostanad is offline   Reply With Quote

Old   September 9, 2016, 16:56
Default
  #10
agd
Senior Member
 
Join Date: Jul 2009
Posts: 357
Rep Power: 19
agd is on a distinguished road
No - you're overthinking it. That dot is just a decimal point, as in 1.0 or 25.4. FORTRAN by default treats all numbers with decimal points as real, and those without decimal points as integers. It would be clearer if the original programmer had written it as

XC2(I,J) = 1.0 - XC(II,J)

but many programmers get lazy and write simple floats as 1. or 65. rather than 1.0 or 65.0.
agd is offline   Reply With Quote

Old   September 10, 2016, 01:50
Default
  #11
Senior Member
 
mohammad
Join Date: Sep 2015
Posts: 279
Rep Power: 12
mostanad is on a distinguished road
Quote:
Originally Posted by agd View Post
No - you're overthinking it. That dot is just a decimal point, as in 1.0 or 25.4. FORTRAN by default treats all numbers with decimal points as real, and those without decimal points as integers. It would be clearer if the original programmer had written it as

XC2(I,J) = 1.0 - XC(II,J)

but many programmers get lazy and write simple floats as 1. or 65. rather than 1.0 or 65.0.
Thanks agd
U teach a new lesson
mostanad is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison between C/C++ and Fortran? rick Main CFD Forum 45 September 6, 2011 01:52
Fortran 90 faster than C/C++ B. R. Guirguis Main CFD Forum 48 March 6, 2006 14:49


All times are GMT -4. The time now is 13:56.