LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-25-2008, 05:12 PM   #1
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
Fortran type conversion error in block data


I'm trying to compile a Fortran program, but am having trouble converting from int to char. I looked into the ICHAR procedure offered with the GNU compiler, but I haven't figured out how to use it since my code is within a block data section. Does anyone have an idea how to change these lines so that I don't get the error? (or is there a compiler option?)

Code:
gfortran -c -I./included_dir -Werror -Wtabs -fall-intrinsics myfortranfile.f
myfortranfile.f:107.15:

      DATA NUM/'0   ','1   ','2   ','3   ','4   ','5   ','6   ',
              1
Error: Incompatible types in assignment at (1), CHARACTER(1) to INTEGER(4)
myfortranfile.f:106.17:

      DATA LEVEL/'+   ','/   ','    ','*   ','0   ','B   '/
                1
Error: Incompatible types in assignment at (1), CHARACTER(1) to INTEGER(4)
make: *** [myfortranfile.o] Error 1
Thanks,
Jameson
 
Old 06-26-2008, 10:09 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The ichar function returns the ASCII code of the characters. To convert from int to char and vice versa you have to use internal file I/O, that is:
Code:
READ(STRING, '(I5)') IVAR    ! converts a numeric string to integer
WRITE(STRING, '(I5)') IVAR   ! converts an integer to a string
but you can do that when assigning values in a DATA statement. You have to respect the type of the variable and eventually do the conversion inside the code when you need them. Also from the second line of your error message:
Code:
DATA LEVEL/'+   ','/   ','    ','*   ','0   ','B   '/
I don't really understand how do you want to convert symbols to integer, unless you really want their ASCII code, in which case I have misunderstood your post.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cifs and 426 Sendfile error: Value too large for defined data type punt Linux - Networking 5 04-10-2008 05:59 AM
conversion and compileng fortran from vax to linux v2010 Linux - Software 1 12-07-2005 10:05 AM
Data type conversion in C zaichik Programming 6 09-10-2005 05:47 PM
c + type conversion dilberim82 Programming 8 03-08-2005 12:17 PM
Fortran unformatted file conversion from Solaris to linux SenorPedo Programming 2 02-29-2004 11:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration