Re: converting between YYYYMMDD and Julian date and back

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Mon, 09 Mar 2009 16:28:04 -0600

Joe,

"new_day" is missing the special units attribute for time. This is
a side effect of the way that you are creating this variable in the
first pass of the loop. Add this line just before the top of the
loop, and ut_calendar will work correctly:

   new_day = jul_day ; init data type and units attribute

Dave Allured
CU/CIRES Climate Diagnostics Center (CDC)
http://cires.colorado.edu/science/centers/cdc/
NOAA/ESRL/PSD, Climate Analysis Branch (CAB)
http://www.cdc.noaa.gov/psd1/

Joe Grim wrote:
> Hi,
>
> Would you be able to help me with an NCL problem?
>
> I've been trying to figure out how to read in files using NCL for 12
> consecutive days. The files have the date in their name following the
> YYYYMMDD format. Since I need to make sure it works crossing months and
> years, I know I need to convert it into Julian days and back to the
> YYYYMMDD format. I have a simplified version of my program below,
> showing the steps I used. Everything works right until I get to the
> loop. "new_day" counts down just like I want it to, but when I ask it
> to print out the dates within the loop, I get -999 (I assume "missing")
> where I expect to see the date in YYYYMMDD format. Do you know how I
> can get the date to come out in YYYYMMDD format?
>
> Thank you very much!
>
> Joe Grim
> Associate Scientist II
> RAL/NCAR
>
> ---code starts below---
>
> begin
>
> ; Loop through past 12 days of data to get 12-day composite
> num_days=12
> day=20090104
> final_day=stringtoint(day)
> year=final_day/10000
> month=(final_day-year*10000)/100
> dy=final_day-year*10000-month*100
> jul_day=ut_inv_calendar(year,month,dy,0,0,0,"days after 2000-01-01
> 00:00:00",0)
>
> print(sprinti("%4.0i",year)+"-"+sprinti("%2.2i",month)+"-"+sprinti("%2.2i",dy))
> print(jul_day)
> print(ut_calendar(jul_day,-2))
> print("BEGIN LOOP")
> do comp_ctr=0,num_days-1
> new_day=jul_day-comp_ctr
> print(new_day)
> print(ut_calendar(new_day,-2))
> ; Here is where I normally read in the file using the date
> (YYYYMMDD) in the title
> end do
> end
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 09 2009 - 16:28:04 MDT

This archive was generated by hypermail 2.2.0 : Mon Mar 09 2009 - 21:47:10 MDT