I need to generate a sound in fortran when my run ends.
I need something similar to "\a" or Beep(,) that are used in c++.
Try adding the following at the end of your program
print *, char(7)
If you want to be a little creative you can end your program with a music file. In most c:/windows/media folders you can find a number of .wav files.
In this case I copied the tada.wav file over to the location of my executable so it can play the tada.wav file in the command prompt when the program ends.
If you use Intel Fortran then this implementation shall work:
program zsound
use ifport
implicit none
integer i
character(100) :: musicfile
musicfile = "tada.wav"
! Your Program goes here...
! CALL EXECUTE_COMMAND_LINE(musicfile)
i = system(musicfile)
end
Related
I can open a file with
integer fd;
fd = $fopen ("file_to_open.txt", "r");
But if i have multiple files in a directory such as
f1.txt
f2.txt
f3.txt
How can I iterate over these files without explicitly defining their name in my verilog testbench?
In bash, this would be done with:
for f in ./*.txt; do
...
done
Verilog does not have a way of directly interacting with the Operating System a simulation is running on, so it cannot expand file names.
Two alternatives you have in Verilog are:
writing some C code that does this and linking that code through the VPI (difficult)
Creating a bash script that builds your list of files into a text file, then reading that list one line at a time with $fgets or $fscanf. (cumbersome)
This would be much easier if you were using SystemVerilog because it has string data types, and a direct interface to C (DPI)
Lets say an environment redirects stdout, ignores the output, and then uses their own IO object to write to the screen:
const supersecretstdoutname = Ref{IO}()
# ...
function evironment_init()
# ...
supersecretstdoutname[] = stdout
stdout = DevNull
# ...
end
Would I have any way of finding supersecretstdoutname (or if they did something similar with stdin) without digging through source code?
Said another way, can I get a list of open IOs, or at least the ones that have access to the screen/user input?
I have R code as below. Below code resides in a file called 'iot.R'. I am executing it in Linux.
I want to print content of variable 'fileinformation' to a file mentioned by file=fileConn...
I thought that the 3rd line will solve the issue, but it is not giving the required output :(
fileinformation = system(paste("file", filenames[1]))
#print(fileinformation)
cat(print(fileinformation),"\r\n","\r\n", file=fileConn)
When I run the file, i get below result. It prints to my screen, rather than writing to the file :(
> source('iot.R')
CH7Data_20130401T135010.csv: ASCII text, with CRLF line terminators
[1] 0
--------------------update1
I also tried below command, but didnt get the expected rsult
cat(capture.output(fileinformation),"\r\n","\r\n", file=fileConn)
You need to set the intern argument to TRUE in your call to system. For instance:
fileinformation<-system("file cinzia_2.gif",intern=TRUE)
fileinformation
#[1] "cinzia_2.gif: GIF image data, version 89a, 640 x 640"
Of course I tried a file on my pc. Setting intern to TRUE the return value of system becomes the console output of the command. Then, when you call cat, you don't need to enclose fileinformation into print, but a simple cat(fileinformation,"\r\n","\r\n", file=fileConn) will suffice.
Hi Just a comment as I dont have enough rep to comment in the normal way. but cant you use
write.table
to save the output to a file? It may be easier?
I'm writing code in .csh, and I'm trying to change the bunit header for a FITS file from K (kelvin) to km/s. How can I do that?
I know in Python I would use new_fitsfile.header['BUNIT']='km/s', but that won't work in the current .csh code, and it's not an option to switch it to Python code.
If this is needed only once, call interactively fv or ds9, move to the header, edit the header card and save the result.
For generic batch jobs, one needs some online FITS editor like fmodhead fmodhead, fthedit, or my fedithead
sed "s:BUNIT = 'K ':BUNIT = 'km/s ':g" old.fits >new.fits
and be very careful to count the significant spaces.
I'm having the following problem. I want to write a program in Fortran90 which I want to be able to call like this:
./program.x < main.in > main.out
Additionally to "main.out" (whose name I can set when calling the program), secondary outputs have to be written and I wanted them to have a similar name to either "main.in" or "main.out" (they are not actually called "main"); however, when I use:
INQUIRE(UNIT=5,NAME=sInputName)
The content of sInputName becomes "Stdin" instead of the name of the file. Is there some way to obtain the name of files that are linked to stdin/stdout when the program is called??
Unfortunately the point of i/o redirection is that you're program doesn't have to know what the input/output files are. On unix based systems you cannot look at the command line arguments as the < main.in > main.out are actually processed by the shell which uses these files to set up standard input and output before your program is invoked.
You have to remember that sometimes the standard input and output will not even be files, as they could be a terminal or a pipe. e.g.
./generate_input | ./program.x | less
So one solution is to redesign your program so that the output file is an explicit argument.
./program.x --out=main.out
That way your program knows the filename. The cost is that your program is now responsible for openning (and maybe creating) the file.
That said, on linux systems you can actually find yout where your standard file handles are pointing from the special /proc filesystem. There will be symbolic links in place for each file descriptor
/proc/<process_id>/fd/0 -> standard_input
/proc/<process_id>/fd/1 -> standard_output
/proc/<process_id>/fd/2 -> standard_error
Sorry, I don't know fortran, but a psudeo code way of checking the output file could be:
out_name = realLink( "/proc/"+getpid()+"/fd/1" )
if( isNormalFile( out_name ) )
...
Keep in mind what I said earlier, there is no garauntee this will actually be a normal file. It could be a terminal device, a pipe, a network socket, whatever... Also, I do not know what other operating systems this works on other than redhat/centos linux, so it may not be that portable. More a diagnostic tool.
Maybe the intrinsic subroutines get_command and/or get_command_argument can be of help. They were introduced in fortran 2003, and either return the full command line which was used to invoke the program, or the specified argument.