Prev: many runs in one directory
Next: pressure and fortran
From: James Van Buskirk on 5 Jun 2010 16:30 "Richard Maine" <nospam(a)see.signature> wrote in message news:1jjlww8.gf2p4izgoelsN%nospam(a)see.signature... > The "usual" workaround for things where you want different properties > for different elements of an array applies. Make it an array or derived > type, something like > type string_type > character, allocatable :: string*(:) > end string_type > type(string_type) :: strings(2) !-- Or whatever shape. > Then each element of the array can be separately allocated to a > different length. (This requires f2003 for allocatable length). > I'm not at all sure that it would be suitable for the OP's purpose, > though, as, among other things, I don't think you can write a handy > literal form for this. No, I think this would be just great given full f03. Just change the last declaration above to: type(string_type), allocatable :: strings(:) Then he could write: strings = [string_type('Hello'),string_type(' '),string_type('World!')] and then he could: CALL routine1(strings) or for that matter: CALL routine1([string_type('Hello'),string_type(' '),string_type('World!')]) without the temporary(?) strings array. The OPTIONAL arguments way is much more arduous than this because one really needs different code in SUBROUTINE routine1 for each possible number of passed arguments (we assume the caller isn't cruel enough to skip any via keywords...) Unfortunately gfortran doesn't have this implemented yet TTBOMK; if ifort does, though, I would go with it in a heartbeat because other compilers may catch up by the time you want to port the code. -- write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, & 6.0134700243160014d-154/),(/'x'/)); end
From: Gib Bogle on 5 Jun 2010 20:07 Jovan Cormac wrote: > > WRITE(*,*) 'Hello', ' ', 'world' > > will do just what I described (without any additional processing, of > course), so technically, it is certainly possible. > > In the most limited sense, you can achieve what the write statement does by creating the string exactly as you want it WRITE(mystr,*) 'Hello', ' ', 'world' then passing mystr to the subroutine. No doubt this doesn't help with your real problem.
From: Richard Maine on 5 Jun 2010 20:53 glen herrmannsfeldt <gah(a)ugcs.caltech.edu> wrote: > Richard Maine <nospam(a)see.signature> wrote: > >> dpb wrote: > > >> > do i = 1, 3 > >> > call doit(str(i)(:min(1,len_trim(str(i))) > >> > end do > >> > end > > (snip) > > > While on the subject, I'm wondering why you have the max (or min) at > > all? I'm confused as to what is intended here and why it isn't just > > > call doit(trim(str(i))) > > > I wonder whether you might have been recalling the f77 limitation that > > did not allow zero-length substrings. > > I thought the OP wanted one space between the words, though > that isn't so obvious. He didn't seem to want them jammed together. > > call doit(trim(str(i))//' ') Hmm. Ok. There's a bit of guessing here about what the original problem really was, but I suppose it is plausible guessing. If I were trying to output an array of "words", where trailing blanks were assumed to be insignificant, but a space between each word was wanted, I'd just write something like write (*,*) (trim(str(i)),' ', i = 1 , size(str)) That assumes that an extra trailing blank is harmless. It also assumes that list-directed output acts more "nicely" than is actually guaranteed. Both of those assumptions could be fixed with a little extra work. Perhaps the biggest guess here is that a blank is always wanted as a word separator. If that's what I always wanted, I'd write the code to do that rather than trying to put the blank as a separate "word" in the array. This would still require that the array be constructed from a valid array constructor (or otherwise), perhaps using the f2003 form of array constructor. -- Richard Maine | Good judgment comes from experience; email: last name at domain . net | experience comes from bad judgment. domain: summertriangle | -- Mark Twain
From: robin on 5 Jun 2010 21:22 "dpb" <none(a)non.net> wrote in message news:hue9ak$a3m$1(a)news.eternal-september.org... | My understanding was that OP didn't want a zero-length string in his | routine but didn't like trailing blanks on otherwise non-blank strings, He wanted whatever was in the argument. If the corresponding argument contained a (blank) string of length 1, the OP wanted that printed. What he didn't want was the appending of trailing blanks. | either; the above simply provided that to the subroutine. If I missed | the target there as well as the backwards logic selection, won't be | first time that's happened, either... :)
From: robin on 5 Jun 2010 21:24
"glen herrmannsfeldt" <gah(a)ugcs.caltech.edu> wrote in message news:hueagr$qrq$1(a)speranza.aioe.org... | I thought the OP wanted one space between the words, though | that isn't so obvious. The OP didn't want blanks appended to any of the array elements. |