Issues with porting Fortran code

In summary, gsal was able to debug and solve his problem by changing the buffer encoding system of the file being read.
  • #1
WD_star
5
0
I have a Fortran (F77) code which I used to use at my previous institution that I am having trouble with at my new job. I used to compile it with ifort on computers running Fedora (14 if I recall correctly). At my new job they don't have ifort so I have had to revert to the use of g77 (f77) on systems running Red Hat.

It took awhile, and a little help, to figure out that one of my codes would compile but crash once executed because g77 didn't automatically initialize all variables to zero. Luckily switches do exist to make g77 do this and I thought I was home free. This week, I tried running what is essentially the same code, but I get an ''illegal unit number error" when opening a file. I have Googled extensively to both understand the problem and find a solution but have ultimately been unsuccessful. I know illegal unit numbers can come from choosing things out of the range of 0 to 99, but in this case the unit number in question is 87! Furthermore, the other code I had trouble with previously includes the exact same subroutine where that file is opened and it doesn't cause a problem!

Any and all suggestions are useful. Please let me know if I can supply any additional information that might help pinpoint the problem.

Thanks.
 
Technology news on Phys.org
  • #2
It's a simple open statement:

Code:
      open(87,file='data/fort_HALPHA.22')

And yes I have tried adding a status='old' statement but I get the same error which is as follows:

open: illegal unit number
apparent state: unit 87 (unnamed)
last format: list io
lately reading sequential formatted external IO
Abort (core dumped)
 
  • #3
Maybe the problem is not when opening the file...looks like that already worked...maybe the problem is at some reading statement somewhrw else where somehow the unit number is not correct. Is the code long? May want to post it
 
  • #4
The whole code is quite long, here is the portion where the file is read(it coincides with the end of the subroutine):

Code:
      nxbal=0
      read(87,*) nxbal,stnnec,stnchc,vneuc,vchac
      do i=1,nxbal
         read(87,*) xlbal(i),(plbal(i,j),j=1,NNMAX)
      end do
      close(87)
      stnnec=10.0**stnnec
      stnchc=10.0**stnchc
      iwarnc=0
      return
      end

There is also a related issue that I didn't mention in my first post because I found a way to solve it even though it shouldn't be a problem at all. There is an input file that the code cannot find (''file not found'' type of error). The name of the input file is read as a string in another input file. However, if I hardcode the filename in the open command, then there is no problem. The relevant code for that follows:

Code:
      read(iunit1,100) file
c      open(iunit4,file=file,status='old')
      open(iunit4,file='data/grid_DA_FINAL',status='old')
 
  • #5
Bump

Anybody have any suggestions??
 
  • #6
You did not post much about the "open" statement for unit 87...maybe that statement is not working out too good...did you verify that it worked? You can use one of the arguments to the OPEN statement and inspect that upon return from the OPEN statement to see if it worked or not.

As far as that other file name being read from a file vs hardcoded...did you verify what you are reading from the file? You need to read the filename and write it back out and see what you are reading, THEN if that does match the actual filename.

Also, if the file you are trying to read is not in the exact same directory where you are running from, I wonder if you can work with relative path or you need full path, etc.
 
  • #7
gsal, thanks for taking the time to try and help me.

I have actually solved my problem and it wasn't related to Fortran (at least not exactly). I read your last post and started running some tests. In the process, I noticed that at the bottom of the emacs window for the input file where the other input filename was read, it was written 'DOS'. After a quick Google search, I understood that I had somehow inadvertently changed the buffer encoding system of that file from Unix to DOS! (http://edivad.wordpress.com/2007/04/03/emacs-convert-dos-to-unix-and-vice-versa/) I switched it back to Unix and presto, the code works! Clearly Fortran could not read the file with the DOS buffer encoding.

In any case, thanks again gsal!

Case closed!
 

1. What is porting and why is it necessary for Fortran code?

Porting refers to the process of adapting a computer program or code to run on a different platform or operating system. It is necessary for Fortran code because different platforms and operating systems may have different requirements or features that need to be accounted for in order for the code to run properly.

2. What are some common issues that arise when porting Fortran code?

Some common issues that arise when porting Fortran code include compatibility issues with different compilers, differences in syntax and language standards, and issues with accessing resources or libraries that may not be available on the new platform.

3. How can these issues be addressed or resolved when porting Fortran code?

To address compatibility issues with different compilers, it is important to make sure that the code is written according to the chosen compiler's syntax and standards. Using compiler directives or flags can also help to ensure compatibility. To address issues with accessing resources or libraries, it may be necessary to rewrite or modify parts of the code to work with the resources available on the new platform.

4. Are there any tools or resources available to aid in the porting process for Fortran code?

Yes, there are several tools and resources available to aid in the porting process for Fortran code. These include compiler-specific porting guides, compatibility checkers, and automated conversion tools that can help with adapting code to different platforms and compilers.

5. How can I ensure that my ported Fortran code will run efficiently and effectively on the new platform?

To ensure that your ported Fortran code runs efficiently and effectively on the new platform, it is important to thoroughly test the code after porting. This can include running performance tests, checking for errors and bugs, and optimizing the code for the specific platform and compiler being used.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
616
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
14
Views
4K
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
Back
Top