- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a very large routine full of WRITE statements which write to a unit number (for file output). This routine is now going to also be called by a GUI through a DLL, and in this case I want the WRITE statements to write to a character array instead of the file unit number. (It must still be able to write to the unit number if not called from the GUI). Now short of putting an IF statement around every WRITE statement, can I use a better method eg. using pointers to do it?
Say I have:
WRITE(IU,'(a,/,a)') 'test1', 'test2'
And I want the same code to work if IU points to a character array (if called from the GUI)
So I know I can say:
INTEGER :: IU
CHARACTER(256) :: CA(2)
IF(GUI) then
WRITE(CA(1:2),'(a,/,a)') 'test1', 'test2'
ELSE
WRITE(IU,'(a,/,a)') 'test1', 'test2'
ENDIF
but I'd prefer it if I can use then same code without the IF test, by some fancy footwork on IU and CA(2) beforehand so I wouln't have to modify every IF statement, eg.
IF(GUI) THEN
IU -> CA ! or whatever
ENDIF
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually I'll just change IU into a character array, and then write the character aray into the file at the end of the routine!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Adrian,
Could you consider always writing to the character array, then at the end of the routine check if the GUI flag is set, and if not loop through the character array and write to the file?
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Michael, thanks that's what I did in the end.
![](/skins/images/8B6E2C8F64F54CBD7F7262AA46F575DA/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page