Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new to Fortran, need help with Strings and Characters

Status
Not open for further replies.

DannyPants

Technical User
Nov 24, 2008
2
US
I'm trying to modify some Fortran code, and I'm having trouble counting the number of characters in a string. Below is the line of code I have a question about. Specifically, I don't understand why CHARACTER(88) says there are 88 characters in this string. At most I can only count 82 characters (by counting the characters in-between the " " and also each tab counts as one character. Am I miscounting? Or is there a mistake in this code? How many characters do you guys count, and how did you do it? Thanks for the help, this is my first post here!
Code:
CHARACTER( 88), PARAMETER :: FmtBEDt = "(I3,'"//Tab//"',2(F6.1,'"//Tab//"'),4(F6.3,'"//Tab//"'),2(F7.2,'"//Tab//"'),5(F6.3,'"//Tab//"'),F10.1,'"//Tab//"',F11.1,'"//Tab//"',F12.3)"
 
CHARACTER(88) will always give you 88 characters. If you do not want the trailing characters, use TRIM before you use LEN.

I counted 83 characters.
 
So does the number in the CHARACTER statement have to exactly match the number of characters in the string that you type? It sounds like you are saying that the number you pass to the CHARACTER statement can be as large as you want, but what if your string contains more characters than the number of characters you input into CHARACTER? Will the program crash?

Thanks so much for your reply!
 
Number of character - yes
Crash - no

If you wish to use it as an argument to a routine, declare the argument as CHARACTER*(*)

Note that CHARACTER*88 is a packed character string. CHARACTER(88) is an array of 88 characters. Slightly different in some implementations in that CHARACTER(88) can take up 88 words internally whereas CHARACTER*88 may only take up 22 32-bit words. On some implementations, they're exactly the same.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top