Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Cast from double to string

oglok
Beginner
1,716 Views
Hello everyone,

This is the first time I write in this forum, but I read many threads very very useful.

I am converting all my programs from Compaq compiler to Intel compiler, and in this case, I have a file with some data, and I want to replace some information.

My problem is that I have a number (double) and I want to make a cast to character. My code is this:

double precision, dimension (dimdata) :: datavector
character ( len = 20 ) :: cast, castcopy

write(castcopy, '(1pg12.7)') datavector(numaccess)

The last line make the program crashes. The whole project compile perfectly, but when it is running and it arrives to this line, it crashes (and the console window closes). I checked that the error is in this line.

Any suggestion??

Thanks!!!
0 Kudos
4 Replies
mecej4
Honored Contributor III
1,716 Views
What is the problem?

[fortran]program tcast
integer, parameter :: dimdata=2
double precision, dimension (dimdata) :: datavector = [1d1,2d2]
character ( len = 20 ) :: castcopy
integer :: numaccess

do numaccess=1,dimdata
  write(castcopy, '(1pg12.7)') datavector(numaccess)
  print *,numaccess,datavector(numaccess),castcopy
end do
end program tcast
[/fortran]
Compile and run:

[bash]s:LANG>ifort /traceback /fpe:0 cast1.f90
Intel Visual Fortran Compiler Professional for applications running on IA-32, Version 11.1    Build 2010120
1 Package ID: w_cprof_p_11.1.070
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

Microsoft  Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:cast1.exe
-subsystem:console
-incremental:no
cast1.obj

s:LANG>cast1
           1   10.0000000000000      10.00000
           2   200.000000000000      200.0000
[/bash]
0 Kudos
Les_Neilson
Valued Contributor II
1,716 Views
What is the value of numaccess ?
Did you get or see an error message? If so what was it?
You shouldbuild your application with debug run time options on- for example /check:all
(or at least check array bounds and uninitialised variables)

Les
0 Kudos
oglok
Beginner
1,716 Views
I'm sorry guys, that line was wrong, but not for the casting....It was a mistake of array's dimension!!

Thanks anyway.

BTW, could you any explain to me why this format to make that casting?? '1pg12.7' I found it somewhere....but I don't get it...

0 Kudos
Lars_Jakobsen
Beginner
1,716 Views
Take a look at "Format Specifications" in the fortran help file

In my installation is is here
ms-help://MS.VSCC.v90/intel.forprodocs/intel.fprocompilerdocs/main_for/lref_for/source_files/pghfrmio.htm

regards

Lars
0 Kudos
Reply