Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Overriding the READ function in Fortran

John_V_
Beginner
789 Views

All,

I have inherited a legacy Fortran system which contains several different modules which read ASCII text files from various logical units.  Examples:

100 read (userin,1,iostas=ios) line

READ(I3,805) ACTYCO,

etc.

The Fortran system is distributed with the necessary ASCII text files.  I have been given the task to only delivered the system with binary files instead of ASCII files for proprietary data security.  An easy solution would be to add a converter of the binary files to ASCII in a temporary file at the beginning of the system and then delete the temporary ASCII files after all the reads are complete.  This solution has been removed due to the possible of temporary file remaining on the user's machine after an unexpected crash of the Fortran.

So, my question is:  Can I override the "READ" function in Fortran ( similar to C capability ) to insert my own READ which would handle either ASCII or binary?  This would allow me to not change the hundred or so READ statements in the legacy code.  Also, if there is a more elegant solution this the problem stated, I am all ears.

Thanks,

Bryan

0 Kudos
2 Replies
Steven_L_Intel1
Employee
789 Views

No, sorry. In Fortran, READ is a statement, not a function, and can't be overridden by the user. But even just a switch to binary (or "unformatted" in Fortran terminology) is hardly any kind of protection, as anyone with a file dumper (such as Visual Studio's binary editor) can read a binary file and figure out what data it contains.

How big are these data files? The simplest approach from the code perspective would be to load the "binary" data into a big array of character values, and instead of reading from a unit number (I3 in your example), reading from an element of the array. You'd have to keep track of the element number for the index. The rest of the code would not need to change.

For the binary data, if protection is really important you could encrypt it and decrypt it into memory. We supply a "Crypto" sample showing how this is done using the Windows cryptography services. The key would have to be in the source code and you'd need to protect it against debuggers and just dumping the executable by constructing it in memory, or maybe XORing the key with some pattern.

0 Kudos
John_V_
Beginner
789 Views

Thanks for the info

0 Kudos
Reply