Sunday 17 May 2020

EXTERNAL FUNCTION

EXTERNAL FUNCTION-

The intrinsic functions in FORTRAN are useful but there will be a time when there is no intrinsic function to meet your needs. when the occurs you may write your own function subprogram.
you have to do one thing in the main program to use an external function you need to declare the function name in the variable declaration section. Function names follow the same rules as for variable name less then with a letter. Because of this, as variable names. once that is done and the function is written activating it is just like activating an intrinsic function.
Now you are ready to write your function. These are a few rules for writing external function:-

-> Function subprograms and any other sub programs are placed after the END statement of the main program.

-> They are started with a line that includes the type of value the function will return, the function name and the list of arguments the function takes as inputs.

-> Any variables the function uses, including the arguments, must be declared in the function right after the first line. The function name is hot declared within the function.

-> You must use the function name in an assignment statement within the function. This is how the compiler knows which value to pass back to the main program.

-> A function must finish with RETURN and END statements.

The example program below shows how to write an external function. which calculates the average of three numbers. Note the argument list inn the main program does not use the same variable names as the argument list in the function. This is not a problem because a function is a self contained entity whose only tie with the main program is the order of the values in the argument list. so in the first reference to the function, the value in A(5.0) gets transferred to x, the value in B(3.0) to z. However, 
It is the squared value (25.0,4.0,9.0) that are transferred to x,y and z respectively in the function and therefore is declared only in the function







RAVISHANKAR THAKUR M.SC PHYSICS

No comments:

Post a Comment

Quantum Atom Theory

There is no concept of ‘the moment of now’ in physics, is this why we have no Grand Unified Theory The moment of now can be represented by t...