title: Different CHARACTER lengths (3/4) in array constructor, how to trim strings - fortran
body: <p>According to an answer to a similar question, I have declared the characters as indicated here <a href="https://stackoverflow.com/questions/21552430/gfortran-does-not-allow-character-arrays-with-varying-component-lengths-fortran">gfortran does not allow character arrays with varying component lengths</a> . However I would like to use a trim function because I need to add spaces to manually pad the names and these variables are then used in another part of the code. Can I trim at the same time as creating the array?</p>
  
  <blockquote>
    <p>Error: Different CHARACTER lengths (3/4) in array constructor at (1)</p>
  </blockquote>
  
  <p>If I add random characters to make them the same length it works but I can't do that for obvious reasons. I have compiled both with gfortran and mpif90 with same results</p>
  
  <pre><code>use mod_maxdims , only : maxstr
  integer, parameter :: nvars_ncep = 12
  
  character(len=maxstr), parameter, dimension(nvars_ncep) :: vars_ncep =                  &amp;
                             (/ 'air'              &amp; ! Air temperature                  [      K]
                              , 'pres'             &amp; ! Pressure                         [     Pa]
                              , 'rhum'             &amp; ! Relative humidity                [      %]
                              , 'uwnd'             &amp; ! Zonal wind                       [    m/s]
                              , 'vwnd'             &amp; ! Zonal wind                       [    m/s]
                              , 'pres'             &amp; ! Pressure                         [     Pa]
                              , 'dlwrf'            &amp; ! Downward long wave radiation     [   W/m2]
                              , 'nbdsf'            &amp; ! Near-IR beam radiation           [   W/m2]
                              , 'nddsf'            &amp; ! Near-IR diffuse radiation        [   W/m2]
                              , 'vbdsf'            &amp; ! Visible beam radiation           [   W/m2]
                              , 'vddsf'            &amp; ! Visible beam radiation           [   W/m2]
                              , 'prate'           /) ! Precipitation rate               [kg/m2/s]
  </code></pre>