create_netcdf.c

Go to the documentation of this file.
00001 /* ***************************************************** */
00002 /* create_netcdf Create a new NetCDF file with global    */
00003 /*               CF_1.0 attributes.                      */
00004 /* create_netcdf.c                                       */
00005 /* ***************************************************** */
00006 /* Author: Christian Page, CERFACS, Toulouse, France.    */
00007 /* ***************************************************** */
00008 /* Date of creation: oct 2008                            */
00009 /* Last date of modification: oct 2008                   */
00010 /* ***************************************************** */
00011 /* Original version: 1.0                                 */
00012 /* Current revision:                                     */
00013 /* ***************************************************** */
00014 /* Revisions                                             */
00015 /* ***************************************************** */
00020 /* LICENSE BEGIN
00021 
00022 Copyright Cerfacs (Christian Page) (2015)
00023 
00024 christian.page@cerfacs.fr
00025 
00026 This software is a computer program whose purpose is to downscale climate
00027 scenarios using a statistical methodology based on weather regimes.
00028 
00029 This software is governed by the CeCILL license under French law and
00030 abiding by the rules of distribution of free software. You can use, 
00031 modify and/ or redistribute the software under the terms of the CeCILL
00032 license as circulated by CEA, CNRS and INRIA at the following URL
00033 "http://www.cecill.info". 
00034 
00035 As a counterpart to the access to the source code and rights to copy,
00036 modify and redistribute granted by the license, users are provided only
00037 with a limited warranty and the software's author, the holder of the
00038 economic rights, and the successive licensors have only limited
00039 liability. 
00040 
00041 In this respect, the user's attention is drawn to the risks associated
00042 with loading, using, modifying and/or developing or reproducing the
00043 software by the user in light of its specific status of free software,
00044 that may mean that it is complicated to manipulate, and that also
00045 therefore means that it is reserved for developers and experienced
00046 professionals having in-depth computer knowledge. Users are therefore
00047 encouraged to load and test the software's suitability as regards their
00048 requirements in conditions enabling the security of their systems and/or 
00049 data to be ensured and, more generally, to use and operate it in the 
00050 same conditions as regards security. 
00051 
00052 The fact that you are presently reading this means that you have had
00053 knowledge of the CeCILL license and that you accept its terms.
00054 
00055 LICENSE END */
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 #include <io.h>
00064 
00066 int
00067 create_netcdf(char *title, char *title_french, char *summary, char *summary_french,
00068               char *keywords, char *processor, char *software, char *description, char *institution,
00069               char *creator_email, char *creator_url, char *creator_name,
00070               char *version, char *scenario, char *scenario_co2, char *model,
00071               char *institution_model, char *country, char *member, char *downscaling_forcing,
00072               char *contact_email, char *contact_name, char *other_contact_email, char *other_contact_name,
00073               char *filename, int outinfo, int format, int compression) {
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