Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PARAMETER attribute for data type

Status
Not open for further replies.

ya0037

Programmer
Oct 7, 2010
30
DE
Dear All,

I have two questions I hope someone could help me.

If I want to use parameter attribute for data type declaration there would be some problems, please look at the below example:

TYPE PEOPLE ! Defining derived type PEOPLE
INTEGER AGE
CHARACTER*20 NAME
END TYPE PEOPLE
TYPE(PEOPLE), Parameter :: SMITH = PEOPLE(25,'John Smith')

TYPE triplet
REAL, DIMENSION(3) :: vertex
END TYPE triplet
TYPE(triplet), PARAMETER :: t = triplet(1.0)

In this example there is no problem but if I want to give different value to the data type variable what should I do??

TYPE triplet
REAL, DIMENSION(3) :: vertex
END TYPE triplet
TYPE(triplet), PARAMETER :: t = triplet(1.0, 2.0, 3.0)

I mean how should I give different value to the data type above :

t%vertex(1)=1.0
t%vertex(2)=2.0
t%vertex(3)=3.0


Second question:::

There are some papers in which there are some comparisons between FORTRAN and c++ speed. In all of them they stated that FORTRAN is faster than C++.

There it comes my question, if FORTRAN is faster why all the big software and open source projects like big MD (Molecular Dynamics) codes are changing toward c++, in these numerical codes speed is very important, but they gradually changing toward c++.

I am wondering should we change toward that!!!!!


Thank you very much.

I am really looking forward to hearing from you.

Regards,







 
What do you mean by different values? If you want to change the values, leave away the word "PARAMETER
 
I have told that,

I want data type parameter declaration that gives the following result : t%vertex(1)=1.0 and t%vertex(2)=2.0 and t%vertex(3)=3.0
 
My second example will give error:

TYPE triplet
REAL, DIMENSION(3) :: vertex
END TYPE triplet
TYPE(triplet), PARAMETER :: t = triplet(1.0, 2.0, 3.0)

how should I correct it?????

If I give
TYPE(triplet), PARAMETER :: t = triplet(1.0)
then t%vertex(1)=1.0 and t%vertex(2)=1.0 and t%vertex(3)=1.0

But I want the different value:
t%vertex(1)=1.0 and t%vertex(2)=2.0 and t%vertex(3)=3.0

 
Only 10% (or less) LOC of large computational program code performs math calculations (traditional Fortran area). There are massive data pre- and post-processing, complex process control, specific DBMSs, data viewing and other modules in these programs. C++ is a most comfortable and effective language in these problem areas. In essence it's system programming, not "a formula translation".

That's why so many serious "number-crunching" programs goes "from Fortran to C++".

That's a good example of a senseless statement: "the language A is faster than the language B". Underlying abstract Fortran and C++ machines are the same. Both languages are strong static typed. Classic CRAY-like processors (remember Fortran 90+ arrays vector-oriented stuff) are historical artifacts now. Modern cluster Unix-driven supercomputers - natural areal of C++ codes.

Good programs (written in C++ or Fortran) are faster than bad programs (written in Fortran or C++) - that's all. There are much more good C++ programmers in the world now...

There are tons of legacy Fortran codes. So Fortran (now borrowed most of C++ OOP features;) is immortal ;)
 
First of all, I'm happy to hear that there are people who think that fortran is immortal :), I don't feel for learning C++

About the original question, it's a type incompatibility that gives the error.
Code:
PROGRAM Test

TYPE triplet
  REAL, DIMENSION(3) :: vertex
END TYPE triplet

TYPE(triplet), PARAMETER :: t=triplet(RESHAPE(SOURCE=(/1.0,2.0,3.0/),SHAPE=(/3/)))

WRITE(*,*)t%vertex(:)

END PROGRAM Test
Gives:
Code:
   1.0000000       2.0000000       3.0000000
As output

The fact that you can say t=triplet using the typename for assigning values was new to me, thanks for that!
 
Hi all

I completely agree with GerritGroot, I´m happy to see that ArkM thinks that Fortran in immortal! I learned Fortran years before C was even invented and I have used it extensively in my work as an engineer and still do (although many simple calculations can be done in Excel). I have had to write a few C programs during the years, but still consider C inferior to Fortran in my area of work. Also these endless "{" and "}" are boring...


 
Dear All,

Thank you all very much, I understand my mistake.

Instead of :
Code:
  TYPE(triplet), PARAMETER :: t = triplet(1.0, 2.0, 3.0)

I should simply use:
Code:
  TYPE(triplet), PARAMETER :: t = triplet((/1.0, 2.0, 3.0/))


Thanks a lot.

Best Regards,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top