[ncl-talk] Editing global attributes of a NetCDF file in NCL

Adam Phillips asphilli at ucar.edu
Wed Aug 26 10:41:19 MDT 2020


Hi Tabish,
I would use the NetCDF operator ncatted to edit the file. Here's a NCL code
snippet where I used ncatted to edit all files in a specified directory,
but you can use whatever language you want to call ncatted:
; I modified the following to alter your MMINLU global history attribute

  dir = "/project/data/sim1/sic/"   ; directory holding files needing
modification
  fils = systemfunc("ls "+dir)
  do gg = 0,dimsizes(fils)-1
     system("ncatted  -O -a MMINLU,global,o,c,'attribute text goes here'
"+dir+fils(gg))
  end do

http://nco.sourceforge.net/nco.html#ncatted-netCDF-Attribute-Editor

As I used the above coding for my own files, I strongly suggest you test
altering a duplicate file before altering the real files.
Hope that helps!
Adam


On Wed, Aug 26, 2020 at 10:19 AM Tabish Ansari via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> Hi
>
> I need to make a small amendment in a global attribute of a WRF-related
> netCDF file. This is a model "restart" file which stores crucial
> information about the model setup and tells the model what datasets to
> pick-up. For some reason, the latest WRF version has made a minor mistake
> in writing the global attributes and this is causing errors, which I think
> could be solved simply by editing one of the global attributes. I know of
> NCL functions which copy entire metadata from one nc file to another but Is
> there a way in NCL to edit these particular fields?
>
> Here's what it looks like and I need to edit the line shown in red towards
> the end:
>
> // global attributes:
> :TITLE = " OUTPUT FROM *             PROGRAM:WRF-Chem V4.1.3 MODEL" ;
> :START_DATE = "2020-02-29_00:00:00" ;
> :SIMULATION_START_DATE = "2020-02-29_00:00:00" ;
> :FLAG_RESTART = 1 ;
> :MAX_WRF_ALARMS = 55 ;
> :WRF_ALARM_ISRINGING_01 = 1 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_01 = 3600 ;
> :WRF_ALARM_ISRINGING_02 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_02 = 1700000000 ;
> :WRF_ALARM_ISRINGING_03 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_03 = 1700000000 ;
> :WRF_ALARM_ISRINGING_04 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_04 = 1700000000 ;
> :WRF_ALARM_ISRINGING_05 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_05 = 1700000000 ;
> :WRF_ALARM_ISRINGING_06 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_06 = 1700000000 ;
> :WRF_ALARM_ISRINGING_07 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_07 = 1700000000 ;
> :WRF_ALARM_ISRINGING_08 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_08 = 1700000000 ;
> :WRF_ALARM_ISRINGING_09 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_09 = 1700000000 ;
> :WRF_ALARM_ISRINGING_10 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_10 = 1700000000 ;
> :WRF_ALARM_ISRINGING_11 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_11 = 1700000000 ;
> :WRF_ALARM_ISRINGING_12 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_12 = 1700000000 ;
> :WRF_ALARM_ISRINGING_13 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_13 = 1700000000 ;
> :WRF_ALARM_ISRINGING_14 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_14 = 1700000000 ;
> :WRF_ALARM_ISRINGING_15 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_15 = 1700000000 ;
> :WRF_ALARM_ISRINGING_16 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_16 = 1700000000 ;
> :WRF_ALARM_ISRINGING_17 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_17 = 1700000000 ;
> :WRF_ALARM_ISRINGING_18 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_18 = 1700000000 ;
> :WRF_ALARM_ISRINGING_19 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_19 = 1700000000 ;
> :WRF_ALARM_ISRINGING_20 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_20 = 1700000000 ;
> :WRF_ALARM_ISRINGING_21 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_21 = 1700000000 ;
> :WRF_ALARM_ISRINGING_22 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_22 = 1700000000 ;
> :WRF_ALARM_ISRINGING_23 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_23 = 1700000000 ;
> :WRF_ALARM_ISRINGING_24 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_24 = 1700000000 ;
> :WRF_ALARM_ISRINGING_25 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_25 = 1700000000 ;
> :WRF_ALARM_ISRINGING_27 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_27 = 1700000000 ;
> :WRF_ALARM_ISRINGING_28 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_28 = 1700000000 ;
> :WRF_ALARM_ISRINGING_29 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_29 = 1700000000 ;
> :WRF_ALARM_ISRINGING_30 = 1 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_30 = 21600 ;
> :WRF_ALARM_ISRINGING_31 = 1 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_31 = 3600 ;
> :WRF_ALARM_ISRINGING_32 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_32 = 1700000000 ;
> :WRF_ALARM_ISRINGING_33 = 1 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_33 = 3600 ;
> :WRF_ALARM_ISRINGING_34 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_34 = 1700000000 ;
> :WRF_ALARM_ISRINGING_35 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_35 = 1700000000 ;
> :WRF_ALARM_ISRINGING_36 = 1 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_36 = 21600 ;
> :WRF_ALARM_ISRINGING_37 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_37 = 1700000000 ;
> :WRF_ALARM_ISRINGING_38 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_38 = 1700000000 ;
> :WRF_ALARM_ISRINGING_39 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_39 = 1700000000 ;
> :WRF_ALARM_ISRINGING_40 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_40 = 1700000000 ;
> :WRF_ALARM_ISRINGING_41 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_41 = 1700000000 ;
> :WRF_ALARM_ISRINGING_42 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_42 = 1700000000 ;
> :WRF_ALARM_ISRINGING_43 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_43 = 1700000000 ;
> :WRF_ALARM_ISRINGING_44 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_44 = 1700000000 ;
> :WRF_ALARM_ISRINGING_45 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_45 = 1700000000 ;
> :WRF_ALARM_ISRINGING_46 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_46 = 1700000000 ;
> :WRF_ALARM_ISRINGING_47 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_47 = 1700000000 ;
> :WRF_ALARM_ISRINGING_48 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_48 = 1700000000 ;
> :WRF_ALARM_ISRINGING_49 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_49 = 1700000000 ;
> :WRF_ALARM_ISRINGING_50 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_50 = 1700000000 ;
> :WRF_ALARM_ISRINGING_51 = 1 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_51 = 86400 ;
> :WRF_ALARM_ISRINGING_53 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_53 = 1700000000 ;
> :WRF_ALARM_ISRINGING_55 = 0 ;
> :WRF_ALARM_SECS_TIL_NEXT_RING_55 = -1123200 ;
> :WEST-EAST_GRID_DIMENSION = 100 ;
> :SOUTH-NORTH_GRID_DIMENSION = 100 ;
> :BOTTOM-TOP_GRID_DIMENSION = 41 ;
> :DX = 1000.f ;
> :DY = 1000.f ;
> :AERCU_OPT = 0 ;
> :AERCU_FCT = 1.f ;
> :IDEAL_CASE = 0 ;
> :DIFF_6TH_SLOPEOPT = 0 ;
> :AUTO_LEVELS_OPT = 2 ;
> :DIFF_6TH_THRESH = 0.1f ;
> :DZBOT = 50.f ;
> :DZSTRETCH_S = 1.3f ;
> :DZSTRETCH_U = 1.1f ;
> :GRIDTYPE = "C" ;
> :DIFF_OPT = 1 ;
> :KM_OPT = 4 ;
> :DAMP_OPT = 3 ;
> :DAMPCOEF = 0.2f ;
> :KHDIF = 0.f ;
> :KVDIF = 0.f ;
> :MP_PHYSICS = 10 ;
> :RA_LW_PHYSICS = 4 ;
> :RA_SW_PHYSICS = 4 ;
> :SF_SFCLAY_PHYSICS = 2 ;
> :SF_SURFACE_PHYSICS = 2 ;
> :BL_PBL_PHYSICS = 2 ;
> :CU_PHYSICS = 0 ;
> :SF_LAKE_PHYSICS = 0 ;
> :SURFACE_INPUT_SOURCE = 1 ;
> :SST_UPDATE = 1 ;
> :GRID_FDDA = 1 ;
> :GFDDA_INTERVAL_M = 360 ;
> :GFDDA_END_H = 2400 ;
> :GRID_SFDDA = 0 ;
> :SGFDDA_INTERVAL_M = 0 ;
> :SGFDDA_END_H = 0 ;
> :HYPSOMETRIC_OPT = 2 ;
> :USE_THETA_M = 1 ;
> :GWD_OPT = 0 ;
> :SF_URBAN_PHYSICS = 2 ;
> :SF_SURFACE_MOSAIC = 0 ;
> :SF_OCEAN_PHYSICS = 0 ;
> :SIMULATION_INITIALIZATION_TYPE = "REAL-DATA CASE" ;
> :WEST-EAST_PATCH_START_UNSTAG = 1 ;
> :WEST-EAST_PATCH_END_UNSTAG = 99 ;
> :WEST-EAST_PATCH_START_STAG = 1 ;
> :WEST-EAST_PATCH_END_STAG = 100 ;
> :SOUTH-NORTH_PATCH_START_UNSTAG = 1 ;
> :SOUTH-NORTH_PATCH_END_UNSTAG = 99 ;
> :SOUTH-NORTH_PATCH_START_STAG = 1 ;
> :SOUTH-NORTH_PATCH_END_STAG = 100 ;
> :BOTTOM-TOP_PATCH_START_UNSTAG = 1 ;
> :BOTTOM-TOP_PATCH_END_UNSTAG = 40 ;
> :BOTTOM-TOP_PATCH_START_STAG = 1 ;
> :BOTTOM-TOP_PATCH_END_STAG = 41 ;
> :GRID_ID = 3 ;
> :PARENT_ID = 2 ;
> :I_PARENT_START = 85 ;
> :J_PARENT_START = 58 ;
> :PARENT_GRID_RATIO = 3 ;
> :DT = 5.f ;
> :CEN_LAT = 53.37321f ;
> :CEN_LON = -6.254578f ;
> :TRUELAT1 = 53.3498f ;
> :TRUELAT2 = 53.3498f ;
> :MOAD_CEN_LAT = 54.5f ;
> :STAND_LON = -6.2603f ;
> :POLE_LAT = 90.f ;
> :POLE_LON = 0.f ;
> :GMT = 0.f ;
> :JULYR = 2016 ;
> :JULDAY = 320 ;
> :MAP_PROJ = 1 ;
> :MAP_PROJ_CHAR = "Lambert Conformal" ;
> :MMINLU = "" ;
> :NUM_LAND_CAT = 21 ;
> :ISWATER = 16 ;
> :ISLAKE = -1 ;
> :ISICE = 24 ;
> :ISURBAN = 1 ;
> :ISOILWATER = 14 ;
> :HYBRID_OPT = 2 ;
> :ETAC = 0.2f ;
>
>
> Any help would be much appreciated.
>
> best regards,
>
> Tabish
>
>
> *Tabish U Ansari*
>
> *Postdoctoral Researcher *
>
> *Centre for Climate and Air Pollution Studies (C-CAPS)*
> *School of Physics, NUI-Galway**, Ireland*
> *ResearchGate <https://www.researchgate.net/profile/Tabish_Ansari> |
> Google Scholar
> <https://scholar.google.com/citations?user=E94r-mwAAAAJ&hl=en&oi=ao> |
> Twitter <https://twitter.com/tabishbiet> | Github
> <https://github.com/tabishumaransari/NCL-scripts>*
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk



-- 
Adam Phillips
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/   303-497-1726

<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200826/a7cbb7a6/attachment.html>


More information about the ncl-talk mailing list