You are not logged in.

#1 2017-02-09 22:14:49

militarymaid
Member
From: Mexico City
Registered: 2017-02-09
Posts: 26

Compiling issues with cross platform fortran code.

Hello world!
So I found this nicely made code of a Grand Canonical Monte Carlo simulator for gases. The main problem comes when I try to compile it (gcc-gfortran) according to the instructions of the developer:
http://paros.princeton.edu/jerring/gcmc … source.htm
I have to run first pc2unic_all (makefile does not work by default I checked) in order to get the program to be properly compiled in linux.

[media@Mugenkan source]$ tcsh
> ./pc2unix_all
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command
sed: -e expression #1, char 2: unterminated `s' command

When the routine is done every file in my sourcecode directory is blank.
Here is the routine pc2unix_all

#!/bin/csh  
./pc2unix add
./pc2unix alpha_ch
./pc2unix amoeba
./pc2unix amotry
./pc2unix banner
./pc2unix bondl
./pc2unix bigread
./pc2unix com
./pc2unix cone
./pc2unix cranksh
./pc2unix create
./pc2unix displace
./pc2unix e6interact
./pc2unix e6molecule
./pc2unix erf
./pc2unix erfc
./pc2unix fourier_move
./pc2unix fourier_setup
./pc2unix grow
./pc2unix intrabend
./pc2unix intratorsion
./pc2unix ionmolecule
./pc2unix littleread
./pc2unix lrcorr
./pc2unix gcmc
./pc2unix methods
./pc2unix newmaxima
./pc2unix outfold
./pc2unix predict
./pc2unix ran2
./pc2unix realinteract
./pc2unix realmolecule
./pc2unix regrow
./pc2unix remove
./pc2unix resmethods
./pc2unix resread
./pc2unix ressetup
./pc2unix resupdate
./pc2unix selfmolecule
./pc2unix sphere
./pc2unix store
./pc2unix surf_move
./pc2unix weights
./pc2unix writedata
./pc2unix writehist
./pc2unix writeresults
./pc2unix zbrent

Here is the routine pc2unix

#!/bin/csh  

sed -f ms_c $1.f90 | sed s/\
// | sed -f al_unc | sed -f al_c > $1.tmp
rm $1.f90
mv $1.tmp $1.f90
    

Offline

#2 2017-02-09 22:31:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Compiling issues with cross platform fortran code.

That's damn near obfuscated code.  I suspect the primary problem is that mid-pipeline sed expression: it needs to be quoted.  But it's hard to tell if that is all that is wrong.  Pipelining 4 sed commands, one inline, and 3 from "scripts" is absolutely ridiculous.  I hope the authors understanding of fortran is better than their understanding of sed.

This *might* work:

sed -f ms_c $1.f90 | sed 's/\n//' | sed -f al_unc | sed -f al_c > $1.tmp
rm $1.f90
mv $1.tmp $1.f90

This will do what the author intended - but I'm not sure they know what they are doing.

Also there is absolutely nothing in that that should need csh, so explicitly requiring that is silly.

I wouldn't be surprised if that whole pc2unix thing was just to fix line endings.  There are many *much much* better ways of doing that.
EDIT: nope, it's to comment out lines that don't apply.  But there are still much much better ways of doing this.

The following should have the same effect as all that nonsense:

sed -i '/# MS/d;/# C_ALPHA/d;/# U_ALPHA/s/^!//;s/\r//' *.f90

This does what the author intended without several subshells, csh, or broken sed scripts in several files.  What it does: removes all lines with a comment including any of "# MS" "# C_ALPHA" or "# U_ALPHA" and removes carriage returns leaving only newline characters.  I doubt this last part is useful though.

EDIT 2: that makefile is pretty hideous too.  I proper makefile for this would be about 7 or 8 lines (I should have one very soon).

EDIT 3: oops, yes, the U_ALPHA lines get *uncommented*.  I just fixed my sed command for that.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2017-02-09 22:48:16

militarymaid
Member
From: Mexico City
Registered: 2017-02-09
Posts: 26

Re: Compiling issues with cross platform fortran code.

Probably their understanding of UNIX as a whole. As of right now the routine pc2unix ran without deleting all my files, it also uncommented some lines while commenting others as intended.
Thanks for the quick answer, probably more problems will arise later on but as of right now there is nothing much to worry about.

Offline

#4 2017-02-09 22:59:12

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Compiling issues with cross platform fortran code.

Here's a makefile that does the same thing as their ridiculously long makefile:

FC       =  gfortran
PROG     =  gcmc
FFLAGS   = -O5 -fdefault-real-8
MODULES  =  $(basename $(wildcard *.f90))

${PROG}: ${MODULES:%=%.o}

%.o: %.f90
	$(FC) -c $(FFLAGS) $< -o $@

I made a couple changes to FFLAGS as they seem to be using a fortran compiler with different flag syntax.  I don't know what the -u flag is ... so that was left out.  I assume the -r8 was for 8byte real so I used the gfortran option for that.  There are errors compiling several of the modules though - so more needs to be done.

Also see above for an edit to the sed line.  I missed that the U_ALPHA lines were to be uncommented.  The sed line works now.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2017-02-09 23:07:59

militarymaid
Member
From: Mexico City
Registered: 2017-02-09
Posts: 26

Re: Compiling issues with cross platform fortran code.

Thank you very much for all this help!

The errors from some of the modules already came out for me, I am even seriously thinking of redoing the project from scratch and copy/paste some of the modules. Also yes I checked the line of the pc2unix fix, thanks for that.

Offline

#6 2017-02-09 23:13:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Compiling issues with cross platform fortran code.

Note that the single sed line isn't a replacement for pc2unix.  It is a replacement for pc2unix *and* that ridiculous pc2unix_all script.  So now: 1) download and extract the source tarball. 2) cd to the directory with the files and run that sed command.  3) there is no three. wink


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2017-02-10 00:49:13

militarymaid
Member
From: Mexico City
Registered: 2017-02-09
Posts: 26

Re: Compiling issues with cross platform fortran code.

Thanks for the note, was wondering if I was right to put that  in terminal and not in the weird pc2unix file... so well now off to start the real work in the code hahaha! (step 3?)

Offline

Board footer

Powered by FluxBB