[ncl-talk] Time coordinate

Mary Haley haley at ucar.edu
Sun Jun 19 22:58:53 MDT 2016


Guilherme,

You are creating a new NetCDF file for each variable. You have these lines
inside your innermost do loop:

      ; Salva no netCDF.

      system("/bin/rm -f "+var(j)+".nc")
      nc = addfile(var(j)+".nc" ,"c")
      filedimdef(nc,"time",-1,True)
      nc->$var(j)$ = xint

Note that you are creating the file with the same name as your variable, so
this means that each variable is being written to its own file: "hus.nc", "
water.nc", "va.nc" and "ps.nc".  If you want the four variables to be
written to the same file, then perhaps what you mean to do is open the file
to be created outside of the "do 0,nvar-1" loop:

do i = 0,nmodels-1
  dir =
"/media/gui/GUI_1Tb/gui/CMIP5_DOLMAN/historical/"+modelos(i)+"/bruto/"
    ; Salva no netCDF.
                        out_filename = "somefile" + i + ".nc"  ; obviously
you will want to use a more appropriate filename
  system("/bin/rm -f "+ out_filename)
  nc = addfile(out_filename,"c")
  filedimdef(nc,"time",-1,True)
  do j = 0,nvar-1
    . . .

--Mary


On Sun, Jun 19, 2016 at 10:30 PM, Guilherme Martins <jgmsantos at gmail.com>
wrote:

> Hi Mary,
>
> The code is right, the problem is I want to create the four variables ( "hus",
> "water", "va", "ps" ) in a single file for each model. In my loop is
> being written only the last variable ("ps"). The variables are being
> overwritten. My final file contains only the last variable, ie, ps (my list
> of variables => var = (/ "hus", "water", "va", "ps" /)). I hope you
> understand me.
>
> Thanks,
>
> Guilherme.
>
> Em seg, 20 de jun de 2016 às 01:19, Mary Haley <haley at ucar.edu> escreveu:
>
>> Hi Guilherme,
>>
>> The error message is indicating that that units of "time" are not set
>> right before you call cd_calendar. You said that you did explicitly set
>> this, but I can't tell from looking at the code how you did this. You need
>> to look at your "time" array every time in the loop, using
>> "printVarSummary" to verify whether or not you have the expected "units"
>> attribute:
>>
>>          time := f->$nome_var(0)$
>>          printVarSummary(time)         ; Check for valid "units" attribute
>>          YYYYMM := cd_calendar(time,-1)
>>
>> You have this code in both the "if" and "else" parts of an "if"
>> statement, so you must do this in both locations.
>>
>> For your second question, you didn't indicate exactly what the problem
>> is.  Are you getting an error of any kind? Does the file simply not exist
>> after you run the script?  Please be explicit. Your code looks correct to
>> me, but without being able to run it, or knowing if there are any errors,
>> it's hard to help.
>>
>> --Mary
>>
>>
>>
>> On Sat, Jun 18, 2016 at 1:15 PM, Guilherme Martins <jgmsantos at gmail.com>
>> wrote:
>>
>>> Hi users,
>>>
>>> 1) I'm reading some netCDF files to interpolate and to fill missing
>>> values.
>>>
>>> The first model it's ok, but the others I don't know why the reason it
>>> don't work. I get the following message error:
>>>
>>>
>>> *fatal:cd_calendar: no 'units' attribute provided*
>>> *fatal:["Execute.c":8575]:Execute: Error occurred at or near line 25 in
>>> file 01limpa.CMIP5.ncl*
>>>
>>> I tried to use the time at units = "day since ..." but it doesn't work.
>>>
>>> 2) Other question, I want to write the four variables
>>> ("hus","ua","va","ps") in same netCDF file for each model, but I'm not
>>> capable to do that.
>>>
>>> My script is in attachment.
>>>
>>> Any help is very apreciated.
>>>
>>> Cheers,
>>>
>>> Guilherme Martins.
>>> --
>>>
>>> ------------------------------------------------------------------------------------------
>>> Dr. Guilherme Martins
>>> Instituto Nacional de Pesquisas Espaciais (INPE)
>>> Centro de Previsão de Tempo e Estudos Climáticos (CPTEC)
>>> Grupo de Desenvolvimento em Assimilação de Dados (GDAD)
>>> Telefone (INPE/CP): +55 12 3186-8551 || Celular (TIM): +55 12 98152-8580
>>> E-mail: guilherme.martins at inpe.br || jgmsantos at gmail.com
>>> Skype: guilherme.martins.
>>> Homepage: https://sites.google.com/site/jgmsantos
>>> Currículo Lattes: http://lattes.cnpq.br/5997657584785803
>>>
>>> ------------------------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>> --
>
> ------------------------------------------------------------------------------------------
> Dr. Guilherme Martins
> Instituto Nacional de Pesquisas Espaciais (INPE)
> Centro de Previsão de Tempo e Estudos Climáticos (CPTEC)
> Grupo de Desenvolvimento em Assimilação de Dados (GDAD)
> Telefone (INPE/CP): +55 12 3186-8551 || Celular (TIM): +55 12 98152-8580
> E-mail: guilherme.martins at inpe.br || jgmsantos at gmail.com
> Skype: guilherme.martins.
> Homepage: https://sites.google.com/site/jgmsantos
> Currículo Lattes: http://lattes.cnpq.br/5997657584785803
>
> ------------------------------------------------------------------------------------------
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160619/abb08d21/attachment.html 


More information about the ncl-talk mailing list