Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Programming & Scripting > reassigning unit numbers in g77

Forgot Password?
 Linux Programming & Scripting   C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 12-15-2005   #1 (permalink)
Just Joined!
 
Join Date: Dec 2005
Posts: 2
reassigning unit numbers in g77

Hi everyone! I am dealing with an ancient and huge Fortran project that was being developed on various platforms for decades. I want to compile it with g77. My problem is that I/O units 5 and 6, which are by convention used for standard I/O, are in this code assigned to regular files, opened with OPEN statements. If I compile this with g77, the resulting executable encounters a segmentation fault when it tries to open a file and assign it to unit 6, because it is the console output. Since this unit number is accesed in thousands of places trough the code, I would like to avoid modifying the code, but instead somehow reassign unit numbers to make it possible to use units 5 and 6 for regular files. Is this possible? I know that I can redirect standard I/O using piping on the command line, but I would prefer a cleaner solution. Thanks!
vitke is offline  


Reply With Quote
Old 12-15-2005   #2 (permalink)
Just Joined!
 
Join Date: Apr 2005
Posts: 23
my first suggestion would be to use sed and regular expressions to replace all of the 5 and 6 unit numbers you talked about, simply because it is generally bad practice to use those unit numbers for files. sed would have no problem fixing thousands of cases for you, you just need to make sure you get the regular expression right so you don't change the numbers 5 and 6 to something else when they are in an actual number, like 3.567.

that would be the "cleanest" fix. otherwise, you can rig some fix to associate stdin and stdout with some other unit numbers, but then the next guy that comes along is going to be sitting in the same boat you are.

if you really want to change the number that stdin and stdout are associateed with, i dont know exactly how to do it, but you might try an open statement with the file "SYSIN" and "SYSOUT". these may be the filenames associated with 5 and 6, and you could maybe open them as files to associate them with different numbers.

i haven't actually been able to try that, i dont have a FORTRAN 77 compiler on my machine any more, but that's what i would try first. If it doesn't work, check to make sure "SYSIN" and "SYSOUT" are actually the correct names.
sirclif is offline   Reply With Quote
Old 12-15-2005   #3 (permalink)
Just Joined!
 
Join Date: Dec 2005
Posts: 2
Thanks sirclif for your answer. I was thinking about regular expressions, but as I am not sure that I could list all possible contexts in which a unit number could appear and then write regular expressions that would certainly find everything, I would prefer to asociate stdin and stdout with something else. For example, a WRITE statement can have a unit number as the first argument, or it may appear later with 'UNIT=...', a unit number can also appear in CLOSE, REWIND and other statements, spaces are ignored in Fortran so maybe there is WRI TE in my code, or I may have UNI in columns 70-72, and NIT=6 in columns 7-11 of the next line. Things like these really appear in this code, I have seen them. So if I have to foresee all such things, I may as well write a compiler.

So I tried with SYSIN and SYSOUT. These names appear on the Internet, but it seems that they are not parts of the Fortran 77 standard. I can open(98,'SYSIN'), but I think that the compiler thinks that SYSIN is a regular file, as the next line OPEN(6,'filename') leads to a segmentation fault. Also CLOSE(6) before all this leads to a segmentation fault.
vitke is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 05:12 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2