create_netcdf.c File Reference

Create a new NetCDF file with global CF-1.0 attributes. More...

#include <io.h>
Include dependency graph for create_netcdf.c:

Go to the source code of this file.

Functions

int create_netcdf (char *title, char *title_french, char *summary, char *summary_french, char *keywords, char *processor, char *software, char *description, char *institution, char *creator_email, char *creator_url, char *creator_name, char *version, char *scenario, char *scenario_co2, char *model, char *institution_model, char *country, char *member, char *downscaling_forcing, char *contact_email, char *contact_name, char *other_contact_email, char *other_contact_name, char *filename, int outinfo, int format, int compression)
 Create a new NetCDF file with global CF-1.0 attributes.

Detailed Description

Create a new NetCDF file with global CF-1.0 attributes.

Definition in file create_netcdf.c.


Function Documentation

int create_netcdf ( char *  title,
char *  title_french,
char *  summary,
char *  summary_french,
char *  keywords,
char *  processor,
char *  software,
char *  description,
char *  institution,
char *  creator_email,
char *  creator_url,
char *  creator_name,
char *  version,
char *  scenario,
char *  scenario_co2,
char *  model,
char *  institution_model,
char *  country,
char *  member,
char *  downscaling_forcing,
char *  contact_email,
char *  contact_name,
char *  other_contact_email,
char *  other_contact_name,
char *  filename,
int  outinfo,
int  format,
int  compression 
)

Create a new NetCDF file with global CF-1.0 attributes.

Parameters:
[in] title Title (english)
[in] title_french Title (french)
[in] summary Summary (english)
[in] summary_french Summary *french)
[in] keywords Keyword
[in] processor Program, processor which have generated the data
[in] software Software and version which have generated the data
[in] description Main description of the data
[in] institution Institution which generated the data
[in] creator_email Contact email of the creator of the data
[in] creator_url Website creator of the data
[in] creator_name Name of the creator of the data
[in] version Version of the data
[in] scenario Climate scenario
[in] scenario_co2 CO2 scenario
[in] model Numerical model used
[in] institution_model Institution who developed the numerical model used
[in] country Country of the institution who developed the numerical model used
[in] member Member in the case of multi-member model configurations
[in] downscaling_forcing Observations database used when downscaling
[in] contact_email Contact email
[in] contact_name Contact name
[in] other_contact_email Other contact email
[in] other_contact_name Other contact name
[in] filename NetCDF output filename
[in] outinfo TRUE if we want information output, FALSE if not
[in] format File format version for NetCDF
[in] compression Compression flag for NetCDF-4 file format
Returns:
Status.

Definition at line 67 of file create_netcdf.c.

References alloc_error(), handle_netcdf_error(), MAXPATH, and TRUE.

Referenced by output_downscaled_analog(), and remove_clim().

00073                                                                         {
00107   int istat = 0; /* Diagnostic status */
00108   int ncoutid; /* NetCDF output file handle ID */
00109   char *tmpstr = NULL; /* Temporary string */
00110 
00111   if (outinfo == TRUE)
00112     (void) fprintf(stdout, "%s: Creating NetCDF file %s\n", __FILE__, filename);
00113 
00114   /* Allocate memory */
00115   tmpstr = (char *) malloc(MAXPATH * sizeof(char));
00116   if (tmpstr == NULL) alloc_error(__FILE__, __LINE__);
00117 
00118   /* Open NetCDF file for writing, overwrite and truncate existing file if any */
00119   if (format == 4 && compression == TRUE)
00120 #ifdef NC_NETCDF4
00121     istat = nc_create(filename, NC_CLOBBER | NC_NETCDF4 | NC_CLASSIC_MODEL, &ncoutid);
00122 #else
00123     istat = nc_create(filename, NC_CLOBBER, &ncoutid);
00124 #endif
00125   else
00126 #ifdef NC_NETCDF4
00127     if (format == 4)
00128       istat = nc_create(filename, NC_CLOBBER | NC_NETCDF4 | NC_CLASSIC_MODEL, &ncoutid);
00129     else
00130       istat = nc_create(filename, NC_CLOBBER, &ncoutid);
00131 #else
00132     istat = nc_create(filename, NC_CLOBBER, &ncoutid);
00133 #endif
00134     //    istat = nc_create(filename, NC_CLOBBER, &ncoutid);
00135   if (istat != NC_NOERR) handle_netcdf_error(istat, __FILE__, __LINE__);
00136 
00137   /* Set global attributes */
00138   (void) strcpy(tmpstr, "CF-1.0");
00139   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "Conventions", strlen(tmpstr), tmpstr);
00140   (void) strcpy(tmpstr, "Unidata Dataset Discovery v1.0");
00141   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "Metadata_Conventions", strlen(tmpstr), tmpstr);
00142   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "title", strlen(title), title);
00143   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "title_french", strlen(title_french), title_french);
00144   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "summary", strlen(summary), summary);
00145   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "summary_french", strlen(summary_french), summary_french);
00146   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "keywords", strlen(keywords), keywords);
00147   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "processor", strlen(processor), processor);
00148   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "software", strlen(software), software);
00149   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "description", strlen(description), description);
00150   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "institution", strlen(institution), institution);
00151   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "creator_email", strlen(creator_email), creator_email);
00152   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "creator_url", strlen(creator_url), creator_url);
00153   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "creator_name", strlen(creator_name), creator_name);
00154   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "version", strlen(version), version);
00155   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "scenario", strlen(scenario), scenario);
00156   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "scenario_co2", strlen(scenario_co2), scenario_co2);
00157   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "model", strlen(model), model);
00158   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "institution_model", strlen(institution_model), institution_model);
00159   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "country", strlen(country), country);
00160   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "member", strlen(member), member);
00161   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "downscaling_forcing", strlen(downscaling_forcing), downscaling_forcing);
00162   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "contact_email", strlen(contact_email), contact_email);
00163   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "contact_name", strlen(contact_name), contact_name);
00164   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "other_contact_email", strlen(other_contact_email), other_contact_email);
00165   istat = nc_put_att_text(ncoutid, NC_GLOBAL, "other_contact_name", strlen(other_contact_name), other_contact_name);
00166 
00167   /* End definition mode */
00168   istat = nc_enddef(ncoutid);
00169   if (istat != NC_NOERR) handle_netcdf_error(istat, __FILE__, __LINE__);
00170 
00171   /* Close the output netCDF file */
00172   istat = ncclose(ncoutid);
00173   if (istat != NC_NOERR) handle_netcdf_error(istat, __FILE__, __LINE__);
00174 
00175   /* Free memory */
00176   (void) free(tmpstr);
00177 
00178   /* Success status */
00179   return 0;
00180 }


Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1