c=========================================================== c stringfmt: Illustrates use of Fortran "Internal I/O c (equivalent of "sprintf" in C) to create strings such c as c c filename..dat c c where is a run-time parameter c c Sample usage on lnx1: c c lnx1% pwd c /home/phys410/util c c lnx1% make stringfmt c pgf77 -g -c stringfmt.f c pgf77 -g -L/usr/local/PGI/lib \ c stringfmt.o -lp410f -o stringfmt c Linking: c c lnx1% stringfmt c usage: stringfmt c c lnx1% stringfmt 100 c c c lnx1% stringfmt 0 c c c lnx1% stringfmt 123456 c c=========================================================== program stringfmt implicit none c----------------------------------------------------------- c Define a character variable which will be the "target" c of the "write" operation. c----------------------------------------------------------- character*128 buffer integer iargc, i4arg, indlnb, n if( iargc() .ne. 1 ) go to 900 n = i4arg(1,-1) if( n .lt. 0 ) go to 900 c----------------------------------------------------------- c Write the value of 'n' to 'buffer' according using c format code i6.6; this produces an integer field c precisely 6 digits wide, with leading 0's if c necessary c----------------------------------------------------------- write(buffer,100) n 100 format('filename.',i6.6,'.dat') write(*,*) '<'//buffer(1:indlnb(buffer))//'>' stop 900 continue write(0,*) 'usage: stringfmt ' stop end