begin nmaxcyclones = 1 cyclone = 1 cyclone!0 = "cyclone" cyclone@long_name = "dimension index of cyclone number" string_FillValue = "" CYCLONE_ATCF_stormid = new(nmaxcyclones,"string",string_FillValue) CYCLONE_ATCF_stormid!0 = "cyclone" CYCLONE_ATCF_stormid@longname = "Cyclone ATCF storm ID" CYCLONE_ATCF_stormid = (/"AL132023"/) ;=================================================================== ; Set the file structure to Advanced so that we can write out strings. ;=================================================================== setfileoption("nc","FileStructure","Advanced") ;=================================================================== ; Set the file format to NetCDF4 so that compression can be used. ;=================================================================== setfileoption("nc","Format","NetCDF4") ;=================================================================== ; Create the file for writing ;=================================================================== fout = addfile("test.nc","c") ; open output file ;=================================================================== ; Explicitly declare file definition mode. This improves efficiency. ;=================================================================== setfileoption(fout,"DefineMode",True) setfileoption(fout,"CompressionLevel",5) ; NOTE: setting a level of 5 gives a pretty good balance between compression and efficiency. ; A level of 9 (the maximum level of compression) can result in a slightly smaller filesize, ; but at 4-5 times the computational cost. ;=================================================================== ; Create global attributes of the file (these are output in reverse order given) ;=================================================================== ; Write global attributes to file. It's okay to do this before ; predefining the file's variables. We are still in "define" mode. fAtt = True fAtt@title = "Test" fileattdef(fout,fAtt) ; define file attributes ;=================================================================== ; predefine the coordinate variables and their dimensionality ; Note: to get an UNLIMITED record dimension, we set the dimensionality ; to -1 and set the unlimited array to True. ;=================================================================== dimNames = (/"cyclone"/) dimSizes = (/nmaxcyclones/) dimUnlim = (/True/) filedimdef(fout,dimNames,dimSizes,dimUnlim) ;=================================================================== ; predefine the the dimensionality of the variables to be written out ; filevardef(output_file, name of variable, type of variable, CV's of -> Could we use getvardim for the third column?? ; variable) note: at this point, when you do an ncdump on the file, it ; will look like the variable is there. If you do not output the values, ; however, then an ncdump -v xxx will reveal that there is no data. ;=================================================================== ; coordinate dimensions filevardef(fout, "cyclone", typeof(cyclone), "cyclone") filevardef(fout, "CYCLONE_ATCF_stormid", typeof(CYCLONE_ATCF_stormid), "cyclone") ;=================================================================== ; add some attributes ; note, since we are copying variables from one file to another, ; the original variables already have attributes, and we can copy ; them directly by just passing the variable to filevarattdef. You can ; create your own attributes by assigning them to the variable as we ; do with u. ;==================================================================== ; coordinate dimensions filevarattdef(fout, "cyclone", cyclone) filevarattdef(fout, "CYCLONE_ATCF_stormid", CYCLONE_ATCF_stormid) ;==================================================================== ; explicitly exit file definition mode. **NOT REQUIRED** ;==================================================================== ; setfileoption(fout,"DefineMode",False) ; write out the coordinate dimensions fout->cyclone = (/ cyclone /) fout->CYCLONE_ATCF_stormid = (/ CYCLONE_ATCF_stormid /) ; Delete the file variable so that NCL will finalize and close it prior to trying to upload it to the server. delete(fout) end