@@ -118,8 +118,8 @@ static struct FORMATMODES {
118118{"classic" ,NC_FORMATX_NC3 ,0 }, /* ditto */
119119{"netcdf-4" ,NC_FORMATX_NC4 ,NC_FORMAT_NETCDF4 },
120120{"enhanced" ,NC_FORMATX_NC4 ,NC_FORMAT_NETCDF4 },
121- {"udf0" ,NC_FORMATX_UDF0 ,NC_FORMAT_NETCDF4 },
122- {"udf1" ,NC_FORMATX_UDF1 ,NC_FORMAT_NETCDF4 },
121+ {"udf0" ,NC_FORMATX_UDF0 ,0 },
122+ {"udf1" ,NC_FORMATX_UDF1 ,0 },
123123{"nczarr" ,NC_FORMATX_NCZARR ,NC_FORMAT_NETCDF4 },
124124{"zarr" ,NC_FORMATX_NCZARR ,NC_FORMAT_NETCDF4 },
125125{"bytes" ,NC_FORMATX_NC4 ,NC_FORMAT_NETCDF4 }, /* temporary until 3 vs 4 is determined */
@@ -182,8 +182,8 @@ static struct Readable {
182182{NC_FORMATX_PNETCDF ,1 },
183183{NC_FORMATX_DAP2 ,0 },
184184{NC_FORMATX_DAP4 ,0 },
185- {NC_FORMATX_UDF0 ,0 },
186- {NC_FORMATX_UDF1 ,0 },
185+ {NC_FORMATX_UDF0 ,1 },
186+ {NC_FORMATX_UDF1 ,1 },
187187{NC_FORMATX_NCZARR ,0 }, /* eventually make readable */
188188{0 ,0 },
189189};
@@ -762,13 +762,31 @@ NC_omodeinfer(int useparallel, int cmode, NCmodel* model)
762762 * use some of the other flags, like NC_NETCDF4, so we must first
763763 * check NC_UDF0 and NC_UDF1 before checking for any other
764764 * flag. */
765- if (fIsSet (cmode ,(NC_UDF0 |NC_UDF1 ))) {
766- model -> format = NC_FORMAT_NETCDF4 ;
767- if (fIsSet (cmode ,NC_UDF0 )) {
765+ if (fIsSet (cmode , NC_UDF0 ) || fIsSet (cmode , NC_UDF1 ))
766+ {
767+ if (fIsSet (cmode , NC_UDF0 ))
768+ {
768769 model -> impl = NC_FORMATX_UDF0 ;
769770 } else {
770771 model -> impl = NC_FORMATX_UDF1 ;
771772 }
773+ if (fIsSet (cmode ,NC_64BIT_OFFSET ))
774+ {
775+ model -> format = NC_FORMAT_64BIT_OFFSET ;
776+ }
777+ else if (fIsSet (cmode ,NC_64BIT_DATA ))
778+ {
779+ model -> format = NC_FORMAT_64BIT_DATA ;
780+ }
781+ else if (fIsSet (cmode ,NC_NETCDF4 ))
782+ {
783+ if (fIsSet (cmode ,NC_CLASSIC_MODEL ))
784+ model -> format = NC_FORMAT_NETCDF4_CLASSIC ;
785+ else
786+ model -> format = NC_FORMAT_NETCDF4 ;
787+ }
788+ if (! model -> format )
789+ model -> format = NC_FORMAT_CLASSIC ;
772790 goto done ;
773791 }
774792
@@ -981,8 +999,6 @@ NC_infermodel(const char* path, int* omodep, int iscreate, int useparallel, void
981999 case NC_FORMATX_NC4 :
9821000 case NC_FORMATX_NC_HDF4 :
9831001 case NC_FORMATX_DAP4 :
984- case NC_FORMATX_UDF0 :
985- case NC_FORMATX_UDF1 :
9861002 case NC_FORMATX_NCZARR :
9871003 omode |= NC_NETCDF4 ;
9881004 if (model -> format == NC_FORMAT_NETCDF4_CLASSIC )
@@ -1001,6 +1017,17 @@ NC_infermodel(const char* path, int* omodep, int iscreate, int useparallel, void
10011017 case NC_FORMATX_DAP2 :
10021018 omode &= ~(NC_NETCDF4 |NC_64BIT_OFFSET |NC_64BIT_DATA |NC_CLASSIC_MODEL );
10031019 break ;
1020+ case NC_FORMATX_UDF0 :
1021+ case NC_FORMATX_UDF1 :
1022+ if (model -> format == NC_FORMAT_64BIT_OFFSET )
1023+ omode |= NC_64BIT_OFFSET ;
1024+ else if (model -> format == NC_FORMAT_64BIT_DATA )
1025+ omode |= NC_64BIT_DATA ;
1026+ else if (model -> format == NC_FORMAT_NETCDF4 )
1027+ omode |= NC_NETCDF4 ;
1028+ else if (model -> format == NC_FORMAT_NETCDF4_CLASSIC )
1029+ omode |= NC_NETCDF4 |NC_CLASSIC_MODEL ;
1030+ break ;
10041031 default :
10051032 {stat = NC_ENOTNC ; goto done ;}
10061033 }
@@ -1513,23 +1540,10 @@ static int
15131540NC_interpret_magic_number (char * magic , NCmodel * model )
15141541{
15151542 int status = NC_NOERR ;
1543+ int tmpimpl = 0 ;
15161544 /* Look at the magic number */
1517- #ifdef USE_NETCDF4
1518- if (strlen (UDF0_magic_number ) && !strncmp (UDF0_magic_number , magic ,
1519- strlen (UDF0_magic_number )))
1520- {
1521- model -> impl = NC_FORMATX_UDF0 ;
1522- model -> format = NC_FORMAT_NETCDF4 ;
1523- goto done ;
1524- }
1525- if (strlen (UDF1_magic_number ) && !strncmp (UDF1_magic_number , magic ,
1526- strlen (UDF1_magic_number )))
1527- {
1528- model -> impl = NC_FORMATX_UDF1 ;
1529- model -> format = NC_FORMAT_NETCDF4 ;
1530- goto done ;
1531- }
1532- #endif /* USE_NETCDF4 */
1545+ if (model -> impl == NC_FORMATX_UDF0 || model -> impl == NC_FORMATX_UDF1 )
1546+ tmpimpl = model -> impl ;
15331547
15341548 /* Use the complete magic number string for HDF5 */
15351549 if (memcmp (magic ,HDF5_SIGNATURE ,sizeof (HDF5_SIGNATURE ))== 0 ) {
@@ -1561,10 +1575,29 @@ NC_interpret_magic_number(char* magic, NCmodel* model)
15611575 }
15621576 }
15631577 /* No match */
1564- status = NC_ENOTNC ;
1578+ if (!tmpimpl )
1579+ status = NC_ENOTNC ;
1580+
15651581 goto done ;
15661582
15671583done :
1584+ /* if model->impl was UDF0 or UDF1 on entry, make it so on exit */
1585+ if (tmpimpl )
1586+ model -> impl = tmpimpl ;
1587+ /* if this is a UDF magic_number update the model->impl */
1588+ if (strlen (UDF0_magic_number ) && !strncmp (UDF0_magic_number , magic ,
1589+ strlen (UDF0_magic_number )))
1590+ {
1591+ model -> impl = NC_FORMATX_UDF0 ;
1592+ status = NC_NOERR ;
1593+ }
1594+ if (strlen (UDF1_magic_number ) && !strncmp (UDF1_magic_number , magic ,
1595+ strlen (UDF1_magic_number )))
1596+ {
1597+ model -> impl = NC_FORMATX_UDF1 ;
1598+ status = NC_NOERR ;
1599+ }
1600+
15681601 return check (status );
15691602}
15701603
0 commit comments