;This script is a simple example of how to read data in and write it ;out to a new .nc file using NCL. The .nc file output from this script ;should be readable by GrADS or any other software. ;Questions? srausche@students.wisc.ediu begin ; open file to write variable to (file should not already exist) out = addfile("test.nc","c") ; open data file to get data from data = addfile("/grove3/iesuw/genesis2/GEN2LSX-SAKMR1-MONE1620.nc", "r") ; Define the variables and their dimensions. ; Variables have dimensions of (time,level,latitude,longitude) or (time,latitude,longitude) ; depending on whether it is a multi-level or sfc variable ;get dimensions of variable in file dims = dimsizes(data->PRECIPMM) ;print dims to check them print(dims) ;assign same dimensions to new variable ;another way to do this: simply set dimensions yourself, e.g.: ;pme = new((/12,90,180/),float) pme = new((/dims(0),dims(1),dims(2)/),float) ; Create your new variable (put in whatever expression you want for this variable (this is an example)) pme(:,:,:) = data->PRECIPMM(:,:,:) - data->AVAP(:,:,:) ; Assign metadata to variables ; get time, latitude, longitude from orig data file ; need to do this so GrADS will read the file pme!0 = "time" pme&time = data->time pme!1 = "latitude" pme&latitude = data->latitude pme!2 = "longitude" pme&longitude = data->longitude ; write out data to file ; write variables out->pme = pme ; write metadata out->latitude = data->latitude out->longitude = data->longitude out->time = data->time end