Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29280 Discussions

dynamic character length declaration

pfwang
Beginner
1,699 Views

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.

0 Kudos
5 Replies
Steven_L_Intel1
Employee
1,699 Views
Fortran 95 doesn't have such a feature. The syntax you're using is for passed-length character arguments, valiid only for procedure arguments.

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.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,699 Views

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
0 Kudos
Steven_L_Intel1
Employee
1,699 Views
That's not really the same thing - that declares a local variable whose length is based on a dummy argument, but once it is created, the length cannot change for the rest of the routine.

Of course, I don't really know what pfwang had in mind.
0 Kudos
pfwang
Beginner
1,699 Views

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.

0 Kudos
Steven_L_Intel1
Employee
1,699 Views
TRIM is your friend.
0 Kudos
Reply