I've been going through a textbook to learn fortran 90. At the moment I'm learning about dummy arguments and local variables in functions.
One of the exercises is to write a program which asks the user for their first name and last name, then joins the names together and prints the full name. Here's the code:
PROGRAM name_test
IMPLICIT NONE
! Declare variables
CHARACTER(LEN=12) :: first, last
CHARACTER(LEN=30), EXTERNAL :: full_name
! 1. Ask for first name and family name, then read them
PRINT *, "Please enter your first name"
READ *, first
PRINT *, "Please enter your family name"
READ *, last
! 2. Join names together
full_name(first, last)
! 3. Print welcome message
PRINT *, "Welcome ", full_name(first, last)
END PROGRAM name_test
CHARACTER(LEN=*) FUNCTION full_name(first_name, last_name)
IMPLICIT NONE
! Function which joins 2 names to form a full name
! Dummy argument declarations
CHARACTER(LEN=*), INTENT(IN) :: first_name, last_name
! Local variables
CHARACTER(LEN=LEN(first_name)) :: new_first_name
CHARACTER(LEN=LEN(last_name)) :: new_last_name
! Use ADJUSTL to remove redundant leading blanks
new_first_name = ADJUSTL(first_name)
new_last_name = ADJUSTL(last_name)
! Join names
full_name = TRIM(new_first_name)//" "//new_last_name
END FUNCTION full_name
When I try to compile, it comes up with an error referring to the function call at line 15:
full_name(first, last)
This is the compile error:
Error: Unclassifiable statement at (1)