- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to use some dynamic character length for some variable. I have tried several coding, but non of them works:
Character*(*) title
Character (LEN=*) title
Character title*(*)
All have compilation errors.
Anyone knows what is right way to do this?
Thanks.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortran 2003 adds a feature for dynamically-allocated-length character variables, but that's not supported yet by Intel Fortran.
Fortran 90/95 describes a module called ISO_VARYING_STRINGS which uses existing language features to create a varying string type. The initial version of this had some bad memory leaks due to inadequacies in Fortran 90. Fortran 95 remedied the problem and a variant was created to make use of that. There's another version that uses the "allocatable component" feature of F2003 (which Intel Fortran DOES support), but I can't guarantee that it all works properly. Feel free to try it.
Learn more (and download) here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
From the IVF documentation:
In the following example, NAME2 is an automatic object:
SUBROUTINE AUTO_NAME(NAME1)
CHARACTER(LEN = *) NAME1
CHARACTER(LEN = LEN(NAME1)) NAME2
For your use try ...
subroutine YourSubroutine(InputTitle)
Character(LEN=*) InputTitle
Character(LEN = LEN(InputTitle)) title
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Of course, I don't really know what pfwang had in mind.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I have tried the example that Jim suggested. I still could not get the flexibility of inputting characters with variable length and then patch it to a fixed name without leaving blank space in between.
subroutine YourSubroutine(InputTitle)
Character(LEN=*) InputTitle
Character(LEN = LEN(InputTitle)) title
The InputTitle still needs to begiven a fixed length in the main program. The above coding does not change the length of InputTitle for InputTile and/or title. These two variables always keep the same length of InputTitle, the length of which is defined in main program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page