Q: print and newline 
Author Message
 Q: print and newline

How do I make print _not_ append a newline?

do j = 1, 10
        print *, "Line ", j, ": "
        do i = 1, 40
                print *, "a"
        enddo
        ! then print newline
enddo

I want the output to be like this:
Line 1: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Line 2: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
.
.
Line 10: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

and _not_:
Line 1:
a
a
a
a
.
.
a
Line 2:
.
.

How?

--
Knut Petter Svendsen



Wed, 18 Jun 1902 08:00:00 GMT  
 Q: print and newline

Quote:

> How do I make print _not_ append a newline?

> do j = 1, 10
>         print *, "Line ", j, ": "
>         do i = 1, 40
>                 print *, "a"
>         enddo
>         ! then print newline
> enddo

do j = 1, 10
  write(*,"(a)",advance="no") "Line ", j, ": "
  do i = 1, 40
    write(*,"(a)",advance="no") "a"
  end do
  print *    ! line feed
end do

--
Henry Leyh
Max-Planck-Institut fr Plasmaphysik, Bereich Stellaratortheorie
Wendelsteinstra?e 1, 17491 Greifswald, Germany
Tel: +49-(0)3834-88-2422



Wed, 18 Jun 1902 08:00:00 GMT  
 Q: print and newline

Quote:

> do j = 1, 10
>   write(*,"(a)",advance="no") "Line ", j, ": "
>   do i = 1, 40
>     write(*,"(a)",advance="no") "a"
>   end do
>   print *    ! line feed
> end do

Thanks, it works! But, if I replace the inner loop with:

     do i = 1, 640
        write(*,"(a a)",advance="no") "a" , "b"
     end do

It dumps core:

lib-4211 : UNRECOVERABLE library error
  A WRITE operation tried to write a record that was too long.

Encountered during a sequential formatted WRITE to unit 101
fortran unit 101 is connected to a sequential formatted text file
  (standard output).
 Current format: (a a)  
                ^

IOT Trap
Abort (core dumped)

Isn't it possible to write soo long lines? Are there any workarounds?

--
Knut Petter Svendsen



Wed, 18 Jun 1902 08:00:00 GMT  
 Q: print and newline
On 07 Jul 2000 10:57:13 +0200, Knut Petter Svendsen


Quote:
>Thanks, it works! But, if I replace the inner loop with:
>     do i = 1, 640
>        write(*,"(a a)",advance="no") "a" , "b"
>     end do
>It dumps core:
>lib-4211 : UNRECOVERABLE library error
>  A WRITE operation tried to write a record that was too long.
>Encountered during a sequential formatted WRITE to unit 101
>Fortran unit 101 is connected to a sequential formatted text file
>  (standard output).
> Current format: (a a)  
                ^
>IOT Trap
>Abort (core dumped)
>Isn't it possible to write soo long lines? Are there any workarounds?

        Why do you want to write such a long line to the console?  Surely
it's fixed at some width?  The answer to your basic question is that when
a file is opened it has a maximum record length specified -- in this
case the * unit is pre-connected with some default width (possibly 132)
which you are exceeding.  You probably can't change this, but you can
open another unit-number with a different maximum record length.  See
your documentation for the OPEN statement, in particular the RECL
keyword.

--

        KotPT -- "for stupidity above and beyond the call of duty".



Wed, 18 Jun 1902 08:00:00 GMT  
 Q: print and newline

Quote:


> > do j = 1, 10
> >   write(*,"(a)",advance="no") "Line ", j, ": "
> >   do i = 1, 40
> >     write(*,"(a)",advance="no") "a"
> >   end do
> >   print *    ! line feed
> > end do

> Thanks, it works! But, if I replace the inner loop with:

>      do i = 1, 640
>         write(*,"(a a)",advance="no") "a" , "b"
>      end do

> It dumps core:

> lib-4211 : UNRECOVERABLE library error
>   A WRITE operation tried to write a record that was too long.

> Encountered during a sequential formatted WRITE to unit 101
> Fortran unit 101 is connected to a sequential formatted text file
>   (standard output).
>  Current format: (a a)
>                 ^

> IOT Trap
> Abort (core dumped)

> Isn't it possible to write soo long lines? Are there any workarounds?

Mhm, looks like SGI... trying... aah... :-)  I run into that problem on
an Origin 2000, a Cray T3E and also on a NEC SX-5, but it works fine on
AIX, Linux and SUN (the latter stating that there is a comma required
between the two format 'a's, by the way).  The max length of the string
passed to the write routine seems to be hard-wired, maybe for
performance reasons or because of mere sloppiness (side glance at
MIPS...).  You should try to find a way to split that line in some way
as you usually won't write to terminals the width of 1280 characters...

Good luck and Gruss,
--
Henry Leyh
Max-Planck-Institut fr Plasmaphysik, Bereich Stellaratortheorie
Wendelsteinstra?e 1, 17491 Greifswald, Germany
Tel: +49-(0)3834-88-2422



Wed, 18 Jun 1902 08:00:00 GMT  
 Q: print and newline

Quote:

> > do j = 1, 10
> >   write(*,"(a)",advance="no") "Line ", j, ": "
> >   do i = 1, 40
> >     write(*,"(a)",advance="no") "a"
> >   end do
> >   print *    ! line feed
> > end do

> Thanks, it works! But, if I replace the inner loop with:

>      do i = 1, 640
>         write(*,"(a a)",advance="no") "a" , "b"
>      end do

> It dumps core:

> lib-4211 : UNRECOVERABLE library error
>   A WRITE operation tried to write a record that was too long.

> Encountered during a sequential formatted WRITE to unit 101
> Fortran unit 101 is connected to a sequential formatted text file
>   (standard output).
>  Current format: (a a)  
>                 ^

> IOT Trap
> Abort (core dumped)

> Isn't it possible to write soo long lines? Are there any workarounds?

Are you using SGI MIPSPro? If so, then RTFM:

$ LANG=C explain lib-4211  # this system has LANG=en_CA

  A WRITE operation tried to write a record that was too long.

  A Fortran WRITE operation tried to write a record that was too long.

  Either reduce the size of the record to be written or increase the size
  of the largest record that can be written.

  The maximum formatted record size (for either sequential- or direct-
  access files) can be increased with the use of RECL parameter on the
  OPEN statement.

  The error class is UNRECOVERABLE (issued by the run-time library).

--



Wed, 18 Jun 1902 08:00:00 GMT  
 Q: print and newline

Quote:

>    Why do you want to write such a long line to the console?  Surely
> it's fixed at some width?  The answer to your basic question is that when

I'm generating a XPM file with large resolution. (I've seen libXpm, but I
couldn't manage to use it..) Each scanline is a string of 2 * x-res
characters. I've found a workaround by calling a c-function:

void p_(char *str, int i) {
  int t;

  for (t = 0; t < i; t++)
    putchar(str[t]);

Quote:
}

Compiled this and linked it into my program. Then 'call p(string)' works
fine :)

--
Knut Petter Svendsen



Wed, 18 Jun 1902 08:00:00 GMT  
 Q: print and newline

Quote:
> void p_(char *str, int i) {
>   int t;

>   for (t = 0; t < i; t++)
>     putchar(str[t]);
> }

Retch. Why don't you just write the whole array in one go as an unformatted
binary file? Or do you think calling through N levels of run time library code
for every single byte of output makes good use of your processor?

        Jan



Wed, 18 Jun 1902 08:00:00 GMT  
 Q: print and newline

Quote:

> Retch. Why don't you just write the whole array in one go as an unformatted
> binary file? Or do you think calling through N levels of run time library code
> for every single byte of output makes good use of your processor?

Because I don't know better ;) If you could tell me how it would be nice.

--
Knut Petter Svendsen



Wed, 18 Jun 1902 08:00:00 GMT  
 Q: print and newline
On 07 Jul 2000 17:36:25 +0200, Jan Vorbrueggen


Quote:

>> void p_(char *str, int i) {
>>   int t;
>>   for (t = 0; t < i; t++)
>>     putchar(str[t]);
>> }
>Retch. Why don't you just write the whole array in one go as an unformatted
>binary file? Or do you think calling through N levels of run time library code
>for every single byte of output makes good use of your processor?

        I'm sure somewhen I've decompiled a library fwrite statement into
approximately:

fwrite(buff,s,n,file)
char *buff;
size_t size,n;
FILE *file;
{ char *c;
  int i,j;

        for (c=buff, i=0; i<n; i++)
            for (j=0; j<s; j++)
                fputc(*(c++),file);

Quote:
}

        but I can't remember which compiler it was...

--

        KotPT -- "for stupidity above and beyond the call of duty".



Wed, 18 Jun 1902 08:00:00 GMT  
 Q: print and newline

Quote:
> > Retch. Why don't you just write the whole array in one go as an unformatted
> > binary file? Or do you think calling through N levels of run time library
> > code for every single byte of output makes good use of your processor?
> Because I don't know better ;) If you could tell me how it would be nice.

Hmmm. I think Statoil earns enough money to buy you one of the excellent books
on Fortran that are regularly referenced here.

        Jan



Wed, 18 Jun 1902 08:00:00 GMT  
 Q: print and newline

Quote:

> Hmmm. I think Statoil earns enough money to buy you one of the excellent
> books on Fortran that are regularly referenced here.

We probably do, but I've got two of those books and I couldn't find an answer
for my first question. Anyway, I found a workaround which works :)

--
Knut Petter Svendsen



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. PEP 259: Omit printing newline after newline

2. PEP 259: Omit printing newline after newline

3. Newline Suppression in Print

4. instead of single column, print fields 3 or 4 across then newline

5. Printing newlines

6. echo, print and the newline character

7. print without newline?

8. print without newline

9. Printing without newlines..

10. Print characters on one line without newline...???

11. several Qs

12. Qs on CLUBMGR, Template BUG ???

 

 
Powered by phpBB® Forum Software