Code Comments
Programming Forum and web based access to our favorite programming groups.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!"
Post Follow-up to this messageCarlie 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 so mething 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 compon ent. > 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 encourage s sloppiness (goodness, I sound like a school marm!) I think having to specify the kind t ype 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" p lenty 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 st ill 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
Post Follow-up to this messageI 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!"
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.