Alex, > I have to read a NetCDF file in which a variable (LONGITUDE) is defined, with > attributes, but in the values part of the file there is no data for this > variable (the variable doesn't exist in fact) > > The code I user is : > > $l_varId = NetCDF::varid($p_file, $p_variable); > $l_status = NetCDF::varinq($p_file, $l_varId, \$l_name, \$l_datatype, > \$l_dimCount, address@hidden, \$l_atts); > if ($l_status == -1) > { > Print "$p_variable doesn't exist\n"; > } > else > { > $l_status = $TRUE; > $l_dimSizes[$l_dimCount - 1] = undef; > NetCDF::diminq($p_file, $l_dimIds[0], \$l_name, \$l_dimSizes[0]); > NetCDF::varget($p_file, $l_varId, [0], [$l_dimSizes[0]], address@hidden); > } > > And I get the following message : "ncvarget: ncid 10; varid 20: Index exceeds > dimension bound" and the script stops immediately. > > I tried the same with an "eval block" like ths : > > $l_varId = NetCDF::varid($p_file, $p_variable); > $l_status = NetCDF::varinq($p_file, $l_varId, \$l_name, \$l_datatype, > \$l_dimCount, address@hidden, \$l_atts); > if ($l_status == -1) > { > Print "Error reading $p_variable\n"; > } > else > { > $l_status = $TRUE; > $l_dimSizes[$l_dimCount - 1] = undef; > NetCDF::diminq($p_file, $l_dimIds[0], \$l_name, \$l_dimSizes[0]); > eval > { > NetCDF::varget($p_file, $l_varId, [0], [$l_dimSizes[0]], address@hidden); > }; > if($@) > { > CoScrReport::SendError("Variable $p_variable has no values : $@"); > } > } > > But I still have the same error message and the script stops. > > Questions : how can I catch the error to write an user friendly error > message and that the script doesn't stops immediately ? You have to use the NetCDF::opts(i) function to tell the netCDF library not to exit if an error occurs. Valid values are 0, NetCDF::FATAL (1), NetCDF::VERBOSE (2), or a bitwise OR of these values. I would call NetCDF::opts(0). > Thanks for your response. > > Best regards > > Alex THEPAUT Regards, Steve Emmerson Ticket Details =================== Ticket ID: GTU-862479 Department: Support netCDF Perl Priority: Normal Status: Closed
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.