@@ -96,54 +96,11 @@ subroutine contour_filled(x, y, z, levels, colormap, show_colorbar, label)
9696 call ensure_global_figure_initialized()
9797
9898 ! Convert input arrays to working precision
99- allocate (wp_x(size (x)), wp_y(size (y)), wp_z(size (z,1 ), size (z,2 )))
100- wp_x = real (x, wp)
101- wp_y = real (y, wp)
102- wp_z = real (z, wp)
99+ call convert_contour_arrays(x, y, z, levels, wp_x, wp_y, wp_z, wp_levels)
103100
104- if (present (levels)) then
105- allocate (wp_levels(size (levels)))
106- wp_levels = real (levels, wp)
107- else
108- allocate (wp_levels(0 ))
109- end if
110-
111- ! Forward parameters to underlying method using conditional calls for memory safety
112- if (present (levels) .and. present (colormap) .and. present (show_colorbar) .and. present (label)) then
113- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, &
114- colormap= colormap, show_colorbar= show_colorbar, label= label)
115- else if (present (levels) .and. present (colormap) .and. present (show_colorbar)) then
116- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, &
117- colormap= colormap, show_colorbar= show_colorbar)
118- else if (present (levels) .and. present (colormap) .and. present (label)) then
119- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, &
120- colormap= colormap, label= label)
121- else if (present (colormap) .and. present (show_colorbar) .and. present (label)) then
122- call fig% add_contour_filled(wp_x, wp_y, wp_z, colormap= colormap, &
123- show_colorbar= show_colorbar, label= label)
124- else if (present (levels) .and. present (colormap)) then
125- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, colormap= colormap)
126- else if (present (levels) .and. present (show_colorbar)) then
127- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, show_colorbar= show_colorbar)
128- else if (present (levels) .and. present (label)) then
129- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, label= label)
130- else if (present (colormap) .and. present (show_colorbar)) then
131- call fig% add_contour_filled(wp_x, wp_y, wp_z, colormap= colormap, show_colorbar= show_colorbar)
132- else if (present (colormap) .and. present (label)) then
133- call fig% add_contour_filled(wp_x, wp_y, wp_z, colormap= colormap, label= label)
134- else if (present (show_colorbar) .and. present (label)) then
135- call fig% add_contour_filled(wp_x, wp_y, wp_z, show_colorbar= show_colorbar, label= label)
136- else if (present (levels)) then
137- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels)
138- else if (present (colormap)) then
139- call fig% add_contour_filled(wp_x, wp_y, wp_z, colormap= colormap)
140- else if (present (show_colorbar)) then
141- call fig% add_contour_filled(wp_x, wp_y, wp_z, show_colorbar= show_colorbar)
142- else if (present (label)) then
143- call fig% add_contour_filled(wp_x, wp_y, wp_z, label= label)
144- else
145- call fig% add_contour_filled(wp_x, wp_y, wp_z)
146- end if
101+ ! Forward parameters using helper subroutine
102+ call forward_contour_filled_params(fig, wp_x, wp_y, wp_z, wp_levels, &
103+ colormap, show_colorbar, label)
147104
148105 deallocate (wp_x, wp_y, wp_z)
149106 if (allocated (wp_levels)) deallocate (wp_levels)
@@ -451,54 +408,11 @@ subroutine add_contour_filled(x, y, z, levels, colormap, show_colorbar, label)
451408 call ensure_global_figure_initialized()
452409
453410 ! Convert input arrays to working precision
454- allocate (wp_x(size (x)), wp_y(size (y)), wp_z(size (z,1 ), size (z,2 )))
455- wp_x = real (x, wp)
456- wp_y = real (y, wp)
457- wp_z = real (z, wp)
458-
459- if (present (levels)) then
460- allocate (wp_levels(size (levels)))
461- wp_levels = real (levels, wp)
462- else
463- allocate (wp_levels(0 ))
464- end if
411+ call convert_contour_arrays(x, y, z, levels, wp_x, wp_y, wp_z, wp_levels)
465412
466- ! Forward parameters to underlying method using conditional calls for memory safety
467- if (present (levels) .and. present (colormap) .and. present (show_colorbar) .and. present (label)) then
468- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, &
469- colormap= colormap, show_colorbar= show_colorbar, label= label)
470- else if (present (levels) .and. present (colormap) .and. present (show_colorbar)) then
471- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, &
472- colormap= colormap, show_colorbar= show_colorbar)
473- else if (present (levels) .and. present (colormap) .and. present (label)) then
474- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, &
475- colormap= colormap, label= label)
476- else if (present (colormap) .and. present (show_colorbar) .and. present (label)) then
477- call fig% add_contour_filled(wp_x, wp_y, wp_z, colormap= colormap, &
478- show_colorbar= show_colorbar, label= label)
479- else if (present (levels) .and. present (colormap)) then
480- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, colormap= colormap)
481- else if (present (levels) .and. present (show_colorbar)) then
482- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, show_colorbar= show_colorbar)
483- else if (present (levels) .and. present (label)) then
484- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels, label= label)
485- else if (present (colormap) .and. present (show_colorbar)) then
486- call fig% add_contour_filled(wp_x, wp_y, wp_z, colormap= colormap, show_colorbar= show_colorbar)
487- else if (present (colormap) .and. present (label)) then
488- call fig% add_contour_filled(wp_x, wp_y, wp_z, colormap= colormap, label= label)
489- else if (present (show_colorbar) .and. present (label)) then
490- call fig% add_contour_filled(wp_x, wp_y, wp_z, show_colorbar= show_colorbar, label= label)
491- else if (present (levels)) then
492- call fig% add_contour_filled(wp_x, wp_y, wp_z, levels= wp_levels)
493- else if (present (colormap)) then
494- call fig% add_contour_filled(wp_x, wp_y, wp_z, colormap= colormap)
495- else if (present (show_colorbar)) then
496- call fig% add_contour_filled(wp_x, wp_y, wp_z, show_colorbar= show_colorbar)
497- else if (present (label)) then
498- call fig% add_contour_filled(wp_x, wp_y, wp_z, label= label)
499- else
500- call fig% add_contour_filled(wp_x, wp_y, wp_z)
501- end if
413+ ! Forward parameters using helper subroutine
414+ call forward_contour_filled_params(fig, wp_x, wp_y, wp_z, wp_levels, &
415+ colormap, show_colorbar, label)
502416
503417 deallocate (wp_x, wp_y, wp_z)
504418 if (allocated (wp_levels)) deallocate (wp_levels)
@@ -884,4 +798,102 @@ subroutine show_viewer_implementation(blocking)
884798 end if
885799 end subroutine show_viewer_implementation
886800
801+ ! Helper subroutines for contour parameter forwarding
802+
803+ subroutine convert_contour_arrays (x , y , z , levels , wp_x , wp_y , wp_z , wp_levels )
804+ ! ! Convert contour input arrays to working precision
805+ real (8 ), dimension (:), intent (in ) :: x, y
806+ real (8 ), dimension (:,:), intent (in ) :: z
807+ real (8 ), dimension (:), intent (in ), optional :: levels
808+ real (wp), allocatable , intent (out ) :: wp_x(:), wp_y(:), wp_z(:,:), wp_levels(:)
809+
810+ allocate (wp_x(size (x)), wp_y(size (y)), wp_z(size (z,1 ), size (z,2 )))
811+ wp_x = real (x, wp)
812+ wp_y = real (y, wp)
813+ wp_z = real (z, wp)
814+
815+ if (present (levels)) then
816+ allocate (wp_levels(size (levels)))
817+ wp_levels = real (levels, wp)
818+ else
819+ allocate (wp_levels(0 ))
820+ end if
821+ end subroutine convert_contour_arrays
822+
823+ subroutine forward_contour_filled_params (figure_obj , x , y , z , levels , &
824+ colormap , show_colorbar , label )
825+ ! ! Forward optional parameters to add_contour_filled with correct combinations
826+ type (figure_t), intent (inout ) :: figure_obj
827+ real (wp), dimension (:), intent (in ) :: x, y
828+ real (wp), dimension (:,:), intent (in ) :: z
829+ real (wp), dimension (:), intent (in ) :: levels
830+ character (len=* ), intent (in ), optional :: colormap, label
831+ logical , intent (in ), optional :: show_colorbar
832+
833+ logical :: has_levels, has_colormap, has_colorbar, has_label
834+
835+ ! Check which parameters are present and meaningful
836+ has_levels = size (levels) > 0
837+ has_colormap = present (colormap)
838+ has_colorbar = present (show_colorbar)
839+ has_label = present (label)
840+
841+ ! Forward based on parameter combinations using nested if structure
842+ if (has_levels) then
843+ if (has_colormap) then
844+ if (has_colorbar) then
845+ if (has_label) then
846+ call figure_obj% add_contour_filled(x, y, z, levels= levels, &
847+ colormap= colormap, show_colorbar= show_colorbar, label= label)
848+ else
849+ call figure_obj% add_contour_filled(x, y, z, levels= levels, &
850+ colormap= colormap, show_colorbar= show_colorbar)
851+ end if
852+ else if (has_label) then
853+ call figure_obj% add_contour_filled(x, y, z, levels= levels, &
854+ colormap= colormap, label= label)
855+ else
856+ call figure_obj% add_contour_filled(x, y, z, levels= levels, colormap= colormap)
857+ end if
858+ else if (has_colorbar) then
859+ if (has_label) then
860+ call figure_obj% add_contour_filled(x, y, z, levels= levels, &
861+ show_colorbar= show_colorbar, label= label)
862+ else
863+ call figure_obj% add_contour_filled(x, y, z, levels= levels, &
864+ show_colorbar= show_colorbar)
865+ end if
866+ else if (has_label) then
867+ call figure_obj% add_contour_filled(x, y, z, levels= levels, label= label)
868+ else
869+ call figure_obj% add_contour_filled(x, y, z, levels= levels)
870+ end if
871+ else if (has_colormap) then
872+ if (has_colorbar) then
873+ if (has_label) then
874+ call figure_obj% add_contour_filled(x, y, z, colormap= colormap, &
875+ show_colorbar= show_colorbar, label= label)
876+ else
877+ call figure_obj% add_contour_filled(x, y, z, colormap= colormap, &
878+ show_colorbar= show_colorbar)
879+ end if
880+ else if (has_label) then
881+ call figure_obj% add_contour_filled(x, y, z, colormap= colormap, label= label)
882+ else
883+ call figure_obj% add_contour_filled(x, y, z, colormap= colormap)
884+ end if
885+ else if (has_colorbar) then
886+ if (has_label) then
887+ call figure_obj% add_contour_filled(x, y, z, show_colorbar= show_colorbar, &
888+ label= label)
889+ else
890+ call figure_obj% add_contour_filled(x, y, z, show_colorbar= show_colorbar)
891+ end if
892+ else if (has_label) then
893+ call figure_obj% add_contour_filled(x, y, z, label= label)
894+ else
895+ call figure_obj% add_contour_filled(x, y, z)
896+ end if
897+ end subroutine forward_contour_filled_params
898+
887899end module fortplot_matplotlib
0 commit comments