2

I would like to use FM package capabilities for the study of a problem in number theory. I installed the package, compiled libraries, and ran the two test suites supplied, all without any problems.

I wrote test.f:

   use fmzm

   TYPE (IM), SAVE :: n

   n = 0
   WRITE(*,*) n

   end

and compiled using

gfortran -c -O3 -Wall test.f
gfortran fmsave.o fm.o fmzm90.o test.o -o test

which returned no error or warning. But got disappointed by discovering the output:

./test
200000

The number 200000 appears to be a memory location for the variable n. I experimented a little, and if I change n to complex type (ZM) it outputs 200000, 199999. Similarly if I declare and initialize two variable instead of one.

If I change TYPE (IM), SAVE :: n to INTEGER n, and compile exactly as above, I get the expected 0 as output.

If I replace the code by

   n = 0
   do
   n=n+1
   if (n < 10) WRITE(*,*) n
   end do

then the output 200000 repeats 9 times and then stops. So it is the WRITE function which only finds the location and not the value. PRINT does the same.

veryreverie
  • 2,397
  • 1
  • 12
  • 25

1 Answers1

1

As Vladimir points out, unless you write out a value of a standard type, it seems you have to first convert to a string using a maneuver such as

str = im_format('i100', n)
str = adjustl(str)
str = trim(str)
print*, str

where the middle two lines can be left out.

francescalus
  • 27,974
  • 11
  • 58
  • 92