Re: [Help] error in converting .nc to .txt using NCL

From: Rick Brownrigg <brownrig_at_nyahnyahspammersnyahnyah>
Date: Tue Feb 18 2014 - 10:17:12 MST

Hi,

I can't be completely certain what the issue is, but in my mail-clients your script appears to have double-newlines after each line under the linux machine, and "escaped" newline characters on the Mac. I'm wondering by chance, does it have carriage-control/newline characters as line terminators? This would likely cause an error on the continuation line at line 74.

Rick
  
On Feb 18, 2014, at 9:53 AM, " Chenguang Wang" <wangch28@msu.edu> wrote:

> Dear All,
>
> I want to convert CCSM4 netCDF files to text files. I have little knowledge in NCL, so my friend wrote a code in NCL6.1.0, which works fine on his computer. But I don't know why the same code doesn't work at my school computer cluster which has NCL 6.1.2. I got fatal error messages in line 74 and 80. Can someone help to fix it? Also, "ncdump" seems to be much faster than NCL in converting .nc to .txt, but the data format is not I desired. Has anyone done this before?
>
> ;----------------------------------------------------------------------
> ; write_asc_2.ncl
> ; Concepts illustrated:
> ; - Writing formatted string, float, and integer data to an ASCII file
> ;----------------------------------------------------------------------
> ; This script uses "write_table" which is much faster than using
> ; "sprintf" and "sprinti".
> ;----------------------------------------------------------------------
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> begin
>
> directory = "/mnt/home/wangch28/CCSM4nc/" ; need a change
> in1 = addfile(directory + "pr_day_CCSM4_historical_r6i1p1_19900101-20051231.nc","r") ; need a change
> in2 = addfile(directory + "tasmax_day_CCSM4_historical_r6i1p1_19900101-20051231.nc","r") ; need a change
> in3 = addfile(directory + "tasmin_day_CCSM4_historical_r6i1p1_19900101-20051231.nc","r") ; need a change
>
> lat = in1->lat
> lon = in1->lon
> time = in1->time
> nlat = dimsizes(in1->lat)
> nlon = dimsizes(in1->lon)
> ntime = dimsizes(in1->time)
> ntotal_num = 365*nlat*nlon ; every year for each txt file
> nyear = ntime/365
>
> prect_uu = in1->pr(:,:,:)
> prect_uu = (/prect_uu/1000.0*100.0*24.0*3600.0/) ; kg/m2/s -> cm/day
> tasmax_uu = in2->tasmax(:,:,:)
> tasmin_uu = in3->tasmin(:,:,:)
>
> daysince = 19900101 ; need a change
>
> ;printVarSummary(prect_uu)
> ;printVarSummary(tasmax_uu)
> ;printVarSummary(tasmin_uu)
> ;printVarSummary(lat)
> ;printVarSummary(lon)
> ;printVarSummary(time)
>
> tMin = new(ntotal_num, "float")
> tMax = new(ntotal_num, "float")
> prec = new(ntotal_num, "float")
>
> lati = new(ntotal_num, "double")
> loni = new(ntotal_num, "double")
>
> year = new(ntotal_num, "integer")
> day = new(ntotal_num, "integer")
>
>
> do n=0,nyear-1,1
> do m=0,ntotal_num-1,1
> timem = m/(nlon*nlat)
> latm = (m - timem*(nlon*nlat))/nlon
> lonm = m - timem*(nlon*nlat) - latm*nlon
> lati(m) = lat(latm)
> loni(m) = lon(lonm)
>
> timenm = n*365 + timem
> year(m) = (/timenm/365 + 1 + 1990/) ; need a change
> day(m) = (/timenm + 1 - (year(m)-1990-1)*365/) ; need a change
>
> tMin(m) = tasmin_uu(time|timenm, lat|latm, lon|lonm)
> tMax(m) = tasmax_uu(time|timenm, lat|latm, lon|lonm)
> prec(m) = prect_uu(time|timenm, lat|latm, lon|lonm)
>
> end do
>
> yeari = 1990+n ; need a change
> filenamen = "CCSM4_Three_Vars_historical_r6i1p1_" + yeari + "0101-" + yeari + "1231.txt" ; need a change
> write_table(filenamen, "w", [/year, day, lati, loni, tMin, tMax, prec/], \
> "%04i %03i %3.2f %3.2f %4.1f %4.1f %2.5f")
>
> end do
>
> ; header = "Year,Day,Latitude,Longitude,Tasmin[K],Tasmax[K],Pr[cm/day]"
>
> end
>
> Thanks,
> Chenguang Wang
> -------------------------------------------------------------------------------
> Ph.D.candidate
> Department of Agriculture, Food and Resource Economics
> 203A Cook Hall, Michigan State University
> Cell Phone: (614) 264-8277, Email: wangch28@msu.edu
> https://www.msu.edu/~wangch28/
> -------------------------------------------------------------------------------
>
> _______________________________________________
> 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
Received on Tue Feb 18 10:18:02 2014

This archive was generated by hypermail 2.1.8 : Wed Feb 19 2014 - 15:58:35 MST