Newbie question, but I can't find some good fortran documentation anywhere.
I am studying a program and the writer uses a read statement to evaluate if the user wants to rerun the script.
The code is:
PRINT *,'Calculate again? .TRUE./T/t -> yes , .FALSE./F/f -> no'
READ *,answer
Then it uses the logical variable answer to select where does the program have to goto next.
What does the code above do?
Probably it is supposed to be READ *, answer to read answer from the standard input unit.
The code outputs "Calculate again? .TRUE./T/t -> yes , .FALSE./F/f -> no" then reads into answer, which I suppose is declared as a logical variable.
See http://en.wikipedia.org/wiki/Fortran_95_language_features for documentation of Fortran 95.
M.S.B is right, I just add what did not fit into a comment.
There are tons of good Fortran resources on the internet. You can use official standard, but better are usually documantation for compilers. This one http://publib.boulder.ibm.com/infocenter/comphelp/v111v131/index.jsp?topic=%2Fcom.ibm.xlf131.aix.doc%2Flanguage_ref%2Fassociatestmt.html is very good.
Also there are numerous courses and tutorials. Just google "Fortran beginner course", "Fortran tutorial" or similar.
Related
I think this is really hard to explain what I want. But, let me try.
(I am trying to build a program for scoring student's programming homework)
There are a lot of simple source codes in C++. (Please think there are more than 100 code files)
// C:\homework1\studentA.cpp
int main()
{
cout << "The answer is 456" << endl;
}
And This is question. As you can see, there are tons of code files and I cannot compile it and check it whether right or wrong one by one. So, I need to make scoring program for convenience.
How can I read the standard output (The answer is 456) in another program? Is there any function for 'compiling source code' and 'save standard output' ?
I would use a bash script for this instead of C++. Something along the lines of:
g++ $filename
./a.out > student_answer.txt
diff -q student_answer.txt expected_answer.txt
Then, $? would tell you whether the answer was correct.
How can I read the standard output (The answer is 456) in another program?
You cannot do that without help from your operating system. Because you don't have (in general, according to the C++17 standard) some "other program" running (read about processes). When you have one, please thank your OS. Read some textbook about operating systems.
However, on Linux, you could just use popen(3) (or fork(2), execve(2), pipe(7) so pipe(2), dup2(2), waitpid(2)) and on operating systems for which Qt has been ported (that includes Windows, but read about the WinAPI), you could use QProcess.
If you are paranoid, consider using setuid and/or chroot techniques (perhaps with LXC) on Linux to increase the security of your tool.
Look also inside the POCO framework library.
Thank you for reading my question, I searched everywhere on the net and I couldn't find an answer.
I have a test (Olympiad in informatic) next week, The programming language that I'll be using is c++, My code gets compiled by a server which then responds whether my answer was true or false (Wrong compilation is considered as false of course), The problem is that I don't have access to the compilation phase so I can not set c++ to be compiled as c++11 (Can't set compilation flags).
My question is: Is there is any way I can add flags inside my cpp file (which will be uploaded to the server) to enable the c++11? Can it be done with predecessor with #somthing ?
Note: I have no access except to the cpp file, NO makefile, nor anything else.
Thank you For your help, i really appreciate it.
No, there isn't.
You will have to use the C++ standard dictated by the test.
There isn't a way to set the compilation flags from the code but:
From Wikipedia
On each of the two competition days, the students are typically given three problems which they have to solve in five hours. Each student works on his/her own, with only a computer and no other help allowed, specifically no communication with other contestants, books etc. Usually to solve a task the contestant has to write a computer program (in C, C++ or Pascal, and occasionally FORTRAN and PHP, C++11 is supported starting from IOI 2014, while Java is planned to be added in IOI 2015[2])
Emphasis mine
I am using fortran and I have the following error message:
undefined reference to `newuoa_h_'
does anyone know how to run NEWUOA_H(n,npt,x,rhobeg,rhoend,iprint,maxfun,w,mv) in fortran?
thanks
Your missing function seems to be here in the otkpp optimization library.
You may have to install it, or at list to extract the functions you need (there is a C++ wrapper, but the algorithms are written in Fortran).
By the way, if you use also LMBM, there is a note on Napsu Karmitsa's site (the author) which is not on Google groups: The software is free for academic teaching and research purposes but I ask you to refer at least one of the references given below if you use it". I don't know who wrote newuoa, but otkpp itself is under GPLv3, and it's author, Seppo Pulkkinen, is a student under Karmitsa's supervision (see here).
edit
After more search, it appears newuoa has been written by M. J. D. Powell (a numerical analyst well known in the optimization field), now retired. The source code is also here, in Fortran together with an f2c translation. The fortran code is "totally free" according to this site.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Have you used any of the C++ interpreters (not compilers)?
Hi,
I am currently learning C++ and a beginner in programming in general. I've been trying to write some code to a few programming problems from the book I'm using. What I find is that often I make mistakes in what I write and those mistakes come up when the program is run. Its usually quite obvious where in the program I've gone wrong when there is regular output. But in a long computation I'm often not sure why a particular code has acted a certain way. I've also looked at Python recently. Python works with an interpreter, which can take any piece of Python code and compute its output.
I was wondering if there was something similar for C++. Right now when I want to check a line or block of code I have to comment out a lot, save it, compile it, and then run it from a command line. And I have to do that many times for a single error until I've solved it. Is there a way to type code into an active terminal which would run code and show me output? What would be better still would be a way to select a block of code (like you select text) or multiple blocks (to see how a function is being handled) within the IDE and click run to run just that block of code and see its output without having comment out irrelevant lines or to save the file. The compiled code could just reside in memory.
CINT is a c & C++ interpretter that accepts nearly all valid C++. Unfortunately many Linux distros do not offer it, and you'll probably have to build it from source... and that is a non-trivial task.
Typically a debugger is used to step through code line by line, starting at a chosen breakpoint, and keep watch of all variables/values.
Unit testing is a technique to test smaller pieces of code.
A stepping debugger, as found in most IDEs will help you with this.
Here (for example) is a description of how to set the Execution point in In Visual Studio, which sounds like what you want to do.
For certain situations, the "Immediate Window" may be of use to you. It allows you to type in expressions to evaluate immediately.
Rather than just running individual lines independently, or relying on print statements to tell you the state of whatever variables you have decided to print, you can use the debugger to run to the point of interest (where you will have set a breakpoint), then you can examine the state of any in-scope variables, or even alter the normal flow of the program.
There are some solutions that try to do this - the ones I know are Ch and TextTransformer.
However, I doubt that this works very well. C++ is not at all designed to run as an interpreted language.
One of the problems is that C++ is very, very hard to parse. And this makes it very hard to provide certain types of tools that are usual for other languages. For example, I don't think there is any C++ refactoring tool that really works well.
C++ is a compiled language not like python. But there are few c/c++ interpreters out there but not sure about their features. Check these out: Ch interpreter and CINT
If you really want to learn c++ please do not use the c/c++ interpreters.
If you insist on using a interactive interpreter there is since a long time CINT which is the default interpreter used in the ROOT project. It got better over the years, but still has only limited capabilities when dealing with templates. Also, there is a move to replace it with a JIT compiling interpreter based on clang inside the ROOT project.
If I were you I would learn how to run compiler and an interactive debugger like suggested in some comments already.
I'm just being introduced to C++, and want to know a basic question....
What happens when using C++? Is there anywhere I can see a working example? Textbooks break it down, segment by segment. I would really like to SEE what happens.
ANY suggestion would be appreciated. Hope MY question is not too vague.
Thanks!
You get into the office around 8:30am, get some tea, and you sit down and run a program called an IDE. It lets you type code with the keyboard, such as:
(*m_pHopeThisIsntNull)->doIt();
You can then hit F5 and the code runs and you find out it doesn't work the way you expected. Pretty soon it's 5:30pm.
If you are trying to learn C++, you cannot just read from the textbook -- programming is learned best through hands-on practice. You should get a C++ compiler and run through the textbook examples yourself.
When I use C++, other programmers bow down to me because of my awesomeness. But that's just my experience.
Sounds like a short session with your TA (at an American university, this is the graduate student who helps with the hands-on stuff, does the grading, etc., as a help to the professor) is in order. Get him/her to show you how to use whatever IDE (integrated development environment) your class is requiring/suggesting. Or wait for your lab session, where you will learn this.
You can use a debugger to execute your program step by step, looking at the variables. If that's not enough, debuggers can also show you the a disassembled version of the machine code along with the processor's registers.
Would that help?
You are using C++! your browser is written in C++!
If you want to see it step by step:
Set a breakpoint at the first line and start in debug (F5 in Visual Studio). You can step through the program step-by-step and see what's going on with varying granularity (Step Over or Step Into - usually F10 and F11 in Visual Studio). Stepping into will follow a function call whereas F10 will call it, and step forward over it after it returns.
If you want to see what's going on at a lower level you can use disassemble on your code.
I've used Visual Studio/Windows stuff here b/c that's what I'm most used to but these things are in every major C++ IDE I've seen.