Silverfrost Forums

Welcome to our forums

Read format error

4 Sep 2008 4:28 #3792

Hi,

I found the following problem: I´m reading an array of data like: 10180 10209.5 10229.1 10239

In the FORMAT statement I specified f7.1 the point is that I read and I get the following result: 1018.0 10209.5 10229.1 1023.9

Is like with that format, always writes with decimal even when it´s not, what should I do to short it out??? Thanks very much

Best regards RCA

4 Sep 2008 9:36 #3793

I am not sure why you are getting this result. Perhaps in reality the are some leading spaces in the field.

Anyway, the usual approach is to use 'list-directed' input which means using an asterisk in place of the format string.

5 Sep 2008 12:01 #3796

Use format f7.0. This should fix the problem of implied decimal points. You should also check the use of bz or bn, as this would have changed the interpretation of 10180.

Try the following example: character string7, fmt10 real x ! string = '10180 ' ! fmt = '(bz,f7.0)'; read (string, fmt=fmt) x; write (,) x, ' ', fmt fmt = '(bz,f7.1)'; read (string, fmt=fmt) x; write (,) x, ' ', fmt fmt = '(bn,f7.0)'; read (string, fmt=fmt) x; write (,) x, ' ', fmt fmt = '(bn,f7.1)'; read (string, fmt=fmt) x; write (,) x, ' ', fmt end

5 Sep 2008 8:56 #3799

Umm, I see, I undertand but the problem is that I have a matrix of around 8000x15 data.., there is not a method to automatice this problem. I think I should talk with the data provider in order to get the data always with decimal, even when is .0

Paul, I used the *, but the program crashs, I ´m reading a file like: 2008-09-01 00:05:25,-1,-1,-1,-1,-1,-1,10.597,5940,-1,-1,-1 2008-09-01 00:05:38,6191.58,127.864,-1,-1,-1,-1,10.6544,5970,-1,-1,-1 2008-09-01 00:05:51,6201,186.879,-1,-1,-1,-1,12.6394,5940,-1,-1,-1 2008-09-01 00:06:04,6211.25,206.55,-1,-1,-1,-1,15.3091,5970,-1,-1,-1

And I use the format: (i4, 4(1x,i2),4x,7f9.2,4f9.2)

It´s a difficult problem, as you can see, there is INTEGER and REAL in the same position: -1 6191.58 6201 6211.25

The '-1' don´t mind, becasue means no data and I created and statment that turn it to '0.00' when is read '-0.01' ( In this formtat, fortran reads ---0.01 insted of -1), but the '6201' is a real problem, because reads '620.1' and I´m doing some averages.... I will talk with the data provider, I think there is not a automaticaly way to short it out

Thanks very much for your responses

Warmest regards RCA

5 Sep 2008 9:42 #3800

I don´t know how or why, but I tried the format:

(i4, 4(1x,i2),4x,7f9.0,4f9.0)

As Campbell suggested and YES!!!!!!!!!!!, finally solves the problem!!!!!

But I don´t understand why solves

Eternally grateful for your support!!!! best regards RCA

5 Sep 2008 10:16 #3801

RCA,

I would read each line as a character string, then process this string as follows:-

The date and time part is of a constant length and format, so this can be read using a fixed format on an internal read. After reading the date and time fill this part of the character string with spaces. Then using a simple loop check each character of the remaining string to see if they are a comma or not, and replace commas with a space. Finally use the free format * to read the rest of the string.

Please login to reply.