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

Compatiblity with legacy fortran: display of leading zeroes

Marion
Beginner
686 Views
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?

0 Kudos
12 Replies
Steven_L_Intel1
Employee
686 Views
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?
0 Kudos
lklawrie
Beginner
686 Views
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
0 Kudos
mecej4
Honored Contributor III
686 Views
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.
0 Kudos
Steven_L_Intel1
Employee
686 Views
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?
0 Kudos
Arjen_Markus
Honored Contributor I
686 Views
Maybe it happens with a tight format? The leading zero is superfluous, so ...

Regards,

Arjen
0 Kudos
netphilou31
New Contributor III
686 Views
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,
0 Kudos
Marion
Beginner
686 Views
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.
0 Kudos
dboggs
New Contributor I
686 Views
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.
0 Kudos
Steven_L_Intel1
Employee
686 Views
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.
0 Kudos
Arjen_Markus
Honored Contributor I
686 Views
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
0 Kudos
dboggs
New Contributor I
686 Views
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.
0 Kudos
Steven_L_Intel1
Employee
686 Views
I have not seen any evidence that we changed the behavior, unless there was some edge case clarified by an interpretation to the standard.
0 Kudos
Reply