Fortran Fortran 77 - Troubleshoot Char Function Error

  • Thread starter Thread starter Milentije
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
The discussion centers on troubleshooting a Fortran program that encounters a "No such file or directory" error when attempting to open a file named fd01.picks. The code uses the char function to convert integer values into characters, concatenating them to form the filename. Despite confirming that fd01.picks exists in the directory, the program fails to locate it, suggesting a potential issue with the directory path or file naming conventions. Participants emphasize checking the current working directory of the executable and ensuring that the file is indeed present there. Additionally, concerns are raised about spaces in file names, which may complicate file access. The initialization parameters in the code are noted to be valid, but the underlying issue appears to be related to the program's inability to find the specified files, possibly due to directory misconfigurations or compiler settings.
Milentije
Messages
47
Reaction score
0
I am using one progran,have problem with char function.
rfile(3:4)=char(id1+48)//char(id2+48)
write(6,*)rfile
open(28, file=rfile, form='unformatted', status='old')
I have entered write line.This is what I get:
fd01.picks
open: No such file or directory
apparent state: unit 28 named fd01.picks
last format: list io
lately writing sequential formatted external IO
What is actually char doing?
 
Technology news on Phys.org
I haven't done any Fortran for a few years, but here's what seems to be happening.

char(id1+48) converts the integer value id1 + 48 to a character. char(id2 + 48) converts the integer value id2+48 to a character.

This line of code --
rfile(3:4)=char(id1+48)//char(id2+48)
-- concatenates the two characters and stores them in the rfile string at indexes 3 and 4.

It's hard to tell exactly what's happening here without knowing the values of id1 and id2, but it seems that char(id1+48) is '0' and char(id2+48) is '1'.

Your code seems to be looking for a file named fd01.picks. Are you sure that this file exists in the directory the program is looking in? It appears that the open line is not able to find this file - that's what the error message is saying.
 
You are right fd01.picks is the file.Well I still have problems with new line:
open(28, file=rfile, form='unformatted', status='old')
I get this:
open: No such file or directory
apparent state: unit 28 named fd01.picks
last format: list io
lately writing sequential formatted external IO
Aborted
 
You didn't answer the question I asked in the last line of my previous post. Is the program able to find the file it's trying to open - fd01.picks?

Look in the directory that you're executable program file is in. I believe that's the directory in which your program is looking. If this directory doesn't contain fd01.picks, that's why you're getting the error you see.
 
Thanks for helping me!
data xsource/nsources*-9999999./,
+ isource/nsources*-1/,tfile,rfile,r2file,ofile,t2file
+ /'fd .times','fd .picks','rec. ','fd .calc',
This is part of the code for initialization parameters.
fd01.picks should be output file,travel times are there that is what I want to get from the program.
 
Now I have put fd01.picks from examples into my directory.I still have problems:
FD: finite difference traveltime calculation
fd01.picks
fd01.times
fd18.picks
open: No such file or directory
apparent state: unit 28 named fd18.picks
last format: list io
lately writing sequential formatted external IO
 
Milentije said:
Thanks for helping me!
data xsource/nsources*-9999999./,
+ isource/nsources*-1/,tfile,rfile,r2file,ofile,t2file
+ /'fd .times','fd .picks','rec. ','fd .calc',
This is part of the code for initialization parameters.
fd01.picks should be output file,travel times are there that is what I want to get from the program.

This code doesn't look like Fortran or any language I know about, so I don't know what it's doing. Even so, the problem might be the spaces in the names of these files:

'fd .times'
'fd .picks'
'fd .calc'

Before you run your Fortran program, but after you run the code above, look in the directory where your program is, and check that there is a file fd01.picks there. Your program is reporting that it can't find this file.
 
Mark44 said:
This code doesn't look like Fortran or any language I know about, so I don't know what it's doing.

The DATA statement is valid Fortran, assuming the "+" at the beginning of the following lines is actually in the correct location to indicate a statement-continuation line. (The forum software tends to "eat" extra blank spaces.) It simply initializes variables to the indicated values.

Even so, the problem might be the spaces in the names of these files:

'fd .times'
'fd .picks'
'fd .calc'

It appears that the character-manipulation code in the first two posts is intended to replace those blank spaces with digits.

It looks like the program is constructing the file name correctly, because the error message displays the correct file name. The problem is that the file isn't in the directory (or folder) in which the program is looking for it.

As you say, usually a program looks first in the directory in which the program itself is located. If the file really is in that directory, then Milentije needs to find out where the program actually expects the file to be. It may depend on a compiler setting, or an operating-system thing like a Unix shell's PATH variable.
 

Similar threads

Replies
2
Views
2K
Replies
8
Views
4K
Replies
6
Views
3K
Replies
2
Views
3K
Replies
2
Views
2K
Replies
3
Views
4K
Replies
5
Views
6K
Replies
22
Views
5K
Replies
5
Views
3K
Back
Top