Fortran Count Words In Essay

What is WordCounter?

Apart from counting words and characters, our online editor can help you to improve word choice and writing style, and, optionally, help you to detect grammar mistakes and plagiarism. To check word count, simply place your cursor into the text box above and start typing. You'll see the number of characters and words increase or decrease as you type, delete, and edit them. You can also copy and paste text from another program over into the online editor above. The Auto-Save feature will make sure you won't lose any changes while editing, even if you leave the site and come back later. Tip: Bookmark this page now.

Knowing the word count of a text can be important. For example, if an author has to write a minimum or maximum amount of words for an article, essay, report, story, book, paper, you name it. WordCounter will help to make sure its word count reaches a specific requirement or stays within a certain limit.

In addition, WordCounter shows you the top 10 keywords and keyword density of the article you're writing. This allows you to know which keywords you use how often and at what percentages. This can prevent you from over-using certain words or word combinations and check for best distribution of keywords in your writing.

In the Details overview you can see the average speaking and reading time for your text, while Reading Level is an indicator of the education level a person would need in order to understand the words you’re using.

Disclaimer: We strive to make our tools as accurate as possible but we cannot guarantee it will always be so.

Functions and Subroutines

Functions and subroutines are FORTRAN's subprograms. Most problems that require a computer program to solve them are too complex to sit down and work all the way through them in one go. Using subprograms allows you to tackle bite size pieces of a problem individually. Once each piece is working correctly you then put the pieces together to create the whole solution. To implement functions and subroutines, first write a main program that references all of the subprograms in the desired order and then start writing the subprograms. This is similar to composing an outline for an essay before writing the essay and will help keep you on track.

Functions

The purpose of a function is to take in a number of values or arguments, do some calculations with those arguments and then return a single result. There are some functions which are written into FORTRAN and can be used without any special effort by you, the programmer. They are called intrinsic functions. There are over 40 intrinsic functions in FORTRAN and they are mainly concerned with mathematical functions.

The general way to activate a function is to use the function name in an expression. The function name is followed by a list of inputs, also called arguments, enclosed in parenthesis:

Example

PRINT*, ABS (T) The compiler evaluates the absolute value of T and prints it out
Y = SIN (X) + 45

The compiler calculates the value of sin x, adds 45 then puts the result into the variable Y, where x is in radians.

M=MAX(a,b,c,d)

The compiler puts the maximum value of a, b, c and d into the variable M. If a=2, b=4, c=1 and d=7, then M would have a value of 7.

C=SQRT ( a* * 2 +b* * 2 ) The compiler evaluates the expression, a**2+b**2, sends that value to the SQRT function, and places the answer in the variable

As shown by the MAX function example above, a function may have one or more arguments but will only give one result. Also, as shown by the SQRT function example above, the argument for a function does not have to be a variable. It can be an expression or even a constant if you want to reference it again. One last item to remember, you must use result of a function call in an assignment statement or a PRINT statement, as shown in the examples above.

External Functions

The intrinsic functions in FORTRAN are useful but there will be a time when there is no intrinsic function to meet your needs. When this 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 names: less than six letters or numbers and beginning with a letter. Because of this, function names should not be used 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. There are a few rules for writing external functions:

  • Function subprograms and any other subprograms are placed after the ENDstatement 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 not 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 in 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 (2.0) to Y and the value in c (3.0) to z. However, in the third reference to the function, it is the squared values (25.0, 4.0, 9.0) that are transferred to x, Y and z respectively in the function. Note also that the variable SUM is used only in the function and therefore is declared only in the function.

Example Program

Subroutines

You will want to use a function if you need to do a complicated calculation that has only one result which you may or may not want to subsequently use in an expression. Recall the external function example program where the average was called and then squared in one line. Subroutines, on the other hand, can return several results. However, calls to subroutines cannot be placed in an expression.

In the main program, a subroutine is activated by using a CALL statement which include the subroutine name followed by the list of inputs to and outputs from the subroutine surrounded by parenthesis. The inputs and outputs are collectively called the arguments.

A subroutine name follows the same rules as for function names and variable names: less than six letters and numbers and beginning with a letter. Because of this, subroutine names should be different than those used for variables or functions.

As with functions, there are some rules for using subroutines. Keep these in mind when writing your subroutines:

  • You do not need to declare the subroutine name in the main program as you do with a function name.
  • They begin with a line that includes the word SUBROUTINE, the name of the subroutine, and the arguments for the subroutine.

One way of indicating which variables are inputs and which are outputs is to put the inputs on the first line, use a continuation marker and put the outputs on the second line. See the example program for an application of this programming style.

All variables used by the subroutine, including the arguments, must be declared in the subroutine. The subroutine name is not declared anywhere in the program.

A subroutine is finished off with a RETURN and an END statement.

Exercise 4: Subroutines

In larger programs it is good programming style to include after the FUNCTION or SUBROUTINE statements comments explaining the meanings of the arguments and what the subprogram does.

A hint when you are debugging your programs: When extraordinary, incorrect numbers start appearing from nowhere as your program runs, you probably have not got your subroutine arguments in the right order in either the main program or in the subroutine. The same trick applies to functions. Example Program

Now go to the exercises and work your way through the subprograms and functions.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *