LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-23-2015, 09:01 PM   #16
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331

Sorry Alex. I already had that file/package on my machine so I didn't think to tell you that is available in a package.
For Ubuntu 12.04 (right?): http://packages.ubuntu.com/precise/libfftw3-dev

Edit:
It seems that you don't need the include statement in fortran.f03. Before installing the above package try compiling with it commented out:
Code:
!        include 'fftw3.f03'

Last edited by norobro; 03-23-2015 at 11:07 PM.
 
Old 03-24-2015, 08:36 AM   #17
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
Norm hi. I found fftw3.f03. It is a long file. There is no need to post it. Thank you, - Alex

P.S. I did not realize you responsed yesterday and the reply went over to the next page. The file is here. It is a fortran interface.

Your help is incredible. Thank you very much. - Alex

Last edited by AlexBB; 03-28-2015 at 01:51 PM.
 
Old 03-24-2015, 01:31 PM   #18
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Alex,

I posted an incorrect version of my C++ fft_() function. Confused myself with all of the Fortran experimentation!

Use this instead:
Code:
extern "C" {
	void fft_(int *n, complex array[])
	{
		int array_size = *n;
		std::vector<complex> Input, Output(array_size);
		for (int jj = 0; jj < array_size; ++jj) {
			double xx = blackmanHarrisWindow(jj,array_size);
			Input.emplace_back(xx);
		}
		CFFT::Forward (&Input[0], &Output[0], array_size);
		CFFT::Inverse (&Output[0], &Input[0], array_size);
		for(int i = 0;i < array_size; ++i){
			array[i] = Output[i];
		}
		return;
	}
} // extern "C"
The command to compile the c++ files will need -std=c++11 for vector::emplace_back():
g++ -std=c++11 -c *.cpp
 
Old 03-24-2015, 08:52 PM   #19
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
Norm, you are saying you posted the wrong code! It is all too familiar. I just placed fftw3.f03 file in the wrong directory, tried to move it to the correct one and it disappeared. I am too weak with ubuntu OS commands. All I do is applications. In the meantime I tried to compile fftw.f03 and got a few dozen compile errors. No regrets :-)

I work 4-10s with Fridays off and in a couple of days I will be putting it all together. Please wait for a bunch of questions coming your way very soon.

Thank you, - Alex

Last edited by AlexBB; 03-27-2015 at 12:46 PM.
 
Old 03-27-2015, 03:22 PM   #20
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
Norm hi,

I just tried to put together the software you posted here for me.

Code:
g++ -std=c++11 -c main.cpp
cc1plus: error: unrecognized command line option -std=c++11
with just g++ it almost compiled but emplace_back had to be replaced with push_back.

At that stage it naturally asked for the class CFFT. Remember, Forward and Inverse also have their own dependencies, so those also must be provided if I want to run this code. I however have it all set up in both C++ and Gfortran program which work and give me pretty much identical results.

Still main.cpp is a nice code sample for me by itself. I appreciate it. I haven't used such code before.

At this stage I have to confess I don't understand how could the code you posted demonstrate the interoperability and I am interested primarily in Fortran routine calling "C" functions or subroutines, not the other way around.

My next question is related to fftw3.f03 file. It is a FORTRAN interface, actually two, however it does not contain fft_ function definition and overall it does not seem to have anything to do with the task at hand.

My third question or rather statement of fact is that when I tried to compile fortran.f03 it gave me an expected error:

Code:
undefined reference to `fft_'
I will appreciate if you read my post and help me to put it all together with clarifying explanations.

Thanks you, - Alex

Last edited by AlexBB; 03-27-2015 at 03:23 PM.
 
Old 03-27-2015, 05:59 PM   #21
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Hi Alex,
Quote:
At this stage I have to confess I don't understand how could the code you posted demonstrate the interoperability . . .
The problem is that I don't understand what you mean by interoperability (sometimes I can be kind of thick). I was under the impression that you wanted to call the C++ functions, pass the data back to the caller and then further manipulate the data in Fortran. I see in your "DEALLOCATE" thread that in your Fortran CFFT code you are outputting the CFFT data to files. It is possible to write to files in the C++ function just like you did in the pure C++ code.

You are absolutely correct about not needing the fftw3.f03 file. Perhaps you missed my edit in post #16.

Regarding your third question: I'm not sure what the problem is. You can try using -std=f2003 on the gfortran command line. It could be the version of gfortran on your machine (4.6.4?) although the docs say that version handles Fortran 2003. I run Debian Sid which has pretty much the lastest releases. For example:
Quote:
$ gfortran --version
GNU Fortran (Debian 4.9.2-10) 4.9.2
As I said in another post I'm operating in the dark on the Fortran side.

Norm
 
Old 03-27-2015, 08:18 PM   #22
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
Norm, many thanks. I will have to read it all tomorrow again to digest athough much of it is clear. Interoperability is an official concept. This is just one example. My original idea (which has evolved quite a bit) was to call CFFT class routines Forward and Inverse from my large Fortran program. I thought to do it on the cheap: grasp a few ideas and write the code. It did not work this way. I came to the conclusion that perhaps I had no background to implement it. My next step was to rewrite c++ CFFT routines into Fortran and this worked quite well. Thus now I don't even need to educate myself on the interoperability.

At this stage Norm showed up like an angel and offered his set of code blocks which seemed to have been tested and tried. It is a great asset to have someone with real experience because, although now I do not need interoperability, I may need it again in two months or sooner.

So, I will try to formulate my position more clearly tomorrow because it is the end of the day in my time zone.

Thanks, - Alex
 
Old 03-28-2015, 05:36 PM   #23
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
Code:
$ gfortran --version
GNU Fortran (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
I think now everything sort of compiles with the exception that fortran.f03 cannot find fft_ function which is of course in a different (cpp) file main.cpp.

How can I make fortran.f03 aware of the function in main.cpp?

Thank you, - Alex

Last edited by AlexBB; 03-29-2015 at 01:27 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need solution to Sed problem. Want to match "&" but not "&amp;" tells Linux - General 14 02-05-2012 08:59 AM
[SOLVED] "Insert" & "Delete" key returns "~" in a terminal. sharky Linux - General 15 04-26-2011 08:36 AM
"bad_pool_error" & "Your system is not fully acpi compliant get your Bios updated" errors in WinXP Aquarius_Girl General 10 07-30-2010 11:27 AM
LXer: Benefit of Microsoft and Novell "interoperability" LXer Syndicated Linux News 1 12-28-2006 07:15 PM
does the G95 or Gfortran support the concept of "module" in fortran95 ztdep Programming 1 09-08-2005 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration