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

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

<p>Thank you very much in deed.</p>

<p>my wrfinput file format:</p>

<pre><code>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 ;
</code></pre>

<p>///////////////////////////////my netcdf file:</p>

<pre><code>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 ;
</code></pre>

<p>/////////////////////////////////////////////////////////</p>

<p>it hasn't the same attribute  </p>

CC BY-SA 4.0
2020-03-13T13:18:35.823Z
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
CC BY-SA 4.0
2020-03-13T13:22:29.400Z
For the work within Python I would suggest the [Python netCDF library by Unidata](https://unidata.github.io/netcdf4-python/). There are two netCDF packages available for R. Both are not officially made by Unidata. I personally prefer [ncdf4](https://cran.r-project.org/package=ncdf4). There is also [RNetCDF](https://cran.r-project.org/package=RNetCDF). I mention Unidata explicitly because develop the netCDF-C, -C++ and -Fortran Libraries.
daniel.heydebreck
CC BY-SA 4.0
2020-03-13T14:13:25.160Z
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
CC BY-SA 4.0
2020-03-13T14:22:28.017Z
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
CC BY-SA 4.0
2020-03-13T14:54:54.997Z
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
CC BY-SA 4.0
2020-03-13T20:26:23.247Z
You should be able to attach certain file types (e.g. text files with netCDF headers). I think you just move them via the mouse pointer into text field of your question (when editing it). As I said: DateStrLen is no attribute but a dimension. Regarding the levels: you can also do vertical interpolation with CDO. Unfortunately, I won't be able to reply the next days because I will be in a region bis bad internet access.
daniel.heydebreck
CC BY-SA 4.0
2020-03-14T07:26:19.643Z
thanks dear daniel.neumann... i will attach file types
sara
<netcdf>
how can I write my netCDF file in my wrfinput_d01 format
sara
# how can I write my netCDF file in my wrfinput_d01 format

(Asked by: username_0 on 2020-03-13)

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

**Tags:** netcdf

> **Comments:**
> **username_1**: 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.  
> **username_1**: For the work within Python I would suggest the [Python netCDF library by Unidata](https://unidata.github.io/netcdf4-python/). There are two netCDF packages available for R. Both are not officially made by Unidata. I personally prefer [ncdf4](https://cran.r-project.org/package=ncdf4). There is also [RNetCDF](https://cran.r-project.org/package=RNetCDF). I mention Unidata explicitly because develop the netCDF-C, -C++ and -Fortran Libraries.  
> **username_0**: 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 ;**      **)  
> **username_1**: 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?  
> **username_0**: 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!!!  
> **username_1**: You should be able to attach certain file types (e.g. text files with netCDF headers). I think you just move them via the mouse pointer into text field of your question (when editing it). As I said: DateStrLen is no attribute but a dimension. Regarding the levels: you can also do vertical interpolation with CDO. Unfortunately, I won't be able to reply the next days because I will be in a region bis bad internet access.  
> **username_0**: thanks dear daniel.neumann... i will attach file types  

---

## 0 answers

