Problem in con2stn?

Post any defects you find in the HYSPLIT software here. The HYSPLIT Developers carefully monitor this list and will work diligently to repair any reported problems. When posting a bug report, please specify both the HYSPLIT version and operating system you are using.
Post Reply
Eslinger
Posts: 2
Joined: January 20th, 2014, 8:54 pm
Registered HYSPLIT User: Yes

Problem in con2stn?

Post by Eslinger »

I recently had a problem with abnormal program termination while running the utility program con2stn on a Linux system for a linear interpolation extraction. I don't get the same problem with the nearest neighbor extraction. I think I have tracked the problem to a place in the source code. I have copied the relevant block of code below. The equations for CTOP and CBOT use the variable CSUM. The indices II and JJ are checked for array bounds in the first line of code I have copied, but the equations for CTOP and CBOT reference CSUM(II+1) and CSUM(JJ+1), which have the potential for being out of array bounds even if the first check is satisfied.

IF(II.GE.1.AND.II.LT.NLON.AND.JJ.GE.1.AND.JJ.LE.NLAT)THEN
IF(LINEAR.EQ.0)THEN
! nearest neighbor concentration extraction
II=NINT(XI)
JJ=NINT(YJ)
CONC(KS)=CSUM(II,JJ)*CFACT
ELSE
! linear interpolation extraction
XF=XI-II
YF=YJ-JJ
CTOP=(CSUM(II+1,JJ+1)-CSUM(II,JJ+1))*XF+CSUM(II,JJ+1)
CBOT=(CSUM(II+1,JJ )-CSUM(II,JJ ))*XF+CSUM(II,JJ)
CONC(KS)=((CTOP-CBOT)*YF+CBOT)*CFACT
END IF
ELSE
! at edge or outside of grid
CONC(KS)=-1.0
END IF
barbara.stunder
Posts: 451
Joined: November 9th, 2012, 4:23 pm
Registered HYSPLIT User: Yes

Re: Problem in con2stn?

Post by barbara.stunder »

Thanks for tracking this down. Go ahead and make the fix and test it. If you send the fix it to us, we can include it in the next version.
Eslinger
Posts: 2
Joined: January 20th, 2014, 8:54 pm
Registered HYSPLIT User: Yes

Re: Problem in con2stn?

Post by Eslinger »

I have included below an originakl code block and a suggested revised code block in con2stn.f for the Linux version

Original code block in con2stn.f in lines 386 through 424
DO KS=1,NSTA

! longitude correction to avoid dateline problems
IF(CLON.GE.0.0.AND.SLON(KS).LT.0.0)THEN
GLON=SLON(KS)+360.0
ELSEIF((DLON*NLON.GT.180.0).AND.(SLON(KS)-CLON.LE.0.0))THEN
GLON=SLON(KS)+360.0
ELSE
GLON=SLON(KS)
END IF

! convert to grid point
XI=(GLON -CLON)/DLON+1.0
YJ=(SLAT(KS)-CLAT)/DLAT+1.0
II=INT(XI)
JJ=INT(YJ)

IF(II.GE.1.AND.II.LT.NLON.AND.JJ.GE.1.AND.JJ.LE.NLAT)THEN
IF(LINEAR.EQ.0)THEN
! nearest neighbor concentration extraction
II=NINT(XI)
JJ=NINT(YJ)
CONC(KS)=CSUM(II,JJ)*CFACT
ELSE
! linear interpolation extraction
XF=XI-II
YF=YJ-JJ
CTOP=(CSUM(II+1,JJ+1)-CSUM(II,JJ+1))*XF+CSUM(II,JJ+1)
CBOT=(CSUM(II+1,JJ )-CSUM(II,JJ ))*XF+CSUM(II,JJ)
CONC(KS)=((CTOP-CBOT)*YF+CBOT)*CFACT
END IF

ELSE
! at edge or outside of grid
CONC(KS)=-1.0
END IF

! station loop
END DO


Revised code block. The lines down through YJ=(SLAT(KS)-CLAT)/DLAT+1.0 are not modified.
The index check is different on the upper end (NLAT or NLON) for the different
types of concentration extraction. Thus, this code block reverses the order of the
interpolation type check and the index check. It also moves the
INT(II) and NINT(II) types of conversion next to where the indices are used

DO KS=1,NSTA

! longitude correction to avoid dateline problems
IF(CLON.GE.0.0.AND.SLON(KS).LT.0.0)THEN
GLON=SLON(KS)+360.0
ELSEIF((DLON*NLON.GT.180.0).AND.(SLON(KS)-CLON.LE.0.0))THEN
GLON=SLON(KS)+360.0
ELSE
GLON=SLON(KS)
END IF

! convert to grid point
XI=(GLON -CLON)/DLON+1.0
YJ=(SLAT(KS)-CLAT)/DLAT+1.0

IF(LINEAR.EQ.0)THEN
! nearest neighbor concentration extraction
II=NINT(XI)
JJ=NINT(YJ)
IF(II.GE.1.AND.II.LE.NLON.AND.JJ.GE.1.AND.JJ.LE.NLAT)THEN
CONC(KS)=CSUM(II,JJ)*CFACT
ELSE
! at edge or outside of grid
CONC(KS)=-1.0
END IF
ELSE
! linear interpolation concentration extraction
II=INT(XI)
JJ=INT(YJ)
XF=XI-II
YF=YJ-JJ
IF(II.GE.1.AND.II.LT.NLON.AND.JJ.GE.1.AND.JJ.LT.NLAT)THEN
CTOP=(CSUM(II+1,JJ+1)-CSUM(II,JJ+1))*XF+CSUM(II,JJ+1)
CBOT=(CSUM(II+1,JJ )-CSUM(II,JJ ))*XF+CSUM(II,JJ)
CONC(KS)=((CTOP-CBOT)*YF+CBOT)*CFACT
ELSE
! at edge or outside of grid
CONC(KS)=-1.0
END IF
END IF

! station loop
END DO
barbara.stunder
Posts: 451
Joined: November 9th, 2012, 4:23 pm
Registered HYSPLIT User: Yes

Re: Problem in con2stn?

Post by barbara.stunder »

Thank you for the revised code. It will be included in the next update.
Post Reply

Return to “Bugs”