- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a legacy fortran (16 bit) application, along with the Fotran 77 fixed format source files.
I need to rebuild this as a 32-bit exe. It outputs files, which are used in another application which I cannot change.
After some pain I can recompile these and build an exe. Unfortunately there are some differences in the files produced by the new build of my exe, and the second application is unable to read them correctly.
For floating point numbers the leading zero is written in the old version, but suppressed in the new one
Example, Old version 's output:
0.4120E+03
New version output :
.4120E+03
Is there a compiler switch which will force it to output the leading zeroes?
I need to rebuild this as a 32-bit exe. It outputs files, which are used in another application which I cannot change.
After some pain I can recompile these and build an exe. Unfortunately there are some differences in the files produced by the new build of my exe, and the second application is unable to read them correctly.
For floating point numbers the leading zero is written in the old version, but suppressed in the new one
Example, Old version 's output:
0.4120E+03
New version output :
.4120E+03
Is there a compiler switch which will force it to output the leading zeroes?
Link Copied
12 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, there isn't. The Fortran standard says that the leading zero is optional and we don't emit it. What kind of application can't read these?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And, regardless of what the Fortran Standard says, it's always been an option of the particular compiler whether they are included or not. It's not a Legacy issue.
Linda
Linda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The standard allows the processor to print or omit a zero to the left of the decimal point when an E or D format is used.
Please elaborate on your constraints, and give some examples of the format descriptors that you use for the output that caused you problems. Also, please state the compiler version and OS used.
Is the leading '0' missing only from the first number on a line?
Will the consuming application handle ^4.12E0+03, where '^' stands for blank? Is the field length fixed, or will the input be scanned until the next white-space character? Do you have non-numeric text in the input along with numbers?
Will output from your program with a format specification ES do? Have you looked at the kP scale prefix?
If none of these work out, you may need to consider to use an external filter ( such as sed ) to add the missing leading zeroes.
Please elaborate on your constraints, and give some examples of the format descriptors that you use for the output that caused you problems. Also, please state the compiler version and OS used.
Is the leading '0' missing only from the first number on a line?
Will the consuming application handle ^4.12E0+03, where '^' stands for blank? Is the field length fixed, or will the input be scanned until the next white-space character? Do you have non-numeric text in the input along with numbers?
Will output from your program with a format specification ES do? Have you looked at the kP scale prefix?
If none of these work out, you may need to consider to use an external filter ( such as sed ) to add the missing leading zeroes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was trying some examples and I always saw the leading zero. My memory is a bit hazy on where we differed from Microsoft on this. Can you show an example that omits the zero?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe it happens with a tight format? The leading zero is superfluous, so ...
Regards,
Arjen
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Marion,
If the scientific format is mandatory (i.e. use of 'E' or 'G' format descriptors), may be you can consider using the '1P' format modifier. It will force to have the first digit not equal to zero.
I explain: In the old format if you had ^0.4120E+03, using for example the format : E11.4,
using the format : 1PE11.4,will produce the following output : ^4.1200E+02(don't remember to add a digit for the possible leading sign).
However you have to be very careful using the 'P' format modifier as it could changes the behavior of the formats following the modified one. It is not a problem if they all use a 'E' or 'G' format descriptor but not for other numeric formats ; in this you will need to cancel the '1P' format modifier by adding a '0P' format modifier to the next first non 'E' or 'P' format descriptor (I and F especially). I hope to have been clear but if not don't hesitate to look in the FORTRAN manual about the 'P' format modifier.
Best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The consuming application is VB, converted from Excel (via a code converter I think). I am surprised that it can't read numbers without the leading zero, but the example they have supplied has no other differences between the old and new files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What's the latest on this leading zero problem? There has been a lot of discussion on different threads in this forum but some of the rules seem to have changed.
I am using G format. My legacy programs (way back to Microsoft 5.0) did not print a leading zero. Fairly recent discussions here were sometimes from people using Intel 11 that were not getting the leading zero but the wanted it. I am using Intel 12 and I am getting a leading zero and I don't want it.
Surely there is (or should be) a way to specify whether it is printed or not?
The documentation states that a leading zero is option when using the E edit descriptor, but it doesn't say how to control it.
I am using G format. My legacy programs (way back to Microsoft 5.0) did not print a leading zero. Fairly recent discussions here were sometimes from people using Intel 11 that were not getting the leading zero but the wanted it. I am using Intel 12 and I am getting a leading zero and I don't want it.
Surely there is (or should be) a way to specify whether it is printed or not?
The documentation states that a leading zero is option when using the E edit descriptor, but it doesn't say how to control it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You do not have control over this. As has been recently discussed in comp.lang.fortran, the "option" is the choice of the compiler, not the programmer. Nothing has changed in this regard since 1997.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
On that forum John Harper wrote that he has a module (in two versions) that gives you the
control over whether a leading zero is printed or not. I have added the code to my Flibs
project (http://flibs.sf.net- see the CVS repository for the actual code). But it remains
something outside the standard.
Regards,
Arjen
control over whether a leading zero is printed or not. I have added the code to my Flibs
project (http://flibs.sf.net- see the CVS repository for the actual code). But it remains
something outside the standard.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't really care whether the leading zero is part of the standard or not, I just want consistency and don't like it when a compiler vendor changes their mind in ways that affect my old code--never mind that the standard "allows them to do that."
Thanks for offering the module, but I can probablymodify my code to accommodate the change as easy as I can accommodate a new module. I just don't like having to do it too often.
Thanks for offering the module, but I can probablymodify my code to accommodate the change as easy as I can accommodate a new module. I just don't like having to do it too often.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have not seen any evidence that we changed the behavior, unless there was some edge case clarified by an interpretation to the standard.

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