Netcdf files: creation and merge

From: louis Vonder <appopson_at_nyahnyahspammersnyahnyah>
Date: Tue Nov 22 2011 - 10:15:24 MST

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: 
XCut_025_FLFC_01_213K.txtXCut_025_FLFC_02_213K.txtXCut_025_FLFC_03_213K.txtXCut_025_FLFC_04_213K.txt
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"
begin

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   =  "original-file.nc" 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/)

delete(dummy_data)delete(fout)
   end do 
end

Regards

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Nov 22 10:15:33 2011

This archive was generated by hypermail 2.1.8 : Tue Nov 22 2011 - 14:17:52 MST