Home > Archive > Fortran > February 2005 > Another question for you - files name
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 |
Another question for you - files name
|
|
| Steve_Vai 2005-02-22, 4:01 pm |
| I would like to create files whose name is related to one on more
input-output data of my programs.
The problem is that I don't know how to give a "dynamic name" to files,
neither if it's possible or not to be honest at all :-)
At the moment, I create files in this way:
open (34, file='chosen.kumac')
were "chosen.kumac" it's not dynamic at all - I mean, it's not a function
of the input-output of the program.
My problem, basically, is that the number of files I have to create depends
on input-output data: so a priori, in my program, I can't write these
instruction (while I can write IN files dynamic stuff - I still thank you
for your help).
I could manage this problem with some "if - then - goto" statements, but
that wouldn't be a serious solution.
Ciao!
| |
| Gareth Owen 2005-02-22, 4:01 pm |
| Steve_Vai <gio@localhost.localdomain> writes:
> I would like to create files whose name is related to one on more
> input-output data of my programs.
Create a character variable of the appropriate length
then use a formatted write() statement to modify the character variable
-----------------------------------------------------------------------------
character*20 :: base = './output/LST....'
integer hours
{your code here, setting variable hours depending on the state}
write (base(13:16),905) hours
905 format(i4.4)
open(unit=999,file=base,form='formatted'
,status='unknown')
-----------------------------------------------------------------------------
You don't have to use an integer,
just use the format statement approprite to what you want to write.
--
Gareth Owen
Nerd Test: How many syllables do you think there are in the word "coax"?
| |
|
| if all you want to do is to change the filename, then, you can append
something suitable to the filename :
write(filename,'(a,i3.3)') "chosen.kumac.", some_integer
open(34, file = trim(filename))
if you keep changing some_integer between writes, you get different
filenames.
Hope this helps,
Srinivasan
| |
| Richard E Maine 2005-02-22, 4:01 pm |
| In article <1109097139.412126.190640@c13g2000cwb.googlegroups.com>,
"ajs" <ajs00g@gmail.com> wrote:
> open(34, file = trim(filename))
The trim here is completely redundant. The standard specifies that the
compiler will do the trim anyway. I keep seeing people use this
redundant trim, occasionally with mentions of recalling some old
compiler that failed to do it. I have never seen a mention of any
current (or within 2 decades of current) compiler that gets this wrong.
Other than that, allow me to mention the general rule for file names,
which is that what follows the file= is allowed to be any character
expression. The two most common cases are simple character literals (as
in the OP's code) or simple character variables (as in the above with
the trim omitted). The simple variable case is most likely appropriate
for the OP. I just wanted to mention the general case so that he doesn't
think that the 2 simple cases are the only ones allowed.
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
| |
| Steve_Vai 2005-02-22, 8:59 pm |
| Richard E Maine wrote:
> In article <1109097139.412126.190640@c13g2000cwb.googlegroups.com>,
> "ajs" <ajs00g@gmail.com> wrote:
>
>
> The trim here is completely redundant. The standard specifies that the
> compiler will do the trim anyway. I keep seeing people use this
> redundant trim, occasionally with mentions of recalling some old
> compiler that failed to do it. I have never seen a mention of any
> current (or within 2 decades of current) compiler that gets this wrong.
>
> Other than that, allow me to mention the general rule for file names,
> which is that what follows the file= is allowed to be any character
> expression. The two most common cases are simple character literals (as
> in the OP's code) or simple character variables (as in the above with
> the trim omitted). The simple variable case is most likely appropriate
> for the OP. I just wanted to mention the general case so that he doesn't
> think that the 2 simple cases are the only ones allowed.
I thank you all, I'm trying to make my program able to write automatically
some *.kumac (macros for a program called PAW) and thanks to you I'm doing
pretty well :-)
Ciao :)
>
|
|
|
|
|