debugging an error

Everything related to the preinstalled test cases in COHERENS. Additionally, you can find here the necessary files to setup a test case.If you have developed a new test case and you want to share it with other users, feel free to post a new thread.

Moderator:Katrijn

Post Reply
Sou
Posts:51
Joined:Wed Sep 03, 2014 7:46 pm
Full name:Soudeh Afsharian
debugging an error

Post by Sou » Fri Jul 24, 2015 5:26 am

Hi,
anyone knows why this error shows up with this piece of code? The error shows up at last line of the run.
I found the problem is with :
surdata(i,j,1) = uwindatu_cst; surdata(i,j,2) = vwindatv_cst when I use i,j , otherwise the program runs normally.


My Code:


!========================================================================

SUBROUTINE usrdef_surface_data(iddesc,ifil,ciodatetime,surdata,n1dat,n2dat,&
& novars)
!************************************************************************
!
! *usrdef_surface_data* Define surface input data
!
! Author - Patrick Luyten
!
! Version - @(COHERENS)Usrdef_Surface_Data.f90 V2.0
!
! Description - test case csnsp
!
! Reference -
!
! Calling program - define_surface_data
!
! Module calls - convert_date, open_filepars
!
!************************************************************************
!
USE iopars
USE syspars
USE timepars
USE inout_routines, ONLY: open_filepars
USE time_routines, ONLY: convert_date, log_timer_in, log_timer_out

IMPLICIT NONE

!
!*Arguments
!
CHARACTER (LEN=lentime), INTENT(INOUT) :: ciodatetime
INTEGER, INTENT(IN) :: iddesc, ifil, novars, n1dat, n2dat
REAL, INTENT(INOUT), DIMENSION(n1dat,n2dat,novars) :: surdata

!
! Name Type Purpose
!------------------------------------------------------------------------------
!*iddesc* INTEGER Data file id
!*ifil* INTEGER No. of data file
!*ciodatetime* CHAR Date/time in data file
!*surdata* REAL Data array
!*n1dat* INTEGER X-dimension of data array
!*n2dat* INTEGER Y-dimension of data array
!*novars* INTEGER Number of data parameters
!
!------------------------------------------------------------------------------
!
!*Local variables
!
INTEGER, SAVE :: iunit, i, j, ncT, nrT,nc, nr, HT
REAL :: ct, DT, z0, zr, delxdat, delydat,c1, kk, Xm, XT, YT,thetacart0 ,thetacart,&
wind, wdir, XX,YY, mdelutu0, mdelutu, Rw, gxcoordglb,gycoordglb, airtemp_cst, cloud_cover_cst, relhum_cst,&
uwindatu_cst, vwindatv_cst
INTEGER, DIMENSION(7) :: iodatetime


procname(pglev+1) = 'usrdef_surface_data'
CALL log_timer_in()

!
!1. Open file
!------------
!

IF (modfiles(io_metsur,1,1)%iostat.EQ.0) THEN
CALL open_filepars(modfiles(io_metsur,1,1))
iunit = modfiles(io_metsur,1,1)%iunit
modfiles(io_metsur,1,1)%iostat = 1
READ (iunit,*)
GOTO 1000
ENDIF

!
!2. Define and Read data
!------------
!
iodatetime(1) = IStartDateTime(1);
iodatetime(6:7) = 0
READ (iunit,*,END=99) iodatetime(1:5), wind, wdir, airtemp_cst, relhum_cst, cloud_cover_cst
!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>SOUDEH>>>>>>>>>>>>>>>>>>>>>>>>>>
!WRITE (*,*)iodatetime(1:5),wind, wdir, airtemp_cst, relhum_cst, cloud_cover_cst
!<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
ciodatetime = convert_date(iodatetime)


ct=0.50
HT = 80
DT = 100.00
z0 = 0.001
zr = 10.00
ncT = 5
nrT = 10
nc = 41
nr = 41
delxdat = 100
delydat = 100

c1 = 1- sqrt(1-ct)
kk = 0.5/ (alog(HT/z0))
XT = delxdat * ncT
YT = delydat * nrT





thetacart0 = 270 - wdir
thetacart = thetacart0 * degtorad

Xm = ((HT-zr) - 0.5*DT)/ kk

Do i=1,nc

Do j = 1, nr

XX = delxdat * i;
YY = delydat * j;

gxcoordglb = ((XX - XT) * COS( thetacart)) + ((YY - YT) * SIN( thetacart));
gycoordglb = ((XT - XX) * SIN( thetacart)) + ((YY - YT) * COS( thetacart));




mdelutu0 = 1.0
Rw = (DT/2) + (kk * gxcoordglb)


mdelutu= 0.0
IF ((gxcoordglb .GT. Xm) .AND. (gycoordglb**2 + (HT - zr)**2) .LE. Rw**2) THEN
mdelutu = mdelutu0
END IF



uwindatu_cst = (wind * COS(thetacart))*(1 - mdelutu)
vwindatv_cst = (wind * SIN(thetacart))*(1 - mdelutu)


!WRITE (*,*)iodatetime(1:5), x,y,uwindatu_cst

surdata(i,j,1) = uwindatu_cst;
surdata(i,j,2) = vwindatv_cst
END DO
END DO


surdata(:,:,3) = airtemp_cst;
surdata(:,:,4) = relhum_cst
surdata(:,:,5) = cloud_cover_cst


1000 CALL log_timer_out()


RETURN

!
!3. Set end of file condition
!----------------------------
!

99 modfiles(io_metsur,1,1)%iostat = 3
CALL log_timer_out()

RETURN

!9001 FORMAT(4I2,5(2X,E11.4))

END SUBROUTINE usrdef_surface_data



The Error:
*** glibc detected *** ./coherens: free(): invalid next size (fast): 0x0000000001c79590 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3f19875e66]
/lib64/libc.so.6[0x3f198789b3]
./coherens[0x7e5c7d]
./coherens[0x8e2687]
./coherens[0x8e275a]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x3f1981ed5d]
./coherens[0x402439]
======= Memory map: ========
00400000-0099e000 r-xp 00000000 fd:02 126484487 /home/soudeh83/mytest/3D/whone/coherens
00b9d000-00b9f000 rw-p 0059d000 fd:02 126484487 /home/soudeh83/mytest/3D/whone/coherens
00b9f000-00c67000 rw-p 00000000 00:00 0
01bfd000-01dba000 rw-p 00000000 00:00 0 [heap]
3f19400000-3f19420000 r-xp 00000000 fd:00 1310803 /lib64/ld-2.12.so
3f1961f000-3f19620000 r--p 0001f000 fd:00 1310803 /lib64/ld-2.12.so
3f19620000-3f19621000 rw-p 00020000 fd:00 1310803 /lib64/ld-2.12.so
3f19621000-3f19622000 rw-p 00000000 00:00 0
3f19800000-3f1998a000 r-xp 00000000 fd:00 1318574 /lib64/libc-2.12.so
3f1998a000-3f19b8a000 ---p 0018a000 fd:00 1318574 /lib64/libc-2.12.so
3f19b8a000-3f19b8e000 r--p 0018a000 fd:00 1318574 /lib64/libc-2.12.so
3f19b8e000-3f19b8f000 rw-p 0018e000 fd:00 1318574 /lib64/libc-2.12.so
3f19b8f000-3f19b94000 rw-p 00000000 00:00 0
3f1a800000-3f1a883000 r-xp 00000000 fd:00 1318586 /lib64/libm-2.12.so
3f1a883000-3f1aa82000 ---p 00083000 fd:00 1318586 /lib64/libm-2.12.so
3f1aa82000-3f1aa83000 r--p 00082000 fd:00 1318586 /lib64/libm-2.12.so
3f1aa83000-3f1aa84000 rw-p 00083000 fd:00 1318586 /lib64/libm-2.12.so
3f23c00000-3f23c16000 r-xp 00000000 fd:00 1318620 /lib64/libgcc_s-4.4.7-20120601.so.1
3f23c16000-3f23e15000 ---p 00016000 fd:00 1318620 /lib64/libgcc_s-4.4.7-20120601.so.1
3f23e15000-3f23e16000 rw-p 00015000 fd:00 1318620 /lib64/libgcc_s-4.4.7-20120601.so.1
7f3a23db1000-7f3a24663000 rw-p 00000000 00:00 0
7f3a24692000-7f3a24696000 rw-p 00000000 00:00 0
7f3a24696000-7f3a24786000 r-xp 00000000 fd:00 660873 /usr/lib64/libgfortran.so.3.0.0
7f3a24786000-7f3a24985000 ---p 000f0000 fd:00 660873 /usr/lib64/libgfortran.so.3.0.0
7f3a24985000-7f3a24987000 rw-p 000ef000 fd:00 660873 /usr/lib64/libgfortran.so.3.0.0
7f3a24987000-7f3a24988000 rw-p 00000000 00:00 0
7f3a249a2000-7f3a249a3000 rw-p 00000000 00:00 0
7ffeccb66000-7ffeccb80000 rw-p 00000000 00:00 0 [stack]
7ffeccbe2000-7ffeccbe3000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
./Run: line 4: 6858 Aborted (core dumped) ./coherens





Thanx,
Sue

Katrijn
Posts:86
Joined:Fri Nov 29, 2013 3:04 pm
Full name:Katrijn Baetens

Re: debugging an error

Post by Katrijn » Fri Jul 24, 2015 9:49 am

Hi Sou,

You can check the dimensions of your surface grid by 'print *, size(surdata,1), size(surdata,2).

By default (nhtype = 0 in Usrdef_Model) the surface grid has 1 single grid point, if you want it to be equal to the model grid then set nhtype = 4

Good luck

Sou
Posts:51
Joined:Wed Sep 03, 2014 7:46 pm
Full name:Soudeh Afsharian

Re: debugging an error

Post by Sou » Fri Jul 24, 2015 10:39 pm

Dear Katrijn,
It showsthat the size for both is 1.
I set iopt_grid_htype = 4 but, now it shows this error in errlogA
Invalid value for integer parameter iopt_grid_htype: 4
Must be between: 1 and 3
A total of 1 errors occurred in check_mod_filepars
Error type 7 : Invalid initial values for model parameters or arrays
PROGRAM TERMINATED ABNORMALLY

Katrijn
Posts:86
Joined:Fri Nov 29, 2013 3:04 pm
Full name:Katrijn Baetens

Re: debugging an error

Post by Katrijn » Mon Jul 27, 2015 8:15 am

Hi Sou,

iopt_grid_htype is the grid of the model, which is different than the surface grid. If you want the two to be the same you should enter nhtype = 4 (and not iopt_grid_htyp = 4)

Good luck,

Katrijn

Post Reply