I am trying to compile a Fortran program by submitting the input via pipe. Can GNU Fortran compiler read the source input from the pipe
Related
I am trying to use a .txt file for my stdin in a c++ program. Essentially, I am just trying to find where in this IDE (Dev C++) I would be able to specify the file I want to use for program input.
I thought that I would be able to read file input here:
But this doesn't seem to be working. I have tried with a space between the 1 and the file name and with quotes around the file name.
I know my program allows for the file to be read properly because when running it in the command line it outputs the first line of the stdin file, test01.txt.
The command I am using to run the program in cmd line is: ./prog 1 < test01.txt where 1 is a case number for a switch statement and test01.txt is input used by that switch statement.
How would I mimic this command line call in Dev C++ IDE? The test01.txt file is part of my project files...
I am making a program that reads from stdin.
I want to debug the program in qtcreator but I can't find a way of providing input except using the terminal. Which is not very practical because my input is a big file with a lot of lines.
I tried going to the run options of qtcreator and insert the following in the Command Line Arguments: < filename
But Qtcreator gave me an error in the application output:
14:26:54: Debugging complex shell commands in a terminal is currently not supported.
Is there no way of providing a file as stdin in qtcreator?
I am using an old Fortran code and I have running it using g77-3.3 in an old OS. Since this version of the compiler no longer comes with most Linux distributions I tried using gfortran (4.9.2), and I am facing this small problem.
This codes uses temporary files. It writes to this file and then at a certain point it changes the status of the file to scratch, like in the following example:
PROGRAM testopenfile
IMPLICIT NONE
WRITE(8,*)'fdsasfd'
OPEN(8,STATUS='SCRATCH')
CLOSE(8)
END PROGRAM
This piece of code works with the g77 compiler, but when I run it with gfortran I get the message:
At line 4 of file testopenfile.f (unit = 8, file = 'fort.8')
Fortran runtime error: Cannot change STATUS paramter in OPEN statement.
Has this way of setting temporary files changed in gfortran? Am I doing something wrong? Could this be a bug in this version of gfortran?
If you write to unit 8 before opening the file, you are in fact writing to a file called fort.8, see here. Apparently, this file is still open at unit 8 when you try to attach the scratch file to it.
You can solve this by opening the scratch file before writing to the unit:
PROGRAM testopenfile
IMPLICIT NONE
OPEN(8,STATUS='SCRATCH')
WRITE(8,*)'fdsasfd'
CLOSE(8)
END PROGRAM
or by using a different unit.
Chapter C.6.3 ("OPEN statement (9.5.6)") in the Fortran 2008 Standard treats this case and has an example which looks just like your code. It states that this "example is invalid because it attempts to change the value of the STATUS= specifier."
If you want to delete the file on closing, you can also do
PROGRAM testopenfile
IMPLICIT NONE
WRITE(8,*)'fdsasfd'
CLOSE(8,status='DELETE')
END PROGRAM
Is there any way that I can see the run time of my C++ program in Geany? I am trying to add a execute command like this "time(./%e<i.txt)" it is giving error
./geany_run_script.sh: 5: ./geany_run_script.sh: time(./g<i.txt): not found
I have i.txt in the same directory as output file.I just want to know the runtime of my C++ programs while taking input from .txt file without writing the commands every time in the terminal myself any way I can do this?
I'm new to fortran and i'm trying to execute this as an output.
program write2file
implicit none
! open file
open (10, file='output_file.txt', status='unknown')
! write to file
write(10, *) 'Hello World!'
! close file
close(10)
end program write2file
I'm running it on Linux and I have tried to use this statement to compile and execute the output, but unfortunately, I wasn't able to get the 'output_file.txt'
Does anyone know what's wrong?
This is a comment rather than an answer but I feel in need of better formatting. After you execute the command
ifort -o output hi.f90
you should have an executable called output in your current working directory. To execute that executable execute the command
./output
which will, if you are successful, write the output you want to wherever the current version of the program directs it.
Reading your comments makes me suspect that you think the command
ifort -o output hi.f90
ought to execute your program and cause the creation of the output requested. But that command just compiles your sources (in the file hi.f90) into the executable called ouptut. Is this the first time you've used a compiler ?