: This script converts an ascii file to netcdf ; Author: Sara Rauscher srausche@students.wisc.edu ; Date: 10/22/02 ;load contributed function file (has copy_VarCoords function used later) load "contributed.edited.ncl" begin ;open .nc file to get dimensions and coordinates data = addfile("/cvine2/iesuw/foam/hc.F1.0k.mone486605.nc", "r") ;check to make sure netcdf file doesn't exist; if it does, remove it ;then open netcdf file to write to system("rm carbon2.nc") out = addfile("carbon2.nc", "c") ;We use an existing .nc file to get dimensions for our ascii data ;In this case, the ascii data has the same dims as the FOAM Coupler (128x128) ;Ascii data has no time dim, so just get lat&lon dimenstion ;TSSUB1 is dimensioned (time x lat x lon) ts = data->TSSUB1(0,:,:) ;create new variables to hold ascii data ;we use two because we have to do some re-arranging of the data carbon = new((/128,128/),float) carbon2 = new((/128,128/),float) ;read in ascii file kaz = asciiread("bobocarbon.asc",(/256,64/),"float") ;the data is dimensioned a little strangely by hemisphere, ;so we have to do some re-ordering here ;put ascii info into a variable do j=0,63 do i=0,127 carbon(i,j) = kaz(i,j) end do end do do j=64,127 do i=128,255 carbon(i-128,j) = kaz(i,j-64) end do end do do i=0,127 carbon2(127-i,:) = carbon(i,:) end do ;copy coordinate variable info from variable we created above from ;netcdf file to our new variable so that we can read the output in grads ;this copy_VarCoords function is in contributed.edited.ncl and saves a lot of time ;make sure the dims match between the two variables copy_VarCoords(ts,carbon2) ;output vars to .nc file - you must also put in lat/lon information out->carbon = carbon2 out->lat = data->lat out->lon = data->lon end