[ncl-talk] set_date_time [SEC=UNCLASSIFIED]

Mary Haley haley at ucar.edu
Fri Oct 6 13:51:25 MDT 2017


Kunal,

Please create a new email thread when you have a new question, otherwise
you forcing someone to continue answering a stream of questions.

Since you are using CDO to create the file, you could ask the CDO
developers about what happened to the coordinates attribute:

https://code.mpimet.mpg.de/projects/cdo/boards

One thing I want to point out: these two lines are special for NCL plotting
ONLY, and should not be used when writing "var" to the file:

        var at lat2d = lat
        var at lon2d = lon

Please remove the above two lines, rerun the script and try the CDO
conversion again. Maybe that will fix things with CDO?

--Mary




On Fri, Oct 6, 2017 at 11:12 AM, Kunal Bali <kunal.bali9 at gmail.com> wrote:

> Dear Griffith and Guido Sir,
>
> I am able to create the date correctly now. But after creating the date, I
> am facing one problem with my netcdf file.
>
> After creating the date using shell script, the lat lon coordinates
> disappeared (please see the attached figure) from .nc file.
> MAIACTAOT.h00v02.20010040635.nc (after conversion hdf to netcdf)
> reMAIACTAOT.h00v02.20010040635.nc (after creating the date)
>
> I need to create
> How to fix it. Any suggestion ?
>
> I convrt hdf to netcdf so that I can handle netcdf by CDO. That is much
> easy for me to work on it.
>
> I have attached the conversion ncl script (netcdf.ncl), shell script
> (set_time.sh).
>
>
> Regards
> Kunal Bali
>
>
>
>
>
>
> On Fri, Oct 6, 2017 at 11:02 AM, Kunal Bali <kunal.bali9 at gmail.com> wrote:
>
>> Thank you so much, Griffith and  Guido Cioni for this valuable
>> suggestion.
>> It worked.
>>
>> regards
>> Kunal Bali
>>
>>
>>
>>
>> On Fri, Oct 6, 2017 at 3:16 AM, Griffith Young <griffith.young at bom.gov.au
>> > wrote:
>>
>>> Hello Kunal,
>>>
>>>                 “creating wrong date as the files are of December
>>> month, but it is generating January month date also. I don't know why.”
>>>
>>>
>>>
>>>                 Your script was fine.  You just needed to subtract 1
>>> from your Julian date.  So you math was wrong…
>>>
>>>
>>>
>>>                 For example …2000001… would become “001 days
>>> 2000-01-01”, which is 2000-01-02.
>>>
>>>
>>>
>>>                 Guido’s (excellent) script could also be simplified to
>>> return the whole date at once.
>>>
>>>
>>>
>>>                 yyyymmdd=`date -d "${year}-01-01 +${day_of_year} days
>>> -1 day" "+%Y%m%d"`
>>>
>>>
>>>
>>>                 If you are using bash, I would recommend using $(command)
>>> instead of `command` as it is clearer where the boundaries are.  (If
>>> that makes sense.  Backticks can lead to strange behaviours that are
>>> hard to spot when sharing code.)
>>>
>>>
>>>
>>>                 I find this easier to read:
>>>
>>>                 *             yyyymmdd=$(date -d "${year}-01-01 +${day_of_year}
>>> days -1 day" "+%Y%m%d")
>>>
>>>
>>>
>>>                 I hope I have answered your “I don't know why” question.
>>>
>>>
>>>
>>> Regards,
>>>
>>>                 Griff.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *From:* ncl-talk [mailto:ncl-talk-bounces at ucar.edu] *On Behalf Of *Guido
>>> Cioni
>>> *Sent:* Friday, 6 October 2017 7:46 AM
>>> *To:* Marston Johnston
>>> *Cc:* ncl-talk
>>> *Subject:* Re: [ncl-talk] set_date_time
>>>
>>>
>>>
>>> I had to do something similar last week. Converting from hdf to netcdf
>>> and then merge into a single file with time information. It was modis
>>> data. I don't have time to explain the script so I'm copying here hoping
>>> that it could help.
>>>
>>>
>>>
>>> for f in *.nc; do
>>>
>>>     year=${f:9:4}
>>>
>>>     day_of_year=${f:13:3}
>>>
>>>     month=`date -d "${year}-01-01 +${day_of_year} days -1 day" "+%m"`
>>>
>>>     day=`date -d "${year}-01-01 +${day_of_year} days -1 day" "+%d"`
>>>
>>>     echo ${year}-${month}-${day}
>>>
>>>     cdo -b F64 setdate,${year}-${month}-${day} ${f} ${f%.nc}_2.nc
>>>
>>> done
>>>
>>>
>>>
>>>
>>>
>>> Cheers
>>>
>>>
>>>
>>> Il 5 ott 2017 9:56 PM, "Marston Johnston" <shejo284 at gmail.com> ha
>>> scritto:
>>>
>>> It seems like you choose a fairly complicated way to solve the problem.
>>>
>>> May I suggest reading in the MAIACTAOT.h00v02.***.nc files in
>>> chronological order and then writing new netcdf files in ncl where you
>>> can create a time array with the correct dtg.
>>>
>>> It’s fairly quick and easy in ncl.
>>>
>>> I’ve had such problems before and found it easiest to with the above
>>> method.
>>>
>>>
>>>
>>> Hope this helps,
>>>
>>> /M
>>>
>>>
>>>
>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>
>>> Marston S. Ward, PhD
>>>
>>> Department of Earth Sciences
>>>
>>> University of Gothenburg, Sweden
>>>
>>> Email: marston.johnston at gu.se
>>>
>>> SkypeID: marston.johnston
>>>
>>> Phone: +46-31-7864901 <+46%2031%20786%2049%2001>
>>>
>>> Only the fruitful thing is true!
>>>
>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>
>>>
>>>
>>>
>>>
>>> *From: *ncl-talk <ncl-talk-bounces at ucar.edu> on behalf of Kunal Bali <
>>> kunal.bali9 at gmail.com>
>>> *Date: *Thursday, 5 October 2017 at 20:40
>>> *To: *"ncl-talk at ucar.edu" <ncl-talk at ucar.edu>
>>> *Subject: *[ncl-talk] set_date_time
>>>
>>>
>>>
>>> Dear NCL users,
>>>
>>>
>>>
>>> I have one question regarding date-time setting from filename. This
>>> question is not actually related to NCL, sorry in advance.
>>>
>>>
>>>
>>> I have 4 .nc files named given below. The time is not created in these
>>> files during conversion from hdf to netcdf in NCL.
>>>
>>>
>>>
>>> MAIACTAOT.h00v02.*20003640715*.nc   --> 2000=year, 364=day, 07=hr,
>>> 15=min
>>>
>>> MAIACTAOT.h00v02.20003650620.nc
>>>
>>> MAIACTAOT.h00v02.20003660525.nc
>>>
>>> MAIACTAOT.h00v02.20003660700.nc
>>>
>>>
>>>
>>> So, I did try to create the date-time with shell scripting (given below)
>>>
>>> but it is creating wrong date as the files are of December month, but
>>> it is generating January month date also. I don't know why.
>>>
>>>
>>>
>>> *2000-01-01 05:25:00*
>>>
>>> *2000-01-01 07:00:00*
>>>
>>> 2000-12-30 07:15:00
>>>
>>> 2000-12-31 06:20:00
>>>
>>>
>>>
>>>
>>>
>>> the shell script, which I am using
>>>
>>>
>>>
>>> #######################################
>>>
>>>
>>>
>>> for n in  MAIACTAOT.h00v02.20*.nc;do
>>>
>>>  ls $n > text
>>>
>>> export xx=`cut -c18-28 text`
>>>
>>> export YYYY=`cut -c18-21 text`
>>>
>>> export JJJ=`cut -c22-24 text`
>>>
>>> export HH=`cut -c25-26 text`
>>>
>>> export MM=`cut -c27-28 text`
>>>
>>> mm=`date -d "$JJJ days $YYYY-01-01" +"%m"`
>>>
>>> dd=`date -d "$JJJ days $YYYY-01-01" +"%d"`
>>>
>>> mydate=${YYYY}-${mm}-${dd},${HH}:${MM}:00
>>>
>>> echo $mydate
>>>
>>>
>>>
>>> echo "cdo settaxis,$mydate $n re$n"
>>>
>>> cdo settaxis,$mydate $n re$n
>>>
>>>
>>>
>>> done
>>>
>>>
>>>
>>> cdo mergetime reMAI*.nc final.nc
>>>
>>> exit
>>>
>>> #################################
>>>
>>>
>>>
>>>
>>>
>>> Any suggestion regarding this issue would be very helpful.
>>>
>>>
>>>
>>> Thank You
>>>
>>>
>>> Kunal Bali
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________ ncl-talk mailing list
>>> ncl-talk at ucar.edu List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
> _______________________________________________
> 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/20171006/4c9c4908/attachment.html>


More information about the ncl-talk mailing list