Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29267 Discussions

Create arrays or vectors as I want in Ifort Linux

katrinastone
Beginner
820 Views
Hi all,

I'm new in Ifort and I have a little problem with a code, maybe it's a simple problem, who knows but I don't know resolve...

I have a vector with nn data. I need to separate the vector in mm smalls vectors depending of one condition (I know how do that!).
I want that if I change the value of mm the code makes the mm vectors automatically, the problem is I can't image how define the vectors without changing the code structure each time.... Thanks a lot for the help!
0 Kudos
7 Replies
mecej4
Honored Contributor III
820 Views
You have not yet stated whether mm has a known value, or is to be determined from one or more conditions, and whether or not nn is divisible by mm.

Thus, while I cannot think of a specific answer, I suggest that you look at the WHERE statement and the WHERE construct, which are described in Fortran reference manuals.
0 Kudos
katrinastone
Beginner
820 Views
Hi,

For example, I have a vector with 36 values and I have to separate this vector in 5 parts. But the data in the vector and the separated parts (smalls vectors) change depending of the what I need. In Fortran you MUST declare each vector, but I don't want to change the code every time I change the information. So, I need the code itself read the number of parts and generate the vectors related.

Thanks!
0 Kudos
jimdempseyatthecove
Honored Contributor III
820 Views
is the Fortran code going to manipulate the parts?
Are the parts polymorphic? (int(1), int(2),...real(8), char(1), char(2),...user defined type)
When the manipulation is other than byte copy (and, or, cat, ...) then it may be difficult to accomplish what you ask without knowing the type.

However, you can pass field start, end for character field mapping (or array population should these vectors contain numeric data).

character(MAX_CHARS_IN_VECTOR) :: Vector ! you choose max size

type FieldPosition
integer :: iFrom, iTo ! 0 == not mapped
end type FieldPosition
...
type(FieldPosition) :: Field(MAX_FIELDS) ! you choose max fields

CALL GetFields(Field, MAX_FIELDS) ! populate array from header in file of data
...
CALL ReadVector(Vector, MAX_CHARS_IN_VECTOR)
do I=1,MAX_FIELDS
if(Field(I)%iFrom == 0) exit
CALL DoSomethingWithField(Vector(Field(I)%iFrom:Field(I)%iTo))
end do
0 Kudos
katrinastone
Beginner
820 Views
Thanks!

Fortran IS going to manipulate the parts.
The parts will be real or integer

But the problem still exists! You must wrote the vector and set up the code every time. :(
0 Kudos
mecej4
Honored Contributor III
820 Views
So, polymorphism will not suffice. I am afraid that Fortran will not come endowed with the clairvoyance that you desire for many years to come.
0 Kudos
jimdempseyatthecove
Honored Contributor III
820 Views
I suggest a design a vector consisting of an unknown number and sequence of previously defined types. The types contained within the vector have a type code. You also define the operators for these types. This can be done with F2003 features. What you cannot have is an unknown type (unless that type brings in the operator functions). This potentially can be done with a DLL (shared library). This is similar to having a free formatted file where variable length record (vector) contains {type ID}{type data}{type ID}{type data}...

Jim Dempsey
0 Kudos
jimdempseyatthecove
Honored Contributor III
820 Views
Perhaps katrinastone could post a diagram of what is desired and pseudo code of the operations desired.

Jim Dempsey
0 Kudos
Reply