# how can I write my netCDF file in my wrfinput_d01 format

I have a netCDF data file as my emmission data in netCDF format. I have interpolated it in my wrfinput_d01 resolution by using CDO. I can write my data to a netCDF file but, I would like to write it in netCDF file like wrfinput_d01, and change the attributed file to my wrfinput_d01 (time, datestrlen, zdim, ...), (of curse, I shold say that I have my data in first layer of wrf-model ,beacuse they are emissions and wouldn't like to be in 64 level.)...

• How can I write netCDF file from my data, like "wrfinput_d01 " in R or matlab or python?
• Does any one know?
• I have my emission data in the wrfinput resolution, but the netCDF file doesn't look like wrfinput_d01? :(

Thank you very much in deed.

my wrfinput file format:

netcdf wrfinput_d01 {
dimensions:
Time = UNLIMITED ; // (1 currently)
**DateStrLen = 19 ;**      **???????**
west_east = 173 ;       **??????**
south_north = 124 ;        **???????**
bottom_top = 64 ;
bottom_top_stag = 65 ;
soil_layers_stag = 4 ;
west_east_stag = 174 ;
south_north_stag = 125 ;
DIM0009 = 5 ;
land_cat_stag = 21 ;
soil_cat_stag = 16 ;
num_ext_model_couple_dom_stag = 1 ;
dust_erosion_dimension = 3 ;
klevs_for_fire = 1 ;
variables:
float TH2(Time, south_north, west_east) ;
TH2:FieldType = 104 ;
TH2:MemoryOrder = "XY " ;
TH2:description = "POT TEMP at 2 M" ;
TH2:units = "K" ;
TH2:stagger = "" ;
TH2:coordinates = "XLONG XLAT XTIME" ;
.
.
.
// **global attributes: ?????????????????????**
:TITLE = " OUTPUT FROM REAL_EM V3.9.1.1 PREPROCESSOR" ;
:START_DATE = "2010-08-28_12:00:00" ;
:SIMULATION_START_DATE = "2010-08-28_12:00:00" ;
:WEST-EAST_GRID_DIMENSION = 174 ;
:SOUTH-NORTH_GRID_DIMENSION = 125 ;
:BOTTOM-TOP_GRID_DIMENSION = 65 ;
:DX = 30000.f ;
:DY = 30000.f ;
:GRIDTYPE = "C" ;
:DIFF_OPT = 2 ;
:KM_OPT = 4 ;
:DAMP_OPT = 0 ;
:DAMPCOEF = 0.2f ;


///////////////////////////////my netcdf file:

dimensions:
Lon = 21452 ;
Lat = 21452 ;
Time = UNLIMITED ; // (1 currently)
variables:
double Lon(Lon) ;
Lon:units = "degrees" ;
Lon:long_name = "Lon" ;
double Lat(Lat) ;
Lat:units = "degrees" ;
Lat:long_name = "Lat" ;
double Time(Time) ;
Time:units = "days since 2010-08-28" ;
Time:long_name = "Time" ;
float E_CO2(Time, Lat, Lon) ;
E_CO2:units = "mol km**-2 hr**-1" ;
E_CO2:_FillValue = 1.e+30f ;


/////////////////////////////////////////////////////////

it hasn't the same attribute

• Could you also add the header of your interpolated file? When you say that the attributes are not the same. Do you mean that they have different names? Or that they are different ones by meaning? For attribute modification I tend to use ncatted of the NCOs (netCDF Operators). Wie ncatted you can easily add, remove and modify attributes (global and of variables). If you need to rename things (dimensions, variables or attributes), you can use ncrename of the NCOs. The usage of both tools is quite straight forward. – daniel.heydebreck Mar 13 '20 at 13:18
• For the work within Python I would suggest the Python netCDF library by Unidata. There are two netCDF packages available for R. Both are not officially made by Unidata. I personally prefer ncdf4. There is also RNetCDF. I mention Unidata explicitly because develop the netCDF-C, -C++ and -Fortran Libraries. – daniel.heydebreck Mar 13 '20 at 13:22
• thanks for the response,header of your interpolated file is in end of my question. i would like to create attributes like my wrfinput attributs in it's header file ...i woldn't like to rename variable or units. (i would like my file has same attributs ,like DateStrlen,lon,lat ,...(dimensions: Time = UNLIMITED ; // (1 currently) DateStrLen = 19 ; **) – sara Mar 13 '20 at 14:13
• These are dimensions and not attributes. Commonly, a dimension only exist when there is a variable using it. You could simply copy this variable from the old to the new file. E.g. via ncks -A -v VARNAME OLD_WRF_FILE NEW_WRF_FILE. VARNAME has to be replaced by the respective variable name. OLD_WRF_FILE and NEW_WRF_FILE have to be replaced by the file names. Could you upload the full netCDF files headers (ncdump -h) as text files? – daniel.heydebreck Mar 13 '20 at 14:22
• thank you very much for your helping. you know my wrfinput_d01 has 27 level.my emission data file as you know are in the first layer of model(just have one level). I thought first I should extract some variable from my wrfinput_d01 in new file.then open it in Matlab and replace my emission file date to it and save it. but my problem is their levels. are not in the same levels.and DateStrLen and another attribute---how can I apload both of my files(my emission and my wrfinput_d01)? here we can't apload our files!!! – sara Mar 13 '20 at 14:54