COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Character to Real*8

• Email
• Follow

Hi, This hopefully is a basic question.  How do I equate a real to a
character if I know that the character array contains a number.

E.G.

real*8 X
character a(*)

x= real(a(0:10)) doesn't work but what does?

Thanks, Rudy

 0
Reply rjmagyar (14) 6/13/2006 4:13:10 PM

See related articles to this posting

Hello,

rjmagyar wrote:
> Hi, This hopefully is a basic question.  How do I equate a real to a
> character if I know that the character array contains a number.
>
> E.G.
>
> real*8 X
> character a(*)
>
> x= real(a(0:10)) doesn't work but what does?

read( unit= a, fmt='...') x

Investigate "internal read" in your compiler's documentation
or a Fortran textbook.

Note that the length of the character variable ( the "*"
in the a(*) above) should be consistent with the format used
in the internal read.

HTH

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.
 0
Reply dannagle (1019) 6/13/2006 4:31:02 PM

rjmagyar <rjmagyar@gmail.com> wrote:

> Hi, This hopefully is a basic question.  How do I equate a real to a
> character if I know that the character array contains a number.
>
> E.G.
>
> real*8 X
> character a(*)
>
> x= real(a(0:10)) doesn't work but what does?

Three things.

1. Just a terminology matter. What you want is not to "equate" them. If
you use that terminology, you will end up going down the wrong path.
What you want is to convert a value from one form to the other.

2. Do you really want to use character arrays instead of character
strings? Both are allowed, but character strings are more natural for
most Fortran purposes, including this one. Yes, there is a difference,
as comes up below.

3. With character strings, this is a FAQ, and the answer is an internal
READ. If "a" were a string instead of an array, you could do something
like

(Note. The use of list-directed formatting - the * here - is standard in
f90 and later, but not in f77, although most later f77 compilers accept
it as an extension. For string f77, you'd need an explicit format, which
can add extra complications if the string length is arbitrary).

For the character array case, the first thing you need to do is copy the
array into a temporary string.... and there are extra complications
there because the declaration form you used means that the size of the
array is unknown. I see that you used a(1:10) in your example. Does this
mean that you are guaranteed that both

a) The array is at least 10 elements in size

and

b) The data of interest (and nothing else) is all within the first 10
elements?

If both of these are true, then you could declare the temporary string
as

character*10 c

and do the copy with (using f90 DO loop syntax)

do i = 1 , 10
c(i:i) = a(i)
end do

Then you can do the internal read with

If either of the conditions is false, then that adds a little extra,
depending on exactly what you can guarantee.

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain
 0
Reply nospam47 (9744) 6/13/2006 4:34:16 PM

Dan Nagle <dannagle@verizon.net> wrote:

> Note that the length of the character variable ( the "*"
> in the a(*) above) should be consistent with the format used
> in the internal read.

Note that, unfortunately, the length of the character variable in
question is 1. The * is for the size of the character array. See my
other post.  The form for a scalar character string would be a*(*)
instead of a(*) (or any of several alternative forms). Look ssimilar,
but the difference is important.

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain
 0
Reply nospam47 (9744) 6/13/2006 4:38:34 PM

Hello,

Richard E Maine wrote:
> Dan Nagle <dannagle@verizon.net> wrote:
>
>> Note that the length of the character variable ( the "*"
>> in the a(*) above) should be consistent with the format used
>> in the internal read.
>
> Note that, unfortunately, the length of the character variable in
> question is 1. The * is for the size of the character array. See my
> other post.  The form for a scalar character string would be a*(*)
> instead of a(*) (or any of several alternative forms). Look ssimilar,
> but the difference is important.

You're right, sorry, I missed that.

But the lengths of the character variable and the length implied
by the format still must be consistent.

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.
 0
Reply dannagle (1019) 6/13/2006 4:53:21 PM

4 Replies
93 Views

Similar Articles

12/10/2013 1:20:09 AM
[PageSpeed]

Similar Artilces:

Test #8
deerffgt

vectorizing #8
for-loop is fast, and much easier to understand and maintain ind = [1 3 8 11 15 20] ; val = [1 2 4 6 10] ; output = zeros(1,ind(end)) ; % pre-allocation!! if ind(1)==1, ind(1)=0 ; end % special case!! for k = 1:numel(ind)-1, output(ind(k)+1:ind(k+1)) = val(k) ; end If you insist, take a look at one of the run-length decoders available on the File Exchange, or write one yourself, like: ind = [1 3 8 11 15 20] ; val = [1 2 4 6 10] ; ind2 = zeros(1,ind(end)) if ind(1)==1, ind(1)=0 ; end % special case!! ind2(ind(1:end-1)+1) = 1 ind2 = cumsum(ind2) output2 = val(ind2

help #8
I want to simulate my design with help of altera netlist .vo format and and timing information .sdo in generated in quartus s/w 6.0 for cyclone devic in ncverilog.I need library information of altera.where can i get it.what are the commands used for that in ncverilog.Please give information on this.Thanking you kumar

CONGRATULATION!!! #8
FROM: THE DIRECTOR EUROPEAN PRIZE AWARD DEPT. REF:EL3/9318/04 BATCH:8/163/EL. Attn:Dear Sir/Madam We are pleased to inform you of the result of the Lottery Winners International programs held on the 15/3/2004. Your e-mail address attached to ticket number :EL-23133 with serial number: EL-123542,batch number: EL-35,lottery ref number: EL-9318 and drew lucky numbers 7-1-8-36-4-22 which consequently won in the 1st category, you have therefore been approved for a lump sum pay out of US\$2,500,000.00 (Two Million, Five Hundred Thousand United States dollars) CONGRATULATIONS!!! Due to mix up of so

Help! #8
Hi! i need to know how can i do a program that print this... ROGRAMA GENERADOR DE SECUENCIA TRIANGULAR DE NUMEROS Cuantos renglones son: 7 1 2 3 2 3 4 5 4 3 4 5 6 7 6 5 4 5 6 7 8 9 8 7 6 5 6 7 8 9 0 1 0 9 8 7 6 7 8 9 0 1 2 3 2 1 0 9 8 7 PLEase if you can help me... thanks. martinmontielr@gmail.com ha scritto: > Hi! i need to know how can i do a program that print this... Hauahuaha, you won't learn if you behave this way! Try, then, maybe, post. martinmontielr@gmail.com wrote: > Hi! i need to know how can i do a program that print this... just for this time, eh! #include <iostream> int main() { char* myMessage = "PROGRAMA GENERADOR DE SECUENCIA TRIANGULAR DE NUMEROS\n\ Cuantos renglones son: 7\n\n\ 1\n\n\n\ 2 3 2\n\n\n\ 3 4 5 4 3\n\n\n\ 4 5 6 7 6 5 4\n\n\n\ 5 6 7 8 9 8 7 6 5\n\n\n\ 6 7 8 9 0 1 0 9 8 7 6\n\n\n\ 7 8 9 0 1 2 3 2 1 0 9 8 7\n\n\ PLEase if you can help me... thanks.\n"; std::cout << myMessage; return 0; } Regards, Zeppe

help #8
) dayNumber = 31 + 28 + 31; else if(month > 4) dayNumber = 31 + 28 + 31; else if(month > 5) dayNumber = 31 + 28 + 31 + 30; else if(month > 6) dayNumber = 31 + 28 + 31 + 30 + 31; else if(month > 7) dayNumber = 31 + 28 + 31 + 30 + 31 + 30; else if(month > 8) dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31; else if(month > 9) dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31; else if(month > 10) dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30; else if(month > 11) dayNumber = 31 + 28... if(month > 6) > dayNumber = 31 + 28 + 31 + 30 + 31; > else if(month > 7) > dayNumber = 31 + 28 + 31 + 30 + 31 + 30; > else if(month > 8) > dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31; > else if(month > 9) > dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31; > else if(month > 10) > dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30; > else if(month > 11) > dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31; > else if(month > 12) > dayNumber

test #8
Test of the News -- Elvira Mi Photo Gallery http://www.personal.able.es/ensoriano

lpc #8
how to calculate inverse LPC On May 29, 2:14=A0pm, "sia " <pallavi8b...@gmail.com> wrote: > how to calculate inverse LPC I get no response from help lpc lookfor lpc What does LPC stand for? What is the corresponding toolbox? Thanks. Greg

Harpoon #8
The 16th NEW Harpoon scenario of the year! Task Force 77 A Harpoon Commanders Edition (HCE) scenario for the Westpac Battleset and the HCE Cold War Database (HCCW-110222 or later). In April 1975, with the North Vietnamese tightening their stranglehold on South Vietnam and their army closing on Saigon, the Americans assembled a large naval force to assist in the evacuation of American civilians and Vietnamese refugees deemed to be at risk when the entire country eventually fell to the NVA. In this scenario, the Soviets launch a much more overt effort to support the North in the c

Query #8
;###-#####", "315 ###-####". > Any ideas on what I am doing wrong? > > Access Newbie :( > Thomas Where Left([Phone],3) = "315" or left([Phone],5) = "(315)" should take care of entries like (313) 123-4567 or 313 123-4567 If you also store phone numbers without the area code, you would also want to restrict the search to only records where the length of the Phone data was more than 8 characters: Where Len([Phone])>8 and (Left([Phone],3) = "315" Or left([Phone],5) = "(315)") -- Fred Please respond only to this newsgroup. I