<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>I think you have to do some debugging.<br><br>===<br></div><div><br>Look at &quot;time&quot;:    time: [20143050010..2.426116152246728e-315]<br></div>The last time is obviously wrong! How did this happen? <br></div><div>It did not happen with the 5 sample files ... why with all the files?<br></div><div><br></div><div>Each iteration thru the loop .... print the current &#39;time&#39; value. <br><br></div><div>Also ... after the loop is complete ... <br><br></div><div>print(time)   ; print all values<br><br></div><div>This issue must be cleared up!<br><br></div><div>If &#39;time&#39; is messed up ... what about other variables?<br></div><div><br></div>-------<br><br></div>In the code that reads/plots the netCDF ... did you do any debugging?? <br><br>    diri  = &quot;./&quot;<br>    fili  = &quot;<a href="http://MODIS_L2.Swath.nc">MODIS_L2.Swath.nc</a>&quot;<br>    f     = addfile(diri+fili, &quot;r&quot;)<br><br></div>    print(f)<br><br></div>    AOT = f-&gt;AOT<br></div>    printVarSummary(AOT)<br></div><div>    printMinMax(AOT,0)<br></div><div><br></div>   lat2d = f-&gt;LAT2D<br></div>   printVarSummary(LAT2D)<br></div><div>   printMinMax(lat2d,0)<br></div><div><br></div>   lon2d = f-&gt;LON2D<br></div>   printVarSummary(lon2d)<br>   printMinMax(lon2d,0)<br><br></div>Do these not match the original created values<br><div><div><div><div><div><div><div><div><div><div><div><div><br>--------<br><div>Minor: the dimension name &quot;Cell_ACross_Swath&quot;  should be &quot;Cell_Across_Swath&quot;  </div><div><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 27, 2015 at 8:34 AM, BLIUJUS, STEVEN D CTR USAF AFMC AFLCMC/HBAW-OL <span dir="ltr">&lt;<a href="mailto:steven.bliujus.3.ctr@us.af.mil" target="_blank">steven.bliujus.3.ctr@us.af.mil</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dennis the script works however for some reason the data is not getting put into the NetCDF file correctly. I have ~120 files I&#39;m going through, and when the script prints the dimensions, the following are stated:<br>
<br>
Variable: time<br>
Type: double<br>
Total Size: 2080 bytes<br>
            260 values<br>
Number of Dimensions: 1<br>
Dimensions and sizes:   [time | 260]<br>
Coordinates:<br>
            time: [20143050010..2.426116152246728e-315]<br>
Number Of Attributes: 1<br>
  long_name :   current time as YYYYDDDHHMM<br>
<br>
Variable: data<br>
Type: float<br>
Total Size: 28641600 bytes<br>
            7160400 values<br>
Number of Dimensions: 3<br>
Dimensions and sizes:   [time | 260] x [Cell_Along_Swath | 204] x [Cell_ACross_Swath | 135]<br>
Coordinates:<br>
            time: [20143050010..2.426116152246728e-315]<br>
Number Of Attributes: 2<br>
  long_name :    AOT at 0.55 micron for both ocean and land<br>
  _FillValue :  -9999<br>
(0)     data: min=-0.05   max=4.277<br>
<br>
Variable: lat2d<br>
Type: float<br>
Total Size: 28641600 bytes<br>
            7160400 values<br>
Number of Dimensions: 3<br>
Dimensions and sizes:   [time | 260] x [Cell_Along_Swath | 204] x [Cell_ACross_Swath | 135]<br>
Coordinates:<br>
            time: [20143050010..2.426116152246728e-315]<br>
Number Of Attributes: 3<br>
  units :       degrees_north<br>
  long_name :   Geodetic Latitude<br>
  _FillValue :  -999<br>
(0)     lat2d: min=-89.894   max=77.2616<br>
<br>
Variable: lon2d<br>
Type: float<br>
Total Size: 28641600 bytes<br>
            7160400 values<br>
Number of Dimensions: 3<br>
Dimensions and sizes:   [time | 260] x [Cell_Along_Swath | 204] x [Cell_ACross_Swath | 135]<br>
Coordinates:<br>
            time: [20143050010..2.426116152246728e-315]<br>
Number Of Attributes: 3<br>
  units :       degrees_east<br>
  long_name :   Geodetic Longitude<br>
  _FillValue :  -999<br>
(0)     lon2d: min=-179.999   max=179.977<br>
(0)     -----<br>
<br>
<br>
The thing that stands out is when the NetCDF file is created, the Longitude in the file only goes from 85.1406 - 172.263 and not -179.999 - 179.977 like the varSummary states. There is an error that gets thrown during the run:<br>
<br>
fatal:Dimension size mismatch on subscript #1, left-hand and right-hand side dimensions do not match<br>
fatal:[&quot;Execute.c&quot;:8128]:Execute: Error occurred at or near line 71 in file modis.ncl<br>
<br>
I have attached the image created from your script, compared to the image I get from the other script. I also reattached your script as I modified some directory things and added the libraries which shifted some of the lines. It should be noted that the information present from your script does match the data location on the image I created from a different script, it&#39;s just missing everything else.<br>
<span class="im HOEnZb"><br>
<br>
Steve<br>
<br>
-----Original Message-----<br>
From: Dennis Shea [mailto:<a href="mailto:shea@ucar.edu">shea@ucar.edu</a>]<br>
</span><div class="HOEnZb"><div class="h5">Sent: Tuesday, May 26, 2015 5:43 PM<br>
To: BLIUJUS, STEVEN D CTR USAF AFMC AFLCMC/HBAW-OL<br>
Cc: <a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
Subject: Re: [ncl-talk] Problems converting hdf to netcdf using NCL<br>
<br>
I just looked at the 5 sample files you sent ....<br>
<br>
The dimension sizes are *not* the same size across all files<br>
<br>
<br>
The 1st 4files are:<br>
<br>
<br>
MOD04_L2.A2014305.0000.006.2015077213911.pscs_000500937810.hdf<br>
  dimensions:<br>
      Cell_Along_Swath = 203       &lt;=====<br>
      Cell_Across_Swath = 135<br>
<br>
The last file is:<br>
<br>
MOD04_L2.A2014305.0500.006.2015077215106.pscs_000500937810<br>
   dimensions:<br>
      Cell_Along_Swath = 204     &lt;====<br>
      Cell_Across_Swath= 135<br>
<br>
<br>
That can be &#39;programmed around&#39;.<br>
<br>
<br>
See attached<br>
<br>
<br>
<br>
<br>
On Tue, May 26, 2015 at 6:34 AM, BLIUJUS, STEVEN D CTR USAF AFMC AFLCMC/HBAW-OL &lt;<a href="mailto:steven.bliujus.3.ctr@us.af.mil">steven.bliujus.3.ctr@us.af.mil</a>&gt; wrote:<br>
<br>
<br>
        Dennis,<br>
<br>
        #2 and #3: Cell_Along_Swath, and Cell_Across_Swath are exactly the same for every file as far as actual dimension size, the variables are not though.<br>
        #4: I am trying to create a mosaic of all the files and that is why I am wanting to generate one NetCDF file. So when I run my script the image above is what comes out. This image is what I want to create in a NetCDF file (Globe.PNG).<br>
        #5: I did this because I was following a script online that I found where I needed to give the main variable(Optical Depth) the latitude/longitude dimensions. It used (::5) which what I just followed. When I try plotting using just (:,:), the plot take an extremely long time to plot(though there is much more data prevalent)...If it is one file it doesn’t take long, but when you add them all in the mosaic form, it takes a much more substantial amount of time to generate the image.<br>
        #6: I&#39;m not sure exactly what you mean by this as there is not time field in the file.<br>
        #7: See 5 attached MODIS files<br>
        #8: I am trying to create a NetCDF file for a coworker to use for his verification software. He only reads in NetCDF files or text files (though he would prefer NetCDF files)<br>
<br>
        I also attached the script (with all previous commented lines removed) that plots the files and also creates a text table of the data.<br>
<br>
        Any help would be appreciated.<br>
<br>
        Steve<br>
<br>
<br>
<br>
        -----Original Message-----<br>
        From: Dennis Shea [mailto:<a href="mailto:shea@ucar.edu">shea@ucar.edu</a>]<br>
<br>
        Sent: Saturday, May 23, 2015 2:30 PM<br>
        To: BLIUJUS, STEVEN D CTR USAF AFMC AFLCMC/HBAW-OL<br>
        Cc: <a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
        Subject: Re: [ncl-talk] Problems converting hdf to netcdf using NCL<br>
<br>
        I have looked at this and there are *lots* of issues.<br>
<br>
        &quot;... taking several hdf files (200-400) and trying to generate one NetCDF file.&quot;<br>
<br>
<br>
        So ...  **Conceptually**, you want<br>
<br>
<br>
            AOT(time, Cell_Along_Swath, Cell_Across_Swath)<br>
<br>
<br>
        Thing  is your geographic coordinates are 2-dimensional. see below<br>
<br>
<br>
<br>
<br>
        [1]<br>
<br>
        The files contain swath data. From your dump:<br>
<br>
        path:   MOD04_L2.A2014306.2330.006.2015077230656.pscs_000500937810.hdf<br>
           file global attributes:<br>
              HDFEOSVersion : HDFEOS_V2.17<br>
              StructMetadata_0 : GROUP=SwathStructure<br>
                GROUP=SWATH_1<br>
                        SwathName=&quot;mod04&quot;<br>
<br>
<br>
        [2] Are the dimension sizes<br>
<br>
               (Cell_Along_Swath,Cell_Across_Swath) =&gt; (203,135)<br>
<br>
<br>
             exactly the same for *all* files?<br>
<br>
<br>
        [3] If [2] is satisfied  .... Are the *values* contained within the following variables<br>
<br>
               Latitude ( Cell_Along_Swath, Cell_Across_Swath)<br>
<br>
               Longitude ( Cell_Along_Swath, Cell_Across_Swath )<br>
<br>
<br>
              *exactly* the same for *all* files?  ie: homogeneous space!<br>
<br>
<br>
             My (limited) experience with satellite swath data is that the answer is &quot;no&quot;<br>
<br>
<br>
        [4] If [2] *and* [3] are not satisfied, I see no advantage of creating a single netCDF file.<br>
<br>
             You would end up with 200-400 sets of dimension sizes *and* 200-400 variables<br>
<br>
             associated 200-400two-dimensional spatial variables.<br>
<br>
<br>
        [5]  I have no idea why you are sub-sampling [decimating] the array by 5:<br>
               (::5,::5) the resolution from (203,135) to  ??(41,27)??. This seems drastic!<br>
<br>
              Sub-sampling (array decimation) is commonly used used when the resolution is (say) (2500,4000) and the data are reasonably smooth.<br>
<br>
<br>
<br>
        [6] In any case you should be using<br>
<br>
              ListSetType(a,&quot;join&quot;)<br>
<br>
<br>
             to add a record dimension ... which you should fill in with &#39;time&#39;<br>
<br>
             (parse file name) or some sequential number.<br>
<br>
<br>
             Please read<br>
                <a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml" target="_blank">https://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml</a><br>
<br>
             Example 3 illustrates what &quot;join&quot; will do.<br>
<br>
<br>
<br>
        [7] I do not have your ?MODIS? data file. Based upon your dump, I created a script that creates a netCDF file for each HDF file and (I hope) a sample graphic.<br>
<br>
<br>
        [8] I am not sure of ultimate use of the data but from an NCL perspective, there is no reason to convert to netCDF.<br>
<br>
<br>
        ===========================<br>
<br>
<br>
        Please upgrade to 6.3.0<br>
<br>
        <a href="http://www.ncl.ucar.edu/Download/" target="_blank">http://www.ncl.ucar.edu/Download/</a><br>
<br>
        ============================<br>
<br>
<br>
<br>
<br>
<br>
        On Fri, May 22, 2015 at 9:59 AM, BLIUJUS, STEVEN D CTR USAF AFMC AFLCMC/HBAW-OL &lt;<a href="mailto:steven.bliujus.3.ctr@us.af.mil">steven.bliujus.3.ctr@us.af.mil</a>&gt; wrote:<br>
<br>
<br>
                I wanted to provide an example of what is in the hdf file. See attached.<br>
<br>
                Steve<br>
<br>
<br>
                -----Original Message-----<br>
                From: <a href="mailto:ncl-talk-bounces@ucar.edu">ncl-talk-bounces@ucar.edu</a> [mailto:<a href="mailto:ncl-talk-bounces@ucar.edu">ncl-talk-bounces@ucar.edu</a>] On Behalf Of BLIUJUS, STEVEN D CTR USAF AFMC AFLCMC/HBAW-OL<br>
                Sent: Friday, May 22, 2015 10:36 AM<br>
                To: <a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
                Subject: [ncl-talk] Problems converting hdf to netcdf using NCL<br>
<br>
                I am taking several hdf files (200-400) and trying to generate one NetCDF file. I am able to plot it on a grid, but when I try to write to a NetCDF file, I get the following error:<br>
<br>
                fatal:Number of dimensions in parameter (2) of (filedimdef) is (2), (1) dimensions were expected<br>
                fatal:[&quot;Execute.c&quot;:8128]:Execute: Error occurred at or near line 82 in file File.ncl<br>
<br>
<br>
                The data I am creating is AOD with two dimensions (lat/lon). I am uncertain as to why it is expecting one dimension. Below is my script. FYI, the original files had to be manipulated in order to make AOD have the lat/lon dimensions. Any help would be greatly appreciated.<br>
<br>
<br>
                load &quot;/home/bliujuss/ncl/lib/ncarg/nclscripts/csm/gsn_code.ncl&quot;<br>
                load &quot;/home/bliujuss/ncl/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl&quot;<br>
                load &quot;/home/bliujuss/ncl/lib/ncarg/nclscripts/csm/gsn_csm.ncl&quot;<br>
                load &quot;/home/bliujuss/ncl/lib/ncarg/nclscripts/csm/shea_util.ncl&quot;<br>
                begin<br>
<br>
                diri = &quot;/home/bliujuss/Verification_data/Test/&quot;<br>
                fili = systemfunc(&quot;ls &quot;+diri+&quot;*.hdf&quot;)<br>
                a = addfiles(fili,&quot;r&quot;)<br>
<br>
                ;ListSetType(a,&quot;cat&quot;)<br>
<br>
                var1=a[:]-&gt;Optical_Depth_Land_And_Ocean(:,:)<br>
                Optical_Depth_Land_And_Ocean = short2flt(var1)<br>
<br>
                var2=a[:]-&gt;Longitude(:,:)<br>
                Longitude=var2<br>
<br>
<br>
                var3 = a[:]-&gt;Latitude(:,:)<br>
                Latitude=var3<br>
<br>
                dims = dimsizes(Optical_Depth_Land_And_Ocean)<br>
                nrows = dims(0) ;203<br>
                npixels = dims(1) ;135<br>
<br>
                lat2d = new((/nrows,npixels/),float)<br>
                lon2d = new((/nrows,npixels/),float)<br>
<br>
                do i=0,npixels-1<br>
                  lat2d(:,i) = Latitude(:,i)<br>
                end do<br>
<br>
                do i=0,nrows-1<br>
                  lon2d(i,:) = Longitude(i,:)<br>
                end do<br>
<br>
                Optical_Depth_Land_And_Ocean@lat2d = lat2d(::5,::5) Optical_Depth_Land_And_Ocean@lon2d = lon2d(::5,::5)<br>
<br>
<br>
                wks = gsn_open_wks(&quot;x11&quot;,&quot;plot_aod&quot;)<br>
                gsn_define_colormap(wks,&quot;NCV_banded&quot;)<br>
                setvalues NhlGetWorkspaceObjectId()<br>
                  &quot;wsMaximumSize&quot;: 300000000<br>
                end setvalues<br>
<br>
                res                   = True               ; plot mods desired<br>
                res@cnLinesOn         = False              ; turn off contour lines<br>
                res@cnFillOn          = True               ; color plot desired<br>
                res@cnLineLabelsOn    = False              ; turn off contour lines<br>
                res@gsnAddCyclic      = False             ; non-global data<br>
                res@gsnSpreadColors   = True               ; use full range of colormap<br>
                ;res@cnFillMode        = &quot;RasterFill&quot;       ; turn on raster mode<br>
                res@lbLabelAutoStride = True               ; nice spacing of lables<br>
                res@gsnMaximize       = True               ; blow up plot as much as poss<br>
                ;print(min(lat2d))<br>
                ;print(max(lat2d))<br>
                ;print(min(lon2d))<br>
                ;print(max(lon2d))<br>
<br>
                plot = gsn_csm_contour_map_ce(wks,Optical_Depth_Land_And_Ocean(::5,::5),res)<br>
                print(max(Optical_Depth_Land_And_Ocean(::5,::5)))<br>
<br>
                nlat = dimsizes(lat2d(::5,::5))<br>
                nlon = dimsizes(lon2d(::5,::5))<br>
<br>
                diro = &quot;/home/bliujuss/Plots/&quot;<br>
                filo = &quot;<a href="http://example.nc" target="_blank">example.nc</a>&quot;<br>
                system(&quot;rm -f&quot; + diro + filo)<br>
                fout = addfile (diro + filo, &quot;c&quot;)<br>
<br>
                setfileoption(fout,&quot;DefineMode&quot;,True)<br>
<br>
                dim_names = (/&quot;lat&quot;, &quot;lon&quot;/)<br>
                dim_sizes = (/nlat, nlon/)<br>
                dimUnlim = (/False, False/)<br>
                filedimdef(fout,dim_names,dim_sizes,dimUnlim)<br>
<br>
                filevardef(fout, &quot;lat&quot;, typeof(lat2d(::5,::5)),getvardims(lat2d(::5,::5)))<br>
                filevardef(fout, &quot;lon&quot;, typeof(lon2d(::5,::5)),getvardims(lon2d(::5,::5)))<br>
                filevardef(fout, &quot;AOT&quot;, typeof(Optical_Depth_Land_And_Ocean(::5,::5)),getvardims(Optical_Depth_Land_And_Ocean(::5,::5)))<br>
<br>
                filevarattdef(fout,&quot;AOT&quot;, Optical_Depth_Land_And_Ocean(::5,::5))<br>
                filevarattdef(fout,&quot;lat&quot;, lat2d(::5,::5)) filevarattdef(fout,&quot;lon&quot;, lon2d(::5,::5))<br>
<br>
                setfileoption(fout,&quot;DefineMode&quot;,False)<br>
<br>
                fout-&gt;Optical_Depth_Land_And_Ocean(::5,::5) =<br>
<br>
                fout-&gt;(/Optical_Depth_Land_And_Ocean(::5,::5)/)<br>
<br>
                fout-&gt;lat2d(::5,::5) = (/lat2d(::5,::5)/)<br>
                fout-&gt;lon2d(::5,::5) = (/lon2d(::5,::5)/)<br>
<br>
                end<br>
<br>
<br>
                Steven Bliujus<br>
<br>
<br>
                _______________________________________________<br>
                ncl-talk mailing list<br>
                List instructions, subscriber options, unsubscribe:<br>
                <a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br>
<br>
                _______________________________________________<br>
                ncl-talk mailing list<br>
                List instructions, subscriber options, unsubscribe:<br>
                <a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div></div></blockquote></div><br></div>