Clicky

Fortran Wiki
Questions (Rev #8, changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #7 to #8: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

This page is for general questions about Fortran. If you’re searching for something, such as a library or routine to perform a particular task, feel free to ask here.


Q: Hi! I’m quite new in FORTRAN, and I’m using Microsoft Visual 2008 as IDE and Intel Fortran as compiler. I’d like to know how I can creat a fortran library using them and how I can link my code to the library. Thanks.


Q: Hi! I have a quite simple question: if I have an array of integers as A = (/1,2,3,4,5/), how do I convert this array in the number 12345? Thank you very much in advanced for your help Regards

A: There are a number of ways you could go about doing this. Perhaps the simplest is to create a loop over the array index and use integer arithmatic operations.

number = 0
DO i=1,SIZE(A)
 number = number + A(i)*10**(SIZE(A)-i)
END DO

Note that I have not tested this to confirm it’s correctness, but it should be correct. If not, you could easily figure out where I made a typo or went wrong. One could also write the array elements to a character variable and then read the character variable back as an integer.


Q: Does anyone know how to overload intrinsic functions? Preeferably using f95 comnpliant syntax if possible. Thanks.

A: It’s actually simple. You just overload the function you want. For example, you can overload ABS:

module myabs
implicit none
type vector
 real :: x, y, z
end type vector
interface ABS
 module procedure absvector
end interface ABS
contains
 real function absvector(vec)
 
 type(vector), intent(in) :: vec
 absvector = sqrt(vec%x ** 2 + vec%y ** 2 + vec%z ** 2)
 end function absvector
 
end module myabs

If you test this, you’ll see that you can now call ABS with REAL, INTEGER, COMPLEX, and even vector.


category: help

(追記) (追記ここまで)(追記)

Q: I am new to Fortran and want to compile a source file. But it gives me a lot of errors:

(追記ここまで)
(追記) (追記ここまで)(追記)

evfit.f90(47): error #5082: Syntax error, found IDENTIFIER ‘UNIT’ when expecting one of: ( % [: . = => C unit conversion -^ evfit.f90(47): error #6404: This name does not have a type, and must have an explicit type. C C unit conversion ^ evfit.f90(47): error #6404: This name does not have a type, and must have an explicit type. CONVERSION C unit conversion ^ evfit.f90(134): error #5120: Unterminated character constant c emin = energia allequilibrio, ottenuta minimizzando chi2 -^ evfit.f90(134): error #5144: Invalid character_kind_parameter. No underscore c emin = energia allequilibrio, ottenuta minimizzando chi2 ^ evfit.f90(134): error #5082: Syntax error, found IDENTIFIER EMIN when expecting one of: ( % : . = => c emin = energia allequilibrio, ottenuta minimizzando chi2 -^ evfit.f90(167): remark #8291: Recommended relationship between field width W and the number of fractional digits D in this edit descriptor is W>=D+7. if(istat.eq.1) write(iun,( Equation of state: , ^ evfit.f90(169): remark #8291: Recommended relationship between field width W and the number of fractional digits D in this edit descriptor is W>=D+7. if(istat.eq.2) write(iun,( Equation of state: , -^ evfit.f90(171): remark #8291: Recommended relationship between field width W and the number of fractional digits D in this edit descriptor is W>=D+7. if(istat.eq.3) write(iun,( Equation of state: , ^ evfit.f90(173): remark #8291: Recommended relationship between field width W and the number of fractional digits D in this edit descriptor is W>=D+7. if(istat.eq.4) write(iun,( Equation of state: , ^ evfit.f90(198): error #5082: Syntax error, found IDENTIFIER MINIMIZATION when expecting one of: ( % : . = => c minimization through random seek followed by ZXSSQ (imsl). Input: -^ evfit.f90(199): error #5082: Syntax error, found IDENTIFIER FUNC when expecting one of: ( % : . = => c func, called by ZXSSQ, produces a vector Deltaf(npt) -^]

(追記ここまで)
(追記) (追記ここまで)(追記)

Does anyone know how to handle this?

(追記ここまで)
Revision from August 12, 2013 07:17:58 by Anonymous Coward
Forward in time (4 more) | Back in time (7 more) | See current | Hide changes | History | Rollback | View: Source | Linked from: HomePage

AltStyle によって変換されたページ (->オリジナル) /