Fortran 77 - Troubleshoot Char Function Error

  • Fortran
  • Thread starter Milentije
  • Start date
  • Tags
    Fortran
In summary: So the solution may be to move the file to the right place, or it may be to change a compiler setting or environment variable.One other thing to check: is the file really named "fd01.picks", or is it possible that it has a longer name, like "fd01.picks.txt"?In summary, It appears that the program is trying to open a file named "fd01.picks" but is unable to find it in the directory it's searching. The code is attempting to replace spaces in the file name with digits, but the problem may be related to compiler settings or the actual location of the file. It's also possible that the file has a longer name with an additional extension that is not being accounted for
  • #1
Milentije
48
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
  • #2
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.
 
  • #3
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
 
  • #4
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.
 
  • #5
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.
 
  • #6
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
 
  • #7
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.
 
  • #8
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.
 

Related to Fortran 77 - Troubleshoot Char Function Error

What is Fortran 77?

Fortran 77 is a programming language commonly used in scientific and engineering applications. It was first introduced in 1977 and has been widely used since then for its efficient numerical computation capabilities.

What is the Char function in Fortran 77?

The Char function in Fortran 77 is used to convert an integer value to its corresponding character. It takes in an integer argument and returns the corresponding character from the ASCII character set.

Why am I getting an error with the Char function in Fortran 77?

There could be several reasons for getting an error with the Char function in Fortran 77. Some common reasons include passing in an invalid argument, not declaring the function properly, or using the function in a way that is not allowed. It is important to carefully check the syntax and arguments used with the Char function to troubleshoot the error.

How can I troubleshoot Char function errors in Fortran 77?

To troubleshoot Char function errors in Fortran 77, start by carefully checking the syntax and arguments used with the function. Make sure the function is declared properly and that the argument passed in is valid. You can also try using a debugger to step through the code and identify any potential issues.

Are there any alternatives to the Char function in Fortran 77?

Yes, there are alternative ways to convert an integer to a character in Fortran 77. One way is to use the ICHAR function, which converts a character to its corresponding ASCII code. Another option is to use character constants, where you can assign a specific character to a variable using the CHAR() function.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
6
Views
3K
  • Programming and Computer Science
Replies
22
Views
4K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
Replies
5
Views
6K
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
6
Views
2K
Back
Top