# Fortran Question

by ethyl
Tags: fortran
 P: 7 Is there any code that i can use to execute a file through a fortran compiler? For example i want to execute an excel file (kk.xls) just before the termination of the main code. Thank you
 Emeritus Sci Advisor PF Gold P: 10,428 You can't "execute" an Excel file. You might want to be more specific about what you mean. - Warren
 P: 7 I want to write a code line that will call an excel file after running the main code. I just want to call the file! Not input or export any data. So just before the code terminates it will call this file on the screen. just that. although i dont know if it is possible.
 HW Helper P: 7,055 Fortran Question Sounds like you want to run Excel with a file you created from your program. This could be done via a batch file that first runs your program and then runs Excel. If you want to run Excel from within your program via an internal command line interface, your Fortran compiler would have to support this. It would be nice if the Excell program could be launched as an independent task so your program could exit and not occupy space after it's done and the Excell program starts.
 P: 7 Exactly Jeff! But how am i doing that?
 HW Helper P: 7,055 What you want is the equivalent of ShellExecute() that is available in Microsoft C or C++ compilers. The alternative is to create a dos console batch file and then optionally create a shortcut to the batch file in a program folder. To create shortcuts: Click on start, right click on all programs. Create a new folder. Double click on the new folder to open it. Right click on folder window and select new, shortcut. Search for your program (the .exe) file. If the program has an icon in it, it will automatically get picked up. If there are parameters, add them after the name of the program when creating the shortcut. Click on next and change the name if you want. If you didn't get an icon for the shortcut, right click on the shortcut, and click on change icon, and again, fine the .ico file for your program. Windows will start off with the generic set of icons from some .DLL file. You can pick up icons from .DLL files, .EXE files, or .ICO files. Note that this same process can also be used to create shortcuts to .BAT file to run command scripts. For Windows XP or Vista batch files, prefxing a program path and name with start, such as start \myfolder\myprogram1.exe start \myfolder\myprogram2.exe allows multiple programs or multiple instances of a program to be launched with a single shortcut to a batch file.
 P: 7 buy saing program you mean the file that contains the fortran code or the excel file? Because non of them is a .exe file. And then still what is the code to call the file from the fortran compiler? I want to call my excel file from the fortran code not make a script that will call both the fortran compiler to open and the excel file as well.
HW Helper
P: 7,055
Quote by ethyl
 ShellExecute()
You mean the file that contains the fortran code or the excel file?
I don't know about the Fortran compiler. Using the ShellExecute() function in C / C++, you could choose to "open" or "edit" the file, which would autolaunch Excel if the file had an "Excel" associated suffix, such as SAMPLE.XLS. You could also to choose to "open" Excel.EXE with your created SAMPLE.XLS file as a parameter.
 P: 7 1) Is there any code that can make a fortran compiler to export data to an excel file? But not just OPEN(3,FILE='Z2.xls') for example because it is inserting the data in a messed up way and i can not draw a graph. 2)Also another in fortran code lets say we ve got OPEN(2,FILE='kk1.DAT') The part of the code in ' ' is understood by fortran as the name of the file that will open. Can i make 1 to be a variable so if i create a loop the name of the file will take the value of the variable. For example OPEN(2,FILE='kkX.DAT') where X will be the variable.
HW Helper
P: 7,055
 Quote by ethyl 1) Is there any code that can make a fortran compiler to export data to an excel file?
Output a text file SAMPLE.TXT, then open this with Excel.
Use spaces, or commas to seperate the numbers on each line of the text file.
P: n/a
 1) Is there any code that can make a fortran compiler to export data to an excel file? But not just OPEN(3,FILE='Z2.xls') for example because it is inserting the data in a messed up way and i can not draw a graph.
Create/open a file as a text file, not .xls. Then when you write the data cells, insert tabs between each cell when you want to create new columns, or insert crlf if you want to make a new row. Then run the text file but open using using Excel. Specify tab separation between the cells.

 2)Also another in fortran code lets say we ve got OPEN(2,FILE='kk1.DAT') The part of the code in ' ' is understood by fortran as the name of the file that will open. Can i make 1 to be a variable so if i create a loop the name of the file will take the value of the variable. For example OPEN(2,FILE='kkX.DAT') where X will be the variable.
Yes you can do this. You will have to create the file name as a string variable by concatenating various components. First convert the number variable to an ascii character string, then concatenate 'kk' + 'numberVariable + '.DAT' and call it something else. Then OPEN(2,FILE='somethingElse')

BTW I do not know any Fortran compilers that will directly call up an run an .exe program such as with ShellExecute() in C++. If you do this in C you will likely have to call "Excel.exe mySpreadsheet.xls". You may also have to call the Excel .exe and or the spreadsheet name as a full file pathname, e.g. "C:\blah\blah\mySpreadsheet.xls"
P: 7
 Quote by ChrisLeslie Yes you can do this. You will have to create the file name as a string variable by concatenating various components. First convert the number variable to an ascii character string, then concatenate 'kk' + 'numberVariable + '.DAT' and call it something else. Then OPEN(2,FILE='somethingElse')
Thank you for your answer. I do not know how to create a string variable or an ascii character or how to concaternate the variables together :S Can you be a little more detailed on that. I realised that fortran does not give to many options in plotting and i am desperatly trying to convert my code into matlab. I have used many converters. I managed to convert from fortran 77 to fortran 90 but i fail to do so on Matlab
 P: n/a Perhaps this may help to open some doors:  CHARACTER s*4 ! create string variabel 4 characters long DO 10 i=1,5 WRITE(s,20) i ! convert integer i to string in s using format in 20 PRINT *, 'kk'//s//'.dat' ! concatenates 'kk' plus s plus '.dat' 10 CONTINUE 20 FORMAT(I4.4) END This should print a list of file name that have an incrementing number in it, i.e. kk0001.dat kk0002.dat kk0003.dat kk0004.dat kk0005.dat I must admit to being a bit lost as to you actual problem however.
 P: 7 Thanks again vor your answer! It was helpful. The thing is that i have a code in fortran 77 that is giving me some data on external files every time i run it. It is a simulation of a flow. At first i was trying to create additional code so every time the program will give me a new notepad file with external data then the target file that contains the initial data will change its name into the name of the external data file. Then the program would run again but with different initial data ( as now the initial data will be the results data from the first run of the program) and would give me a different external data. And i wanted this to go on for 10 times in order to get 10 files with external data. But then i decided that instead of using excel to plot my data i could translate into matlab and do it a lot easier. So i managed to convert the code from fortran 77 to fortran 90 but i can not manage to translate into matlab as i am using f2matlab converter.
 P: 5 I want to calculate sum of square of two matrix in fortran . how can I do that using " sum function".
 P: 5 Hi dear i want to write a " if command" whit fortran which is too long. could you please what can I do? thanks a lot
 P: 5 Hi dear i want to write a " if command" whit fortran which is too long. could you please what can I do? thanks a lot
 Mentor P: 21,214 You need to be more specific about what you are trying to do. Also, instead of tacking your question onto the end of a thread that is almost three years old, it's better to start a new thread.

 Related Discussions Programming & Computer Science 2 Programming & Computer Science 0 Programming & Computer Science 0 Programming & Computer Science 4 Programming & Computer Science 7