Need Help with Fortran compiler errors

Click For Summary

Discussion Overview

The discussion revolves around troubleshooting Fortran compiler errors encountered while compiling a program. The focus is on understanding specific error messages related to character constants and invalid characters, as well as seeking guidance on writing a program to determine astrological signs based on input dates.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant reports receiving "Unterminated character constant beginning at (1)" and "invalid character in name" errors in their Fortran code.
  • Another participant suggests that the issue may be due to invisible characters in the source code.
  • A different participant mentions that the file extension should be f90 for the variant of Fortran being used.
  • One participant proposes creating an array of months to simplify string comparison and conversion to month numbers.
  • Another participant emphasizes breaking down the task into smaller components to facilitate the programming process.
  • Multiple participants express confusion about Fortran and seek resources for beginners.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the cause of the initial compiler errors, as different suggestions are offered without definitive resolution. The discussion on the astrological sign program also remains unresolved, with various approaches proposed but no agreement on a specific solution.

Contextual Notes

Participants note potential issues with spacing and formatting in Fortran code, which may affect compilation. There is also mention of the need for proper file extensions and the importance of using code tags for clarity in communication.

Who May Find This Useful

Individuals learning Fortran, particularly beginners facing compiler errors or seeking to understand program structure related to date handling and string manipulation.

suezxc6
Messages
11
Reaction score
0
Summary:: so I am trying to compile this program and i keep on getting "Unterminated character constant beginning at (1)" and "invalid character in name" at the months section. what do i have to change to fix it?

thanks

Fortran:
program Lab6

implicit none
character*9 month

integer monthNum, pos
character*108 months
months = "January       February March       April     &

                  &May             June         July           August  &

                  &SeptemberOctober November December "
print*, "Enter the month name"

read*, month
pos = index(months,month)

if (pos .eq. 0) then

print*, "The month is invalid"

else

monthNum = pos/9 + 1

! process day

print*, month, " is month #", monthNum

print*, "now process day"

end if
stop

end
<Moderator's note: code tags added>
 
Last edited by a moderator:
Physics news on Phys.org
I added code tags to your post, but you will need to repost to get the spacing correct.

I see nothing wrong, assuming that the blank lines 18 and 20 are not really present. Which compiler are you using?
 
GNU. And there are no blank lines present. At line 17 i get "Unterminated character constant beginning at (1)" then at 19 and 21 i get "invalid character in name".
 
I have no problem compiling it with gfortran. Can you show the compile command you are using?
 
You may have an invisible character, such as ESC, in the source code. How that happened and how you get rid of it I don't know.
 
a.png

this is what it looks like.
 
The file extension needs to be f90, since you re using that variant of Fortran.
 
  • Like
Likes   Reactions: berkeman and jedishrfu
Thanks, it works!
I'm new to fortran and this is all still pretty confusing. Is there by any chance a fortran for dummies book i could buy online somewhere? With lectures being canceled I am going to need all the help i can get
 
ok sorry yall. its me again and i need help with this exercise.
I have to write a program that will output the astrological signs for given birthdays. It will have to read a date in a given format and after a simplified validity check it has to determine the corresponding astrological sign. So if i wrote September 21 it has to output virgo. I'm getting a lot of errors and also having a hard time with the part i italicized.

program Lab6
implicit none

character*1 reply

do
print*, "Do you want to convert a date, Y or N?"
read*, reply
if (reply .eq. "N" .or. reply .eq. "n") exit
print*, "process a date"

character*9 month
integer monthNum, pos, day

character*36 months1 / "January February March April "
character*36 months2 / "May June July August "
character*36 months3 / "SeptemberOctober November December "

character*108 months

integer lastDay(12) / 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 /

integer splitDay(12) / 19,18,20,19,20,20,22,22,22,22,21,21 /

character*11 astroSign(12) / "Capricorn", "Aquarius",
x "Pisces", "Aries", "Taurus", "Gemini", "Cancer",
x "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius" /

months = months1 // months2 // months3

print*, "Enter the month name"
read*, month

pos = index (months, month)
if (pos .eq. 0) then
print*, "The month is invalid"
else
monthNum = pos/9 + 1
monthNum = mod(monthNum, 12)+1
print*, "Enter the day"
read*, day
if (invalid day for the given month) then
print*, "The day is invalid"
else
adjust monthNum to align with astrological sign
print*, "The astrological sign is: ", astroSign(monthNum)
end if
end if

end do
stop
end
 
  • #10
I suggest you make an array of months as you did for the astrological signs. This will make string comparison easier and you can also more easily convert the month into a number.

Think of how you would do things yourself, with a calendar you are not familiar with. First, you would check to see if the month is part of the list of valid months, then if the day is a valid number for that month. I let you figure out how you would then figure out the corresponding star sign. This is the basis of algorithms: decompose the big task into smaller tasks.
 
  • #11
  • #12
@suezxc6 Please use code tags (>_ Inline code in the dropdown menu) when posting code:
Screen Shot 2020-03-20 at 13.06.51.png
I have also moved the thread to the homework forum.
 
  • #13
FORTRAN can be very space and column dependent. You need to use the code tags (see the '</>' tag at the top of the edit window) to keep those exactly like your program code or it will not be possible to get help.
 

Similar threads

Replies
4
Views
3K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
5
Views
3K
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K