public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
* gsl_vector_fprintf
@ 2000-07-18 19:15 E. Robert Tisdale
  2000-07-19 13:57 ` gsl_vector_fprintf Brian Gough
  0 siblings, 1 reply; 7+ messages in thread
From: E. Robert Tisdale @ 2000-07-18 19:15 UTC (permalink / raw)
  To: gsl-discuss

I am suggesting that the GSL vector fprintf function be changed from

    int gsl_vector_fprintf(FILE *stream, const gsl_vector* v,
      const char* format);

to

    int gsl_vector_fprintf(FILE *stream, const gsl_vector* v,
      int width, unsigned int precision, unsigned int columns);

This permits the numerical application programmer
to display columns elements of a row vector at a time
on a line with a space between each element on a line
like this:

    0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0

instead of like this:

    0.0
    1.0
    2.0
    3.0
    4.0
    5.0
    6.0
    7.0
    8.0
    9.0

for a vector of 10 elements, for example.
A similar function for type gsl_matrix
simply prints the row vectors in order
so that it appears as a matrix on the display
if all of the columns of a row fit on one line.

int gsl_fprintf(FILE *stream, gsl_double x,
  int width, unsigned int precision) {
  char format[64];
  int   characters = sprintf(format, "%%%d.%ue", width, precision);
  if (0 <= characters) {
    return fprintf(stream, format, (gsl_double)x); } else { return -1; }
  }

int gsl_vector_fprintf(FILE *stream, const gsl_vector* v,
  int width, unsigned int precision, unsigned int columns) {
  int           modulus = (0 < columns)? columns: 4;
  int           characters;
  int           total = 0;
  gsl_extent    n = gsl_vector_extent(v);
  gsl_offset    j = 0;
  for (j = 0; j < n; j++) {
    characters = (0 == j%modulus)? fprintf(stream, "\n"): fprintf(stream, " ");
    if (0 <= characters) { total += characters; } else { return -1; }
    characters = gsl_fprintf(stream, gsl_vector_get(v, j), width, precision);
    if (0 <= characters) { total += characters; } else { return -1; }
    }
  characters = fprintf(stream, "\n");
  if (0 <= characters) { total += characters; } else { return -1; }
  return total;
  }



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gsl_vector_fprintf
  2000-07-18 19:15 gsl_vector_fprintf E. Robert Tisdale
@ 2000-07-19 13:57 ` Brian Gough
  2000-07-19 14:47   ` gsl_vector_fprintf E. Robert Tisdale
  0 siblings, 1 reply; 7+ messages in thread
From: Brian Gough @ 2000-07-19 13:57 UTC (permalink / raw)
  To: E. Robert Tisdale; +Cc: gsl-discuss

Yup, a pretty print function is needed, probably with options to use
separators like , or to enclose the vector in parentheses.

The output from the current print functions is not very readable on
screen -- it's really intended for dumping to a file and to allow
arbitrary formats to be used, e.g. hex for integer data.

E. Robert Tisdale writes:
 > I am suggesting that the GSL vector fprintf function be changed from
 > 
 >     int gsl_vector_fprintf(FILE *stream, const gsl_vector* v,
 >       const char* format);
 > 
 > to
 > 
 >     int gsl_vector_fprintf(FILE *stream, const gsl_vector* v,
 >       int width, unsigned int precision, unsigned int columns);
 > 
 > This permits the numerical application programmer
 > to display columns elements of a row vector at a time
 > on a line with a space between each element on a line
 > like this:
 > 
 >     0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
 > 
 > instead of like this:
 > 
 >     0.0
 >     1.0
 >     2.0
 >     3.0
 >     4.0
 >     5.0
 >     6.0
 >     7.0
 >     8.0
 >     9.0
 > 
 > for a vector of 10 elements, for example.
 > A similar function for type gsl_matrix
 > simply prints the row vectors in order
 > so that it appears as a matrix on the display
 > if all of the columns of a row fit on one line.
 > 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gsl_vector_fprintf
  2000-07-19 13:57 ` gsl_vector_fprintf Brian Gough
@ 2000-07-19 14:47   ` E. Robert Tisdale
  2000-07-19 15:24     ` gsl_vector_fprintf Gerard Jungman
  0 siblings, 1 reply; 7+ messages in thread
From: E. Robert Tisdale @ 2000-07-19 14:47 UTC (permalink / raw)
  To: gsl-discuss

Brian Gough wrote:

> Yup, a pretty print function is needed,
> probably with options to use separators like ,
> or to enclose the vector in parentheses.

I'm not so sure about that.
Pretty printing with separators and enclosures
seems to imply that you would have
another GSL function that could scan it all back in.
What would you do if you scanned in the last element
before you got to the closing paren?
Or if you encountered a closing right paren
before the end of your vector view?

> The output from the current print functions
> is not very readable on screen --
> it's really intended for dumping to a file
> and to allow arbitrary formats to be used,
> e.g. hex for integer data.

My version of gsl_vector_fprintf permits you
to set the number of columns to 1
so you could get the same output as your version.
I suppose that my version should include
an argument to set format flags so that it can print
fixed or scientific floating-point notation or
decimal, hexadecimal or octal integers.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gsl_vector_fprintf
  2000-07-19 14:47   ` gsl_vector_fprintf E. Robert Tisdale
@ 2000-07-19 15:24     ` Gerard Jungman
  0 siblings, 0 replies; 7+ messages in thread
From: Gerard Jungman @ 2000-07-19 15:24 UTC (permalink / raw)
  To: GSL discussion list

"E. Robert Tisdale" wrote:
> 
> I'm not so sure about that.
> Pretty printing with separators and enclosures
> seems to imply that you would have
> another GSL function that could scan it all back in.

Yes, that would be consistent.

> What would you do if you scanned in the last element
> before you got to the closing paren?
> Or if you encountered a closing right paren
> before the end of your vector view?

Sometimes, it would be an error.


-- 
G. Jungman

^ permalink raw reply	[flat|nested] 7+ messages in thread

* gsl_vector_fprintf
@ 2003-03-06  7:50 Annett Keller
  0 siblings, 0 replies; 7+ messages in thread
From: Annett Keller @ 2003-03-06  7:50 UTC (permalink / raw)
  To: gsl-discuss

Hi Brian,

could figure out the problem by myself. But thank you very much for the
option anyway.
Maybe it is interesting for somebody: running GSL under Visual C++ (in my
case 6.0) needs some adaption (Multithreaded DLL). And then things should work.

Again thanks a lot
regrads
Annett

-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gsl_vector_fprintf
  2003-02-26 10:48 gsl_vector_fprintf Annett Keller
@ 2003-03-02 20:32 ` Brian Gough
  0 siblings, 0 replies; 7+ messages in thread
From: Brian Gough @ 2003-03-02 20:32 UTC (permalink / raw)
  To: Annett Keller; +Cc: gsl-discuss

Annett Keller writes:
 > Probably my problem is quite simple to solve but I can't do it.  I
 > want to run the test program for gsl_vector_fprintf given in the
 > GNU-GSL library:
 > 
 > #include <stdio.h> include <gsl/gsl_vector.h>
 > 
 > int main(void) {
 > 	int i;
 > 	gsl_vector *v=gsl_vector_alloc(10);
 > 
 > 	for (i=0;i<10;i++)
 > 	{
 > 		gsl_vector_set(v,i,1.23+i);
 > 	}
 > 	{
 > 		FILE *f=fopen("test1.txt","w"); /* "test1.dat" doesn't
 > work either
 > 		gsl_vector_fprintf(f,v,"%.5g");
 > 		fclose(f);
 > 	}
 > 
 > 	return 0; }
 > 
 > compiling shows no error but running leads to an error message:
 > somthing like 'the command in line 0x77883941 points to store
 > address 0x00000010. "written" can't be run on that store address'
 > did anyone ever had such a problem?  Thanks Annett

It looks like you may be using a non-unix platform.  If you still have
problems please send a bug report to bug-gsl@gnu.org with details of
the compiler and operating system version and commands used to compile
and run the program so we can try to reproduce the problem for
testing. Thanks.

regards,
-- 
Brian Gough

----------------------------------------------------------------------
Network Theory Ltd            Phone: 0117 3179309 (+44 117 3179309)
15 Royal Park                   Fax: 0117 9048108 (+44 117 9048108)
Bristol BS8 3AL                 WWW: http://www.network-theory.co.uk/
United Kingdom                Email: bjg@network-theory.co.uk     
----------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 7+ messages in thread

* gsl_vector_fprintf
@ 2003-02-26 10:48 Annett Keller
  2003-03-02 20:32 ` gsl_vector_fprintf Brian Gough
  0 siblings, 1 reply; 7+ messages in thread
From: Annett Keller @ 2003-02-26 10:48 UTC (permalink / raw)
  To: gsl-discuss

Hi,

hope I chose the right list/address.

Probably my problem is quite simple to solve but I can't do it.

I want to run the test program for gsl_vector_fprintf given in the GNU-GSL
library:

#include <stdio.h>
#include <gsl/gsl_vector.h>

int main(void)
{
	int i;
	gsl_vector *v=gsl_vector_alloc(10);

	for (i=0;i<10;i++)
	{
		gsl_vector_set(v,i,1.23+i);
	}
	{
		FILE *f=fopen("test1.txt","w");     /* "test1.dat" doesn't work either
		gsl_vector_fprintf(f,v,"%.5g");
		fclose(f);
	}

	return 0;
}

compiling shows no error but running leads to an error message:

somthing like 'the command in line 0x77883941 points to store address
0x00000010. "written" can't be run on that store address'

did anyone ever had such a problem?
Thanks
Annett
keller_annett@gmx.de

-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-03-06  7:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-18 19:15 gsl_vector_fprintf E. Robert Tisdale
2000-07-19 13:57 ` gsl_vector_fprintf Brian Gough
2000-07-19 14:47   ` gsl_vector_fprintf E. Robert Tisdale
2000-07-19 15:24     ` gsl_vector_fprintf Gerard Jungman
2003-02-26 10:48 gsl_vector_fprintf Annett Keller
2003-03-02 20:32 ` gsl_vector_fprintf Brian Gough
2003-03-06  7:50 gsl_vector_fprintf Annett Keller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).