Fortran 77 - Troubleshoot Char Function Error

  • Context: Fortran 
  • Thread starter Thread starter Milentije
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting an error related to the CHAR function in Fortran 77, specifically in the context of file handling and string manipulation. Participants explore the implications of the CHAR function, the construction of file names, and the conditions under which files are accessed in the program.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Experimental/applied

Main Points Raised

  • One participant describes the CHAR function as converting integer values to characters, specifically noting that CHAR(id1+48) and CHAR(id2+48) are used to create a file name.
  • Another participant suggests that the error arises because the program cannot find the specified file, fd01.picks, in the expected directory.
  • A later reply indicates that the program continues to encounter errors even after placing fd01.picks in the directory, now referencing fd18.picks instead.
  • Some participants express uncertainty about the validity of the code structure, questioning whether the DATA statement is correctly formatted and whether spaces in file names could be causing issues.
  • There is a suggestion that the program may be looking in the wrong directory for the files, potentially due to compiler settings or operating system configurations.

Areas of Agreement / Disagreement

Participants generally agree that the program is unable to locate the specified files, but there is no consensus on the underlying cause of the issue, with multiple competing views on the validity of the code and the file naming conventions.

Contextual Notes

There are unresolved questions regarding the exact values of id1 and id2, the correct formatting of the DATA statement, and the implications of spaces in file names. The discussion does not clarify the specific directory the program is accessing.

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 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 22 ·
Replies
22
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K