;====ncl-talk: 21 Nov 2019======= ; I have multiple datasets for individual lat lon positions. ; I want to make a 3-D dataset (lon,lat,Var1) from all the list of files. Var1=Col.1 dataset ; Please give me a hint for the above. ;================================ dir_data = "./" fil_data = systemfunc("cd "+dir_data+" ; ls data_*") nfil = dimsizes(fil_data) ; grid information LAT = tofloat(str_get_field(fil_data, 2, "_")) LON = tofloat(str_get_field(fil_data, 3, "_")) mnLAT = min(LAT) mxLAT = max(LAT) mnLON = min(LON) mxLON = max(LON) dlat = 0.25 dlon = 0.25 nlat = toint((mxLAT-mnLAT)/dlat) + 1 mlon = toint((mxLON-mnLON)/dlon) + 1 lat = fspan(mnLAT,mxLAT, nlat) lon = fspan(mnLON,mxLON, mlon) ntim = numAsciiRow(dir_data+fil_data(0)) time = ispan(0,ntim-1,1) nvar = 4 var = new((/nvar,ntim,nlat,mlon/),"float") do nf=0,nfil-1 path = dir_data+fil_data(nf) data = asciiread(path,(/ntim,nvar/),"float") ylat = tofloat(str_get_field(path, 2, "_")) xlon = tofloat(str_get_field(path, 3, "_")) nl = toint((ylat-mnLAT)/dlat) ml = toint((xlon-mnLON)/dlon) ;;;print(fil_data(nf)+": xlon="+xlon+" ylat="+ylat+" nl="+nl+" ml="+ml) var(0,:,nl,ml) = data(:,0) var(1,:,nl,ml) = data(:,1) var(2,:,nl,ml) = data(:,2) var(3,:,nl,ml) = data(:,3) end do ; meta data time!0 = "time" time@long_name = "time" time@units = "unknown" lat!0 = "lat" lon!0 = "lon" lat@long_name = "latitude" lon@long_name = "longitude" lat@units = "degrees_north" lon@units = "degrees_east" var@long_name = "array holding "+nvar+" variables" var!0 = "variable_ID" var!1 = "time" var!2 = "lat" var!3 = "lon" var&time = time var&lat = lat var&lon = lon printVarSummary(var) print("===========") ; exolicitly extract individual variables var0 = var(0,:,:,:) var0@long_name = "???" var0@units = "???" printVarSummary(var0) print("===========") ; etc ;======== ; Create netCDF ; http://www.ncl.ucar.edu/Applications/method_1.shtml ;======== dirnc = "./" filnc = "SOMA.nc" pthnc = dirnc+filnc system("/bin/rm -f "+pthnc) ; remove any pre-existing file ncdf = addfile(pthnc ,"c") ; open output netCDF file ;=================================================================== ; create global attributes of the file (optional) ;=================================================================== fAtt = True ; assign file attributes fAtt@title = "NCL-TALK question: 11 Nov 2019" ;;fAtt@source_file = "data_30.625_73.125" fAtt@Conventions = "None" fAtt@creation_date = systemfunc ("date") fileattdef( ncdf, fAtt ) ; copy file attributes filedimdef(ncdf,"time",-1,True) ncdf->VAR0 = var0 exit ncdf->VAR1 = var1 ncdf->VAR2 = var2 ncdf->VAR3 = var3