[ncl-talk] string argument to user defined function
Rick Brownrigg
brownrig at ucar.edu
Thu Feb 20 07:41:13 MST 2020
Hi Tabish,
I *think* the notation for what you want to do is:
* var_a1_00z_Oct = a1_00z_Oct ->$var$*
*Rick*
On Thu, Feb 20, 2020 at 7:24 AM Tabish Ansari via ncl-talk <
ncl-talk at ucar.edu> wrote:
> Hi
>
> I need to repeat a dimension averaging and sum operation over several
> variables inside netcdf file that I'm reading through addfiles function. I
> have written a user defined function for the same and want to call it with
> the names of different variables present in the file. However, NCL isn't
> accepting string arguments to be used directly as variable names to read
> off the file.
>
> Here's my script
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *;THIS SCRIPT COMPUTES TOTAL EMISSION FLUX PER SPECIES FOR EACH MODEL
> DOMAINbegin;DOMAIN 1a1_00z_Oct =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_00z_d01_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_00z_d01_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc>","r")a1_12z_Oct
> =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_12z_d01_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_12z_d01_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc>","r")a1_00z_Nov
> =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_00z_d01_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_00z_d01_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc>","r")a1_12z_Nov
> =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_12z_d01_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_12z_d01_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc>","r");DOMAIN
> 2a2_00z_Oct =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_00z_d02_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_00z_d02_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc>","r")a2_12z_Oct
> =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_12z_d02_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_12z_d02_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc>","r")a2_00z_Nov
> =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_00z_d02_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_00z_d02_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc>","r")a2_12z_Nov
> =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_12z_d02_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_12z_d02_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc>","r");DOMAIN
> 3a3_00z_Oct =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_00z_d03_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_00z_d03_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc>","r")a3_12z_Oct
> =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_12z_d03_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_12z_d03_total_Oct_8lev_0.5BTHso2_so4_allnormal.nc>","r")a3_00z_Nov
> =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_00z_d03_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_00z_d03_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc>","r")a3_12z_Nov
> =
> addfile("/data3/tabish/vert-MEIC-emis/APEC-wrfchemi/wrfchemi_12z_d03_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc
> <http://wrfchemi_12z_d03_total_Nov_8lev_0.5BTHso2_so4_allnormal.nc>","r");FUNCTION
> TO SUM ACROSS 8 VERT LEVELS THEN AVERAGE OVER
> LAT,LONG,TIMEundef("avgsum")function avgsum(var:string)begin var_a1_00z_Oct
> = a1_00z_Oct ->var var_a1_00z_Oct_vsum =
> dim_sum_n_Wrap(var_a1_00z_Oct,1) var_a1_00z_Oct_vsum_snavg =
> dim_avg_n_Wrap(var_a1_00z_Oct_vsum,1) var_a1_00z_Oct_vsum_snweavg =
> dim_avg_n_Wrap(var_a1_00z_Oct_vsum_snavg,1) var_a1_00z_Oct_vsum_snwetavg =
> dim_avg_n_Wrap(var_a1_00z_Oct_vsum_snweavg,0) var_a1_12z_Oct = a1_12z_Oct
> ->var var_a1_12z_Oct_vsum =
> dim_sum_n_Wrap(var_a1_12z_Oct,1) var_a1_12z_Oct_vsum_snavg =
> dim_avg_n_Wrap(var_a1_12z_Oct_vsum,1) var_a1_12z_Oct_vsum_snweavg =
> dim_avg_n_Wrap(var_a1_12z_Oct_vsum_snavg,1) var_a1_12z_Oct_vsum_snwetavg =
> dim_avg_n_Wrap(var_a1_12z_Oct_vsum_snweavg,0) result =
> (var_a1_00z_Oct_vsum_snwetavg +
> var_a1_12z_Oct_vsum_snwetavg)/2.0 return(result)endprint(avgsum("E_CO"))end*
>
> I am getting this error:
> fatal:["Execute.c":6397]:variable (var) is not in file (a1_00z_Oct)
> fatal:["Execute.c":8640]:Execute: Error occurred at or near line 27 in
> file emistotals.ncl
>
> fatal:["Execute.c":8640]:Execute: Error occurred at or near line 44 in
> file emistotals.ncl
>
> 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
> <https://www.researchgate.net/profile/Tabish_Ansari>*
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200220/1748d567/attachment-0001.html>
More information about the ncl-talk
mailing list