Re: Netcdf files: creation and merge

From: louis Vonder <appopson_at_nyahnyahspammersnyahnyah>
Date: Wed Nov 23 2011 - 00:29:44 MST

Many thanks Mary,

Sorry for few information I given in my last email.

The NCEP/NCAR time that I am talking about look like this 2010:06:01:00:30:00

Here attached *.txt  files that I listed.  Each file contain a parameter recorded every 30 min during a day starting at 00:30 LST.

So, i want to generated date from the order of files.
For example

  XCut_025_FLFC_01_213K.txt  -> 2010:06:01:00:30:00
  XCut_025_FLFC_02_213K.txt  -> 2010:06:01:01:00:00

After this operation the unique file generated should have three dimension (time, lat, lon).
With these I can manipulate my netcdf data more easily.

I guess that informations I send now can better give you some idea on what I am trying to do?



--- En date de : Mar 22.11.11, Mary Haley <> a écrit :

De: Mary Haley <>
Objet: Re: [ncl-talk] Netcdf files: creation and merge
Ŕ: "louis Vonder" <>
Cc: " forum" <>
Date: Mardi 22 novembre 2011, 22h16

I need some clarification. Exactly what problem are you having generating the date? You said you want it to look like the one in the NCEP/NCAR dataset.  What do these dates look like? 
Also I'm not sure what your question is about writing the data to one file.  Right now, you have all the NetCDF file stuff inside the loop. If you want to write your data to one file, you'll need to move the file definition code outside the loop, but then add a third dimension along with "lat" and "lon", called something like "date" or "time".   It would help if you can provide the *.txt files that you list below.

On Nov 22, 2011, at 10:15 AM, louis Vonder wrote:
Dear all,
I have a ncl code (inspired from ncl examples) that I am using to save my data in netcdf format. But this code creates for each ascii file a netcdf data, unfortunately this procedure is not nice !!!Now I want to better customize this script so that i can save all my data in a unique netcdf file. 
But I am facing a problem to generate the date. For example, my files are named as the  following: 
Where 01, 02, 03, 04 correspond to 00:30 LST, 01:00 LST, 01:30 LST and 02:00 LST  (LST = Local Solar Time).
The year can be for example 2010 during the month of August.
So I want that the generated file contain date such as in netcdf file generated by NCEP/NCAR dataset. 
Below the script I am using
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"load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"

nlat = 58   ini_lat = 1.   lat    = ini_lat + (ispan(0, nlat-1, 1)*0.25)

nlon = 66ini_lon = 1.5lon    = ini_lon + (ispan(0, nlon-1, 1)*0.25)

  lat@units   = "degrees_north"  lat@long_name = "latitude"  lon@units   = "degrees_east"  lon@long_name = "longitude"
     fili = systemfunc("ls  XCut_025_FLFC_*_235K.txt")  nfil = dimsizes( fili )
    do n=0, nfil - 1       name  = stringtocharacter(fili(n))        name1  = name(0:20)       name2 = chartostring(name1)
       dummy_data = asciiread(fili(n), (/nlat, nlon/), "float")  ; Set up coordinate arrays so we can overlay on map.  dummy_data!0   = "lat"  dummy_data!1   = "lon"  dummy_data&lat = lat  dummy_data&lon = lon  dummy_data@units = "%"  dummy_data@_FillValue    = -9999.  dummy_data@missing_value = dummy_data@_FillValue   dummy_data@long_name = "Fractional coverage"
        diro = "./"                     ; Output directory        filo =   name2+".nc"             ; Output file system("/bin/rm -f " + diro + filo)    ; remove if exists fout  = addfile (diro + filo, "c")  ; open output file

 ;===================================================================    ; explicitly declare file definition mode. Improve efficiency.    ;===================================================================        setfileoption(fout,"DefineMode",True)
  ;===================================================================    ; create global attributes of the file    ;===================================================================        fAtt               = True            ; assign file attributes fAtt@title         = "NCL Efficient Approach to netCDF Creation"   fAtt@source_file   =  "" fAtt@Conventions   = "None"    fAtt@creation_date = systemfunc ("date")         fileattdef( fout, fAtt )            ; copy file attributes        ;===================================================================    ; predefine the coordinate variables and their dimensionality    ; note: to get an UNLIMITED record dimension, we set the dimensionality    ; to -1 and set the unlimited array to True.    ;===================================================================        dimNames = (/"lat", "lon"/)   dimSizes = (/nlat,  nlon/)  dimUnlim = (/False, False/)    filedimdef(fout, dimNames, dimSizes, dimUnlim)

            filevardef(fout, "lat"  ,typeof(lat), "lat")                                 filevardef(fout, "lon"  ,typeof(lon), "lon")                                 filevardef(fout, "FC", typeof(dummy_data), (/"lat" ,"lon"/))  

       filevarattdef(fout, "lat", lat)                       ; copy lat attributes       filevarattdef(fout, "lon", lon)                       ; copy lon attributes       filevarattdef(fout, "FC", dummy_data)                 ; copy TOPOG attributes
        setfileoption(fout, "DefineMode", False)

       fout->lat    = (/lat/)       fout->lon    = (/lon/)        fout->FC  = (/dummy_data/)

   end do 


ncl-talk mailing list
List instructions, subscriber options, unsubscribe:

Received on Wed Nov 23 00:32:12 2011

This archive was generated by hypermail 2.1.8 : Wed Nov 23 2011 - 16:46:19 MST