- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I'm trying to write a routine which should accept an argument of the following type : an array of character string.
The length of the array is unknown and the length of each string is unknown.
Currently the syntax I'm using is:
SUBROUTINE FOO(XTAB)
C
CHARACTER*(*) XTAB
C
DIMENSION XTAB(*)
It compiles but during the execution I've some crash when I try to access the XTAB variable.
Is the syntax I'm using correct ? Why is it not working ?
I'm currently using the Intel Visual Fortran Version 11.1.
Thanks in advance for any help.
I'm trying to write a routine which should accept an argument of the following type : an array of character string.
The length of the array is unknown and the length of each string is unknown.
Currently the syntax I'm using is:
SUBROUTINE FOO(XTAB)
C
CHARACTER*(*) XTAB
C
DIMENSION XTAB(*)
It compiles but during the execution I've some crash when I try to access the XTAB variable.
Is the syntax I'm using correct ? Why is it not working ?
I'm currently using the Intel Visual Fortran Version 11.1.
Thanks in advance for any help.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Franois-Xavier
Hello,
I'm trying to write a routine which should accept an argument of the following type : an array of character string.
The length of the array is unknown and the length of each string is unknown.
Currently the syntax I'm using is:
SUBROUTINE FOO(XTAB)
C
CHARACTER*(*) XTAB
C
DIMENSION XTAB(*)
It compiles but during the execution I've some crash when I try to access the XTAB variable.
Is the syntax I'm using correct ? Why is it not working ?
I'm currently using the Intel Visual Fortran Version 11.1.
Thanks in advance for any help.
I'm trying to write a routine which should accept an argument of the following type : an array of character string.
The length of the array is unknown and the length of each string is unknown.
Currently the syntax I'm using is:
SUBROUTINE FOO(XTAB)
C
CHARACTER*(*) XTAB
C
DIMENSION XTAB(*)
It compiles but during the execution I've some crash when I try to access the XTAB variable.
Is the syntax I'm using correct ? Why is it not working ?
I'm currently using the Intel Visual Fortran Version 11.1.
Thanks in advance for any help.
I assume the lengthmust beknown to the caller at least, so why not send that as an argument? Also, I assume there must be a largest string length that is defined in the calling program, so why not declarean array of elements of just such a maximum length and send that too?
eg
SUBROUTINE FOO(CHARRAY, NELEMENTS, MAXLENGTH)
CHARACTER (LEN=MAXLENGTH) CHARRAY(NELEMENTS)
Ifsome array elements containcharacter strings that are less than MAXLENGTH, then I guess you need to use a terminating character to mark the end of the string, for example the CHAR(0) null character as used by C-strings.
This would mean that strings of length up to MAXLENGTH-1 could be stored, or MAXLENGTH-2 if two CHAR(0) terminator characters are used.
ps. in your code you have
C
CHARACTER*(*)
C
which I assume indicates that you are using fixed format and so the CHARACTER statement is ignored because it begins with 'C'?
CHARACTER*(*) is obsolete Fortran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First, Fortran doesn't have the concept of an array of character strings where each element has a different length. You can approximate this with an array of derived type where each derived type element is a CHARACTER(:), ALLOCATABLE. (You then have to allocate each string to the proper length - this can be done with an assignment to it.)
You don't say how you are passing XTAB to this routine and how the caller declares it. You also don't say what the "crash" is.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page