- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to be able to open output files of a FORTRAN code in excel. If I name an output file in a FORTRAN code, as: ouput1.xls, then would it be a an excel file to open in Excel?
If not, how can I do that?
opening txt files in Excel is another option but it is not easy for formatted outputs.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I name an output file in a FORTRAN code, as: ouput1.xls, then would it be a an excel file to open in Excel?No. Would naming a cat "dog" make it one? Giving a file an incorrect filename extension would, through file-type association, cause that file type to be opened by the specified application when the file is opened using the Windows GUI or the "start" command. However, if the contents of the file do not have the expected format, the application (e.g., Excel) may flag an error or behave incorrectly. You can easily write the output file as a tab (or comma or some other field separator) delimited file, which Excel can open properly. For example, the format string "(I8,3(1H,,I8))" would be suitable for writing four integers per line. Based on your numerous postings on rather elementary questions relating to Fortran, I think that you should spend an appropriate amount of time learning the language before attempting formatted output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I did not think I could concatenate the format strings within the Write StatementDavid, Note that a character variable may be used in place of a character constant for the format in a WRITE or READ statement. Likewise, one may build up a format string by (i) declaring a character variable for the string, (ii) doing an internal WRITE to that string (or manipulating string expressions as IanH showed) to produce the format, and (iii) following that by a WRITE to an external file using the newly built-up format string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
All of the solutions so far have dealt with the process of completely filling a blank Excel worksheet with data. This is actually fairly easy. More generally, we have need of writing to only a portion of an existing worksheet, or of reading the contents of [a portion of] a worksheet. And I don't mean by getting into Excel, export the contents to an ASCII file, and then read that. What we need is a direct interface to a .xls file based on the Excel object model.
Recognizing that IVF can't do this directly, I search for a 3rd-party solution. All I have come up with is a company called Canaimasoft.com, which appears to be defunct. Does anyone know of any other? Or is there a way to do it within IVF? I vaguely recall some discussion in this forum 2 - 3 years ago but it didn't seem very easy.
It's hard enough for Fortran to keep up in today's Language-of-the-month mentality, but in my field the .xls file has become the defacto standard for exchanging data with customers, so a good easy way of interfacing Fortran to Excel would go a long ways to supporting the future of Fortran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use COM to talk to (read or write) parts of an Excel worksheet. I'm pretty sure there are examples that come with IVF (I would have learnt from something like that), but its been a while since I've looked at those. If you have a particular scenario that isn't covered by those/that examples, let me know and ankle-biters and model convergence permitting I'll see if I can put something together.
The current office file formats (xlsx etc) are just zipped file/directory structures of xml files (change the name of an .xlsx worksheet to .zip and open it in your favourite archive viewer to see what I mean). Not sure I'd fancy trying to work with that directly for an existing file though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can try the ODBC module in my FLibs project - http://flibs.sf.net This ought to give you read/write access to MS Excel files.
A problem is: how to find out what cells to write to. But I will that to you.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
dboggs wrote:
All of the solutions so far have dealt with the process of completely filling a blank Excel worksheet with data. This is actually fairly easy. More generally, we have need of writing to only a portion of an existing worksheet, or of reading the contents of [a portion of] a worksheet.
In my limited experience, if you have a Fortran program producing data that you want to display in Excel from within the Fortran code, including drawing a chart, it is a good idea to first program what you want to do in Visual Basic (Express, .NET), get it to work and then figure out how the sequence of required VB code operations can be reproduced using Fortran that makes use of the Excel module that can be created using the Fortran module wizard operating on the installed Microsoft Excel Object library. If it is a question of charting data, I find writing the data to a text file in fixed-width, comma or tab-delimited format is a good start. Then you can test the VB code using [csharp] oXL.Workbooks.OpenText(Filename:="c:\yourfilenamehere.txt", Origin:=437, StartRow:=1, DataType:=XlTextParsingType.xlFixedWidth)[/csharp] then, defining your ranges, use the chart wizard to plot the data. Although OpenText causes a new workbook to be created and filled from cell A1, you can later move the data, if you so wish, to another workbook\worksheet, placing it in a more convenient location. This code can usually be reproduced using the code available in the Excel Fortran module, again it is best to do it in VB first, then you know exactly what the Fortran must reproduce.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page