opening existing files with OPEN() 
Author Message
 opening existing files with OPEN()

Hi, I am trying to write my own program where I am trying to read
x,y,z points from an existing.  The current beginning of my code has
been working well so far, until a few hours ago, where it says that it
can't find the existing files I'm telling it to find by name (even
though I am spelling the names correctly and making sure that file is
in the same directory).
Here is my code.  Any suggestions of where I can look?  Thanks:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
implicit none
double precision :: x_coord(100000), y_coord(100000), z_coord(100000),
z_max, z_min
integer :: i, j, openstatus, readstatus

! opening and creating proper files
character(25) :: Filename, newname, readin, writeout, junk

readin = "(F8.2, 1A, F9.2, 1A, F5.2)"
writeout = "(F5.2)"

write (*, '(1X, A)', ADVANCE = "no") "Enter name of bathymetry file:"
read *, Filename
open (12, file = Filename, status = "old", iostat = openstatus)
if (openstatus > 0) then
        write (*, '(1X, A)') "***Cannot open file***"
        stop
        endif

write (*, '(1X, A)', ADVANCE = "no") "Enter name of desired shoreline
file:"
read *, newname
open (13, file = newname, status = "new", action = "write", iostat =
OPENSTATUS)
if (OPENSTATUS > 0) then
        write (*, '(1X, A)') "***Cannot create new file***"
        stop
        endif

! defining variables in relation to bathymetry file and each other

do 01
        do 02 i = 1, 100
        write (*, writeout, iostat = readstatus) 1.0, ",", 2.0, ",", 3.0
        if (readstatus > 0) then
                write (*, '(1X,A)') "***Cannot read existing file***"
                stop
                endif
! if end of file is reached during reading the initial file
        if (readstatus < 0) then
                exit
                endif
        02 enddo
01 enddo



Sat, 27 Feb 2010 03:29:18 GMT  
 opening existing files with OPEN()


Quote:
> do 01
>    do 02 i = 1, 100
>    write (*, writeout, iostat = readstatus) 1.0, ",", 2.0, ",", 3.0

        ^^^^^
This and

Quote:
>    if (readstatus > 0) then
>            write (*, '(1X,A)') "***Cannot read existing file***"

                                               ^^^^
this do not match.

--
Steve
http://troutmask.apl.washington.edu/~kargl/



Sat, 27 Feb 2010 03:43:56 GMT  
 opening existing files with OPEN()

Quote:

> Hi, I am trying to write my own program where I am trying to read
> x,y,z points from an existing.  The current beginning of my code has
> been working well so far, until a few hours ago, where it says that it
> can't find the existing files I'm telling it to find by name (even
> though I am spelling the names correctly and making sure that file is
> in the same directory).
> Here is my code.  Any suggestions of where I can look?  Thanks:

Which file can't it find?  Are you sure you've got the upper and
lower case stuff correct.  How about leading blanks?

Write out the name of the file you are trying to open.  Make sure
it is what you expected and didn't get magically "improved" during the
input process.

Print the value of openstatus (or readstatus).  Try looking in the
compiler manual and see what that error means.

Try doing an INQUIRE on the file, before the OPEN, and see if any of
the approximately 137 inquire parameters tell you anything
interesting.

Double check and make sure you are really in the directory you think you
are in.  (It's kind of like telling you to make sure the computer is
plugged in, but you'd be surprised how often it isn't ;) )  Do you
need a ./ (or whatever) in the file name to get into the right directory?

Dick Hendrickson

Quote:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> implicit none
> double precision :: x_coord(100000), y_coord(100000), z_coord(100000),
> z_max, z_min
> integer :: i, j, openstatus, readstatus

> ! opening and creating proper files
> character(25) :: Filename, newname, readin, writeout, junk

> readin = "(F8.2, 1A, F9.2, 1A, F5.2)"
> writeout = "(F5.2)"

> write (*, '(1X, A)', ADVANCE = "no") "Enter name of bathymetry file:"
> read *, Filename
> open (12, file = Filename, status = "old", iostat = openstatus)
> if (openstatus > 0) then
>    write (*, '(1X, A)') "***Cannot open file***"
>    stop
>    endif

> write (*, '(1X, A)', ADVANCE = "no") "Enter name of desired shoreline
> file:"
> read *, newname
> open (13, file = newname, status = "new", action = "write", iostat =
> OPENSTATUS)
> if (OPENSTATUS > 0) then
>    write (*, '(1X, A)') "***Cannot create new file***"
>    stop
>    endif

> ! defining variables in relation to bathymetry file and each other

> do 01
>    do 02 i = 1, 100
>    write (*, writeout, iostat = readstatus) 1.0, ",", 2.0, ",", 3.0
>    if (readstatus > 0) then
>            write (*, '(1X,A)') "***Cannot read existing file***"
>            stop
>            endif
> ! if end of file is reached during reading the initial file
>    if (readstatus < 0) then
>            exit
>            endif
>    02 enddo
> 01 enddo



Sat, 27 Feb 2010 05:12:55 GMT  
 opening existing files with OPEN()

Quote:

> it says that it
> can't find the existing files I'm telling it to find by name (even
> though I am spelling the names correctly and making sure that file is
> in the same directory).

Dick gave some good suggestions. To his comments I might add that,
because you are using list-directed reads to read the file names, there
are lots of extra things that could cause problems. Embedded blanks,
commas, slashes, and quote marks in the file name come to mind. All of
these can be diagnosed using{*filter*}'s suggestion to print out the file
name to make sure it is what you intended.

Also, it would help to know exactly what message your program gives. The
last part of your program looks to have some problems. They shouldn't
have anything to do with opening the file.... but then perhaps the
confusing messages in that part of the code have confused you. In
particular...

Quote:
> do 01
>       do 02 i = 1, 100
>       write (*, writeout, iostat = readstatus) 1.0, ",", 2.0, ",", 3.0
>       if (readstatus > 0) then
>               write (*, '(1X,A)') "***Cannot read existing file***"
>               stop
>               endif
> ! if end of file is reached during reading the initial file
>       if (readstatus < 0) then
>               exit
>               endif
>       02 enddo
> 01 enddo

None of this seems to have anything to do with any of the files in
question; you aren't accessing them. But you have an error message that
incorrectly says "Cannot read existing file." Is that the message you
are getting? If so, note that it doesn't actually result from anything
having to do with reading or with an existing file.

Also note that the "do 01" is an infinite loop. That error message is
basically the only way ever out of that loop. It won't hit an
end-of-file because there are no reads in the loop. In spite of the
variable name readstatus, it is getting the status of a write - not a
read. This loop will probably run until it fills up your disk, hits a
compiler limit, or some such simillar thing, after which it will either
crash or give you that error message.

Speaking of filling up the disk, if you have managed to do that (perhaps
with code like this), then you can get all kinds of strange symptoms,
sometimes not accurately reported.

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain



Sat, 27 Feb 2010 05:51:55 GMT  
 opening existing files with OPEN()
Quote:


>> it says that it
>> can't find the existing files I'm telling it to find by name (even
>> though I am spelling the names correctly and making sure that file is
>> in the same directory).

...

Quote:
> Also, it would help to know exactly what message your program gives. The
> last part of your program looks to have some problems. They shouldn't
> have anything to do with opening the file.... but then perhaps the
> confusing messages in that part of the code have confused you. In
> particular...

>> do 01
>>       do 02 i = 1, 100
>>       write (*, writeout, iostat = readstatus) 1.0, ",", 2.0, ",", 3.0
>>       if (readstatus > 0) then
>>               write (*, '(1X,A)') "***Cannot read existing file***"
>>               stop
>>               endif
>> ! if end of file is reached during reading the initial file
>>       if (readstatus < 0) then
>>               exit
>>               endif
>>       02 enddo
>> 01 enddo

> None of this seems to have anything to do with any of the files in
> question; you aren't accessing them. But you have an error message that
> incorrectly says "Cannot read existing file." Is that the message you
> are getting? If so, note that it doesn't actually result from anything
> having to do with reading or with an existing file.

> Also note that the "do 01" is an infinite loop. That error message is
> basically the only way ever out of that loop. It won't hit an
> end-of-file because there are no reads in the loop. In spite of the
> variable name readstatus, it is getting the status of a write - not a
> read. This loop will probably run until it fills up your disk, hits a
> compiler limit, or some such simillar thing, after which it will either
> crash or give you that error message.

> Speaking of filling up the disk, if you have managed to do that (perhaps
> with code like this), then you can get all kinds of strange symptoms,
> sometimes not accurately reported.

This _particular_ write is to "*" so unless he's redirected output it
should go to the console...of course, all it would take is another
incompletely-corrected copy and paste w/ an actual file unit of this
code section and the condition could be...

But it is suspiciously likely the error reported may well be from the
above rather than from where it is supposed to be, for sure...

--



Sat, 27 Feb 2010 05:58:36 GMT  
 opening existing files with OPEN()

Quote:
> Hi, I am trying to write my own program where I am trying to read
> x,y,z points from an existing.  The current beginning of my code has
> been working well so far, until a few hours ago, where it says that it
> can't find the existing files I'm telling it to find by name (even
> though I am spelling the names correctly and making sure that file is
> in the same directory).
> Here is my code.  Any suggestions of where I can look?  Thanks:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> implicit none
> double precision :: x_coord(100000), y_coord(100000), z_coord(100000),
> z_max, z_min
> integer :: i, j, openstatus, readstatus

> ! opening and creating proper files
> character(25) :: Filename, newname, readin, writeout, junk

> readin = "(F8.2, 1A, F9.2, 1A, F5.2)"
> writeout = "(F5.2)"

> write (*, '(1X, A)', ADVANCE = "no") "Enter name of bathymetry file:"
> read *, Filename
> open (12, file = Filename, status = "old", iostat = openstatus)

If you remove the iostat= specifier, the fortran run-time
system is likely to give you more information about why the
open failed.

Bob Corbett



Sat, 27 Feb 2010 07:22:22 GMT  
 opening existing files with OPEN()
Sorry for the delay, but I was unfamiliar on how this thing notified
the creator of any replies.

The file I am asking for it to find is a copy of a small portion of a
very large raw data file (just for me to make sure the program works
before I try running it on the real thing).  The data in the file is
in the following format:
234843.23,4782438.85,239.42
458394.34,2204845.34,247.60
...
(just an example of the numerical values, but the format/style is the
same)
(and yes, there aren't any spaces in any of the lines)
So one of the issues I was trying to solve before my posted problem
was getting the program to read this format correctly.

The thing is, the program was finding this particular file fine until
it just randomly stopped finding it (I was getting error number 29 for
my openstatus value when I was using the in-program debug program
which told me all of the values of my given variables, which I have
interpreted to being the error #, not the # of errors).  I am fairly
confident that I have the correct directory: when I run it in DOS/
Command Prompt, I see both the executable AND the input file when I do
the 'dir' command (using Windows).  And I do type in the input file
correctly when it asks me.

The error I am getting while running the de{*filter*} in my developer
studio is the following:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM32\kernel32.dll', no matching symbolic
information found.
The program 'C:\Documents and Settings\Mary Serdakowski\Desktop
\Shoreline_Extract\Debug\Shoreline_Extract.exe' has exited with code 0
(0x0).

Hope this helps...

Also, this is my first work in coding/programming in over four years
and I'm learning Fortran in the process, so pardon my stupid
questions.

To specific people:
- Steven Kargl, I do not fully understand.  How do they not match?
-{*filter*} Henderson, I've never heard of the INQUIRE command.  What is
the proper layout for that command?



Sun, 28 Feb 2010 22:13:16 GMT  
 opening existing files with OPEN()

Quote:

> If you remove the iostat= specifier, the Fortran run-time
> system is likely to give you more information about why the
> open failed.

> Bob Corbett

I get the following thing:
"user breakpoint called from code at 0x7c901230", which means
absolutely nothing to me.  The developer studio then shows me a screen
with the following:

7C901230     int   3



Sun, 28 Feb 2010 22:25:21 GMT  
 opening existing files with OPEN()
Also, when I did the INQUIRE command (I found the coding format), I
get severe error <29>, file cannot be found (which was my assumption
to begin with).


Sun, 28 Feb 2010 22:28:04 GMT  
 opening existing files with OPEN()
Quote:

> Sorry for the delay, but I was unfamiliar on how this thing notified
> the creator of any replies.

> The file I am asking for it to find is a copy of a small portion of a
> very large raw data file (just for me to make sure the program works
> before I try running it on the real thing).  The data in the file is
> in the following format:
> 234843.23,4782438.85,239.42
> 458394.34,2204845.34,247.60
> ...
> (just an example of the numerical values, but the format/style is the
> same)
> (and yes, there aren't any spaces in any of the lines)
> So one of the issues I was trying to solve before my posted problem
> was getting the program to read this format correctly.

> The thing is, the program was finding this particular file fine until
> it just randomly stopped finding it (I was getting error number 29 for
> my openstatus value when I was using the in-program debug program
> which told me all of the values of my given variables, which I have
> interpreted to being the error #, not the # of errors).  I am fairly
> confident that I have the correct directory: when I run it in DOS/
> Command Prompt, I see both the executable AND the input file when I do
> the 'dir' command (using Windows).  And I do type in the input file
> correctly when it asks me.

How do you know you type it correctly?  Some things to try.
1)  WRITE out the file name after you've typed it in.  Something like
        write (*,'(a3,a,a3)') ">>>",filename,"<<<"

the > and <s are to make sure you see where the filename begins
and ends, it's sometimes hard to see leading blanks.

1.5)  Have you got the case of the file name correct?  Do you have the
proper name extension?  Are you using "name" when you need "name.txt"?
Some directory listing utilities don't always show the extension.

2)  Put the file name in quotes in the OPEN statement, not a variable.
That way you are sure of what you are trying to open.  Once you make
that work, go back to typing in the name.

3)  Most compilers support some sort of way to run a shell command.
Try something like
         call system ("dir")
as a first step in your program.  This should give you the contents
of what the OS thinks is the directory.

4)  Try an INQUIRE with an iostat parameter.  You said in other posts
that you've tried INQUIRE, but I'm not sure what specifiers you
used.  At least try the exist= specifier and print the results.

5)  Have you checked the file permissions?  If you don't have the right
kind of access permission, the OS might not let you "see" the file.

Dick Hendrickson

- Show quoted text -

Quote:
> The error I am getting while running the de{*filter*} in my developer
> studio is the following:
> Loaded 'ntdll.dll', no matching symbolic information found.
> Loaded 'C:\WINDOWS\SYSTEM32\kernel32.dll', no matching symbolic
> information found.
> The program 'C:\Documents and Settings\Mary Serdakowski\Desktop
> \Shoreline_Extract\Debug\Shoreline_Extract.exe' has exited with code 0
> (0x0).

> Hope this helps...

> Also, this is my first work in coding/programming in over four years
> and I'm learning Fortran in the process, so pardon my stupid
> questions.

> To specific people:
> - Steven Kargl, I do not fully understand.  How do they not match?
> -{*filter*} Henderson, I've never heard of the INQUIRE command.  What is
> the proper layout for that command?



Sun, 28 Feb 2010 23:37:29 GMT  
 opening existing files with OPEN()


Quote:

> To specific people:
> - Steven Kargl, I do not fully understand.  How do they not match?

My point was that the code is not doing what the error
stated.

Quote:
>> do 01
>>       do 02 i = 1, 100
>>       write (*, writeout, iostat = readstatus) 1.0, ",", 2.0, ",", 3.0
>        ^^^^^
>This and

>>       if (readstatus > 0) then
>>              write (*, '(1X,A)') "***Cannot read existing file***"
>                                              ^^^^
>this do not match.

You are writing to the file.  The error messages claims you
are trying to read the file.  In what you provided in the
original post, it seems that you opened a file with the
intention of reading it.  However, if you wrote to the file,
which will destroy the original file.

--
Steve
http://troutmask.apl.washington.edu/~kargl/



Mon, 01 Mar 2010 00:30:09 GMT  
 opening existing files with OPEN()


Quote:

> > Sorry for the delay, but I was unfamiliar on how this thing notified
> > the creator of any replies.

> > The file I am asking for it to find is a copy of a small portion of a
> > very large raw data file (just for me to make sure the program works
> > before I try running it on the real thing).  The data in the file is
> > in the following format:
> > 234843.23,4782438.85,239.42
> > 458394.34,2204845.34,247.60
> > ...
> > (just an example of the numerical values, but the format/style is the
> > same)
> > (and yes, there aren't any spaces in any of the lines)
> > So one of the issues I was trying to solve before my posted problem
> > was getting the program to read this format correctly.

> > The thing is, the program was finding this particular file fine until
> > it just randomly stopped finding it (I was getting error number 29 for
> > my openstatus value when I was using the in-program debug program
> > which told me all of the values of my given variables, which I have
> > interpreted to being the error #, not the # of errors).  I am fairly
> > confident that I have the correct directory: when I run it in DOS/
> > Command Prompt, I see both the executable AND the input file when I do
> > the 'dir' command (using Windows).  And I do type in the input file
> > correctly when it asks me.

> How do you know you type it correctly?  Some things to try.
> 1)  WRITE out the file name after you've typed it in.  Something like
>         write (*,'(a3,a,a3)') ">>>",filename,"<<<"

> the > and <s are to make sure you see where the filename begins
> and ends, it's sometimes hard to see leading blanks.

> 1.5)  Have you got the case of the file name correct?  Do you have the
> proper name extension?  Are you using "name" when you need "name.txt"?
> Some directory listing utilities don't always show the extension.

Yes, I do type in both the name and the extension.

Quote:
> 2)  Put the file name in quotes in the OPEN statement, not a variable.
> That way you are sure of what you are trying to open.  Once you make
> that work, go back to typing in the name.

I'll try that one.

Quote:
> 3)  Most compilers support some sort of way to run a shell command.
> Try something like
>          call system ("dir")
> as a first step in your program.  This should give you the contents
> of what the OS thinks is the directory.

I have done this.  It sees the file within the same directory as the
executable.

Quote:

> 5)  Have you checked the file permissions?  If you don't have the right
> kind of access permission, the OS might not let you "see" the file.

 Would this be under the file 'properties' and related to the
attributes such as 'read only'?
When I check this, none of the attributes are selected.


Mon, 01 Mar 2010 00:44:05 GMT  
 opening existing files with OPEN()
Ah, I see what you mean.  Thanks for that: I wouldn't have seen it
otherwise.  Stupid me.


Mon, 01 Mar 2010 00:44:35 GMT  
 opening existing files with OPEN()

Quote:

> The thing is, the program was finding this particular file fine until
> it just randomly stopped finding it (I was getting error number 29 for
> my openstatus value when I was using the in-program debug program
> which told me all of the values of my given variables, which I have
> interpreted to being the error #, not the # of errors).  I am fairly
> confident that I have the correct directory: when I run it in DOS/
> Command Prompt, I see both the executable AND the input file when I do
> the 'dir' command (using Windows).  And I do type in the input file
> correctly when it asks me.

Is it not finding it when you run from the command line, or is it not
finding it when you run from the IDE?  If the latter, double-check that
you didn't do something to change the startup directory settings.

Quote:
> The error I am getting while running the de{*filter*} in my developer
> studio is the following:
> Loaded 'ntdll.dll', no matching symbolic information found.
> Loaded 'C:\WINDOWS\SYSTEM32\kernel32.dll', no matching symbolic
> information found.
> The program 'C:\Documents and Settings\Mary Serdakowski\Desktop
> \Shoreline_Extract\Debug\Shoreline_Extract.exe' has exited with code 0
> (0x0).

That's not an error message.  That's perfectly normal.

Quote:
> -{*filter*} Henderson, I've never heard of the INQUIRE command.  What is
> the proper layout for that command?

Check your documentation.  If you're using something from the
Intel/Compaq family, there should be extensive documentation of the form
of INQUIRE and the parameters that are supported.  The Intel/Compaq
documentation has included a very good language reference since I
started using DVF 5 ca. 1999.


Mon, 01 Mar 2010 03:52:54 GMT  
 opening existing files with OPEN()

Quote:

> Is it not finding it when you run from the command line, or is it not
> finding it when you run from the IDE?  If the latter, double-check that
> you didn't do something to change the startup directory settings.

What is IDE?


Mon, 01 Mar 2010 03:54:34 GMT  
 
 [ 26 post ]  Go to page: [1] [2]

 Relevant Pages 

1. File Dialog - Open button (Existing/new file)

2. Problem opening the existing excel file

3. Open existing file

4. Code to open a .HTML file which already exists

5. mxedit on linux -- Problem opening existing files

6. File Open, or not Open, question

7. OPEN(VIEW) without OPEN(FILE)

8. Opening a file already open

9. opening a file opens it in Notepad

10. opening 'file open' dialog from console

11. multiple use of with-open-file, or with-open-stream

12. opening file vs. opening pipeline on NT.

 

 
Powered by phpBB® Forum Software