Re: ARCHIVE .nc

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Fri, 24 Nov 2006 11:09:23 -0700 (MST)

> I need convert an archive in the ".txt" format
> to an archive ".nc", but I'm not understanding how do this.
> I already having looked at the site of the NCL
>
> The link of the archive ".txt" is:
> http://www.lpc.uottawa.ca/data/americas/samerica/precipitation.txt
> So, thanks a lot...
=======================

Did you try to read the ascii file and then
create a netCDF file? If so, where did it fail?

Please look at:
  http://www.ncl.ucar.edu/Document/Functions/Contributed/readAsciiTable.shtml

; Read ascii file
   ncol = 14
   data = readAsciiTable("precipitation.txt", ncol, "float", 10)
                                                                                             
   LON = data(:,0) ; all rows of the 1st column
   LAT = data(:,1) ; 2nd
   PRC = data(:,2:) ; all rows from 3-14 columns
    
                           
   minLON = min(LON)
   maxLON = max(LON)
   minLAT = min(LAT)
   maxLAT = max(LAT)
   print("LON: min="+min(LON)+" max="+max(LON) ) ; LON: min=-91.5 max=-35
   print("LAT: min="+min(LAT)+" max="+max(LAT) ) ; LAT: min=-56 max=12
   
   dlat = 0.5
   dlon = 0.5
   
   nlat = floattoshort((maxLAT-minLAT)/dlat) + 1
   mlon = floattoshort((maxLON-minLON)/dlon) + 1
   print("nlat="+nlat+" mlon="+mlon) ; nlat=137 mlon=114

   lat = fspan(minLAT,maxLAT, nlat)
   lat!0 = "lat"
   lat_at_long_name = "latitude"
   lat_at_units = "degrees_north"

   lon = fspan(minLON,maxLON, mlon)
   lon!0 = "lon"
   lon_at_long_name = "longitude"
   

You have to create a variable

   prc = new ( (/12 , nlat,mlon/), "float", 1e20)
   prc!0 = "time"
   prc!1 = "lat"
   prc!2 = "lon"
   prc_at_long_name = "Total Monthly Precipitation"
   prc_at_units = "mm"

   do n=0,npts-1 ; loop over each point
      nl = ind(LAT(n).eq.lat)
      ml = ind(LON(n).eq.lon)
      prc(:,nl,ml) = (/ PRC(n,:) /)
   end do
   
Then, using the LON/LAT values determine the appropriate
spatial subscripts.

Then create the netCDF file ... see

http://www.ncl.ucar.edu/Applications/method_2.shtml

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Nov 24 2006 - 11:09:23 MST

This archive was generated by hypermail 2.2.0 : Tue Nov 28 2006 - 15:20:59 MST