[ncl-talk] Calculating date after/before specified number of days of given date

Dipti Hingmire diptikalyanshetti at gmail.com
Wed May 23 01:46:54 MDT 2018


Thanks Walter. It worked.



Thanks and Regards,
Dipti

Thanks and Regards,
Dipti


2018-05-23 12:46 GMT+05:30 Walter Kolczynski <walter.kolczynski at noaa.gov>:

> Dipti,
>
> Convert the year-month-day to a single calendar unit with cd_inv_calendar
> <http://www.ncl.ucar.edu/Document/Functions/Built-in/cd_inv_calendar.shtml>
> (I usually use Unix epoch-seconds, but NCL is flexible), do the math in
> that space, and then use that to make a string (using cd_string
> <http://www.ncl.ucar.edu/Document/Functions/User_contributed/cd_string.shtml>)
> or recover the year-month-day as separate variables using cd_calendar
> <http://www.ncl.ucar.edu/Document/Functions/Built-in/cd_calendar.shtml>:
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/cd_string.ncl"
>
> start_year    = 2018
> start_month   = 1
> start_day     = 5
> delta_days    = -7
>
> start_time    = cd_inv_calendar( start_year, start_month, start_day, 0, 0,
> 0, "seconds since 1970-1-1 00:00:00", 0 )
> delta         = delta_days * 86400             ; Convert delta to seconds,
> since our calendar units are seconds
> end_time      = start_time + delta
> copy_VarAtts(start_time, end_time)             ; Copy calendar information
> to end_time
> end_string    = cd_string(end_time, "%Y-%N-%D")
> end_time_UT   = cd_calendar(end_time, -5)      ; -5 gives integer values
> instead of float
> end_year      = end_time_UT(:,0)
> end_month     = end_time_UT(:,1)
> end_day       = end_time_UT(:,2)
>
> print(end_string)
> print(end_year)
> print(end_month)
> print(end_day)
>
> **** OUTPUT ****
>
> Variable: end_string
> Type: string
> Total Size: 8 bytes
>             1 values
> Number of Dimensions: 1
> Dimensions and sizes:   [1]
> Coordinates:
> Number Of Attributes: 1
>   _FillValue :  missing
> (0)     2017-12-29
>
> Variable: end_year
> Type: integer
> Total Size: 4 bytes
>             1 values
> Number of Dimensions: 1
> Dimensions and sizes:   [1]
> Coordinates:
> Number Of Attributes: 1
>   calendar :    standard
> (0)     2017
>
> Variable: end_month
> Type: integer
> Total Size: 4 bytes
>             1 values
> Number of Dimensions: 1
> Dimensions and sizes:   [1]
> Coordinates:
> Number Of Attributes: 1
>   calendar :    standard
> (0)     12
>
> Variable: end_day
> Type: integer
> Total Size: 4 bytes
>             1 values
> Number of Dimensions: 1
> Dimensions and sizes:   [1]
> Coordinates:
> Number Of Attributes: 1
>   calendar :    standard
> (0)     29
>
> - Walter
>
> On 2018-05-23 02:44, Dipti Hingmire wrote:
>
> Dear All,
>
> I wan to plot lead lag composite plots of a set of events/dates.
>
> Is there any inbuilt function in ncl which will provide me date
> after/before specified number of days of given date?
>
>
> e.g. If i give 2018-01-05 as input date and I want the date 7 days before
> I should get 2017-12-29
>
> Thanks and Regards,
> Dipti
>
>
> _______________________________________________
> ncl-talk mailing listncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
>
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=icon> Virus-free.
> www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=link>
> <#m_-5719813883415627176_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180523/1f414f60/attachment.html>


More information about the ncl-talk mailing list