Home > Archive > Fortran > October 2004 > F2007: another possible improvement
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
F2007: another possible improvement
|
|
| Carlie J. Coats 2004-10-29, 3:58 pm |
|
INMHO, array constructors should allow us to declare the types of the
entries in a declaration, so that something like the following would
be possible:
CHARACTER(LEN=16), PARAMETER:: WEEKDAYS( 7 ) = &
CHARACTER(LEN=9)(/
'Sunday', 'Monday', 'Tuesday', &
'Wednesday', 'Thursday', 'Friday' &
'Saturday', 'Sunday'
/)
so that all of the names of the days would be coerced into the same
length and therefore could be used as the PARAMETER-value for the
array WEEKDAYS, for example.
Likewise, one should be able to do an array constructor like
REAL(KIND=foo)(/ 1, 2.0, 3.0D0 /)
where all of the entries are coerced into REAL(KIND=foo) before
being used as array-entries in the array-constructor.
fwiw--
Carlie J. Coats, Jr. carlie.coats@baronams.com
Environmental Modeling Center carlie_coats@ncsu.edu
c/o North Carolina State University MEAS Department
1125 Jordan Hall Campus Box 8208
Raleigh, NC 27695 phone: (919)515-7076 / fax: (919)515-7802
"My opinions are my own, and I've got *lots* of them!"
| |
| Paul Van Delst 2004-10-29, 3:58 pm |
| Carlie J. Coats wrote:
>
> INMHO, array constructors should allow us to declare the types of the
> entries in a declaration, so that something like the following would
> be possible:
>
> CHARACTER(LEN=16), PARAMETER:: WEEKDAYS( 7 ) = &
> CHARACTER(LEN=9)(/
> 'Sunday', 'Monday', 'Tuesday', &
> 'Wednesday', 'Thursday', 'Friday' &
> 'Saturday', 'Sunday'
> /)
>
> so that all of the names of the days would be coerced into the same
> length and therefore could be used as the PARAMETER-value for the
> array WEEKDAYS, for example.
I'm . What length do you want? Len=16 or Len=9? What's wrong with something like:
CHARACTER(*), PARAMETER:: WEEKDAYS( 7 ) = &
(/'Sunday', 'Monday', 'Tuesday', &
'Wednesday', 'Thursday', 'Friday' &
'Saturday', 'Sunday'/)
and with the result that LEN(WEEKDAYS(1)) = the length of the longest component.
> Likewise, one should be able to do an array constructor like
> REAL(KIND=foo)(/ 1, 2.0, 3.0D0 /)
> where all of the entries are coerced into REAL(KIND=foo) before
> being used as array-entries in the array-constructor.
This one I like even less - for personal reasons, since I think it encourages sloppiness
(goodness, I sound like a school marm!) I think having to specify the kind type in the
declaration ala
REAL(foo) :: x(3)
x = (/ 1.0_foo, 2.0_foo, 3.0_foo /)
makes one think more about the precision required (e.g. do I even need KIND=foo? Or will
KIND=bar be enough? Is "x" declared as KIND=foo or KIND=bar?) I've "fixed" plenty of code
that didn't work right because people assumed, e.g., the variable assignment x=0.1 meant x
really was 0.100000000000....etc, and not x=0.09999999485763.....whatever. (Aside: the
thing that gets me about this is that a few times the result is said people thinking
Fortran is a stupid language. Oof. I'm amazed at the number of people who still don't grok
how numbers are represented in computers.)
> Carlie J. Coats, Jr. carlie.coats@baronams.com
> Environmental Modeling Center carlie_coats@ncsu.edu
> c/o North Carolina State University MEAS Department
Hey! I thought *I* was at EMC! :o)
cheers,
paulv
--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
| |
| Dick Hendrickson 2004-10-29, 3:58 pm |
| I think F2003 does what you want, you can
put a type-spec as the leading thing in an array
constructor. The syntax rule is
R465 array-constructor is (/ ac-spec /)
....
R466 ac-spec is type-spec ::
or [type-spec ::] ac-value-list
And "type-spec" is
R401 type-spec is intrinsic-type-spec
or derived-type-spec
which covers anything you should want ;). It coerces all
of the following constructor values into the specified type.
An example is:
(/ CHARACTER(LEN=7) :: 'Takata', 'Tanaka', 'Hayashi' /)
Before anyone asks, the first form
(/ type-spec:: /)
allows you to create a zero-size array of a specific type.
You couldn't do that before F2003. (There was an ambiguity
in what (/ (I, I=1,0) /) meant.)
Dick Hendrickson
Carlie J. Coats wrote:
>
> INMHO, array constructors should allow us to declare the types of the
> entries in a declaration, so that something like the following would
> be possible:
>
> CHARACTER(LEN=16), PARAMETER:: WEEKDAYS( 7 ) = &
> CHARACTER(LEN=9)(/
> 'Sunday', 'Monday', 'Tuesday', &
> 'Wednesday', 'Thursday', 'Friday' &
> 'Saturday', 'Sunday'
> /)
>
> so that all of the names of the days would be coerced into the same
> length and therefore could be used as the PARAMETER-value for the
> array WEEKDAYS, for example.
>
> Likewise, one should be able to do an array constructor like
> REAL(KIND=foo)(/ 1, 2.0, 3.0D0 /)
> where all of the entries are coerced into REAL(KIND=foo) before
> being used as array-entries in the array-constructor.
>
>
> fwiw--
>
> Carlie J. Coats, Jr. carlie.coats@baronams.com
> Environmental Modeling Center carlie_coats@ncsu.edu
> c/o North Carolina State University MEAS Department
> 1125 Jordan Hall Campus Box 8208
> Raleigh, NC 27695 phone: (919)515-7076 / fax: (919)515-7802
> "My opinions are my own, and I've got *lots* of them!"
|
|
|
|
|