Problem using OPEN command with an integer file name 
Author Message
 Problem using OPEN command with an integer file name

I would be grateful if you could help me out of this situation:

I am using ms dev studio 4.0.  In a part of a program, I need to create
a new file with a file name of CYCNO, where CYCNO is an integer used in
a loop. It looks like this:

INTEGER CYCNO
DO 15 CYCNO=1,1000,1
    OPEN (6,FILE=CYCNO)
    WRITE (6,16) CYCNO, additional information(other arrays)
    CLOSE (6)
15 CONTINUE

I need to create different files named the same as the cycle numbers, as
you can see. However, I run into the problem that after the FILE
command, I need to supply a name which is a character, not a integer
variable.

How can I find a way to do this?

Thanks in advance,

Bulent AGAR

--
Bulent AGAR
http://www.*-*-*.com/ ~agarbul



Mon, 22 May 2000 03:00:00 GMT  
 Problem using OPEN command with an integer file name

Maybe i didn't make myself clear:

when cycno=1, then the name of the  file to be created is 1, then that file
is closed.
when cycno=2, the name of the file to be created is 2, and again the file is
closed.
.
.
.
.
when cycno=1000, the file name is 1000.

Better yet, I would prefer the file names to be cycle1, cycle2, cycle3....
cycle1000,
instead of just 1,2,3,  because I am going to post-process all these files
and need to see
which data points correspond to which cycle numbers.

Any suggestions?

Quote:

> I would be grateful if you could help me out of this situation:

> I am using ms dev studio 4.0.  In a part of a program, I need to create
> a new file with a file name of CYCNO, where CYCNO is an integer used in
> a loop. It looks like this:

> INTEGER CYCNO
> DO 15 CYCNO=1,1000,1
>     OPEN (6,FILE=CYCNO)
>     WRITE (6,16) CYCNO, additional information(other arrays)
>     CLOSE (6)
> 15 CONTINUE

> I need to create different files named the same as the cycle numbers, as
> you can see. However, I run into the problem that after the FILE
> command, I need to supply a name which is a character, not a integer
> variable.

> How can I find a way to do this?

> Thanks in advance,

> Bulent AGAR

> --
> Bulent AGAR
> http://www.iit.edu/~agarbul



Mon, 22 May 2000 03:00:00 GMT  
 Problem using OPEN command with an integer file name

Quote:

> I would be grateful if you could help me out of this situation:

> I am using ms dev studio 4.0.  In a part of a program,
>I need to create a new file with a file name of CYCNO,
> where CYCNO is an integer used in
> a loop. It looks like this:

> INTEGER CYCNO
> DO 15 CYCNO=1,1000,1
>     OPEN (6,FILE=CYCNO)
>     WRITE (6,16) CYCNO, additional information(other arrays)
>     CLOSE (6)
> 15 CONTINUE

<snip>

Quote:
> How can I find a way to do this?

        You could write the value of CYCNO to a seperate
character string and use that as  the file name:

INTEGER CYCNO
CHARACTER FILENM*8
DO 15 CYNO=1,1000,1
        WRITE(FILENM(1:8),'(I8)')
        OPEN (6,FILE=FILENM)
        WRITE (6,16) CYCNO, ETC...
        CLOSE (6)
15   CONTINUE

        If you need consistency in filename length you can use
a format of '(I8.8)' to force 8 digits (ie, 354 => 00000354).
        Hope that helps!

--
Chad A. English
Hydrologist
USGS, Menlo Park



Tue, 23 May 2000 03:00:00 GMT  
 Problem using OPEN command with an integer file name

Quote:

>Maybe i didn't make myself clear:

>when cycno=1, then the name of the  file to be created is 1, then that file
>is closed.
>when cycno=2, the name of the file to be created is 2, and again the file is
>closed.
>.
>.
>.
>.
>when cycno=1000, the file name is 1000.

>Better yet, I would prefer the file names to be cycle1, cycle2, cycle3....
>cycle1000,
>instead of just 1,2,3,  because I am going to post-process all these files
>and need to see
>which data points correspond to which cycle numbers.

>Any suggestions?


>> I would be grateful if you could help me out of this situation:

>> I am using ms dev studio 4.0.  In a part of a program, I need to create
>> a new file with a file name of CYCNO, where CYCNO is an integer used in
>> a loop. It looks like this:

>> INTEGER CYCNO
>> DO 15 CYCNO=1,1000,1
>>     OPEN (6,FILE=CYCNO)
>>     WRITE (6,16) CYCNO, additional information(other arrays)
>>     CLOSE (6)
>> 15 CONTINUE

>> I need to create different files named the same as the cycle numbers, as
>> you can see. However, I run into the problem that after the FILE
>> command, I need to supply a name which is a character, not a integer
>> variable.

>> How can I find a way to do this?

>> Thanks in advance,

>> Bulent AGAR

>> --
>> Bulent AGAR
>> http://www.iit.edu/~agarbul

character *8 filename

          write(filename,2000) 'CYCL',cycno
2000  format(a4,i4.4)

this will generate character strings such as   CYCL0001,
CYCL0001....CYCL9999
now just open (13,file=filename.....) and procede...  



Tue, 23 May 2000 03:00:00 GMT  
 Problem using OPEN command with an integer file name

Try this instead.

INTEGER CYCNO
CHARACTER CY*4
DO 15 CYCNO=1,1000
   WRITE (CY,1)CYCNO
1  FORMAT(i4)
   OPEN(6,File=CY)
   WRITE(6,16)...
   CLOSE(6)
15 CONTINUE



Sat, 27 May 2000 03:00:00 GMT  
 Problem using OPEN command with an integer file name

that's a nice little hack...i recently had the same problem (needing to get
filenames from a do loop index)...i won't even tell you what my lame
solution was...i'll give you a hint though: it included using the
ICHAR and CHAR functions and knowing about ascii's decimal representation.  
that's why this is my favorite ng to read--it's one of the few that still has
useful stuff in it.
-ckm



Sat, 27 May 2000 03:00:00 GMT  
 Problem using OPEN command with an integer file name

I am glad to hear somebody put this question forward as I had tried to deal with
it for a long time.
Using write is an excellent idea.  But Chris, once a time, I had used your
method, ichar and char to
deal with it.  Although it works but I have to make a lot of 'if' because if the
file name is just from
1 to 10, it drives you mad in writing 'if' and 'do' to deal with just 10 files
only.

Regards

Quote:

> that's a nice little hack...i recently had the same problem (needing to get
> filenames from a do loop index)...i won't even tell you what my lame
> solution was...i'll give you a hint though: it included using the
> ICHAR and CHAR functions and knowing about ascii's decimal representation.
> that's why this is my favorite ng to read--it's one of the few that still has
> useful stuff in it.
> -ckm



Mon, 29 May 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. error 37 File not open using a variable file name

2. open pipe problem under windows, file name argument is hosed

3. Problem opening files while using os.path.walk

4. File names and the file command

5. Problems using the file command & var substitution

6. DOS File Lookup - just the file name, not the path AND file name

7. integer in file name

8. (VA 4.02b) using long file names for Envy file attachments

9. copying files using as a different file name

10. Using Long File Names (TPS Files) in Clarion

11. invalid command name when using tclblend extension from Tcl scipt

12. help me to execute my file without using wish (menu file, command source)

 

 
Powered by phpBB® Forum Software