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

Integer to string conversion/concatenation problem

Stuart_M_
Beginner
502 Views
Hi folks

Steve posted this back in 2001:http://software.intel.com/en-us/forums/showthread.php?t=45268

I've been trying to apply this in order to have a character variable printed to an output file each iteration of a DO loop with an incrementally larger numeric addendum equal to the number of that loop appended to the name each time.

CHARACTER*4 CONP
CHARACTER*1 LSTRING
CHARACTER*5 CONPO
INTEGER LPRINTI

DATA CONP/'CONP'/

IF(LMAX.GT.O) THEN

DO LPRINT=1,LMAX
LPRINTI=LPRINT (not sure if this is really necessary or if I could use LPRINT as is)


IF(NST/NPRR(LPRINT)*NPRR(LPRINT) .EQ. NST)THEN
KREC=KREC+1
WRITE(LSTRING,'(I1)') LPRINTI
CONPO=CONP//LSTRING
WRITE(NUBINARY,REC=KREC)CONPO,NST,((RP(N,M,LPRINT), M=1,MMAX),N=1,NMAX)
ENDIF

ENDDO
ENDIF

I'm getting the following error referring to the line I have in bold italics:
Test_Case (042809)FTLOADDSUpdatesout.f(230): error #6303: The assignment operation or the binary expression operation is invalid for the data types of the two operands.

Much 'bliged
0 Kudos
4 Replies
TimP
Honored Contributor III
502 Views
It's difficult to figure out whether you have homed in on a single problem when so many things are wrong:
stub.f90(8): error #12143: "LMAX" is uninitialized
stub.f90(8): error #12143: "O" is uninitialized
stub.f90(14): error #12143: "NST" is uninitialized
stub.f90(15): error #12143: "KREC" is uninitialized
stub.f90(18): error #12143: "MMAX" is uninitialized
stub.f90(18): error #12143: "NMAX" is uninitialized
stub.f90(18): error #12143: "NUBINARY" is uninitialized
For example, maybe you meant the constant 0 rather than another implicit variable declaration "O". In fact, some nonsensical error reports might go away if other errors were corrected.
It does seem you could have stuck closer to the example you mentioned.
0 Kudos
Stuart_M_
Beginner
502 Views

Sorry, I was attempting to keep the code brief but functionally clear enough for someone to see what I was trying to do. It's a fairly large piece of code that I know works perfectly already (it's in a well-established model that I have used for a while), but to which I have tried to add some changes to automate the output printing that is currently controlled by manually editing code each time.

If you would prefer I can include it all, but I assure you everything is initialized.
0 Kudos
Stuart_M_
Beginner
502 Views
Quoting - stubaan

Sorry, I was attempting to keep the code brief but functionally clear enough for someone to see what I was trying to do. It's a fairly large piece of code that I know works perfectly already (it's in a well-established model that I have used for a while), but to which I have tried to add some changes to automate the output printing that is currently controlled by manually editing code each time.

If you would prefer I can include it all, but I assure you everything is initialized.

Ugh! Apologies - it looks like it may simply have been a matter of misnamed variables in the code (CONPO vs CONPNO)

Thanks for now... hopefully for good :-)
0 Kudos
Paul_Curtis
Valued Contributor I
502 Views
Quoting - stubaan
IF(NST/NPRR(LPRINT)*NPRR(LPRINT) .EQ. NST)THEN
KREC=KREC+1
WRITE(LSTRING,'(I1)') LPRINTI
CONPO=CONP//LSTRING
WRITE(NUBINARY,REC=KREC)CONPO,NST,((RP(N,M,LPRINT), M=1,MMAX),N=1,NMAX)
ENDIF

IF (MOD(nprr(lprint), nst) == 0) THEN
krec = krec + 1
WRITE (conp(5:5), '(I1)') lprint
WRITE (nubinary, REC=krec) conp, nst, .... etc...
END IF

and somewhere upstream of your loop you need to initialize krec.
0 Kudos
Reply