How do I change the first “write” statement (not the array definition) to make this work correctly?
main.c
#include <stdio.h>
#include <string.h>
void test2_(); /*float *q, int sugar, int firm, char *amt, float a, float b, float c);*/
int test1 (double z1, int firm, char *amt, double z2, double z3, double z4)
{
float q;
float a, b, c;
int sugar = 1;
q = (float) 1.0 + z1;
a = (float) z2;
b = (float) z3;
c = (float) z4;
printf ("test1: amt = %s\n",amt);
test2_ (&q, &sugar, &firm, amt, &a, &b, &c);
return 0;
}
int main ()
{
double have1 = 100.0;
int have2 = 1;
char have3 [31] = "Rock And Roll";
double have4 = 300.0;
double have5 = 400.0;
double have6 = 500.0;
have3[31] = '\0';
test1(have1, have2, have3, have4, have5, have6);
return 0;
}
test.f:
SUBROUTINE test2(Q, SUGAR, FIRM, AMT, A, B, C)
IMPLICIT NONE
INTEGER SUGAR, FIRM
REAL Q, A, B, C
CHARACTER AMT(31)
CHARACTER*10 MILK
INTEGER WATER,RICE
CHARACTER*1000 THESTRING
if (FIRM.EQ.1) THEN
WRITE(THESTRING,
&'(I3,1X,F16.2,1X,I2,1X,A4,1X,A26,3(1X,F10.4),1X,I2)')
&WATER,Q,SUGAR,MILK,AMT,A,B,C,RICE
write(*,*)'THESTRING is ---> ',THESTRING
ENDIF
RETURN
END
Compilation and run:
gfortran -c -g test.f -o test.o
gcc -c -g main.c -o main.o -DLINUX -DSYSV -DNOHLA -g -Wall -Werror -fmax-errors=1
gfortran -g test.o main.o -o main.exe -lgfortran -w -u -g -fno-second-underscore $(M32_OR_64_BIT_FLAG) -Wall -Werror -fmax-errors=1 -fcheck=all -fPIC
./main.exe
Output:
test1: amt = Rock And Roll
At line 14 of file test.f
Fortran runtime error: Expected REAL for item 6 in formatted transfer, got CHARACTER
(I3,1X,F16.2,1X,I2,1X,A4,1X,A26,3(1X,F10.4),1X,I2)