[ncl-talk] query ( CONVERSION ASCII TO NetCDF)

Karin Meier-Fleischer meier-fleischer at dkrz.de
Wed Sep 24 04:00:42 MDT 2014


Hi Kunal, 

didn’t you use the isnan_ieee section in the script? You have NaNs in your data and they should be set to _FillValue.

  if (any(isnan_ieee(data))) then
      value = 1.e20
      replace_ieeenan (data, value, 0)
      data at _FillValue = value
  end if

Again, without your script we could not help properly!

Bye,
Karin

Am 24.09.2014 um 11:40 schrieb Kunal Bali <kunal.bali9 at gmail.com>:

> Dear NCL users
> 
> With the help of NCL users Now i am able to convert ASCII to netcdf format. But when i tried to plot this .nc file the contour map is not coming out in proper way. 
> 
> But when i use the original .nc file (without any conversion) then the plot is coming nicely. Here is attached the file with figure and all commands which i am using to plot. 
> 
> Thank You
> 
> Kunal Bali
> Research Scholar 
> Radio & Atmospheric Science Division 
> CSIR - National Physical Laboratory
> New Delhi - 110012
> 
> 
> 
> 
> 
> 
> On Wed, Sep 24, 2014 at 1:54 PM, Karin Meier-Fleischer <meier-fleischer at dkrz.de> wrote:
> Hi Kunal,
> 
> you read the data into an array called data with nlines=64800 and ncolumns=3  —>  data(nlines,ncolumns)
> 
> The 1st column, all lines:  data(:,0)
> The 2nd column, all lines:  data(:,1)
> The 3rd column, all lines:  data(:,2)
> 
> nLongitude = 360
> Longitude = data(0:nLongitude-1,1)   —> read 2nd column, first 360 lines
> 
> Please, take a look at 
> 
> http://www.ncl.ucar.edu/Document/Manuals/Getting_Started/basics.shtml#ArraySubscripting
> 
> Bye,
> Karin
> 
> Am 24.09.2014 um 07:10 schrieb Kunal Bali <kunal.bali9 at gmail.com>:
> 
>> Dear Karin Meier-Fleischer
>> 
>> Thank You so much for helping me. Your run your scripts and working well. 
>> I just want know what is the means of this line  > Longitude = data(0:nLongitude-1,1)
>> 
>> Thank You
>> 
>> Kunal Bali
>> Research Scholar 
>> Radio & Atmospheric Science Division 
>> CSIR - National Physical Laboratory
>> New Delhi - 110012
>> 
>> 
>> 
>> 
>> 
>> 
>> On Wed, Sep 24, 2014 at 1:01 AM, Karin Meier-Fleischer <meier-fleischer at dkrz.de> wrote:
>> Hi Kunal,
>> 
>> one problems occurred while reading the datacaused by the variable name TotCH4_A in the 
>> header line of your data file 14-01.txt. NCL reads the value 4 in the name and writes it as first 
>> value into the data array. After renaming to TotCH_A in 14-01.txt file everything works well. 
>> 
>> You missed to convert the one dimensional variable TotCH4_A (in your NCL script) to a two 
>> dimensional array. Also as described in the mails before you should assign latitude and 
>> longitude to the named variables of TotCH4_A2D. See the script below.
>> 
>> It is easier to write/save the NCL commands in a text file (e.g. script.ncl) and run it 
>> using ’ncl script.ncl'
>> 
>> Bye, Karin
>> 
>> ;-----------------------------------------------------------------------------
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" 
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" 
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" 
>> 
>> begin
>> 
>>   nLatitude = 180
>>   nLongitude = 360
>>   
>>   data = asciiread("14-01.txt",(/nLatitude*nLongitude,3/),"float")
>> 
>>   Latitude  = data(::nLongitude,0)
>>   Longitude = data(0:nLongitude-1,1)
>>   TotCH4_A  = data(:,2)  
>>   TotCH4_A2D = onedtond(TotCH4_A,(/nLatitude,nLongitude/))
>> 
>>   if (any(isnan_ieee(TotCH4_A2D))) then
>>     value = 1.e20
>>     replace_ieeenan (TotCH4_A2D, value, 0)
>>     TotCH4_A2D at _FillValue = value
>>   end if
>> 
>>   printMinMax(Latitude,0)
>>   printMinMax(Longitude,0)
>>   printMinMax(TotCH4_A,0)
>> 
>> ; Assign named dimensions 
>> 
>>   TotCH4_A2D!0 = "lat"
>>   TotCH4_A2D!1 = "lon"
>> 
>> ; Assign coordinate variables
>> 
>>   TotCH4_A2D&lat = Latitude
>>   TotCH4_A2D&lon = Longitude
>> 
>>   TotCH4_A2D&lat at units = "degrees_north"
>>   TotCH4_A2D&lon at units = "degrees_east"
>>   
>>   printVarSummary(TotCH4_A2D)
>> 
>> ; delete existing netcdf file to create a new one
>>   system("rm -rf Sample.nc")
>>   ncdf = addfile("Sample.nc","c")
>> 
>> ; write data to netcdf file
>> 
>>   ncdf->TotCH4_A = TotCH4_A2D
>> 
>> ; plot data
>> 
>>   wks = gsn_open_wks("x11","test")
>>   plot = gsn_csm_contour_map(wks,TotCH4_A2D,False)
>> 
>> end
>> 
>> ;-----------------------------------------------------------------------------
>> 
>> 
>> 
>> Am 23.09.2014 um 19:45 schrieb Kunal Bali <kunal.bali9 at gmail.com>:
>> 
>>> Here i attached scripts which i am trying to get the  ascii to netcdf conversion. 
>>> 
>>> Kunal Bali
>>> Research Scholar 
>>> Radio & Atmospheric Science Division 
>>> CSIR - National Physical Laboratory
>>> New Delhi - 110012
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> On Tue, Sep 23, 2014 at 11:03 PM, Karin Meier-Fleischer <meier-fleischer at dkrz.de> wrote:
>>> Hi Kunal,
>>> 
>>> could you provide the data file and your script. 
>>> 
>>> Bye,
>>> Karin
>>> 
>>> 
>>> Am 23.09.2014 um 19:05 schrieb Kunal Bali <kunal.bali9 at gmail.com>:
>>> 
>>>> Dear NCL users
>>>> 
>>>> I tried previous mail scripts for converting ASCII to netcdf format , the file is generating but its without data points.Only variable names generating. 
>>>> 
>>>> Kunal Bali
>>>> Research Scholar 
>>>> Radio & Atmospheric Science Division 
>>>> CSIR - National Physical Laboratory
>>>> New Delhi - 110012
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> On Tue, Sep 23, 2014 at 1:28 PM, Karin Meier-Fleischer <meier-fleischer at dkrz.de> wrote:
>>>> Hi Kunal,
>>>> 
>>>> the answer was given in an earlier mail:
>>>> 
>>>> 1. read the ASCII data variable, lat and lon
>>>> 2. create a output file:                         netcdf = addfile("simple.nc","c")
>>>> 3. write your data variable to the output file:  ncdf->values = values
>>>> 
>>>> 
>>>> Please read the 'output to netcdf' examples for more details:
>>>> http://ncl.ucar.edu/Applications/o-netcdf.shtml
>>>> 
>>>> Bye,
>>>> Karin
>>>> 
>>>> Am 23.09.14 07:04, schrieb Kunal Bali:
>>>>> Dear NCL users
>>>>> 
>>>>> I am still not getting how to do the conversion from ASCII to netcdf ??
>>>>> 
>>>>> Kunal Bali
>>>>> Research Scholar 
>>>>> Radio & Atmospheric Science Division 
>>>>> CSIR - National Physical Laboratory
>>>>> New Delhi - 110012
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> On Mon, Sep 22, 2014 at 7:35 PM, Yuqiang Zhang <yuqiangzhang.thu at gmail.com> wrote:
>>>>> Hi Kunal,
>>>>> 
>>>>>  
>>>>> In line 30, “ncl 30> TotCH4_A = data(:,2) “. You variable “TotCH4_A” is only assigned one dimension’s value, so you can’t assign two dimension through line 33 & 34.
>>>>> 
>>>>>  
>>>>> Regards,
>>>>> 
>>>>> Yuqiang
>>>>> 
>>>>>  
>>>>> From: ncl-talk-bounces at ucar.edu [mailto:ncl-talk-bounces at ucar.edu] On Behalf Of Kunal Bali
>>>>> Sent: Monday, September 22, 2014 8:53 AM
>>>>> To: Karin Meier-Fleischer
>>>>> Cc: ncl-talk at ucar.edu
>>>>> Subject: Re: [ncl-talk] query ( CONVERSION ASCII TO NetCDF)
>>>>> 
>>>>>  
>>>>> Dear NCL user
>>>>> 
>>>>> I tried this script from NCL but still getting error
>>>>> 
>>>>> 
>>>>> ncl 28> Longitude = data(:,1)
>>>>> ncl 29> Latitude = data(:,0)  
>>>>> ncl 30> TotCH4_A = data(:,2)  
>>>>> ncl 31> ncdf = addfile("/home/kunal/simple1.nc","c")
>>>>> ncl 32> filedimdef(ncdf,"time",-1,True)              
>>>>> ncl 33> TotCH4_A!0 = "Latitude"
>>>>> ncl 34> TotCH4_A!1 = "Longitude"
>>>>> fatal:Variable (TotCH4_A) has (1) dimensions can not write to dimension (1)
>>>>> fatal:["Execute.c":8565]:Execute: Error occurred at or near line 34
>>>>> 
>>>>> 
>>>>> 
>>>>> Kunal Bali
>>>>> 
>>>>> Research Scholar
>>>>> 
>>>>> Radio & Atmospheric Science Division
>>>>> 
>>>>> CSIR - National Physical Laboratory
>>>>> 
>>>>> New Delhi - 110012
>>>>> 
>>>>>  
>>>>>  
>>>>>  
>>>>>  
>>>>>  
>>>>> On Mon, Sep 22, 2014 at 5:32 PM, Karin Meier-Fleischer <meier-fleischer at dkrz.de> wrote:
>>>>> 
>>>>> Hi Kunal,
>>>>> 
>>>>>  
>>>>> Please, take a look at the 'output netcdf' examples page, method_1
>>>>> 
>>>>>  
>>>>> http://ncl.ucar.edu/Applications/method_1.shtml
>>>>> 
>>>>> Try this:
>>>>> 
>>>>>  
>>>>>  
>>>>> lat = data(:,0)
>>>>> 
>>>>> lat = data(:,1)
>>>>> 
>>>>> values= data(:,2)
>>>>> 
>>>>> system("/bin/rm -f simple.nc") ; remove any pre-existing file 
>>>>> 
>>>>> ncdf = addfile("simple.nc" ,"c") ; output netCDF file
>>>>> filedimdef(ncdf,"time",-1,True) ; recommended
>>>>> values!0 = "lat"
>>>>> values!1 = "lon"
>>>>> values&lat = lat
>>>>> values&lon = lon 
>>>>> ncdf->values = values
>>>>>  
>>>>> Bye, Karin
>>>>> 
>>>>>  
>>>>> 
>>>>> Am 22.09.2014 um 11:40 schrieb Kunal Bali <kunal.bali9 at gmail.com>:
>>>>> 
>>>>> Dear NCL users
>>>>> 
>>>>> I want to convert ASCII to .nc file format. Could any one please provides me the link for this query or give any detail about this ??
>>>>> 
>>>>> I have data in 3 column ( Latitude Longitude Values)
>>>>> 
>>>>> More Detail
>>>>> 
>>>>> Variable: data
>>>>> Type: float
>>>>> Total Size: 777600 bytes
>>>>>             194400 values
>>>>> Number of Dimensions: 2
>>>>> Dimensions and sizes:    [64800] x [3]
>>>>> Coordinates: 
>>>>> Number Of Attributes: 1
>>>>>   _FillValue :    9.96921e+36
>>>>> 
>>>>> 
>>>>> So is there any ways to convert ASCII to netcdf format ???
>>>>> 
>>>>> Thank You
>>>>> 
>>>>> 
>>>>> Kunal Bali
>>>>> 
>>>>> Research Scholar
>>>>> 
>>>>> Radio & Atmospheric Science Division
>>>>> 
>>>>> CSIR - National Physical Laboratory
>>>>> 
>>>>> New Delhi - 110012
>>>>> 
>>>>>  
>>>>>  
>>>>>  
>>>>>  
>>>>> _______________________________________________
>>>>> 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
>>>> 
>>>> _______________________________________________
>>>> 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
>>> 
>>> ____________________________________
>>> Dipl. Geophys. Karin Meier-Fleischer
>>> Visualisierung
>>> Abteilung Anwendungen
>>> 
>>> Deutsches Klimarechenzentrum GmbH (DKRZ)
>>> Bundesstrasse 45a * D-20146 Hamburg                          
>>> Germany                                
>>> 
>>> Phone:	+49 (0)40 460094 126
>>> Fax:	+49 (0)40 460094 270
>>> E-Mail:	meier-fleischer at dkrz.de
>>> URL:	http://www.dkrz.de/
>>> 
>>> Geschäftsführer: Prof. Dr. Thomas Ludwig
>>> Sitz der Gesellschaft: Hamburg
>>> Amtsgericht Hamburg HRB 39784
>>> 
>>> 
>>> 
>>> 
>>> 
>>> <14-01.txt><ASCII to netcdf.ncl>_______________________________________________
>>> 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
> 
> 
> 
> 
> <contour_error.png>_______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

____________________________________
Dipl. Geophys. Karin Meier-Fleischer
Visualisierung
Abteilung Anwendungen

Deutsches Klimarechenzentrum GmbH (DKRZ)
Bundesstrasse 45a * D-20146 Hamburg                          
Germany                                

Phone:	+49 (0)40 460094 126
Fax:	+49 (0)40 460094 270
E-Mail:	meier-fleischer at dkrz.de
URL:	http://www.dkrz.de/

Geschäftsführer: Prof. Dr. Thomas Ludwig
Sitz der Gesellschaft: Hamburg
Amtsgericht Hamburg HRB 39784




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140924/f2dca44c/attachment.html 


More information about the ncl-talk mailing list