string formatting from date/time wave

hi,

I built a function to format a string (gdasfile_str) following values in a date/time wave. Code is hereinafter. What is strange is that the last if statement actually doesn't work properly, and cannot figure out why... It is mainly for determining the week number in a month, and when going from 01/02/2015 (as a example) to 01/03/2015, the 7 first days are good (week="w1"), but then week="w2" for all other values... Experiment is also included.

Any help would be great!!
Thanks a lot
J-E

#pragma rtGlobals=3     // Use modern global access method and strict wave access.


Function GDASFile(DateWave)
    wave DateWave
    variable numrows=numpnts(DateWave)
    variable i
    variable dt,day, month, year, dayOfWeek,hour
    String shortDateStr,year_str,month_str,week,gdasfile_str
    for (i=0;i<numrows;i+=1)
        dt=DateWave[i]
        shortDateStr = Secs2Date(dt, -1)
        sscanf shortDateStr, "%d/%d/%d (%d)", day, month, year, dayOfWeek
        Variable time = mod(dt, 24*60*60)
        hour=trunc(time/(60*60))
        year_str=num2str(year)[2,3]
       
        if (month==1)
            month_str="jan"
        elseif (month==2)
            month_str="feb"
        elseif (month==3)
            month_str="mar"
        elseif (month==4)
            month_str="apr"
        elseif (month==5)
            month_str="may"
        elseif (month==6)
            month_str="jun"
        elseif (month==7)
            month_str="jul"
        elseif (month==8)
            month_str="aug"
        elseif (month==9)
            month_str="sep"
        elseif (month==10)
            month_str="oct"
        elseif (month==11)
            month_str="nov"
        elseif (month==12)
            month_str="dec"
        endif
       
        if (day<=7)
            week="w1"
        elseif (day>=8 || day <=14)
            week="w2"
        elseif (day>=15 || day <=21)
            week="w3"
        elseif (day>=22 || day <=28)
            week="w4"
        elseif (day>=29)
            week="w5"  
        endif
       
        gdasfile_str="gdas1"+"."+month_str+year_str+"."+week
        print day
        print gdasfile_str
       
    endfor
   
end function
Hysplit.pxp (55.11 KB)
Hi J-E,

it should be (day>=8 && day <=14) and also && instead of || in the following elseif conditions.

Thomas
nevermind, thought it was a more tricky mistake, but I actually used OR statement instead of AND....
sorry for "trolling", this post can be deleted.