24
24
programming interface "mpp_io_mod"
25
25
(http://www.gfdl.noaa.gov/~vb/mpp_io.html) by V. Balaji.
26
26
27
+ V2.2.8: Hans.Vahlenkamp@noaa.gov
28
+ If no netCDF format is specified (no -64 or -n4 options) for the
29
+ output file then use the netCDF format of the first input file;
30
+ use netCDF3 64-bit offset format or netCDF4 classic format.
27
31
V2.2.7: Hans.Vahlenkamp@noaa.gov
28
32
Synchronize output file before closing and check for errors.
29
33
V2.2.6: Seth Underwood <Seth.Underwood@noaa.gov>
@@ -184,8 +188,8 @@ static unsigned long maxrss = 0; /* maximum memory used so far in kilobytes */
184
188
static int print_mem_usage = 0 ;
185
189
static unsigned long mem_allocated = 0 ; /* memory allocated so far */
186
190
187
- static const char version [] = "2.2.7 " ;
188
- static const char last_updated [] = "2024-09-25 " ;
191
+ static const char version [] = "2.2.8 " ;
192
+ static const char last_updated [] = "2024-12-05 " ;
189
193
190
194
static unsigned long estimated_maxrss = 0 ; /* see option: -x */
191
195
static int mem_dry_run = 0 ; /* set if -x option is used */
@@ -366,37 +370,38 @@ int main(int argc, char *argv[])
366
370
/* Disable fatal returns from netCDF library functions */
367
371
ncopts = 0 ;
368
372
369
- if (!mem_dry_run ) {
370
- /* Create a new netCDF output file */
371
- if ((ncoutfile = (struct fileinfo * )malloc (sizeof (struct fileinfo )))== NULL )
372
- {
373
- fprintf (stderr ,"Error: cannot allocate enough memory!\n" ); return (1 );
374
- }
375
- if (!appendnc )
376
- {
377
- if (stat (outfilename ,& statbuf )== 0 )
378
- {
379
- fprintf (stderr ,"Error: output file seems to exist already!\n" );
380
- free (ncoutfile ); return (1 );
381
- }
382
- status = nc__create (outfilename , format , 0 , & blksz , & ncoutfile -> ncfid );
383
- if (status == (-1 ))
384
- {
385
- fprintf (stderr ,"Error: cannot create the output netCDF file!\n" );
386
- free (ncoutfile ); return (1 );
387
- }
388
- ncsetfill (ncoutfile -> ncfid ,NC_NOFILL );
389
- }
390
- /* Open an existing netCDF file for appending */
391
- else
392
- {
393
- if ((ncoutfile -> ncfid = ncopen (outfilename ,NC_WRITE ))== (-1 ))
394
- {
395
- fprintf (stderr ,"Error: cannot open the output netCDF file for appending!\n" );
396
- free (ncoutfile ); return (1 );
397
- }
398
- }
399
- }
373
+ if (!mem_dry_run )
374
+ {
375
+ /* Create a new netCDF output file */
376
+ if ((ncoutfile = (struct fileinfo * )malloc (sizeof (struct fileinfo )))== NULL )
377
+ {
378
+ fprintf (stderr ,"Error: cannot allocate enough memory!\n" ); return (1 );
379
+ }
380
+ if (!appendnc )
381
+ {
382
+ if (stat (outfilename ,& statbuf )== 0 )
383
+ {
384
+ fprintf (stderr ,"Error: output file seems to exist already!\n" );
385
+ free (ncoutfile ); return (1 );
386
+ }
387
+ status = nc__create (outfilename , format , 0 , & blksz , & ncoutfile -> ncfid );
388
+ if (status == (-1 ))
389
+ {
390
+ fprintf (stderr ,"Error: cannot create the output netCDF file!\n" );
391
+ free (ncoutfile ); return (1 );
392
+ }
393
+ ncsetfill (ncoutfile -> ncfid ,NC_NOFILL );
394
+ }
395
+ /* Open an existing netCDF file for appending */
396
+ else
397
+ {
398
+ if ((ncoutfile -> ncfid = ncopen (outfilename ,NC_WRITE ))== (-1 ))
399
+ {
400
+ fprintf (stderr ,"Error: cannot open the output netCDF file for appending!\n" );
401
+ free (ncoutfile ); return (1 );
402
+ }
403
+ }
404
+ }
400
405
401
406
/* No input files are specified on the command-line */
402
407
if (inputarg == (-1 ))
@@ -740,6 +745,7 @@ int process_file(char *ncname, unsigned char appendnc,
740
745
{
741
746
struct fileinfo * ncinfile ; /* Information about an input netCDF file */
742
747
int nfiles2 ; /* Number of files in the decomposed domain */
748
+ int ncinformat , ncoutformat ; /* Format of input and output netCDF files */
743
749
int d , v , n ; /* Loop variables */
744
750
int dimid ; /* ID of a dimension */
745
751
int decomp [4 ]; /* "domain_decomposition = #0, #1, #2, #3" attribute */
@@ -749,6 +755,7 @@ int process_file(char *ncname, unsigned char appendnc,
749
755
/* #3 ending position of decomposed dimension */
750
756
char attname [MAX_NC_NAME ]; /* Name of a global or variable attribute */
751
757
unsigned char ncinfileerror = 0 ; /* Were there any file errors? */
758
+ size_t blksz = 65536 ; /* netCDF block size */
752
759
753
760
if (print_mem_usage ) check_mem_usage ();
754
761
@@ -878,6 +885,48 @@ int process_file(char *ncname, unsigned char appendnc,
878
885
{
879
886
if (verbose ) printf (" Creating output \"%s\"\n" ,outncname );
880
887
888
+ /* Determine the format of the input netCDF file */
889
+ if (nc_inq_format (ncinfile -> ncfid ,& ncinformat )== (-1 ))
890
+ {
891
+ fprintf (stderr ,"Error: cannot read the input file format!\n" );
892
+ ncclose (ncinfile -> ncfid ); free (ncinfile ); return (1 );
893
+ }
894
+
895
+ /* Determine the format of the output netCDF file */
896
+ if (nc_inq_format (ncoutfile -> ncfid ,& ncoutformat )== (-1 ))
897
+ {
898
+ fprintf (stderr ,"Error: cannot read the output file format!\n" );
899
+ ncclose (ncinfile -> ncfid ); free (ncinfile ); return (1 );
900
+ }
901
+
902
+ if (verbose ) printf (" ncinformat=%d, ncoutformat=%d\n" ,ncinformat ,ncoutformat );
903
+
904
+ /* If the format option (-64 or -n4) for the output netCDF file is not specified then */
905
+ /* recreate the output netCDF file based upon the format of the input netCDF file */
906
+ if (ncoutformat == NC_FORMAT_CLASSIC )
907
+ {
908
+ if (ncinformat == NC_FORMAT_CLASSIC || ncinformat == NC_FORMAT_64BIT_OFFSET )
909
+ {
910
+ ncoutformat = (NC_CLOBBER | NC_64BIT_OFFSET );
911
+ if (verbose ) printf (" ncoutformat reset to NC_64BIT_OFFSET \n" );
912
+ }
913
+ else
914
+ {
915
+ if (ncinformat == NC_FORMAT_NETCDF4 || ncinformat == NC_FORMAT_NETCDF4_CLASSIC )
916
+ {
917
+ ncoutformat = (NC_CLOBBER | NC_NETCDF4 | NC_CLASSIC_MODEL );
918
+ if (verbose ) printf (" ncoutformat reset to NC_NETCDF4 with NC_CLASSIC_MODEL\n" );
919
+ }
920
+ }
921
+ ncclose (ncoutfile -> ncfid );
922
+ if (nc__create (outncname ,ncoutformat ,0 ,& blksz ,& ncoutfile -> ncfid )== (-1 ))
923
+ {
924
+ fprintf (stderr ,"Error: cannot create the output netCDF file!\n" );
925
+ free (ncoutfile ); return (1 );
926
+ }
927
+ ncsetfill (ncoutfile -> ncfid ,NC_NOFILL );
928
+ }
929
+
881
930
/* Define the dimensions */
882
931
for (d = 0 ; d < ncinfile -> ndims ; d ++ )
883
932
{
@@ -948,7 +997,6 @@ int process_file(char *ncname, unsigned char appendnc,
948
997
}
949
998
}
950
999
951
-
952
1000
/* Definitions done */
953
1001
nc__enddef (ncoutfile -> ncfid ,headerpad ,4 ,0 ,4 );
954
1002
}
0 commit comments