- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
I have two question about "rand."
(1) Why the code "40+int(rand(0)*2)+1" shows 67? I expect it shows 41 or 42.
(2) Why I need modify the code as below to get my results (i.g. 41 or 42)?
use IFPORT
idfile = 40+int(rand()*2+1)
Thanks all experts.
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would recommend the use of the standard intrinsic RANDOM_NUMBER rather than the non-standard RAND, but it is a subroutine and not a function.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I get 41 or 42. Can you show a complete program that gets the 67 result?
If I had to guess, it would be that you have an IMPLICIT typing for the letter R that is not REAL(4).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
You are right. There are several subroutines show r as a real number. For example:
real fi (ilg), evap (ilg), r (ilg), zpond (ilg), dt (ilg)
I post several codes that I think they might related for your diagnosing.
program runclass
:
!-----pre-running meteorological data
open(unit=41,file="Met_2003.dat")
open(unit=42,file="Met_2004.dat")
:
!-----randomly choose a pre-run meteorological file in the begining of the year
idfile = 40+int(rand(0)*2)+1 !open file id = 41 or 42
rewind(unit=idfile) !rewinding the file to the first line
print *,iyear,idfile !for checking purpose
endif
read(idfile,*,end=1000) xyear,xday,ihour,imin,fsdown,fdlgrd(i), &
& pregrd(i),tagrd(i),uvgrd(i),presgrd(i),qagrd(i)
else
!-----a CR met data
read(51,*,end=999) iyear,iday,ihour,imin,fsdown,fdlgrd(i), &
& pregrd(i),tagrd(i),uvgrd(i),presgrd(i),qagrd(i)
endif
I wonder my new modification which is using "use IFPORT"and "idfile = 40+int(rand()*2+1)" will influence the whole calculations, becuase I had some error message showed as below.
kuo-macbook-pro:src cks$ ./runclass
2002 41
starting year .... 2002
1st soil layer energy balance error @ 2002
1 0 0
soil water balance error @ 2002 1
0 0
snow layer energy balance error @ 2002 8
14 0
snow layer energy balance error @ 2002 35
0 0
snow layer energy balance error @ 2002 63
15 0
ground water balance error @ 2002 63
15 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ALWAYS use "IMPLICIT NONE", except for small "jiffy" code, and also use "-warn declarations" to catch places where you forgot the "IMPLICIT NONE".
If you want to be extra strict, you can set $IFORTCFG to something like ~/.ifortrc, then put "-warn declarations" in that file to always emit missing declaration errors. These are only warnings, so you can still write jiffies with implicit variables if you want to, and just ignore the warnings.
Joe Krahn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi steve,
Because it contains several thouthads lines, here is a part of the mian program.
Please have a look at this attachment: main.F90
Thanks for your kind advise. Please let me know if I need to post more information for diagnosing.
Thank you.
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You didn't correctly attach the file. Go back into Add Files, select the file you uploaded and click "Add as attachment".
What you did was get the URL of the link, which doesn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please provide a short (10 line) program that demonstrates the 67 result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I upload two files: rand_test.F90 and Makefile
It seems my homemade Makefile causes the problems. Can you please have a look? I have already try different flaging in the Makefile, I have no idea about which Flaging doable. Please advise me.
Thanks,
Michael
kuo-macbook-pro:Desktop cks$ ifort -O0 -real_size 64 -integer_size 64 -heap-arrays rand_test.F90
kuo-macbook-pro:Desktop cks$ ./a.out
-9223372036854775768
41
41
41
41
41
41
41
41
41
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are there the other functions particularly I need to concern when I using the -real_size 64? How to you think about my Makefile? Any suggestions?
Thanks,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would recommend the use of the standard intrinsic RANDOM_NUMBER rather than the non-standard RAND, but it is a subroutine and not a function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Michael
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page